@umituz/web-dashboard 8.11.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -7
- package/package.json +6 -2
- package/src/config/DashboardConfig.ts +4 -8
- package/src/domains/analytics/components/AnalyticsLayout.test.tsx +85 -0
- package/src/domains/analytics/components/AnalyticsLayout.tsx +103 -105
- package/src/domains/analytics/components/index.ts +0 -3
- package/src/domains/analytics/hooks/index.ts +1 -1
- package/src/domains/analytics/hooks/useAnalytics.test.tsx +125 -0
- package/src/domains/analytics/hooks/useAnalytics.ts +37 -56
- package/src/domains/analytics/index.ts +9 -26
- package/src/domains/analytics/services/index.ts +0 -1
- package/src/domains/analytics/types/analytics.ts +32 -149
- package/src/domains/analytics/types/index.ts +3 -15
- package/src/domains/analytics/utils/analytics.test.ts +82 -13
- package/src/domains/analytics/utils/analytics.ts +52 -75
- package/src/domains/analytics/utils/index.ts +5 -8
- package/src/domains/charts/charts.css +455 -0
- package/src/domains/charts/components/ActivityHeatmap.test.tsx +48 -0
- package/src/domains/charts/components/ActivityHeatmap.tsx +58 -0
- package/src/domains/charts/components/BarChart.test.tsx +91 -0
- package/src/domains/charts/components/BarChart.tsx +143 -0
- package/src/domains/charts/components/ChartCard.tsx +39 -0
- package/src/domains/charts/components/ChartPrimitives.test.tsx +90 -0
- package/src/domains/charts/components/ChartTip.tsx +18 -0
- package/src/domains/charts/components/Donut.test.tsx +51 -0
- package/src/domains/charts/components/Donut.tsx +97 -0
- package/src/domains/charts/components/HBars.tsx +31 -0
- package/src/domains/charts/components/Legend.tsx +21 -0
- package/src/domains/charts/components/LineChart.test.tsx +81 -0
- package/src/domains/charts/components/LineChart.tsx +244 -0
- package/src/domains/charts/components/Sparkline.tsx +35 -0
- package/src/domains/charts/components/index.ts +16 -0
- package/src/domains/charts/index.ts +16 -2
- package/src/domains/charts/ssr.test.tsx +35 -0
- package/src/domains/charts/types/index.ts +8 -0
- package/src/domains/charts/utils.ts +15 -0
- package/src/index.ts +6 -23
- package/src/styles/chrome.css +10 -490
- package/src/styles/dashboard.contract.test.ts +20 -5
- package/src/styles/dashboard.css +1 -0
- package/src/domains/analytics/components/AnalyticsCard.tsx +0 -87
- package/src/domains/analytics/components/AnalyticsChart.tsx +0 -387
- package/src/domains/analytics/components/MetricCard.tsx +0 -42
- package/src/domains/analytics/services/AnalyticsEngineService.ts +0 -300
- package/src/domains/charts/components.test.tsx +0 -141
- package/src/domains/charts/components.tsx +0 -683
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
import type { Metric, KPIData, DateRangePreset } from "../types/analytics";
|
|
1
|
+
import type { TimeSeriesDatum } from "../types/analytics";
|
|
4
2
|
|
|
5
3
|
export function formatNumber(num: number, decimals: number = 1): string {
|
|
6
4
|
if (num >= 1_000_000_000) {
|
|
@@ -44,50 +42,62 @@ export function getTrend(growth: number): "up" | "down" | "stable" {
|
|
|
44
42
|
return "stable";
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
export
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
previous,
|
|
52
|
-
growth,
|
|
53
|
-
};
|
|
45
|
+
export interface KpiDeltaLike {
|
|
46
|
+
value: string;
|
|
47
|
+
direction: "up" | "down" | "flat";
|
|
48
|
+
good: boolean;
|
|
54
49
|
}
|
|
55
50
|
|
|
56
|
-
export function
|
|
57
|
-
|
|
58
|
-
name: string,
|
|
59
|
-
value: number,
|
|
51
|
+
export function toKpiDelta(
|
|
52
|
+
value: number | string,
|
|
60
53
|
previousValue?: number,
|
|
61
|
-
|
|
62
|
-
):
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
54
|
+
goodWhen: "up" | "down" = "up",
|
|
55
|
+
): KpiDeltaLike | undefined {
|
|
56
|
+
if (previousValue === undefined || previousValue === 0) return undefined;
|
|
57
|
+
const current = typeof value === "number" ? value : Number(value);
|
|
58
|
+
if (!Number.isFinite(current)) return undefined;
|
|
59
|
+
const change = ((current - previousValue) / previousValue) * 100;
|
|
60
|
+
if (Math.abs(change) < 0.05) {
|
|
61
|
+
return { value: `${change.toFixed(1)}%`, direction: "flat", good: true };
|
|
62
|
+
}
|
|
63
|
+
const direction = change > 0 ? "up" : "down";
|
|
64
|
+
const good = direction === goodWhen;
|
|
65
|
+
return { value: `${change > 0 ? "+" : ""}${change.toFixed(1)}%`, direction, good };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function toCsv(
|
|
69
|
+
headers: readonly string[],
|
|
70
|
+
rows: readonly (readonly (string | number)[])[],
|
|
71
|
+
): string {
|
|
72
|
+
const escapeCell = (cell: string | number): string => {
|
|
73
|
+
const text = String(cell);
|
|
74
|
+
return /[",\n;]/.test(text) ? `"${text.replaceAll('"', '""')}"` : text;
|
|
71
75
|
};
|
|
76
|
+
const lines = [
|
|
77
|
+
headers.map(escapeCell).join(","),
|
|
78
|
+
...rows.map((row) => row.map(escapeCell).join(",")),
|
|
79
|
+
];
|
|
80
|
+
return `${lines.join("\r\n")}`;
|
|
72
81
|
}
|
|
73
82
|
|
|
74
|
-
export function
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
83
|
+
export function downloadCsv(filename: string, csv: string): void {
|
|
84
|
+
const blob = new Blob([csv], { type: "text/csv;charset=utf-8" });
|
|
85
|
+
const url = URL.createObjectURL(blob);
|
|
86
|
+
const link = document.createElement("a");
|
|
87
|
+
link.href = url;
|
|
88
|
+
link.download = filename;
|
|
89
|
+
document.body.appendChild(link);
|
|
90
|
+
link.click();
|
|
91
|
+
document.body.removeChild(link);
|
|
92
|
+
URL.revokeObjectURL(url);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function exportCsv(options: {
|
|
96
|
+
filename: string;
|
|
97
|
+
headers: readonly string[];
|
|
98
|
+
rows: readonly (readonly (string | number)[])[];
|
|
99
|
+
}): void {
|
|
100
|
+
downloadCsv(options.filename, toCsv(options.headers, options.rows));
|
|
91
101
|
}
|
|
92
102
|
|
|
93
103
|
export function calculateConversionRate(converted: number, total: number): number {
|
|
@@ -100,30 +110,6 @@ export function calculateDropOffRate(current: number, previous: number): number
|
|
|
100
110
|
return ((previous - current) / previous) * 100;
|
|
101
111
|
}
|
|
102
112
|
|
|
103
|
-
export function createDateRangePreset(label: string, days: number): DateRangePreset {
|
|
104
|
-
const to = new Date();
|
|
105
|
-
const from = new Date();
|
|
106
|
-
from.setDate(from.getDate() - days);
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
label,
|
|
110
|
-
value: label.toLowerCase().replace(/\s+/g, "-"),
|
|
111
|
-
days,
|
|
112
|
-
from: from.toISOString().split("T")[0],
|
|
113
|
-
to: to.toISOString().split("T")[0],
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function getDateRangePresets(): DateRangePreset[] {
|
|
118
|
-
return [
|
|
119
|
-
createDateRangePreset("Last 7 Days", 7),
|
|
120
|
-
createDateRangePreset("Last 30 Days", 30),
|
|
121
|
-
createDateRangePreset("Last 90 Days", 90),
|
|
122
|
-
createDateRangePreset("This Year", 365),
|
|
123
|
-
createDateRangePreset("All Time", 365 * 10),
|
|
124
|
-
];
|
|
125
|
-
}
|
|
126
|
-
|
|
127
113
|
export function aggregateByPeriod(
|
|
128
114
|
data: Array<{ date: string; [key: string]: number | string }>,
|
|
129
115
|
period: "day" | "week" | "month" = "day"
|
|
@@ -155,7 +141,7 @@ export function aggregateByPeriod(
|
|
|
155
141
|
});
|
|
156
142
|
|
|
157
143
|
return Array.from(grouped.entries()).map(([date, items]) => {
|
|
158
|
-
const aggregated:
|
|
144
|
+
const aggregated: TimeSeriesDatum = { date };
|
|
159
145
|
|
|
160
146
|
items.forEach((item) => {
|
|
161
147
|
Object.entries(item).forEach(([key, value]) => {
|
|
@@ -205,12 +191,3 @@ export function roundTo(num: number, decimals: number = 2): number {
|
|
|
205
191
|
const multiplier = Math.pow(10, decimals);
|
|
206
192
|
return Math.round(num * multiplier) / multiplier;
|
|
207
193
|
}
|
|
208
|
-
|
|
209
|
-
export function generateColor(index: number, alpha: number = 1): string {
|
|
210
|
-
const hue = (index * 137.508) % 360;
|
|
211
|
-
return `hsla(${hue}, 70%, 50%, ${alpha})`;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export function generateChartColors(count: number, alpha: number = 1): string[] {
|
|
215
|
-
return Array.from({ length: count }, (_, i) => generateColor(i, alpha));
|
|
216
|
-
}
|
|
@@ -4,18 +4,15 @@ export {
|
|
|
4
4
|
formatCurrency,
|
|
5
5
|
calculateGrowth,
|
|
6
6
|
getTrend,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
toKpiDelta,
|
|
8
|
+
toCsv,
|
|
9
|
+
downloadCsv,
|
|
10
|
+
exportCsv,
|
|
10
11
|
calculateConversionRate,
|
|
11
12
|
calculateDropOffRate,
|
|
12
|
-
createDateRangePreset,
|
|
13
|
-
getDateRangePresets,
|
|
14
13
|
aggregateByPeriod,
|
|
15
14
|
calculateMovingAverage,
|
|
16
15
|
detectOutliers,
|
|
17
16
|
roundTo,
|
|
18
|
-
generateColor,
|
|
19
|
-
generateChartColors,
|
|
20
17
|
} from "./analytics";
|
|
21
|
-
|
|
18
|
+
export type { KpiDeltaLike } from "./analytics";
|
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--udb-chart-1: #357344;
|
|
3
|
+
--udb-chart-2: #b06e22;
|
|
4
|
+
--udb-chart-3: #3e5f80;
|
|
5
|
+
--udb-chart-4: #7a6ba8;
|
|
6
|
+
--udb-chart-5: #8a5a3b;
|
|
7
|
+
--udb-chart-6: #5e7d5a;
|
|
8
|
+
--udb-chart-7: #a8b5a0;
|
|
9
|
+
--udb-chart-8: #c9862f;
|
|
10
|
+
}
|
|
11
|
+
.udb-chartcard {
|
|
12
|
+
display: flex;
|
|
13
|
+
flex-direction: column;
|
|
14
|
+
min-width: 0;
|
|
15
|
+
background: var(--color-card);
|
|
16
|
+
border: 1px solid var(--color-border);
|
|
17
|
+
border-radius: var(--radius-lg);
|
|
18
|
+
box-shadow: var(--shadow-sm);
|
|
19
|
+
}
|
|
20
|
+
.udb-chartcard__head {
|
|
21
|
+
display: flex;
|
|
22
|
+
align-items: flex-start;
|
|
23
|
+
justify-content: space-between;
|
|
24
|
+
gap: var(--udb-space-3);
|
|
25
|
+
padding: 14px 18px 4px;
|
|
26
|
+
flex-wrap: wrap;
|
|
27
|
+
}
|
|
28
|
+
.udb-chartcard__heading {
|
|
29
|
+
min-width: 0;
|
|
30
|
+
}
|
|
31
|
+
.udb-chartcard__title {
|
|
32
|
+
font-size: var(--udb-font-size-md);
|
|
33
|
+
font-weight: 600;
|
|
34
|
+
color: var(--color-foreground);
|
|
35
|
+
}
|
|
36
|
+
.udb-chartcard__sub {
|
|
37
|
+
font-size: var(--udb-font-size-sm);
|
|
38
|
+
color: var(--color-muted-foreground);
|
|
39
|
+
margin-top: 1px;
|
|
40
|
+
}
|
|
41
|
+
.udb-chartcard__tools {
|
|
42
|
+
display: flex;
|
|
43
|
+
align-items: center;
|
|
44
|
+
gap: 12px;
|
|
45
|
+
flex-wrap: wrap;
|
|
46
|
+
}
|
|
47
|
+
.udb-chartcard__body {
|
|
48
|
+
padding: 10px 14px 14px;
|
|
49
|
+
min-width: 0;
|
|
50
|
+
}
|
|
51
|
+
.udb-chartcard__body svg {
|
|
52
|
+
display: block;
|
|
53
|
+
width: 100%;
|
|
54
|
+
height: auto;
|
|
55
|
+
}
|
|
56
|
+
.udb-chartcard__plot {
|
|
57
|
+
position: relative;
|
|
58
|
+
}
|
|
59
|
+
.udb-chartlegend {
|
|
60
|
+
display: flex;
|
|
61
|
+
flex-wrap: wrap;
|
|
62
|
+
gap: 5px 14px;
|
|
63
|
+
}
|
|
64
|
+
.udb-chartlegend__item {
|
|
65
|
+
display: inline-flex;
|
|
66
|
+
align-items: center;
|
|
67
|
+
gap: 6px;
|
|
68
|
+
font-size: var(--udb-font-size-sm);
|
|
69
|
+
color: var(--color-foreground);
|
|
70
|
+
white-space: nowrap;
|
|
71
|
+
}
|
|
72
|
+
.udb-chartlegend__dot {
|
|
73
|
+
width: 8px;
|
|
74
|
+
height: 8px;
|
|
75
|
+
border-radius: 2.5px;
|
|
76
|
+
flex: none;
|
|
77
|
+
}
|
|
78
|
+
.udb-chartlegend__value {
|
|
79
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
80
|
+
color: var(--color-muted-foreground);
|
|
81
|
+
font-size: var(--udb-font-size-xs);
|
|
82
|
+
}
|
|
83
|
+
.udb-chartlegend__hint {
|
|
84
|
+
color: var(--color-muted-foreground);
|
|
85
|
+
font-size: var(--udb-font-size-xs);
|
|
86
|
+
}
|
|
87
|
+
.udb-charttip {
|
|
88
|
+
position: absolute;
|
|
89
|
+
pointer-events: none;
|
|
90
|
+
background: var(--color-foreground);
|
|
91
|
+
color: var(--color-background);
|
|
92
|
+
border-radius: var(--radius-md);
|
|
93
|
+
padding: 7px 10px;
|
|
94
|
+
font-size: var(--udb-font-size-sm);
|
|
95
|
+
box-shadow: var(--shadow-lg);
|
|
96
|
+
z-index: 30;
|
|
97
|
+
min-width: 120px;
|
|
98
|
+
transform: translate(-50%, calc(-100% - 10px));
|
|
99
|
+
}
|
|
100
|
+
.udb-charttip__title {
|
|
101
|
+
font-weight: 600;
|
|
102
|
+
margin-bottom: 2px;
|
|
103
|
+
white-space: nowrap;
|
|
104
|
+
}
|
|
105
|
+
.udb-charttip__row {
|
|
106
|
+
display: flex;
|
|
107
|
+
align-items: center;
|
|
108
|
+
gap: 6px;
|
|
109
|
+
justify-content: space-between;
|
|
110
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
111
|
+
font-size: var(--udb-font-size-xs);
|
|
112
|
+
}
|
|
113
|
+
.udb-charttip__row b {
|
|
114
|
+
font-weight: 600;
|
|
115
|
+
}
|
|
116
|
+
.udb-charttip__label {
|
|
117
|
+
display: inline-flex;
|
|
118
|
+
align-items: center;
|
|
119
|
+
gap: 5px;
|
|
120
|
+
}
|
|
121
|
+
.udb-hbars {
|
|
122
|
+
display: flex;
|
|
123
|
+
flex-direction: column;
|
|
124
|
+
gap: 10px;
|
|
125
|
+
}
|
|
126
|
+
.udb-hbars__row {
|
|
127
|
+
display: grid;
|
|
128
|
+
grid-template-columns: minmax(120px, 1.2fr) 2fr auto;
|
|
129
|
+
align-items: center;
|
|
130
|
+
gap: 12px;
|
|
131
|
+
}
|
|
132
|
+
.udb-hbars__label {
|
|
133
|
+
min-width: 0;
|
|
134
|
+
}
|
|
135
|
+
.udb-hbars__name {
|
|
136
|
+
font-weight: 600;
|
|
137
|
+
font-size: var(--udb-font-size-sm);
|
|
138
|
+
overflow: hidden;
|
|
139
|
+
text-overflow: ellipsis;
|
|
140
|
+
white-space: nowrap;
|
|
141
|
+
color: var(--color-foreground);
|
|
142
|
+
}
|
|
143
|
+
.udb-hbars__sub {
|
|
144
|
+
font-size: var(--udb-font-size-xs);
|
|
145
|
+
color: var(--color-muted-foreground);
|
|
146
|
+
}
|
|
147
|
+
.udb-hbars__track {
|
|
148
|
+
height: 8px;
|
|
149
|
+
background: var(--color-border);
|
|
150
|
+
border-radius: 999px;
|
|
151
|
+
overflow: hidden;
|
|
152
|
+
}
|
|
153
|
+
.udb-hbars__fill {
|
|
154
|
+
height: 100%;
|
|
155
|
+
background: var(--color-primary);
|
|
156
|
+
border-radius: 999px;
|
|
157
|
+
}
|
|
158
|
+
.udb-hbars__value {
|
|
159
|
+
font-size: var(--udb-font-size-sm);
|
|
160
|
+
color: var(--color-foreground);
|
|
161
|
+
text-align: right;
|
|
162
|
+
font-variant-numeric: tabular-nums;
|
|
163
|
+
}
|
|
164
|
+
.udb-barchart {
|
|
165
|
+
position: relative;
|
|
166
|
+
display: flex;
|
|
167
|
+
align-items: flex-end;
|
|
168
|
+
gap: 3px;
|
|
169
|
+
width: 100%;
|
|
170
|
+
}
|
|
171
|
+
.udb-barchart__goal {
|
|
172
|
+
position: absolute;
|
|
173
|
+
left: 0;
|
|
174
|
+
right: 0;
|
|
175
|
+
z-index: 5;
|
|
176
|
+
pointer-events: none;
|
|
177
|
+
border-top: 1.5px dashed var(--udb-chart-goal, #d97706);
|
|
178
|
+
}
|
|
179
|
+
.udb-barchart__goallabel {
|
|
180
|
+
position: absolute;
|
|
181
|
+
right: 0;
|
|
182
|
+
bottom: 2px;
|
|
183
|
+
padding: 0 4px;
|
|
184
|
+
border: 1px solid var(--udb-chart-goal, #d97706);
|
|
185
|
+
border-radius: var(--udb-radius-pill);
|
|
186
|
+
background: var(--color-card);
|
|
187
|
+
font-size: var(--udb-font-size-xs);
|
|
188
|
+
line-height: 16px;
|
|
189
|
+
color: var(--udb-chart-goal, #d97706);
|
|
190
|
+
}
|
|
191
|
+
.udb-barchart__col {
|
|
192
|
+
position: relative;
|
|
193
|
+
display: flex;
|
|
194
|
+
flex: 1;
|
|
195
|
+
align-items: flex-end;
|
|
196
|
+
min-width: 0;
|
|
197
|
+
height: 100%;
|
|
198
|
+
}
|
|
199
|
+
.udb-barchart__bars {
|
|
200
|
+
display: flex;
|
|
201
|
+
align-items: flex-end;
|
|
202
|
+
justify-content: center;
|
|
203
|
+
gap: 2px;
|
|
204
|
+
width: 100%;
|
|
205
|
+
height: 100%;
|
|
206
|
+
}
|
|
207
|
+
.udb-barchart__bars .udb-barchart__bar {
|
|
208
|
+
flex: 1;
|
|
209
|
+
width: auto;
|
|
210
|
+
}
|
|
211
|
+
.udb-barchart__bar {
|
|
212
|
+
width: 100%;
|
|
213
|
+
min-height: 2px;
|
|
214
|
+
border-radius: 3px 3px 0 0;
|
|
215
|
+
transition: opacity 150ms ease, height 300ms ease;
|
|
216
|
+
}
|
|
217
|
+
.udb-barchart__bars--stacked {
|
|
218
|
+
flex-direction: column-reverse;
|
|
219
|
+
align-items: center;
|
|
220
|
+
justify-content: flex-end;
|
|
221
|
+
gap: 0;
|
|
222
|
+
}
|
|
223
|
+
.udb-barchart__bars--stacked .udb-barchart__bar {
|
|
224
|
+
flex: none;
|
|
225
|
+
width: 100%;
|
|
226
|
+
border-radius: 0;
|
|
227
|
+
}
|
|
228
|
+
.udb-barchart__bars--stacked .udb-barchart__bar:last-child {
|
|
229
|
+
border-radius: 3px 3px 0 0;
|
|
230
|
+
}
|
|
231
|
+
.udb-barchart__tip {
|
|
232
|
+
position: absolute;
|
|
233
|
+
bottom: calc(100% + 6px);
|
|
234
|
+
left: 50%;
|
|
235
|
+
z-index: 10;
|
|
236
|
+
padding: 4px 8px;
|
|
237
|
+
white-space: nowrap;
|
|
238
|
+
pointer-events: none;
|
|
239
|
+
border: 1px solid var(--color-border);
|
|
240
|
+
border-radius: var(--radius-sm);
|
|
241
|
+
background: var(--color-card);
|
|
242
|
+
box-shadow: var(--shadow-sm);
|
|
243
|
+
font-size: var(--udb-font-size-xs);
|
|
244
|
+
color: var(--color-muted-foreground);
|
|
245
|
+
}
|
|
246
|
+
.udb-barchart__tiptitle {
|
|
247
|
+
font-weight: var(--font-weight-medium);
|
|
248
|
+
color: var(--color-foreground);
|
|
249
|
+
}
|
|
250
|
+
.udb-barchart__tiprow {
|
|
251
|
+
display: flex;
|
|
252
|
+
align-items: center;
|
|
253
|
+
justify-content: space-between;
|
|
254
|
+
gap: 10px;
|
|
255
|
+
}
|
|
256
|
+
.udb-barchart__tiprow--total {
|
|
257
|
+
margin-top: 3px;
|
|
258
|
+
padding-top: 3px;
|
|
259
|
+
border-top: 1px solid var(--color-border);
|
|
260
|
+
}
|
|
261
|
+
.udb-barchart__tiplabel {
|
|
262
|
+
display: inline-flex;
|
|
263
|
+
align-items: center;
|
|
264
|
+
gap: 5px;
|
|
265
|
+
}
|
|
266
|
+
.udb-barchart__tip b {
|
|
267
|
+
margin-right: 4px;
|
|
268
|
+
font-weight: var(--font-weight-medium);
|
|
269
|
+
color: var(--color-foreground);
|
|
270
|
+
}
|
|
271
|
+
.udb-donut {
|
|
272
|
+
display: flex;
|
|
273
|
+
align-items: center;
|
|
274
|
+
gap: 20px;
|
|
275
|
+
}
|
|
276
|
+
.udb-donut__wrap {
|
|
277
|
+
position: relative;
|
|
278
|
+
flex-shrink: 0;
|
|
279
|
+
}
|
|
280
|
+
.udb-donut__seg {
|
|
281
|
+
cursor: pointer;
|
|
282
|
+
transition: stroke-width 150ms ease, opacity 150ms ease;
|
|
283
|
+
}
|
|
284
|
+
.udb-donut__center {
|
|
285
|
+
position: absolute;
|
|
286
|
+
inset: 0;
|
|
287
|
+
display: flex;
|
|
288
|
+
flex-direction: column;
|
|
289
|
+
align-items: center;
|
|
290
|
+
justify-content: center;
|
|
291
|
+
}
|
|
292
|
+
.udb-donut__value {
|
|
293
|
+
font-size: var(--udb-font-size-lg);
|
|
294
|
+
font-weight: var(--font-weight-bold);
|
|
295
|
+
color: var(--color-foreground);
|
|
296
|
+
font-variant-numeric: tabular-nums;
|
|
297
|
+
}
|
|
298
|
+
.udb-donut__label {
|
|
299
|
+
margin-top: 2px;
|
|
300
|
+
font-size: var(--udb-font-size-xs);
|
|
301
|
+
color: var(--color-muted-foreground);
|
|
302
|
+
}
|
|
303
|
+
.udb-donut__list {
|
|
304
|
+
display: flex;
|
|
305
|
+
min-width: 0;
|
|
306
|
+
flex: 1;
|
|
307
|
+
flex-direction: column;
|
|
308
|
+
gap: 6px;
|
|
309
|
+
}
|
|
310
|
+
.udb-donut__item {
|
|
311
|
+
display: flex;
|
|
312
|
+
align-items: center;
|
|
313
|
+
justify-content: space-between;
|
|
314
|
+
gap: 8px;
|
|
315
|
+
padding: 4px 6px;
|
|
316
|
+
border-radius: var(--radius-sm);
|
|
317
|
+
}
|
|
318
|
+
.udb-donut__item:hover {
|
|
319
|
+
background: var(--color-muted);
|
|
320
|
+
}
|
|
321
|
+
.udb-donut__itemlabel {
|
|
322
|
+
display: flex;
|
|
323
|
+
min-width: 0;
|
|
324
|
+
align-items: center;
|
|
325
|
+
gap: 8px;
|
|
326
|
+
font-size: var(--udb-font-size-sm);
|
|
327
|
+
color: var(--color-foreground);
|
|
328
|
+
}
|
|
329
|
+
.udb-donut__dot {
|
|
330
|
+
width: 8px;
|
|
331
|
+
height: 8px;
|
|
332
|
+
flex-shrink: 0;
|
|
333
|
+
border-radius: 3px;
|
|
334
|
+
}
|
|
335
|
+
.udb-donut__itemvalue {
|
|
336
|
+
flex-shrink: 0;
|
|
337
|
+
font-size: var(--udb-font-size-sm);
|
|
338
|
+
font-weight: var(--font-weight-medium);
|
|
339
|
+
color: var(--color-foreground);
|
|
340
|
+
font-variant-numeric: tabular-nums;
|
|
341
|
+
}
|
|
342
|
+
.udb-donut__pct {
|
|
343
|
+
margin-left: 6px;
|
|
344
|
+
color: var(--color-muted-foreground);
|
|
345
|
+
}
|
|
346
|
+
.udb-linechart {
|
|
347
|
+
position: relative;
|
|
348
|
+
width: 100%;
|
|
349
|
+
user-select: none;
|
|
350
|
+
}
|
|
351
|
+
.udb-linechart__svg {
|
|
352
|
+
display: block;
|
|
353
|
+
width: 100%;
|
|
354
|
+
}
|
|
355
|
+
.udb-linechart__axis {
|
|
356
|
+
fill: var(--color-muted-foreground);
|
|
357
|
+
font-size: var(--udb-font-size-xs);
|
|
358
|
+
font-family: var(--font-sans);
|
|
359
|
+
}
|
|
360
|
+
.udb-linechart__grid {
|
|
361
|
+
stroke: var(--color-border);
|
|
362
|
+
stroke-width: 1;
|
|
363
|
+
}
|
|
364
|
+
.udb-linechart__band {
|
|
365
|
+
fill: var(--color-primary);
|
|
366
|
+
opacity: 0.08;
|
|
367
|
+
}
|
|
368
|
+
.udb-linechart__crosshair {
|
|
369
|
+
stroke: var(--udb-border-strong);
|
|
370
|
+
stroke-width: 1;
|
|
371
|
+
stroke-dasharray: 3 3;
|
|
372
|
+
}
|
|
373
|
+
.udb-linechart__tip {
|
|
374
|
+
position: absolute;
|
|
375
|
+
top: 8px;
|
|
376
|
+
z-index: 10;
|
|
377
|
+
min-width: 132px;
|
|
378
|
+
padding: 8px;
|
|
379
|
+
pointer-events: none;
|
|
380
|
+
border: 1px solid var(--color-border);
|
|
381
|
+
border-radius: var(--radius-md);
|
|
382
|
+
background: var(--color-card);
|
|
383
|
+
box-shadow: var(--shadow-md);
|
|
384
|
+
}
|
|
385
|
+
.udb-linechart__tiptitle {
|
|
386
|
+
margin-bottom: 4px;
|
|
387
|
+
font-size: var(--udb-font-size-xs);
|
|
388
|
+
color: var(--color-muted-foreground);
|
|
389
|
+
}
|
|
390
|
+
.udb-linechart__tiprow {
|
|
391
|
+
display: flex;
|
|
392
|
+
align-items: center;
|
|
393
|
+
justify-content: space-between;
|
|
394
|
+
gap: 12px;
|
|
395
|
+
font-size: var(--udb-font-size-sm);
|
|
396
|
+
}
|
|
397
|
+
.udb-linechart__tiprow span {
|
|
398
|
+
display: flex;
|
|
399
|
+
align-items: center;
|
|
400
|
+
gap: 6px;
|
|
401
|
+
color: var(--color-muted-foreground);
|
|
402
|
+
}
|
|
403
|
+
.udb-linechart__tiprow b {
|
|
404
|
+
font-weight: var(--font-weight-medium);
|
|
405
|
+
color: var(--color-foreground);
|
|
406
|
+
font-variant-numeric: tabular-nums;
|
|
407
|
+
}
|
|
408
|
+
.udb-linechart__swatch {
|
|
409
|
+
display: inline-block;
|
|
410
|
+
width: 12px;
|
|
411
|
+
height: 3px;
|
|
412
|
+
border-radius: 999px;
|
|
413
|
+
}
|
|
414
|
+
.udb-linechart__legendhost {
|
|
415
|
+
margin-top: 4px;
|
|
416
|
+
padding: 0 8px;
|
|
417
|
+
}
|
|
418
|
+
.udb-heatmap {
|
|
419
|
+
display: grid;
|
|
420
|
+
grid-auto-flow: column;
|
|
421
|
+
grid-template-rows: repeat(7, minmax(0, 1fr));
|
|
422
|
+
gap: 4px;
|
|
423
|
+
}
|
|
424
|
+
.udb-heatmap__cell {
|
|
425
|
+
width: 14px;
|
|
426
|
+
height: 14px;
|
|
427
|
+
border-radius: 3px;
|
|
428
|
+
transition: background-color 150ms ease;
|
|
429
|
+
}
|
|
430
|
+
.udb-heatmap__cell--l0 {
|
|
431
|
+
background: color-mix(in oklab, var(--color-muted) 40%, transparent);
|
|
432
|
+
}
|
|
433
|
+
.udb-heatmap__cell--l1 {
|
|
434
|
+
background: color-mix(in oklab, var(--color-primary) 20%, var(--color-card));
|
|
435
|
+
}
|
|
436
|
+
.udb-heatmap__cell--l2 {
|
|
437
|
+
background: color-mix(in oklab, var(--color-primary) 40%, var(--color-card));
|
|
438
|
+
}
|
|
439
|
+
.udb-heatmap__cell--l3 {
|
|
440
|
+
background: color-mix(in oklab, var(--color-primary) 70%, var(--color-card));
|
|
441
|
+
}
|
|
442
|
+
.udb-heatmap__cell--l4 {
|
|
443
|
+
background: var(--color-primary);
|
|
444
|
+
}
|
|
445
|
+
.udb-heatmap__sr {
|
|
446
|
+
position: absolute;
|
|
447
|
+
width: 1px;
|
|
448
|
+
height: 1px;
|
|
449
|
+
padding: 0;
|
|
450
|
+
margin: -1px;
|
|
451
|
+
overflow: hidden;
|
|
452
|
+
clip: rect(0, 0, 0, 0);
|
|
453
|
+
white-space: nowrap;
|
|
454
|
+
border-width: 0;
|
|
455
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import { ActivityHeatmap } from "./ActivityHeatmap";
|
|
4
|
+
|
|
5
|
+
const cells = [
|
|
6
|
+
{ day: "2026-01-01", value: 0 },
|
|
7
|
+
{ day: "2026-01-02", value: 5 },
|
|
8
|
+
{ day: "2026-01-03", value: 10 },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
describe("ActivityHeatmap", () => {
|
|
12
|
+
it("levels cells by intensity against the peak", () => {
|
|
13
|
+
const { container } = render(<ActivityHeatmap cells={cells} max={10} />);
|
|
14
|
+
const cellEls = container.querySelectorAll(".udb-heatmap__cell");
|
|
15
|
+
expect(cellEls).toHaveLength(3);
|
|
16
|
+
expect(cellEls[0]!.className).toContain("udb-heatmap__cell--l0");
|
|
17
|
+
expect(cellEls[1]!.className).toContain("udb-heatmap__cell--l2");
|
|
18
|
+
expect(cellEls[2]!.className).toContain("udb-heatmap__cell--l4");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("exposes each cell title visually and for screen readers", () => {
|
|
22
|
+
const { container } = render(<ActivityHeatmap cells={cells} max={10} />);
|
|
23
|
+
expect(container.querySelector(".udb-heatmap__cell")!.getAttribute("title")).toBe(
|
|
24
|
+
"2026-01-01: 0",
|
|
25
|
+
);
|
|
26
|
+
expect(container.querySelector(".udb-heatmap__sr")!.textContent).toBe("2026-01-01: 0");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("keeps the levelClassNames escape hatch", () => {
|
|
30
|
+
const { container } = render(
|
|
31
|
+
<ActivityHeatmap
|
|
32
|
+
cells={cells}
|
|
33
|
+
max={10}
|
|
34
|
+
levelClassNames={["z0", "z1", "z2", "z3", "z4"]}
|
|
35
|
+
/>,
|
|
36
|
+
);
|
|
37
|
+
const cellEls = container.querySelectorAll(".udb-heatmap__cell");
|
|
38
|
+
expect(cellEls[0]!.className).toContain("z0");
|
|
39
|
+
expect(cellEls[0]!.className).not.toContain("udb-heatmap__cell--");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("derives the peak from the data when max is omitted", () => {
|
|
43
|
+
const { container } = render(<ActivityHeatmap cells={cells} />);
|
|
44
|
+
const cellEls = container.querySelectorAll(".udb-heatmap__cell");
|
|
45
|
+
expect(cellEls[1]!.className).toContain("udb-heatmap__cell--l2");
|
|
46
|
+
expect(cellEls[2]!.className).toContain("udb-heatmap__cell--l4");
|
|
47
|
+
});
|
|
48
|
+
});
|