fix(ui): Show single-point sparkline as horizontal line

When there's only 1 day of AI usage data, the sparkline was invisible
because a single point draws at x=0 with no width. Now draws a
horizontal line across the full width so users can see the value.

This happens when AI has just been enabled and there's only one
day of recorded usage so far.
This commit is contained in:
rcourtman 2025-12-12 13:21:54 +00:00
parent 5f2c240480
commit a0d2e46510

View file

@ -34,7 +34,14 @@ const TinySparkline: Component<{
const max = Math.max(...values, 0);
const safeMax = max <= 0 ? 1 : max;
const xStep = values.length <= 1 ? 0 : w / (values.length - 1);
// For single point, draw a horizontal line across the middle
if (values.length === 1) {
const y = h - (Math.max(0, values[0]) / safeMax) * h;
// Draw a short horizontal line to make the single point visible
return `M0,${y.toFixed(2)} L${w.toFixed(2)},${y.toFixed(2)}`;
}
const xStep = w / (values.length - 1);
let d = '';
values.forEach((v, idx) => {
const x = idx * xStep;