@aiconstructions/graficos 0.0.0-stage → 0.2.2
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/ALTERACOES.md +57 -0
- package/LICENSE-BKLIT +21 -0
- package/LICENSE-visx-pattern +21 -0
- package/README.md +189 -2
- package/dist/aic/cores.js +83 -0
- package/dist/aic/index.js +22 -0
- package/dist/aic/interacao.js +55 -0
- package/dist/charts/animation.js +55 -0
- package/dist/charts/arc-geometry.js +58 -0
- package/dist/charts/arc-path.js +15 -0
- package/dist/charts/area-chart-loading.js +89 -0
- package/dist/charts/area-chart.js +149 -0
- package/dist/charts/area-gradient-defs.js +90 -0
- package/dist/charts/area-value-label-layout.js +70 -0
- package/dist/charts/area-value-labels.js +211 -0
- package/dist/charts/area.js +272 -0
- package/dist/charts/background.js +198 -0
- package/dist/charts/band-config.js +82 -0
- package/dist/charts/band-geometry.js +186 -0
- package/dist/charts/band.js +346 -0
- package/dist/charts/bar-chart-loading.js +27 -0
- package/dist/charts/bar-chart.js +545 -0
- package/dist/charts/bar-depth-geometry.js +18 -0
- package/dist/charts/bar-depth.js +608 -0
- package/dist/charts/bar-lollipop.js +278 -0
- package/dist/charts/bar-squares-layout.js +66 -0
- package/dist/charts/bar-squares.js +467 -0
- package/dist/charts/bar-value-label-layout.js +42 -0
- package/dist/charts/bar-x-axis.js +133 -0
- package/dist/charts/bar-y-axis.js +116 -0
- package/dist/charts/bar.js +457 -0
- package/dist/charts/bollinger.js +49 -0
- package/dist/charts/candlestick-chart.js +370 -0
- package/dist/charts/candlestick.js +368 -0
- package/dist/charts/chart-brush-handle.js +91 -0
- package/dist/charts/chart-brush-layout.js +91 -0
- package/dist/charts/chart-brush-selection-overlay.js +87 -0
- package/dist/charts/chart-brush-state.js +253 -0
- package/dist/charts/chart-brush-track-overlay.js +103 -0
- package/dist/charts/chart-brush.js +517 -0
- package/dist/charts/chart-center-typography.js +8 -0
- package/dist/charts/chart-child-passthrough.js +119 -0
- package/dist/charts/chart-config-context.js +56 -0
- package/dist/charts/chart-context.js +337 -0
- package/dist/charts/chart-crosshair.js +262 -0
- package/dist/charts/chart-data-override.js +186 -0
- package/dist/charts/chart-defs.js +56 -0
- package/dist/charts/chart-formatters.js +77 -0
- package/dist/charts/chart-legend-hover.js +27 -0
- package/dist/charts/chart-legend.js +163 -0
- package/dist/charts/chart-loading-label.js +52 -0
- package/dist/charts/chart-parent-size.js +138 -0
- package/dist/charts/chart-phase.js +29 -0
- package/dist/charts/chart-reveal-clip.js +62 -0
- package/dist/charts/chart-scale.js +19 -0
- package/dist/charts/chart-stat-flow.js +72 -0
- package/dist/charts/choropleth/choropleth-background.js +29 -0
- package/dist/charts/choropleth/choropleth-camera.js +379 -0
- package/dist/charts/choropleth/choropleth-chart.js +644 -0
- package/dist/charts/choropleth/choropleth-context.js +152 -0
- package/dist/charts/choropleth/choropleth-dot-grid.js +293 -0
- package/dist/charts/choropleth/choropleth-feature.js +291 -0
- package/dist/charts/choropleth/choropleth-graticule.js +40 -0
- package/dist/charts/choropleth/choropleth-marker.js +222 -0
- package/dist/charts/choropleth/choropleth-projection.js +37 -0
- package/dist/charts/choropleth/choropleth-tooltip.js +82 -0
- package/dist/charts/choropleth/choropleth-zoom-matrix.js +150 -0
- package/dist/charts/choropleth/index.js +44 -0
- package/dist/charts/choropleth/use-choropleth-zoom-state.js +636 -0
- package/dist/charts/composed-chart.js +346 -0
- package/dist/charts/crosshair-store.js +49 -0
- package/dist/charts/dash-tail-stroke.js +58 -0
- package/dist/charts/date-pill-store.js +50 -0
- package/dist/charts/date-ranges.js +131 -0
- package/dist/charts/deadline.js +295 -0
- package/dist/charts/decimate-time-series.js +112 -0
- package/dist/charts/fade-edges.js +171 -0
- package/dist/charts/fast-path.js +78 -0
- package/dist/charts/filter-data-by-x-domain.js +45 -0
- package/dist/charts/funnel-chart.js +773 -0
- package/dist/charts/gauge-arc-layers.js +479 -0
- package/dist/charts/gauge-dial.js +329 -0
- package/dist/charts/gauge-label-layout.js +148 -0
- package/dist/charts/gauge.js +946 -0
- package/dist/charts/generate-chart-skeleton-data.js +27 -0
- package/dist/charts/gradients.js +158 -0
- package/dist/charts/grid-lines.js +114 -0
- package/dist/charts/grid.js +225 -0
- package/dist/charts/heatmap/generate-heatmap-skeleton-data.js +13 -0
- package/dist/charts/heatmap/heatmap-animation.js +128 -0
- package/dist/charts/heatmap/heatmap-cells.js +519 -0
- package/dist/charts/heatmap/heatmap-chart-loading.js +44 -0
- package/dist/charts/heatmap/heatmap-chart.js +548 -0
- package/dist/charts/heatmap/heatmap-colors.js +127 -0
- package/dist/charts/heatmap/heatmap-context.js +107 -0
- package/dist/charts/heatmap/heatmap-legend-gradient.js +97 -0
- package/dist/charts/heatmap/heatmap-legend-swatch.js +76 -0
- package/dist/charts/heatmap/heatmap-legend.js +165 -0
- package/dist/charts/heatmap/heatmap-pattern-defs.js +37 -0
- package/dist/charts/heatmap/heatmap-rect-cells.js +39 -0
- package/dist/charts/heatmap/heatmap-resolve-separator.js +84 -0
- package/dist/charts/heatmap/heatmap-separator.js +168 -0
- package/dist/charts/heatmap/heatmap-tooltip.js +73 -0
- package/dist/charts/heatmap/heatmap-utils.js +633 -0
- package/dist/charts/heatmap/heatmap-x-axis.js +79 -0
- package/dist/charts/heatmap/heatmap-y-axis.js +72 -0
- package/dist/charts/heatmap/index.js +208 -0
- package/dist/charts/highlight-segment-bounds.js +34 -0
- package/dist/charts/highlight-segment.js +119 -0
- package/dist/charts/index.js +944 -0
- package/dist/charts/indicator-fade.js +44 -0
- package/dist/charts/legend/index.js +22 -0
- package/dist/charts/legend/legend-context.js +47 -0
- package/dist/charts/legend/legend-item.js +30 -0
- package/dist/charts/legend/legend-label.js +14 -0
- package/dist/charts/legend/legend-marker.js +18 -0
- package/dist/charts/legend/legend-progress.js +39 -0
- package/dist/charts/legend/legend-value.js +31 -0
- package/dist/charts/legend/legend.js +69 -0
- package/dist/charts/line-backdrop.js +129 -0
- package/dist/charts/line-chart-loading.js +85 -0
- package/dist/charts/line-chart.js +182 -0
- package/dist/charts/line-loading-pulse.js +185 -0
- package/dist/charts/line-loading-timing.js +12 -0
- package/dist/charts/line-path.js +58 -0
- package/dist/charts/line-series-terminal-marker.js +75 -0
- package/dist/charts/line.js +499 -0
- package/dist/charts/live-line-chart.js +494 -0
- package/dist/charts/live-line.js +277 -0
- package/dist/charts/live-x-axis.js +116 -0
- package/dist/charts/live-y-axis.js +164 -0
- package/dist/charts/loading-sweep.js +344 -0
- package/dist/charts/local-point.js +56 -0
- package/dist/charts/markers/chart-markers.js +149 -0
- package/dist/charts/markers/index.js +14 -0
- package/dist/charts/markers/marker-group.js +411 -0
- package/dist/charts/motion-utils.js +29 -0
- package/dist/charts/notch-gauge-shared.js +146 -0
- package/dist/charts/particle-line.js +1340 -0
- package/dist/charts/path-stroke-utils.js +51 -0
- package/dist/charts/pattern-area.js +127 -0
- package/dist/charts/pattern-preset.js +287 -0
- package/dist/charts/pattern-tile.js +31 -0
- package/dist/charts/patterns/circles.js +62 -0
- package/dist/charts/patterns/constants.js +9 -0
- package/dist/charts/patterns/hexagons.js +38 -0
- package/dist/charts/patterns/index.js +16 -0
- package/dist/charts/patterns/lines.js +65 -0
- package/dist/charts/patterns/path.js +37 -0
- package/dist/charts/patterns/pattern.js +16 -0
- package/dist/charts/patterns/waves.js +40 -0
- package/dist/charts/pie-center-shell.js +127 -0
- package/dist/charts/pie-center.js +87 -0
- package/dist/charts/pie-chart.js +377 -0
- package/dist/charts/pie-context.js +116 -0
- package/dist/charts/pie-slice.js +394 -0
- package/dist/charts/pie-ticks.js +332 -0
- package/dist/charts/profit-loss-legend-hover.js +18 -0
- package/dist/charts/profit-loss-legend.js +53 -0
- package/dist/charts/profit-loss-line.js +162 -0
- package/dist/charts/profit-loss-segments.js +88 -0
- package/dist/charts/projection-config.js +90 -0
- package/dist/charts/projection-line-end-marker.js +50 -0
- package/dist/charts/projection-line.js +466 -0
- package/dist/charts/projection-utils.js +303 -0
- package/dist/charts/radar-area.js +192 -0
- package/dist/charts/radar-axis.js +41 -0
- package/dist/charts/radar-chart.js +184 -0
- package/dist/charts/radar-context.js +104 -0
- package/dist/charts/radar-grid.js +121 -0
- package/dist/charts/radar-labels.js +62 -0
- package/dist/charts/radial-area.js +498 -0
- package/dist/charts/radial-axis.js +652 -0
- package/dist/charts/radial-bar.js +316 -0
- package/dist/charts/radial-center.js +67 -0
- package/dist/charts/radial-chart.js +740 -0
- package/dist/charts/radial-dot-bar-layout.js +68 -0
- package/dist/charts/radial-dot-bar.js +387 -0
- package/dist/charts/radial-geometry.js +114 -0
- package/dist/charts/radial-legend.js +66 -0
- package/dist/charts/radial-line.js +280 -0
- package/dist/charts/radial-ring-bar.js +255 -0
- package/dist/charts/radial-scrubber.js +120 -0
- package/dist/charts/radial-series-color.js +10 -0
- package/dist/charts/reference-area-config.js +43 -0
- package/dist/charts/reference-area-geometry.js +76 -0
- package/dist/charts/reference-area-registration-context.js +10 -0
- package/dist/charts/reference-area.js +241 -0
- package/dist/charts/responsive-chart-label-count.js +18 -0
- package/dist/charts/ring-center.js +78 -0
- package/dist/charts/ring-chart.js +362 -0
- package/dist/charts/ring-context.js +122 -0
- package/dist/charts/ring-grid.js +175 -0
- package/dist/charts/ring-labels.js +109 -0
- package/dist/charts/ring.js +237 -0
- package/dist/charts/sankey/index.js +22 -0
- package/dist/charts/sankey/sankey-chart.js +199 -0
- package/dist/charts/sankey/sankey-context.js +32 -0
- package/dist/charts/sankey/sankey-link.js +232 -0
- package/dist/charts/sankey/sankey-node.js +348 -0
- package/dist/charts/sankey/sankey-tooltip.js +94 -0
- package/dist/charts/scatter-chart-shell.js +279 -0
- package/dist/charts/scatter-chart.js +150 -0
- package/dist/charts/scatter-jitter.js +86 -0
- package/dist/charts/scatter-svg.js +17 -0
- package/dist/charts/scatter.js +92 -0
- package/dist/charts/segment.js +107 -0
- package/dist/charts/series-bar-layout.js +42 -0
- package/dist/charts/series-bar.js +241 -0
- package/dist/charts/series-dash-tail-overlay.js +53 -0
- package/dist/charts/series-highlight-layer.js +43 -0
- package/dist/charts/series-hover-dim.js +32 -0
- package/dist/charts/series-markers.js +239 -0
- package/dist/charts/series-path-utils.js +185 -0
- package/dist/charts/series-point-marker.js +150 -0
- package/dist/charts/sparkline-geometry.js +197 -0
- package/dist/charts/sparkline.js +910 -0
- package/dist/charts/static-chart-preview-context.js +16 -0
- package/dist/charts/sunburst-breadcrumb.js +33 -0
- package/dist/charts/sunburst-center.js +37 -0
- package/dist/charts/sunburst-chart.js +408 -0
- package/dist/charts/sunburst-context.js +140 -0
- package/dist/charts/sunburst-data.js +0 -0
- package/dist/charts/sunburst-hint.js +42 -0
- package/dist/charts/sunburst-labels.js +130 -0
- package/dist/charts/sunburst-segment.js +144 -0
- package/dist/charts/sunburst.js +419 -0
- package/dist/charts/time-series-chart-shell.js +688 -0
- package/dist/charts/tooltip/chart-tooltip.js +516 -0
- package/dist/charts/tooltip/cursor-tooltip-box.js +183 -0
- package/dist/charts/tooltip/date-ticker.js +376 -0
- package/dist/charts/tooltip/index.js +32 -0
- package/dist/charts/tooltip/liquid-glass.js +142 -0
- package/dist/charts/tooltip/tooltip-box.js +502 -0
- package/dist/charts/tooltip/tooltip-content.js +59 -0
- package/dist/charts/tooltip/tooltip-dot.js +170 -0
- package/dist/charts/tooltip/tooltip-indicator.js +175 -0
- package/dist/charts/tooltip/use-delayed-tooltip-data.js +41 -0
- package/dist/charts/tooltip/use-velocity-stretch.js +52 -0
- package/dist/charts/trend-line-utils.js +64 -0
- package/dist/charts/trend-line.js +318 -0
- package/dist/charts/use-animated-band.js +175 -0
- package/dist/charts/use-animated-series-path.js +208 -0
- package/dist/charts/use-animated-y-domains.js +192 -0
- package/dist/charts/use-category-slots.js +29 -0
- package/dist/charts/use-chart-interaction.js +296 -0
- package/dist/charts/use-chart-phase-orchestrator.js +183 -0
- package/dist/charts/use-enter-complete.js +18 -0
- package/dist/charts/use-grid-shimmer.js +88 -0
- package/dist/charts/use-highlight-segment.js +65 -0
- package/dist/charts/use-mount-progress.js +23 -0
- package/dist/charts/use-scatter-chart-interaction.js +364 -0
- package/dist/charts/use-scheduled-tooltip.js +84 -0
- package/dist/charts/visx-pattern.js +30 -0
- package/dist/charts/weekends.js +174 -0
- package/dist/charts/x-axis-hover.js +46 -0
- package/dist/charts/x-axis.js +523 -0
- package/dist/charts/y-axis-scales.js +71 -0
- package/dist/charts/y-axis-ticks.js +22 -0
- package/dist/charts/y-axis.js +233 -0
- package/dist/charts/y-domain-utils.js +189 -0
- package/dist/index.d.ts +7346 -0
- package/dist/index.js +2 -0
- package/dist/lib/utils.js +8 -0
- package/dist/shimmering-text.js +54 -0
- package/package.json +78 -4
- package/tema.css +202 -0
|
@@ -0,0 +1,910 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
AnimatePresence,
|
|
5
|
+
animate as animateValue,
|
|
6
|
+
domAnimation,
|
|
7
|
+
LazyMotion,
|
|
8
|
+
m,
|
|
9
|
+
useReducedMotion,
|
|
10
|
+
useSpring
|
|
11
|
+
} from "motion/react";
|
|
12
|
+
import {
|
|
13
|
+
memo,
|
|
14
|
+
useCallback,
|
|
15
|
+
useEffect,
|
|
16
|
+
useId,
|
|
17
|
+
useLayoutEffect,
|
|
18
|
+
useMemo,
|
|
19
|
+
useRef,
|
|
20
|
+
useState
|
|
21
|
+
} from "react";
|
|
22
|
+
import { cn } from "../lib/utils";
|
|
23
|
+
import { DEFAULT_ANIMATION_EASING } from "./animation";
|
|
24
|
+
import { chartCssVars } from "./chart-context";
|
|
25
|
+
import { useChartDataOverride } from "./chart-data-override";
|
|
26
|
+
import {
|
|
27
|
+
buildSparklineAreaPath,
|
|
28
|
+
buildSparklineBarSegment,
|
|
29
|
+
buildSparklineBarsPath,
|
|
30
|
+
buildSparklineLinePath,
|
|
31
|
+
computeSparklineDomain,
|
|
32
|
+
computeSparklineLayout,
|
|
33
|
+
describeSparkline,
|
|
34
|
+
interpolateSparklineLayout,
|
|
35
|
+
resolveSparklinePadding,
|
|
36
|
+
resolveSparklineValues,
|
|
37
|
+
sparklineBarWidth,
|
|
38
|
+
sparklineIndexAtX
|
|
39
|
+
} from "./sparkline-geometry";
|
|
40
|
+
const DEFAULT_SPARKLINE_ANIMATION_DURATION_MS = 900;
|
|
41
|
+
const DEFAULT_SPARKLINE_DATA_TRANSITION_MS = 500;
|
|
42
|
+
const DATA_TRANSITION_EASE = [0.85, 0, 0.15, 1];
|
|
43
|
+
const HOVER_FADE = "opacity 400ms ease-in-out";
|
|
44
|
+
const HIGHLIGHT_SPRING = { stiffness: 180, damping: 28 };
|
|
45
|
+
const DEFAULT_SPARKLINE_HEIGHT = 32;
|
|
46
|
+
const REDUCED_MOTION_FADE_MS = 200;
|
|
47
|
+
const DEFAULT_SPARKLINE_HOVER_SPRING = {
|
|
48
|
+
stiffness: 300,
|
|
49
|
+
damping: 30
|
|
50
|
+
};
|
|
51
|
+
let sharedObserver = null;
|
|
52
|
+
const sizeListeners = /* @__PURE__ */ new WeakMap();
|
|
53
|
+
function observeWidth(element, listener) {
|
|
54
|
+
if (typeof ResizeObserver === "undefined") {
|
|
55
|
+
listener(element.getBoundingClientRect().width);
|
|
56
|
+
return () => void 0;
|
|
57
|
+
}
|
|
58
|
+
sharedObserver ??= new ResizeObserver((entries) => {
|
|
59
|
+
for (const entry of entries) {
|
|
60
|
+
sizeListeners.get(entry.target)?.(entry.contentRect.width);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
sizeListeners.set(element, listener);
|
|
64
|
+
sharedObserver.observe(element);
|
|
65
|
+
return () => {
|
|
66
|
+
sizeListeners.delete(element);
|
|
67
|
+
sharedObserver?.unobserve(element);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function useSparklineWidth(ref, fixedWidth) {
|
|
71
|
+
const [measured, setMeasured] = useState(0);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
const element = ref.current;
|
|
74
|
+
if (fixedWidth !== void 0 || !element) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
return observeWidth(
|
|
78
|
+
element,
|
|
79
|
+
(width) => setMeasured(Math.round(width * 2) / 2)
|
|
80
|
+
);
|
|
81
|
+
}, [ref, fixedWidth]);
|
|
82
|
+
return fixedWidth ?? measured;
|
|
83
|
+
}
|
|
84
|
+
function prefersReducedMotion() {
|
|
85
|
+
return typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
|
|
86
|
+
}
|
|
87
|
+
function useEnterAnimation(ref, ready, options) {
|
|
88
|
+
const played = useRef(false);
|
|
89
|
+
const { animate, duration, easing, keyframes } = options;
|
|
90
|
+
useLayoutEffect(() => {
|
|
91
|
+
const element = ref.current;
|
|
92
|
+
if (!(ready && element) || played.current) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
played.current = true;
|
|
96
|
+
if (!animate || duration <= 0 || typeof element.animate !== "function") {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (prefersReducedMotion()) {
|
|
100
|
+
element.animate([{ opacity: 0 }, { opacity: 1 }], {
|
|
101
|
+
duration: REDUCED_MOTION_FADE_MS,
|
|
102
|
+
easing: "ease-out"
|
|
103
|
+
});
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
element.animate(keyframes, { duration, easing });
|
|
107
|
+
}, [ref, ready, animate, duration, easing, keyframes]);
|
|
108
|
+
}
|
|
109
|
+
function sameShape(a, b) {
|
|
110
|
+
if (a === b) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
if (a.points.length !== b.points.length || a.baselineY !== b.baselineY) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
return a.points.every((point, i) => {
|
|
117
|
+
const other = b.points[i];
|
|
118
|
+
return other !== void 0 && Object.is(point.y, other.y) && point.x === other.x;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function useDataTransition(layout, width, duration, draw) {
|
|
122
|
+
const displayed = useRef(null);
|
|
123
|
+
const prevWidth = useRef(width);
|
|
124
|
+
const running = useRef(false);
|
|
125
|
+
const drawRef = useRef(draw);
|
|
126
|
+
useLayoutEffect(() => {
|
|
127
|
+
drawRef.current = draw;
|
|
128
|
+
});
|
|
129
|
+
useLayoutEffect(() => {
|
|
130
|
+
const from = displayed.current;
|
|
131
|
+
const resized = prevWidth.current !== width;
|
|
132
|
+
prevWidth.current = width;
|
|
133
|
+
displayed.current = layout;
|
|
134
|
+
if (!from || sameShape(from, layout) || resized || duration <= 0 || prefersReducedMotion()) {
|
|
135
|
+
if (running.current) {
|
|
136
|
+
running.current = false;
|
|
137
|
+
drawRef.current(layout);
|
|
138
|
+
}
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const frame = (t) => {
|
|
142
|
+
displayed.current = interpolateSparklineLayout(from, layout, t);
|
|
143
|
+
drawRef.current(displayed.current);
|
|
144
|
+
};
|
|
145
|
+
running.current = true;
|
|
146
|
+
frame(0);
|
|
147
|
+
const control = animateValue(0, 1, {
|
|
148
|
+
duration: duration / 1e3,
|
|
149
|
+
ease: [...DATA_TRANSITION_EASE],
|
|
150
|
+
onUpdate: frame,
|
|
151
|
+
onComplete: () => {
|
|
152
|
+
running.current = false;
|
|
153
|
+
displayed.current = layout;
|
|
154
|
+
drawRef.current(layout);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
return () => control.stop();
|
|
158
|
+
}, [layout, width, duration]);
|
|
159
|
+
}
|
|
160
|
+
const wipeKeyframes = [
|
|
161
|
+
{ clipPath: "inset(0 100% 0 0)" },
|
|
162
|
+
{ clipPath: "inset(0 0% 0 0)" }
|
|
163
|
+
];
|
|
164
|
+
const drawKeyframes = [
|
|
165
|
+
{ strokeDashoffset: 1 },
|
|
166
|
+
{ strokeDashoffset: 0 }
|
|
167
|
+
];
|
|
168
|
+
function useHoverState(data, hoverIndexProp, onHoverChange) {
|
|
169
|
+
const [internal, setInternal] = useState(null);
|
|
170
|
+
const controlled = hoverIndexProp !== void 0;
|
|
171
|
+
const hoverIndex = controlled ? hoverIndexProp : internal;
|
|
172
|
+
const current = useRef(hoverIndex);
|
|
173
|
+
current.current = hoverIndex;
|
|
174
|
+
const setHoverIndex = useCallback(
|
|
175
|
+
(index) => {
|
|
176
|
+
if (index === current.current) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
current.current = index;
|
|
180
|
+
if (!controlled) {
|
|
181
|
+
setInternal(index);
|
|
182
|
+
}
|
|
183
|
+
onHoverChange?.(index, index === null ? null : data[index] ?? null);
|
|
184
|
+
},
|
|
185
|
+
[controlled, data, onHoverChange]
|
|
186
|
+
);
|
|
187
|
+
return [hoverIndex, setHoverIndex];
|
|
188
|
+
}
|
|
189
|
+
function SparklineFrame({
|
|
190
|
+
config,
|
|
191
|
+
kind,
|
|
192
|
+
includeZero,
|
|
193
|
+
defaultPadding,
|
|
194
|
+
children
|
|
195
|
+
}) {
|
|
196
|
+
const {
|
|
197
|
+
data,
|
|
198
|
+
dataKey,
|
|
199
|
+
width: widthProp,
|
|
200
|
+
height = DEFAULT_SPARKLINE_HEIGHT,
|
|
201
|
+
color = chartCssVars.linePrimary,
|
|
202
|
+
padding: paddingProp,
|
|
203
|
+
yDomain,
|
|
204
|
+
interactive = true,
|
|
205
|
+
hoverIndex: hoverIndexProp,
|
|
206
|
+
onHoverChange,
|
|
207
|
+
className,
|
|
208
|
+
style
|
|
209
|
+
} = config;
|
|
210
|
+
const containerRef = useRef(null);
|
|
211
|
+
const width = useSparklineWidth(containerRef, widthProp);
|
|
212
|
+
const gradientId = useId();
|
|
213
|
+
const values = useMemo(
|
|
214
|
+
() => resolveSparklineValues(data, dataKey),
|
|
215
|
+
[data, dataKey]
|
|
216
|
+
);
|
|
217
|
+
const resolvedPadding = resolveSparklinePadding(paddingProp, defaultPadding);
|
|
218
|
+
const { top, right, bottom, left } = resolvedPadding;
|
|
219
|
+
const padding = useMemo(
|
|
220
|
+
() => ({ top, right, bottom, left }),
|
|
221
|
+
[top, right, bottom, left]
|
|
222
|
+
);
|
|
223
|
+
const yMin = yDomain?.[0];
|
|
224
|
+
const yMax = yDomain?.[1];
|
|
225
|
+
const layout = useMemo(
|
|
226
|
+
() => computeSparklineLayout(values, {
|
|
227
|
+
width,
|
|
228
|
+
height,
|
|
229
|
+
padding,
|
|
230
|
+
kind,
|
|
231
|
+
domain: computeSparklineDomain(values, {
|
|
232
|
+
yDomain: [yMin, yMax],
|
|
233
|
+
includeZero
|
|
234
|
+
})
|
|
235
|
+
}),
|
|
236
|
+
[values, width, height, padding, kind, yMin, yMax, includeZero]
|
|
237
|
+
);
|
|
238
|
+
const [hoverIndex, setHoverIndex] = useHoverState(
|
|
239
|
+
data,
|
|
240
|
+
hoverIndexProp,
|
|
241
|
+
onHoverChange
|
|
242
|
+
);
|
|
243
|
+
const handlePointerMove = useCallback(
|
|
244
|
+
(event) => {
|
|
245
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
246
|
+
setHoverIndex(
|
|
247
|
+
sparklineIndexAtX(event.clientX - rect.left, {
|
|
248
|
+
count: values.length,
|
|
249
|
+
width,
|
|
250
|
+
padding,
|
|
251
|
+
kind
|
|
252
|
+
})
|
|
253
|
+
);
|
|
254
|
+
},
|
|
255
|
+
[setHoverIndex, values.length, width, padding, kind]
|
|
256
|
+
);
|
|
257
|
+
const handlePointerLeave = useCallback(
|
|
258
|
+
() => setHoverIndex(null),
|
|
259
|
+
[setHoverIndex]
|
|
260
|
+
);
|
|
261
|
+
const label = config["aria-label"] ?? describeSparkline(values);
|
|
262
|
+
return /* @__PURE__ */ jsx(
|
|
263
|
+
"div",
|
|
264
|
+
{
|
|
265
|
+
className: cn(
|
|
266
|
+
"relative min-w-0",
|
|
267
|
+
widthProp === void 0 && "w-full",
|
|
268
|
+
className
|
|
269
|
+
),
|
|
270
|
+
ref: containerRef,
|
|
271
|
+
style: { width: widthProp, height, ...style },
|
|
272
|
+
children: width > 0 ? /* @__PURE__ */ jsx(
|
|
273
|
+
"svg",
|
|
274
|
+
{
|
|
275
|
+
"aria-label": label,
|
|
276
|
+
className: "block overflow-visible",
|
|
277
|
+
height,
|
|
278
|
+
onPointerLeave: interactive ? handlePointerLeave : void 0,
|
|
279
|
+
onPointerMove: interactive ? handlePointerMove : void 0,
|
|
280
|
+
role: "img",
|
|
281
|
+
style: interactive ? { touchAction: "pan-y" } : void 0,
|
|
282
|
+
width,
|
|
283
|
+
children: children({
|
|
284
|
+
width,
|
|
285
|
+
height,
|
|
286
|
+
layout,
|
|
287
|
+
values,
|
|
288
|
+
hoverIndex,
|
|
289
|
+
color,
|
|
290
|
+
gradientId
|
|
291
|
+
})
|
|
292
|
+
}
|
|
293
|
+
) : null
|
|
294
|
+
}
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
function SparklineCrosshairLine({
|
|
298
|
+
x,
|
|
299
|
+
height,
|
|
300
|
+
padding,
|
|
301
|
+
variant,
|
|
302
|
+
gradientId
|
|
303
|
+
}) {
|
|
304
|
+
const id = `${gradientId}-crosshair`;
|
|
305
|
+
return /* @__PURE__ */ jsx(m.g, { "aria-hidden": true, pointerEvents: "none", style: { x }, children: variant === "gradient" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
306
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", { id, x1: "0", x2: "0", y1: "0", y2: "1", children: [
|
|
307
|
+
/* @__PURE__ */ jsx(
|
|
308
|
+
"stop",
|
|
309
|
+
{
|
|
310
|
+
offset: "0",
|
|
311
|
+
stopColor: chartCssVars.crosshair,
|
|
312
|
+
stopOpacity: "0"
|
|
313
|
+
}
|
|
314
|
+
),
|
|
315
|
+
/* @__PURE__ */ jsx(
|
|
316
|
+
"stop",
|
|
317
|
+
{
|
|
318
|
+
offset: "0.5",
|
|
319
|
+
stopColor: chartCssVars.crosshair,
|
|
320
|
+
stopOpacity: "1"
|
|
321
|
+
}
|
|
322
|
+
),
|
|
323
|
+
/* @__PURE__ */ jsx(
|
|
324
|
+
"stop",
|
|
325
|
+
{
|
|
326
|
+
offset: "1",
|
|
327
|
+
stopColor: chartCssVars.crosshair,
|
|
328
|
+
stopOpacity: "0"
|
|
329
|
+
}
|
|
330
|
+
)
|
|
331
|
+
] }) }),
|
|
332
|
+
/* @__PURE__ */ jsx("rect", { fill: `url(#${id})`, height, width: 1, x: -0.5, y: 0 })
|
|
333
|
+
] }) : /* @__PURE__ */ jsx(
|
|
334
|
+
"line",
|
|
335
|
+
{
|
|
336
|
+
stroke: chartCssVars.crosshair,
|
|
337
|
+
strokeDasharray: variant === "dashed" ? "2 2" : void 0,
|
|
338
|
+
strokeWidth: 1,
|
|
339
|
+
x1: 0,
|
|
340
|
+
x2: 0,
|
|
341
|
+
y1: padding.top / 2,
|
|
342
|
+
y2: height - padding.bottom / 2
|
|
343
|
+
}
|
|
344
|
+
) });
|
|
345
|
+
}
|
|
346
|
+
function SparklineDot({
|
|
347
|
+
x,
|
|
348
|
+
y,
|
|
349
|
+
color
|
|
350
|
+
}) {
|
|
351
|
+
return /* @__PURE__ */ jsx(
|
|
352
|
+
m.circle,
|
|
353
|
+
{
|
|
354
|
+
"aria-hidden": true,
|
|
355
|
+
cx: x,
|
|
356
|
+
cy: y,
|
|
357
|
+
fill: color,
|
|
358
|
+
pointerEvents: "none",
|
|
359
|
+
r: 3,
|
|
360
|
+
stroke: chartCssVars.background,
|
|
361
|
+
strokeWidth: 1.5
|
|
362
|
+
}
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
function HoverMarksView({
|
|
366
|
+
x,
|
|
367
|
+
y,
|
|
368
|
+
showDot,
|
|
369
|
+
height,
|
|
370
|
+
padding,
|
|
371
|
+
crosshair,
|
|
372
|
+
dot,
|
|
373
|
+
color,
|
|
374
|
+
gradientId
|
|
375
|
+
}) {
|
|
376
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
377
|
+
crosshair ? /* @__PURE__ */ jsx(
|
|
378
|
+
SparklineCrosshairLine,
|
|
379
|
+
{
|
|
380
|
+
gradientId,
|
|
381
|
+
height,
|
|
382
|
+
padding,
|
|
383
|
+
variant: crosshair,
|
|
384
|
+
x
|
|
385
|
+
}
|
|
386
|
+
) : null,
|
|
387
|
+
dot && showDot ? /* @__PURE__ */ jsx(SparklineDot, { color, x, y }) : null
|
|
388
|
+
] });
|
|
389
|
+
}
|
|
390
|
+
function SpringHoverMarks({
|
|
391
|
+
point,
|
|
392
|
+
fallbackY,
|
|
393
|
+
spring,
|
|
394
|
+
...rest
|
|
395
|
+
}) {
|
|
396
|
+
const targetY = Number.isFinite(point.y) ? point.y : fallbackY;
|
|
397
|
+
const x = useSpring(point.x, spring);
|
|
398
|
+
const y = useSpring(targetY, spring);
|
|
399
|
+
useLayoutEffect(() => {
|
|
400
|
+
x.set(point.x);
|
|
401
|
+
y.set(targetY);
|
|
402
|
+
}, [x, y, point.x, targetY]);
|
|
403
|
+
return /* @__PURE__ */ jsx(HoverMarksView, { showDot: Number.isFinite(point.y), x, y, ...rest });
|
|
404
|
+
}
|
|
405
|
+
function HoverMarks({
|
|
406
|
+
spring,
|
|
407
|
+
point,
|
|
408
|
+
fallbackY,
|
|
409
|
+
...rest
|
|
410
|
+
}) {
|
|
411
|
+
const reducedMotion = useReducedMotion();
|
|
412
|
+
if (spring && !reducedMotion) {
|
|
413
|
+
return /* @__PURE__ */ jsx(
|
|
414
|
+
SpringHoverMarks,
|
|
415
|
+
{
|
|
416
|
+
fallbackY,
|
|
417
|
+
point,
|
|
418
|
+
spring,
|
|
419
|
+
...rest
|
|
420
|
+
}
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
return /* @__PURE__ */ jsx(
|
|
424
|
+
HoverMarksView,
|
|
425
|
+
{
|
|
426
|
+
showDot: Number.isFinite(point.y),
|
|
427
|
+
x: point.x,
|
|
428
|
+
y: point.y,
|
|
429
|
+
...rest
|
|
430
|
+
}
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
function SparklineHighlight({
|
|
434
|
+
layout,
|
|
435
|
+
hoverIndex,
|
|
436
|
+
height,
|
|
437
|
+
lineRef,
|
|
438
|
+
stroke,
|
|
439
|
+
strokeWidth
|
|
440
|
+
}) {
|
|
441
|
+
const clipId = useId();
|
|
442
|
+
const highlightRef = useRef(null);
|
|
443
|
+
const { points } = layout;
|
|
444
|
+
const start = points[Math.max(0, hoverIndex - 1)]?.x ?? 0;
|
|
445
|
+
const end = points[Math.min(points.length - 1, hoverIndex + 1)]?.x ?? 0;
|
|
446
|
+
const x = useSpring(start, HIGHLIGHT_SPRING);
|
|
447
|
+
const width = useSpring(end - start, HIGHLIGHT_SPRING);
|
|
448
|
+
useLayoutEffect(() => {
|
|
449
|
+
highlightRef.current?.setAttribute(
|
|
450
|
+
"d",
|
|
451
|
+
lineRef.current?.getAttribute("d") ?? ""
|
|
452
|
+
);
|
|
453
|
+
if (prefersReducedMotion()) {
|
|
454
|
+
x.jump(start);
|
|
455
|
+
width.jump(end - start);
|
|
456
|
+
} else {
|
|
457
|
+
x.set(start);
|
|
458
|
+
width.set(end - start);
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
return /* @__PURE__ */ jsxs("g", { "aria-hidden": true, pointerEvents: "none", children: [
|
|
462
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("clipPath", { id: clipId, children: /* @__PURE__ */ jsx(
|
|
463
|
+
m.rect,
|
|
464
|
+
{
|
|
465
|
+
height: height + strokeWidth * 2,
|
|
466
|
+
width,
|
|
467
|
+
x,
|
|
468
|
+
y: -strokeWidth
|
|
469
|
+
}
|
|
470
|
+
) }) }),
|
|
471
|
+
/* @__PURE__ */ jsx(
|
|
472
|
+
m.path,
|
|
473
|
+
{
|
|
474
|
+
animate: { opacity: 1 },
|
|
475
|
+
clipPath: `url(#${clipId})`,
|
|
476
|
+
fill: "none",
|
|
477
|
+
initial: { opacity: 0 },
|
|
478
|
+
ref: highlightRef,
|
|
479
|
+
stroke,
|
|
480
|
+
strokeLinecap: "round",
|
|
481
|
+
strokeLinejoin: "round",
|
|
482
|
+
strokeWidth,
|
|
483
|
+
transition: { duration: 0.4, ease: "easeInOut" }
|
|
484
|
+
}
|
|
485
|
+
)
|
|
486
|
+
] });
|
|
487
|
+
}
|
|
488
|
+
function HoverOverlay({
|
|
489
|
+
layout,
|
|
490
|
+
hoverIndex,
|
|
491
|
+
spring,
|
|
492
|
+
...rest
|
|
493
|
+
}) {
|
|
494
|
+
const point = hoverIndex === null ? void 0 : layout.points[hoverIndex];
|
|
495
|
+
if (!point) {
|
|
496
|
+
return null;
|
|
497
|
+
}
|
|
498
|
+
return /* @__PURE__ */ jsx(
|
|
499
|
+
HoverMarks,
|
|
500
|
+
{
|
|
501
|
+
fallbackY: layout.baselineY,
|
|
502
|
+
point,
|
|
503
|
+
spring,
|
|
504
|
+
...rest
|
|
505
|
+
}
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
function resolveHoverSpring(hoverTransition, springConfig) {
|
|
509
|
+
return hoverTransition ? { ...DEFAULT_SPARKLINE_HOVER_SPRING, ...springConfig } : null;
|
|
510
|
+
}
|
|
511
|
+
function LineOrArea({
|
|
512
|
+
config,
|
|
513
|
+
variant
|
|
514
|
+
}) {
|
|
515
|
+
const {
|
|
516
|
+
curve = "monotone",
|
|
517
|
+
strokeWidth = 1.5,
|
|
518
|
+
endDot = false,
|
|
519
|
+
fill = "gradient",
|
|
520
|
+
fillOpacity = variant === "area" ? 0.3 : 0,
|
|
521
|
+
animate = true,
|
|
522
|
+
animationDuration = DEFAULT_SPARKLINE_ANIMATION_DURATION_MS,
|
|
523
|
+
animationEasing = DEFAULT_ANIMATION_EASING,
|
|
524
|
+
dataTransitionDuration = DEFAULT_SPARKLINE_DATA_TRANSITION_MS,
|
|
525
|
+
crosshair = "dashed",
|
|
526
|
+
dot = true,
|
|
527
|
+
hoverTransition = true,
|
|
528
|
+
springConfig,
|
|
529
|
+
showHighlight = true,
|
|
530
|
+
inactiveOpacity = 0.5
|
|
531
|
+
} = config;
|
|
532
|
+
const spring = resolveHoverSpring(hoverTransition, springConfig);
|
|
533
|
+
const padding = resolveSparklinePadding(config.padding, 4);
|
|
534
|
+
const groupRef = useRef(null);
|
|
535
|
+
const lineRef = useRef(null);
|
|
536
|
+
return /* @__PURE__ */ jsx(
|
|
537
|
+
SparklineFrame,
|
|
538
|
+
{
|
|
539
|
+
config,
|
|
540
|
+
defaultPadding: 4,
|
|
541
|
+
includeZero: false,
|
|
542
|
+
kind: "point",
|
|
543
|
+
children: ({ width, height, layout, hoverIndex, color, gradientId }) => /* @__PURE__ */ jsx(
|
|
544
|
+
LineOrAreaPaths,
|
|
545
|
+
{
|
|
546
|
+
animate,
|
|
547
|
+
animationDuration,
|
|
548
|
+
animationEasing,
|
|
549
|
+
color,
|
|
550
|
+
crosshair,
|
|
551
|
+
curve,
|
|
552
|
+
dataTransitionDuration: animate ? dataTransitionDuration : 0,
|
|
553
|
+
dot,
|
|
554
|
+
endDot,
|
|
555
|
+
fill,
|
|
556
|
+
fillOpacity,
|
|
557
|
+
gradientId,
|
|
558
|
+
groupRef,
|
|
559
|
+
height,
|
|
560
|
+
hoverIndex,
|
|
561
|
+
inactiveOpacity: showHighlight ? inactiveOpacity : 1,
|
|
562
|
+
layout,
|
|
563
|
+
lineRef,
|
|
564
|
+
padding,
|
|
565
|
+
showHighlight,
|
|
566
|
+
spring,
|
|
567
|
+
strokeWidth,
|
|
568
|
+
variant,
|
|
569
|
+
width
|
|
570
|
+
}
|
|
571
|
+
)
|
|
572
|
+
}
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
function LineOrAreaPaths({
|
|
576
|
+
variant,
|
|
577
|
+
layout,
|
|
578
|
+
width,
|
|
579
|
+
height,
|
|
580
|
+
padding,
|
|
581
|
+
curve,
|
|
582
|
+
strokeWidth,
|
|
583
|
+
color,
|
|
584
|
+
fill,
|
|
585
|
+
fillOpacity,
|
|
586
|
+
endDot,
|
|
587
|
+
hoverIndex,
|
|
588
|
+
crosshair,
|
|
589
|
+
dot,
|
|
590
|
+
gradientId,
|
|
591
|
+
animate,
|
|
592
|
+
animationDuration,
|
|
593
|
+
animationEasing,
|
|
594
|
+
dataTransitionDuration,
|
|
595
|
+
groupRef,
|
|
596
|
+
lineRef,
|
|
597
|
+
spring,
|
|
598
|
+
showHighlight,
|
|
599
|
+
inactiveOpacity
|
|
600
|
+
}) {
|
|
601
|
+
const linePath = useMemo(
|
|
602
|
+
() => buildSparklineLinePath(layout.points, curve),
|
|
603
|
+
[layout, curve]
|
|
604
|
+
);
|
|
605
|
+
const areaPath = useMemo(
|
|
606
|
+
() => variant === "area" ? buildSparklineAreaPath(layout.points, curve, layout.baselineY) : "",
|
|
607
|
+
[variant, layout, curve]
|
|
608
|
+
);
|
|
609
|
+
const areaRef = useRef(null);
|
|
610
|
+
useDataTransition(layout, width, dataTransitionDuration, (frame) => {
|
|
611
|
+
lineRef.current?.setAttribute(
|
|
612
|
+
"d",
|
|
613
|
+
buildSparklineLinePath(frame.points, curve)
|
|
614
|
+
);
|
|
615
|
+
areaRef.current?.setAttribute(
|
|
616
|
+
"d",
|
|
617
|
+
buildSparklineAreaPath(frame.points, curve, frame.baselineY)
|
|
618
|
+
);
|
|
619
|
+
});
|
|
620
|
+
useEnterAnimation(variant === "line" ? lineRef : groupRef, width > 0, {
|
|
621
|
+
animate,
|
|
622
|
+
duration: animationDuration,
|
|
623
|
+
easing: animationEasing,
|
|
624
|
+
keyframes: variant === "line" ? drawKeyframes : wipeKeyframes
|
|
625
|
+
});
|
|
626
|
+
const fillId = `${gradientId}-fill`;
|
|
627
|
+
let last;
|
|
628
|
+
for (let i = layout.points.length - 1; i >= 0 && !last; i--) {
|
|
629
|
+
const point = layout.points[i];
|
|
630
|
+
if (point && Number.isFinite(point.y)) {
|
|
631
|
+
last = point;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
635
|
+
/* @__PURE__ */ jsxs(
|
|
636
|
+
"g",
|
|
637
|
+
{
|
|
638
|
+
"aria-hidden": true,
|
|
639
|
+
ref: groupRef,
|
|
640
|
+
style: {
|
|
641
|
+
opacity: hoverIndex === null ? 1 : inactiveOpacity,
|
|
642
|
+
transition: HOVER_FADE
|
|
643
|
+
},
|
|
644
|
+
children: [
|
|
645
|
+
variant === "area" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
646
|
+
fill === "gradient" ? /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", { id: fillId, x1: "0", x2: "0", y1: "0", y2: "1", children: [
|
|
647
|
+
/* @__PURE__ */ jsx(
|
|
648
|
+
"stop",
|
|
649
|
+
{
|
|
650
|
+
offset: "0",
|
|
651
|
+
stopColor: color,
|
|
652
|
+
stopOpacity: fillOpacity
|
|
653
|
+
}
|
|
654
|
+
),
|
|
655
|
+
/* @__PURE__ */ jsx("stop", { offset: "1", stopColor: color, stopOpacity: 0 })
|
|
656
|
+
] }) }) : null,
|
|
657
|
+
/* @__PURE__ */ jsx(
|
|
658
|
+
"path",
|
|
659
|
+
{
|
|
660
|
+
d: areaPath,
|
|
661
|
+
fill: fill === "gradient" ? `url(#${fillId})` : color,
|
|
662
|
+
fillOpacity: fill === "gradient" ? 1 : fillOpacity,
|
|
663
|
+
ref: areaRef
|
|
664
|
+
}
|
|
665
|
+
)
|
|
666
|
+
] }) : null,
|
|
667
|
+
/* @__PURE__ */ jsx(
|
|
668
|
+
"path",
|
|
669
|
+
{
|
|
670
|
+
d: linePath,
|
|
671
|
+
fill: "none",
|
|
672
|
+
pathLength: 1,
|
|
673
|
+
ref: lineRef,
|
|
674
|
+
stroke: color,
|
|
675
|
+
strokeDasharray: variant === "line" ? 1 : void 0,
|
|
676
|
+
strokeLinecap: "round",
|
|
677
|
+
strokeLinejoin: "round",
|
|
678
|
+
strokeWidth
|
|
679
|
+
}
|
|
680
|
+
)
|
|
681
|
+
]
|
|
682
|
+
}
|
|
683
|
+
),
|
|
684
|
+
showHighlight && hoverIndex !== null ? /* @__PURE__ */ jsx(
|
|
685
|
+
SparklineHighlight,
|
|
686
|
+
{
|
|
687
|
+
height,
|
|
688
|
+
hoverIndex,
|
|
689
|
+
layout,
|
|
690
|
+
lineRef,
|
|
691
|
+
stroke: color,
|
|
692
|
+
strokeWidth
|
|
693
|
+
}
|
|
694
|
+
) : null,
|
|
695
|
+
endDot && hoverIndex === null && last ? /* @__PURE__ */ jsx(SparklineDot, { color, x: last.x, y: last.y }) : null,
|
|
696
|
+
/* @__PURE__ */ jsx(
|
|
697
|
+
HoverOverlay,
|
|
698
|
+
{
|
|
699
|
+
color,
|
|
700
|
+
crosshair,
|
|
701
|
+
dot,
|
|
702
|
+
gradientId,
|
|
703
|
+
height,
|
|
704
|
+
hoverIndex,
|
|
705
|
+
layout,
|
|
706
|
+
padding,
|
|
707
|
+
spring
|
|
708
|
+
}
|
|
709
|
+
)
|
|
710
|
+
] });
|
|
711
|
+
}
|
|
712
|
+
function LineSparklineImpl({
|
|
713
|
+
data: dataProp,
|
|
714
|
+
...rest
|
|
715
|
+
}) {
|
|
716
|
+
const { data } = useChartDataOverride("LineSparkline", { data: dataProp });
|
|
717
|
+
const props = { ...rest, data };
|
|
718
|
+
return /* @__PURE__ */ jsx(LazyMotion, { features: domAnimation, children: /* @__PURE__ */ jsx(LineOrArea, { config: props, variant: "line" }) });
|
|
719
|
+
}
|
|
720
|
+
function AreaSparklineImpl({
|
|
721
|
+
data: dataProp,
|
|
722
|
+
...rest
|
|
723
|
+
}) {
|
|
724
|
+
const { data } = useChartDataOverride("AreaSparkline", { data: dataProp });
|
|
725
|
+
const props = { ...rest, data };
|
|
726
|
+
return /* @__PURE__ */ jsx(LazyMotion, { features: domAnimation, children: /* @__PURE__ */ jsx(LineOrArea, { config: props, variant: "area" }) });
|
|
727
|
+
}
|
|
728
|
+
function BarSparklineImpl({
|
|
729
|
+
data: dataProp,
|
|
730
|
+
...rest
|
|
731
|
+
}) {
|
|
732
|
+
const { data } = useChartDataOverride("BarSparkline", { data: dataProp });
|
|
733
|
+
const props = { ...rest, data };
|
|
734
|
+
const {
|
|
735
|
+
barGap = 2,
|
|
736
|
+
barRadius = 1,
|
|
737
|
+
inactiveOpacity = 0.4,
|
|
738
|
+
animate = true,
|
|
739
|
+
animationDuration = DEFAULT_SPARKLINE_ANIMATION_DURATION_MS,
|
|
740
|
+
animationEasing = DEFAULT_ANIMATION_EASING,
|
|
741
|
+
dataTransitionDuration = DEFAULT_SPARKLINE_DATA_TRANSITION_MS,
|
|
742
|
+
crosshair = "dashed",
|
|
743
|
+
dot = true,
|
|
744
|
+
hoverTransition = true,
|
|
745
|
+
springConfig
|
|
746
|
+
} = props;
|
|
747
|
+
const spring = resolveHoverSpring(hoverTransition, springConfig);
|
|
748
|
+
const padding = resolveSparklinePadding(props.padding, 2);
|
|
749
|
+
const groupRef = useRef(null);
|
|
750
|
+
return /* @__PURE__ */ jsx(LazyMotion, { features: domAnimation, children: /* @__PURE__ */ jsx(SparklineFrame, { config: props, defaultPadding: 2, includeZero: true, kind: "band", children: ({ width, height, layout, hoverIndex, color, gradientId }) => /* @__PURE__ */ jsx(
|
|
751
|
+
BarPaths,
|
|
752
|
+
{
|
|
753
|
+
animate,
|
|
754
|
+
animationDuration,
|
|
755
|
+
animationEasing,
|
|
756
|
+
barGap,
|
|
757
|
+
barRadius,
|
|
758
|
+
color,
|
|
759
|
+
crosshair,
|
|
760
|
+
dataTransitionDuration: animate ? dataTransitionDuration : 0,
|
|
761
|
+
dot,
|
|
762
|
+
gradientId,
|
|
763
|
+
groupRef,
|
|
764
|
+
height,
|
|
765
|
+
hoverIndex,
|
|
766
|
+
inactiveOpacity,
|
|
767
|
+
layout,
|
|
768
|
+
padding,
|
|
769
|
+
spring,
|
|
770
|
+
width
|
|
771
|
+
}
|
|
772
|
+
) }) });
|
|
773
|
+
}
|
|
774
|
+
function BarPaths({
|
|
775
|
+
layout,
|
|
776
|
+
width,
|
|
777
|
+
height,
|
|
778
|
+
padding,
|
|
779
|
+
barGap,
|
|
780
|
+
barRadius,
|
|
781
|
+
inactiveOpacity,
|
|
782
|
+
color,
|
|
783
|
+
hoverIndex,
|
|
784
|
+
crosshair,
|
|
785
|
+
dot,
|
|
786
|
+
gradientId,
|
|
787
|
+
animate,
|
|
788
|
+
animationDuration,
|
|
789
|
+
animationEasing,
|
|
790
|
+
dataTransitionDuration,
|
|
791
|
+
groupRef,
|
|
792
|
+
spring
|
|
793
|
+
}) {
|
|
794
|
+
const barsRef = useRef(null);
|
|
795
|
+
useDataTransition(layout, width, dataTransitionDuration, (frame) => {
|
|
796
|
+
barsRef.current?.setAttribute(
|
|
797
|
+
"d",
|
|
798
|
+
buildSparklineBarsPath(frame, { gap: barGap, radius: barRadius })
|
|
799
|
+
);
|
|
800
|
+
});
|
|
801
|
+
const barsPath = useMemo(
|
|
802
|
+
() => buildSparklineBarsPath(layout, { gap: barGap, radius: barRadius }),
|
|
803
|
+
[layout, barGap, barRadius]
|
|
804
|
+
);
|
|
805
|
+
const keyframes = useMemo(
|
|
806
|
+
() => [
|
|
807
|
+
{
|
|
808
|
+
clipPath: "inset(0 100% 0 0)",
|
|
809
|
+
transform: "scaleY(0)",
|
|
810
|
+
transformOrigin: `0 ${layout.baselineY}px`
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
clipPath: "inset(0 0% 0 0)",
|
|
814
|
+
transform: "scaleY(1)",
|
|
815
|
+
transformOrigin: `0 ${layout.baselineY}px`
|
|
816
|
+
}
|
|
817
|
+
],
|
|
818
|
+
[layout.baselineY]
|
|
819
|
+
);
|
|
820
|
+
useEnterAnimation(groupRef, width > 0, {
|
|
821
|
+
animate,
|
|
822
|
+
duration: animationDuration,
|
|
823
|
+
easing: animationEasing,
|
|
824
|
+
keyframes
|
|
825
|
+
});
|
|
826
|
+
const hovered = hoverIndex === null ? void 0 : layout.points[hoverIndex];
|
|
827
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
828
|
+
/* @__PURE__ */ jsxs("g", { "aria-hidden": true, ref: groupRef, children: [
|
|
829
|
+
/* @__PURE__ */ jsx(
|
|
830
|
+
"path",
|
|
831
|
+
{
|
|
832
|
+
d: barsPath,
|
|
833
|
+
fill: color,
|
|
834
|
+
ref: barsRef,
|
|
835
|
+
style: {
|
|
836
|
+
opacity: hovered ? inactiveOpacity : 1,
|
|
837
|
+
transition: HOVER_FADE
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
),
|
|
841
|
+
/* @__PURE__ */ jsx(AnimatePresence, { children: hovered && hoverIndex !== null && Number.isFinite(hovered.y) ? /* @__PURE__ */ jsx(
|
|
842
|
+
m.path,
|
|
843
|
+
{
|
|
844
|
+
animate: { opacity: 1 },
|
|
845
|
+
d: buildSparklineBarSegment(
|
|
846
|
+
hovered.x,
|
|
847
|
+
sparklineBarWidth(layout.band, barGap),
|
|
848
|
+
hovered.y,
|
|
849
|
+
layout.baselineY,
|
|
850
|
+
barRadius
|
|
851
|
+
),
|
|
852
|
+
exit: { opacity: 0 },
|
|
853
|
+
fill: color,
|
|
854
|
+
initial: { opacity: inactiveOpacity },
|
|
855
|
+
transition: { duration: 0.2, ease: "easeInOut" }
|
|
856
|
+
},
|
|
857
|
+
hoverIndex
|
|
858
|
+
) : null })
|
|
859
|
+
] }),
|
|
860
|
+
/* @__PURE__ */ jsx(
|
|
861
|
+
HoverOverlay,
|
|
862
|
+
{
|
|
863
|
+
color,
|
|
864
|
+
crosshair,
|
|
865
|
+
dot,
|
|
866
|
+
gradientId,
|
|
867
|
+
height,
|
|
868
|
+
hoverIndex,
|
|
869
|
+
layout,
|
|
870
|
+
padding,
|
|
871
|
+
spring
|
|
872
|
+
}
|
|
873
|
+
)
|
|
874
|
+
] });
|
|
875
|
+
}
|
|
876
|
+
const LineSparkline = memo(
|
|
877
|
+
LineSparklineImpl
|
|
878
|
+
);
|
|
879
|
+
const AreaSparkline = memo(
|
|
880
|
+
AreaSparklineImpl
|
|
881
|
+
);
|
|
882
|
+
const BarSparkline = memo(BarSparklineImpl);
|
|
883
|
+
function useSparklineHover() {
|
|
884
|
+
const [state, setState] = useState(
|
|
885
|
+
{ index: null, datum: null }
|
|
886
|
+
);
|
|
887
|
+
const onHoverChange = useCallback(
|
|
888
|
+
(index, datum) => setState({ index, datum }),
|
|
889
|
+
[]
|
|
890
|
+
);
|
|
891
|
+
const sparklineProps = useMemo(
|
|
892
|
+
() => ({ hoverIndex: state.index, onHoverChange }),
|
|
893
|
+
[state.index, onHoverChange]
|
|
894
|
+
);
|
|
895
|
+
return {
|
|
896
|
+
index: state.index,
|
|
897
|
+
datum: state.datum,
|
|
898
|
+
isHovering: state.index !== null,
|
|
899
|
+
sparklineProps
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
export {
|
|
903
|
+
AreaSparkline,
|
|
904
|
+
BarSparkline,
|
|
905
|
+
DEFAULT_SPARKLINE_ANIMATION_DURATION_MS,
|
|
906
|
+
DEFAULT_SPARKLINE_DATA_TRANSITION_MS,
|
|
907
|
+
DEFAULT_SPARKLINE_HOVER_SPRING,
|
|
908
|
+
LineSparkline,
|
|
909
|
+
useSparklineHover
|
|
910
|
+
};
|