Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/lib/components/charts/linetimeseries/LineTimeSerieChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ const LineTimeSerieChartTooltip = ({

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

return (
<React.Fragment key={index}>
Expand Down Expand Up @@ -375,9 +375,9 @@ export function LineTimeSerieChart({
Object.entries(dataPoint)
.filter(([key]) => key !== 'timestamp')
.map(([_, value]) => {
const num =
typeof value === 'string' ? Number(value) : (value ?? Infinity);
return !isNaN(num) && num !== null ? num : null;
if (value === null || value === undefined) return null;
const num = typeof value === 'string' ? Number(value) : value;
return !isNaN(num) ? num : null;
})
.filter((value): value is number => value !== null),
);
Expand All @@ -386,7 +386,7 @@ export function LineTimeSerieChart({
if (values.length === 0) {
return {
topValue: 100, // Default value for empty charts
unitLabel: yAxisType === 'percentage' ? '%' : '',
unitLabel: yAxisType === 'percentage' ? '%' : undefined,
rechartsData: [],
topDomain: 100,
};
Expand All @@ -404,11 +404,17 @@ export function LineTimeSerieChart({
'timestamp', // LineTimeSerieChart uses 'timestamp' as the key to exclude
);

// For percentage charts, ensure Y-axis goes to at least 100%
const topDomain =
yAxisType === 'percentage'
? Math.max(result.topDomain, 100)
: result.topDomain;

return {
topValue: result.topValue,
unitLabel: result.unitLabel,
topValue: yAxisType === 'percentage' ? Math.max(result.topValue, 100) : result.topValue,
unitLabel: result.unitLabel ?? (yAxisType === 'percentage' ? '%' : undefined),
rechartsData: result.rechartsData,
topDomain: result.topDomain,
topDomain,
};
}, [chartData, yAxisType, unitRange]);

Expand Down Expand Up @@ -473,12 +479,7 @@ export function LineTimeSerieChart({
)}
{isLoading && <Loader />}
</Stack>
<div
onFocus={() => setIsChartActive(true)}
onBlur={() => setIsChartActive(false)}
onFocusCapture={() => setIsChartActive(true)}
onBlurCapture={() => setIsChartActive(false)}
>
<div>
<StyledResponsiveContainer width="100%" height={height}>
<LineChart
data={rechartsData}
Expand Down
Loading