forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoalSparkline.tsx
More file actions
51 lines (44 loc) · 1.18 KB
/
Copy pathGoalSparkline.tsx
File metadata and controls
51 lines (44 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use client';
import { sparklinePoints } from '@/lib/goals';
import type { GoalHistoryEntry } from '@/types/goals';
const WIDTH = 280;
const HEIGHT = 56;
const PADDING = 4;
interface GoalSparklineProps {
history: GoalHistoryEntry[];
label: string;
}
export function GoalSparkline({ history, label }: GoalSparklineProps) {
const points = sparklinePoints(history);
if (points.length < 2) {
return (
<p className="text-sm text-text-quaternary">Not enough history to chart yet.</p>
);
}
const path = points
.map(({ x, y }, index) => {
const px = PADDING + x * (WIDTH - PADDING * 2);
const py = PADDING + y * (HEIGHT - PADDING * 2);
return `${index === 0 ? 'M' : 'L'} ${px.toFixed(1)} ${py.toFixed(1)}`;
})
.join(' ');
return (
<svg
viewBox={`0 0 ${WIDTH} ${HEIGHT}`}
className="h-14 w-full"
role="img"
aria-label={`${label} progress over time`}
preserveAspectRatio="none"
>
<path
d={path}
fill="none"
stroke="currentColor"
strokeWidth={1.5}
strokeLinecap="round"
strokeLinejoin="round"
className="text-text-secondary"
/>
</svg>
);
}