@kumix/ui 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -13
- package/dist/components/agents/agent-activity/index.js +1 -1
- package/dist/components/agents/approval-card/index.js +2 -3
- package/dist/components/agents/approval-card/index.js.map +1 -1
- package/dist/components/agents/prompt-input.js +1 -2
- package/dist/components/agents/prompt-input.js.map +1 -1
- package/dist/components/agents/todo-list.js +1 -1
- package/dist/components/agents/tool-result.js +1 -1
- package/dist/components/charts/bar-chart/context.d.ts +114 -0
- package/dist/components/charts/bar-chart/context.d.ts.map +1 -0
- package/dist/components/charts/bar-chart/context.js +60 -0
- package/dist/components/charts/bar-chart/context.js.map +1 -0
- package/dist/components/charts/bar-chart/legend.d.ts +6 -0
- package/dist/components/charts/bar-chart/legend.d.ts.map +1 -0
- package/dist/components/charts/bar-chart/legend.js +21 -0
- package/dist/components/charts/bar-chart/legend.js.map +1 -0
- package/dist/components/charts/bar-chart/plot.d.ts +10 -0
- package/dist/components/charts/bar-chart/plot.d.ts.map +1 -0
- package/dist/components/charts/bar-chart/plot.js +290 -0
- package/dist/components/charts/bar-chart/plot.js.map +1 -0
- package/dist/components/charts/bar-chart/tooltip.d.ts +20 -0
- package/dist/components/charts/bar-chart/tooltip.d.ts.map +1 -0
- package/dist/components/charts/bar-chart/tooltip.js +57 -0
- package/dist/components/charts/bar-chart/tooltip.js.map +1 -0
- package/dist/components/charts/bar-chart.d.ts +9 -0
- package/dist/components/charts/bar-chart.d.ts.map +1 -0
- package/dist/components/charts/bar-chart.js +51 -0
- package/dist/components/charts/bar-chart.js.map +1 -0
- package/dist/components/charts/bump-chart/plot.js +1 -1
- package/dist/components/charts/bump-chart/point.js +1 -1
- package/dist/components/charts/bump-chart.js +1 -1
- package/dist/components/charts/composition-chart/plot.js +5 -1
- package/dist/components/charts/composition-chart/plot.js.map +1 -1
- package/dist/components/charts/composition-chart/tooltip-content.js +1 -1
- package/dist/components/charts/donut-chart.d.ts +1 -1
- package/dist/components/charts/donut-chart.js +1 -1
- package/dist/components/charts/funnel-chart.js +1 -1
- package/dist/components/charts/heat-calendar/tooltip.js +1 -1
- package/dist/components/charts/line-chart/context.d.ts +154 -0
- package/dist/components/charts/line-chart/context.d.ts.map +1 -0
- package/dist/components/charts/line-chart/context.js +67 -0
- package/dist/components/charts/line-chart/context.js.map +1 -0
- package/dist/components/charts/line-chart/legend.d.ts +6 -0
- package/dist/components/charts/line-chart/legend.d.ts.map +1 -0
- package/dist/components/charts/line-chart/legend.js +21 -0
- package/dist/components/charts/line-chart/legend.js.map +1 -0
- package/dist/components/charts/line-chart/plot.d.ts +12 -0
- package/dist/components/charts/line-chart/plot.d.ts.map +1 -0
- package/dist/components/charts/line-chart/plot.js +604 -0
- package/dist/components/charts/line-chart/plot.js.map +1 -0
- package/dist/components/charts/line-chart/tooltip.d.ts +22 -0
- package/dist/components/charts/line-chart/tooltip.d.ts.map +1 -0
- package/dist/components/charts/line-chart/tooltip.js +108 -0
- package/dist/components/charts/line-chart/tooltip.js.map +1 -0
- package/dist/components/charts/line-chart.d.ts +10 -0
- package/dist/components/charts/line-chart.d.ts.map +1 -0
- package/dist/components/charts/line-chart.js +53 -0
- package/dist/components/charts/line-chart.js.map +1 -0
- package/dist/components/charts/liquidity-heatmap.js +1 -1
- package/dist/components/charts/price-target-fan.js +1 -1
- package/dist/components/charts/returns-calendar/tooltip.js +1 -1
- package/dist/components/charts/returns-calendar.d.ts.map +1 -1
- package/dist/components/charts/sankey-chart/context.d.ts +2 -0
- package/dist/components/charts/sankey-chart/context.js +2 -0
- package/dist/components/charts/sankey-chart/plot.d.ts +8 -0
- package/dist/components/charts/sankey-chart/plot.d.ts.map +1 -0
- package/dist/components/charts/sankey-chart/plot.js +342 -0
- package/dist/components/charts/sankey-chart/plot.js.map +1 -0
- package/dist/components/charts/sankey-chart/tooltip.d.ts +10 -0
- package/dist/components/charts/sankey-chart/tooltip.d.ts.map +1 -0
- package/dist/components/charts/sankey-chart/tooltip.js +147 -0
- package/dist/components/charts/sankey-chart/tooltip.js.map +1 -0
- package/dist/components/charts/sankey-chart.d.ts +17 -0
- package/dist/components/charts/sankey-chart.d.ts.map +1 -0
- package/dist/components/charts/sankey-chart.js +76 -0
- package/dist/components/charts/sankey-chart.js.map +1 -0
- package/dist/components/charts/sparkline.d.ts +26 -0
- package/dist/components/charts/sparkline.d.ts.map +1 -0
- package/dist/components/charts/sparkline.js +197 -0
- package/dist/components/charts/sparkline.js.map +1 -0
- package/dist/components/charts/treemap/tooltip.js +1 -1
- package/dist/components/charts/treemap.d.ts.map +1 -1
- package/dist/components/charts/volume-profile/tooltip.js +1 -1
- package/dist/components/charts/xy/axis.d.ts +24 -0
- package/dist/components/charts/xy/axis.d.ts.map +1 -0
- package/dist/components/charts/xy/axis.js +90 -0
- package/dist/components/charts/xy/axis.js.map +1 -0
- package/dist/components/charts/xy/data-table.d.ts +9 -0
- package/dist/components/charts/xy/data-table.d.ts.map +1 -0
- package/dist/components/charts/xy/data-table.js +29 -0
- package/dist/components/charts/xy/data-table.js.map +1 -0
- package/dist/components/charts/xy/inspector.d.ts +27 -0
- package/dist/components/charts/xy/inspector.d.ts.map +1 -0
- package/dist/components/charts/xy/inspector.js +110 -0
- package/dist/components/charts/xy/inspector.js.map +1 -0
- package/dist/components/charts/xy/legend.d.ts +13 -0
- package/dist/components/charts/xy/legend.d.ts.map +1 -0
- package/dist/components/charts/xy/legend.js +42 -0
- package/dist/components/charts/xy/legend.js.map +1 -0
- package/dist/components/charts/xy/tooltip-content.d.ts +2 -0
- package/dist/components/charts/xy/tooltip-content.js +66 -0
- package/dist/components/charts/xy/tooltip-content.js.map +1 -0
- package/dist/components/motion/attachment-upload.js +1 -1
- package/dist/components/motion/availability-scheduler/copy-menu.js +1 -1
- package/dist/components/motion/availability-scheduler/day-row.js +2 -2
- package/dist/components/motion/availability-scheduler/index.js +1 -1
- package/dist/components/motion/avatar-group.d.ts +48 -0
- package/dist/components/motion/avatar-group.d.ts.map +1 -0
- package/dist/components/motion/avatar-group.js +196 -0
- package/dist/components/motion/avatar-group.js.map +1 -0
- package/dist/components/motion/bottom-sheet.js +1 -1
- package/dist/components/motion/bouncy-accordion.d.ts.map +1 -1
- package/dist/components/motion/bouncy-accordion.js +20 -34
- package/dist/components/motion/bouncy-accordion.js.map +1 -1
- package/dist/components/motion/breadcrumb.js +0 -3
- package/dist/components/motion/breadcrumb.js.map +1 -1
- package/dist/components/motion/button/magnetic.js +1 -1
- package/dist/components/motion/card-dealer.d.ts +36 -0
- package/dist/components/motion/card-dealer.d.ts.map +1 -0
- package/dist/components/motion/card-dealer.js +232 -0
- package/dist/components/motion/card-dealer.js.map +1 -0
- package/dist/components/motion/color-picker.js +1 -1
- package/dist/components/motion/combobox.js +1 -1
- package/dist/components/motion/context-menu.js +1 -1
- package/dist/components/motion/crash/crash-balloon.d.ts +9 -0
- package/dist/components/motion/crash/crash-balloon.d.ts.map +1 -0
- package/dist/components/motion/crash/crash-balloon.js +829 -0
- package/dist/components/motion/crash/crash-balloon.js.map +1 -0
- package/dist/components/motion/crash/crash-parts.d.ts +59 -0
- package/dist/components/motion/crash/crash-parts.d.ts.map +1 -0
- package/dist/components/motion/crash/crash-parts.js +2 -0
- package/dist/components/motion/crash/crash-tower.d.ts +9 -0
- package/dist/components/motion/crash/crash-tower.d.ts.map +1 -0
- package/dist/components/motion/crash/crash-tower.js +370 -0
- package/dist/components/motion/crash/crash-tower.js.map +1 -0
- package/dist/components/motion/crash.d.ts +9 -0
- package/dist/components/motion/crash.d.ts.map +1 -0
- package/dist/components/motion/crash.js +590 -0
- package/dist/components/motion/crash.js.map +1 -0
- package/dist/components/motion/date-range-picker.js +1 -1
- package/dist/components/motion/feedback-widget.js +0 -1
- package/dist/components/motion/feedback-widget.js.map +1 -1
- package/dist/components/motion/hold-action-button.js +1 -1
- package/dist/components/motion/liquid.js +2 -2
- package/dist/components/motion/liquid.js.map +1 -1
- package/dist/components/motion/loader.js +5 -4
- package/dist/components/motion/loader.js.map +1 -1
- package/dist/components/motion/mines.d.ts +41 -0
- package/dist/components/motion/mines.d.ts.map +1 -0
- package/dist/components/motion/mines.js +762 -0
- package/dist/components/motion/mines.js.map +1 -0
- package/dist/components/motion/morphing-modal.js +6 -4
- package/dist/components/motion/morphing-modal.js.map +1 -1
- package/dist/components/motion/morphing-tabs.js +1 -1
- package/dist/components/motion/multi-select/index.js +1 -1
- package/dist/components/motion/pagination.d.ts +31 -0
- package/dist/components/motion/pagination.d.ts.map +1 -0
- package/dist/components/motion/pagination.js +193 -0
- package/dist/components/motion/pagination.js.map +1 -0
- package/dist/components/motion/plinko.d.ts +59 -0
- package/dist/components/motion/plinko.d.ts.map +1 -0
- package/dist/components/motion/plinko.js +385 -0
- package/dist/components/motion/plinko.js.map +1 -0
- package/dist/components/motion/popover-morph.d.ts +11 -2
- package/dist/components/motion/popover-morph.d.ts.map +1 -1
- package/dist/components/motion/popover-morph.js +98 -4
- package/dist/components/motion/popover-morph.js.map +1 -1
- package/dist/components/motion/pull-to-refresh.js +1 -1
- package/dist/components/motion/range-slider-bubble.js +1 -1
- package/dist/components/motion/range-slider-fluid.js +1 -1
- package/dist/components/motion/range-slider-inline.js +1 -1
- package/dist/components/motion/range-slider-ruler.js +1 -1
- package/dist/components/motion/range-slider-wave.js +1 -1
- package/dist/components/motion/range-slider.js +1 -1
- package/dist/components/motion/signup-form.js +0 -1
- package/dist/components/motion/signup-form.js.map +1 -1
- package/dist/components/motion/slide-action-button.js +1 -1
- package/dist/components/motion/swap/field.js +1 -1
- package/dist/components/motion/swap/token-picker.js +1 -1
- package/dist/components/motion/swap.d.ts +1 -1
- package/dist/components/motion/swap.js +2 -2
- package/dist/components/motion/table/index.js +2 -2
- package/dist/components/motion/table/table-header.js +1 -1
- package/dist/components/motion/tooltip.d.ts +2 -2
- package/dist/components/motion/tooltip.d.ts.map +1 -1
- package/dist/components/motion/wallet-card/index.js +1 -2
- package/dist/components/motion/wallet-card/index.js.map +1 -1
- package/dist/components/motion/wheel-picker.js +1 -1
- package/dist/components/reui/badge.d.ts +1 -1
- package/dist/components/reui/cascader/cascader-columns.js +1 -1
- package/dist/components/reui/cascader/cascader-footer.js +1 -1
- package/dist/components/reui/cascader/cascader-nav.js +1 -1
- package/dist/components/reui/cascader/cascader-virtual.js +1 -1
- package/dist/components/reui/cascader/cascader.d.ts +1 -1
- package/dist/components/reui/cascader/cascader.js +2 -2
- package/dist/components/reui/code-block/code-block.d.ts +2 -1
- package/dist/components/reui/code-block/code-block.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-filter.js +1 -1
- package/dist/components/reui/data-grid/data-grid-pagination.js +1 -1
- package/dist/components/reui/data-grid/data-grid-table.d.ts +1 -1
- package/dist/components/reui/data-grid/data-grid-table.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table.js +1 -1
- package/dist/components/reui/date-selector.js +2 -2
- package/dist/components/reui/emoji-picker.js +2 -2
- package/dist/components/reui/event-calendar/event-calendar-agenda-view.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-content.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-dnd.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-event.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-month-view.js +2 -2
- package/dist/components/reui/event-calendar/event-calendar-nav.js +2 -2
- package/dist/components/reui/event-calendar/event-calendar-resource-view.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-time-grid.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar.d.ts +1 -1
- package/dist/components/reui/filters/filters-advanced.js +4 -4
- package/dist/components/reui/filters/filters-builder.js +1 -1
- package/dist/components/reui/filters/filters-chip.js +2 -2
- package/dist/components/reui/filters/filters-context.d.ts +1 -1
- package/dist/components/reui/filters/filters-editors.js +3 -3
- package/dist/components/reui/filters/filters.d.ts +3 -3
- package/dist/components/reui/filters/filters.js +6 -6
- package/dist/components/reui/gantt/gantt-bar.js +1 -1
- package/dist/components/reui/gantt/gantt-dnd.js +1 -1
- package/dist/components/reui/gantt/gantt-nav.js +2 -2
- package/dist/components/reui/gantt/gantt-view.js +3 -3
- package/dist/components/reui/gantt/gantt.d.ts +1 -1
- package/dist/components/reui/icon-tile.d.ts +1 -1
- package/dist/components/reui/phone-input.js +2 -2
- package/dist/components/reui/tree.d.ts +1 -0
- package/dist/components/reui/tree.d.ts.map +1 -1
- package/dist/components/ui/attachment.d.ts +1 -1
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/bubble.d.ts +1 -1
- package/dist/components/ui/button-group.d.ts +1 -1
- package/dist/components/ui/button.d.ts +2 -2
- package/dist/components/ui/command.js +1 -1
- package/dist/components/ui/field.d.ts +1 -1
- package/dist/components/ui/field.js +1 -1
- package/dist/components/ui/item.d.ts +1 -1
- package/dist/components/ui/marker.d.ts +1 -1
- package/dist/components/ui/sidebar.d.ts +1 -1
- package/dist/components/ui/sidebar.js +1 -1
- package/dist/components/ui/tabs.d.ts +1 -1
- package/dist/context-CQbvWVnM.js +393 -0
- package/dist/context-CQbvWVnM.js.map +1 -0
- package/dist/context-tv-kneJV.d.ts +204 -0
- package/dist/context-tv-kneJV.d.ts.map +1 -0
- package/dist/{copy-menu-CKW3jM1J.js → copy-menu-LU54Aruj.js} +2 -2
- package/dist/{copy-menu-CKW3jM1J.js.map → copy-menu-LU54Aruj.js.map} +1 -1
- package/dist/crash-parts-CUv5gFYQ.js +1053 -0
- package/dist/crash-parts-CUv5gFYQ.js.map +1 -0
- package/dist/{ease-CHhXKlG3.d.ts → ease-DjhlGGZO.d.ts} +4 -2
- package/dist/ease-DjhlGGZO.d.ts.map +1 -0
- package/dist/hooks/use-highlighted-code.d.ts +1 -1
- package/dist/hooks/use-highlighted-code.d.ts.map +1 -1
- package/dist/hooks/use-modal-scope.js +2 -2
- package/dist/hooks/use-modal-scope.js.map +1 -1
- package/dist/lib/audio-context.d.ts +11 -0
- package/dist/lib/audio-context.d.ts.map +1 -0
- package/dist/lib/audio-context.js +37 -0
- package/dist/lib/audio-context.js.map +1 -0
- package/dist/lib/ease.d.ts +2 -2
- package/dist/lib/ease.js +8 -1
- package/dist/lib/ease.js.map +1 -1
- package/dist/lib/focusable.d.ts +2 -0
- package/dist/lib/focusable.d.ts.map +1 -0
- package/dist/lib/focusable.js +12 -0
- package/dist/lib/focusable.js.map +1 -0
- package/dist/lib/game-sounds.d.ts +18 -0
- package/dist/lib/game-sounds.d.ts.map +1 -0
- package/dist/lib/game-sounds.js +142 -0
- package/dist/lib/game-sounds.js.map +1 -0
- package/dist/lib/tick-sound.d.ts +4 -3
- package/dist/lib/tick-sound.d.ts.map +1 -1
- package/dist/lib/tick-sound.js +30 -37
- package/dist/lib/tick-sound.js.map +1 -1
- package/dist/model-CvWolJdo.d.ts +14 -0
- package/dist/model-CvWolJdo.d.ts.map +1 -0
- package/dist/path-VEfFUowr.d.ts +3 -0
- package/dist/path-VEfFUowr.d.ts.map +1 -0
- package/dist/{plot-DAKl-Lu1.js → plot-CTQFrQKi.js} +2 -2
- package/dist/{plot-DAKl-Lu1.js.map → plot-CTQFrQKi.js.map} +1 -1
- package/dist/scale-DSsaupNc.d.ts +7 -0
- package/dist/scale-DSsaupNc.d.ts.map +1 -0
- package/dist/tooltip-CNEYdIX3.d.ts.map +1 -1
- package/dist/tooltip-content-K0vPsEtI.d.ts +17 -0
- package/dist/tooltip-content-K0vPsEtI.d.ts.map +1 -0
- package/dist/use-crash-game-B3RHxFkm.d.ts +108 -0
- package/dist/use-crash-game-B3RHxFkm.d.ts.map +1 -0
- package/dist/use-inspection-CZhdpH8J.js +127 -0
- package/dist/use-inspection-CZhdpH8J.js.map +1 -0
- package/dist/use-points-C2jpElHh.js +118 -0
- package/dist/use-points-C2jpElHh.js.map +1 -0
- package/dist/use-width-CkKCh1b3.js +23 -0
- package/dist/use-width-CkKCh1b3.js.map +1 -0
- package/package.json +7 -7
- package/dist/ease-CHhXKlG3.d.ts.map +0 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { n as XYTooltipRow } from "../../../tooltip-content-K0vPsEtI.js";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
export interface LineChartTooltipData {
|
|
4
|
+
category: string;
|
|
5
|
+
index: number;
|
|
6
|
+
rows: XYTooltipRow[];
|
|
7
|
+
}
|
|
8
|
+
export interface LineChartTooltipProps {
|
|
9
|
+
children?: ReactNode | ((data: LineChartTooltipData) => ReactNode);
|
|
10
|
+
className?: string;
|
|
11
|
+
/**
|
|
12
|
+
* `auto` sits right of the point, flips left near the right edge, and on
|
|
13
|
+
* plots too narrow for either moves above or below the point instead.
|
|
14
|
+
*/
|
|
15
|
+
side?: "auto" | "left" | "right";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A panel inside the plot that springs after the inspected point, beside its
|
|
19
|
+
* highest visible value, so it never covers the dots it describes.
|
|
20
|
+
*/
|
|
21
|
+
export declare function LineChartTooltip({ children, className, side }: LineChartTooltipProps): import("react").ReactPortal | null;
|
|
22
|
+
//# sourceMappingURL=tooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip.d.ts","names":[],"sources":["../../../../src/components/charts/line-chart/tooltip.tsx"],"mappings":";;iBAWiB;EACf;EACA;EACA,MAAM;;iBAGS;EACf,WAAW,cAAc,MAAM,yBAAyB;EACxD;;;;;EAKA;;;;;;wBAcc,mBAAmB,UAAU,WAAW,QAAiB,wCAAqB"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { TooltipSurface } from "../../motion/tooltip-surface.js";
|
|
3
|
+
import { XYTooltipContent } from "../xy/tooltip-content.js";
|
|
4
|
+
import { useLineChart } from "./context.js";
|
|
5
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
6
|
+
import { cn } from "@kumix/utils";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
import { AnimatePresence, motion } from "motion/react";
|
|
9
|
+
import { createPortal } from "react-dom";
|
|
10
|
+
// src/components/charts/line-chart/tooltip.tsx
|
|
11
|
+
const GAP = 16;
|
|
12
|
+
/** The panel may extend this far into the axis gutters beside the plot, in px. */
|
|
13
|
+
const BLEED = {
|
|
14
|
+
left: 40,
|
|
15
|
+
right: 12
|
|
16
|
+
};
|
|
17
|
+
const FOLLOW = {
|
|
18
|
+
type: "spring",
|
|
19
|
+
stiffness: 260,
|
|
20
|
+
damping: 28,
|
|
21
|
+
mass: .7
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A panel inside the plot that springs after the inspected point, beside its
|
|
25
|
+
* highest visible value, so it never covers the dots it describes.
|
|
26
|
+
*/
|
|
27
|
+
function LineChartTooltip({ children, className, side = "auto" }) {
|
|
28
|
+
const { categories, visibleRows, domain, activeIndex, open, loading, overlay, geometry, tooltipId, formatValue, reduce, touching } = useLineChart();
|
|
29
|
+
const panelRef = useRef(null);
|
|
30
|
+
const [size, setSize] = useState({
|
|
31
|
+
width: 224,
|
|
32
|
+
height: 96
|
|
33
|
+
});
|
|
34
|
+
const category = loading ? void 0 : categories[activeIndex];
|
|
35
|
+
const visible = open && category !== void 0;
|
|
36
|
+
useLayoutEffect(() => {
|
|
37
|
+
const node = panelRef.current;
|
|
38
|
+
if (!visible || !node) return;
|
|
39
|
+
const update = () => setSize((previous) => previous.width === node.offsetWidth && previous.height === node.offsetHeight ? previous : {
|
|
40
|
+
width: node.offsetWidth,
|
|
41
|
+
height: node.offsetHeight
|
|
42
|
+
});
|
|
43
|
+
update();
|
|
44
|
+
const observer = new ResizeObserver(update);
|
|
45
|
+
observer.observe(node);
|
|
46
|
+
return () => observer.disconnect();
|
|
47
|
+
}, [visible]);
|
|
48
|
+
if (!overlay) return null;
|
|
49
|
+
const rows = visibleRows.map((row) => ({
|
|
50
|
+
id: row.id,
|
|
51
|
+
name: row.name,
|
|
52
|
+
color: row.color,
|
|
53
|
+
value: row.values[activeIndex] ?? null
|
|
54
|
+
}));
|
|
55
|
+
const values = rows.flatMap((row) => row.value === null ? [] : [row.value]);
|
|
56
|
+
const top = values.length ? Math.max(...values) : domain.max;
|
|
57
|
+
const n = categories.length;
|
|
58
|
+
const { width: W, height: H } = geometry;
|
|
59
|
+
const px = (n === 1 ? .5 : Math.max(activeIndex, 0) / (n - 1)) * W;
|
|
60
|
+
const py = (domain.max - top) / (domain.max - domain.min || 1) * H;
|
|
61
|
+
const minX = -BLEED.left;
|
|
62
|
+
const maxX = W + BLEED.right;
|
|
63
|
+
const fitsRight = px + GAP + size.width <= maxX;
|
|
64
|
+
const fitsLeft = px - GAP - size.width >= minX;
|
|
65
|
+
const placement = side === "right" || side === "auto" && fitsRight ? "right" : side === "left" || side === "auto" && fitsLeft ? "left" : py - GAP - size.height >= 0 ? "above" : "below";
|
|
66
|
+
const clampX = (value) => Math.min(Math.max(value, minX), maxX - size.width);
|
|
67
|
+
const clampY = (value) => Math.min(Math.max(value, -8), Math.max(-8, H + 8 - size.height));
|
|
68
|
+
const position = placement === "right" ? {
|
|
69
|
+
x: px + GAP,
|
|
70
|
+
y: clampY(py - size.height / 2)
|
|
71
|
+
} : placement === "left" ? {
|
|
72
|
+
x: px - GAP - size.width,
|
|
73
|
+
y: clampY(py - size.height / 2)
|
|
74
|
+
} : {
|
|
75
|
+
x: clampX(px - size.width / 2),
|
|
76
|
+
y: placement === "above" ? py - GAP - size.height : py + GAP
|
|
77
|
+
};
|
|
78
|
+
const origin = {
|
|
79
|
+
right: "left center",
|
|
80
|
+
left: "right center",
|
|
81
|
+
above: "bottom center",
|
|
82
|
+
below: "top center"
|
|
83
|
+
}[placement];
|
|
84
|
+
return createPortal(/* @__PURE__ */ jsx(AnimatePresence, { children: visible ? /* @__PURE__ */ jsx(motion.div, {
|
|
85
|
+
ref: panelRef,
|
|
86
|
+
className: "pointer-events-none absolute top-0 left-0 z-10 w-max",
|
|
87
|
+
initial: position,
|
|
88
|
+
animate: position,
|
|
89
|
+
transition: reduce || touching ? { duration: 0 } : FOLLOW,
|
|
90
|
+
children: /* @__PURE__ */ jsx(TooltipSurface, {
|
|
91
|
+
id: tooltipId,
|
|
92
|
+
style: { "--tooltip-origin": origin },
|
|
93
|
+
className: cn("max-w-[min(20rem,calc(100vw-2rem))] py-2", className),
|
|
94
|
+
children: typeof children === "function" ? children({
|
|
95
|
+
category,
|
|
96
|
+
index: activeIndex,
|
|
97
|
+
rows
|
|
98
|
+
}) : children ?? /* @__PURE__ */ jsx(XYTooltipContent, {
|
|
99
|
+
title: category,
|
|
100
|
+
rows,
|
|
101
|
+
formatValue
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
}, "tooltip") : null }), overlay);
|
|
105
|
+
}
|
|
106
|
+
export { LineChartTooltip };
|
|
107
|
+
|
|
108
|
+
//# sourceMappingURL=tooltip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip.js","names":[],"sources":["../../../../src/components/charts/line-chart/tooltip.tsx"],"sourcesContent":["\"use client\";\n\nimport { type CSSProperties, type ReactNode, useLayoutEffect, useRef, useState } from \"react\";\nimport { AnimatePresence, motion } from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { TooltipSurface } from \"../../motion/tooltip-surface\";\nimport { XYTooltipContent, type XYTooltipRow } from \"../xy/tooltip-content\";\nimport { useLineChart } from \"./context\";\n\nexport interface LineChartTooltipData {\n category: string;\n index: number;\n rows: XYTooltipRow[];\n}\n\nexport interface LineChartTooltipProps {\n children?: ReactNode | ((data: LineChartTooltipData) => ReactNode);\n className?: string;\n /**\n * `auto` sits right of the point, flips left near the right edge, and on\n * plots too narrow for either moves above or below the point instead.\n */\n side?: \"auto\" | \"left\" | \"right\";\n}\n\nconst GAP = 16;\n/** The panel may extend this far into the axis gutters beside the plot, in px. */\nconst BLEED = { left: 40, right: 12 } as const;\n// Softer than the crosshair's layout spring on purpose: the panel trails a\n// beat behind the point it describes instead of moving rigidly with it.\nconst FOLLOW = { type: \"spring\", stiffness: 260, damping: 28, mass: 0.7 } as const;\n\n/**\n * A panel inside the plot that springs after the inspected point, beside its\n * highest visible value, so it never covers the dots it describes.\n */\nexport function LineChartTooltip({ children, className, side = \"auto\" }: LineChartTooltipProps) {\n const {\n categories,\n visibleRows,\n domain,\n activeIndex,\n open,\n loading,\n overlay,\n geometry,\n tooltipId,\n formatValue,\n reduce,\n touching,\n } = useLineChart();\n const panelRef = useRef<HTMLDivElement>(null);\n // Kept between openings: the panel's size barely changes from one point to the next.\n const [size, setSize] = useState({ width: 224, height: 96 });\n const category = loading ? undefined : categories[activeIndex];\n const visible = open && category !== undefined;\n useLayoutEffect(() => {\n const node = panelRef.current;\n if (!visible || !node) return;\n const update = () =>\n setSize((previous) =>\n previous.width === node.offsetWidth && previous.height === node.offsetHeight\n ? previous\n : { width: node.offsetWidth, height: node.offsetHeight },\n );\n update();\n const observer = new ResizeObserver(update);\n observer.observe(node);\n return () => observer.disconnect();\n }, [visible]);\n if (!overlay) return null;\n\n const rows: XYTooltipRow[] = visibleRows.map((row) => ({\n id: row.id,\n name: row.name,\n color: row.color,\n value: row.values[activeIndex] ?? null,\n }));\n const values = rows.flatMap((row) => (row.value === null ? [] : [row.value]));\n const top = values.length ? Math.max(...values) : domain.max;\n const n = categories.length;\n const { width: W, height: H } = geometry;\n const px = (n === 1 ? 0.5 : Math.max(activeIndex, 0) / (n - 1)) * W;\n const py = ((domain.max - top) / (domain.max - domain.min || 1)) * H;\n const minX = -BLEED.left;\n const maxX = W + BLEED.right;\n const fitsRight = px + GAP + size.width <= maxX;\n const fitsLeft = px - GAP - size.width >= minX;\n const placement =\n side === \"right\" || (side === \"auto\" && fitsRight)\n ? \"right\"\n : side === \"left\" || (side === \"auto\" && fitsLeft)\n ? \"left\"\n : py - GAP - size.height >= 0\n ? \"above\"\n : \"below\";\n const clampX = (value: number) => Math.min(Math.max(value, minX), maxX - size.width);\n const clampY = (value: number) =>\n Math.min(Math.max(value, -8), Math.max(-8, H + 8 - size.height));\n const position =\n placement === \"right\"\n ? { x: px + GAP, y: clampY(py - size.height / 2) }\n : placement === \"left\"\n ? { x: px - GAP - size.width, y: clampY(py - size.height / 2) }\n : {\n x: clampX(px - size.width / 2),\n y: placement === \"above\" ? py - GAP - size.height : py + GAP,\n };\n const origin = {\n right: \"left center\",\n left: \"right center\",\n above: \"bottom center\",\n below: \"top center\",\n }[placement];\n\n return createPortal(\n <AnimatePresence>\n {visible ? (\n <motion.div\n key=\"tooltip\"\n ref={panelRef}\n className=\"pointer-events-none absolute top-0 left-0 z-10 w-max\"\n initial={position}\n animate={position}\n // The trailing follow suits a mouse; under a finger it reads as lag.\n transition={reduce || touching ? { duration: 0 } : FOLLOW}\n >\n <TooltipSurface\n id={tooltipId}\n style={{ \"--tooltip-origin\": origin } as CSSProperties}\n className={cn(\"max-w-[min(20rem,calc(100vw-2rem))] py-2\", className)}\n >\n {typeof children === \"function\"\n ? children({ category, index: activeIndex, rows })\n : (children ?? (\n <XYTooltipContent title={category} rows={rows} formatValue={formatValue} />\n ))}\n </TooltipSurface>\n </motion.div>\n ) : null}\n </AnimatePresence>,\n overlay,\n );\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LineChartProps, useLineChart } from "./line-chart/context.js";
|
|
2
|
+
import { LineChartLegend, LineChartLegendProps } from "./line-chart/legend.js";
|
|
3
|
+
import { LineChartPlot, LineChartPlotProps } from "./line-chart/plot.js";
|
|
4
|
+
import { LineChartTooltip, LineChartTooltipData, LineChartTooltipProps } from "./line-chart/tooltip.js";
|
|
5
|
+
import { n as XYSeries } from "../../model-CvWolJdo.js";
|
|
6
|
+
import { t as XYCurve } from "../../path-VEfFUowr.js";
|
|
7
|
+
/** Compose Plot, Tooltip and Legend, or omit children for the complete chart. */
|
|
8
|
+
export declare function LineChart({ series, categories, variant, curve, domain, activeId, defaultActiveId, onActiveChange, hiddenSeries, defaultHiddenSeries, onHiddenSeriesChange, formatValue, formatTick, label, status, loadingLabel, children, className, ...props }: LineChartProps): import("react").JSX.Element;
|
|
9
|
+
export { type XYCurve as LineChartCurve, LineChartLegend, type LineChartLegendProps, LineChartPlot, type LineChartPlotProps, type LineChartProps, type XYSeries as LineChartSeries, LineChartTooltip, type LineChartTooltipData, type LineChartTooltipProps, useLineChart };
|
|
10
|
+
//# sourceMappingURL=line-chart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line-chart.d.ts","names":[],"sources":["../../../src/components/charts/line-chart.tsx"],"mappings":";;;;;;;wBAUgB,YACd,QACA,YACA,SACA,OACA,QACA,UACA,iBACA,gBACA,cACA,qBACA,sBACA,aACA,YACA,OACA,QACA,cACA,UACA,cACG,SACF,iCAAc,IAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { LineChartContext, useLineChart, useLineChartModel } from "./line-chart/context.js";
|
|
3
|
+
import { LineChartLegend } from "./line-chart/legend.js";
|
|
4
|
+
import { LineChartPlot } from "./line-chart/plot.js";
|
|
5
|
+
import { LineChartTooltip } from "./line-chart/tooltip.js";
|
|
6
|
+
import { XYDataTable } from "./xy/data-table.js";
|
|
7
|
+
import { cn } from "@kumix/utils";
|
|
8
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
// src/components/charts/line-chart.tsx
|
|
10
|
+
/** Compose Plot, Tooltip and Legend, or omit children for the complete chart. */
|
|
11
|
+
function LineChart({ series, categories, variant, curve, domain, activeId, defaultActiveId, onActiveChange, hiddenSeries, defaultHiddenSeries, onHiddenSeriesChange, formatValue, formatTick, label, status, loadingLabel, children, className, ...props }) {
|
|
12
|
+
const model = useLineChartModel({
|
|
13
|
+
series,
|
|
14
|
+
categories,
|
|
15
|
+
variant,
|
|
16
|
+
curve,
|
|
17
|
+
domain,
|
|
18
|
+
activeId,
|
|
19
|
+
defaultActiveId,
|
|
20
|
+
onActiveChange,
|
|
21
|
+
hiddenSeries,
|
|
22
|
+
defaultHiddenSeries,
|
|
23
|
+
onHiddenSeriesChange,
|
|
24
|
+
formatValue,
|
|
25
|
+
formatTick,
|
|
26
|
+
label,
|
|
27
|
+
status,
|
|
28
|
+
loadingLabel
|
|
29
|
+
});
|
|
30
|
+
return /* @__PURE__ */ jsx(LineChartContext.Provider, {
|
|
31
|
+
value: model,
|
|
32
|
+
children: /* @__PURE__ */ jsxs("section", {
|
|
33
|
+
"aria-label": model.label,
|
|
34
|
+
"aria-busy": model.loading || void 0,
|
|
35
|
+
...props,
|
|
36
|
+
"data-slot": "line-chart",
|
|
37
|
+
className: cn("w-full min-w-0 space-y-3", className),
|
|
38
|
+
children: [children === void 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
39
|
+
/* @__PURE__ */ jsx(LineChartPlot, {}),
|
|
40
|
+
/* @__PURE__ */ jsx(LineChartTooltip, {}),
|
|
41
|
+
model.rows.length > 1 ? /* @__PURE__ */ jsx(LineChartLegend, {}) : null
|
|
42
|
+
] }) : children, model.loading ? null : /* @__PURE__ */ jsx(XYDataTable, {
|
|
43
|
+
label: model.label,
|
|
44
|
+
rows: model.rows,
|
|
45
|
+
categories: model.categories,
|
|
46
|
+
formatValue: model.formatValue
|
|
47
|
+
})]
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export { LineChart, LineChartLegend, LineChartPlot, LineChartTooltip, useLineChart };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=line-chart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line-chart.js","names":[],"sources":["../../../src/components/charts/line-chart.tsx"],"sourcesContent":["\"use client\";\n\nimport { cn } from \"@kumix/utils\";\nimport { LineChartContext, type LineChartProps, useLineChartModel } from \"./line-chart/context\";\nimport { LineChartLegend } from \"./line-chart/legend\";\nimport { LineChartPlot } from \"./line-chart/plot\";\nimport { LineChartTooltip } from \"./line-chart/tooltip\";\nimport { XYDataTable } from \"./xy/data-table\";\n\n/** Compose Plot, Tooltip and Legend, or omit children for the complete chart. */\nexport function LineChart({\n series,\n categories,\n variant,\n curve,\n domain,\n activeId,\n defaultActiveId,\n onActiveChange,\n hiddenSeries,\n defaultHiddenSeries,\n onHiddenSeriesChange,\n formatValue,\n formatTick,\n label,\n status,\n loadingLabel,\n children,\n className,\n ...props\n}: LineChartProps) {\n const model = useLineChartModel({\n series,\n categories,\n variant,\n curve,\n domain,\n activeId,\n defaultActiveId,\n onActiveChange,\n hiddenSeries,\n defaultHiddenSeries,\n onHiddenSeriesChange,\n formatValue,\n formatTick,\n label,\n status,\n loadingLabel,\n });\n return (\n <LineChartContext.Provider value={model}>\n <section\n aria-label={model.label}\n aria-busy={model.loading || undefined}\n {...props}\n data-slot=\"line-chart\"\n className={cn(\"w-full min-w-0 space-y-3\", className)}\n >\n {children === undefined ? (\n <>\n <LineChartPlot />\n <LineChartTooltip />\n {model.rows.length > 1 ? <LineChartLegend /> : null}\n </>\n ) : (\n children\n )}\n {/* Placeholder or stale values are not data yet. */}\n {model.loading ? null : (\n <XYDataTable\n label={model.label}\n rows={model.rows}\n categories={model.categories}\n formatValue={model.formatValue}\n />\n )}\n </section>\n </LineChartContext.Provider>\n );\n}\n\nexport type { LineChartProps } from \"./line-chart/context\";\nexport { useLineChart } from \"./line-chart/context\";\nexport type { LineChartLegendProps } from \"./line-chart/legend\";\nexport { LineChartLegend } from \"./line-chart/legend\";\nexport type { LineChartPlotProps } from \"./line-chart/plot\";\nexport { LineChartPlot } from \"./line-chart/plot\";\nexport type { LineChartTooltipData, LineChartTooltipProps } from \"./line-chart/tooltip\";\nexport { LineChartTooltip } from \"./line-chart/tooltip\";\nexport type { XYSeries as LineChartSeries } from \"./xy/model\";\nexport type { XYCurve as LineChartCurve } from \"./xy/path\";\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,UAAU,EACxB,QACA,YACA,SACA,OACA,QACA,UACA,iBACA,gBACA,cACA,qBACA,sBACA,aACA,YACA,OACA,QACA,cACA,UACA,WACA,GAAG,SACc;CACjB,MAAM,QAAQ,kBAAkB;EAC9B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,iBAAiB,UAAlB;EAA2B,OAAO;EAChC,UAAA,qBAAC,WAAD;GACE,cAAY,MAAM;GAClB,aAAW,MAAM,WAAW,KAAA;GAC5B,GAAI;GACJ,aAAU;GACV,WAAW,GAAG,4BAA4B,SAAS;GALrD,UAAA,CAOG,aAAa,KAAA,IACZ,qBAAA,UAAA,EAAA,UAAA;IACE,oBAAC,eAAD,CAAgB,CAAA;IAChB,oBAAC,kBAAD,CAAmB,CAAA;IAClB,MAAM,KAAK,SAAS,IAAI,oBAAC,iBAAD,CAAkB,CAAA,IAAI;GAC/C,EAAA,CAAA,IAEF,UAGD,MAAM,UAAU,OACf,oBAAC,aAAD;IACE,OAAO,MAAM;IACb,MAAM,MAAM;IACZ,YAAY,MAAM;IAClB,aAAa,MAAM;GACpB,CAAA,CAEI;;CACgB,CAAA;AAE/B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { EASE_OUT } from "../../lib/ease.js";
|
|
3
|
-
import { t as Tooltip } from "../../tooltip-CuHpilPN.js";
|
|
4
3
|
import { NumberTicker } from "../motion/number-ticker.js";
|
|
4
|
+
import { t as Tooltip } from "../../tooltip-CuHpilPN.js";
|
|
5
5
|
import { createContext, useContext, useId, useMemo, useRef, useState } from "react";
|
|
6
6
|
import { cn } from "@kumix/utils";
|
|
7
7
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { n as usePriceTargetFan, r as usePriceTargetFanModel, t as PriceTargetFanContext } from "../../context-ChsuSih6.js";
|
|
3
3
|
import { PriceTargetFanHeader } from "./price-target-fan/header.js";
|
|
4
|
+
import { PriceTargetFanAxes, PriceTargetFanPlot, PriceTargetFanSvg } from "./price-target-fan/plot.js";
|
|
4
5
|
import { PriceTargetFanCursor, PriceTargetFanHistory, PriceTargetFanNow, PriceTargetFanTargets } from "./price-target-fan/series.js";
|
|
5
6
|
import { PriceTargetFanTooltip } from "./price-target-fan/tooltip.js";
|
|
6
|
-
import { PriceTargetFanAxes, PriceTargetFanPlot, PriceTargetFanSvg } from "./price-target-fan/plot.js";
|
|
7
7
|
import { cn } from "@kumix/utils";
|
|
8
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
// src/components/charts/price-target-fan.tsx
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { t as Tooltip } from "../../../tooltip-CuHpilPN.js";
|
|
3
2
|
import { NumberTicker } from "../../motion/number-ticker.js";
|
|
3
|
+
import { t as Tooltip } from "../../../tooltip-CuHpilPN.js";
|
|
4
4
|
import { l as ink, n as useReturnsCalendar } from "../../../context-Dk6C9IvC.js";
|
|
5
5
|
import { useMemo, useState } from "react";
|
|
6
6
|
import { cn } from "@kumix/utils";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"returns-calendar.d.ts","names":["
|
|
1
|
+
{"version":3,"file":"returns-calendar.d.ts","names":["_$__returns_calendar_types0.ReturnsCalendarCell"],"sources":["../../../src/components/charts/returns-calendar/context.ts","../../../src/components/charts/returns-calendar.tsx"],"mappings":";;wBAwMgB;;;;;;;;;EA1HM,UAAA,WAAM;;;;;;;;;;;;;;;;;EAiFR,QAAA,WAAM;EACN,QAAA,WAAM;EACE,gBAAA;IAAE;;;;;;EA1GA,eAAA,MAAA;;;wBC9Cd,kBAAkB,UAAU,cAAc,SAAS,uCAAoB,IAAA;YA2B3E,sBAAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as emphasis, i as SankeyModel, n as SankeyChartProps, o as useSankeyChart, r as SankeyContext, s as useSankeyModel, t as SankeyActive } from "../../../context-tv-kneJV.js";
|
|
2
|
+
export { SankeyActive, SankeyChartProps, SankeyContext, SankeyModel, emphasis, useSankeyChart, useSankeyModel };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface SankeyChartPlotProps {
|
|
2
|
+
/** Sets the plot height; default 20rem. The layout follows its measured size. */
|
|
3
|
+
className?: string;
|
|
4
|
+
/** Show each node's value under its label when there is room. */
|
|
5
|
+
showValues?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function SankeyChartPlot({ className, showValues }: SankeyChartPlotProps): import("react").JSX.Element;
|
|
8
|
+
//# sourceMappingURL=plot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plot.d.ts","names":[],"sources":["../../../../src/components/charts/sankey-chart/plot.tsx"],"mappings":"A,iBAyCiB;;EAEf;;EAEA;;wBAWc,kBAAkB,WAAW,cAAqB,uCAAoB,IAAA"}
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { EASE_OUT, SPRING_LAYOUT } from "../../../lib/ease.js";
|
|
3
|
+
import { n as emphasis, r as useSankeyChart } from "../../../context-CQbvWVnM.js";
|
|
4
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
5
|
+
import { cn } from "@kumix/utils";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { motion, useInView } from "motion/react";
|
|
8
|
+
// src/components/charts/sankey-chart/plot.tsx
|
|
9
|
+
const COLUMN_DELAY = .12;
|
|
10
|
+
const DRAW_DURATION = .7;
|
|
11
|
+
const MIN_LABEL_HEIGHT = 12;
|
|
12
|
+
const LABEL_GAP = 8;
|
|
13
|
+
const LABEL_CHAR_WIDTH = 6.6;
|
|
14
|
+
const HIT_SLOP = 4;
|
|
15
|
+
const MIN_HIT = 24;
|
|
16
|
+
const MIN_LINK_HIT = 8;
|
|
17
|
+
/** Fits a label to `room` px, ending in an ellipsis; null when nothing fits. */
|
|
18
|
+
function fit(label, room) {
|
|
19
|
+
const chars = Math.floor(room / LABEL_CHAR_WIDTH);
|
|
20
|
+
if (chars >= label.length) return label;
|
|
21
|
+
if (chars < 4) return null;
|
|
22
|
+
return `${label.slice(0, chars - 1).trimEnd()}…`;
|
|
23
|
+
}
|
|
24
|
+
function SankeyChartPlot({ className, showValues = true }) {
|
|
25
|
+
const { nodes, links, columns, step, nodeWidth, size, setSize, resized, active, setActive, cursor, tooltipOpen, setTooltipOpen, tooltipId, gradientId, plotRef, buttons, registerButton, formatValue, label, empty, reduce, canHover } = useSankeyChart();
|
|
26
|
+
const inView = useInView(plotRef, {
|
|
27
|
+
once: true,
|
|
28
|
+
amount: .3
|
|
29
|
+
});
|
|
30
|
+
const shown = reduce || inView;
|
|
31
|
+
const [entered, setEntered] = useState(false);
|
|
32
|
+
const focusedId = useRef(null);
|
|
33
|
+
const gradient = gradientId.replace(/[^\w-]/g, "");
|
|
34
|
+
useLayoutEffect(() => {
|
|
35
|
+
const plot = plotRef.current;
|
|
36
|
+
if (!plot) return;
|
|
37
|
+
const measure = () => {
|
|
38
|
+
const { width, height } = plot.getBoundingClientRect();
|
|
39
|
+
if (width > 0 && height > 0) setSize((s) => s.width === width && s.height === height ? s : {
|
|
40
|
+
width,
|
|
41
|
+
height
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
measure();
|
|
45
|
+
const observer = new ResizeObserver(measure);
|
|
46
|
+
observer.observe(plot);
|
|
47
|
+
return () => observer.disconnect();
|
|
48
|
+
}, [plotRef, setSize]);
|
|
49
|
+
useLayoutEffect(() => {
|
|
50
|
+
const id = focusedId.current;
|
|
51
|
+
if (!id || nodes.some((node) => node.id === id)) return;
|
|
52
|
+
focusedId.current = null;
|
|
53
|
+
const lost = document.activeElement;
|
|
54
|
+
if (lost === document.body || !plotRef.current?.contains(lost)) {
|
|
55
|
+
const replacement = nodes[Math.max(cursor.activeIndex, 0)];
|
|
56
|
+
if (replacement) buttons.current.get(replacement.id)?.focus();
|
|
57
|
+
else plotRef.current?.focus();
|
|
58
|
+
}
|
|
59
|
+
}, [
|
|
60
|
+
nodes,
|
|
61
|
+
cursor.activeIndex,
|
|
62
|
+
buttons,
|
|
63
|
+
plotRef
|
|
64
|
+
]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!tooltipOpen) return;
|
|
67
|
+
const dismiss = (event) => {
|
|
68
|
+
if (plotRef.current?.contains(event.target)) return;
|
|
69
|
+
setTooltipOpen(false);
|
|
70
|
+
setActive(null);
|
|
71
|
+
};
|
|
72
|
+
document.addEventListener("pointerdown", dismiss);
|
|
73
|
+
return () => document.removeEventListener("pointerdown", dismiss);
|
|
74
|
+
}, [
|
|
75
|
+
tooltipOpen,
|
|
76
|
+
plotRef,
|
|
77
|
+
setTooltipOpen,
|
|
78
|
+
setActive
|
|
79
|
+
]);
|
|
80
|
+
const lit = emphasis(active);
|
|
81
|
+
const neighbours = /* @__PURE__ */ new Set();
|
|
82
|
+
if (active?.type === "node") for (const link of links) {
|
|
83
|
+
if (link.source === active.node) neighbours.add(link.target);
|
|
84
|
+
if (link.target === active.node) neighbours.add(link.source);
|
|
85
|
+
}
|
|
86
|
+
const nodeLit = (node) => lit.node(node) || neighbours.has(node);
|
|
87
|
+
const tabStop = nodes[Math.max(cursor.activeIndex, 0)]?.id;
|
|
88
|
+
const ref = useCallback((id) => (element) => registerButton(id, element), [registerButton]);
|
|
89
|
+
const onKeyDown = (event) => {
|
|
90
|
+
const target = event.target;
|
|
91
|
+
if (!(target instanceof HTMLButtonElement)) return;
|
|
92
|
+
const current = nodes.find((node) => node.id === target.dataset.sankeyNode);
|
|
93
|
+
if (!current) return;
|
|
94
|
+
if (event.key === "Escape") {
|
|
95
|
+
if (!tooltipOpen) return;
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
setTooltipOpen(false);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const center = (node) => (node.y0 + node.y1) / 2;
|
|
101
|
+
const column = (depth) => nodes.filter((node) => node.depth === depth);
|
|
102
|
+
let next;
|
|
103
|
+
if (event.key === "Home") next = nodes[0];
|
|
104
|
+
else if (event.key === "End") next = nodes[nodes.length - 1];
|
|
105
|
+
else if (event.key === "ArrowUp" || event.key === "ArrowDown") {
|
|
106
|
+
const same = column(current.depth);
|
|
107
|
+
next = same[same.indexOf(current) + (event.key === "ArrowUp" ? -1 : 1)];
|
|
108
|
+
} else if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
|
109
|
+
const dir = event.key === "ArrowLeft" ? -1 : 1;
|
|
110
|
+
for (let d = current.depth + dir; d >= 0 && d < columns && !next; d += dir) next = column(d).reduce((best, node) => !best || Math.abs(center(node) - center(current)) < Math.abs(center(best) - center(current)) ? node : best, void 0);
|
|
111
|
+
} else return;
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
setTooltipOpen(true);
|
|
114
|
+
if (next && next !== current) buttons.current.get(next.id)?.focus();
|
|
115
|
+
else setActive(current.id);
|
|
116
|
+
};
|
|
117
|
+
const point = (event, id) => {
|
|
118
|
+
if (event.pointerType === "touch" ? event.buttons !== 1 : !canHover) return;
|
|
119
|
+
setActive(id);
|
|
120
|
+
setTooltipOpen(true);
|
|
121
|
+
};
|
|
122
|
+
const press = (id) => {
|
|
123
|
+
setActive(id);
|
|
124
|
+
setTooltipOpen(true);
|
|
125
|
+
};
|
|
126
|
+
const geometry = reduce || resized ? { duration: 0 } : SPRING_LAYOUT;
|
|
127
|
+
const linkOpacity = (lightUp) => active ? lightUp ? .6 : .08 : .32;
|
|
128
|
+
const labelRoom = columns > 1 ? step - nodeWidth - 16 : size.width;
|
|
129
|
+
const hitOrder = [...links].sort((a, b) => b.width - a.width);
|
|
130
|
+
return /* @__PURE__ */ jsx("div", {
|
|
131
|
+
className: "-m-2 overflow-x-auto overflow-y-hidden p-2",
|
|
132
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
133
|
+
ref: plotRef,
|
|
134
|
+
role: "group",
|
|
135
|
+
"aria-label": `${label} nodes`,
|
|
136
|
+
tabIndex: -1,
|
|
137
|
+
"data-slot": "sankey-chart-plot",
|
|
138
|
+
className: cn("relative h-80 w-full min-w-[32rem] outline-none", className),
|
|
139
|
+
onKeyDown,
|
|
140
|
+
onFocus: (event) => {
|
|
141
|
+
if (event.target instanceof HTMLButtonElement) focusedId.current = event.target.dataset.sankeyNode ?? null;
|
|
142
|
+
},
|
|
143
|
+
onBlur: (event) => {
|
|
144
|
+
if (event.currentTarget.contains(event.relatedTarget)) return;
|
|
145
|
+
focusedId.current = null;
|
|
146
|
+
setTooltipOpen(false);
|
|
147
|
+
setActive(null);
|
|
148
|
+
},
|
|
149
|
+
onPointerLeave: (event) => {
|
|
150
|
+
if (event.pointerType === "touch") return;
|
|
151
|
+
setTooltipOpen(false);
|
|
152
|
+
setActive(null);
|
|
153
|
+
},
|
|
154
|
+
children: [
|
|
155
|
+
/* @__PURE__ */ jsxs("svg", {
|
|
156
|
+
width: size.width,
|
|
157
|
+
height: size.height,
|
|
158
|
+
viewBox: `0 0 ${size.width} ${size.height}`,
|
|
159
|
+
"aria-hidden": "true",
|
|
160
|
+
className: "absolute inset-0 overflow-visible",
|
|
161
|
+
children: [
|
|
162
|
+
/* @__PURE__ */ jsx("defs", { children: links.map((link, i) => /* @__PURE__ */ jsxs("linearGradient", {
|
|
163
|
+
id: `${gradient}-${i}`,
|
|
164
|
+
gradientUnits: "userSpaceOnUse",
|
|
165
|
+
x1: link.x0,
|
|
166
|
+
x2: link.x1,
|
|
167
|
+
children: [/* @__PURE__ */ jsx("stop", {
|
|
168
|
+
offset: "0%",
|
|
169
|
+
stopColor: link.source.color
|
|
170
|
+
}), /* @__PURE__ */ jsx("stop", {
|
|
171
|
+
offset: "100%",
|
|
172
|
+
stopColor: link.target.color
|
|
173
|
+
})]
|
|
174
|
+
}, link.id)) }),
|
|
175
|
+
/* @__PURE__ */ jsx("g", {
|
|
176
|
+
fill: "none",
|
|
177
|
+
pointerEvents: "none",
|
|
178
|
+
children: links.map((link, i) => /* @__PURE__ */ jsx(motion.path, {
|
|
179
|
+
stroke: `url(#${gradient}-${i})`,
|
|
180
|
+
strokeWidth: Math.max(1, link.width),
|
|
181
|
+
initial: reduce ? false : {
|
|
182
|
+
d: link.path,
|
|
183
|
+
pathLength: 0,
|
|
184
|
+
opacity: .32
|
|
185
|
+
},
|
|
186
|
+
animate: shown ? {
|
|
187
|
+
d: link.path,
|
|
188
|
+
pathLength: 1,
|
|
189
|
+
opacity: linkOpacity(lit.link(link))
|
|
190
|
+
} : void 0,
|
|
191
|
+
transition: reduce ? { duration: 0 } : {
|
|
192
|
+
d: geometry,
|
|
193
|
+
pathLength: {
|
|
194
|
+
duration: DRAW_DURATION,
|
|
195
|
+
ease: EASE_OUT,
|
|
196
|
+
delay: entered ? 0 : link.source.depth * COLUMN_DELAY
|
|
197
|
+
},
|
|
198
|
+
opacity: {
|
|
199
|
+
duration: .16,
|
|
200
|
+
ease: EASE_OUT
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
onAnimationComplete: () => setEntered(true)
|
|
204
|
+
}, link.id))
|
|
205
|
+
}),
|
|
206
|
+
/* @__PURE__ */ jsx("g", {
|
|
207
|
+
fill: "none",
|
|
208
|
+
stroke: "transparent",
|
|
209
|
+
children: hitOrder.map((link) => /* @__PURE__ */ jsx("path", {
|
|
210
|
+
d: link.path,
|
|
211
|
+
strokeWidth: Math.max(MIN_LINK_HIT, link.width),
|
|
212
|
+
pointerEvents: shown ? "stroke" : "none",
|
|
213
|
+
className: "cursor-pointer",
|
|
214
|
+
onPointerEnter: (event) => point(event, link.id),
|
|
215
|
+
onPointerMove: (event) => point(event, link.id),
|
|
216
|
+
onPointerDown: () => press(link.id)
|
|
217
|
+
}, link.id))
|
|
218
|
+
}),
|
|
219
|
+
/* @__PURE__ */ jsx("g", {
|
|
220
|
+
pointerEvents: "none",
|
|
221
|
+
children: nodes.map((node) => /* @__PURE__ */ jsx(motion.rect, {
|
|
222
|
+
x: node.x0,
|
|
223
|
+
width: node.x1 - node.x0,
|
|
224
|
+
rx: 2,
|
|
225
|
+
fill: node.color,
|
|
226
|
+
initial: reduce ? false : {
|
|
227
|
+
y: node.y0,
|
|
228
|
+
height: node.y1 - node.y0,
|
|
229
|
+
opacity: 0
|
|
230
|
+
},
|
|
231
|
+
animate: shown ? {
|
|
232
|
+
y: node.y0,
|
|
233
|
+
height: Math.max(1, node.y1 - node.y0),
|
|
234
|
+
opacity: nodeLit(node) ? 1 : .3
|
|
235
|
+
} : void 0,
|
|
236
|
+
transition: reduce ? { duration: 0 } : {
|
|
237
|
+
y: geometry,
|
|
238
|
+
height: geometry,
|
|
239
|
+
opacity: {
|
|
240
|
+
duration: entered ? .16 : .3,
|
|
241
|
+
ease: EASE_OUT,
|
|
242
|
+
delay: entered ? 0 : .1 + node.depth * COLUMN_DELAY
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}, node.id))
|
|
246
|
+
}),
|
|
247
|
+
/* @__PURE__ */ jsx("g", {
|
|
248
|
+
className: "text-xs",
|
|
249
|
+
pointerEvents: "none",
|
|
250
|
+
children: nodes.map((node) => {
|
|
251
|
+
const h = node.y1 - node.y0;
|
|
252
|
+
if (h < MIN_LABEL_HEIGHT) return null;
|
|
253
|
+
const text = fit(node.label, labelRoom);
|
|
254
|
+
if (!text) return null;
|
|
255
|
+
const last = columns > 1 && node.depth === columns - 1;
|
|
256
|
+
const x = last ? node.x0 - LABEL_GAP : node.x1 + LABEL_GAP;
|
|
257
|
+
const value = formatValue(node.value);
|
|
258
|
+
const twoLines = showValues && h >= MIN_LABEL_HEIGHT * 2.4 && value.length * LABEL_CHAR_WIDTH <= labelRoom;
|
|
259
|
+
return /* @__PURE__ */ jsxs(motion.text, {
|
|
260
|
+
x,
|
|
261
|
+
textAnchor: last ? "end" : "start",
|
|
262
|
+
dominantBaseline: "middle",
|
|
263
|
+
className: "fill-foreground stroke-background [paint-order:stroke]",
|
|
264
|
+
strokeWidth: 3,
|
|
265
|
+
strokeLinejoin: "round",
|
|
266
|
+
initial: reduce ? false : {
|
|
267
|
+
y: (node.y0 + node.y1) / 2,
|
|
268
|
+
opacity: 0
|
|
269
|
+
},
|
|
270
|
+
animate: shown ? {
|
|
271
|
+
y: (node.y0 + node.y1) / 2,
|
|
272
|
+
opacity: nodeLit(node) ? 1 : .35
|
|
273
|
+
} : void 0,
|
|
274
|
+
transition: reduce ? { duration: 0 } : {
|
|
275
|
+
y: geometry,
|
|
276
|
+
opacity: {
|
|
277
|
+
duration: .2,
|
|
278
|
+
ease: EASE_OUT,
|
|
279
|
+
delay: entered ? 0 : .2 + node.depth * COLUMN_DELAY
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
children: [/* @__PURE__ */ jsx("tspan", {
|
|
283
|
+
x,
|
|
284
|
+
dy: twoLines ? "-0.6em" : 0,
|
|
285
|
+
className: "font-medium",
|
|
286
|
+
children: text
|
|
287
|
+
}), twoLines ? /* @__PURE__ */ jsx("tspan", {
|
|
288
|
+
x,
|
|
289
|
+
dy: "1.2em",
|
|
290
|
+
className: "fill-muted-foreground tabular-nums",
|
|
291
|
+
children: value
|
|
292
|
+
}) : null]
|
|
293
|
+
}, node.id);
|
|
294
|
+
})
|
|
295
|
+
})
|
|
296
|
+
]
|
|
297
|
+
}),
|
|
298
|
+
nodes.map((node) => {
|
|
299
|
+
const selected = tooltipOpen && active?.type === "node" && active.node === node;
|
|
300
|
+
const h = Math.max(1, node.y1 - node.y0);
|
|
301
|
+
const hit = Math.max(MIN_HIT, h + 8);
|
|
302
|
+
return /* @__PURE__ */ jsx("button", {
|
|
303
|
+
ref: ref(node.id),
|
|
304
|
+
type: "button",
|
|
305
|
+
"data-sankey-node": node.id,
|
|
306
|
+
tabIndex: node.id === tabStop ? 0 : -1,
|
|
307
|
+
"aria-label": [
|
|
308
|
+
node.label,
|
|
309
|
+
formatValue(node.value),
|
|
310
|
+
node.inValue && node.outValue ? `in ${formatValue(node.inValue)}, out ${formatValue(node.outValue)}` : null,
|
|
311
|
+
node.description
|
|
312
|
+
].filter(Boolean).join(". "),
|
|
313
|
+
"aria-describedby": selected ? tooltipId : void 0,
|
|
314
|
+
className: "focus-visible:ring-ring focus-visible:ring-offset-background absolute rounded-sm outline-none focus-visible:ring-2 focus-visible:ring-offset-2",
|
|
315
|
+
style: {
|
|
316
|
+
left: node.x0 - HIT_SLOP,
|
|
317
|
+
top: node.y0 + h / 2 - hit / 2,
|
|
318
|
+
width: node.x1 - node.x0 + 8,
|
|
319
|
+
height: hit,
|
|
320
|
+
pointerEvents: shown ? "auto" : "none"
|
|
321
|
+
},
|
|
322
|
+
onPointerEnter: (event) => point(event, node.id),
|
|
323
|
+
onPointerMove: (event) => point(event, node.id),
|
|
324
|
+
onPointerDown: () => press(node.id),
|
|
325
|
+
onFocus: () => {
|
|
326
|
+
cursor.moveTo(node.id);
|
|
327
|
+
setActive(node.id);
|
|
328
|
+
setTooltipOpen(true);
|
|
329
|
+
}
|
|
330
|
+
}, node.id);
|
|
331
|
+
}),
|
|
332
|
+
empty ? /* @__PURE__ */ jsx("p", {
|
|
333
|
+
className: "text-muted-foreground flex h-full items-center justify-center text-sm",
|
|
334
|
+
children: empty
|
|
335
|
+
}) : null
|
|
336
|
+
]
|
|
337
|
+
})
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
export { SankeyChartPlot };
|
|
341
|
+
|
|
342
|
+
//# sourceMappingURL=plot.js.map
|