Skip to content

Commit ef07c16

Browse files
fix undefined unit label in tooltip
1 parent 908bff1 commit ef07c16

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/lib/components/charts/linetimeseries/LineTimeSerieChart.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ const LineTimeSerieChartTooltip = ({
172172

173173
const formattedValue = !Number.isFinite(entry.value)
174174
? '-'
175-
: `${entry.value.toFixed(2)} ${unitLabel}`;
175+
: `${entry.value.toFixed(2)}${unitLabel ? ` ${unitLabel}` : ''}`;
176176

177177
return (
178178
<React.Fragment key={index}>
@@ -375,9 +375,9 @@ export function LineTimeSerieChart({
375375
Object.entries(dataPoint)
376376
.filter(([key]) => key !== 'timestamp')
377377
.map(([_, value]) => {
378-
const num =
379-
typeof value === 'string' ? Number(value) : (value ?? Infinity);
380-
return !isNaN(num) && num !== null ? num : null;
378+
if (value === null || value === undefined) return null;
379+
const num = typeof value === 'string' ? Number(value) : value;
380+
return !isNaN(num) ? num : null;
381381
})
382382
.filter((value): value is number => value !== null),
383383
);
@@ -386,7 +386,7 @@ export function LineTimeSerieChart({
386386
if (values.length === 0) {
387387
return {
388388
topValue: 100, // Default value for empty charts
389-
unitLabel: yAxisType === 'percentage' ? '%' : '',
389+
unitLabel: yAxisType === 'percentage' ? '%' : undefined,
390390
rechartsData: [],
391391
topDomain: 100,
392392
};
@@ -406,7 +406,7 @@ export function LineTimeSerieChart({
406406

407407
return {
408408
topValue: result.topValue,
409-
unitLabel: result.unitLabel,
409+
unitLabel: result.unitLabel ?? (yAxisType === 'percentage' ? '%' : undefined),
410410
rechartsData: result.rechartsData,
411411
topDomain: result.topDomain,
412412
};

0 commit comments

Comments
 (0)