@spatika/react 1.0.0 → 1.2.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/AGENTS.md +71 -0
- package/README.md +4 -3
- package/dist/composites/AccentRule.d.ts +6 -0
- package/dist/composites/AccentRule.d.ts.map +1 -0
- package/dist/composites/AccentRule.js +6 -0
- package/dist/composites/AvailabilityBadge.d.ts +9 -0
- package/dist/composites/AvailabilityBadge.d.ts.map +1 -0
- package/dist/composites/AvailabilityBadge.js +9 -0
- package/dist/composites/Card.d.ts +7 -1
- package/dist/composites/Card.d.ts.map +1 -1
- package/dist/composites/Card.js +10 -0
- package/dist/composites/CareerCard.d.ts +20 -0
- package/dist/composites/CareerCard.d.ts.map +1 -0
- package/dist/composites/CareerCard.js +17 -0
- package/dist/composites/ChartDataGrid.d.ts +33 -0
- package/dist/composites/ChartDataGrid.d.ts.map +1 -0
- package/dist/composites/ChartDataGrid.js +77 -0
- package/dist/composites/ContactLink.d.ts +15 -0
- package/dist/composites/ContactLink.d.ts.map +1 -0
- package/dist/composites/ContactLink.js +8 -0
- package/dist/composites/CoverHero.d.ts +1 -1
- package/dist/composites/CoverHero.d.ts.map +1 -1
- package/dist/composites/CoverHero.js +2 -2
- package/dist/composites/DisplayHeading.d.ts +9 -0
- package/dist/composites/DisplayHeading.d.ts.map +1 -0
- package/dist/composites/DisplayHeading.js +6 -0
- package/dist/composites/EntityMediaCard.d.ts +1 -1
- package/dist/composites/EntityMediaCard.d.ts.map +1 -1
- package/dist/composites/EntityMediaCard.js +12 -4
- package/dist/composites/EventCalendar.d.ts +35 -0
- package/dist/composites/EventCalendar.d.ts.map +1 -0
- package/dist/composites/EventCalendar.js +339 -0
- package/dist/composites/EventEditor.d.ts +22 -0
- package/dist/composites/EventEditor.d.ts.map +1 -0
- package/dist/composites/EventEditor.js +86 -0
- package/dist/composites/EventTimeline.d.ts +24 -0
- package/dist/composites/EventTimeline.d.ts.map +1 -0
- package/dist/composites/EventTimeline.js +184 -0
- package/dist/composites/FloatChip.d.ts +15 -0
- package/dist/composites/FloatChip.d.ts.map +1 -0
- package/dist/composites/FloatChip.js +7 -0
- package/dist/composites/GradientText.d.ts +11 -0
- package/dist/composites/GradientText.d.ts.map +1 -0
- package/dist/composites/GradientText.js +6 -0
- package/dist/composites/IconTile.d.ts +10 -0
- package/dist/composites/IconTile.d.ts.map +1 -0
- package/dist/composites/IconTile.js +7 -0
- package/dist/composites/MapChart.d.ts +24 -0
- package/dist/composites/MapChart.d.ts.map +1 -0
- package/dist/composites/MapChart.js +58 -0
- package/dist/composites/MetaChip.d.ts +9 -0
- package/dist/composites/MetaChip.d.ts.map +1 -0
- package/dist/composites/MetaChip.js +6 -0
- package/dist/composites/PresenceDot.d.ts +10 -0
- package/dist/composites/PresenceDot.d.ts.map +1 -0
- package/dist/composites/PresenceDot.js +10 -0
- package/dist/composites/ProfileHero.d.ts +6 -4
- package/dist/composites/ProfileHero.d.ts.map +1 -1
- package/dist/composites/ProfileHero.js +8 -8
- package/dist/composites/ProjectCard.d.ts +12 -0
- package/dist/composites/ProjectCard.d.ts.map +1 -0
- package/dist/composites/ProjectCard.js +9 -0
- package/dist/composites/ScatterWebGL.d.ts +22 -0
- package/dist/composites/ScatterWebGL.d.ts.map +1 -0
- package/dist/composites/ScatterWebGL.js +45 -0
- package/dist/composites/SectionHeading.d.ts +16 -0
- package/dist/composites/SectionHeading.d.ts.map +1 -0
- package/dist/composites/SectionHeading.js +12 -0
- package/dist/composites/SiteFooter.d.ts +18 -0
- package/dist/composites/SiteFooter.d.ts.map +1 -0
- package/dist/composites/SiteFooter.js +15 -0
- package/dist/composites/SiteNav.d.ts +25 -0
- package/dist/composites/SiteNav.d.ts.map +1 -0
- package/dist/composites/SiteNav.js +44 -0
- package/dist/composites/StatCard.d.ts +7 -1
- package/dist/composites/StatCard.d.ts.map +1 -1
- package/dist/composites/StatCard.js +5 -2
- package/dist/composites/StatusDot.d.ts +1 -1
- package/dist/composites/Tag.d.ts +11 -0
- package/dist/composites/Tag.d.ts.map +1 -0
- package/dist/composites/Tag.js +33 -0
- package/dist/composites/Wordmark.d.ts +19 -0
- package/dist/composites/Wordmark.d.ts.map +1 -0
- package/dist/composites/Wordmark.js +15 -0
- package/dist/composites/cartesian-charts.d.ts +138 -0
- package/dist/composites/cartesian-charts.d.ts.map +1 -0
- package/dist/composites/cartesian-charts.js +401 -0
- package/dist/composites/chart-composition.d.ts +139 -0
- package/dist/composites/chart-composition.d.ts.map +1 -0
- package/dist/composites/chart-composition.js +486 -0
- package/dist/composites/chart-ui.d.ts +83 -0
- package/dist/composites/chart-ui.d.ts.map +1 -0
- package/dist/composites/chart-ui.js +108 -0
- package/dist/composites/charts-3d.d.ts +37 -0
- package/dist/composites/charts-3d.d.ts.map +1 -0
- package/dist/composites/charts-3d.js +121 -0
- package/dist/composites/flow-charts.d.ts +89 -0
- package/dist/composites/flow-charts.d.ts.map +1 -0
- package/dist/composites/flow-charts.js +186 -0
- package/dist/composites/radial-charts.d.ts +109 -0
- package/dist/composites/radial-charts.d.ts.map +1 -0
- package/dist/composites/radial-charts.js +176 -0
- package/dist/composites/scheduler-ui.d.ts +43 -0
- package/dist/composites/scheduler-ui.d.ts.map +1 -0
- package/dist/composites/scheduler-ui.js +71 -0
- package/dist/index.d.ts +83 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +74 -7
- package/dist/lib/chart-export.d.ts +10 -0
- package/dist/lib/chart-export.d.ts.map +1 -0
- package/dist/lib/chart-export.js +102 -0
- package/dist/lib/charts.d.ts +235 -0
- package/dist/lib/charts.d.ts.map +1 -0
- package/dist/lib/charts.js +744 -0
- package/dist/lib/geo.d.ts +39 -0
- package/dist/lib/geo.d.ts.map +1 -0
- package/dist/lib/geo.js +101 -0
- package/dist/lib/iso.d.ts +21 -0
- package/dist/lib/iso.d.ts.map +1 -0
- package/dist/lib/iso.js +56 -0
- package/dist/lib/rrule.d.ts +20 -0
- package/dist/lib/rrule.d.ts.map +1 -0
- package/dist/lib/rrule.js +236 -0
- package/dist/lib/scheduler.d.ts +152 -0
- package/dist/lib/scheduler.d.ts.map +1 -0
- package/dist/lib/scheduler.js +501 -0
- package/dist/lib/webgl-scatter.d.ts +44 -0
- package/dist/lib/webgl-scatter.d.ts.map +1 -0
- package/dist/lib/webgl-scatter.js +185 -0
- package/dist/primitives/Accordion.d.ts +44 -20
- package/dist/primitives/Accordion.d.ts.map +1 -1
- package/dist/primitives/Accordion.js +82 -22
- package/dist/primitives/AppBar.d.ts +13 -0
- package/dist/primitives/AppBar.d.ts.map +1 -0
- package/dist/primitives/AppBar.js +27 -0
- package/dist/primitives/Autocomplete.d.ts +28 -0
- package/dist/primitives/Autocomplete.d.ts.map +1 -0
- package/dist/primitives/Autocomplete.js +118 -0
- package/dist/primitives/Avatar.d.ts +13 -1
- package/dist/primitives/Avatar.d.ts.map +1 -1
- package/dist/primitives/Avatar.js +17 -2
- package/dist/primitives/Backdrop.d.ts +17 -0
- package/dist/primitives/Backdrop.d.ts.map +1 -0
- package/dist/primitives/Backdrop.js +17 -0
- package/dist/primitives/BottomNavigation.d.ts +23 -0
- package/dist/primitives/BottomNavigation.d.ts.map +1 -0
- package/dist/primitives/BottomNavigation.js +30 -0
- package/dist/primitives/Button.d.ts +4 -4
- package/dist/primitives/Button.d.ts.map +1 -1
- package/dist/primitives/Button.js +2 -0
- package/dist/primitives/ButtonBase.d.ts +14 -0
- package/dist/primitives/ButtonBase.d.ts.map +1 -0
- package/dist/primitives/ButtonBase.js +13 -0
- package/dist/primitives/ButtonGroup.d.ts +25 -0
- package/dist/primitives/ButtonGroup.d.ts.map +1 -0
- package/dist/primitives/ButtonGroup.js +44 -0
- package/dist/primitives/CircularProgress.d.ts +16 -0
- package/dist/primitives/CircularProgress.d.ts.map +1 -0
- package/dist/primitives/CircularProgress.js +17 -0
- package/dist/primitives/ClickAwayListener.d.ts +16 -0
- package/dist/primitives/ClickAwayListener.d.ts.map +1 -0
- package/dist/primitives/ClickAwayListener.js +33 -0
- package/dist/primitives/Collapse.d.ts +19 -0
- package/dist/primitives/Collapse.d.ts.map +1 -0
- package/dist/primitives/Collapse.js +14 -0
- package/dist/primitives/Container.d.ts +13 -0
- package/dist/primitives/Container.d.ts.map +1 -0
- package/dist/primitives/Container.js +26 -0
- package/dist/primitives/Fab.d.ts +22 -0
- package/dist/primitives/Fab.d.ts.map +1 -0
- package/dist/primitives/Fab.js +42 -0
- package/dist/primitives/FormControl.d.ts +27 -0
- package/dist/primitives/FormControl.d.ts.map +1 -0
- package/dist/primitives/FormControl.js +24 -0
- package/dist/primitives/FormControlLabel.d.ts +18 -0
- package/dist/primitives/FormControlLabel.d.ts.map +1 -0
- package/dist/primitives/FormControlLabel.js +19 -0
- package/dist/primitives/Grid.d.ts +32 -0
- package/dist/primitives/Grid.d.ts.map +1 -0
- package/dist/primitives/Grid.js +50 -0
- package/dist/primitives/IconButton.d.ts +22 -0
- package/dist/primitives/IconButton.d.ts.map +1 -0
- package/dist/primitives/IconButton.js +39 -0
- package/dist/primitives/ImageList.d.ts +31 -0
- package/dist/primitives/ImageList.d.ts.map +1 -0
- package/dist/primitives/ImageList.js +33 -0
- package/dist/primitives/InputAdornment.d.ts +28 -0
- package/dist/primitives/InputAdornment.d.ts.map +1 -0
- package/dist/primitives/InputAdornment.js +13 -0
- package/dist/primitives/Link.d.ts +17 -0
- package/dist/primitives/Link.d.ts.map +1 -0
- package/dist/primitives/Link.js +29 -0
- package/dist/primitives/List.d.ts +41 -0
- package/dist/primitives/List.d.ts.map +1 -0
- package/dist/primitives/List.js +22 -0
- package/dist/primitives/Masonry.d.ts +14 -0
- package/dist/primitives/Masonry.d.ts.map +1 -0
- package/dist/primitives/Masonry.js +15 -0
- package/dist/primitives/Menu.d.ts +28 -0
- package/dist/primitives/Menu.d.ts.map +1 -0
- package/dist/primitives/Menu.js +54 -0
- package/dist/primitives/MobileStepper.d.ts +15 -0
- package/dist/primitives/MobileStepper.d.ts.map +1 -0
- package/dist/primitives/MobileStepper.js +8 -0
- package/dist/primitives/Modal.d.ts +18 -0
- package/dist/primitives/Modal.d.ts.map +1 -0
- package/dist/primitives/Modal.js +29 -0
- package/dist/primitives/NoSsr.d.ts +15 -0
- package/dist/primitives/NoSsr.d.ts.map +1 -0
- package/dist/primitives/NoSsr.js +19 -0
- package/dist/primitives/Paper.d.ts +22 -0
- package/dist/primitives/Paper.d.ts.map +1 -0
- package/dist/primitives/Paper.js +33 -0
- package/dist/primitives/Progress.d.ts +6 -2
- package/dist/primitives/Progress.d.ts.map +1 -1
- package/dist/primitives/Progress.js +8 -3
- package/dist/primitives/Snackbar.d.ts +23 -0
- package/dist/primitives/Snackbar.d.ts.map +1 -0
- package/dist/primitives/Snackbar.js +33 -0
- package/dist/primitives/SpeedDial.d.ts +26 -0
- package/dist/primitives/SpeedDial.d.ts.map +1 -0
- package/dist/primitives/SpeedDial.js +26 -0
- package/dist/primitives/Stack.d.ts +15 -0
- package/dist/primitives/Stack.d.ts.map +1 -0
- package/dist/primitives/Stack.js +45 -0
- package/dist/primitives/StarRating.d.ts +19 -1
- package/dist/primitives/StarRating.d.ts.map +1 -1
- package/dist/primitives/StarRating.js +36 -6
- package/dist/primitives/Stepper.d.ts +36 -0
- package/dist/primitives/Stepper.d.ts.map +1 -0
- package/dist/primitives/Stepper.js +53 -0
- package/dist/primitives/TablePagination.d.ts +16 -0
- package/dist/primitives/TablePagination.d.ts.map +1 -0
- package/dist/primitives/TablePagination.js +12 -0
- package/dist/primitives/TextField.d.ts +24 -0
- package/dist/primitives/TextField.d.ts.map +1 -0
- package/dist/primitives/TextField.js +19 -0
- package/dist/primitives/TextareaAutosize.d.ts +11 -0
- package/dist/primitives/TextareaAutosize.d.ts.map +1 -0
- package/dist/primitives/TextareaAutosize.js +26 -0
- package/dist/primitives/ToggleButton.d.ts +28 -0
- package/dist/primitives/ToggleButton.d.ts.map +1 -0
- package/dist/primitives/ToggleButton.js +56 -0
- package/dist/primitives/TransferList.d.ts +21 -0
- package/dist/primitives/TransferList.d.ts.map +1 -0
- package/dist/primitives/TransferList.js +40 -0
- package/dist/primitives/Typography.d.ts +23 -0
- package/dist/primitives/Typography.d.ts.map +1 -0
- package/dist/primitives/Typography.js +69 -0
- package/dist/primitives/transitions.d.ts +29 -0
- package/dist/primitives/transitions.d.ts.map +1 -0
- package/dist/primitives/transitions.js +52 -0
- package/package.json +30 -5
- package/skills/spatika-ui/SKILL.md +96 -0
- package/src/composites/AccentRule.tsx +12 -0
- package/src/composites/AvailabilityBadge.tsx +32 -0
- package/src/composites/Card.tsx +51 -1
- package/src/composites/CareerCard.tsx +111 -0
- package/src/composites/ChartDataGrid.test.tsx +57 -0
- package/src/composites/ChartDataGrid.tsx +196 -0
- package/src/composites/ContactLink.tsx +66 -0
- package/src/composites/CoverHero.test.tsx +38 -0
- package/src/composites/CoverHero.tsx +29 -22
- package/src/composites/DisplayHeading.tsx +27 -0
- package/src/composites/EntityMediaCard.test.tsx +58 -0
- package/src/composites/EntityMediaCard.tsx +31 -13
- package/src/composites/EventCalendar.tsx +928 -0
- package/src/composites/EventEditor.tsx +268 -0
- package/src/composites/EventTimeline.tsx +357 -0
- package/src/composites/FloatChip.tsx +63 -0
- package/src/composites/GradientText.tsx +31 -0
- package/src/composites/IconTile.tsx +33 -0
- package/src/composites/MapChart.test.tsx +39 -0
- package/src/composites/MapChart.tsx +130 -0
- package/src/composites/MetaChip.tsx +24 -0
- package/src/composites/PresenceDot.tsx +42 -0
- package/src/composites/ProfileHero.test.tsx +33 -0
- package/src/composites/ProfileHero.tsx +96 -79
- package/src/composites/ProjectCard.tsx +65 -0
- package/src/composites/ScatterWebGL.test.tsx +25 -0
- package/src/composites/ScatterWebGL.tsx +79 -0
- package/src/composites/SectionHeading.tsx +61 -0
- package/src/composites/SiteFooter.test.tsx +37 -0
- package/src/composites/SiteFooter.tsx +79 -0
- package/src/composites/SiteNav.test.tsx +46 -0
- package/src/composites/SiteNav.tsx +150 -0
- package/src/composites/StatCard.test.tsx +30 -0
- package/src/composites/StatCard.tsx +36 -1
- package/src/composites/Tag.tsx +50 -0
- package/src/composites/Wordmark.test.tsx +23 -0
- package/src/composites/Wordmark.tsx +46 -0
- package/src/composites/cartesian-charts.test.tsx +52 -0
- package/src/composites/cartesian-charts.tsx +1287 -0
- package/src/composites/chart-composition.test.tsx +53 -0
- package/src/composites/chart-composition.tsx +898 -0
- package/src/composites/chart-ui.tsx +328 -0
- package/src/composites/charts-3d.test.tsx +25 -0
- package/src/composites/charts-3d.tsx +318 -0
- package/src/composites/charts.test.tsx +254 -0
- package/src/composites/chrome.test.tsx +29 -0
- package/src/composites/flow-charts.test.tsx +79 -0
- package/src/composites/flow-charts.tsx +607 -0
- package/src/composites/marketing.test.tsx +192 -0
- package/src/composites/radial-charts.test.tsx +74 -0
- package/src/composites/radial-charts.tsx +617 -0
- package/src/composites/scheduler-ui.tsx +304 -0
- package/src/composites/scheduler.test.tsx +194 -0
- package/src/index.test.ts +22 -0
- package/src/index.ts +300 -5
- package/src/lib/chart-export.test.ts +20 -0
- package/src/lib/chart-export.ts +99 -0
- package/src/lib/charts-platform.test.ts +93 -0
- package/src/lib/charts.test.ts +132 -0
- package/src/lib/charts.ts +1021 -0
- package/src/lib/geo.test.ts +42 -0
- package/src/lib/geo.ts +138 -0
- package/src/lib/iso.test.ts +22 -0
- package/src/lib/iso.ts +102 -0
- package/src/lib/rrule.test.ts +53 -0
- package/src/lib/rrule.ts +281 -0
- package/src/lib/scheduler.test.ts +186 -0
- package/src/lib/scheduler.ts +688 -0
- package/src/lib/tokens.test.ts +2 -2
- package/src/lib/webgl-scatter.test.ts +36 -0
- package/src/lib/webgl-scatter.ts +230 -0
- package/src/primitives/Accordion.tsx +218 -63
- package/src/primitives/AppBar.tsx +39 -0
- package/src/primitives/Autocomplete.tsx +236 -0
- package/src/primitives/Avatar.tsx +52 -1
- package/src/primitives/Backdrop.tsx +48 -0
- package/src/primitives/BottomNavigation.tsx +102 -0
- package/src/primitives/Button.tsx +3 -0
- package/src/primitives/ButtonBase.tsx +34 -0
- package/src/primitives/ButtonGroup.tsx +90 -0
- package/src/primitives/CircularProgress.tsx +104 -0
- package/src/primitives/ClickAwayListener.tsx +46 -0
- package/src/primitives/Collapse.tsx +39 -0
- package/src/primitives/Container.tsx +40 -0
- package/src/primitives/Fab.tsx +62 -0
- package/src/primitives/FormControl.tsx +90 -0
- package/src/primitives/FormControlLabel.tsx +51 -0
- package/src/primitives/Grid.tsx +101 -0
- package/src/primitives/IconButton.tsx +59 -0
- package/src/primitives/ImageList.test.tsx +48 -0
- package/src/primitives/ImageList.tsx +112 -0
- package/src/primitives/InputAdornment.tsx +86 -0
- package/src/primitives/Link.tsx +48 -0
- package/src/primitives/List.tsx +121 -0
- package/src/primitives/Masonry.tsx +32 -0
- package/src/primitives/Menu.tsx +112 -0
- package/src/primitives/MobileStepper.tsx +64 -0
- package/src/primitives/Modal.tsx +70 -0
- package/src/primitives/NoSsr.tsx +28 -0
- package/src/primitives/Paper.tsx +55 -0
- package/src/primitives/Progress.tsx +25 -7
- package/src/primitives/Snackbar.tsx +83 -0
- package/src/primitives/SpeedDial.tsx +110 -0
- package/src/primitives/Stack.tsx +88 -0
- package/src/primitives/StarRating.tsx +87 -28
- package/src/primitives/Stepper.tsx +184 -0
- package/src/primitives/TablePagination.tsx +58 -0
- package/src/primitives/TextField.tsx +105 -0
- package/src/primitives/TextareaAutosize.tsx +49 -0
- package/src/primitives/ToggleButton.tsx +148 -0
- package/src/primitives/TransferList.tsx +110 -0
- package/src/primitives/Typography.tsx +90 -0
- package/src/primitives/mui-more.test.tsx +76 -0
- package/src/primitives/mui.test.tsx +134 -0
- package/src/primitives/transitions.tsx +120 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState, } from "react";
|
|
3
|
+
import { cn } from "../lib/cn";
|
|
4
|
+
import { DEFAULT_CHART_MARGIN, chartColor, formatAxisValue, formatChartNumber, } from "../lib/charts";
|
|
5
|
+
export function resolveMargin(margin) {
|
|
6
|
+
return {
|
|
7
|
+
top: margin?.top ?? DEFAULT_CHART_MARGIN.top,
|
|
8
|
+
right: margin?.right ?? DEFAULT_CHART_MARGIN.right,
|
|
9
|
+
bottom: margin?.bottom ?? DEFAULT_CHART_MARGIN.bottom,
|
|
10
|
+
left: margin?.left ?? DEFAULT_CHART_MARGIN.left,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function useElementSize(ref, fallbackWidth, fallbackHeight) {
|
|
14
|
+
const [size, setSize] = useState({ width: fallbackWidth, height: fallbackHeight });
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const el = ref.current;
|
|
17
|
+
if (!el)
|
|
18
|
+
return;
|
|
19
|
+
const apply = () => {
|
|
20
|
+
setSize({
|
|
21
|
+
width: el.clientWidth || fallbackWidth,
|
|
22
|
+
height: el.clientHeight || fallbackHeight,
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
apply();
|
|
26
|
+
if (typeof ResizeObserver === "undefined")
|
|
27
|
+
return;
|
|
28
|
+
const observer = new ResizeObserver(apply);
|
|
29
|
+
observer.observe(el);
|
|
30
|
+
return () => observer.disconnect();
|
|
31
|
+
}, [fallbackWidth, fallbackHeight, ref]);
|
|
32
|
+
return size;
|
|
33
|
+
}
|
|
34
|
+
export function ChartFrame({ slot, className, width, height = 280, margin, legend, hiddenIds, onToggleSeries, hover, "aria-label": ariaLabel, children, }) {
|
|
35
|
+
const surfaceRef = useRef(null);
|
|
36
|
+
const measured = useElementSize(surfaceRef, width ?? 320, height);
|
|
37
|
+
const plotWidth = width ?? measured.width;
|
|
38
|
+
const plotHeight = height;
|
|
39
|
+
const m = resolveMargin(margin);
|
|
40
|
+
return (_jsxs("div", { "data-slot": slot, className: cn("spk-chart", className), role: "img", "aria-label": ariaLabel, children: [legend?.length ? (_jsx(ChartLegend, { items: legend, hiddenIds: hiddenIds, onToggle: onToggleSeries })) : null, _jsxs("div", { ref: surfaceRef, className: "spk-chart-surface", style: { height: plotHeight }, children: [plotWidth > 0 ? children({ width: plotWidth, height: plotHeight, m }) : null, _jsx(ChartTooltip, { hover: hover ?? null, boundsWidth: plotWidth })] })] }));
|
|
41
|
+
}
|
|
42
|
+
export function ChartLegend({ items, hiddenIds, onToggle, }) {
|
|
43
|
+
return (_jsx("div", { className: "spk-chart-legend", children: items.map((item) => (_jsxs("button", { type: "button", className: "spk-chart-legend-item", "data-hidden": hiddenIds?.has(item.id) ? "true" : undefined, onClick: () => onToggle?.(item.id), children: [_jsx("span", { className: "spk-chart-swatch", style: { background: item.color } }), item.label] }, item.id))) }));
|
|
44
|
+
}
|
|
45
|
+
export function ChartTooltip({ hover, boundsWidth, }) {
|
|
46
|
+
if (!hover || !hover.items.length)
|
|
47
|
+
return null;
|
|
48
|
+
const left = clampTooltip(hover.x, boundsWidth);
|
|
49
|
+
return (_jsxs("div", { className: "spk-chart-tooltip", style: { left, top: hover.y }, role: "tooltip", children: [hover.title ? _jsx("p", { className: "spk-chart-tooltip-title", children: hover.title }) : null, _jsx("ul", { children: hover.items.map((item) => (_jsxs("li", { children: [_jsx("span", { className: "spk-chart-swatch", style: { background: item.color } }), _jsx("span", { children: item.label }), _jsx("strong", { children: item.value })] }, item.label))) })] }));
|
|
50
|
+
}
|
|
51
|
+
function clampTooltip(x, width) {
|
|
52
|
+
return clampNum(x, 72, Math.max(72, width - 72));
|
|
53
|
+
}
|
|
54
|
+
function clampNum(value, min, max) {
|
|
55
|
+
return Math.min(max, Math.max(min, value));
|
|
56
|
+
}
|
|
57
|
+
export function CartesianGrid({ ticks, scale, left, right, top, bottom, }) {
|
|
58
|
+
return (_jsxs("g", { "data-slot": "chart-grid", children: [ticks.map((tick) => (_jsx("line", { className: "spk-chart-grid", x1: left, x2: right, y1: scale(tick), y2: scale(tick) }, tick))), _jsx("line", { className: "spk-chart-axis", x1: left, x2: right, y1: bottom, y2: bottom }), _jsx("line", { className: "spk-chart-axis", x1: left, x2: left, y1: top, y2: bottom })] }));
|
|
59
|
+
}
|
|
60
|
+
export function ValueAxis({ ticks, scale, left, width, }) {
|
|
61
|
+
return (_jsxs("g", { "data-slot": "chart-y-axis", children: [ticks.map((tick) => (_jsx("text", { className: "spk-chart-tick", x: left - 8, y: scale(tick), textAnchor: "end", dominantBaseline: "middle", children: formatChartNumber(tick) }, tick))), width ? (_jsx("text", { className: "spk-chart-axis-label", x: 12, y: width / 2, transform: `rotate(-90 12 ${width / 2})`, textAnchor: "middle" })) : null] }));
|
|
62
|
+
}
|
|
63
|
+
export function CategoryAxis({ labels, position, y, }) {
|
|
64
|
+
const maxLabels = labels.length > 12 ? Math.ceil(labels.length / 8) : 1;
|
|
65
|
+
return (_jsx("g", { "data-slot": "chart-x-axis", children: labels.map((label, index) => {
|
|
66
|
+
if (index % maxLabels !== 0)
|
|
67
|
+
return null;
|
|
68
|
+
return (_jsx("text", { className: "spk-chart-tick", x: position(index), y: y + 16, textAnchor: "middle", children: formatAxisValue(label) }, `${index}-${String(label)}`));
|
|
69
|
+
}) }));
|
|
70
|
+
}
|
|
71
|
+
export function useHiddenSeries(ids) {
|
|
72
|
+
const [hidden, setHidden] = useState(new Set());
|
|
73
|
+
const toggle = (id) => {
|
|
74
|
+
setHidden((current) => {
|
|
75
|
+
const next = new Set(current);
|
|
76
|
+
if (next.has(id))
|
|
77
|
+
next.delete(id);
|
|
78
|
+
else
|
|
79
|
+
next.add(id);
|
|
80
|
+
return next;
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
const visible = ids.filter((id) => !hidden.has(id));
|
|
84
|
+
return { hidden, toggle, visible };
|
|
85
|
+
}
|
|
86
|
+
export function seriesMeta(series, colors) {
|
|
87
|
+
return series.map((item, index) => ({
|
|
88
|
+
id: item.id ?? item.label ?? `series-${index}`,
|
|
89
|
+
label: item.label ?? item.id ?? `Series ${index + 1}`,
|
|
90
|
+
color: item.color ?? chartColor(index, colors),
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
export function useChartHover() {
|
|
94
|
+
const [hover, setHover] = useState(null);
|
|
95
|
+
return { hover, setHover, clear: () => setHover(null) };
|
|
96
|
+
}
|
|
97
|
+
export function categoryLabels(axis, length = 0) {
|
|
98
|
+
if (axis?.data?.length)
|
|
99
|
+
return axis.data;
|
|
100
|
+
return Array.from({ length }, (_, i) => i + 1);
|
|
101
|
+
}
|
|
102
|
+
export function formatSeriesValue(value) {
|
|
103
|
+
if (value == null)
|
|
104
|
+
return "—";
|
|
105
|
+
if (Array.isArray(value))
|
|
106
|
+
return `${formatChartNumber(value[0])} – ${formatChartNumber(value[1])}`;
|
|
107
|
+
return formatChartNumber(value);
|
|
108
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ChartAxisConfig, type ChartMargin } from "../lib/charts";
|
|
2
|
+
import type { NumericSeries } from "./cartesian-charts";
|
|
3
|
+
export type BarChart3DProps = {
|
|
4
|
+
series: NumericSeries[];
|
|
5
|
+
xAxis?: ChartAxisConfig[];
|
|
6
|
+
yAxis?: ChartAxisConfig[];
|
|
7
|
+
height?: number;
|
|
8
|
+
width?: number;
|
|
9
|
+
colors?: string[];
|
|
10
|
+
hideLegend?: boolean;
|
|
11
|
+
hideGrid?: boolean;
|
|
12
|
+
margin?: ChartMargin;
|
|
13
|
+
className?: string;
|
|
14
|
+
depth?: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function BarChart3D({ series, xAxis, yAxis, height, width, colors, hideLegend, hideGrid, margin, className, depth, }: BarChart3DProps): import("react").JSX.Element;
|
|
17
|
+
export type PieChart3DProps = {
|
|
18
|
+
series: Array<{
|
|
19
|
+
data: Array<{
|
|
20
|
+
id?: string | number;
|
|
21
|
+
value: number;
|
|
22
|
+
label?: string;
|
|
23
|
+
color?: string;
|
|
24
|
+
}>;
|
|
25
|
+
innerRadius?: number;
|
|
26
|
+
paddingAngle?: number;
|
|
27
|
+
}>;
|
|
28
|
+
height?: number;
|
|
29
|
+
width?: number;
|
|
30
|
+
colors?: string[];
|
|
31
|
+
hideLegend?: boolean;
|
|
32
|
+
margin?: ChartMargin;
|
|
33
|
+
className?: string;
|
|
34
|
+
thickness?: number;
|
|
35
|
+
};
|
|
36
|
+
export declare function PieChart3D({ series, height, width, colors, hideLegend, margin, className, thickness, }: PieChart3DProps): import("react").JSX.Element;
|
|
37
|
+
//# sourceMappingURL=charts-3d.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"charts-3d.d.ts","sourceRoot":"","sources":["../../src/composites/charts-3d.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,eAAe,EACpB,KAAK,WAAW,EACjB,MAAM,eAAe,CAAC;AAWvB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAaxD,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,KAAK,CAAC,EAAE,eAAe,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,eAAe,EAAE,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,KAAK,EACL,KAAK,EACL,MAAY,EACZ,KAAK,EACL,MAAM,EACN,UAAU,EACV,QAAQ,EACR,MAAM,EACN,SAAS,EACT,KAAU,GACX,EAAE,eAAe,+BAiHjB;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,KAAK,CAAC;YAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QACrF,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC,CAAC;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,MAAY,EACZ,KAAK,EACL,MAAM,EACN,UAAU,EACV,MAAM,EACN,SAAS,EACT,SAAc,GACf,EAAE,eAAe,+BAoHjB"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { extent, formatChartNumber, niceTicks, pieSlices, } from "../lib/charts";
|
|
3
|
+
import { ellipseSlicePath, ellipseWallPath, isoBoxFaces, isoPoint } from "../lib/iso";
|
|
4
|
+
import { CartesianGrid, ChartFrame, categoryLabels, formatSeriesValue, seriesMeta, useChartHover, useHiddenSeries, } from "./chart-ui";
|
|
5
|
+
function box(width, height, m) {
|
|
6
|
+
return {
|
|
7
|
+
left: m.left,
|
|
8
|
+
right: width - m.right,
|
|
9
|
+
top: m.top,
|
|
10
|
+
bottom: height - m.bottom,
|
|
11
|
+
iw: Math.max(1, width - m.left - m.right),
|
|
12
|
+
ih: Math.max(1, height - m.top - m.bottom),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function BarChart3D({ series, xAxis, yAxis, height = 280, width, colors, hideLegend, hideGrid, margin, className, depth = 14, }) {
|
|
16
|
+
const meta = seriesMeta(series, colors);
|
|
17
|
+
const ids = meta.map((item) => item.id);
|
|
18
|
+
const { hidden, toggle } = useHiddenSeries(ids);
|
|
19
|
+
const { hover, setHover, clear } = useChartHover();
|
|
20
|
+
const categories = categoryLabels(xAxis?.[0], series[0]?.data?.length ?? 0);
|
|
21
|
+
const values = series.flatMap((item) => (item.data ?? []).map((v) => v ?? 0));
|
|
22
|
+
const domain = [
|
|
23
|
+
yAxis?.[0]?.min ?? Math.min(0, extent(values, 0.08)[0]),
|
|
24
|
+
yAxis?.[0]?.max ?? extent(values, 0.08)[1],
|
|
25
|
+
];
|
|
26
|
+
const ticks = niceTicks(domain[0], domain[1], 4);
|
|
27
|
+
return (_jsx(ChartFrame, { slot: "bar-chart-3d", className: className, width: width, height: height, margin: margin ?? { top: 24, right: 28, bottom: 40, left: 48 }, legend: hideLegend ? undefined : meta, hiddenIds: hidden, onToggleSeries: toggle, hover: hover, "aria-label": "3D bar chart", children: ({ width: w, height: h, m }) => {
|
|
28
|
+
const plot = box(w, h, m);
|
|
29
|
+
const originX = plot.left + plot.iw * 0.16;
|
|
30
|
+
const originY = plot.bottom - 6;
|
|
31
|
+
const visible = series
|
|
32
|
+
.map((item, s) => ({ item, info: meta[s], s }))
|
|
33
|
+
.filter(({ info }) => !hidden.has(info.id));
|
|
34
|
+
const n = Math.max(categories.length, 1);
|
|
35
|
+
const groupW = Math.max(18, (plot.iw * 0.72) / n);
|
|
36
|
+
const barW = Math.max(8, (groupW * 0.78) / Math.max(visible.length, 1));
|
|
37
|
+
const gap = Math.max(2, (groupW - barW * visible.length) / Math.max(visible.length + 1, 1));
|
|
38
|
+
const maxH = plot.ih * 0.78;
|
|
39
|
+
const yScale = (value) => ((value - domain[0]) / (domain[1] - domain[0] || 1)) * maxH;
|
|
40
|
+
const yAt = (value) => originY - yScale(value);
|
|
41
|
+
return (_jsxs("svg", { width: w, height: h, viewBox: `0 0 ${w} ${h}`, children: [hideGrid ? null : (_jsx(CartesianGrid, { ticks: ticks, scale: yAt, left: plot.left, right: plot.right, top: plot.top, bottom: plot.bottom })), ticks.map((tick) => (_jsx("text", { className: "spk-chart-tick", x: plot.left - 8, y: yAt(tick), textAnchor: "end", children: formatChartNumber(tick) }, tick))), categories.map((label, i) => {
|
|
42
|
+
const x0 = i * groupW;
|
|
43
|
+
const foot = isoPoint(x0 + groupW / 2, 0, depth, originX, originY);
|
|
44
|
+
return (_jsx("text", { className: "spk-chart-tick", x: foot.x, y: plot.bottom + 16, textAnchor: "middle", children: String(label) }, String(label)));
|
|
45
|
+
}), categories.flatMap((_, i) => visible.map(({ item, info }, s) => {
|
|
46
|
+
const value = item.data?.[i] ?? 0;
|
|
47
|
+
const barH = Math.max(2, yScale(value));
|
|
48
|
+
const x = i * groupW + gap + s * (barW + gap * 0.2);
|
|
49
|
+
const faces = isoBoxFaces(x, 0, 0, barW, barH, depth, originX, originY);
|
|
50
|
+
const color = info.color;
|
|
51
|
+
return (_jsxs("g", { className: "spk-chart-mark", onMouseEnter: (event) => setHover({
|
|
52
|
+
x: event.nativeEvent.offsetX,
|
|
53
|
+
y: event.nativeEvent.offsetY,
|
|
54
|
+
title: String(categories[i]),
|
|
55
|
+
items: [
|
|
56
|
+
{
|
|
57
|
+
color,
|
|
58
|
+
label: info.label,
|
|
59
|
+
value: formatSeriesValue(value),
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
}), onMouseLeave: clear, children: [_jsx("path", { d: faces.side, fill: `color-mix(in srgb, ${color} 78%, black)` }), _jsx("path", { d: faces.top, fill: `color-mix(in srgb, ${color} 72%, white)` }), _jsx("path", { d: faces.front, fill: color })] }, `${info.id}-${i}`));
|
|
63
|
+
}))] }));
|
|
64
|
+
} }));
|
|
65
|
+
}
|
|
66
|
+
export function PieChart3D({ series, height = 280, width, colors, hideLegend, margin, className, thickness = 18, }) {
|
|
67
|
+
const first = series[0] ?? { data: [] };
|
|
68
|
+
const meta = seriesMeta(first.data.map((item, i) => ({
|
|
69
|
+
id: String(item.id ?? item.label ?? i),
|
|
70
|
+
label: item.label ?? `Slice ${i + 1}`,
|
|
71
|
+
color: item.color,
|
|
72
|
+
})), colors);
|
|
73
|
+
const ids = meta.map((item) => item.id);
|
|
74
|
+
const { hidden, toggle } = useHiddenSeries(ids);
|
|
75
|
+
const { hover, setHover, clear } = useChartHover();
|
|
76
|
+
return (_jsx(ChartFrame, { slot: "pie-chart-3d", className: className, width: width, height: height, margin: margin ?? { top: 12, right: 12, bottom: 20, left: 12 }, legend: hideLegend ? undefined : meta, hiddenIds: hidden, onToggleSeries: toggle, hover: hover, "aria-label": "3D pie chart", children: ({ width: w, height: h, m }) => {
|
|
77
|
+
const cx = w / 2;
|
|
78
|
+
const cy = (h - thickness) / 2;
|
|
79
|
+
const rx = Math.min(w - m.left - m.right, (h - m.top - m.bottom - thickness) * 1.7) / 2;
|
|
80
|
+
const ry = rx * 0.42;
|
|
81
|
+
const visible = first.data.map((item, i) => (hidden.has(meta[i].id) ? 0 : item.value));
|
|
82
|
+
const slices = pieSlices(visible, {
|
|
83
|
+
cx,
|
|
84
|
+
cy,
|
|
85
|
+
innerRadius: 0,
|
|
86
|
+
outerRadius: rx,
|
|
87
|
+
paddingAngle: first.paddingAngle,
|
|
88
|
+
});
|
|
89
|
+
const ordered = slices
|
|
90
|
+
.map((slice, i) => ({ slice, info: meta[i], item: first.data[i] }))
|
|
91
|
+
.filter(({ info, slice }) => !hidden.has(info.id) && slice.path)
|
|
92
|
+
.sort((a, b) => ellipsePointY(cx, cy, rx, ry, a.slice.midAngle) - ellipsePointY(cx, cy, rx, ry, b.slice.midAngle));
|
|
93
|
+
return (_jsxs("svg", { width: w, height: h, viewBox: `0 0 ${w} ${h}`, children: [ordered.map(({ slice, info, item }) => (_jsx("g", { className: "spk-chart-mark", onMouseEnter: (event) => setHover({
|
|
94
|
+
x: event.nativeEvent.offsetX,
|
|
95
|
+
y: event.nativeEvent.offsetY,
|
|
96
|
+
title: info.label,
|
|
97
|
+
items: [
|
|
98
|
+
{
|
|
99
|
+
color: info.color,
|
|
100
|
+
label: info.label,
|
|
101
|
+
value: `${formatChartNumber(item.value)} (${Math.round(slice.percent * 100)}%)`,
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
}), onMouseLeave: clear, children: _jsx("path", { d: ellipseWallPath(cx, cy, rx, ry, slice.startAngle, slice.endAngle, thickness), fill: `color-mix(in srgb, ${info.color} 70%, black)` }) }, `${info.id}-wall`))), ordered.map(({ slice, info, item }) => (_jsxs("g", { className: "spk-chart-mark", onMouseEnter: (event) => setHover({
|
|
105
|
+
x: event.nativeEvent.offsetX,
|
|
106
|
+
y: event.nativeEvent.offsetY,
|
|
107
|
+
title: info.label,
|
|
108
|
+
items: [
|
|
109
|
+
{
|
|
110
|
+
color: info.color,
|
|
111
|
+
label: info.label,
|
|
112
|
+
value: `${formatChartNumber(item.value)} (${Math.round(slice.percent * 100)}%)`,
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
}), onMouseLeave: clear, children: [_jsx("path", { d: ellipseSlicePath(cx, cy, rx, ry, slice.startAngle, slice.endAngle), fill: info.color }), slice.percent > 0.08 ? (_jsxs("text", { className: "spk-chart-label", x: cx + Math.cos(((slice.midAngle - 90) * Math.PI) / 180) * rx * 0.55, y: cy + Math.sin(((slice.midAngle - 90) * Math.PI) / 180) * ry * 0.55, textAnchor: "middle", dominantBaseline: "middle", fill: "var(--primary-foreground)", children: [Math.round(slice.percent * 100), "%"] })) : null] }, info.id)))] }));
|
|
116
|
+
} }));
|
|
117
|
+
}
|
|
118
|
+
function ellipsePointY(cx, cy, rx, ry, angleDeg) {
|
|
119
|
+
const rad = ((angleDeg - 90) * Math.PI) / 180;
|
|
120
|
+
return cy + ry * Math.sin(rad);
|
|
121
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type ChartAxisConfig, type ChartMargin, type SankeyLink, type SankeyNode, type TreeNode } from "../lib/charts";
|
|
2
|
+
export type HeatDatum = {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
value: number;
|
|
6
|
+
};
|
|
7
|
+
export type HeatmapProps = {
|
|
8
|
+
xAxis?: ChartAxisConfig[];
|
|
9
|
+
yAxis?: ChartAxisConfig[];
|
|
10
|
+
series: Array<{
|
|
11
|
+
data: HeatDatum[];
|
|
12
|
+
}>;
|
|
13
|
+
height?: number;
|
|
14
|
+
width?: number;
|
|
15
|
+
hideLegend?: boolean;
|
|
16
|
+
showColorScale?: boolean;
|
|
17
|
+
margin?: ChartMargin;
|
|
18
|
+
className?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function Heatmap({ xAxis, yAxis, series, height, width, hideLegend, showColorScale, margin, className, }: HeatmapProps): import("react").JSX.Element;
|
|
21
|
+
export type FunnelDatum = {
|
|
22
|
+
id?: string;
|
|
23
|
+
label: string;
|
|
24
|
+
value: number;
|
|
25
|
+
color?: string;
|
|
26
|
+
};
|
|
27
|
+
export type FunnelSeries = {
|
|
28
|
+
id?: string;
|
|
29
|
+
label?: string;
|
|
30
|
+
data: FunnelDatum[];
|
|
31
|
+
};
|
|
32
|
+
export type FunnelLabelPosition = "inside" | "outside" | "both";
|
|
33
|
+
export type FunnelChartProps = {
|
|
34
|
+
series: FunnelSeries[];
|
|
35
|
+
height?: number;
|
|
36
|
+
width?: number;
|
|
37
|
+
colors?: string[];
|
|
38
|
+
hideLegend?: boolean;
|
|
39
|
+
className?: string;
|
|
40
|
+
variant?: "funnel" | "pyramid";
|
|
41
|
+
gap?: number;
|
|
42
|
+
labelPosition?: FunnelLabelPosition;
|
|
43
|
+
valueFormatter?: (value: number, percent: number) => string;
|
|
44
|
+
};
|
|
45
|
+
export declare function FunnelChart({ series, height, width, colors, hideLegend, className, variant, gap, labelPosition, valueFormatter, }: FunnelChartProps): import("react").JSX.Element;
|
|
46
|
+
export declare function PyramidChart(props: FunnelChartProps): import("react").JSX.Element;
|
|
47
|
+
export type SankeyChartProps = {
|
|
48
|
+
series: {
|
|
49
|
+
data: SankeyNode[];
|
|
50
|
+
links: SankeyLink[];
|
|
51
|
+
};
|
|
52
|
+
height?: number;
|
|
53
|
+
width?: number;
|
|
54
|
+
colors?: string[];
|
|
55
|
+
className?: string;
|
|
56
|
+
};
|
|
57
|
+
export declare function SankeyChart({ series, height, width, colors, className }: SankeyChartProps): import("react").JSX.Element;
|
|
58
|
+
export type TreemapProps = {
|
|
59
|
+
series: Array<{
|
|
60
|
+
data: TreeNode[];
|
|
61
|
+
}>;
|
|
62
|
+
height?: number;
|
|
63
|
+
width?: number;
|
|
64
|
+
colors?: string[];
|
|
65
|
+
className?: string;
|
|
66
|
+
};
|
|
67
|
+
export declare function Treemap({ series, height, width, colors, className }: TreemapProps): import("react").JSX.Element;
|
|
68
|
+
export type SunburstChartProps = {
|
|
69
|
+
series: Array<{
|
|
70
|
+
data: TreeNode[];
|
|
71
|
+
}>;
|
|
72
|
+
height?: number;
|
|
73
|
+
width?: number;
|
|
74
|
+
colors?: string[];
|
|
75
|
+
className?: string;
|
|
76
|
+
};
|
|
77
|
+
export declare function SunburstChart({ series, height, width, colors, className }: SunburstChartProps): import("react").JSX.Element;
|
|
78
|
+
export type ChordChartProps = {
|
|
79
|
+
series: {
|
|
80
|
+
data: string[];
|
|
81
|
+
matrix: number[][];
|
|
82
|
+
};
|
|
83
|
+
height?: number;
|
|
84
|
+
width?: number;
|
|
85
|
+
colors?: string[];
|
|
86
|
+
className?: string;
|
|
87
|
+
};
|
|
88
|
+
export declare function ChordChart({ series, height, width, colors, className }: ChordChartProps): import("react").JSX.Element;
|
|
89
|
+
//# sourceMappingURL=flow-charts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-charts.d.ts","sourceRoot":"","sources":["../../src/composites/flow-charts.tsx"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
import { chartColor, chordLayout, formatChartNumber, funnelLayout, heatColor, pyramidLayout, sankeyLayout, squarify, sunburstLayout, } from "../lib/charts";
|
|
4
|
+
import { ChartFrame, categoryLabels, seriesMeta, useChartHover, useHiddenSeries, } from "./chart-ui";
|
|
5
|
+
export function Heatmap({ xAxis, yAxis, series, height = 280, width, hideLegend, showColorScale, margin, className, }) {
|
|
6
|
+
const cells = series[0]?.data ?? [];
|
|
7
|
+
const xs = categoryLabels(xAxis?.[0], Math.max(...cells.map((c) => c.x), 0) + 1);
|
|
8
|
+
const ys = categoryLabels(yAxis?.[0], Math.max(...cells.map((c) => c.y), 0) + 1);
|
|
9
|
+
const values = cells.map((c) => c.value);
|
|
10
|
+
const min = Math.min(...values, 0);
|
|
11
|
+
const max = Math.max(...values, 1);
|
|
12
|
+
const { hover, setHover, clear } = useChartHover();
|
|
13
|
+
const reactId = useId().replace(/:/g, "");
|
|
14
|
+
const scaleId = `spk-heat-scale-${reactId}`;
|
|
15
|
+
const colorScale = showColorScale ?? !hideLegend;
|
|
16
|
+
return (_jsx(ChartFrame, { slot: "heatmap", className: className, width: width, height: height, margin: margin ?? { top: colorScale ? 32 : 12, right: 12, bottom: 36, left: 72 }, hover: hover, "aria-label": "Heatmap", children: ({ width: w, height: h, m }) => {
|
|
17
|
+
const iw = Math.max(1, w - m.left - m.right);
|
|
18
|
+
const ih = Math.max(1, h - m.top - m.bottom);
|
|
19
|
+
const cw = iw / Math.max(xs.length, 1);
|
|
20
|
+
const ch = ih / Math.max(ys.length, 1);
|
|
21
|
+
return (_jsxs("svg", { width: w, height: h, viewBox: `0 0 ${w} ${h}`, children: [colorScale ? (_jsxs("g", { className: "spk-chart-color-scale", "data-slot": "heatmap-color-scale", children: [_jsx("defs", { children: _jsxs("linearGradient", { id: scaleId, x1: "0", y1: "0", x2: "1", y2: "0", children: [_jsx("stop", { offset: "0%", stopColor: heatColor(0) }), _jsx("stop", { offset: "50%", stopColor: heatColor(0.5) }), _jsx("stop", { offset: "100%", stopColor: heatColor(1) })] }) }), _jsx("text", { className: "spk-chart-muted", x: m.left, y: m.top - 16, children: formatChartNumber(min) }), _jsx("text", { className: "spk-chart-muted", x: m.left + iw, y: m.top - 16, textAnchor: "end", children: formatChartNumber(max) }), _jsx("rect", { x: m.left, y: m.top - 12, width: iw, height: 6, rx: 3, fill: `url(#${scaleId})` })] })) : null, ys.map((label, y) => (_jsx("text", { className: "spk-chart-tick", x: m.left - 8, y: m.top + y * ch + ch / 2, textAnchor: "end", dominantBaseline: "middle", children: String(label) }, `y-${String(label)}`))), xs.map((label, x) => (_jsx("text", { className: "spk-chart-tick", x: m.left + x * cw + cw / 2, y: h - m.bottom + 16, textAnchor: "middle", children: String(label) }, `x-${String(label)}`))), cells.map((cell, i) => {
|
|
22
|
+
const t = (cell.value - min) / (max - min || 1);
|
|
23
|
+
return (_jsx("rect", { x: m.left + cell.x * cw + 1.5, y: m.top + cell.y * ch + 1.5, width: Math.max(1, cw - 3), height: Math.max(1, ch - 3), rx: 4, fill: heatColor(t), className: "spk-chart-mark", onMouseEnter: (event) => setHover({
|
|
24
|
+
x: event.nativeEvent.offsetX,
|
|
25
|
+
y: event.nativeEvent.offsetY,
|
|
26
|
+
title: `${xs[cell.x]} · ${ys[cell.y]}`,
|
|
27
|
+
items: [
|
|
28
|
+
{
|
|
29
|
+
color: heatColor(t),
|
|
30
|
+
label: "value",
|
|
31
|
+
value: formatChartNumber(cell.value),
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
}), onMouseLeave: clear }, i));
|
|
35
|
+
})] }));
|
|
36
|
+
} }));
|
|
37
|
+
}
|
|
38
|
+
export function FunnelChart({ series, height = 300, width, colors, hideLegend, className, variant = "funnel", gap = 6, labelPosition, valueFormatter, }) {
|
|
39
|
+
const stages = series[0]?.data ?? [];
|
|
40
|
+
const comparison = series.length > 1;
|
|
41
|
+
const position = labelPosition ?? (comparison ? "both" : "inside");
|
|
42
|
+
const formatValue = valueFormatter ?? ((value) => formatChartNumber(value));
|
|
43
|
+
const meta = seriesMeta(stages.map((item) => ({ id: item.id ?? item.label, label: item.label, color: item.color })), colors);
|
|
44
|
+
const { hover, setHover, clear } = useChartHover();
|
|
45
|
+
const ids = meta.map((item) => item.id);
|
|
46
|
+
const { hidden, toggle } = useHiddenSeries(ids);
|
|
47
|
+
const showInside = position === "inside" || position === "both";
|
|
48
|
+
const showOutside = position === "outside" || position === "both";
|
|
49
|
+
return (_jsx(ChartFrame, { slot: variant === "pyramid" ? "pyramid-chart" : "funnel-chart", className: className, width: width, height: height, margin: {
|
|
50
|
+
top: 8,
|
|
51
|
+
right: showOutside ? 56 : 8,
|
|
52
|
+
bottom: 8,
|
|
53
|
+
left: 8,
|
|
54
|
+
}, legend: hideLegend ? undefined : meta, hiddenIds: hidden, onToggleSeries: toggle, hover: hover, "aria-label": variant === "pyramid" ? "Pyramid chart" : "Funnel chart", children: ({ width: w, height: h, m }) => {
|
|
55
|
+
const visibleIndexes = stages
|
|
56
|
+
.map((_, i) => i)
|
|
57
|
+
.filter((i) => !hidden.has(meta[i].id));
|
|
58
|
+
const visibleSeries = series.map((item) => ({
|
|
59
|
+
...item,
|
|
60
|
+
data: visibleIndexes.map((i) => item.data[i]).filter((row) => row != null),
|
|
61
|
+
}));
|
|
62
|
+
const maxValue = Math.max(...visibleSeries.flatMap((item) => item.data.map((row) => row.value)), 1);
|
|
63
|
+
const innerW = w - m.left - m.right;
|
|
64
|
+
const innerH = h - m.top - m.bottom;
|
|
65
|
+
const layouts = visibleSeries.map((item) => {
|
|
66
|
+
const rows = item.data.map((row, i) => ({
|
|
67
|
+
...row,
|
|
68
|
+
color: meta[visibleIndexes[i] ?? i]?.color,
|
|
69
|
+
}));
|
|
70
|
+
return variant === "pyramid"
|
|
71
|
+
? pyramidLayout(rows, innerW, innerH)
|
|
72
|
+
: funnelLayout(rows, innerW, innerH, gap, maxValue);
|
|
73
|
+
});
|
|
74
|
+
const drawOrder = layouts.map((_, i) => i).sort((a, b) => (a === 0 ? 1 : b === 0 ? -1 : a - b));
|
|
75
|
+
return (_jsx("svg", { width: w, height: h, viewBox: `0 0 ${w} ${h}`, children: drawOrder.flatMap((seriesIndex) => {
|
|
76
|
+
const layout = layouts[seriesIndex] ?? [];
|
|
77
|
+
const primary = seriesIndex === 0;
|
|
78
|
+
return layout.map((row, i) => {
|
|
79
|
+
const info = meta.find((item) => item.label === row.label) ?? meta[visibleIndexes[i] ?? i];
|
|
80
|
+
const d = `M${m.left + row.topLeft} ${m.top + row.y} L${m.left + row.topRight} ${m.top + row.y} L${m.left + row.bottomRight} ${m.top + row.y + row.height} L${m.left + row.bottomLeft} ${m.top + row.y + row.height} Z`;
|
|
81
|
+
const valueText = formatValue(row.value, row.percent);
|
|
82
|
+
const inside = showInside &&
|
|
83
|
+
primary &&
|
|
84
|
+
(hideLegend && !comparison ? row.label : valueText);
|
|
85
|
+
const outside = showOutside && !primary ? valueText : showOutside && !comparison ? valueText : null;
|
|
86
|
+
return (_jsxs("g", { children: [_jsx("path", { d: d, fill: info.color, fillOpacity: primary ? 1 : 0.14, stroke: primary ? "none" : info.color, strokeWidth: primary ? 0 : 1.75, className: "spk-chart-mark", onMouseEnter: (event) => setHover({
|
|
87
|
+
x: event.nativeEvent.offsetX,
|
|
88
|
+
y: event.nativeEvent.offsetY,
|
|
89
|
+
title: row.label,
|
|
90
|
+
items: [
|
|
91
|
+
{
|
|
92
|
+
color: info.color,
|
|
93
|
+
label: visibleSeries[seriesIndex]?.label ?? row.label,
|
|
94
|
+
value: formatChartNumber(row.value),
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
}), onMouseLeave: clear }), inside ? (_jsx("text", { className: "spk-chart-label", fill: "var(--primary-foreground)", x: w / 2, y: m.top + row.y + row.height / 2, textAnchor: "middle", dominantBaseline: "middle", children: inside })) : null, outside ? (_jsx("text", { className: "spk-chart-tick", x: m.left + Math.max(row.topRight, row.bottomRight) + 8, y: m.top + row.y + row.height / 2, dominantBaseline: "middle", children: outside })) : null] }, `${seriesIndex}-${row.label}`));
|
|
98
|
+
});
|
|
99
|
+
}) }));
|
|
100
|
+
} }));
|
|
101
|
+
}
|
|
102
|
+
export function PyramidChart(props) {
|
|
103
|
+
return _jsx(FunnelChart, { ...props, variant: "pyramid" });
|
|
104
|
+
}
|
|
105
|
+
export function SankeyChart({ series, height = 300, width, colors, className }) {
|
|
106
|
+
const { hover, setHover, clear } = useChartHover();
|
|
107
|
+
return (_jsx(ChartFrame, { slot: "sankey-chart", className: className, width: width, height: height, margin: { top: 12, right: 88, bottom: 12, left: 12 }, hover: hover, "aria-label": "Sankey chart", children: ({ width: w, height: h, m }) => {
|
|
108
|
+
const layout = sankeyLayout(series.data, series.links, w - m.left - m.right, h - m.top - m.bottom);
|
|
109
|
+
return (_jsxs("svg", { width: w, height: h, viewBox: `0 0 ${w} ${h}`, children: [layout.links.map((link, i) => (_jsx("path", { d: link.path, transform: `translate(${m.left} ${m.top})`, fill: chartColor(i, colors), fillOpacity: 0.28, className: "spk-chart-mark", onMouseEnter: (event) => setHover({
|
|
110
|
+
x: event.nativeEvent.offsetX,
|
|
111
|
+
y: event.nativeEvent.offsetY,
|
|
112
|
+
title: `${link.source} → ${link.target}`,
|
|
113
|
+
items: [
|
|
114
|
+
{
|
|
115
|
+
color: chartColor(i, colors),
|
|
116
|
+
label: "flow",
|
|
117
|
+
value: formatChartNumber(link.value),
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
}), onMouseLeave: clear }, `${link.source}-${link.target}-${i}`))), layout.nodes.map((node, i) => (_jsxs("g", { transform: `translate(${m.left} ${m.top})`, children: [_jsx("rect", { x: node.x, y: node.y, width: node.width, height: node.height, rx: 4, fill: node.color ?? chartColor(i, colors) }), _jsx("text", { className: "spk-chart-tick", x: node.x + node.width + 6, y: node.y + node.height / 2, dominantBaseline: "middle", children: node.label })] }, node.id)))] }));
|
|
121
|
+
} }));
|
|
122
|
+
}
|
|
123
|
+
export function Treemap({ series, height = 280, width, colors, className }) {
|
|
124
|
+
const { hover, setHover, clear } = useChartHover();
|
|
125
|
+
const data = series[0]?.data ?? [];
|
|
126
|
+
return (_jsx(ChartFrame, { slot: "treemap", className: className, width: width, height: height, margin: { top: 4, right: 4, bottom: 4, left: 4 }, hover: hover, "aria-label": "Treemap", children: ({ width: w, height: h, m }) => {
|
|
127
|
+
const rects = squarify(data, 0, 0, w - m.left - m.right, h - m.top - m.bottom);
|
|
128
|
+
return (_jsx("svg", { width: w, height: h, viewBox: `0 0 ${w} ${h}`, children: rects.map((rect, i) => (_jsxs("g", { transform: `translate(${m.left} ${m.top})`, children: [_jsx("rect", { x: rect.x + 1.5, y: rect.y + 1.5, width: Math.max(0, rect.w - 3), height: Math.max(0, rect.h - 3), rx: 8, fill: rect.color ?? chartColor(i, colors), className: "spk-chart-mark", onMouseEnter: (event) => setHover({
|
|
129
|
+
x: event.nativeEvent.offsetX,
|
|
130
|
+
y: event.nativeEvent.offsetY,
|
|
131
|
+
title: rect.label,
|
|
132
|
+
items: [
|
|
133
|
+
{
|
|
134
|
+
color: rect.color ?? chartColor(i, colors),
|
|
135
|
+
label: rect.label,
|
|
136
|
+
value: formatChartNumber(rect.value),
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
}), onMouseLeave: clear }), rect.w > 56 && rect.h > 28 ? (_jsx("text", { className: "spk-chart-label", x: rect.x + 10, y: rect.y + 20, children: rect.label })) : null] }, rect.id))) }));
|
|
140
|
+
} }));
|
|
141
|
+
}
|
|
142
|
+
export function SunburstChart({ series, height = 300, width, colors, className }) {
|
|
143
|
+
const { hover, setHover, clear } = useChartHover();
|
|
144
|
+
const data = series[0]?.data ?? [];
|
|
145
|
+
return (_jsx(ChartFrame, { slot: "sunburst-chart", className: className, width: width, height: height, margin: { top: 8, right: 8, bottom: 8, left: 8 }, hover: hover, "aria-label": "Sunburst chart", children: ({ width: w, height: h }) => {
|
|
146
|
+
const cx = w / 2;
|
|
147
|
+
const cy = h / 2;
|
|
148
|
+
const outer = Math.min(w, h) * 0.42;
|
|
149
|
+
const slices = sunburstLayout(data, cx, cy, outer * 0.22, outer);
|
|
150
|
+
return (_jsx("svg", { width: w, height: h, viewBox: `0 0 ${w} ${h}`, children: slices.map((slice, i) => (_jsx("path", { d: slice.path, fill: slice.color ?? chartColor(slice.depth + i, colors), stroke: "var(--background)", strokeWidth: 1.5, className: "spk-chart-mark", onMouseEnter: (event) => setHover({
|
|
151
|
+
x: event.nativeEvent.offsetX,
|
|
152
|
+
y: event.nativeEvent.offsetY,
|
|
153
|
+
title: slice.label,
|
|
154
|
+
items: [
|
|
155
|
+
{
|
|
156
|
+
color: slice.color ?? chartColor(i, colors),
|
|
157
|
+
label: slice.label,
|
|
158
|
+
value: formatChartNumber(slice.value),
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
}), onMouseLeave: clear }, `${slice.id}-${i}`))) }));
|
|
162
|
+
} }));
|
|
163
|
+
}
|
|
164
|
+
export function ChordChart({ series, height = 300, width, colors, className }) {
|
|
165
|
+
const { hover, setHover, clear } = useChartHover();
|
|
166
|
+
const meta = seriesMeta(series.data.map((label) => ({ id: label, label })), colors);
|
|
167
|
+
return (_jsx(ChartFrame, { slot: "chord-chart", className: className, width: width, height: height, margin: { top: 24, right: 24, bottom: 24, left: 24 }, legend: meta, hover: hover, "aria-label": "Chord chart", children: ({ width: w, height: h }) => {
|
|
168
|
+
const cx = w / 2;
|
|
169
|
+
const cy = h / 2;
|
|
170
|
+
const outer = Math.min(w, h) * 0.38;
|
|
171
|
+
const inner = outer * 0.9;
|
|
172
|
+
const layout = chordLayout(series.data, series.matrix, cx, cy, inner, outer);
|
|
173
|
+
return (_jsxs("svg", { width: w, height: h, viewBox: `0 0 ${w} ${h}`, children: [layout.ribbons.map((ribbon, i) => (_jsx("path", { d: ribbon.path, fill: chartColor(ribbon.source, colors), fillOpacity: 0.28, className: "spk-chart-mark", onMouseEnter: (event) => setHover({
|
|
174
|
+
x: event.nativeEvent.offsetX,
|
|
175
|
+
y: event.nativeEvent.offsetY,
|
|
176
|
+
title: `${series.data[ribbon.source]} → ${series.data[ribbon.target]}`,
|
|
177
|
+
items: [
|
|
178
|
+
{
|
|
179
|
+
color: chartColor(ribbon.source, colors),
|
|
180
|
+
label: "flow",
|
|
181
|
+
value: formatChartNumber(ribbon.value),
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
}), onMouseLeave: clear }, `${ribbon.source}-${ribbon.target}-${i}`))), layout.groups.map((group) => (_jsx("path", { d: group.path, fill: chartColor(group.index, colors) }, group.label)))] }));
|
|
185
|
+
} }));
|
|
186
|
+
}
|