@misoto22/design 0.3.1 → 0.6.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 +124 -0
- package/bin/misoto22-design.mjs +205 -0
- package/dist/agent/Accordion.md +41 -0
- package/dist/agent/Alert.md +42 -0
- package/dist/agent/AppShell.md +40 -0
- package/dist/agent/AreaChart.md +68 -0
- package/dist/agent/Article.md +41 -0
- package/dist/agent/Avatar.md +32 -0
- package/dist/agent/Badge.md +40 -0
- package/dist/agent/BarChart.md +65 -0
- package/dist/agent/BarList.md +40 -0
- package/dist/agent/BigNumber.md +45 -0
- package/dist/agent/BoxPlot.md +58 -0
- package/dist/agent/Breadcrumb.md +32 -0
- package/dist/agent/BulletChart.md +48 -0
- package/dist/agent/Button.md +56 -0
- package/dist/agent/Calendar.md +42 -0
- package/dist/agent/Card.md +49 -0
- package/dist/agent/Checkbox.md +35 -0
- package/dist/agent/Collapsible.md +46 -0
- package/dist/agent/Combobox.md +50 -0
- package/dist/agent/Command.md +93 -0
- package/dist/agent/ComposedChart.md +57 -0
- package/dist/agent/ContextMenu.md +59 -0
- package/dist/agent/DatePicker.md +75 -0
- package/dist/agent/Diagram.md +46 -0
- package/dist/agent/Dialog.md +52 -0
- package/dist/agent/DropdownMenu.md +70 -0
- package/dist/agent/EmptyState.md +37 -0
- package/dist/agent/ErrorState.md +41 -0
- package/dist/agent/Facet.md +82 -0
- package/dist/agent/Field.md +37 -0
- package/dist/agent/FigureBand.md +37 -0
- package/dist/agent/FloatingIconButton.md +38 -0
- package/dist/agent/FunnelChart.md +52 -0
- package/dist/agent/Heatmap.md +53 -0
- package/dist/agent/Histogram.md +63 -0
- package/dist/agent/Input.md +30 -0
- package/dist/agent/Kbd.md +29 -0
- package/dist/agent/LineChart.md +60 -0
- package/dist/agent/LinkArrow.md +29 -0
- package/dist/agent/NativeSelect.md +40 -0
- package/dist/agent/NavItem.md +35 -0
- package/dist/agent/Pagination.md +43 -0
- package/dist/agent/PieChart.md +55 -0
- package/dist/agent/Popover.md +57 -0
- package/dist/agent/Progress.md +33 -0
- package/dist/agent/RadarChart.md +54 -0
- package/dist/agent/RadialChart.md +57 -0
- package/dist/agent/RadioGroup.md +44 -0
- package/dist/agent/SankeyChart.md +61 -0
- package/dist/agent/ScatterChart.md +54 -0
- package/dist/agent/ScrollArea.md +40 -0
- package/dist/agent/SearchableMenu.md +46 -0
- package/dist/agent/Select.md +75 -0
- package/dist/agent/Separator.md +35 -0
- package/dist/agent/Sheet.md +57 -0
- package/dist/agent/Skeleton.md +73 -0
- package/dist/agent/Slider.md +39 -0
- package/dist/agent/Sparkline.md +45 -0
- package/dist/agent/Spinner.md +39 -0
- package/dist/agent/StatusDot.md +36 -0
- package/dist/agent/StatusPill.md +28 -0
- package/dist/agent/Steps.md +44 -0
- package/dist/agent/Switch.md +29 -0
- package/dist/agent/Table.md +85 -0
- package/dist/agent/Tabs.md +48 -0
- package/dist/agent/Tag.md +35 -0
- package/dist/agent/Textarea.md +26 -0
- package/dist/agent/Toast.md +26 -0
- package/dist/agent/ToggleGroup.md +44 -0
- package/dist/agent/Tooltip.md +51 -0
- package/dist/agent/TreemapChart.md +52 -0
- package/dist/agent/WaterfallChart.md +62 -0
- package/dist/agent/catalog.json +1791 -0
- package/dist/agent/index.md +131 -0
- package/dist/article.css +393 -0
- package/dist/charts/AreaChart/AreaChart.d.ts +191 -0
- package/dist/charts/AreaChart/AreaChart.js +480 -0
- package/dist/charts/AreaChart/AreaChart.js.map +1 -0
- package/dist/charts/BarChart/BarChart.d.ts +179 -0
- package/dist/charts/BarChart/BarChart.js +591 -0
- package/dist/charts/BarChart/BarChart.js.map +1 -0
- package/dist/charts/BarList/BarList.d.ts +57 -0
- package/dist/charts/BarList/BarList.js +71 -0
- package/dist/charts/BarList/BarList.js.map +1 -0
- package/dist/charts/BigNumber/BigNumber.d.ts +56 -0
- package/dist/charts/BigNumber/BigNumber.js +31 -0
- package/dist/charts/BigNumber/BigNumber.js.map +1 -0
- package/dist/charts/BoxPlot/BoxPlot.d.ts +177 -0
- package/dist/charts/BoxPlot/BoxPlot.js +495 -0
- package/dist/charts/BoxPlot/BoxPlot.js.map +1 -0
- package/dist/charts/BulletChart/BulletChart.d.ts +100 -0
- package/dist/charts/BulletChart/BulletChart.js +162 -0
- package/dist/charts/BulletChart/BulletChart.js.map +1 -0
- package/dist/charts/ComposedChart/ComposedChart.d.ts +171 -0
- package/dist/charts/ComposedChart/ComposedChart.js +667 -0
- package/dist/charts/ComposedChart/ComposedChart.js.map +1 -0
- package/dist/charts/Facet/Facet.d.ts +240 -0
- package/dist/charts/Facet/Facet.js +133 -0
- package/dist/charts/Facet/Facet.js.map +1 -0
- package/dist/charts/Facet/panels.d.ts +187 -0
- package/dist/charts/Facet/panels.js +203 -0
- package/dist/charts/Facet/panels.js.map +1 -0
- package/dist/charts/FunnelChart/FunnelChart.d.ts +101 -0
- package/dist/charts/FunnelChart/FunnelChart.js +147 -0
- package/dist/charts/FunnelChart/FunnelChart.js.map +1 -0
- package/dist/charts/Heatmap/Heatmap.d.ts +78 -0
- package/dist/charts/Heatmap/Heatmap.js +108 -0
- package/dist/charts/Heatmap/Heatmap.js.map +1 -0
- package/dist/charts/Histogram/Histogram.d.ts +165 -0
- package/dist/charts/Histogram/Histogram.js +350 -0
- package/dist/charts/Histogram/Histogram.js.map +1 -0
- package/dist/charts/LineChart/LineChart.d.ts +167 -0
- package/dist/charts/LineChart/LineChart.js +486 -0
- package/dist/charts/LineChart/LineChart.js.map +1 -0
- package/dist/charts/PieChart/PieChart.d.ts +128 -0
- package/dist/charts/PieChart/PieChart.js +309 -0
- package/dist/charts/PieChart/PieChart.js.map +1 -0
- package/dist/charts/RadarChart/RadarChart.d.ts +123 -0
- package/dist/charts/RadarChart/RadarChart.js +299 -0
- package/dist/charts/RadarChart/RadarChart.js.map +1 -0
- package/dist/charts/RadialChart/RadialChart.d.ts +124 -0
- package/dist/charts/RadialChart/RadialChart.js +257 -0
- package/dist/charts/RadialChart/RadialChart.js.map +1 -0
- package/dist/charts/SankeyChart/SankeyChart.d.ts +137 -0
- package/dist/charts/SankeyChart/SankeyChart.js +501 -0
- package/dist/charts/SankeyChart/SankeyChart.js.map +1 -0
- package/dist/charts/ScatterChart/ScatterChart.d.ts +128 -0
- package/dist/charts/ScatterChart/ScatterChart.js +269 -0
- package/dist/charts/ScatterChart/ScatterChart.js.map +1 -0
- package/dist/charts/Sparkline/Sparkline.d.ts +53 -0
- package/dist/charts/Sparkline/Sparkline.js +93 -0
- package/dist/charts/Sparkline/Sparkline.js.map +1 -0
- package/dist/charts/TreemapChart/TreemapChart.d.ts +93 -0
- package/dist/charts/TreemapChart/TreemapChart.js +118 -0
- package/dist/charts/TreemapChart/TreemapChart.js.map +1 -0
- package/dist/charts/WaterfallChart/WaterfallChart.d.ts +164 -0
- package/dist/charts/WaterfallChart/WaterfallChart.js +319 -0
- package/dist/charts/WaterfallChart/WaterfallChart.js.map +1 -0
- package/dist/charts/index.d.ts +41 -0
- package/dist/charts/index.js +128 -0
- package/dist/charts/index.js.map +1 -0
- package/dist/charts/lib/annotations.d.ts +103 -0
- package/dist/charts/lib/annotations.js +99 -0
- package/dist/charts/lib/annotations.js.map +1 -0
- package/dist/charts/lib/axis.d.ts +18 -0
- package/dist/charts/lib/axis.js +21 -0
- package/dist/charts/lib/axis.js.map +1 -0
- package/dist/charts/lib/background.d.ts +33 -0
- package/dist/charts/lib/background.js +173 -0
- package/dist/charts/lib/background.js.map +1 -0
- package/dist/charts/lib/brush.d.ts +94 -0
- package/dist/charts/lib/brush.js +535 -0
- package/dist/charts/lib/brush.js.map +1 -0
- package/dist/charts/lib/chart.d.ts +94 -0
- package/dist/charts/lib/chart.js +134 -0
- package/dist/charts/lib/chart.js.map +1 -0
- package/dist/charts/lib/dot.d.ts +29 -0
- package/dist/charts/lib/dot.js +78 -0
- package/dist/charts/lib/dot.js.map +1 -0
- package/dist/charts/lib/empty.d.ts +31 -0
- package/dist/charts/lib/empty.js +13 -0
- package/dist/charts/lib/empty.js.map +1 -0
- package/dist/charts/lib/export.d.ts +103 -0
- package/dist/charts/lib/export.js +204 -0
- package/dist/charts/lib/export.js.map +1 -0
- package/dist/charts/lib/figure.d.ts +61 -0
- package/dist/charts/lib/figure.js +59 -0
- package/dist/charts/lib/figure.js.map +1 -0
- package/dist/charts/lib/format.d.ts +46 -0
- package/dist/charts/lib/format.js +56 -0
- package/dist/charts/lib/format.js.map +1 -0
- package/dist/charts/lib/legend.d.ts +45 -0
- package/dist/charts/lib/legend.js +117 -0
- package/dist/charts/lib/legend.js.map +1 -0
- package/dist/charts/lib/loading.d.ts +48 -0
- package/dist/charts/lib/loading.js +105 -0
- package/dist/charts/lib/loading.js.map +1 -0
- package/dist/charts/lib/paint.d.ts +154 -0
- package/dist/charts/lib/paint.js +551 -0
- package/dist/charts/lib/paint.js.map +1 -0
- package/dist/charts/lib/sonify-control.d.ts +163 -0
- package/dist/charts/lib/sonify-control.js +172 -0
- package/dist/charts/lib/sonify-control.js.map +1 -0
- package/dist/charts/lib/sonify.d.ts +248 -0
- package/dist/charts/lib/sonify.js +262 -0
- package/dist/charts/lib/sonify.js.map +1 -0
- package/dist/charts/lib/toolbar.d.ts +143 -0
- package/dist/charts/lib/toolbar.js +156 -0
- package/dist/charts/lib/toolbar.js.map +1 -0
- package/dist/charts/lib/tooltip.d.ts +59 -0
- package/dist/charts/lib/tooltip.js +135 -0
- package/dist/charts/lib/tooltip.js.map +1 -0
- package/dist/charts/lib/values.d.ts +56 -0
- package/dist/charts/lib/values.js +71 -0
- package/dist/charts/lib/values.js.map +1 -0
- package/dist/charts/lib/zoom.d.ts +139 -0
- package/dist/charts/lib/zoom.js +314 -0
- package/dist/charts/lib/zoom.js.map +1 -0
- package/dist/components/AppShell/AppShell.d.ts +15 -1
- package/dist/components/AppShell/AppShell.js +8 -4
- package/dist/components/AppShell/AppShell.js.map +1 -1
- package/dist/components/Article/Article.d.ts +51 -0
- package/dist/components/Article/Article.js +21 -0
- package/dist/components/Article/Article.js.map +1 -0
- package/dist/components/Button/Button.js +2 -2
- package/dist/components/Button/Button.js.map +1 -1
- package/dist/components/Calendar/Calendar.d.ts +1 -1
- package/dist/components/Calendar/Calendar.js +259 -24
- package/dist/components/Calendar/Calendar.js.map +1 -1
- package/dist/components/Checkbox/Checkbox.js +1 -1
- package/dist/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/components/Collapsible/Collapsible.d.ts +15 -1
- package/dist/components/Collapsible/Collapsible.js +18 -0
- package/dist/components/Collapsible/Collapsible.js.map +1 -1
- package/dist/components/Combobox/Combobox.js +1 -1
- package/dist/components/Combobox/Combobox.js.map +1 -1
- package/dist/components/Command/Command.js +7 -7
- package/dist/components/Command/Command.js.map +1 -1
- package/dist/components/ContextMenu/ContextMenu.js +2 -2
- package/dist/components/ContextMenu/ContextMenu.js.map +1 -1
- package/dist/components/Diagram/Diagram.d.ts +81 -0
- package/dist/components/Diagram/Diagram.js +139 -0
- package/dist/components/Diagram/Diagram.js.map +1 -0
- package/dist/components/Dialog/Dialog.js +1 -1
- package/dist/components/Dialog/Dialog.js.map +1 -1
- package/dist/components/DropdownMenu/DropdownMenu.js +2 -2
- package/dist/components/DropdownMenu/DropdownMenu.js.map +1 -1
- package/dist/components/FigureBand/FigureBand.js +41 -30
- package/dist/components/FigureBand/FigureBand.js.map +1 -1
- package/dist/components/Popover/Popover.js +1 -1
- package/dist/components/Popover/Popover.js.map +1 -1
- package/dist/components/Select/Select.js +2 -2
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/Sheet/Sheet.js +1 -1
- package/dist/components/Sheet/Sheet.js.map +1 -1
- package/dist/components/Slider/Slider.js +1 -1
- package/dist/components/Slider/Slider.js.map +1 -1
- package/dist/components/Steps/Steps.d.ts +65 -0
- package/dist/components/Steps/Steps.js +55 -0
- package/dist/components/Steps/Steps.js.map +1 -0
- package/dist/components/Switch/Switch.js +1 -1
- package/dist/components/Switch/Switch.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.js +1 -1
- package/dist/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/useSelectionIndicator.js +14 -10
- package/dist/lib/useSelectionIndicator.js.map +1 -1
- package/dist/semantic.css +19 -0
- package/dist/styles.css +1 -1
- package/dist/themes.css +103 -7
- package/dist/tokens.css +193 -10
- package/dist/tokens.d.ts +25 -0
- package/dist/tokens.js +154 -8
- package/dist/tokens.json +154 -8
- package/package.json +45 -20
- package/skills/misoto22-design/SKILL.md +171 -0
- package/skills/misoto22-design/evals/claims.json +95 -0
- package/skills/misoto22-design/rules/a11y.md +115 -0
- package/skills/misoto22-design/rules/composition.md +108 -0
- package/skills/misoto22-design/rules/forms.md +128 -0
- package/skills/misoto22-design/rules/naming.md +155 -0
- package/skills/misoto22-design/rules/tokens.md +131 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
Children,
|
|
5
|
+
createContext,
|
|
6
|
+
isValidElement,
|
|
7
|
+
useCallback,
|
|
8
|
+
useContext,
|
|
9
|
+
useEffect,
|
|
10
|
+
useId,
|
|
11
|
+
useMemo,
|
|
12
|
+
useState
|
|
13
|
+
} from "react";
|
|
14
|
+
import {
|
|
15
|
+
PolarAngleAxis as RechartsPolarAngleAxis,
|
|
16
|
+
PolarGrid as RechartsPolarGrid,
|
|
17
|
+
PolarRadiusAxis as RechartsPolarRadiusAxis,
|
|
18
|
+
Radar as RechartsRadar,
|
|
19
|
+
RadarChart as RechartsRadarChart
|
|
20
|
+
} from "recharts";
|
|
21
|
+
import { useReducedMotion } from "motion/react";
|
|
22
|
+
import { ChartContainer, colorStops } from "../lib/chart.js";
|
|
23
|
+
import { ChartFigure } from "../lib/figure.js";
|
|
24
|
+
import { ChartBackground } from "../lib/background.js";
|
|
25
|
+
import { ChartDot } from "../lib/dot.js";
|
|
26
|
+
import { ChartLegend, ChartLegendContent } from "../lib/legend.js";
|
|
27
|
+
import { ChartTooltip, ChartTooltipContent } from "../lib/tooltip.js";
|
|
28
|
+
import { LoadingIndicator } from "../lib/loading.js";
|
|
29
|
+
import { ColorStops, GlowFilter, SeriesGradient } from "../lib/paint.js";
|
|
30
|
+
const STROKE_WIDTH = 1;
|
|
31
|
+
const FILL_STRENGTH = 2.2;
|
|
32
|
+
const LOADING_POINTS = 6;
|
|
33
|
+
const LOADING_CYCLE = 1500;
|
|
34
|
+
const RadarChartContext = createContext(null);
|
|
35
|
+
function useRadarChart() {
|
|
36
|
+
const context = useContext(RadarChartContext);
|
|
37
|
+
if (!context) throw new Error("A radar chart part must be rendered inside <RadarChart>");
|
|
38
|
+
return context;
|
|
39
|
+
}
|
|
40
|
+
function RadarChart({
|
|
41
|
+
config,
|
|
42
|
+
data,
|
|
43
|
+
title,
|
|
44
|
+
showTitle,
|
|
45
|
+
description,
|
|
46
|
+
children,
|
|
47
|
+
className,
|
|
48
|
+
chartProps,
|
|
49
|
+
defaultSelectedDataKey = null,
|
|
50
|
+
onSelectionChange,
|
|
51
|
+
isLoading = false,
|
|
52
|
+
loadingPoints,
|
|
53
|
+
angleDataKey,
|
|
54
|
+
hideDataTable = false
|
|
55
|
+
}) {
|
|
56
|
+
const chartId = useId().replace(/:/g, "");
|
|
57
|
+
const [selectedDataKey, setSelectedDataKey] = useState(defaultSelectedDataKey);
|
|
58
|
+
const loadingData = useLoadingShape(isLoading, loadingPoints);
|
|
59
|
+
const selectDataKey = useCallback(
|
|
60
|
+
(next) => {
|
|
61
|
+
setSelectedDataKey(next);
|
|
62
|
+
onSelectionChange?.(next);
|
|
63
|
+
},
|
|
64
|
+
[onSelectionChange]
|
|
65
|
+
);
|
|
66
|
+
const context = useMemo(
|
|
67
|
+
() => ({ config, isLoading, selectedDataKey, selectDataKey }),
|
|
68
|
+
[config, isLoading, selectDataKey, selectedDataKey]
|
|
69
|
+
);
|
|
70
|
+
return /* @__PURE__ */ jsx(RadarChartContext.Provider, { value: context, children: /* @__PURE__ */ jsxs(
|
|
71
|
+
ChartFigure,
|
|
72
|
+
{
|
|
73
|
+
title,
|
|
74
|
+
showTitle,
|
|
75
|
+
description,
|
|
76
|
+
className,
|
|
77
|
+
table: hideDataTable ? false : {
|
|
78
|
+
rows: data,
|
|
79
|
+
rowKey: angleDataKey,
|
|
80
|
+
columns: Object.entries(config).map(([key, series]) => ({
|
|
81
|
+
key,
|
|
82
|
+
label: series.label
|
|
83
|
+
}))
|
|
84
|
+
},
|
|
85
|
+
children: [
|
|
86
|
+
/* @__PURE__ */ jsx(ChartContainer, { config, children: /* @__PURE__ */ jsxs(RechartsRadarChart, { id: chartId, data: isLoading ? loadingData : data, ...chartProps, children: [
|
|
87
|
+
children,
|
|
88
|
+
isLoading && /* @__PURE__ */ jsx(LoadingRadar, {})
|
|
89
|
+
] }) }),
|
|
90
|
+
/* @__PURE__ */ jsx(LoadingIndicator, { isLoading })
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
) });
|
|
94
|
+
}
|
|
95
|
+
function Radar({
|
|
96
|
+
dataKey,
|
|
97
|
+
variant = "filled",
|
|
98
|
+
fillOpacity,
|
|
99
|
+
glowing = false,
|
|
100
|
+
isClickable = false,
|
|
101
|
+
children,
|
|
102
|
+
radarProps
|
|
103
|
+
}) {
|
|
104
|
+
const { config, isLoading, selectedDataKey, selectDataKey } = useRadarChart();
|
|
105
|
+
const id = useId().replace(/:/g, "");
|
|
106
|
+
if (isLoading) return null;
|
|
107
|
+
const isSelected = selectedDataKey === null || selectedDataKey === dataKey;
|
|
108
|
+
const dimmed = isClickable && !isSelected;
|
|
109
|
+
const opacity = { stroke: dimmed ? 0.2 : 1, fill: dimmed ? 0.1 : 1, dot: dimmed ? 0.2 : 1 };
|
|
110
|
+
const isFilled = variant === "filled";
|
|
111
|
+
const { dot, activeDot } = resolveDots(children, id, dataKey, opacity.dot);
|
|
112
|
+
const filledStrength = `calc(var(--chart-fill) * ${FILL_STRENGTH})`;
|
|
113
|
+
const stops = colorStops(config[dataKey]);
|
|
114
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
115
|
+
/* @__PURE__ */ jsx(
|
|
116
|
+
RechartsRadar,
|
|
117
|
+
{
|
|
118
|
+
dataKey,
|
|
119
|
+
stroke: `url(#${id}-stroke-${dataKey})`,
|
|
120
|
+
strokeOpacity: opacity.stroke,
|
|
121
|
+
strokeWidth: STROKE_WIDTH,
|
|
122
|
+
fill: isFilled ? `url(#${id}-fill-${dataKey})` : "none",
|
|
123
|
+
fillOpacity: isFilled ? (fillOpacity ?? filledStrength) * opacity.fill : 0,
|
|
124
|
+
dot,
|
|
125
|
+
activeDot,
|
|
126
|
+
filter: glowing ? `url(#${id}-glow-${dataKey})` : void 0,
|
|
127
|
+
className: "transition-opacity duration-(--duration-base)",
|
|
128
|
+
style: isClickable ? { cursor: "pointer" } : void 0,
|
|
129
|
+
onClick: () => {
|
|
130
|
+
if (!isClickable) return;
|
|
131
|
+
selectDataKey(selectedDataKey === dataKey ? null : dataKey);
|
|
132
|
+
},
|
|
133
|
+
...radarProps
|
|
134
|
+
}
|
|
135
|
+
),
|
|
136
|
+
/* @__PURE__ */ jsxs("defs", { children: [
|
|
137
|
+
/* @__PURE__ */ jsx(SeriesGradient, { id, dataKey, config }),
|
|
138
|
+
/* @__PURE__ */ jsx("linearGradient", { id: `${id}-stroke-${dataKey}`, x1: "0", y1: "0", x2: "1", y2: "1", children: /* @__PURE__ */ jsx(ColorStops, { dataKey, stops }) }),
|
|
139
|
+
isFilled && // Radial, and fading outward: a flat fill makes the outer ring — the
|
|
140
|
+
// part carrying the shape — the least readable part of the mark.
|
|
141
|
+
/* @__PURE__ */ jsx("radialGradient", { id: `${id}-fill-${dataKey}`, cx: "50%", cy: "50%", r: "50%", children: /* @__PURE__ */ jsx(
|
|
142
|
+
ColorStops,
|
|
143
|
+
{
|
|
144
|
+
dataKey,
|
|
145
|
+
stops,
|
|
146
|
+
opacities: stops === 1 ? [0.8, 0.3] : Array.from({ length: stops }, (_, i) => i === 0 ? 0.8 : 0.3)
|
|
147
|
+
}
|
|
148
|
+
) }),
|
|
149
|
+
glowing && /* @__PURE__ */ jsx(GlowFilter, { id, dataKey, spread: 4, intensity: 0.6 })
|
|
150
|
+
] })
|
|
151
|
+
] });
|
|
152
|
+
}
|
|
153
|
+
const Dot = () => null;
|
|
154
|
+
const ActiveDot = () => null;
|
|
155
|
+
function resolveDots(children, id, dataKey, dotOpacity) {
|
|
156
|
+
let dot = false;
|
|
157
|
+
let activeDot = false;
|
|
158
|
+
Children.forEach(children, (child) => {
|
|
159
|
+
if (!isValidElement(child)) return;
|
|
160
|
+
const { variant } = child.props;
|
|
161
|
+
if (child.type === Dot) {
|
|
162
|
+
dot = /* @__PURE__ */ jsx(ChartDot, { variant, dataKey, chartId: id, fillOpacity: dotOpacity });
|
|
163
|
+
}
|
|
164
|
+
if (child.type === ActiveDot) {
|
|
165
|
+
activeDot = /* @__PURE__ */ jsx(ChartDot, { variant, dataKey, chartId: id, fillOpacity: dotOpacity });
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
return { dot, activeDot };
|
|
169
|
+
}
|
|
170
|
+
function PolarGrid({
|
|
171
|
+
gridType = "polygon",
|
|
172
|
+
stroke = "var(--chart-grid)",
|
|
173
|
+
strokeDasharray = "3 4",
|
|
174
|
+
...rest
|
|
175
|
+
}) {
|
|
176
|
+
return /* @__PURE__ */ jsx(
|
|
177
|
+
RechartsPolarGrid,
|
|
178
|
+
{
|
|
179
|
+
gridType,
|
|
180
|
+
stroke,
|
|
181
|
+
strokeDasharray,
|
|
182
|
+
...rest
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
function PolarAngleAxis({
|
|
187
|
+
tick = { fill: "var(--chart-axis)", fontSize: 12 },
|
|
188
|
+
tickLine = false,
|
|
189
|
+
...rest
|
|
190
|
+
}) {
|
|
191
|
+
const { isLoading } = useRadarChart();
|
|
192
|
+
if (isLoading) return null;
|
|
193
|
+
return /* @__PURE__ */ jsx(RechartsPolarAngleAxis, { tick, tickLine, ...rest });
|
|
194
|
+
}
|
|
195
|
+
function PolarRadiusAxis({
|
|
196
|
+
tick = { fill: "var(--chart-axis)", fontSize: 10 },
|
|
197
|
+
tickLine = false,
|
|
198
|
+
axisLine = false,
|
|
199
|
+
...rest
|
|
200
|
+
}) {
|
|
201
|
+
const { isLoading } = useRadarChart();
|
|
202
|
+
if (isLoading) return null;
|
|
203
|
+
return /* @__PURE__ */ jsx(RechartsPolarRadiusAxis, { tick, tickLine, axisLine, ...rest });
|
|
204
|
+
}
|
|
205
|
+
function Tooltip({ variant, roundness, defaultIndex }) {
|
|
206
|
+
const { isLoading, selectedDataKey } = useRadarChart();
|
|
207
|
+
if (isLoading) return null;
|
|
208
|
+
return /* @__PURE__ */ jsx(
|
|
209
|
+
ChartTooltip,
|
|
210
|
+
{
|
|
211
|
+
defaultIndex,
|
|
212
|
+
cursor: false,
|
|
213
|
+
content: /* @__PURE__ */ jsx(ChartTooltipContent, { selected: selectedDataKey, roundness, variant })
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
function Legend({
|
|
218
|
+
variant,
|
|
219
|
+
align = "center",
|
|
220
|
+
verticalAlign = "bottom",
|
|
221
|
+
isClickable = false
|
|
222
|
+
}) {
|
|
223
|
+
const { isLoading, selectedDataKey, selectDataKey } = useRadarChart();
|
|
224
|
+
if (isLoading) return null;
|
|
225
|
+
return /* @__PURE__ */ jsx(
|
|
226
|
+
ChartLegend,
|
|
227
|
+
{
|
|
228
|
+
verticalAlign,
|
|
229
|
+
align,
|
|
230
|
+
content: /* @__PURE__ */ jsx(
|
|
231
|
+
ChartLegendContent,
|
|
232
|
+
{
|
|
233
|
+
selected: selectedDataKey,
|
|
234
|
+
onSelectChange: selectDataKey,
|
|
235
|
+
isClickable,
|
|
236
|
+
variant
|
|
237
|
+
}
|
|
238
|
+
)
|
|
239
|
+
}
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
function Background({ variant = "dots" }) {
|
|
243
|
+
const { isLoading } = useRadarChart();
|
|
244
|
+
if (isLoading) return null;
|
|
245
|
+
return /* @__PURE__ */ jsx(ChartBackground, { variant });
|
|
246
|
+
}
|
|
247
|
+
function shape(index, cycle) {
|
|
248
|
+
const x = Math.sin(index * 91.7 + cycle * 47.3) * 21942.7;
|
|
249
|
+
return 30 + (x - Math.floor(x)) * 70;
|
|
250
|
+
}
|
|
251
|
+
function useLoadingShape(isLoading, points = LOADING_POINTS) {
|
|
252
|
+
const [cycle, setCycle] = useState(0);
|
|
253
|
+
useEffect(() => {
|
|
254
|
+
if (!isLoading) return;
|
|
255
|
+
const timer = setInterval(() => setCycle((previous) => previous + 1), LOADING_CYCLE);
|
|
256
|
+
return () => clearInterval(timer);
|
|
257
|
+
}, [isLoading]);
|
|
258
|
+
return useMemo(
|
|
259
|
+
() => Array.from({ length: points }, (_, index) => ({
|
|
260
|
+
spoke: String.fromCharCode(65 + index),
|
|
261
|
+
value: shape(index, cycle)
|
|
262
|
+
})),
|
|
263
|
+
[cycle, points]
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
function LoadingRadar() {
|
|
267
|
+
const reduceMotion = useReducedMotion();
|
|
268
|
+
return /* @__PURE__ */ jsx(
|
|
269
|
+
RechartsRadar,
|
|
270
|
+
{
|
|
271
|
+
dataKey: "value",
|
|
272
|
+
stroke: "currentColor",
|
|
273
|
+
strokeOpacity: 0.3,
|
|
274
|
+
strokeWidth: 2,
|
|
275
|
+
fill: "currentColor",
|
|
276
|
+
fillOpacity: 0.1,
|
|
277
|
+
dot: false,
|
|
278
|
+
className: "text-(--ink)",
|
|
279
|
+
isAnimationActive: !reduceMotion,
|
|
280
|
+
animationDuration: LOADING_CYCLE,
|
|
281
|
+
animationEasing: "ease-in-out"
|
|
282
|
+
}
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
RadarChart.Radar = Radar;
|
|
286
|
+
RadarChart.Dot = Dot;
|
|
287
|
+
RadarChart.ActiveDot = ActiveDot;
|
|
288
|
+
RadarChart.PolarGrid = PolarGrid;
|
|
289
|
+
RadarChart.PolarAngleAxis = PolarAngleAxis;
|
|
290
|
+
RadarChart.PolarRadiusAxis = PolarRadiusAxis;
|
|
291
|
+
RadarChart.Tooltip = Tooltip;
|
|
292
|
+
RadarChart.Legend = Legend;
|
|
293
|
+
RadarChart.Background = Background;
|
|
294
|
+
var RadarChart_default = RadarChart;
|
|
295
|
+
export {
|
|
296
|
+
RadarChart,
|
|
297
|
+
RadarChart_default as default
|
|
298
|
+
};
|
|
299
|
+
//# sourceMappingURL=RadarChart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/charts/RadarChart/RadarChart.tsx"],"sourcesContent":["'use client'\n\nimport {\n Children,\n createContext,\n isValidElement,\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useState,\n type ComponentProps,\n type FC,\n type ReactElement,\n type ReactNode,\n} from 'react'\nimport {\n PolarAngleAxis as RechartsPolarAngleAxis,\n PolarGrid as RechartsPolarGrid,\n PolarRadiusAxis as RechartsPolarRadiusAxis,\n Radar as RechartsRadar,\n RadarChart as RechartsRadarChart,\n} from 'recharts'\nimport { useReducedMotion } from 'motion/react'\nimport { ChartContainer, colorStops, type ChartConfig } from '../lib/chart'\nimport { ChartFigure } from '../lib/figure'\nimport { ChartBackground, type ChartBackgroundVariant } from '../lib/background'\nimport { ChartDot, type ChartDotVariant } from '../lib/dot'\nimport { ChartLegend, ChartLegendContent } from '../lib/legend'\nimport { ChartTooltip, ChartTooltipContent } from '../lib/tooltip'\nimport { LoadingIndicator } from '../lib/loading'\nimport { ColorStops, GlowFilter, SeriesGradient } from '../lib/paint'\nimport type { ChartLegendSlotProps, ChartTooltipSlotProps } from '../AreaChart/AreaChart'\n\nconst STROKE_WIDTH = 1\n/**\n * How solid a filled radar is, as a multiplier on `--chart-fill`.\n *\n * Above 1 because a radar's fill is the mark itself rather than a wash under a\n * line — it has to hold its shape where two of them overlap.\n */\nconst FILL_STRENGTH = 2.2\nconst LOADING_POINTS = 6\n\n/** One skeleton morph, in milliseconds. */\nconst LOADING_CYCLE = 1500\n\n/**\n * Whether a radar is filled or left as an outline.\n *\n * `lines` is the honest default above two series: filled polygons overlap, and\n * the reader is then judging areas through two layers of translucency, which is\n * the one thing a radar is worst at.\n */\nexport type RadarVariant = 'filled' | 'lines'\n\ninterface RadarChartContextValue {\n config: ChartConfig\n isLoading: boolean\n selectedDataKey: string | null\n selectDataKey: (dataKey: string | null) => void\n}\n\nconst RadarChartContext = createContext<RadarChartContextValue | null>(null)\n\nfunction useRadarChart(): RadarChartContextValue {\n const context = useContext(RadarChartContext)\n if (!context) throw new Error('A radar chart part must be rendered inside <RadarChart>')\n return context\n}\n\ntype ValidateKeys<TData, TConfig> = {\n [K in keyof TConfig]: K extends keyof TData ? ChartConfig[string] : never\n}\n\nexport interface RadarChartProps<\n TData extends Record<string, unknown>,\n TConfig extends Record<string, ChartConfig[string]>,\n> {\n config: TConfig & ValidateKeys<TData, TConfig>\n /** The rows the chart draws. One entry per point, bar or category. */\n data: TData[]\n /**\n * What the chart shows, in a sentence a reader could act on. Required, and\n * announced to a screen reader even when it is not printed.\n */\n title: string\n /** Prints the title above the plot instead of hiding it from sight. */\n showTitle?: boolean\n /** A line under the title — the unit, the window, the caveat. */\n description?: ReactNode\n /**\n * The composed parts — axes, grid, tooltip, legend, and the marks\n * themselves.\n */\n children: ReactNode\n /** Merged onto the figure, last, so a call site can size or space it. */\n className?: string\n /** Escape hatch onto the raw Recharts chart element. */\n chartProps?: ComponentProps<typeof RechartsRadarChart>\n /** The series lit on first render. Selection dims every other series. */\n defaultSelectedDataKey?: string | null\n /** Fires when the selection changes, and with null when it is cleared. */\n onSelectionChange?: (selectedDataKey: string | null) => void\n /**\n * Swaps the marks for an animated skeleton, keeping the measured height so\n * the page does not jump when the data lands.\n */\n isLoading?: boolean\n /** How many points the skeleton draws. */\n loadingPoints?: number\n /** The row field naming each spoke. Used by the table view. */\n angleDataKey?: keyof TData & string\n /**\n * Drops the hidden table view. Only correct when the page prints the data\n * itself.\n */\n hideDataTable?: boolean\n}\n\n/**\n * A profile across several named dimensions — the shape for \"what is this thing\n * strong and weak at\".\n *\n * It reads a SHAPE, not a set of values: the area a radar encloses depends on\n * the order the spokes happen to be in, so it is the wrong chart for comparing\n * magnitudes and the right one for recognising a silhouette. Two or three\n * series at most.\n *\n * @example\n * <RadarChart title=\"Team skills\" config={config} data={data} angleDataKey=\"skill\">\n * <RadarChart.PolarGrid />\n * <RadarChart.PolarAngleAxis dataKey=\"skill\" />\n * <RadarChart.Tooltip />\n * <RadarChart.Radar dataKey=\"current\" />\n * </RadarChart>\n */\nexport function RadarChart<\n TData extends Record<string, unknown>,\n TConfig extends Record<string, ChartConfig[string]>,\n>({\n config,\n data,\n title,\n showTitle,\n description,\n children,\n className,\n chartProps,\n defaultSelectedDataKey = null,\n onSelectionChange,\n isLoading = false,\n loadingPoints,\n angleDataKey,\n hideDataTable = false,\n}: RadarChartProps<TData, TConfig>) {\n const chartId = useId().replace(/:/g, '')\n const [selectedDataKey, setSelectedDataKey] = useState<string | null>(defaultSelectedDataKey)\n const loadingData = useLoadingShape(isLoading, loadingPoints)\n\n const selectDataKey = useCallback(\n (next: string | null) => {\n setSelectedDataKey(next)\n onSelectionChange?.(next)\n },\n [onSelectionChange],\n )\n\n const context = useMemo<RadarChartContextValue>(\n () => ({ config, isLoading, selectedDataKey, selectDataKey }),\n [config, isLoading, selectDataKey, selectedDataKey],\n )\n\n return (\n <RadarChartContext.Provider value={context}>\n <ChartFigure\n title={title}\n showTitle={showTitle}\n description={description}\n className={className}\n table={\n hideDataTable\n ? false\n : {\n rows: data,\n rowKey: angleDataKey,\n columns: Object.entries(config).map(([key, series]) => ({\n key,\n label: series.label,\n })),\n }\n }\n >\n <ChartContainer config={config}>\n <RechartsRadarChart id={chartId} data={isLoading ? loadingData : data} {...chartProps}>\n {children}\n {isLoading && <LoadingRadar />}\n </RechartsRadarChart>\n </ChartContainer>\n <LoadingIndicator isLoading={isLoading} />\n </ChartFigure>\n </RadarChartContext.Provider>\n )\n}\n\nexport interface RadarProps {\n dataKey: string\n variant?: RadarVariant\n /**\n * How solid the filled area is, 0–1. Left unset it follows `--chart-fill`,\n * which is what keeps it readable on both grounds.\n */\n fillOpacity?: number\n /** A halo around the outline — for the one series that is the point. */\n glowing?: boolean\n isClickable?: boolean\n children?: ReactNode\n radarProps?: Omit<ComponentProps<typeof RechartsRadar>, 'dataKey'>\n}\n\n/** One radar series, with its stroke, fill and glow scoped to its own id. */\nfunction Radar({\n dataKey,\n variant = 'filled',\n fillOpacity,\n glowing = false,\n isClickable = false,\n children,\n radarProps,\n}: RadarProps) {\n const { config, isLoading, selectedDataKey, selectDataKey } = useRadarChart()\n const id = useId().replace(/:/g, '')\n\n if (isLoading) return null\n\n const isSelected = selectedDataKey === null || selectedDataKey === dataKey\n const dimmed = isClickable && !isSelected\n // The fill recedes twice as far as the stroke. A dimmed outline still traces\n // its shape, which is what a radar is read by; a dimmed fill just muddies the\n // one that was picked.\n const opacity = { stroke: dimmed ? 0.2 : 1, fill: dimmed ? 0.1 : 1, dot: dimmed ? 0.2 : 1 }\n const isFilled = variant === 'filled'\n\n const { dot, activeDot } = resolveDots(children, id, dataKey, opacity.dot)\n // `--chart-fill` is a number, not a length, so it can be read into a\n // calc() the SVG attribute accepts — which is how the default follows the\n // ground without the component knowing which ground it is on.\n const filledStrength = `calc(var(--chart-fill) * ${FILL_STRENGTH})` as unknown as number\n const stops = colorStops(config[dataKey])\n\n return (\n <>\n <RechartsRadar\n dataKey={dataKey}\n stroke={`url(#${id}-stroke-${dataKey})`}\n strokeOpacity={opacity.stroke}\n strokeWidth={STROKE_WIDTH}\n fill={isFilled ? `url(#${id}-fill-${dataKey})` : 'none'}\n fillOpacity={isFilled ? (fillOpacity ?? filledStrength) * opacity.fill : 0}\n dot={dot}\n activeDot={activeDot}\n filter={glowing ? `url(#${id}-glow-${dataKey})` : undefined}\n className=\"transition-opacity duration-(--duration-base)\"\n style={isClickable ? { cursor: 'pointer' } : undefined}\n onClick={() => {\n if (!isClickable) return\n selectDataKey(selectedDataKey === dataKey ? null : dataKey)\n }}\n {...radarProps}\n />\n <defs>\n {/* The dots read this one; the stroke and fill get their own below. */}\n <SeriesGradient id={id} dataKey={dataKey} config={config} />\n <linearGradient id={`${id}-stroke-${dataKey}`} x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\">\n <ColorStops dataKey={dataKey} stops={stops} />\n </linearGradient>\n {isFilled && (\n // Radial, and fading outward: a flat fill makes the outer ring — the\n // part carrying the shape — the least readable part of the mark.\n <radialGradient id={`${id}-fill-${dataKey}`} cx=\"50%\" cy=\"50%\" r=\"50%\">\n <ColorStops\n dataKey={dataKey}\n stops={stops}\n opacities={\n stops === 1 ? [0.8, 0.3] : Array.from({ length: stops }, (_, i) => (i === 0 ? 0.8 : 0.3))\n }\n />\n </radialGradient>\n )}\n {glowing && <GlowFilter id={id} dataKey={dataKey} spread={4} intensity={0.6} />}\n </defs>\n </>\n )\n}\n\nexport interface DotProps {\n variant?: ChartDotVariant\n}\n\n/** The resting point marker for the radar it is composed inside. A slot. */\nconst Dot: FC<DotProps> = () => null\n\n/** The marker under the pointer. */\nconst ActiveDot: FC<DotProps> = () => null\n\nfunction resolveDots(children: ReactNode, id: string, dataKey: string, dotOpacity: number) {\n let dot: ComponentProps<typeof RechartsRadar>['dot'] = false\n let activeDot: ComponentProps<typeof RechartsRadar>['activeDot'] = false\n\n Children.forEach(children, (child) => {\n if (!isValidElement(child)) return\n const { variant } = (child as ReactElement<DotProps>).props\n\n if (child.type === Dot) {\n dot = <ChartDot variant={variant} dataKey={dataKey} chartId={id} fillOpacity={dotOpacity} />\n }\n if (child.type === ActiveDot) {\n activeDot = (\n <ChartDot variant={variant} dataKey={dataKey} chartId={id} fillOpacity={dotOpacity} />\n )\n }\n })\n\n return { dot, activeDot }\n}\n\n/**\n * The web behind the marks. `gridType=\"circle\"` swaps the polygon for rings,\n * which reads as a scale rather than as a shape and suits a single series.\n */\nfunction PolarGrid({\n gridType = 'polygon',\n stroke = 'var(--chart-grid)',\n strokeDasharray = '3 4',\n ...rest\n}: ComponentProps<typeof RechartsPolarGrid>) {\n return (\n <RechartsPolarGrid\n gridType={gridType}\n stroke={stroke}\n strokeDasharray={strokeDasharray}\n {...rest}\n />\n )\n}\n\n/** The spoke labels around the perimeter. */\nfunction PolarAngleAxis({\n tick = { fill: 'var(--chart-axis)', fontSize: 12 },\n tickLine = false,\n ...rest\n}: ComponentProps<typeof RechartsPolarAngleAxis>) {\n const { isLoading } = useRadarChart()\n if (isLoading) return null\n return <RechartsPolarAngleAxis tick={tick} tickLine={tickLine} {...rest} />\n}\n\n/** The scale running out from the centre. */\nfunction PolarRadiusAxis({\n tick = { fill: 'var(--chart-axis)', fontSize: 10 },\n tickLine = false,\n axisLine = false,\n ...rest\n}: ComponentProps<typeof RechartsPolarRadiusAxis>) {\n const { isLoading } = useRadarChart()\n if (isLoading) return null\n return (\n <RechartsPolarRadiusAxis tick={tick} tickLine={tickLine} axisLine={axisLine} {...rest} />\n )\n}\n\n/** The hover panel. No crosshair: there is no straight axis to run one along. */\nfunction Tooltip({ variant, roundness, defaultIndex }: ChartTooltipSlotProps) {\n const { isLoading, selectedDataKey } = useRadarChart()\n if (isLoading) return null\n\n return (\n <ChartTooltip\n defaultIndex={defaultIndex}\n cursor={false}\n content={\n <ChartTooltipContent selected={selectedDataKey} roundness={roundness} variant={variant} />\n }\n />\n )\n}\n\n/** The key. Under the web and centred, since the spokes name dimensions, not series. */\nfunction Legend({\n variant,\n align = 'center',\n verticalAlign = 'bottom',\n isClickable = false,\n}: ChartLegendSlotProps) {\n const { isLoading, selectedDataKey, selectDataKey } = useRadarChart()\n if (isLoading) return null\n\n return (\n <ChartLegend\n verticalAlign={verticalAlign}\n align={align}\n content={\n <ChartLegendContent\n selected={selectedDataKey}\n onSelectChange={selectDataKey}\n isClickable={isClickable}\n variant={variant}\n />\n }\n />\n )\n}\n\n/** The decorative plate behind the web. */\nfunction Background({ variant = 'dots' }: { variant?: ChartBackgroundVariant }) {\n const { isLoading } = useRadarChart()\n if (isLoading) return null\n return <ChartBackground variant={variant} />\n}\n\n/** A deterministic spoke value, so the server and the client agree. */\nfunction shape(index: number, cycle: number): number {\n const x = Math.sin(index * 91.7 + cycle * 47.3) * 21_942.7\n return 30 + (x - Math.floor(x)) * 70\n}\n\n/**\n * The skeleton's spokes, re-rolled once per cycle.\n *\n * An interval rather than the shimmer's exit callback: a radar's skeleton\n * animates by MORPHING between shapes, which is Recharts' own transition, so\n * there is no travelling highlight to synchronise against.\n */\nfunction useLoadingShape(isLoading: boolean, points = LOADING_POINTS) {\n const [cycle, setCycle] = useState(0)\n\n useEffect(() => {\n if (!isLoading) return\n const timer = setInterval(() => setCycle((previous) => previous + 1), LOADING_CYCLE)\n return () => clearInterval(timer)\n }, [isLoading])\n\n return useMemo(\n () =>\n Array.from({ length: points }, (_, index) => ({\n spoke: String.fromCharCode(65 + index),\n value: shape(index, cycle),\n })),\n [cycle, points],\n )\n}\n\n/** The skeleton radar, morphing between shapes while the data is in flight. */\nfunction LoadingRadar() {\n const reduceMotion = useReducedMotion()\n\n return (\n <RechartsRadar\n dataKey=\"value\"\n stroke=\"currentColor\"\n strokeOpacity={0.3}\n strokeWidth={2}\n fill=\"currentColor\"\n fillOpacity={0.1}\n dot={false}\n className=\"text-(--ink)\"\n isAnimationActive={!reduceMotion}\n animationDuration={LOADING_CYCLE}\n animationEasing=\"ease-in-out\"\n />\n )\n}\n\nRadarChart.Radar = Radar\nRadarChart.Dot = Dot\nRadarChart.ActiveDot = ActiveDot\nRadarChart.PolarGrid = PolarGrid\nRadarChart.PolarAngleAxis = PolarAngleAxis\nRadarChart.PolarRadiusAxis = PolarRadiusAxis\nRadarChart.Tooltip = Tooltip\nRadarChart.Legend = Legend\nRadarChart.Background = Background\n\nexport default RadarChart\n"],"mappings":";AAmMU,SAyDN,UAvDsB,KAFhB;AAjMV;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP;AAAA,EACE,kBAAkB;AAAA,EAClB,aAAa;AAAA,EACb,mBAAmB;AAAA,EACnB,SAAS;AAAA,EACT,cAAc;AAAA,OACT;AACP,SAAS,wBAAwB;AACjC,SAAS,gBAAgB,kBAAoC;AAC7D,SAAS,mBAAmB;AAC5B,SAAS,uBAAoD;AAC7D,SAAS,gBAAsC;AAC/C,SAAS,aAAa,0BAA0B;AAChD,SAAS,cAAc,2BAA2B;AAClD,SAAS,wBAAwB;AACjC,SAAS,YAAY,YAAY,sBAAsB;AAGvD,MAAM,eAAe;AAOrB,MAAM,gBAAgB;AACtB,MAAM,iBAAiB;AAGvB,MAAM,gBAAgB;AAkBtB,MAAM,oBAAoB,cAA6C,IAAI;AAE3E,SAAS,gBAAwC;AAC/C,QAAM,UAAU,WAAW,iBAAiB;AAC5C,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,yDAAyD;AACvF,SAAO;AACT;AAoEO,SAAS,WAGd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,yBAAyB;AAAA,EACzB;AAAA,EACA,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA,gBAAgB;AAClB,GAAoC;AAClC,QAAM,UAAU,MAAM,EAAE,QAAQ,MAAM,EAAE;AACxC,QAAM,CAAC,iBAAiB,kBAAkB,IAAI,SAAwB,sBAAsB;AAC5F,QAAM,cAAc,gBAAgB,WAAW,aAAa;AAE5D,QAAM,gBAAgB;AAAA,IACpB,CAAC,SAAwB;AACvB,yBAAmB,IAAI;AACvB,0BAAoB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AM,KAAK,EAAE,QAAQ,OAAO,GAAG,CAAC,GAAG,WAAW;AAAA,MAC5C,OAAO,OAAO,aAAa,KAAK,KAAK;AAAA,MACrC,OAAO,MAAM,OAAO,KAAK;AAAA,IAC3B,EAAE;AAAA,IACJ,CAAC,OAAO,MAAM;AAAA,EAChB;AACF;AAGA,SAAS,eAAe;AACtB,QAAM,eAAe,iBAAiB;AAEtC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,SAAQ;AAAA,MACR,QAAO;AAAA,MACP,eAAe;AAAA,MACf,aAAa;AAAA,MACb,MAAK;AAAA,MACL,aAAa;AAAA,MACb,KAAK;AAAA,MACL,WAAU;AAAA,MACV,mBAAmB,CAAC;AAAA,MACpB,mBAAmB;AAAA,MACnB,iBAAgB;AAAA;AAAA,EAClB;AAEJ;AAEA,WAAW,QAAQ;AACnB,WAAW,MAAM;AACjB,WAAW,YAAY;AACvB,WAAW,YAAY;AACvB,WAAW,iBAAiB;AAC5B,WAAW,kBAAkB;AAC7B,WAAW,UAAU;AACrB,WAAW,SAAS;AACpB,WAAW,aAAa;AAExB,IAAO,qBAAQ;","names":[]}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentProps, ReactNode } from 'react';
|
|
3
|
+
import { RadialBar, RadialBarChart } from 'recharts';
|
|
4
|
+
import { ChartConfig } from '../lib/chart.js';
|
|
5
|
+
import { ChartBackgroundVariant } from '../lib/background.js';
|
|
6
|
+
import { ChartTooltipSlotProps, ChartLegendSlotProps } from '../AreaChart/AreaChart.js';
|
|
7
|
+
import '../lib/empty.js';
|
|
8
|
+
import '../lib/values.js';
|
|
9
|
+
import '../lib/sonify-control.js';
|
|
10
|
+
import '../lib/sonify.js';
|
|
11
|
+
import '../lib/brush.js';
|
|
12
|
+
import '../lib/toolbar.js';
|
|
13
|
+
import '../lib/zoom.js';
|
|
14
|
+
import '../lib/figure.js';
|
|
15
|
+
import '../lib/paint.js';
|
|
16
|
+
import '../lib/dot.js';
|
|
17
|
+
import '../lib/legend.js';
|
|
18
|
+
import '../lib/tooltip.js';
|
|
19
|
+
import 'recharts/types/component/DefaultTooltipContent';
|
|
20
|
+
import '../lib/annotations.js';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The arc the bars are drawn on.
|
|
24
|
+
*
|
|
25
|
+
* `full` is a ring; `semi` is the half-circle a gauge wants, with the centre
|
|
26
|
+
* dropped so the arc sits in the middle of its own box rather than at the top.
|
|
27
|
+
*/
|
|
28
|
+
type RadialVariant = 'full' | 'semi';
|
|
29
|
+
interface RadialChartProps<TData extends Record<string, unknown>> {
|
|
30
|
+
/** Bar names → their label and paint. Keys must match the `nameKey` values. */
|
|
31
|
+
config: ChartConfig;
|
|
32
|
+
/** The rows the chart draws. One entry per point, bar or category. */
|
|
33
|
+
data: TData[];
|
|
34
|
+
/** The row field naming each bar. */
|
|
35
|
+
nameKey: keyof TData & string;
|
|
36
|
+
/**
|
|
37
|
+
* What the chart shows, in a sentence a reader could act on. Required, and
|
|
38
|
+
* announced to a screen reader even when it is not printed.
|
|
39
|
+
*/
|
|
40
|
+
title: string;
|
|
41
|
+
/** Prints the title above the plot instead of hiding it from sight. */
|
|
42
|
+
showTitle?: boolean;
|
|
43
|
+
/** A line under the title — the unit, the window, the caveat. */
|
|
44
|
+
description?: ReactNode;
|
|
45
|
+
/**
|
|
46
|
+
* The composed parts — axes, grid, tooltip, legend, and the marks
|
|
47
|
+
* themselves.
|
|
48
|
+
*/
|
|
49
|
+
children: ReactNode;
|
|
50
|
+
/** Merged onto the figure, last, so a call site can size or space it. */
|
|
51
|
+
className?: string;
|
|
52
|
+
/** Escape hatch onto the raw Recharts chart element. */
|
|
53
|
+
chartProps?: ComponentProps<typeof RadialBarChart>;
|
|
54
|
+
/** The arc shape — a full ring, or the half circle a gauge wants. */
|
|
55
|
+
variant?: RadialVariant;
|
|
56
|
+
/**
|
|
57
|
+
* What a full sweep is worth.
|
|
58
|
+
*
|
|
59
|
+
* Without it the scale comes from the data, so the largest bar always fills
|
|
60
|
+
* the arc — which is right for a comparison and wrong for a gauge. Set it
|
|
61
|
+
* (typically 100) whenever a single value has to read against a fixed total,
|
|
62
|
+
* or "62%" and "98%" will look identical.
|
|
63
|
+
*/
|
|
64
|
+
max?: number;
|
|
65
|
+
/** Where the arc starts, from the centre. */
|
|
66
|
+
innerRadius?: number | string;
|
|
67
|
+
/** Where the arc ends. */
|
|
68
|
+
outerRadius?: number | string;
|
|
69
|
+
/** The bar lit on first render. */
|
|
70
|
+
defaultSelectedBar?: string | null;
|
|
71
|
+
/** Fires when the selection changes, and with null when it is cleared. */
|
|
72
|
+
onSelectionChange?: (selection: {
|
|
73
|
+
name: string;
|
|
74
|
+
value: number;
|
|
75
|
+
} | null) => void;
|
|
76
|
+
/**
|
|
77
|
+
* Swaps the marks for an animated skeleton, keeping the measured height so
|
|
78
|
+
* the page does not jump when the data lands.
|
|
79
|
+
*/
|
|
80
|
+
isLoading?: boolean;
|
|
81
|
+
/** The row field holding each bar's number. Used by the table view. */
|
|
82
|
+
valueKey?: keyof TData & string;
|
|
83
|
+
/**
|
|
84
|
+
* Drops the hidden table view. Only correct when the page prints the data
|
|
85
|
+
* itself.
|
|
86
|
+
*/
|
|
87
|
+
hideDataTable?: boolean;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Values on an arc — a gauge, or a small set of totals against one scale.
|
|
91
|
+
*
|
|
92
|
+
* The caveat worth knowing before reaching for it: a radial bar's LENGTH is its
|
|
93
|
+
* value, but its RADIUS is not, so an inner bar and an outer bar of the same
|
|
94
|
+
* value are drawn different lengths. That makes it a poor comparison and a good
|
|
95
|
+
* single-value gauge; past about four bars, a `<BarChart>` is the honest choice.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* <RadialChart title="Storage used" config={config} data={data} nameKey="tier" max={100}>
|
|
99
|
+
* <RadialChart.RadialBar dataKey="used" />
|
|
100
|
+
* <RadialChart.Tooltip />
|
|
101
|
+
* </RadialChart>
|
|
102
|
+
*/
|
|
103
|
+
declare function RadialChart<TData extends Record<string, unknown>>({ config, data, nameKey, title, showTitle, description, children, className, chartProps, variant, max, innerRadius, outerRadius, defaultSelectedBar, onSelectionChange, isLoading, valueKey, hideDataTable, }: RadialChartProps<TData>): react.JSX.Element;
|
|
104
|
+
declare namespace RadialChart {
|
|
105
|
+
var RadialBar: ({ dataKey, cornerRadius, barSize, showTrack, isClickable, radialBarProps, }: RadialBarProps) => react.JSX.Element | null;
|
|
106
|
+
var Tooltip: ({ variant, roundness, defaultIndex }: ChartTooltipSlotProps) => react.JSX.Element | null;
|
|
107
|
+
var Legend: ({ variant, align, verticalAlign, isClickable, }: ChartLegendSlotProps) => react.JSX.Element | null;
|
|
108
|
+
var Background: ({ variant }: {
|
|
109
|
+
variant?: ChartBackgroundVariant;
|
|
110
|
+
}) => react.JSX.Element | null;
|
|
111
|
+
}
|
|
112
|
+
interface RadialBarProps {
|
|
113
|
+
/** The row field holding each bar's number. */
|
|
114
|
+
dataKey: string;
|
|
115
|
+
cornerRadius?: number;
|
|
116
|
+
/** How thick each arc is, in pixels. */
|
|
117
|
+
barSize?: number;
|
|
118
|
+
/** Draws the unfilled remainder behind each bar. Required reading for a gauge. */
|
|
119
|
+
showTrack?: boolean;
|
|
120
|
+
isClickable?: boolean;
|
|
121
|
+
radialBarProps?: Omit<ComponentProps<typeof RadialBar>, 'dataKey'>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export { type RadialBarProps, RadialChart, type RadialChartProps, type RadialVariant, RadialChart as default };
|