@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,699 @@
|
|
|
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 { SwapText } from "../lib/swap-text.js";
|
|
6
|
+
import { REVEAL, SWELL, tween } from "../lib/spring-tween.js";
|
|
7
|
+
import { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
8
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
//#region src/treemap/treemap.tsx
|
|
10
|
+
/** Top level branches take chart-1 to chart-4 in order; a fifth and beyond stay neutral rather than reuse a hue. */
|
|
11
|
+
const hueOf = (index) => index < 0 ? "var(--color-chart-1)" : index < 4 ? `var(--color-chart-${index + 1})` : "var(--color-foreground)";
|
|
12
|
+
/** The gap between tiles, the padding of a branch, the height of a branch header, the gap to the tooltip, and the shading steps. */
|
|
13
|
+
const GAP = 2;
|
|
14
|
+
const PAD = 3;
|
|
15
|
+
const HEADER = 22;
|
|
16
|
+
const TIP = 14;
|
|
17
|
+
const STEPS = 5;
|
|
18
|
+
const GROUPED = new Intl.NumberFormat("en-US", { maximumFractionDigits: 1 });
|
|
19
|
+
const PERCENT = new Intl.NumberFormat("en-US", {
|
|
20
|
+
style: "percent",
|
|
21
|
+
maximumFractionDigits: 1
|
|
22
|
+
});
|
|
23
|
+
const clamp = (value, low, high) => Math.min(high, Math.max(low, value));
|
|
24
|
+
const mix = (a, b, t) => a + (b - a) * t;
|
|
25
|
+
const inset = (r, top, side) => ({
|
|
26
|
+
x: r.x + side,
|
|
27
|
+
y: r.y + top,
|
|
28
|
+
w: Math.max(0, r.w - side * 2),
|
|
29
|
+
h: Math.max(0, r.h - top - side)
|
|
30
|
+
});
|
|
31
|
+
function flatten(root) {
|
|
32
|
+
const flat = /* @__PURE__ */ new Map();
|
|
33
|
+
const visit = (node, depth, parent, path) => {
|
|
34
|
+
const kids = node.children ?? [];
|
|
35
|
+
let value = 0;
|
|
36
|
+
let weighted = 0;
|
|
37
|
+
let colored = 0;
|
|
38
|
+
if (kids.length) for (const kid of kids) {
|
|
39
|
+
const r = visit(kid, depth + 1, node.id, depth === 0 ? [] : [...path, node.label]);
|
|
40
|
+
value += r.value;
|
|
41
|
+
weighted += r.weighted;
|
|
42
|
+
colored += r.colored;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
value = Math.max(0, node.value ?? 0);
|
|
46
|
+
if (node.color !== void 0 && Number.isFinite(node.color)) {
|
|
47
|
+
weighted = node.color * value;
|
|
48
|
+
colored = value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
flat.set(node.id, {
|
|
52
|
+
id: node.id,
|
|
53
|
+
label: node.label,
|
|
54
|
+
value,
|
|
55
|
+
color: colored ? weighted / colored : null,
|
|
56
|
+
depth,
|
|
57
|
+
parent,
|
|
58
|
+
children: kids.map((kid) => kid.id),
|
|
59
|
+
path: depth === 0 ? [node.label] : [...path, node.label]
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
value,
|
|
63
|
+
weighted,
|
|
64
|
+
colored
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
visit(root, 0, null, []);
|
|
68
|
+
return flat;
|
|
69
|
+
}
|
|
70
|
+
/** Squarified layout: rows of tiles along the short side, each row closed when adding a tile would make the worst aspect ratio worse. */
|
|
71
|
+
function squarify(items, rect, out) {
|
|
72
|
+
const list = items.filter((item) => item.value > 0).sort((a, b) => b.value - a.value);
|
|
73
|
+
const total = list.reduce((sum, item) => sum + item.value, 0);
|
|
74
|
+
if (!total || rect.w <= 0 || rect.h <= 0) {
|
|
75
|
+
for (const item of items) out.set(item.id, {
|
|
76
|
+
x: rect.x,
|
|
77
|
+
y: rect.y,
|
|
78
|
+
w: 0,
|
|
79
|
+
h: 0
|
|
80
|
+
});
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const scale = rect.w * rect.h / total;
|
|
84
|
+
let { x, y, w, h } = rect;
|
|
85
|
+
let i = 0;
|
|
86
|
+
const worst = (row, side) => {
|
|
87
|
+
const sum = row.reduce((a, b) => a + b, 0);
|
|
88
|
+
return Math.max(side * side * Math.max(...row) / (sum * sum), sum * sum / (side * side * Math.min(...row)));
|
|
89
|
+
};
|
|
90
|
+
while (i < list.length) {
|
|
91
|
+
const side = Math.min(w, h);
|
|
92
|
+
const row = [list[i].value * scale];
|
|
93
|
+
let j = i + 1;
|
|
94
|
+
while (j < list.length) {
|
|
95
|
+
if (worst([...row, list[j].value * scale], side) > worst(row, side)) break;
|
|
96
|
+
row.push(list[j].value * scale);
|
|
97
|
+
j++;
|
|
98
|
+
}
|
|
99
|
+
const sum = row.reduce((a, b) => a + b, 0);
|
|
100
|
+
if (w >= h) {
|
|
101
|
+
const cw = sum / h;
|
|
102
|
+
let cy = y;
|
|
103
|
+
for (let k = i; k < j; k++) {
|
|
104
|
+
const th = list[k].value * scale / cw;
|
|
105
|
+
out.set(list[k].id, {
|
|
106
|
+
x,
|
|
107
|
+
y: cy,
|
|
108
|
+
w: cw,
|
|
109
|
+
h: th
|
|
110
|
+
});
|
|
111
|
+
cy += th;
|
|
112
|
+
}
|
|
113
|
+
x += cw;
|
|
114
|
+
w -= cw;
|
|
115
|
+
} else {
|
|
116
|
+
const rh = sum / w;
|
|
117
|
+
let cx = x;
|
|
118
|
+
for (let k = i; k < j; k++) {
|
|
119
|
+
const tw = list[k].value * scale / rh;
|
|
120
|
+
out.set(list[k].id, {
|
|
121
|
+
x: cx,
|
|
122
|
+
y,
|
|
123
|
+
w: tw,
|
|
124
|
+
h: rh
|
|
125
|
+
});
|
|
126
|
+
cx += tw;
|
|
127
|
+
}
|
|
128
|
+
y += rh;
|
|
129
|
+
h -= rh;
|
|
130
|
+
}
|
|
131
|
+
i = j;
|
|
132
|
+
}
|
|
133
|
+
for (const item of items) if (!out.has(item.id)) out.set(item.id, {
|
|
134
|
+
x: rect.x,
|
|
135
|
+
y: rect.y,
|
|
136
|
+
w: 0,
|
|
137
|
+
h: 0
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/** Rects of every descendant when `focus` fills the view: its children fill the view, and each branch holds its own children under a header. */
|
|
141
|
+
function layoutFrom(flat, focus, view) {
|
|
142
|
+
const out = /* @__PURE__ */ new Map();
|
|
143
|
+
const nest = (id, rect, top) => {
|
|
144
|
+
const node = flat.get(id);
|
|
145
|
+
if (!node.children.length) return;
|
|
146
|
+
const room = top ? rect : inset(rect, rect.h > 48 && rect.w > 64 ? HEADER : PAD, PAD);
|
|
147
|
+
const placed = /* @__PURE__ */ new Map();
|
|
148
|
+
squarify(node.children.map((child) => ({
|
|
149
|
+
id: child,
|
|
150
|
+
value: flat.get(child).value
|
|
151
|
+
})), room, placed);
|
|
152
|
+
for (const [child, r] of placed) {
|
|
153
|
+
const gapped = {
|
|
154
|
+
x: r.x + GAP / 2,
|
|
155
|
+
y: r.y + GAP / 2,
|
|
156
|
+
w: Math.max(0, r.w - GAP),
|
|
157
|
+
h: Math.max(0, r.h - GAP)
|
|
158
|
+
};
|
|
159
|
+
out.set(child, gapped);
|
|
160
|
+
nest(child, gapped, false);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
nest(focus, view, true);
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
/** The affine map that carries rect `from` onto rect `to`, applied to `r`. */
|
|
167
|
+
const carry = (r, from, to) => {
|
|
168
|
+
const sx = to.w / (from.w || 1);
|
|
169
|
+
const sy = to.h / (from.h || 1);
|
|
170
|
+
return {
|
|
171
|
+
x: to.x + (r.x - from.x) * sx,
|
|
172
|
+
y: to.y + (r.y - from.y) * sy,
|
|
173
|
+
w: r.w * sx,
|
|
174
|
+
h: r.h * sy
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
const Treemap = forwardRef(function Treemap({ data, label, formatValue = (value) => GROUPED.format(value), colorLabel, formatColor = (value) => GROUPED.format(value), colorDomain, focus, defaultFocus, onFocusChange, height = 420, emptyLabel = "No data yet", className }, ref) {
|
|
178
|
+
const figure = useRef(null);
|
|
179
|
+
const refs = useMemo(() => mergeRefs(ref, figure), [ref]);
|
|
180
|
+
const stage = useRef(null);
|
|
181
|
+
const tip = useRef(null);
|
|
182
|
+
const tiles = useRef(/* @__PURE__ */ new Map());
|
|
183
|
+
const signature = JSON.stringify(data);
|
|
184
|
+
const flat = useMemo(() => flatten(data), [signature]);
|
|
185
|
+
const root = flat.get(data.id);
|
|
186
|
+
const nodes = useMemo(() => [...flat.values()].filter((node) => node.depth > 0), [flat]);
|
|
187
|
+
const [ownFocus, setOwnFocus] = useState(defaultFocus ?? data.id);
|
|
188
|
+
const wanted = flat.get(focus ?? ownFocus);
|
|
189
|
+
const center = wanted && wanted.children.length ? wanted : root;
|
|
190
|
+
const zoomTo = (id) => {
|
|
191
|
+
if (focus === void 0) setOwnFocus(id);
|
|
192
|
+
onFocusChange?.(id);
|
|
193
|
+
};
|
|
194
|
+
const [active, setActive] = useState(null);
|
|
195
|
+
const [pointer, setPointer] = useState(null);
|
|
196
|
+
const [width, setWidth] = useState(0);
|
|
197
|
+
useIsomorphicLayoutEffect(() => {
|
|
198
|
+
const node = stage.current;
|
|
199
|
+
if (!node || typeof ResizeObserver === "undefined") return;
|
|
200
|
+
const observer = new ResizeObserver(() => setWidth(node.clientWidth));
|
|
201
|
+
observer.observe(node);
|
|
202
|
+
setWidth(node.clientWidth);
|
|
203
|
+
return () => observer.disconnect();
|
|
204
|
+
}, []);
|
|
205
|
+
const view = useMemo(() => ({
|
|
206
|
+
x: 0,
|
|
207
|
+
y: 0,
|
|
208
|
+
w: width,
|
|
209
|
+
h: height
|
|
210
|
+
}), [width, height]);
|
|
211
|
+
const target = useMemo(() => layoutFrom(flat, center.id, view), [
|
|
212
|
+
flat,
|
|
213
|
+
center.id,
|
|
214
|
+
view
|
|
215
|
+
]);
|
|
216
|
+
const levelOf = (node) => node.depth - center.depth;
|
|
217
|
+
const leaves = nodes.filter((node) => !node.children.length && node.color !== null);
|
|
218
|
+
const [lo, hi] = colorDomain ?? (leaves.length ? [Math.min(...leaves.map((node) => node.color)), Math.max(...leaves.map((node) => node.color))] : [0, 1]);
|
|
219
|
+
const colored = colorLabel !== void 0 && leaves.length > 0;
|
|
220
|
+
const shade = (value) => {
|
|
221
|
+
if (!colored || value === null) return 34;
|
|
222
|
+
const t = clamp((value - lo) / (hi - lo || 1), 0, 1);
|
|
223
|
+
return Math.round(14 + Math.round(t * 4) / 4 * 44);
|
|
224
|
+
};
|
|
225
|
+
const branchOf = useMemo(() => {
|
|
226
|
+
const map = /* @__PURE__ */ new Map();
|
|
227
|
+
root.children.forEach((id, index) => {
|
|
228
|
+
const walk = (at) => {
|
|
229
|
+
map.set(at, index);
|
|
230
|
+
flat.get(at)?.children.forEach(walk);
|
|
231
|
+
};
|
|
232
|
+
walk(id);
|
|
233
|
+
});
|
|
234
|
+
return map;
|
|
235
|
+
}, [flat, root]);
|
|
236
|
+
const drawn = useRef(/* @__PURE__ */ new Map());
|
|
237
|
+
const levels = useRef(/* @__PURE__ */ new Map());
|
|
238
|
+
const lastFocus = useRef(null);
|
|
239
|
+
const nodesRef = useRef(nodes);
|
|
240
|
+
useIsomorphicLayoutEffect(() => {
|
|
241
|
+
nodesRef.current = nodes;
|
|
242
|
+
});
|
|
243
|
+
const paint = useCallback(() => {
|
|
244
|
+
for (const node of nodesRef.current) {
|
|
245
|
+
const el = tiles.current.get(node.id);
|
|
246
|
+
const d = drawn.current.get(node.id);
|
|
247
|
+
if (!el) continue;
|
|
248
|
+
if (!d || d.o < .01 || d.w < .5 || d.h < .5) {
|
|
249
|
+
el.style.visibility = "hidden";
|
|
250
|
+
el.style.pointerEvents = "none";
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
el.style.visibility = "visible";
|
|
254
|
+
el.style.transform = `translate3d(${d.x.toFixed(2)}px, ${d.y.toFixed(2)}px, 0)`;
|
|
255
|
+
el.style.width = `${d.w.toFixed(2)}px`;
|
|
256
|
+
el.style.height = `${d.h.toFixed(2)}px`;
|
|
257
|
+
el.style.opacity = d.o.toFixed(3);
|
|
258
|
+
el.style.pointerEvents = d.o > .6 ? "auto" : "none";
|
|
259
|
+
el.dataset.level = String(levels.current.get(node.id) ?? 0);
|
|
260
|
+
el.dataset.room = d.w > 64 && d.h > 38 ? d.h > 54 ? "full" : "name" : "none";
|
|
261
|
+
}
|
|
262
|
+
}, []);
|
|
263
|
+
useIsomorphicLayoutEffect(paint);
|
|
264
|
+
const [inView, setInView] = useState(false);
|
|
265
|
+
useEffect(() => {
|
|
266
|
+
const node = figure.current;
|
|
267
|
+
if (!node || prefersReducedMotion() || typeof IntersectionObserver === "undefined") {
|
|
268
|
+
setInView(true);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
272
|
+
if (!entry?.isIntersecting) return;
|
|
273
|
+
observer.disconnect();
|
|
274
|
+
setInView(true);
|
|
275
|
+
}, { threshold: .25 });
|
|
276
|
+
observer.observe(node);
|
|
277
|
+
return () => observer.disconnect();
|
|
278
|
+
}, []);
|
|
279
|
+
const shown = inView && width > 0;
|
|
280
|
+
useEffect(() => {
|
|
281
|
+
if (!shown) return;
|
|
282
|
+
const prev = lastFocus.current;
|
|
283
|
+
const isUnder = (id, ancestor) => {
|
|
284
|
+
for (let at = flat.get(id); at; at = at.parent ? flat.get(at.parent) : void 0) if (at.id === ancestor) return true;
|
|
285
|
+
return false;
|
|
286
|
+
};
|
|
287
|
+
const visible = (node) => {
|
|
288
|
+
const l = node.depth - center.depth;
|
|
289
|
+
return l >= 1 && l <= 2 && isUnder(node.id, center.id);
|
|
290
|
+
};
|
|
291
|
+
const nextVisible = new Set(nodes.filter(visible).map((node) => node.id));
|
|
292
|
+
const before = new Map(drawn.current);
|
|
293
|
+
const wasVisible = new Set([...before].filter(([, d]) => d.o > .5).map(([id]) => id));
|
|
294
|
+
let toOld = null;
|
|
295
|
+
let toNew = null;
|
|
296
|
+
if (prev && prev.id !== center.id && before.size) {
|
|
297
|
+
if (isUnder(center.id, prev.id)) {
|
|
298
|
+
const inOld = prev.layout.get(center.id);
|
|
299
|
+
if (inOld) {
|
|
300
|
+
toOld = (r) => carry(r, view, inOld);
|
|
301
|
+
toNew = (r) => carry(r, inOld, view);
|
|
302
|
+
}
|
|
303
|
+
} else if (isUnder(prev.id, center.id)) {
|
|
304
|
+
const inNew = target.get(prev.id);
|
|
305
|
+
if (inNew) {
|
|
306
|
+
toOld = (r) => carry(r, inNew, view);
|
|
307
|
+
toNew = (r) => carry(r, view, inNew);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const from = /* @__PURE__ */ new Map();
|
|
312
|
+
const to = /* @__PURE__ */ new Map();
|
|
313
|
+
const first = !before.size;
|
|
314
|
+
for (const node of nodes) {
|
|
315
|
+
const goal = target.get(node.id);
|
|
316
|
+
const now = before.get(node.id);
|
|
317
|
+
const inNext = nextVisible.has(node.id);
|
|
318
|
+
const inPrev = wasVisible.has(node.id);
|
|
319
|
+
if (inNext && goal) {
|
|
320
|
+
to.set(node.id, {
|
|
321
|
+
...goal,
|
|
322
|
+
o: 1
|
|
323
|
+
});
|
|
324
|
+
if (inPrev && now) from.set(node.id, now);
|
|
325
|
+
else if (first) from.set(node.id, {
|
|
326
|
+
x: goal.x + goal.w / 2,
|
|
327
|
+
y: goal.y + goal.h / 2,
|
|
328
|
+
w: 0,
|
|
329
|
+
h: 0,
|
|
330
|
+
o: 0
|
|
331
|
+
});
|
|
332
|
+
else from.set(node.id, {
|
|
333
|
+
...toOld ? toOld(goal) : goal,
|
|
334
|
+
o: 0
|
|
335
|
+
});
|
|
336
|
+
levels.current.set(node.id, levelOf(node));
|
|
337
|
+
} else if (inPrev && now) {
|
|
338
|
+
from.set(node.id, now);
|
|
339
|
+
to.set(node.id, {
|
|
340
|
+
...toNew ? toNew(now) : now,
|
|
341
|
+
o: 0
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
for (const node of nodes) if (!from.has(node.id)) drawn.current.set(node.id, {
|
|
346
|
+
x: 0,
|
|
347
|
+
y: 0,
|
|
348
|
+
w: 0,
|
|
349
|
+
h: 0,
|
|
350
|
+
o: 0
|
|
351
|
+
});
|
|
352
|
+
lastFocus.current = {
|
|
353
|
+
id: center.id,
|
|
354
|
+
layout: target
|
|
355
|
+
};
|
|
356
|
+
return tween(first ? SWELL : REVEAL, (t) => {
|
|
357
|
+
for (const [id, a] of from) {
|
|
358
|
+
const b = to.get(id);
|
|
359
|
+
const local = first ? clamp((t - Math.min(.3, (1 - b.w * b.h / (view.w * view.h || 1)) * .3)) / .7, 0, 1) : t;
|
|
360
|
+
drawn.current.set(id, {
|
|
361
|
+
x: mix(a.x, b.x, local),
|
|
362
|
+
y: mix(a.y, b.y, local),
|
|
363
|
+
w: mix(a.w, b.w, local),
|
|
364
|
+
h: mix(a.h, b.h, local),
|
|
365
|
+
o: mix(a.o, b.o, local)
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
paint();
|
|
369
|
+
}, () => {
|
|
370
|
+
for (const [id, d] of to) drawn.current.set(id, d);
|
|
371
|
+
paint();
|
|
372
|
+
});
|
|
373
|
+
}, [shown, target]);
|
|
374
|
+
const activeNode = active ? flat.get(active) ?? null : null;
|
|
375
|
+
const parentOf = (node) => node.parent ? flat.get(node.parent) : node;
|
|
376
|
+
const share = (node, of) => of.value ? node.value / of.value : 0;
|
|
377
|
+
const shownBefore = useRef(false);
|
|
378
|
+
useIsomorphicLayoutEffect(() => {
|
|
379
|
+
const bubble = tip.current;
|
|
380
|
+
if (!bubble || !activeNode || !width) {
|
|
381
|
+
shownBefore.current = false;
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
const r = target.get(activeNode.id);
|
|
385
|
+
const ax = pointer?.x ?? (r ? r.x + r.w / 2 : 0);
|
|
386
|
+
const ay = pointer?.y ?? (r ? r.y + Math.min(r.h / 2, 28) : 0);
|
|
387
|
+
const tw = bubble.offsetWidth;
|
|
388
|
+
const th = bubble.offsetHeight;
|
|
389
|
+
let left = ax + TIP;
|
|
390
|
+
if (left + tw > width) left = ax - TIP - tw;
|
|
391
|
+
let top = ay + TIP;
|
|
392
|
+
if (top + th > height) top = ay - TIP - th;
|
|
393
|
+
if (!shownBefore.current) bubble.style.transition = "none";
|
|
394
|
+
bubble.style.translate = `${clamp(left, 0, Math.max(0, width - tw))}px ${clamp(top, 0, Math.max(0, height - th))}px`;
|
|
395
|
+
if (!shownBefore.current) {
|
|
396
|
+
bubble.offsetWidth;
|
|
397
|
+
bubble.style.transition = "";
|
|
398
|
+
}
|
|
399
|
+
shownBefore.current = true;
|
|
400
|
+
});
|
|
401
|
+
const topTiles = center.children.map((id) => flat.get(id)).filter((node) => node.value > 0);
|
|
402
|
+
const topOf = (node) => {
|
|
403
|
+
let at = node;
|
|
404
|
+
while (at && at.parent && at.parent !== center.id) at = flat.get(at.parent) ?? null;
|
|
405
|
+
return at && at.parent === center.id ? at : null;
|
|
406
|
+
};
|
|
407
|
+
const onKeyDown = (event) => {
|
|
408
|
+
const current = topOf(activeNode);
|
|
409
|
+
const dirs = {
|
|
410
|
+
ArrowRight: [1, 0],
|
|
411
|
+
ArrowLeft: [-1, 0],
|
|
412
|
+
ArrowDown: [0, 1],
|
|
413
|
+
ArrowUp: [0, -1]
|
|
414
|
+
};
|
|
415
|
+
if (event.key in dirs) {
|
|
416
|
+
event.preventDefault();
|
|
417
|
+
setPointer(null);
|
|
418
|
+
if (!current) {
|
|
419
|
+
setActive(topTiles[0]?.id ?? null);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
const [dx, dy] = dirs[event.key];
|
|
423
|
+
const o = target.get(current.id);
|
|
424
|
+
const ox = o.x + o.w / 2;
|
|
425
|
+
const oy = o.y + o.h / 2;
|
|
426
|
+
let best = null;
|
|
427
|
+
let score = Infinity;
|
|
428
|
+
for (const node of topTiles) {
|
|
429
|
+
if (node.id === current.id) continue;
|
|
430
|
+
const r = target.get(node.id);
|
|
431
|
+
if (!r) continue;
|
|
432
|
+
const vx = r.x + r.w / 2 - ox;
|
|
433
|
+
const vy = r.y + r.h / 2 - oy;
|
|
434
|
+
const along = vx * dx + vy * dy;
|
|
435
|
+
const across = Math.abs(vx * dy - vy * dx);
|
|
436
|
+
if (along <= 1) continue;
|
|
437
|
+
const s = along + across * 1.5;
|
|
438
|
+
if (s < score) {
|
|
439
|
+
score = s;
|
|
440
|
+
best = node;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
if (best) setActive(best.id);
|
|
444
|
+
} else if (event.key === "Home" || event.key === "End") {
|
|
445
|
+
event.preventDefault();
|
|
446
|
+
setPointer(null);
|
|
447
|
+
setActive((event.key === "Home" ? topTiles[0] : topTiles[topTiles.length - 1])?.id ?? null);
|
|
448
|
+
} else if (event.key === "Enter" || event.key === " ") {
|
|
449
|
+
if (current?.children.length) {
|
|
450
|
+
event.preventDefault();
|
|
451
|
+
zoomTo(current.id);
|
|
452
|
+
setActive(current.children[0]);
|
|
453
|
+
}
|
|
454
|
+
} else if (event.key === "Escape" || event.key === "Backspace") {
|
|
455
|
+
if (center.parent) {
|
|
456
|
+
event.preventDefault();
|
|
457
|
+
zoomTo(center.parent);
|
|
458
|
+
setActive(center.id);
|
|
459
|
+
} else if (active) {
|
|
460
|
+
event.preventDefault();
|
|
461
|
+
setActive(null);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
const onTilePointerMove = (event, id) => {
|
|
466
|
+
if (event.pointerType !== "mouse") return;
|
|
467
|
+
const rect = stage.current?.getBoundingClientRect();
|
|
468
|
+
if (rect) setPointer({
|
|
469
|
+
x: event.clientX - rect.left,
|
|
470
|
+
y: event.clientY - rect.top
|
|
471
|
+
});
|
|
472
|
+
setActive(id);
|
|
473
|
+
};
|
|
474
|
+
const onTileClick = (node) => {
|
|
475
|
+
const top = topOf(node);
|
|
476
|
+
if (top?.children.length) zoomTo(top.id);
|
|
477
|
+
else if (!activeNode || activeNode.id !== node.id) setActive(node.id);
|
|
478
|
+
};
|
|
479
|
+
const trail = [];
|
|
480
|
+
for (let at = center; at; at = at.parent ? flat.get(at.parent) : void 0) trail.unshift(at);
|
|
481
|
+
const empty = !root.value;
|
|
482
|
+
const describe = (node) => `${node.path.join(", ")}, ${formatValue(node.value)}, ${PERCENT.format(share(node, parentOf(node)))} of ${parentOf(node).label}${colored && node.color !== null ? `, ${colorLabel} ${formatColor(node.color)}` : ""}`;
|
|
483
|
+
const focusTop = topOf(activeNode);
|
|
484
|
+
const summary = `${label}, ${center.label}, ${formatValue(center.value)}`;
|
|
485
|
+
return /* @__PURE__ */ jsxs("figure", {
|
|
486
|
+
ref: refs,
|
|
487
|
+
"data-slot": "treemap",
|
|
488
|
+
"aria-label": label,
|
|
489
|
+
className: cn("treemap box-border font-sans text-foreground", className),
|
|
490
|
+
children: [
|
|
491
|
+
/* @__PURE__ */ jsxs("div", {
|
|
492
|
+
className: "flex min-w-0 items-center justify-between gap-3",
|
|
493
|
+
children: [/* @__PURE__ */ jsx("nav", {
|
|
494
|
+
"aria-label": `${label} path`,
|
|
495
|
+
className: "-ms-1 min-w-0",
|
|
496
|
+
children: /* @__PURE__ */ jsx("ol", {
|
|
497
|
+
className: "m-0 flex min-h-8 min-w-0 list-none flex-wrap items-center p-0",
|
|
498
|
+
children: trail.map((node, index) => /* @__PURE__ */ jsxs("li", {
|
|
499
|
+
className: "inline-flex min-w-0 items-center motion-safe:animate-fade-in",
|
|
500
|
+
children: [index > 0 ? /* @__PURE__ */ jsx("span", {
|
|
501
|
+
"aria-hidden": "true",
|
|
502
|
+
className: "px-1 text-sm text-muted-foreground",
|
|
503
|
+
children: "/"
|
|
504
|
+
}) : null, index < trail.length - 1 ? /* @__PURE__ */ jsx("button", {
|
|
505
|
+
type: "button",
|
|
506
|
+
className: "treemap-crumb",
|
|
507
|
+
onClick: () => {
|
|
508
|
+
zoomTo(node.id);
|
|
509
|
+
setActive(null);
|
|
510
|
+
},
|
|
511
|
+
children: node.label
|
|
512
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
513
|
+
"aria-current": "location",
|
|
514
|
+
className: "px-1 text-sm font-medium whitespace-nowrap",
|
|
515
|
+
children: node.label
|
|
516
|
+
})]
|
|
517
|
+
}, node.id))
|
|
518
|
+
})
|
|
519
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
520
|
+
"data-slot": "treemap-total",
|
|
521
|
+
className: "m-0 flex-none text-sm font-medium tabular-nums",
|
|
522
|
+
children: /* @__PURE__ */ jsx(SwapText, {
|
|
523
|
+
swapKey: formatValue(center.value),
|
|
524
|
+
motion: "rise",
|
|
525
|
+
children: formatValue(center.value)
|
|
526
|
+
})
|
|
527
|
+
})]
|
|
528
|
+
}),
|
|
529
|
+
/* @__PURE__ */ jsxs("div", {
|
|
530
|
+
ref: stage,
|
|
531
|
+
"data-slot": "treemap-stage",
|
|
532
|
+
"data-active": activeNode ? "" : void 0,
|
|
533
|
+
"data-scrubbing": activeNode ? "" : void 0,
|
|
534
|
+
role: empty ? void 0 : "application",
|
|
535
|
+
tabIndex: empty ? void 0 : 0,
|
|
536
|
+
"aria-roledescription": empty ? void 0 : "treemap",
|
|
537
|
+
"aria-label": empty ? void 0 : `${label}, ${center.label}. Arrow keys move between tiles, Enter zooms in, Escape zooms out.`,
|
|
538
|
+
className: "treemap-stage",
|
|
539
|
+
style: { height },
|
|
540
|
+
onKeyDown,
|
|
541
|
+
onBlur: () => setActive(null),
|
|
542
|
+
onPointerLeave: () => {
|
|
543
|
+
setActive(null);
|
|
544
|
+
setPointer(null);
|
|
545
|
+
},
|
|
546
|
+
children: [
|
|
547
|
+
nodes.map((node) => {
|
|
548
|
+
const top = topOf(node);
|
|
549
|
+
const hue = hueOf(branchOf.get(node.id) ?? -1);
|
|
550
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
551
|
+
ref: (element) => {
|
|
552
|
+
if (element) tiles.current.set(node.id, element);
|
|
553
|
+
else tiles.current.delete(node.id);
|
|
554
|
+
},
|
|
555
|
+
"aria-hidden": "true",
|
|
556
|
+
"data-tile": node.id,
|
|
557
|
+
"data-branch": node.children.length > 0 || void 0,
|
|
558
|
+
"data-active": active === node.id || void 0,
|
|
559
|
+
"data-lineage": focusTop?.id === node.id && active !== node.id || void 0,
|
|
560
|
+
"data-dim": focusTop !== null && top !== null && focusTop.id !== top.id || void 0,
|
|
561
|
+
className: "treemap-tile",
|
|
562
|
+
style: {
|
|
563
|
+
"--hue": hue,
|
|
564
|
+
"--fill": `color-mix(in oklab, ${hue} ${shade(node.color)}%, var(--color-surface))`,
|
|
565
|
+
zIndex: node.depth
|
|
566
|
+
},
|
|
567
|
+
onPointerMove: (event) => {
|
|
568
|
+
event.stopPropagation();
|
|
569
|
+
onTilePointerMove(event, node.id);
|
|
570
|
+
},
|
|
571
|
+
onClick: (event) => {
|
|
572
|
+
event.stopPropagation();
|
|
573
|
+
onTileClick(node);
|
|
574
|
+
},
|
|
575
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
576
|
+
className: "treemap-tile-label",
|
|
577
|
+
children: node.label
|
|
578
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
579
|
+
className: "treemap-tile-value",
|
|
580
|
+
children: formatValue(node.value)
|
|
581
|
+
})]
|
|
582
|
+
}, node.id);
|
|
583
|
+
}),
|
|
584
|
+
empty ? /* @__PURE__ */ jsx("p", {
|
|
585
|
+
className: "pointer-events-none absolute inset-0 m-0 grid place-items-center text-sm text-muted-foreground",
|
|
586
|
+
children: emptyLabel
|
|
587
|
+
}) : null,
|
|
588
|
+
/* @__PURE__ */ jsx("div", {
|
|
589
|
+
className: "pointer-events-none absolute inset-0 z-50",
|
|
590
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
591
|
+
ref: tip,
|
|
592
|
+
"aria-hidden": "true",
|
|
593
|
+
"data-slot": "treemap-tooltip",
|
|
594
|
+
className: "line-chart-tooltip",
|
|
595
|
+
children: activeNode ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
596
|
+
/* @__PURE__ */ jsx("p", {
|
|
597
|
+
className: "m-0 truncate text-xs text-muted-foreground",
|
|
598
|
+
children: activeNode.path.slice(0, -1).join(" / ") || root.label
|
|
599
|
+
}),
|
|
600
|
+
/* @__PURE__ */ jsxs("p", {
|
|
601
|
+
className: "m-0 flex items-baseline justify-between gap-3 text-sm",
|
|
602
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
603
|
+
className: "min-w-0 truncate",
|
|
604
|
+
children: activeNode.label
|
|
605
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
606
|
+
className: "flex-none font-medium tabular-nums",
|
|
607
|
+
children: formatValue(activeNode.value)
|
|
608
|
+
})]
|
|
609
|
+
}),
|
|
610
|
+
/* @__PURE__ */ jsxs("p", {
|
|
611
|
+
className: "m-0 text-xs tabular-nums text-muted-foreground",
|
|
612
|
+
children: [
|
|
613
|
+
PERCENT.format(share(activeNode, parentOf(activeNode))),
|
|
614
|
+
" of ",
|
|
615
|
+
parentOf(activeNode).label
|
|
616
|
+
]
|
|
617
|
+
}),
|
|
618
|
+
colored && activeNode.color !== null ? /* @__PURE__ */ jsxs("p", {
|
|
619
|
+
className: "m-0 text-xs tabular-nums text-muted-foreground",
|
|
620
|
+
children: [
|
|
621
|
+
colorLabel,
|
|
622
|
+
" ",
|
|
623
|
+
formatColor(activeNode.color)
|
|
624
|
+
]
|
|
625
|
+
}) : null
|
|
626
|
+
] }) : null
|
|
627
|
+
})
|
|
628
|
+
})
|
|
629
|
+
]
|
|
630
|
+
}),
|
|
631
|
+
colored ? /* @__PURE__ */ jsxs("div", {
|
|
632
|
+
"aria-hidden": "true",
|
|
633
|
+
className: "flex min-w-0 flex-wrap items-center gap-2 text-xs tabular-nums text-muted-foreground",
|
|
634
|
+
children: [
|
|
635
|
+
/* @__PURE__ */ jsx("span", {
|
|
636
|
+
className: "me-1 text-text-secondary",
|
|
637
|
+
children: colorLabel
|
|
638
|
+
}),
|
|
639
|
+
/* @__PURE__ */ jsx("span", { children: formatColor(lo) }),
|
|
640
|
+
/* @__PURE__ */ jsx("span", {
|
|
641
|
+
className: "inline-flex gap-0.5",
|
|
642
|
+
children: Array.from({ length: STEPS }, (_, i) => /* @__PURE__ */ jsx("span", {
|
|
643
|
+
className: "treemap-step",
|
|
644
|
+
style: { "--fill": `color-mix(in oklab, ${center.depth === 0 ? "var(--color-foreground)" : hueOf(branchOf.get(center.id) ?? -1)} ${Math.round(14 + i / 4 * 44)}%, var(--color-surface))` }
|
|
645
|
+
}, i))
|
|
646
|
+
}),
|
|
647
|
+
/* @__PURE__ */ jsx("span", { children: formatColor(hi) })
|
|
648
|
+
]
|
|
649
|
+
}) : null,
|
|
650
|
+
/* @__PURE__ */ jsx("p", {
|
|
651
|
+
className: "sr-only",
|
|
652
|
+
children: summary
|
|
653
|
+
}),
|
|
654
|
+
/* @__PURE__ */ jsx("p", {
|
|
655
|
+
className: "sr-only",
|
|
656
|
+
"aria-live": "polite",
|
|
657
|
+
"aria-atomic": "true",
|
|
658
|
+
children: activeNode ? describe(activeNode) : ""
|
|
659
|
+
}),
|
|
660
|
+
empty ? null : /* @__PURE__ */ jsx("div", {
|
|
661
|
+
className: "sr-only",
|
|
662
|
+
children: /* @__PURE__ */ jsxs("table", { children: [
|
|
663
|
+
/* @__PURE__ */ jsx("caption", { children: label }),
|
|
664
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
665
|
+
/* @__PURE__ */ jsx("th", {
|
|
666
|
+
scope: "col",
|
|
667
|
+
children: "Path"
|
|
668
|
+
}),
|
|
669
|
+
/* @__PURE__ */ jsx("th", {
|
|
670
|
+
scope: "col",
|
|
671
|
+
children: "Value"
|
|
672
|
+
}),
|
|
673
|
+
/* @__PURE__ */ jsx("th", {
|
|
674
|
+
scope: "col",
|
|
675
|
+
children: "Share of parent"
|
|
676
|
+
}),
|
|
677
|
+
colored ? /* @__PURE__ */ jsx("th", {
|
|
678
|
+
scope: "col",
|
|
679
|
+
children: colorLabel
|
|
680
|
+
}) : null
|
|
681
|
+
] }) }),
|
|
682
|
+
/* @__PURE__ */ jsx("tbody", { children: nodes.map((node) => /* @__PURE__ */ jsxs("tr", { children: [
|
|
683
|
+
/* @__PURE__ */ jsx("th", {
|
|
684
|
+
scope: "row",
|
|
685
|
+
children: node.path.join(" / ")
|
|
686
|
+
}),
|
|
687
|
+
/* @__PURE__ */ jsx("td", { children: formatValue(node.value) }),
|
|
688
|
+
/* @__PURE__ */ jsx("td", { children: PERCENT.format(share(node, parentOf(node))) }),
|
|
689
|
+
colored ? /* @__PURE__ */ jsx("td", { children: node.color === null ? "" : formatColor(node.color) }) : null
|
|
690
|
+
] }, node.id)) })
|
|
691
|
+
] })
|
|
692
|
+
})
|
|
693
|
+
]
|
|
694
|
+
});
|
|
695
|
+
});
|
|
696
|
+
//#endregion
|
|
697
|
+
export { Treemap };
|
|
698
|
+
|
|
699
|
+
//# sourceMappingURL=treemap.js.map
|