@seekalfred/primitives 0.6.0 → 0.7.3
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 +214 -15
- package/dist/activity-heatmap/activity-heatmap.d.ts +92 -0
- package/dist/activity-heatmap/activity-heatmap.js +699 -0
- package/dist/activity-heatmap/activity-heatmap.js.map +1 -0
- package/dist/activity-heatmap/index.d.ts +2 -0
- package/dist/activity-heatmap/index.js +2 -0
- package/dist/alert/alert.d.ts +53 -4
- package/dist/alert/alert.js +100 -11
- package/dist/alert/alert.js.map +1 -1
- package/dist/alert/index.d.ts +2 -2
- package/dist/alert/index.js +2 -2
- package/dist/alert-dialog/alert-dialog.d.ts +58 -18
- package/dist/alert-dialog/alert-dialog.js +152 -9
- package/dist/alert-dialog/alert-dialog.js.map +1 -1
- package/dist/alert-dialog/index.d.ts +2 -2
- package/dist/alert-dialog/index.js +2 -2
- package/dist/animated-counter/animated-counter.d.ts +38 -0
- package/dist/animated-counter/animated-counter.js +230 -0
- package/dist/animated-counter/animated-counter.js.map +1 -0
- package/dist/animated-counter/index.d.ts +2 -0
- package/dist/animated-counter/index.js +2 -0
- package/dist/announcement-bar/announcement-bar.d.ts +67 -0
- package/dist/announcement-bar/announcement-bar.js +364 -0
- package/dist/announcement-bar/announcement-bar.js.map +1 -0
- package/dist/announcement-bar/index.d.ts +2 -0
- package/dist/announcement-bar/index.js +2 -0
- package/dist/badge/badge.d.ts +1 -1
- package/dist/bar-chart/bar-chart.d.ts +51 -0
- package/dist/bar-chart/bar-chart.js +565 -0
- package/dist/bar-chart/bar-chart.js.map +1 -0
- package/dist/bar-chart/index.d.ts +2 -0
- package/dist/bar-chart/index.js +2 -0
- package/dist/breadcrumb/breadcrumb.d.ts +2 -2
- package/dist/breadcrumb/breadcrumb.js +12 -3
- package/dist/breadcrumb/breadcrumb.js.map +1 -1
- package/dist/brush-chart/brush-chart.d.ts +64 -0
- package/dist/brush-chart/brush-chart.js +1056 -0
- package/dist/brush-chart/brush-chart.js.map +1 -0
- package/dist/brush-chart/index.d.ts +2 -0
- package/dist/brush-chart/index.js +2 -0
- package/dist/button/button.d.ts +1 -1
- package/dist/button/button.js +31 -21
- package/dist/button/button.js.map +1 -1
- package/dist/button-group/button-group.js +3 -4
- package/dist/button-group/button-group.js.map +1 -1
- package/dist/calendar/calendar.d.ts +1 -1
- package/dist/card/card.d.ts +22 -1
- package/dist/card/card.js +60 -7
- package/dist/card/card.js.map +1 -1
- package/dist/card-stack/card-stack.d.ts +54 -0
- package/dist/card-stack/card-stack.js +492 -0
- package/dist/card-stack/card-stack.js.map +1 -0
- package/dist/card-stack/index.d.ts +2 -0
- package/dist/card-stack/index.js +2 -0
- package/dist/carousel/carousel.d.ts +77 -0
- package/dist/carousel/carousel.js +415 -0
- package/dist/carousel/carousel.js.map +1 -0
- package/dist/carousel/index.d.ts +2 -0
- package/dist/carousel/index.js +2 -0
- package/dist/checkbox/checkbox.js +4 -4
- package/dist/checkbox/checkbox.js.map +1 -1
- package/dist/chip-group/chip-group.d.ts +37 -0
- package/dist/chip-group/chip-group.js +148 -0
- package/dist/chip-group/chip-group.js.map +1 -0
- package/dist/chip-group/index.d.ts +2 -0
- package/dist/chip-group/index.js +2 -0
- package/dist/copy-button/copy-button.d.ts +18 -2
- package/dist/copy-button/copy-button.js +29 -8
- package/dist/copy-button/copy-button.js.map +1 -1
- package/dist/countdown/countdown.d.ts +45 -0
- package/dist/countdown/countdown.js +298 -0
- package/dist/countdown/countdown.js.map +1 -0
- package/dist/countdown/index.d.ts +2 -0
- package/dist/countdown/index.js +2 -0
- package/dist/date-picker/picker-parts.js +1 -1
- package/dist/date-picker/picker-parts.js.map +1 -1
- package/dist/dialog/dialog.js +1 -1
- package/dist/dialog/dialog.js.map +1 -1
- package/dist/donut-chart/donut-chart.d.ts +86 -0
- package/dist/donut-chart/donut-chart.js +593 -0
- package/dist/donut-chart/donut-chart.js.map +1 -0
- package/dist/donut-chart/index.d.ts +2 -0
- package/dist/donut-chart/index.js +2 -0
- package/dist/empty-state/empty-state.d.ts +42 -10
- package/dist/empty-state/empty-state.js +44 -26
- package/dist/empty-state/empty-state.js.map +1 -1
- package/dist/empty-state/index.d.ts +2 -2
- package/dist/empty-state/index.js +2 -2
- package/dist/file-drop-zone/file-drop-zone.js +1 -1
- package/dist/file-drop-zone/file-drop-zone.js.map +1 -1
- package/dist/filter-bar/filter-bar.d.ts +50 -26
- package/dist/filter-bar/filter-bar.js +317 -157
- package/dist/filter-bar/filter-bar.js.map +1 -1
- package/dist/gauge/gauge.d.ts +45 -0
- package/dist/gauge/gauge.js +219 -0
- package/dist/gauge/gauge.js.map +1 -0
- package/dist/gauge/index.d.ts +2 -0
- package/dist/gauge/index.js +2 -0
- package/dist/in-view-title/in-view-title.d.ts +33 -0
- package/dist/in-view-title/in-view-title.js +119 -0
- package/dist/in-view-title/in-view-title.js.map +1 -0
- package/dist/in-view-title/index.d.ts +2 -0
- package/dist/in-view-title/index.js +2 -0
- package/dist/index.d.ts +53 -10
- package/dist/index.js +52 -12
- package/dist/input/input.js +4 -4
- package/dist/input/input.js.map +1 -1
- package/dist/lib/cn.js +11 -1
- package/dist/lib/cn.js.map +1 -1
- package/dist/lib/field-message.js +28 -10
- package/dist/lib/field-message.js.map +1 -1
- package/dist/lib/field-shell.js +10 -3
- package/dist/lib/field-shell.js.map +1 -1
- package/dist/lib/field-surface.js +31 -9
- package/dist/lib/field-surface.js.map +1 -1
- package/dist/lib/flag-emoji.js +50 -0
- package/dist/lib/flag-emoji.js.map +1 -0
- package/dist/lib/flip.js +11 -3
- package/dist/lib/flip.js.map +1 -1
- package/dist/lib/menu-highlight.js +64 -0
- package/dist/lib/menu-highlight.js.map +1 -0
- package/dist/lib/motion.js +9 -2
- package/dist/lib/motion.js.map +1 -1
- package/dist/lib/rolling-value.js +1 -1
- package/dist/lib/rolling-value.js.map +1 -1
- package/dist/lib/spring-tween.js +500 -0
- package/dist/lib/spring-tween.js.map +1 -0
- package/dist/lib/swap-text.js +3 -1
- package/dist/lib/swap-text.js.map +1 -1
- package/dist/lib/use-copy-feedback.js +17 -3
- package/dist/lib/use-copy-feedback.js.map +1 -1
- package/dist/line-chart/index.d.ts +2 -0
- package/dist/line-chart/index.js +2 -0
- package/dist/line-chart/line-chart.d.ts +116 -0
- package/dist/line-chart/line-chart.js +740 -0
- package/dist/line-chart/line-chart.js.map +1 -0
- package/dist/mention-input/index.d.ts +2 -0
- package/dist/mention-input/index.js +2 -0
- package/dist/mention-input/mention-input.d.ts +98 -0
- package/dist/mention-input/mention-input.js +576 -0
- package/dist/mention-input/mention-input.js.map +1 -0
- package/dist/menu/menu.d.ts +2 -0
- package/dist/menu/menu.js +23 -12
- package/dist/menu/menu.js.map +1 -1
- package/dist/money-input/index.d.ts +2 -0
- package/dist/money-input/index.js +2 -0
- package/dist/money-input/money-input.d.ts +86 -0
- package/dist/money-input/money-input.js +613 -0
- package/dist/money-input/money-input.js.map +1 -0
- package/dist/morph-select/index.d.ts +2 -0
- package/dist/morph-select/index.js +2 -0
- package/dist/morph-select/morph-select.d.ts +89 -0
- package/dist/morph-select/morph-select.js +712 -0
- package/dist/morph-select/morph-select.js.map +1 -0
- package/dist/multi-select/index.d.ts +2 -0
- package/dist/multi-select/index.js +2 -0
- package/dist/multi-select/multi-select.d.ts +77 -0
- package/dist/multi-select/multi-select.js +209 -0
- package/dist/multi-select/multi-select.js.map +1 -0
- package/dist/number-field/index.d.ts +2 -0
- package/dist/number-field/index.js +2 -0
- package/dist/number-field/number-field.d.ts +42 -0
- package/dist/number-field/number-field.js +199 -0
- package/dist/number-field/number-field.js.map +1 -0
- package/dist/onboarding-checklist/index.d.ts +2 -0
- package/dist/onboarding-checklist/index.js +2 -0
- package/dist/onboarding-checklist/onboarding-checklist.d.ts +55 -0
- package/dist/onboarding-checklist/onboarding-checklist.js +577 -0
- package/dist/onboarding-checklist/onboarding-checklist.js.map +1 -0
- package/dist/password-field/password-field.d.ts +16 -0
- package/dist/password-field/password-field.js +39 -10
- package/dist/password-field/password-field.js.map +1 -1
- package/dist/phone-input/index.d.ts +3 -0
- package/dist/phone-input/index.js +3 -0
- package/dist/phone-input/phone-countries.d.ts +29 -0
- package/dist/phone-input/phone-countries.js +170 -0
- package/dist/phone-input/phone-countries.js.map +1 -0
- package/dist/phone-input/phone-input.d.ts +66 -0
- package/dist/phone-input/phone-input.js +440 -0
- package/dist/phone-input/phone-input.js.map +1 -0
- package/dist/popover/index.d.ts +2 -2
- package/dist/popover/index.js +2 -2
- package/dist/popover/popover.d.ts +51 -2
- package/dist/popover/popover.js +59 -8
- package/dist/popover/popover.js.map +1 -1
- package/dist/progress/progress.d.ts +16 -2
- package/dist/progress/progress.js +16 -9
- package/dist/progress/progress.js.map +1 -1
- package/dist/radio-group/index.d.ts +2 -2
- package/dist/radio-group/index.js +2 -2
- package/dist/radio-group/radio-group.d.ts +33 -3
- package/dist/radio-group/radio-group.js +110 -10
- package/dist/radio-group/radio-group.js.map +1 -1
- package/dist/reactions/index.d.ts +2 -0
- package/dist/reactions/index.js +2 -0
- package/dist/reactions/reactions.d.ts +50 -0
- package/dist/reactions/reactions.js +315 -0
- package/dist/reactions/reactions.js.map +1 -0
- package/dist/rich-text-editor/index.d.ts +3 -0
- package/dist/rich-text-editor/index.js +2 -0
- package/dist/rich-text-editor/rich-text-editor.d.ts +70 -0
- package/dist/rich-text-editor/rich-text-editor.js +909 -0
- package/dist/rich-text-editor/rich-text-editor.js.map +1 -0
- package/dist/rich-text-editor/rich-text-engine.d.ts +16 -0
- package/dist/rich-text-editor/rich-text-engine.js +366 -0
- package/dist/rich-text-editor/rich-text-engine.js.map +1 -0
- package/dist/rich-text-editor/rich-text-html.js +174 -0
- package/dist/rich-text-editor/rich-text-html.js.map +1 -0
- package/dist/rich-text-editor/rich-text-icons.js +43 -0
- package/dist/rich-text-editor/rich-text-icons.js.map +1 -0
- package/dist/ridgeline/index.d.ts +2 -0
- package/dist/ridgeline/index.js +2 -0
- package/dist/ridgeline/ridgeline.d.ts +55 -0
- package/dist/ridgeline/ridgeline.js +701 -0
- package/dist/ridgeline/ridgeline.js.map +1 -0
- package/dist/scroll-area/index.d.ts +2 -2
- package/dist/scroll-area/index.js +2 -2
- package/dist/scroll-area/scroll-area.d.ts +68 -31
- package/dist/scroll-area/scroll-area.js +212 -62
- package/dist/scroll-area/scroll-area.js.map +1 -1
- package/dist/scrub-input/evaluate.d.ts +14 -0
- package/dist/scrub-input/evaluate.js +72 -0
- package/dist/scrub-input/evaluate.js.map +1 -0
- package/dist/scrub-input/index.d.ts +3 -0
- package/dist/scrub-input/index.js +3 -0
- package/dist/scrub-input/scrub-input.d.ts +74 -0
- package/dist/scrub-input/scrub-input.js +486 -0
- package/dist/scrub-input/scrub-input.js.map +1 -0
- package/dist/search-field/search-field.d.ts +24 -2
- package/dist/search-field/search-field.js +24 -9
- package/dist/search-field/search-field.js.map +1 -1
- package/dist/select/select.d.ts +3 -1
- package/dist/select/select.js +28 -14
- package/dist/select/select.js.map +1 -1
- package/dist/separator/separator.d.ts +22 -10
- package/dist/separator/separator.js +33 -11
- package/dist/separator/separator.js.map +1 -1
- package/dist/sheet/sheet.js +2 -1
- package/dist/sheet/sheet.js.map +1 -1
- package/dist/shortcut-recorder/index.d.ts +3 -0
- package/dist/shortcut-recorder/index.js +3 -0
- package/dist/shortcut-recorder/shortcut-model.d.ts +27 -0
- package/dist/shortcut-recorder/shortcut-model.js +206 -0
- package/dist/shortcut-recorder/shortcut-model.js.map +1 -0
- package/dist/shortcut-recorder/shortcut-recorder.d.ts +93 -0
- package/dist/shortcut-recorder/shortcut-recorder.js +489 -0
- package/dist/shortcut-recorder/shortcut-recorder.js.map +1 -0
- package/dist/slider/index.d.ts +2 -2
- package/dist/slider/slider.d.ts +46 -14
- package/dist/slider/slider.js +151 -67
- package/dist/slider/slider.js.map +1 -1
- package/dist/slope-chart/index.d.ts +2 -0
- package/dist/slope-chart/index.js +2 -0
- package/dist/slope-chart/slope-chart.d.ts +54 -0
- package/dist/slope-chart/slope-chart.js +568 -0
- package/dist/slope-chart/slope-chart.js.map +1 -0
- package/dist/sparkline/index.d.ts +2 -0
- package/dist/sparkline/index.js +2 -0
- package/dist/sparkline/sparkline.d.ts +46 -0
- package/dist/sparkline/sparkline.js +390 -0
- package/dist/sparkline/sparkline.js.map +1 -0
- package/dist/split-bar/index.d.ts +2 -0
- package/dist/split-bar/index.js +2 -0
- package/dist/split-bar/split-bar.d.ts +62 -0
- package/dist/split-bar/split-bar.js +513 -0
- package/dist/split-bar/split-bar.js.map +1 -0
- package/dist/split-button/split-button.d.ts +1 -1
- package/dist/split-button/split-button.js +12 -11
- package/dist/split-button/split-button.js.map +1 -1
- package/dist/stat-card/index.d.ts +2 -2
- package/dist/stat-card/index.js +2 -2
- package/dist/stat-card/stat-card.d.ts +58 -5
- package/dist/stat-card/stat-card.js +144 -17
- package/dist/stat-card/stat-card.js.map +1 -1
- package/dist/stepper/index.d.ts +2 -0
- package/dist/stepper/index.js +2 -0
- package/dist/stepper/stepper.d.ts +51 -0
- package/dist/stepper/stepper.js +215 -0
- package/dist/stepper/stepper.js.map +1 -0
- package/dist/streamgraph/index.d.ts +2 -0
- package/dist/streamgraph/index.js +2 -0
- package/dist/streamgraph/streamgraph.d.ts +70 -0
- package/dist/streamgraph/streamgraph.js +613 -0
- package/dist/streamgraph/streamgraph.js.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/swipe-actions/index.d.ts +2 -0
- package/dist/swipe-actions/index.js +2 -0
- package/dist/swipe-actions/swipe-actions.d.ts +67 -0
- package/dist/swipe-actions/swipe-actions.js +552 -0
- package/dist/swipe-actions/swipe-actions.js.map +1 -0
- package/dist/switch/switch.js +2 -2
- package/dist/switch/switch.js.map +1 -1
- package/dist/table/index.d.ts +2 -2
- package/dist/table/index.js +2 -2
- package/dist/table/table.d.ts +55 -3
- package/dist/table/table.js +340 -165
- package/dist/table/table.js.map +1 -1
- package/dist/tabs/tabs.js +2 -2
- package/dist/tabs/tabs.js.map +1 -1
- package/dist/tag-input/index.d.ts +2 -0
- package/dist/tag-input/index.js +2 -0
- package/dist/tag-input/tag-input.d.ts +40 -0
- package/dist/tag-input/tag-input.js +269 -0
- package/dist/tag-input/tag-input.js.map +1 -0
- package/dist/text-morph/index.d.ts +2 -0
- package/dist/text-morph/index.js +2 -0
- package/dist/text-morph/text-morph.d.ts +23 -0
- package/dist/text-morph/text-morph.js +21 -0
- package/dist/text-morph/text-morph.js.map +1 -0
- package/dist/text-reveal/index.d.ts +2 -0
- package/dist/text-reveal/index.js +2 -0
- package/dist/text-reveal/text-reveal.d.ts +27 -0
- package/dist/text-reveal/text-reveal.js +51 -0
- package/dist/text-reveal/text-reveal.js.map +1 -0
- package/dist/text-shimmer/index.d.ts +2 -0
- package/dist/text-shimmer/index.js +2 -0
- package/dist/text-shimmer/text-shimmer.d.ts +29 -0
- package/dist/text-shimmer/text-shimmer.js +29 -0
- package/dist/text-shimmer/text-shimmer.js.map +1 -0
- package/dist/time-picker/time-picker.d.ts +36 -1
- package/dist/time-picker/time-picker.js +35 -7
- package/dist/time-picker/time-picker.js.map +1 -1
- package/dist/toast/index.d.ts +2 -2
- package/dist/toast/index.js +2 -2
- package/dist/toast/toast.d.ts +7 -1
- package/dist/toast/toast.js +82 -40
- package/dist/toast/toast.js.map +1 -1
- package/dist/tooltip/tooltip.d.ts +9 -2
- package/dist/tooltip/tooltip.js +7 -7
- package/dist/tooltip/tooltip.js.map +1 -1
- package/dist/treemap/index.d.ts +2 -0
- package/dist/treemap/index.js +2 -0
- package/dist/treemap/treemap.d.ts +53 -0
- package/dist/treemap/treemap.js +699 -0
- package/dist/treemap/treemap.js.map +1 -0
- package/dist/usage-meter/index.d.ts +2 -0
- package/dist/usage-meter/index.js +2 -0
- package/dist/usage-meter/usage-meter.d.ts +80 -0
- package/dist/usage-meter/usage-meter.js +458 -0
- package/dist/usage-meter/usage-meter.js.map +1 -0
- package/dist/waffle-chart/index.d.ts +2 -0
- package/dist/waffle-chart/index.js +2 -0
- package/dist/waffle-chart/waffle-chart.d.ts +57 -0
- package/dist/waffle-chart/waffle-chart.js +426 -0
- package/dist/waffle-chart/waffle-chart.js.map +1 -0
- package/package.json +165 -3
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../lib/cn.js";
|
|
3
|
+
import { mergeRefs } from "../lib/merge-refs.js";
|
|
4
|
+
import { prefersReducedMotion, useIsomorphicLayoutEffect } from "../lib/motion.js";
|
|
5
|
+
import { SMOOTH, SNAPPY, SWELL, live, retarget, tween } from "../lib/spring-tween.js";
|
|
6
|
+
import { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
//#region src/streamgraph/streamgraph.tsx
|
|
9
|
+
/** Samples across the plot: every layer is resampled onto the same grid, so datasets of any length morph into each other. */
|
|
10
|
+
const N = 161;
|
|
11
|
+
/** Room above and below the stream, and the gap between the crosshair and its tooltip, in pixels. */
|
|
12
|
+
const PAD = 10;
|
|
13
|
+
const GAP = 14;
|
|
14
|
+
/** The first four layers take chart-1 to chart-4; later layers fall back to neutral steps that alternate in lightness. */
|
|
15
|
+
const SHADES = [
|
|
16
|
+
30,
|
|
17
|
+
18,
|
|
18
|
+
24,
|
|
19
|
+
14
|
|
20
|
+
];
|
|
21
|
+
const colorOf = (item, index) => item.color ?? (index < 4 ? `var(--color-chart-${index + 1})` : `color-mix(in oklab, var(--color-foreground) ${SHADES[(index - 4) % SHADES.length]}%, var(--color-surface))`);
|
|
22
|
+
const GROUPED = new Intl.NumberFormat("en-US", { maximumFractionDigits: 1 });
|
|
23
|
+
const clamp = (value, low, high) => Math.min(high, Math.max(low, value));
|
|
24
|
+
/** The first layer sits in the middle of the stream and the rest alternate above and below it; a flat baseline stacks them in order. */
|
|
25
|
+
function stackOrder(count, mode) {
|
|
26
|
+
const order = Array.from({ length: count }, (_, index) => index);
|
|
27
|
+
if (mode === "zero") return order;
|
|
28
|
+
return order.reduce((list, index) => index === 0 ? [0] : index % 2 ? [...list, index] : [index, ...list], []);
|
|
29
|
+
}
|
|
30
|
+
/** Resamples values onto the shared grid with monotone cubic tangents, so curves never swing past the data or below zero. */
|
|
31
|
+
function resample(raw) {
|
|
32
|
+
const values = raw.map((value) => Math.max(0, value || 0));
|
|
33
|
+
const out = new Array(N);
|
|
34
|
+
if (!values.length) return out.fill(0);
|
|
35
|
+
if (values.length === 1) return out.fill(values[0]);
|
|
36
|
+
const last = values.length - 1;
|
|
37
|
+
const slopes = values.slice(1).map((value, index) => value - values[index]);
|
|
38
|
+
const tangents = values.map((_, index) => index === 0 || index === last ? 0 : (Math.sign(slopes[index - 1]) + Math.sign(slopes[index])) * Math.min(Math.abs(slopes[index - 1]), Math.abs(slopes[index]), Math.abs(slopes[index - 1] + slopes[index]) / 4) || 0);
|
|
39
|
+
if (last > 1) {
|
|
40
|
+
tangents[0] = (3 * slopes[0] - tangents[1]) / 2;
|
|
41
|
+
tangents[last] = (3 * slopes[last - 1] - tangents[last - 1]) / 2;
|
|
42
|
+
} else tangents[0] = tangents[1] = slopes[0];
|
|
43
|
+
for (let k = 0; k < N; k++) {
|
|
44
|
+
const at = k / 160 * last;
|
|
45
|
+
const seg = Math.min(last - 1, Math.floor(at));
|
|
46
|
+
const t = at - seg;
|
|
47
|
+
const t2 = t * t;
|
|
48
|
+
const t3 = t2 * t;
|
|
49
|
+
const a = values[seg];
|
|
50
|
+
const b = values[seg + 1];
|
|
51
|
+
const value = (2 * t3 - 3 * t2 + 1) * a + (t3 - 2 * t2 + t) * tangents[seg] + (3 * t2 - 2 * t3) * b + (t3 - t2) * tangents[seg + 1];
|
|
52
|
+
out[k] = clamp(value, Math.min(a, b), Math.max(a, b));
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
/** The baseline under the stack. Wiggle follows Byron and Wattenberg, then removes its linear drift so the stream stays level. */
|
|
57
|
+
function baseline(layers, mode) {
|
|
58
|
+
const g = new Array(N).fill(0);
|
|
59
|
+
const totals = g.map((_, j) => layers.reduce((sum, layer) => sum + layer[j], 0));
|
|
60
|
+
if (mode === "zero" || !layers.length) return g;
|
|
61
|
+
if (mode === "silhouette") return totals.map((total) => -total / 2);
|
|
62
|
+
for (let j = 1; j < N; j++) {
|
|
63
|
+
let s1 = 0;
|
|
64
|
+
let s2 = 0;
|
|
65
|
+
let below = 0;
|
|
66
|
+
for (const layer of layers) {
|
|
67
|
+
const change = layer[j] - layer[j - 1];
|
|
68
|
+
s1 += layer[j];
|
|
69
|
+
s2 += (below + change / 2) * layer[j];
|
|
70
|
+
below += change;
|
|
71
|
+
}
|
|
72
|
+
g[j] = g[j - 1] - (s1 ? s2 / s1 : 0);
|
|
73
|
+
}
|
|
74
|
+
const centers = g.map((value, j) => value + totals[j] / 2);
|
|
75
|
+
const mx = 80;
|
|
76
|
+
const my = centers.reduce((sum, value) => sum + value, 0) / N;
|
|
77
|
+
let num = 0;
|
|
78
|
+
let den = 0;
|
|
79
|
+
centers.forEach((value, j) => {
|
|
80
|
+
num += (j - mx) * (value - my);
|
|
81
|
+
den += (j - mx) ** 2;
|
|
82
|
+
});
|
|
83
|
+
const slope = den ? num / den : 0;
|
|
84
|
+
return g.map((value, j) => value - (my + slope * (j - mx)));
|
|
85
|
+
}
|
|
86
|
+
/** Axis labels that fit: at most one per 72 pixels, counted back from the latest. */
|
|
87
|
+
function axisPicks(data, width) {
|
|
88
|
+
const labeled = data.flatMap((item, index) => item.axisLabel ? [index] : []);
|
|
89
|
+
if (!width || !labeled.length) return [];
|
|
90
|
+
const stride = Math.ceil(labeled.length / Math.max(2, Math.floor(width / 72)));
|
|
91
|
+
return labeled.reverse().filter((_, rank) => rank % stride === 0).reverse();
|
|
92
|
+
}
|
|
93
|
+
const Streamgraph = forwardRef(function Streamgraph({ data, series, label, unit = "", height = 260, offset = "wiggle", formatValue, hiddenSeries, defaultHiddenSeries, onHiddenSeriesChange, onActiveChange, legend = true, directLabels = true, categoryLabel = "Date", emptyLabel = "No data for this range", className }, ref) {
|
|
94
|
+
const figure = useRef(null);
|
|
95
|
+
const refs = useMemo(() => mergeRefs(ref, figure), [ref]);
|
|
96
|
+
const plot = useRef(null);
|
|
97
|
+
const svg = useRef(null);
|
|
98
|
+
const tip = useRef(null);
|
|
99
|
+
const last = data.length - 1;
|
|
100
|
+
const empty = data.length === 0;
|
|
101
|
+
const [ownHidden, setOwnHidden] = useState(defaultHiddenSeries ?? []);
|
|
102
|
+
const hidden = hiddenSeries ?? ownHidden;
|
|
103
|
+
const toggle = (key) => {
|
|
104
|
+
const next = hidden.includes(key) ? hidden.filter((item) => item !== key) : [...hidden, key];
|
|
105
|
+
if (hiddenSeries === void 0) setOwnHidden(next);
|
|
106
|
+
onHiddenSeriesChange?.(next);
|
|
107
|
+
};
|
|
108
|
+
const visible = series.filter((item) => !hidden.includes(item.key));
|
|
109
|
+
const signature = `${series.map((item) => item.key).join(",")}|${data.map((item) => series.map((line) => item.values[line.key] ?? 0).join(",")).join(";")}`;
|
|
110
|
+
const targets = useMemo(() => new Map(series.map((line) => [line.key, resample(data.map((item) => item.values[line.key] ?? 0))])), [signature]);
|
|
111
|
+
const [hover, setHover] = useState(null);
|
|
112
|
+
const [seenSignature, setSeenSignature] = useState(signature);
|
|
113
|
+
if (seenSignature !== signature) {
|
|
114
|
+
setSeenSignature(signature);
|
|
115
|
+
setHover(null);
|
|
116
|
+
}
|
|
117
|
+
const index = hover && !empty ? Math.min(hover.index, last) : null;
|
|
118
|
+
const [legendKey, setLegendKey] = useState(null);
|
|
119
|
+
const wanted = hover?.key ?? legendKey;
|
|
120
|
+
const activeKey = wanted && visible.some((item) => item.key === wanted) ? wanted : null;
|
|
121
|
+
const width = useRef(0);
|
|
122
|
+
const [plotWidth, setPlotWidth] = useState(0);
|
|
123
|
+
const shapes = useRef(/* @__PURE__ */ new Map());
|
|
124
|
+
const presence = useRef(/* @__PURE__ */ new Map());
|
|
125
|
+
const frame = useRef(null);
|
|
126
|
+
const spots = useRef(/* @__PURE__ */ new Map());
|
|
127
|
+
const grow = useRef(live(0));
|
|
128
|
+
const cursor = useRef(live(1));
|
|
129
|
+
const current = useRef({
|
|
130
|
+
series,
|
|
131
|
+
offset,
|
|
132
|
+
height
|
|
133
|
+
});
|
|
134
|
+
useIsomorphicLayoutEffect(() => {
|
|
135
|
+
current.current = {
|
|
136
|
+
series,
|
|
137
|
+
offset,
|
|
138
|
+
height
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
/** One writer for every drawn attribute: morphs, toggles, the first swell, the crosshair and resizes all repaint through here. */
|
|
142
|
+
const paint = useCallback(() => {
|
|
143
|
+
const root = svg.current;
|
|
144
|
+
const w = width.current;
|
|
145
|
+
if (!root || !w) return;
|
|
146
|
+
const { series: order, offset: mode, height: h } = current.current;
|
|
147
|
+
const layers = order.map((line) => {
|
|
148
|
+
const shape = shapes.current.get(line.key);
|
|
149
|
+
const p = presence.current.get(line.key)?.value ?? 1;
|
|
150
|
+
return shape ? shape.map((value) => value * p) : new Array(N).fill(0);
|
|
151
|
+
});
|
|
152
|
+
const stack = stackOrder(order.length, mode);
|
|
153
|
+
const g = baseline(stack.map((i) => layers[i]), mode);
|
|
154
|
+
const lower = new Array(order.length);
|
|
155
|
+
const upper = new Array(order.length);
|
|
156
|
+
let running = g.slice();
|
|
157
|
+
for (const i of stack) {
|
|
158
|
+
const layer = layers[i];
|
|
159
|
+
lower[i] = running;
|
|
160
|
+
running = running.map((value, j) => value + layer[j]);
|
|
161
|
+
upper[i] = running;
|
|
162
|
+
}
|
|
163
|
+
let lo = Infinity;
|
|
164
|
+
let hi = -Infinity;
|
|
165
|
+
for (let j = 0; j < N; j++) {
|
|
166
|
+
lo = Math.min(lo, g[j]);
|
|
167
|
+
hi = Math.max(hi, running[j]);
|
|
168
|
+
}
|
|
169
|
+
if (!Number.isFinite(lo) || hi - lo < 1e-9) {
|
|
170
|
+
lo = -1;
|
|
171
|
+
hi = 1;
|
|
172
|
+
}
|
|
173
|
+
const span = hi - lo;
|
|
174
|
+
const s = grow.current.value;
|
|
175
|
+
const center = g.map((value, j) => (value + running[j]) / 2);
|
|
176
|
+
const toY = (value) => PAD + (1 - (value - lo) / span) * (h - 20);
|
|
177
|
+
const yAt = (value, j) => toY(center[j] + (value - center[j]) * s);
|
|
178
|
+
frame.current = {
|
|
179
|
+
lower,
|
|
180
|
+
upper,
|
|
181
|
+
toY
|
|
182
|
+
};
|
|
183
|
+
const xs = Array.from({ length: N }, (_, j) => j / 160 * w);
|
|
184
|
+
order.forEach((line, i) => {
|
|
185
|
+
const top = upper[i];
|
|
186
|
+
const bottom = lower[i];
|
|
187
|
+
const node = root.querySelector(`[data-layer="${CSS.escape(line.key)}"]`);
|
|
188
|
+
if (node) {
|
|
189
|
+
let d = "";
|
|
190
|
+
for (let j = 0; j < N; j++) d += `${j ? "L" : "M"}${xs[j].toFixed(1)},${yAt(top[j], j).toFixed(1)}`;
|
|
191
|
+
for (let j = 160; j >= 0; j--) d += `L${xs[j].toFixed(1)},${yAt(bottom[j], j).toFixed(1)}`;
|
|
192
|
+
node.setAttribute("d", `${d}Z`);
|
|
193
|
+
}
|
|
194
|
+
const text = root.querySelector(`[data-name="${CSS.escape(line.key)}"]`);
|
|
195
|
+
if (!text) return;
|
|
196
|
+
let best = 4;
|
|
197
|
+
for (let j = 4; j < 157; j++) if (top[j] - bottom[j] > top[best] - bottom[best]) best = j;
|
|
198
|
+
const held = spots.current.get(line.key);
|
|
199
|
+
const j = held !== void 0 && top[held] - bottom[held] >= (top[best] - bottom[best]) * .8 ? held : best;
|
|
200
|
+
spots.current.set(line.key, j);
|
|
201
|
+
const thickness = (top[j] - bottom[j]) / span * (h - 20) * s;
|
|
202
|
+
const room = text.getComputedTextLength?.() ?? 60;
|
|
203
|
+
text.setAttribute("x", clamp(xs[j], room / 2 + 6, w - room / 2 - 6).toFixed(1));
|
|
204
|
+
text.setAttribute("y", yAt((top[j] + bottom[j]) / 2, j).toFixed(1));
|
|
205
|
+
text.style.opacity = thickness >= 19 && room + 16 < w ? "1" : "0";
|
|
206
|
+
});
|
|
207
|
+
const x = cursor.current.value * w;
|
|
208
|
+
const cross = root.querySelector("[data-part=crosshair]");
|
|
209
|
+
cross?.setAttribute("x1", x.toFixed(1));
|
|
210
|
+
cross?.setAttribute("x2", x.toFixed(1));
|
|
211
|
+
}, []);
|
|
212
|
+
useIsomorphicLayoutEffect(() => {
|
|
213
|
+
const node = plot.current;
|
|
214
|
+
if (!node) return;
|
|
215
|
+
const read = () => {
|
|
216
|
+
width.current = node.clientWidth;
|
|
217
|
+
setPlotWidth(node.clientWidth);
|
|
218
|
+
paint();
|
|
219
|
+
};
|
|
220
|
+
read();
|
|
221
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
222
|
+
const observer = new ResizeObserver(read);
|
|
223
|
+
observer.observe(node);
|
|
224
|
+
return () => observer.disconnect();
|
|
225
|
+
}, [paint]);
|
|
226
|
+
useIsomorphicLayoutEffect(paint, [
|
|
227
|
+
height,
|
|
228
|
+
offset,
|
|
229
|
+
paint,
|
|
230
|
+
series
|
|
231
|
+
]);
|
|
232
|
+
const mounted = useRef(false);
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
const moves = [];
|
|
235
|
+
for (const [key, to] of targets) {
|
|
236
|
+
const from = shapes.current.get(key);
|
|
237
|
+
if (!from) {
|
|
238
|
+
shapes.current.set(key, to);
|
|
239
|
+
if (mounted.current) {
|
|
240
|
+
const entering = live(0);
|
|
241
|
+
presence.current.set(key, entering);
|
|
242
|
+
retarget(entering, hidden.includes(key) ? 0 : 1, SMOOTH, paint);
|
|
243
|
+
}
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
moves.push({
|
|
247
|
+
key,
|
|
248
|
+
from,
|
|
249
|
+
to
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
for (const key of [...shapes.current.keys()]) if (!targets.has(key)) shapes.current.delete(key);
|
|
253
|
+
mounted.current = true;
|
|
254
|
+
if (!moves.length) {
|
|
255
|
+
paint();
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
return tween(SMOOTH, (p) => {
|
|
259
|
+
for (const move of moves) shapes.current.set(move.key, move.from.map((value, j) => value + (move.to[j] - value) * p));
|
|
260
|
+
paint();
|
|
261
|
+
}, () => {
|
|
262
|
+
for (const move of moves) shapes.current.set(move.key, move.to);
|
|
263
|
+
paint();
|
|
264
|
+
});
|
|
265
|
+
}, [paint, targets]);
|
|
266
|
+
const hiddenKey = hidden.join("|");
|
|
267
|
+
useEffect(() => {
|
|
268
|
+
for (const line of series) {
|
|
269
|
+
const to = hidden.includes(line.key) ? 0 : 1;
|
|
270
|
+
const track = presence.current.get(line.key);
|
|
271
|
+
if (!track) presence.current.set(line.key, live(to));
|
|
272
|
+
else retarget(track, to, SMOOTH, paint);
|
|
273
|
+
}
|
|
274
|
+
paint();
|
|
275
|
+
}, [
|
|
276
|
+
hiddenKey,
|
|
277
|
+
paint,
|
|
278
|
+
series.length
|
|
279
|
+
]);
|
|
280
|
+
useEffect(() => () => {
|
|
281
|
+
grow.current.stop();
|
|
282
|
+
cursor.current.stop();
|
|
283
|
+
for (const track of presence.current.values()) track.stop();
|
|
284
|
+
}, []);
|
|
285
|
+
useEffect(() => {
|
|
286
|
+
const node = figure.current;
|
|
287
|
+
if (empty || !node) return;
|
|
288
|
+
if (prefersReducedMotion() || typeof IntersectionObserver === "undefined") {
|
|
289
|
+
grow.current.value = 1;
|
|
290
|
+
paint();
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
294
|
+
if (!entry?.isIntersecting) return;
|
|
295
|
+
observer.disconnect();
|
|
296
|
+
retarget(grow.current, 1, SWELL, paint);
|
|
297
|
+
}, { threshold: .3 });
|
|
298
|
+
observer.observe(node);
|
|
299
|
+
return () => observer.disconnect();
|
|
300
|
+
}, [empty, paint]);
|
|
301
|
+
const shownBefore = useRef(false);
|
|
302
|
+
useIsomorphicLayoutEffect(() => {
|
|
303
|
+
const bubble = tip.current;
|
|
304
|
+
const w = width.current;
|
|
305
|
+
if (index === null || !bubble || !w) {
|
|
306
|
+
shownBefore.current = false;
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const share = last > 0 ? index / last : .5;
|
|
310
|
+
const x = share * w;
|
|
311
|
+
if (!shownBefore.current) {
|
|
312
|
+
cursor.current.stop();
|
|
313
|
+
cursor.current.value = share;
|
|
314
|
+
paint();
|
|
315
|
+
} else retarget(cursor.current, share, SNAPPY, paint);
|
|
316
|
+
let y = hover?.y ?? null;
|
|
317
|
+
const f = frame.current;
|
|
318
|
+
if (y === null && f && activeKey) {
|
|
319
|
+
const i = series.findIndex((line) => line.key === activeKey);
|
|
320
|
+
const j = Math.round(share * 160);
|
|
321
|
+
if (i >= 0) y = f.toY((f.upper[i][j] + f.lower[i][j]) / 2);
|
|
322
|
+
}
|
|
323
|
+
const tw = bubble.offsetWidth;
|
|
324
|
+
const th = bubble.offsetHeight;
|
|
325
|
+
let left = x + GAP;
|
|
326
|
+
if (left + tw > w) left = x - GAP - tw;
|
|
327
|
+
if (!shownBefore.current) bubble.style.transition = "none";
|
|
328
|
+
bubble.style.translate = `${clamp(left, 0, Math.max(0, w - tw))}px ${clamp((y ?? height / 2) - th / 2, 0, Math.max(0, height - th))}px`;
|
|
329
|
+
if (!shownBefore.current) {
|
|
330
|
+
bubble.offsetWidth;
|
|
331
|
+
bubble.style.transition = "";
|
|
332
|
+
}
|
|
333
|
+
shownBefore.current = true;
|
|
334
|
+
});
|
|
335
|
+
const onActive = useRef(onActiveChange);
|
|
336
|
+
useIsomorphicLayoutEffect(() => {
|
|
337
|
+
onActive.current = onActiveChange;
|
|
338
|
+
});
|
|
339
|
+
useEffect(() => {
|
|
340
|
+
onActive.current?.(index, activeKey);
|
|
341
|
+
}, [index, activeKey]);
|
|
342
|
+
const read = (clientX, clientY) => {
|
|
343
|
+
const rect = plot.current?.getBoundingClientRect();
|
|
344
|
+
const f = frame.current;
|
|
345
|
+
if (!rect?.width || empty) return null;
|
|
346
|
+
const share = clamp((clientX - rect.left) / rect.width, 0, 1);
|
|
347
|
+
const y = clientY - rect.top;
|
|
348
|
+
const at = last > 0 ? Math.round(share * last) : 0;
|
|
349
|
+
const j = Math.round(share * 160);
|
|
350
|
+
let key = null;
|
|
351
|
+
if (f) series.forEach((line, i) => {
|
|
352
|
+
if (hidden.includes(line.key)) return;
|
|
353
|
+
const top = f.toY(f.upper[i][j]);
|
|
354
|
+
const bottom = f.toY(f.lower[i][j]);
|
|
355
|
+
if (y >= top - 1 && y <= bottom + 1) key = line.key;
|
|
356
|
+
});
|
|
357
|
+
return {
|
|
358
|
+
index: at,
|
|
359
|
+
key,
|
|
360
|
+
y
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
const onKeyDown = (event) => {
|
|
364
|
+
if (empty) return;
|
|
365
|
+
if (event.key === "Escape" && hover) {
|
|
366
|
+
event.preventDefault();
|
|
367
|
+
setHover(null);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
const from = index ?? last;
|
|
371
|
+
const keys = visible.map((line) => line.key);
|
|
372
|
+
const at = activeKey ? keys.indexOf(activeKey) : -1;
|
|
373
|
+
const page = Math.max(1, Math.round(data.length / 6));
|
|
374
|
+
const move = {
|
|
375
|
+
ArrowLeft: () => ({
|
|
376
|
+
index: clamp(from - 1, 0, last),
|
|
377
|
+
key: activeKey,
|
|
378
|
+
y: null
|
|
379
|
+
}),
|
|
380
|
+
ArrowRight: () => ({
|
|
381
|
+
index: clamp(index === null ? last : from + 1, 0, last),
|
|
382
|
+
key: activeKey,
|
|
383
|
+
y: null
|
|
384
|
+
}),
|
|
385
|
+
PageDown: () => ({
|
|
386
|
+
index: clamp(from - page, 0, last),
|
|
387
|
+
key: activeKey,
|
|
388
|
+
y: null
|
|
389
|
+
}),
|
|
390
|
+
PageUp: () => ({
|
|
391
|
+
index: clamp(from + page, 0, last),
|
|
392
|
+
key: activeKey,
|
|
393
|
+
y: null
|
|
394
|
+
}),
|
|
395
|
+
Home: () => ({
|
|
396
|
+
index: 0,
|
|
397
|
+
key: activeKey,
|
|
398
|
+
y: null
|
|
399
|
+
}),
|
|
400
|
+
End: () => ({
|
|
401
|
+
index: last,
|
|
402
|
+
key: activeKey,
|
|
403
|
+
y: null
|
|
404
|
+
}),
|
|
405
|
+
ArrowUp: () => ({
|
|
406
|
+
index: from,
|
|
407
|
+
key: keys[at < 0 ? keys.length - 1 : Math.min(keys.length - 1, at + 1)] ?? null,
|
|
408
|
+
y: null
|
|
409
|
+
}),
|
|
410
|
+
ArrowDown: () => ({
|
|
411
|
+
index: from,
|
|
412
|
+
key: keys[at < 0 ? 0 : Math.max(0, at - 1)] ?? null,
|
|
413
|
+
y: null
|
|
414
|
+
})
|
|
415
|
+
}[event.key];
|
|
416
|
+
if (!move) return;
|
|
417
|
+
event.preventDefault();
|
|
418
|
+
setHover(move());
|
|
419
|
+
};
|
|
420
|
+
const suffix = unit ? ` ${unit}` : "";
|
|
421
|
+
const format = (value, line) => `${formatValue ? formatValue(value, line) : GROUPED.format(value)}${suffix}`;
|
|
422
|
+
const reading = index === null ? null : data[index];
|
|
423
|
+
const total = (datum) => visible.reduce((sum, line) => sum + Math.max(0, datum.values[line.key] ?? 0), 0);
|
|
424
|
+
const activeLine = series.find((line) => line.key === activeKey);
|
|
425
|
+
const announce = reading ? `${reading.label}. ${activeLine && activeKey ? `${activeLine.label} ${format(reading.values[activeKey] ?? 0, activeLine)}, ` : ""}${visible.length} layers, ${GROUPED.format(total(reading))}${suffix} in total` : "";
|
|
426
|
+
const summary = empty ? `${label}. ${emptyLabel}.` : `${label}, ${data[0].label} to ${data[last].label}. ${visible.map((line) => `${line.label}, latest ${format(data[last].values[line.key] ?? 0, line)}`).join(". ")}.`;
|
|
427
|
+
const picks = axisPicks(data, plotWidth);
|
|
428
|
+
return /* @__PURE__ */ jsxs("figure", {
|
|
429
|
+
ref: refs,
|
|
430
|
+
"data-slot": "streamgraph",
|
|
431
|
+
"aria-label": label,
|
|
432
|
+
className: cn("streamgraph box-border font-sans text-foreground", className),
|
|
433
|
+
children: [
|
|
434
|
+
legend && series.length > 1 ? /* @__PURE__ */ jsx("div", {
|
|
435
|
+
role: "group",
|
|
436
|
+
"aria-label": `${label} layers`,
|
|
437
|
+
onPointerLeave: () => setLegendKey(null),
|
|
438
|
+
className: "-mx-2 flex min-w-0 flex-wrap gap-x-1 gap-y-0.5",
|
|
439
|
+
children: series.map((line, at) => /* @__PURE__ */ jsxs("button", {
|
|
440
|
+
type: "button",
|
|
441
|
+
"data-slot": "streamgraph-toggle",
|
|
442
|
+
"aria-pressed": !hidden.includes(line.key),
|
|
443
|
+
onClick: () => toggle(line.key),
|
|
444
|
+
onPointerEnter: (event) => {
|
|
445
|
+
if (event.pointerType === "mouse") setLegendKey(line.key);
|
|
446
|
+
},
|
|
447
|
+
onFocus: (event) => {
|
|
448
|
+
if (event.currentTarget.matches(":focus-visible")) setLegendKey(line.key);
|
|
449
|
+
},
|
|
450
|
+
onBlur: () => setLegendKey(null),
|
|
451
|
+
style: { "--series": colorOf(line, at) },
|
|
452
|
+
className: "chart-legend-toggle",
|
|
453
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
454
|
+
"aria-hidden": "true",
|
|
455
|
+
className: "chart-layer-swatch"
|
|
456
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
457
|
+
className: "chart-toggle-label",
|
|
458
|
+
children: line.label
|
|
459
|
+
})]
|
|
460
|
+
}, line.key))
|
|
461
|
+
}) : null,
|
|
462
|
+
/* @__PURE__ */ jsxs("div", {
|
|
463
|
+
"data-slot": "streamgraph-chart",
|
|
464
|
+
"data-scrubbing": index !== null || void 0,
|
|
465
|
+
"data-focus": activeKey ? "" : void 0,
|
|
466
|
+
className: "streamgraph-frame",
|
|
467
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
468
|
+
ref: plot,
|
|
469
|
+
role: "slider",
|
|
470
|
+
tabIndex: empty ? -1 : 0,
|
|
471
|
+
"aria-label": `${label}, explore by ${categoryLabel.toLowerCase()}`,
|
|
472
|
+
"aria-orientation": "horizontal",
|
|
473
|
+
"aria-valuemin": 1,
|
|
474
|
+
"aria-valuemax": Math.max(1, data.length),
|
|
475
|
+
"aria-valuenow": (index ?? last) + 1,
|
|
476
|
+
"aria-valuetext": reading ? announce : summary,
|
|
477
|
+
className: "line-chart-plot streamgraph-plot",
|
|
478
|
+
style: { height },
|
|
479
|
+
onPointerMove: (event) => {
|
|
480
|
+
if (event.pointerType === "mouse" || event.buttons) setHover(read(event.clientX, event.clientY));
|
|
481
|
+
},
|
|
482
|
+
onPointerDown: (event) => {
|
|
483
|
+
if (event.pointerType !== "mouse") event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
484
|
+
setHover(read(event.clientX, event.clientY));
|
|
485
|
+
},
|
|
486
|
+
onPointerUp: (event) => {
|
|
487
|
+
if (event.pointerType !== "mouse") setHover(null);
|
|
488
|
+
},
|
|
489
|
+
onPointerCancel: () => setHover(null),
|
|
490
|
+
onPointerLeave: (event) => {
|
|
491
|
+
if (event.pointerType === "mouse") setHover(null);
|
|
492
|
+
},
|
|
493
|
+
onKeyDown,
|
|
494
|
+
onBlur: () => setHover(null),
|
|
495
|
+
onFocus: (event) => {
|
|
496
|
+
if (event.currentTarget.matches(":focus-visible") && !empty) setHover((now) => now ?? {
|
|
497
|
+
index: last,
|
|
498
|
+
key: null,
|
|
499
|
+
y: null
|
|
500
|
+
});
|
|
501
|
+
},
|
|
502
|
+
children: [
|
|
503
|
+
/* @__PURE__ */ jsxs("svg", {
|
|
504
|
+
ref: svg,
|
|
505
|
+
width: "100%",
|
|
506
|
+
height,
|
|
507
|
+
"aria-hidden": "true",
|
|
508
|
+
focusable: "false",
|
|
509
|
+
className: "block overflow-visible",
|
|
510
|
+
children: [
|
|
511
|
+
series.map((line, at) => /* @__PURE__ */ jsx("path", {
|
|
512
|
+
"data-layer": line.key,
|
|
513
|
+
"data-active": activeKey === line.key || void 0,
|
|
514
|
+
className: "streamgraph-layer",
|
|
515
|
+
style: { "--series": colorOf(line, at) }
|
|
516
|
+
}, line.key)),
|
|
517
|
+
/* @__PURE__ */ jsx("line", {
|
|
518
|
+
"data-part": "crosshair",
|
|
519
|
+
className: "line-chart-crosshair",
|
|
520
|
+
y1: 0,
|
|
521
|
+
y2: height
|
|
522
|
+
}),
|
|
523
|
+
directLabels ? series.map((line) => /* @__PURE__ */ jsx("text", {
|
|
524
|
+
"data-name": line.key,
|
|
525
|
+
"data-hidden": hidden.includes(line.key) || void 0,
|
|
526
|
+
"data-dim": activeKey !== null && activeKey !== line.key || void 0,
|
|
527
|
+
textAnchor: "middle",
|
|
528
|
+
dominantBaseline: "central",
|
|
529
|
+
className: "streamgraph-name",
|
|
530
|
+
children: line.label
|
|
531
|
+
}, line.key)) : null
|
|
532
|
+
]
|
|
533
|
+
}),
|
|
534
|
+
/* @__PURE__ */ jsxs("div", {
|
|
535
|
+
ref: tip,
|
|
536
|
+
"aria-hidden": "true",
|
|
537
|
+
"data-slot": "streamgraph-tooltip",
|
|
538
|
+
className: "line-chart-tooltip",
|
|
539
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
540
|
+
className: "m-0 mb-0.5 whitespace-nowrap text-xs tabular-nums text-text-secondary",
|
|
541
|
+
children: reading?.label ?? ""
|
|
542
|
+
}), stackOrder(series.length, offset).reverse().map((at) => series[at]).filter((line) => !hidden.includes(line.key)).map((line) => /* @__PURE__ */ jsxs("p", {
|
|
543
|
+
"data-active": activeKey === line.key || void 0,
|
|
544
|
+
className: "streamgraph-tip-row",
|
|
545
|
+
style: { "--series": colorOf(line, series.indexOf(line)) },
|
|
546
|
+
children: [
|
|
547
|
+
/* @__PURE__ */ jsx("span", { className: "chart-tip-swatch" }),
|
|
548
|
+
/* @__PURE__ */ jsx("span", {
|
|
549
|
+
className: "streamgraph-tip-name",
|
|
550
|
+
children: line.label
|
|
551
|
+
}),
|
|
552
|
+
/* @__PURE__ */ jsx("span", {
|
|
553
|
+
className: "ms-2 flex-none whitespace-nowrap font-medium tabular-nums text-foreground",
|
|
554
|
+
children: reading ? format(reading.values[line.key] ?? 0, line) : ""
|
|
555
|
+
})
|
|
556
|
+
]
|
|
557
|
+
}, line.key))]
|
|
558
|
+
}),
|
|
559
|
+
empty || visible.length === 0 ? /* @__PURE__ */ jsx("p", {
|
|
560
|
+
className: "pointer-events-none absolute inset-0 m-0 grid place-items-center text-sm text-muted-foreground motion-safe:animate-fade-in",
|
|
561
|
+
children: empty ? emptyLabel : "Choose a layer to show"
|
|
562
|
+
}) : null
|
|
563
|
+
]
|
|
564
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
565
|
+
"aria-hidden": "true",
|
|
566
|
+
className: "relative min-w-0 [grid-area:2/1]",
|
|
567
|
+
children: picks.map((at) => {
|
|
568
|
+
const share = last > 0 ? at / last : .5;
|
|
569
|
+
return /* @__PURE__ */ jsx("span", {
|
|
570
|
+
className: "absolute top-2 whitespace-nowrap text-xs leading-none tabular-nums text-muted-foreground motion-safe:animate-fade-in",
|
|
571
|
+
style: {
|
|
572
|
+
left: `${share * 100}%`,
|
|
573
|
+
translate: `${-share * 100}% 0`
|
|
574
|
+
},
|
|
575
|
+
children: data[at].axisLabel
|
|
576
|
+
}, data[at].key);
|
|
577
|
+
})
|
|
578
|
+
})]
|
|
579
|
+
}),
|
|
580
|
+
/* @__PURE__ */ jsx("p", {
|
|
581
|
+
className: "sr-only",
|
|
582
|
+
"aria-live": "polite",
|
|
583
|
+
"aria-atomic": "true",
|
|
584
|
+
children: announce
|
|
585
|
+
}),
|
|
586
|
+
/* @__PURE__ */ jsx("p", {
|
|
587
|
+
className: "sr-only",
|
|
588
|
+
children: summary
|
|
589
|
+
}),
|
|
590
|
+
empty ? null : /* @__PURE__ */ jsx("div", {
|
|
591
|
+
className: "sr-only",
|
|
592
|
+
children: /* @__PURE__ */ jsxs("table", { children: [
|
|
593
|
+
/* @__PURE__ */ jsx("caption", { children: label }),
|
|
594
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
|
|
595
|
+
scope: "col",
|
|
596
|
+
children: categoryLabel
|
|
597
|
+
}), series.map((line) => /* @__PURE__ */ jsx("th", {
|
|
598
|
+
scope: "col",
|
|
599
|
+
children: line.label
|
|
600
|
+
}, line.key))] }) }),
|
|
601
|
+
/* @__PURE__ */ jsx("tbody", { children: data.map((item) => /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
|
|
602
|
+
scope: "row",
|
|
603
|
+
children: item.label
|
|
604
|
+
}), series.map((line) => /* @__PURE__ */ jsx("td", { children: format(item.values[line.key] ?? 0, line) }, line.key))] }, item.key)) })
|
|
605
|
+
] })
|
|
606
|
+
})
|
|
607
|
+
]
|
|
608
|
+
});
|
|
609
|
+
});
|
|
610
|
+
//#endregion
|
|
611
|
+
export { Streamgraph };
|
|
612
|
+
|
|
613
|
+
//# sourceMappingURL=streamgraph.js.map
|