Timeseries: Numeric duration values could render as NaN (#73795) (#112076)

This commit is contained in:
Paul Marbach
2025-10-08 14:42:13 -04:00
committed by GitHub
parent a0fc683a67
commit 8a59baa7d5
2 changed files with 11 additions and 2 deletions
@@ -423,6 +423,11 @@ describe('Format value', () => {
const processor = getDisplayProcessorFromConfig({ decimals: 5 }, FieldType.number);
expect(processor(35, 2).text).toEqual('35.00000');
});
it('does not attempt to coerce non-numeric strings back to numbers', () => {
const processor = getDisplayProcessorFromConfig({ unit: 'dthms' }, FieldType.number);
expect(processor(35, 2).text).toEqual('00:00:35'); // we're checking that this isn't NaN.
});
});
});
@@ -49,7 +49,7 @@ export function getDisplayProcessor(options?: DisplayProcessorOptions): DisplayP
const { palette } = options.theme.visualization;
let unit = config.unit;
let hasDateUnit = unit && (timeFormats[unit] || unit.startsWith('time:'));
let hasDateUnit = Boolean(unit && (timeFormats[unit] || unit.startsWith('time:')));
let showMs = false;
if (field.type === FieldType.time && !hasDateUnit) {
@@ -152,7 +152,11 @@ export function getDisplayProcessor(options?: DisplayProcessorOptions): DisplayP
// this is needed because we may have determined the minimum determined `adjacentDecimals` for y tick increments based on
// e.g. 'seconds' field unit (0.15s, 0.20s, 0.25s), but then formatFunc decided to return milli or nanos (150, 200, 250)
// so we end up with excess precision: 150.00, 200.00, 250.00
v.text = +v.text + '';
// #73795 - some units, like duration formats, return text which cannot be coerced back into a number safely at this point.
const asNum = +v.text;
if (!Number.isNaN(asNum)) {
v.text = asNum + '';
}
} else {
v = formatFunc(numeric, config.decimals, null, options.timeZone, showMs);
}