@leonardaustin/ui 0.25.0 → 0.26.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 +11 -0
- package/dist/components/app-shell/AppShell.d.ts +3 -3
- package/dist/components/app-shell/AppShell.js +82 -0
- package/dist/components/app-shell/AuthLayout.d.ts +3 -3
- package/dist/components/app-shell/AuthLayout.js +16 -0
- package/dist/components/app-shell/BackLink.d.ts +3 -3
- package/dist/components/app-shell/BackLink.js +19 -0
- package/dist/components/app-shell/BottomNav.d.ts +3 -2
- package/dist/components/app-shell/BottomNav.js +37 -0
- package/dist/components/app-shell/Breadcrumbs.d.ts +3 -2
- package/dist/components/app-shell/Breadcrumbs.js +46 -0
- package/dist/components/app-shell/CommandPalette.d.ts +3 -2
- package/dist/components/app-shell/CommandPalette.js +119 -0
- package/dist/components/app-shell/MobileDrawer.d.ts +3 -3
- package/dist/components/app-shell/MobileDrawer.js +128 -0
- package/dist/components/app-shell/Sidebar.d.ts +3 -3
- package/dist/components/app-shell/Sidebar.js +355 -0
- package/dist/components/app-shell/ThemeMenu.d.ts +3 -2
- package/dist/components/app-shell/ThemeMenu.js +273 -0
- package/dist/components/app-shell/TopBar.d.ts +3 -3
- package/dist/components/app-shell/TopBar.js +129 -0
- package/dist/components/app-shell/commandPaletteEvents.js +16 -0
- package/dist/components/app-shell/navigation.js +21 -0
- package/dist/components/app-shell/themeMenuEvents.js +7 -0
- package/dist/components/charts/AreaChart.d.ts +4 -3
- package/dist/components/charts/AreaChart.js +217 -0
- package/dist/components/charts/BarChart.d.ts +4 -3
- package/dist/components/charts/BarChart.js +91 -0
- package/dist/components/charts/DonutChart.d.ts +4 -3
- package/dist/components/charts/DonutChart.js +172 -0
- package/dist/components/charts/RadarChart.d.ts +4 -3
- package/dist/components/charts/RadarChart.js +142 -0
- package/dist/components/charts/RadialBarChart.d.ts +4 -3
- package/dist/components/charts/RadialBarChart.js +219 -0
- package/dist/components/charts/SparkLine.d.ts +4 -3
- package/dist/components/charts/SparkLine.js +39 -0
- package/dist/components/charts/StackedBarChart.d.ts +4 -3
- package/dist/components/charts/StackedBarChart.js +249 -0
- package/dist/components/charts/VerticalBarChart.d.ts +4 -3
- package/dist/components/charts/VerticalBarChart.js +143 -0
- package/dist/components/charts/chartUtils.js +68 -0
- package/dist/components/tables/ColumnPicker.d.ts +3 -3
- package/dist/components/tables/ColumnPicker.js +59 -0
- package/dist/components/tables/Pagination.d.ts +3 -3
- package/dist/components/tables/Pagination.js +56 -0
- package/dist/components/tables/ResourceTable.d.ts +3 -3
- package/dist/components/tables/ResourceTable.js +88 -0
- package/dist/components/tables/Table.js +95 -0
- package/dist/components/tables/sortRows.js +11 -0
- package/dist/components/ui/Accordion.d.ts +2 -1
- package/dist/components/ui/Accordion.js +35 -0
- package/dist/components/ui/Alert.d.ts +3 -2
- package/dist/components/ui/Alert.js +51 -0
- package/dist/components/ui/AttachmentList.d.ts +5 -5
- package/dist/components/ui/AttachmentList.js +90 -0
- package/dist/components/ui/AudioPlayer.d.ts +5 -2
- package/dist/components/ui/AudioPlayer.js +447 -0
- package/dist/components/ui/AuthCard.d.ts +3 -3
- package/dist/components/ui/AuthCard.js +39 -0
- package/dist/components/ui/AuthorByline.d.ts +3 -3
- package/dist/components/ui/AuthorByline.js +23 -0
- package/dist/components/ui/Avatar.d.ts +3 -2
- package/dist/components/ui/Avatar.js +36 -0
- package/dist/components/ui/Badge.d.ts +3 -2
- package/dist/components/ui/Badge.js +47 -0
- package/dist/components/ui/Button.d.ts +3 -3
- package/dist/components/ui/Button.js +83 -0
- package/dist/components/ui/Calendar.d.ts +3 -3
- package/dist/components/ui/Calendar.js +344 -0
- package/dist/components/ui/CalendarGrid.d.ts +3 -2
- package/dist/components/ui/CalendarGrid.js +136 -0
- package/dist/components/ui/Card.d.ts +6 -5
- package/dist/components/ui/Card.js +53 -0
- package/dist/components/ui/CharacterCount.d.ts +3 -3
- package/dist/components/ui/CharacterCount.js +27 -0
- package/dist/components/ui/Checkbox.d.ts +10 -8
- package/dist/components/ui/Checkbox.js +52 -0
- package/dist/components/ui/CodeInput.d.ts +7 -4
- package/dist/components/ui/CodeInput.js +96 -0
- package/dist/components/ui/Combobox.d.ts +8 -6
- package/dist/components/ui/Combobox.js +213 -0
- package/dist/components/ui/CopyButton.d.ts +1 -1
- package/dist/components/ui/CopyButton.js +57 -0
- package/dist/components/ui/DangerZone.d.ts +3 -3
- package/dist/components/ui/DangerZone.js +23 -0
- package/dist/components/ui/DatePartsInput.d.ts +6 -4
- package/dist/components/ui/DatePartsInput.js +138 -0
- package/dist/components/ui/DatePicker.d.ts +9 -4
- package/dist/components/ui/DatePicker.js +84 -0
- package/dist/components/ui/DateRangePicker.d.ts +7 -4
- package/dist/components/ui/DateRangePicker.js +143 -0
- package/dist/components/ui/DateTimePicker.d.ts +7 -4
- package/dist/components/ui/DateTimePicker.js +267 -0
- package/dist/components/ui/DetailPanel.d.ts +3 -3
- package/dist/components/ui/DetailPanel.js +183 -0
- package/dist/components/ui/Dialog.d.ts +3 -3
- package/dist/components/ui/Dialog.js +411 -0
- package/dist/components/ui/DialogActions.d.ts +3 -3
- package/dist/components/ui/DialogActions.js +35 -0
- package/dist/components/ui/Disclosure.d.ts +3 -3
- package/dist/components/ui/Disclosure.js +45 -0
- package/dist/components/ui/DividerLabel.d.ts +3 -3
- package/dist/components/ui/DividerLabel.js +20 -0
- package/dist/components/ui/DropdownMenu.d.ts +3 -3
- package/dist/components/ui/DropdownMenu.js +229 -0
- package/dist/components/ui/EmptyState.d.ts +3 -3
- package/dist/components/ui/EmptyState.js +31 -0
- package/dist/components/ui/ErrorBoundary.js +46 -0
- package/dist/components/ui/FieldContext.js +8 -0
- package/dist/components/ui/Fieldset.d.ts +2 -2
- package/dist/components/ui/Fieldset.js +39 -0
- package/dist/components/ui/FilterButton.d.ts +4 -7
- package/dist/components/ui/FilterButton.js +17 -0
- package/dist/components/ui/FilterDropdown.d.ts +4 -4
- package/dist/components/ui/FilterDropdown.js +18 -0
- package/dist/components/ui/FormField.d.ts +4 -4
- package/dist/components/ui/FormField.js +68 -0
- package/dist/components/ui/Grid.d.ts +1 -1
- package/dist/components/ui/Grid.js +19 -0
- package/dist/components/ui/GridItem.d.ts +1 -1
- package/dist/components/ui/GridItem.js +16 -0
- package/dist/components/ui/Inline.d.ts +1 -1
- package/dist/components/ui/Inline.js +24 -0
- package/dist/components/ui/Kbd.d.ts +3 -2
- package/dist/components/ui/Kbd.js +13 -0
- package/dist/components/ui/ListItemLink.d.ts +3 -3
- package/dist/components/ui/ListItemLink.js +44 -0
- package/dist/components/ui/LoadingSpinner.d.ts +3 -2
- package/dist/components/ui/LoadingSpinner.js +19 -0
- package/dist/components/ui/MessageBubble.d.ts +2 -2
- package/dist/components/ui/MessageBubble.js +41 -0
- package/dist/components/ui/MetadataGrid.d.ts +5 -3
- package/dist/components/ui/MetadataGrid.js +76 -0
- package/dist/components/ui/MetricCard.d.ts +3 -3
- package/dist/components/ui/MetricCard.js +51 -0
- package/dist/components/ui/NavTabs.d.ts +2 -2
- package/dist/components/ui/NavTabs.js +29 -0
- package/dist/components/ui/OAuthButton.d.ts +2 -2
- package/dist/components/ui/OAuthButton.js +55 -0
- package/dist/components/ui/OverlineLabel.d.ts +3 -3
- package/dist/components/ui/OverlineLabel.js +13 -0
- package/dist/components/ui/PageHeader.d.ts +3 -3
- package/dist/components/ui/PageHeader.js +33 -0
- package/dist/components/ui/PageSection.d.ts +3 -3
- package/dist/components/ui/PageSection.js +31 -0
- package/dist/components/ui/PaginationBar.d.ts +3 -3
- package/dist/components/ui/PaginationBar.js +62 -0
- package/dist/components/ui/PasswordInput.d.ts +3 -3
- package/dist/components/ui/PasswordInput.js +62 -0
- package/dist/components/ui/PasswordRequirements.d.ts +3 -2
- package/dist/components/ui/PasswordRequirements.js +34 -0
- package/dist/components/ui/Popover.d.ts +3 -3
- package/dist/components/ui/Popover.js +53 -0
- package/dist/components/ui/ProfileHeader.d.ts +3 -3
- package/dist/components/ui/ProfileHeader.js +54 -0
- package/dist/components/ui/ProgressBar.d.ts +3 -3
- package/dist/components/ui/ProgressBar.js +42 -0
- package/dist/components/ui/ProseContent.d.ts +3 -3
- package/dist/components/ui/ProseContent.js +13 -0
- package/dist/components/ui/QrCode.d.ts +3 -3
- package/dist/components/ui/QrCode.js +47 -0
- package/dist/components/ui/Radio.d.ts +9 -6
- package/dist/components/ui/Radio.js +58 -0
- package/dist/components/ui/RadioPill.d.ts +7 -4
- package/dist/components/ui/RadioPill.js +53 -0
- package/dist/components/ui/ReorderList.d.ts +3 -3
- package/dist/components/ui/ReorderList.js +123 -0
- package/dist/components/ui/SearchInput.d.ts +7 -5
- package/dist/components/ui/SearchInput.js +49 -0
- package/dist/components/ui/SectionHeader.d.ts +3 -3
- package/dist/components/ui/SectionHeader.js +13 -0
- package/dist/components/ui/Select.d.ts +4 -4
- package/dist/components/ui/Select.js +117 -0
- package/dist/components/ui/SelectDropdown.d.ts +8 -3
- package/dist/components/ui/SelectDropdown.js +206 -0
- package/dist/components/ui/SettingRow.d.ts +5 -5
- package/dist/components/ui/SettingRow.js +25 -0
- package/dist/components/ui/SideSheet.d.ts +3 -3
- package/dist/components/ui/SideSheet.js +164 -0
- package/dist/components/ui/Skeleton.d.ts +3 -3
- package/dist/components/ui/Skeleton.js +18 -0
- package/dist/components/ui/Slider.d.ts +11 -6
- package/dist/components/ui/Slider.js +58 -0
- package/dist/components/ui/SplitPaneLayout.d.ts +5 -5
- package/dist/components/ui/SplitPaneLayout.js +22 -0
- package/dist/components/ui/Stack.d.ts +1 -1
- package/dist/components/ui/Stack.js +18 -0
- package/dist/components/ui/StatusDot.d.ts +3 -2
- package/dist/components/ui/StatusDot.js +24 -0
- package/dist/components/ui/StepProgress.d.ts +3 -2
- package/dist/components/ui/StepProgress.js +33 -0
- package/dist/components/ui/Tabs.d.ts +5 -5
- package/dist/components/ui/Tabs.js +63 -0
- package/dist/components/ui/TextInput.d.ts +3 -3
- package/dist/components/ui/TextInput.js +57 -0
- package/dist/components/ui/Textarea.d.ts +3 -3
- package/dist/components/ui/Textarea.js +59 -0
- package/dist/components/ui/ThemePreview.d.ts +3 -3
- package/dist/components/ui/ThemePreview.js +28 -0
- package/dist/components/ui/TimeInput.d.ts +7 -6
- package/dist/components/ui/TimeInput.js +22 -0
- package/dist/components/ui/Timeline.d.ts +3 -2
- package/dist/components/ui/Timeline.js +29 -0
- package/dist/components/ui/Toast.js +121 -0
- package/dist/components/ui/Toggle.d.ts +5 -3
- package/dist/components/ui/Toggle.js +34 -0
- package/dist/components/ui/Toolbar.d.ts +3 -3
- package/dist/components/ui/Toolbar.js +70 -0
- package/dist/components/ui/Tooltip.js +91 -0
- package/dist/components/ui/TranscriptLine.d.ts +3 -3
- package/dist/components/ui/TranscriptLine.js +40 -0
- package/dist/components/ui/UploadDropzone.d.ts +3 -5
- package/dist/components/ui/UploadDropzone.js +55 -0
- package/dist/components/ui/badgeColors.js +5 -0
- package/dist/components/ui/calendar/AgendaView.js +140 -0
- package/dist/components/ui/calendar/MonthView.js +321 -0
- package/dist/components/ui/calendar/TimeGrid.js +501 -0
- package/dist/components/ui/calendar/TimelineView.js +311 -0
- package/dist/components/ui/calendar/context.js +10 -0
- package/dist/components/ui/calendar/items.js +152 -0
- package/dist/components/ui/calendar/types.js +38 -0
- package/dist/components/ui/calendar/useGridInteraction.js +393 -0
- package/dist/components/ui/useFieldControl.d.ts +1 -1
- package/dist/components/ui/useFieldControl.js +17 -0
- package/dist/config/theme.js +219 -0
- package/dist/core.css +2933 -0
- package/dist/hooks/useAnchoredPopup.js +162 -0
- package/dist/hooks/useApplyTheme.js +16 -0
- package/dist/hooks/useControllableState.d.ts +14 -0
- package/dist/hooks/useControllableState.js +10 -0
- package/dist/hooks/useDismiss.js +24 -0
- package/dist/hooks/useFocusTrap.js +42 -0
- package/dist/hooks/useOverlayStack.js +23 -0
- package/dist/hooks/usePopover.js +47 -0
- package/dist/hooks/usePortalContainer.js +14 -0
- package/dist/hooks/useSettings.js +8 -0
- package/dist/hooks/useTheme.js +8 -0
- package/dist/hooks/useTypeahead.js +19 -0
- package/dist/index.js +133 -12884
- package/dist/lib/anchorPlacement.js +75 -0
- package/dist/lib/calendar.js +666 -0
- package/dist/lib/cn.js +228 -0
- package/dist/lib/codeInput.js +51 -0
- package/dist/lib/dateParts.js +31 -0
- package/dist/lib/dialogDrag.js +45 -0
- package/dist/lib/dialogResize.js +47 -0
- package/dist/lib/formatDate.js +29 -0
- package/dist/lib/formatMediaTime.js +7 -0
- package/dist/lib/layout.js +29 -0
- package/dist/lib/math.js +6 -0
- package/dist/lib/mergeRefs.d.ts +6 -0
- package/dist/lib/mergeRefs.js +17 -0
- package/dist/lib/months.js +30 -0
- package/dist/lib/overlayStack.js +47 -0
- package/dist/lib/panelResize.js +8 -0
- package/dist/lib/passwordRequirements.js +23 -0
- package/dist/lib/qrCode.js +570 -0
- package/dist/lib/tones.js +104 -0
- package/dist/lib/typeahead.js +31 -0
- package/dist/providers/ControlSizeContext.js +9 -0
- package/dist/providers/ControlSizeProvider.js +11 -0
- package/dist/providers/SettingsContext.js +53 -0
- package/dist/providers/SettingsProvider.js +249 -0
- package/dist/providers/ThemeContext.js +5 -0
- package/dist/providers/ThemeProvider.js +17 -0
- package/dist/providers/accentColors.js +75 -0
- package/dist/providers/themeClasses.d.ts +1 -0
- package/dist/providers/themeClasses.js +20 -0
- package/dist/styles.css +228 -176
- package/dist/themes/cyber-brutal-dark.css +53 -0
- package/dist/themes/cyber-brutal-light.css +75 -0
- package/dist/themes/glass-dark.css +217 -0
- package/dist/themes/glass-light.css +215 -0
- package/dist/themes/hashi.css +66 -0
- package/dist/themes/light-inverted.css +32 -0
- package/dist/themes/light.css +1 -0
- package/dist/themes/monokai.css +51 -0
- package/dist/themes/solarized.css +55 -0
- package/package.json +3 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { cn as e } from "../../lib/cn.js";
|
|
2
|
+
import { estimateTooltipWidth as t, getFloatingTooltipStyle as n, getPositiveValue as r, resolveChartColor as i } from "./chartUtils.js";
|
|
3
|
+
import { useState as a } from "react";
|
|
4
|
+
import { jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
5
|
+
//#region src/components/charts/DonutChart.tsx
|
|
6
|
+
function c(e, t) {
|
|
7
|
+
let n = e.reduce((e, t) => e + r(t.value), 0), i = 0;
|
|
8
|
+
return e.map((e) => {
|
|
9
|
+
let a = r(e.value), o = n > 0 ? a / n * t : 0, s = t - o, c = i / t * 360 - 90, l = c + o / t * 180, u = n > 0 ? a / n * 100 : 0;
|
|
10
|
+
return i += o, {
|
|
11
|
+
segment: e,
|
|
12
|
+
segmentLength: o,
|
|
13
|
+
dashOffset: s,
|
|
14
|
+
rotation: c,
|
|
15
|
+
midAngle: l,
|
|
16
|
+
percentage: u
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function l({ segments: l, size: u = 180, strokeWidth: d = 28, valueFormatter: f, percentageFormatter: p, showLegend: m = !0, "aria-label": h = "Donut chart", className: g, ref: _, ...v }) {
|
|
21
|
+
let [y, b] = a(null), x = l.reduce((e, t) => e + r(t.value), 0), S = Math.max(1, u), C = Math.max(1, Math.min(d, S - 1)), w = Math.max(.5, (S - C) / 2), T = c(l, 2 * Math.PI * w), E = f ?? ((e) => e.toLocaleString()), D = p ?? ((e) => `${e.toFixed(1)}%`), O = S + 12, k = O / 2;
|
|
22
|
+
return /* @__PURE__ */ s("div", {
|
|
23
|
+
ref: _,
|
|
24
|
+
...v,
|
|
25
|
+
className: e("flex flex-col items-center gap-4", g),
|
|
26
|
+
children: [/* @__PURE__ */ s("div", {
|
|
27
|
+
className: "relative",
|
|
28
|
+
children: [/* @__PURE__ */ s("svg", {
|
|
29
|
+
width: O,
|
|
30
|
+
height: O,
|
|
31
|
+
viewBox: `0 0 ${O} ${O}`,
|
|
32
|
+
className: "select-none",
|
|
33
|
+
onMouseLeave: () => b(null),
|
|
34
|
+
onPointerLeave: () => b(null),
|
|
35
|
+
role: "img",
|
|
36
|
+
"aria-label": h,
|
|
37
|
+
children: [
|
|
38
|
+
T.map((e, t) => /* @__PURE__ */ o("circle", {
|
|
39
|
+
cx: k,
|
|
40
|
+
cy: k,
|
|
41
|
+
r: w,
|
|
42
|
+
fill: "none",
|
|
43
|
+
stroke: "transparent",
|
|
44
|
+
strokeWidth: C + 12 + 8,
|
|
45
|
+
strokeDasharray: `${e.segmentLength} ${e.dashOffset}`,
|
|
46
|
+
strokeLinecap: "butt",
|
|
47
|
+
transform: `rotate(${e.rotation} ${k} ${k})`,
|
|
48
|
+
onMouseEnter: () => b(t),
|
|
49
|
+
onPointerEnter: () => b(t),
|
|
50
|
+
onPointerDown: () => b(t),
|
|
51
|
+
onFocus: () => b(t),
|
|
52
|
+
onBlur: () => b(null),
|
|
53
|
+
tabIndex: 0,
|
|
54
|
+
role: "button",
|
|
55
|
+
"aria-label": `${e.segment.name}: ${E(r(e.segment.value))} (${D(e.percentage)})`,
|
|
56
|
+
className: "cursor-pointer"
|
|
57
|
+
}, `hit-${e.segment.name}`)),
|
|
58
|
+
T.map((e, t) => {
|
|
59
|
+
let n = y === t, r = e.midAngle * Math.PI / 180, a = n ? Math.cos(r) * 6 : 0, s = n ? Math.sin(r) * 6 : 0;
|
|
60
|
+
return /* @__PURE__ */ o("circle", {
|
|
61
|
+
cx: k,
|
|
62
|
+
cy: k,
|
|
63
|
+
r: w,
|
|
64
|
+
fill: "none",
|
|
65
|
+
stroke: i(e.segment.color),
|
|
66
|
+
strokeWidth: n ? C + 4 : C,
|
|
67
|
+
strokeDasharray: `${e.segmentLength} ${e.dashOffset}`,
|
|
68
|
+
strokeLinecap: "butt",
|
|
69
|
+
transform: `translate(${a} ${s}) rotate(${e.rotation} ${k} ${k})`,
|
|
70
|
+
opacity: y !== null && !n ? .5 : 1,
|
|
71
|
+
style: { transition: "all 150ms ease-out" },
|
|
72
|
+
className: "pointer-events-none"
|
|
73
|
+
}, e.segment.name);
|
|
74
|
+
}),
|
|
75
|
+
/* @__PURE__ */ o("text", {
|
|
76
|
+
x: k,
|
|
77
|
+
y: k - 6,
|
|
78
|
+
textAnchor: "middle",
|
|
79
|
+
dominantBaseline: "central",
|
|
80
|
+
fill: "var(--text-primary)",
|
|
81
|
+
fontSize: 18,
|
|
82
|
+
fontWeight: 700,
|
|
83
|
+
className: "pointer-events-none",
|
|
84
|
+
children: E(y === null ? x : r(T[y].segment.value))
|
|
85
|
+
}),
|
|
86
|
+
/* @__PURE__ */ o("text", {
|
|
87
|
+
x: k,
|
|
88
|
+
y: k + 12,
|
|
89
|
+
textAnchor: "middle",
|
|
90
|
+
dominantBaseline: "central",
|
|
91
|
+
fill: "var(--text-tertiary)",
|
|
92
|
+
fontSize: 10,
|
|
93
|
+
className: "pointer-events-none",
|
|
94
|
+
children: y === null ? "Total" : T[y].segment.name
|
|
95
|
+
})
|
|
96
|
+
]
|
|
97
|
+
}), y !== null && (() => {
|
|
98
|
+
let e = T[y], a = e.midAngle * Math.PI / 180, c = w + C / 2 + 20, l = k + Math.cos(a) * c, u = k + Math.sin(a) * c, d = i(e.segment.color), f = E(r(e.segment.value)), p = D(e.percentage);
|
|
99
|
+
return /* @__PURE__ */ o("div", {
|
|
100
|
+
className: "ui-glass ui-glass-popover bg-bg-tertiary border-border pointer-events-none absolute z-10 rounded-md border px-2.5 py-1.5 shadow-lg",
|
|
101
|
+
style: n({
|
|
102
|
+
anchorX: l,
|
|
103
|
+
anchorY: u,
|
|
104
|
+
boundsHeight: O,
|
|
105
|
+
boundsWidth: O,
|
|
106
|
+
height: 30,
|
|
107
|
+
margin: 4,
|
|
108
|
+
offset: 8,
|
|
109
|
+
width: t([`${e.segment.name} ${f} ${p}`], {
|
|
110
|
+
maxWidth: 220,
|
|
111
|
+
minWidth: 112
|
|
112
|
+
})
|
|
113
|
+
}),
|
|
114
|
+
children: /* @__PURE__ */ s("div", {
|
|
115
|
+
className: "flex items-center gap-2",
|
|
116
|
+
children: [
|
|
117
|
+
/* @__PURE__ */ o("span", {
|
|
118
|
+
className: "h-2 w-2 shrink-0 rounded-full",
|
|
119
|
+
style: { backgroundColor: d }
|
|
120
|
+
}),
|
|
121
|
+
/* @__PURE__ */ o("span", {
|
|
122
|
+
className: "text-text-secondary text-xs whitespace-nowrap",
|
|
123
|
+
children: e.segment.name
|
|
124
|
+
}),
|
|
125
|
+
/* @__PURE__ */ o("span", {
|
|
126
|
+
className: "text-text-primary text-xs font-semibold",
|
|
127
|
+
children: f
|
|
128
|
+
}),
|
|
129
|
+
/* @__PURE__ */ s("span", {
|
|
130
|
+
className: "text-text-tertiary text-2xs",
|
|
131
|
+
children: [
|
|
132
|
+
"(",
|
|
133
|
+
p,
|
|
134
|
+
")"
|
|
135
|
+
]
|
|
136
|
+
})
|
|
137
|
+
]
|
|
138
|
+
})
|
|
139
|
+
});
|
|
140
|
+
})()]
|
|
141
|
+
}), m && /* @__PURE__ */ o("div", {
|
|
142
|
+
className: "relative z-0 flex flex-wrap justify-center gap-x-4 gap-y-1.5",
|
|
143
|
+
children: l.map((t, n) => /* @__PURE__ */ s("button", {
|
|
144
|
+
type: "button",
|
|
145
|
+
onMouseEnter: () => b(n),
|
|
146
|
+
onMouseLeave: () => b(null),
|
|
147
|
+
onPointerEnter: () => b(n),
|
|
148
|
+
onPointerDown: () => b(n),
|
|
149
|
+
onPointerLeave: () => b(null),
|
|
150
|
+
onFocus: () => b(n),
|
|
151
|
+
onBlur: () => b(null),
|
|
152
|
+
className: e("flex cursor-pointer items-center gap-1.5 transition-opacity duration-[100ms]", y !== null && y !== n && "opacity-50"),
|
|
153
|
+
children: [
|
|
154
|
+
/* @__PURE__ */ o("span", {
|
|
155
|
+
className: "h-2 w-2 rounded-full",
|
|
156
|
+
style: { backgroundColor: i(t.color) }
|
|
157
|
+
}),
|
|
158
|
+
/* @__PURE__ */ o("span", {
|
|
159
|
+
className: "text-text-secondary text-xs",
|
|
160
|
+
children: t.name
|
|
161
|
+
}),
|
|
162
|
+
/* @__PURE__ */ o("span", {
|
|
163
|
+
className: "text-text-primary text-xs font-semibold",
|
|
164
|
+
children: E(r(t.value))
|
|
165
|
+
})
|
|
166
|
+
]
|
|
167
|
+
}, t.name))
|
|
168
|
+
})]
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
export { l as DonutChart };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { type ComponentPropsWithRef } from "react";
|
|
1
2
|
export interface RadarDataPoint {
|
|
2
3
|
label: string;
|
|
3
4
|
value: number;
|
|
4
5
|
}
|
|
5
|
-
export interface RadarChartProps {
|
|
6
|
+
export interface RadarChartProps extends Omit<ComponentPropsWithRef<"div">, "children"> {
|
|
6
7
|
/** Axes of the radar, each with a `label` and numeric `value`, drawn clockwise from the top. */
|
|
7
8
|
data: RadarDataPoint[];
|
|
8
9
|
/** Max value for the scale. Defaults to auto from data. */
|
|
@@ -20,8 +21,8 @@ export interface RadarChartProps {
|
|
|
20
21
|
/** Format values shown on hover. Defaults to `String`. */
|
|
21
22
|
valueFormatter?: (value: number) => string;
|
|
22
23
|
/** Accessible label for the chart. Defaults to "Radar chart". */
|
|
23
|
-
|
|
24
|
+
"aria-label"?: string;
|
|
24
25
|
/** Extra classes for the wrapper element. */
|
|
25
26
|
className?: string;
|
|
26
27
|
}
|
|
27
|
-
export declare function RadarChart({ data, maxValue, size, rings, labelOffset, labelFormatter, maxLabelLength, valueFormatter, ariaLabel, className, }: RadarChartProps): import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
export declare function RadarChart({ data, maxValue, size, rings, labelOffset, labelFormatter, maxLabelLength, valueFormatter, "aria-label": ariaLabel, className, ref, ...rest }: RadarChartProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { cn as e } from "../../lib/cn.js";
|
|
2
|
+
import { clamp as t } from "../../lib/math.js";
|
|
3
|
+
import { getPositiveValue as n, truncateChartLabel as r } from "./chartUtils.js";
|
|
4
|
+
import { useState as i } from "react";
|
|
5
|
+
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
6
|
+
//#region src/components/charts/RadarChart.tsx
|
|
7
|
+
function s({ data: s, maxValue: c, size: l = 240, rings: u = 4, labelOffset: d = 18, labelFormatter: f, maxLabelLength: p, valueFormatter: m, "aria-label": h = "Radar chart", className: g, ref: _, ...v }) {
|
|
8
|
+
let [y, b] = i(null), x = Math.max(80, l), S = Math.max(n(c ?? 0), ...s.map((e) => n(e.value)), 1), C = x / 2, w = Math.max(1, C - Math.max(0, d) - 12), T = s.length > 0 ? 2 * Math.PI / s.length : 0, E = Math.max(1, Math.floor(u)), D = m ?? String, O = s.map((e, t) => {
|
|
9
|
+
let n = f?.(e.label, e, t) ?? e.label, i = r(n, p);
|
|
10
|
+
return {
|
|
11
|
+
displayLabel: i,
|
|
12
|
+
isTruncated: i !== n,
|
|
13
|
+
label: n
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
function k(e, t) {
|
|
17
|
+
return [C + t * Math.cos(e - Math.PI / 2), C + t * Math.sin(e - Math.PI / 2)];
|
|
18
|
+
}
|
|
19
|
+
let A = s.map((e, r) => {
|
|
20
|
+
let i = t(n(e.value), 0, S) / S * w;
|
|
21
|
+
return k(r * T, i);
|
|
22
|
+
}), j = A.map((e) => `${e[0]},${e[1]}`).join(" ");
|
|
23
|
+
return /* @__PURE__ */ o("div", {
|
|
24
|
+
ref: _,
|
|
25
|
+
...v,
|
|
26
|
+
className: e("relative flex flex-col items-center", g),
|
|
27
|
+
children: [/* @__PURE__ */ o("svg", {
|
|
28
|
+
width: x,
|
|
29
|
+
height: x,
|
|
30
|
+
viewBox: `0 0 ${x} ${x}`,
|
|
31
|
+
className: "select-none",
|
|
32
|
+
role: "img",
|
|
33
|
+
"aria-label": h,
|
|
34
|
+
children: [
|
|
35
|
+
s.length > 0 && Array.from({ length: E }, (e, t) => {
|
|
36
|
+
let n = (t + 1) / E * w;
|
|
37
|
+
return /* @__PURE__ */ a("polygon", {
|
|
38
|
+
points: s.map((e, t) => k(t * T, n)).map((e) => `${e[0]},${e[1]}`).join(" "),
|
|
39
|
+
fill: "none",
|
|
40
|
+
stroke: "var(--border)",
|
|
41
|
+
strokeWidth: 1,
|
|
42
|
+
opacity: .5
|
|
43
|
+
}, t);
|
|
44
|
+
}),
|
|
45
|
+
s.map((e, t) => {
|
|
46
|
+
let [n, r] = k(t * T, w);
|
|
47
|
+
return /* @__PURE__ */ a("line", {
|
|
48
|
+
x1: C,
|
|
49
|
+
y1: C,
|
|
50
|
+
x2: n,
|
|
51
|
+
y2: r,
|
|
52
|
+
stroke: "var(--border)",
|
|
53
|
+
strokeWidth: 1,
|
|
54
|
+
opacity: .3
|
|
55
|
+
}, t);
|
|
56
|
+
}),
|
|
57
|
+
s.length > 0 && /* @__PURE__ */ a("polygon", {
|
|
58
|
+
points: j,
|
|
59
|
+
fill: "var(--accent)",
|
|
60
|
+
fillOpacity: .15,
|
|
61
|
+
stroke: "var(--accent)",
|
|
62
|
+
strokeWidth: 2,
|
|
63
|
+
strokeLinejoin: "round"
|
|
64
|
+
}),
|
|
65
|
+
A.map((e, t) => {
|
|
66
|
+
let n = y === t, r = D(s[t].value);
|
|
67
|
+
return /* @__PURE__ */ a("circle", {
|
|
68
|
+
cx: e[0],
|
|
69
|
+
cy: e[1],
|
|
70
|
+
r: n ? 5 : 3,
|
|
71
|
+
fill: "var(--accent)",
|
|
72
|
+
stroke: "var(--bg-secondary)",
|
|
73
|
+
strokeWidth: 2,
|
|
74
|
+
onMouseEnter: () => b(t),
|
|
75
|
+
onMouseLeave: () => b(null),
|
|
76
|
+
onPointerEnter: () => b(t),
|
|
77
|
+
onPointerDown: () => b(t),
|
|
78
|
+
onPointerLeave: () => b(null),
|
|
79
|
+
onFocus: () => b(t),
|
|
80
|
+
onBlur: () => b(null),
|
|
81
|
+
tabIndex: 0,
|
|
82
|
+
role: "button",
|
|
83
|
+
"aria-label": `${O[t].label}: ${r}`,
|
|
84
|
+
className: "cursor-pointer",
|
|
85
|
+
style: { transition: "r 150ms" }
|
|
86
|
+
}, t);
|
|
87
|
+
}),
|
|
88
|
+
s.map((e, t) => {
|
|
89
|
+
let n = w + Math.max(0, d), [r, i] = k(t * T, n), s = O[t], c = Math.max(48, s.displayLabel.length * 6 + 12), l = D(e.value);
|
|
90
|
+
return /* @__PURE__ */ o("g", {
|
|
91
|
+
onMouseEnter: () => b(t),
|
|
92
|
+
onMouseLeave: () => b(null),
|
|
93
|
+
onPointerEnter: () => b(t),
|
|
94
|
+
onPointerDown: () => b(t),
|
|
95
|
+
onPointerLeave: () => b(null),
|
|
96
|
+
onFocus: () => b(t),
|
|
97
|
+
onBlur: () => b(null),
|
|
98
|
+
className: "cursor-pointer",
|
|
99
|
+
tabIndex: 0,
|
|
100
|
+
role: "button",
|
|
101
|
+
"aria-label": `${s.label}: ${l}`,
|
|
102
|
+
children: [/* @__PURE__ */ a("rect", {
|
|
103
|
+
x: r - c / 2,
|
|
104
|
+
y: i - 10,
|
|
105
|
+
width: c,
|
|
106
|
+
height: 20,
|
|
107
|
+
fill: "transparent"
|
|
108
|
+
}), /* @__PURE__ */ o("text", {
|
|
109
|
+
x: r,
|
|
110
|
+
y: i,
|
|
111
|
+
textAnchor: "middle",
|
|
112
|
+
dominantBaseline: "central",
|
|
113
|
+
fill: y === t ? "var(--text-primary)" : "var(--text-tertiary)",
|
|
114
|
+
fontSize: 10,
|
|
115
|
+
fontWeight: y === t ? 600 : 400,
|
|
116
|
+
style: { transition: "all 150ms" },
|
|
117
|
+
children: [s.isTruncated && /* @__PURE__ */ a("title", { children: s.label }), s.displayLabel]
|
|
118
|
+
})]
|
|
119
|
+
}, e.label);
|
|
120
|
+
})
|
|
121
|
+
]
|
|
122
|
+
}), y !== null && /* @__PURE__ */ a("div", {
|
|
123
|
+
className: "ui-glass ui-glass-popover bg-bg-tertiary border-border pointer-events-none absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 rounded-md border px-2.5 py-1.5 shadow-lg",
|
|
124
|
+
children: /* @__PURE__ */ o("div", {
|
|
125
|
+
className: "flex items-center gap-2",
|
|
126
|
+
children: [
|
|
127
|
+
/* @__PURE__ */ a("span", { className: "bg-accent h-2 w-2 shrink-0 rounded-full" }),
|
|
128
|
+
/* @__PURE__ */ a("span", {
|
|
129
|
+
className: e("text-text-secondary text-xs whitespace-nowrap"),
|
|
130
|
+
children: O[y].label
|
|
131
|
+
}),
|
|
132
|
+
/* @__PURE__ */ a("span", {
|
|
133
|
+
className: "text-text-primary text-xs font-semibold",
|
|
134
|
+
children: D(s[y].value)
|
|
135
|
+
})
|
|
136
|
+
]
|
|
137
|
+
})
|
|
138
|
+
})]
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
export { s as RadarChart };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { type ComponentPropsWithRef } from "react";
|
|
1
2
|
export interface RadialSegment {
|
|
2
3
|
label: string;
|
|
3
4
|
value: number;
|
|
4
5
|
max: number;
|
|
5
6
|
color: string;
|
|
6
7
|
}
|
|
7
|
-
export interface RadialBarChartProps {
|
|
8
|
+
export interface RadialBarChartProps extends Omit<ComponentPropsWithRef<"div">, "children"> {
|
|
8
9
|
/** Concentric rings drawn outside in; each has a `label`, `value`, `max` it is measured against, and `color`. */
|
|
9
10
|
segments: RadialSegment[];
|
|
10
11
|
/** Width and height of the chart in px. Defaults to 200. */
|
|
@@ -20,8 +21,8 @@ export interface RadialBarChartProps {
|
|
|
20
21
|
/** Show the legend with each ring's percentage below the chart. Defaults to `true`. */
|
|
21
22
|
showLegend?: boolean;
|
|
22
23
|
/** Accessible label for the chart. Defaults to "Radial bar chart". */
|
|
23
|
-
|
|
24
|
+
"aria-label"?: string;
|
|
24
25
|
/** Extra classes for the wrapper element. */
|
|
25
26
|
className?: string;
|
|
26
27
|
}
|
|
27
|
-
export declare function RadialBarChart({ segments, size, strokeWidth, gap, valueFormatter, percentageFormatter, showLegend, ariaLabel, className, }: RadialBarChartProps): import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
export declare function RadialBarChart({ segments, size, strokeWidth, gap, valueFormatter, percentageFormatter, showLegend, "aria-label": ariaLabel, className, ref, ...rest }: RadialBarChartProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { cn as e } from "../../lib/cn.js";
|
|
2
|
+
import { clamp as t } from "../../lib/math.js";
|
|
3
|
+
import { estimateTooltipWidth as n, getFloatingTooltipStyle as r, getPositiveValue as i, resolveChartColor as a } from "./chartUtils.js";
|
|
4
|
+
import { useRef as o, useState as s } from "react";
|
|
5
|
+
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
6
|
+
//#region src/components/charts/RadialBarChart.tsx
|
|
7
|
+
function u({ segments: u, size: d = 200, strokeWidth: f = 14, gap: p = 6, valueFormatter: m, percentageFormatter: h, showLegend: g = !0, "aria-label": _ = "Radial bar chart", className: v, ref: y, ...b }) {
|
|
8
|
+
let [x, S] = s(null), [C, w] = s({
|
|
9
|
+
x: 0,
|
|
10
|
+
y: 0
|
|
11
|
+
}), T = o(null), E = x?.index ?? null, D = Math.max(1, d), O = Math.max(1, Math.min(f, D)), k = Math.max(0, p), A = D / 2, j = Math.max(0, (D - 40) / 2), M = m ?? String, N = h ?? ((e) => `${Math.round(e)}%`), P = u.reduce((e, t, n) => j - n * (O + k) > 0 ? n : e, -1);
|
|
12
|
+
function F(e) {
|
|
13
|
+
let t = T.current?.getBoundingClientRect();
|
|
14
|
+
t && w({
|
|
15
|
+
x: e.clientX - t.left,
|
|
16
|
+
y: e.clientY - t.top
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function I(e) {
|
|
20
|
+
w({
|
|
21
|
+
x: A,
|
|
22
|
+
y: A
|
|
23
|
+
}), S({
|
|
24
|
+
index: e,
|
|
25
|
+
source: "chart"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function L(e) {
|
|
29
|
+
let n = i(e.max);
|
|
30
|
+
return n <= 0 ? 0 : t(i(e.value) / n, 0, 1);
|
|
31
|
+
}
|
|
32
|
+
function R(e) {
|
|
33
|
+
return L(e) * 100;
|
|
34
|
+
}
|
|
35
|
+
return /* @__PURE__ */ l("div", {
|
|
36
|
+
ref: y,
|
|
37
|
+
...b,
|
|
38
|
+
className: e("flex flex-col items-center gap-4", v),
|
|
39
|
+
children: [/* @__PURE__ */ l("div", {
|
|
40
|
+
className: "relative",
|
|
41
|
+
ref: T,
|
|
42
|
+
onPointerMove: F,
|
|
43
|
+
children: [/* @__PURE__ */ l("svg", {
|
|
44
|
+
width: D,
|
|
45
|
+
height: D,
|
|
46
|
+
viewBox: `0 0 ${D} ${D}`,
|
|
47
|
+
className: "select-none",
|
|
48
|
+
role: "img",
|
|
49
|
+
"aria-label": _,
|
|
50
|
+
children: [u.map((e, t) => {
|
|
51
|
+
let n = j - t * (O + k);
|
|
52
|
+
if (n <= 0) return null;
|
|
53
|
+
let r = 2 * Math.PI * n, i = r * L(e), o = r - i, s = a(e.color), u = E === t, d = R(e);
|
|
54
|
+
return /* @__PURE__ */ l("g", {
|
|
55
|
+
onMouseEnter: () => S({
|
|
56
|
+
index: t,
|
|
57
|
+
source: "chart"
|
|
58
|
+
}),
|
|
59
|
+
onMouseLeave: () => S(null),
|
|
60
|
+
onPointerEnter: () => S({
|
|
61
|
+
index: t,
|
|
62
|
+
source: "chart"
|
|
63
|
+
}),
|
|
64
|
+
onPointerDown: () => S({
|
|
65
|
+
index: t,
|
|
66
|
+
source: "chart"
|
|
67
|
+
}),
|
|
68
|
+
onPointerLeave: () => S(null),
|
|
69
|
+
onFocus: () => I(t),
|
|
70
|
+
onBlur: () => S(null),
|
|
71
|
+
className: "cursor-pointer",
|
|
72
|
+
tabIndex: 0,
|
|
73
|
+
role: "button",
|
|
74
|
+
"aria-label": `${e.label}: ${N(d)} (${M(e.value)}/${M(e.max)})`,
|
|
75
|
+
children: [/* @__PURE__ */ c("circle", {
|
|
76
|
+
cx: A,
|
|
77
|
+
cy: A,
|
|
78
|
+
r: n,
|
|
79
|
+
fill: "none",
|
|
80
|
+
stroke: "var(--border)",
|
|
81
|
+
strokeWidth: O,
|
|
82
|
+
opacity: .3
|
|
83
|
+
}), /* @__PURE__ */ c("circle", {
|
|
84
|
+
cx: A,
|
|
85
|
+
cy: A,
|
|
86
|
+
r: n,
|
|
87
|
+
fill: "none",
|
|
88
|
+
stroke: s,
|
|
89
|
+
strokeWidth: u ? O + 4 : O,
|
|
90
|
+
strokeDasharray: `${i} ${o}`,
|
|
91
|
+
strokeLinecap: "round",
|
|
92
|
+
transform: `rotate(-90 ${A} ${A})`,
|
|
93
|
+
opacity: E !== null && !u ? .4 : 1,
|
|
94
|
+
className: "pointer-events-none",
|
|
95
|
+
style: { transition: "all 150ms ease-out" }
|
|
96
|
+
})]
|
|
97
|
+
}, e.label);
|
|
98
|
+
}), P >= 0 && (() => {
|
|
99
|
+
let e = j - P * (O + k) - O / 2;
|
|
100
|
+
return /* @__PURE__ */ c("circle", {
|
|
101
|
+
cx: A,
|
|
102
|
+
cy: A,
|
|
103
|
+
r: Math.max(0, e),
|
|
104
|
+
fill: "transparent",
|
|
105
|
+
onMouseEnter: () => S({
|
|
106
|
+
index: P,
|
|
107
|
+
source: "chart"
|
|
108
|
+
}),
|
|
109
|
+
onMouseLeave: () => S(null),
|
|
110
|
+
onPointerEnter: () => S({
|
|
111
|
+
index: P,
|
|
112
|
+
source: "chart"
|
|
113
|
+
}),
|
|
114
|
+
onPointerDown: () => S({
|
|
115
|
+
index: P,
|
|
116
|
+
source: "chart"
|
|
117
|
+
}),
|
|
118
|
+
onPointerLeave: () => S(null),
|
|
119
|
+
onFocus: () => I(P),
|
|
120
|
+
onBlur: () => S(null),
|
|
121
|
+
tabIndex: 0,
|
|
122
|
+
role: "button",
|
|
123
|
+
"aria-label": `${u[P].label}: ${N(R(u[P]))}`,
|
|
124
|
+
className: "cursor-pointer"
|
|
125
|
+
});
|
|
126
|
+
})()]
|
|
127
|
+
}), E !== null && x?.source === "chart" && (() => {
|
|
128
|
+
let e = u[E];
|
|
129
|
+
if (!e) return null;
|
|
130
|
+
let t = R(e), i = a(e.color), o = N(t), s = `${M(e.value)}/${M(e.max)}`;
|
|
131
|
+
return /* @__PURE__ */ c("div", {
|
|
132
|
+
className: "ui-glass ui-glass-popover bg-bg-tertiary border-border pointer-events-none absolute z-10 rounded-md border px-2.5 py-1.5 shadow-lg",
|
|
133
|
+
style: r({
|
|
134
|
+
anchorX: C.x,
|
|
135
|
+
anchorY: C.y,
|
|
136
|
+
boundsHeight: D,
|
|
137
|
+
boundsWidth: D,
|
|
138
|
+
height: 30,
|
|
139
|
+
margin: 4,
|
|
140
|
+
offset: 8,
|
|
141
|
+
width: n([`${e.label} ${o} ${s}`], {
|
|
142
|
+
maxWidth: 220,
|
|
143
|
+
minWidth: 112
|
|
144
|
+
})
|
|
145
|
+
}),
|
|
146
|
+
children: /* @__PURE__ */ l("div", {
|
|
147
|
+
className: "flex items-center gap-2",
|
|
148
|
+
children: [
|
|
149
|
+
/* @__PURE__ */ c("span", {
|
|
150
|
+
className: "h-2 w-2 shrink-0 rounded-full",
|
|
151
|
+
style: { backgroundColor: i }
|
|
152
|
+
}),
|
|
153
|
+
/* @__PURE__ */ c("span", {
|
|
154
|
+
className: "text-text-secondary text-xs whitespace-nowrap",
|
|
155
|
+
children: e.label
|
|
156
|
+
}),
|
|
157
|
+
/* @__PURE__ */ c("span", {
|
|
158
|
+
className: "text-text-primary text-xs font-semibold",
|
|
159
|
+
children: o
|
|
160
|
+
}),
|
|
161
|
+
/* @__PURE__ */ l("span", {
|
|
162
|
+
className: "text-text-tertiary text-2xs",
|
|
163
|
+
children: [
|
|
164
|
+
"(",
|
|
165
|
+
s,
|
|
166
|
+
")"
|
|
167
|
+
]
|
|
168
|
+
})
|
|
169
|
+
]
|
|
170
|
+
})
|
|
171
|
+
});
|
|
172
|
+
})()]
|
|
173
|
+
}), g && /* @__PURE__ */ c("div", {
|
|
174
|
+
className: "flex flex-wrap justify-center gap-x-4 gap-y-1.5",
|
|
175
|
+
children: u.map((t, n) => {
|
|
176
|
+
let r = R(t);
|
|
177
|
+
return /* @__PURE__ */ l("button", {
|
|
178
|
+
type: "button",
|
|
179
|
+
onMouseEnter: () => S({
|
|
180
|
+
index: n,
|
|
181
|
+
source: "legend"
|
|
182
|
+
}),
|
|
183
|
+
onMouseLeave: () => S(null),
|
|
184
|
+
onPointerEnter: () => S({
|
|
185
|
+
index: n,
|
|
186
|
+
source: "legend"
|
|
187
|
+
}),
|
|
188
|
+
onPointerDown: () => S({
|
|
189
|
+
index: n,
|
|
190
|
+
source: "legend"
|
|
191
|
+
}),
|
|
192
|
+
onPointerLeave: () => S(null),
|
|
193
|
+
onFocus: () => S({
|
|
194
|
+
index: n,
|
|
195
|
+
source: "legend"
|
|
196
|
+
}),
|
|
197
|
+
onBlur: () => S(null),
|
|
198
|
+
className: e("flex cursor-pointer items-center gap-1.5 transition-opacity duration-[100ms]", E !== null && E !== n && "opacity-50"),
|
|
199
|
+
children: [
|
|
200
|
+
/* @__PURE__ */ c("span", {
|
|
201
|
+
className: "h-2 w-2 rounded-full",
|
|
202
|
+
style: { backgroundColor: a(t.color) }
|
|
203
|
+
}),
|
|
204
|
+
/* @__PURE__ */ c("span", {
|
|
205
|
+
className: "text-text-secondary text-xs",
|
|
206
|
+
children: t.label
|
|
207
|
+
}),
|
|
208
|
+
/* @__PURE__ */ c("span", {
|
|
209
|
+
className: "text-text-primary text-xs font-semibold",
|
|
210
|
+
children: N(r)
|
|
211
|
+
})
|
|
212
|
+
]
|
|
213
|
+
}, t.label);
|
|
214
|
+
})
|
|
215
|
+
})]
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
//#endregion
|
|
219
|
+
export { u as RadialBarChart };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ComponentPropsWithRef } from "react";
|
|
2
|
+
export interface SparkLineProps extends Omit<ComponentPropsWithRef<"svg">, "children" | "viewBox"> {
|
|
2
3
|
/** Values to plot left to right. Renders nothing with fewer than two points. */
|
|
3
4
|
data: number[];
|
|
4
5
|
/** Width in px. Defaults to 60. */
|
|
@@ -27,8 +28,8 @@ export interface SparkLineProps {
|
|
|
27
28
|
/** Opacity of the area fill when `area` is on. Defaults to 0.15. */
|
|
28
29
|
areaOpacity?: number;
|
|
29
30
|
/** Accessible label for the chart. Defaults to "Sparkline chart". */
|
|
30
|
-
|
|
31
|
+
"aria-label"?: string;
|
|
31
32
|
/** Extra classes for the `<svg>`. */
|
|
32
33
|
className?: string;
|
|
33
34
|
}
|
|
34
|
-
export declare function SparkLine({ data, width, height, minValue, maxValue, strokeWidth, padding, color, area, areaOpacity, ariaLabel, className, }: SparkLineProps): import("react/jsx-runtime").JSX.Element | null;
|
|
35
|
+
export declare function SparkLine({ data, width, height, minValue, maxValue, strokeWidth, padding, color, area, areaOpacity, "aria-label": ariaLabel, className, ref, ...rest }: SparkLineProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { cn as e } from "../../lib/cn.js";
|
|
2
|
+
import { clamp as t } from "../../lib/math.js";
|
|
3
|
+
import { jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
4
|
+
//#region src/components/charts/SparkLine.tsx
|
|
5
|
+
function i({ data: i, width: a = 60, height: o = 20, minValue: s, maxValue: c, strokeWidth: l = 1.5, padding: u = 1, color: d = "var(--accent)", area: f = !1, areaOpacity: p = .15, "aria-label": m = "Sparkline chart", className: h, ref: g, ..._ }) {
|
|
6
|
+
if (i.length < 2) return null;
|
|
7
|
+
let v = Math.max(1, a), y = Math.max(1, o), b = Math.max(0, Math.min(u, y / 2, v / 2)), x = s ?? Math.min(...i), S = c ?? Math.max(...i), C = Math.min(x, S), w = Math.max(x, S), T = w - C, E = Math.max(1, v - b * 2), D = Math.max(1, y - b * 2), O = i.map((e, n) => ({
|
|
8
|
+
x: b + n / (i.length - 1) * E,
|
|
9
|
+
y: T === 0 ? y / 2 : b + D - (t(e, C, w) - C) / T * D
|
|
10
|
+
})), k = O.map(({ x: e, y: t }) => `${e},${t}`).join(" "), A = O.length > 0 ? [
|
|
11
|
+
`${O[0].x},${y - b}`,
|
|
12
|
+
...O.map(({ x: e, y: t }) => `${e},${t}`),
|
|
13
|
+
`${O[O.length - 1].x},${y - b}`
|
|
14
|
+
].join(" ") : "";
|
|
15
|
+
return /* @__PURE__ */ r("svg", {
|
|
16
|
+
ref: g,
|
|
17
|
+
..._,
|
|
18
|
+
width: v,
|
|
19
|
+
height: y,
|
|
20
|
+
viewBox: `0 0 ${v} ${y}`,
|
|
21
|
+
className: e("inline-block", h),
|
|
22
|
+
role: "img",
|
|
23
|
+
"aria-label": m,
|
|
24
|
+
children: [f && /* @__PURE__ */ n("polygon", {
|
|
25
|
+
points: A,
|
|
26
|
+
fill: d,
|
|
27
|
+
opacity: p
|
|
28
|
+
}), /* @__PURE__ */ n("polyline", {
|
|
29
|
+
points: k,
|
|
30
|
+
fill: "none",
|
|
31
|
+
stroke: d,
|
|
32
|
+
strokeWidth: l,
|
|
33
|
+
strokeLinecap: "round",
|
|
34
|
+
strokeLinejoin: "round"
|
|
35
|
+
})]
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { i as SparkLine };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ComponentPropsWithRef } from "react";
|
|
1
2
|
export interface StackedBarChartDatum {
|
|
2
3
|
date: string;
|
|
3
4
|
[key: string]: number | string;
|
|
@@ -13,7 +14,7 @@ export interface StackedBarChartTooltipRow {
|
|
|
13
14
|
label: string;
|
|
14
15
|
value: number;
|
|
15
16
|
}
|
|
16
|
-
export interface StackedBarChartProps {
|
|
17
|
+
export interface StackedBarChartProps extends Omit<ComponentPropsWithRef<"svg">, "children" | "viewBox" | "width"> {
|
|
17
18
|
/** One entry per bar, with a `date` label and a numeric value for each segment `key`. */
|
|
18
19
|
data: StackedBarChartDatum[];
|
|
19
20
|
/** Stack layers in order; each maps a `key` in `data` to a `label`, `color`, and optional `opacity`. */
|
|
@@ -21,7 +22,7 @@ export interface StackedBarChartProps {
|
|
|
21
22
|
/** Chart height in SVG units; the width scales to the container. Defaults to 220. */
|
|
22
23
|
height?: number;
|
|
23
24
|
/** Accessible label for the chart. Defaults to "Stacked bar chart". */
|
|
24
|
-
|
|
25
|
+
"aria-label"?: string;
|
|
25
26
|
/** Build custom hover tooltip rows for a bar. Defaults to one row per segment. */
|
|
26
27
|
tooltipRows?: (item: StackedBarChartDatum) => StackedBarChartTooltipRow[];
|
|
27
28
|
/** Format Y-axis labels. Defaults to compact `k`/`M` formatting. */
|
|
@@ -37,4 +38,4 @@ export interface StackedBarChartProps {
|
|
|
37
38
|
/** Extra classes for the `<svg>`. */
|
|
38
39
|
className?: string;
|
|
39
40
|
}
|
|
40
|
-
export declare function StackedBarChart({ data, segments, height, ariaLabel, tooltipRows, valueFormatter, tooltipValueFormatter, xLabelCount, barGap, minBarWidth, className, }: StackedBarChartProps): import("react/jsx-runtime").JSX.Element;
|
|
41
|
+
export declare function StackedBarChart({ data, segments, height, "aria-label": ariaLabel, tooltipRows, valueFormatter, tooltipValueFormatter, xLabelCount, barGap, minBarWidth, className, ref, ...rest }: StackedBarChartProps): import("react/jsx-runtime").JSX.Element;
|