@aiconstructions/graficos 0.0.0-stage → 0.2.1
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 +53 -0
- package/LICENSE-BKLIT +21 -0
- package/LICENSE-visx-pattern +21 -0
- package/README.md +188 -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,192 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { animate, useReducedMotion } from "motion/react";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { LINE_LOADING_PULSE_EASE } from "./line-loading-timing";
|
|
5
|
+
import {
|
|
6
|
+
domainsEqual,
|
|
7
|
+
isYDomainTweenPhase,
|
|
8
|
+
resolveAnimatedYDestinationDomains,
|
|
9
|
+
shouldTweenYDomain
|
|
10
|
+
} from "./y-domain-utils";
|
|
11
|
+
function lerpDomain(from, to, progress) {
|
|
12
|
+
return [
|
|
13
|
+
from[0] + (to[0] - from[0]) * progress,
|
|
14
|
+
from[1] + (to[1] - from[1]) * progress
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
function snapDomains(domains, setAnimatedByAxis, animatedRef) {
|
|
18
|
+
if (domainsEqual(animatedRef.current, domains)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
setAnimatedByAxis(domains);
|
|
22
|
+
animatedRef.current = domains;
|
|
23
|
+
}
|
|
24
|
+
function tweenDomains({
|
|
25
|
+
destination,
|
|
26
|
+
durationMs,
|
|
27
|
+
enabled,
|
|
28
|
+
reducedMotion,
|
|
29
|
+
animatedRef,
|
|
30
|
+
setAnimatedByAxis,
|
|
31
|
+
onSettled
|
|
32
|
+
}) {
|
|
33
|
+
if (domainsEqual(animatedRef.current, destination)) {
|
|
34
|
+
onSettled?.();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (!enabled || reducedMotion) {
|
|
38
|
+
snapDomains(destination, setAnimatedByAxis, animatedRef);
|
|
39
|
+
onSettled?.();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const axisIds = Object.keys(destination);
|
|
43
|
+
const fromSnapshot = animatedRef.current;
|
|
44
|
+
let needsTween = false;
|
|
45
|
+
for (const axisId of axisIds) {
|
|
46
|
+
const from = fromSnapshot[axisId] ?? destination[axisId] ?? [0, 100];
|
|
47
|
+
const to = destination[axisId] ?? from;
|
|
48
|
+
if (shouldTweenYDomain(from, to)) {
|
|
49
|
+
needsTween = true;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (!needsTween) {
|
|
54
|
+
snapDomains(destination, setAnimatedByAxis, animatedRef);
|
|
55
|
+
onSettled?.();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const fromByAxis = {};
|
|
59
|
+
for (const axisId of axisIds) {
|
|
60
|
+
fromByAxis[axisId] = fromSnapshot[axisId] ?? destination[axisId] ?? [0, 100];
|
|
61
|
+
}
|
|
62
|
+
const control = animate(0, 1, {
|
|
63
|
+
duration: durationMs / 1e3,
|
|
64
|
+
ease: [...LINE_LOADING_PULSE_EASE],
|
|
65
|
+
onUpdate: (progress) => {
|
|
66
|
+
const next = {};
|
|
67
|
+
for (const axisId of axisIds) {
|
|
68
|
+
const from = fromByAxis[axisId] ?? destination[axisId] ?? [0, 100];
|
|
69
|
+
const to = destination[axisId] ?? from;
|
|
70
|
+
next[axisId] = shouldTweenYDomain(from, to) ? lerpDomain(from, to, progress) : to;
|
|
71
|
+
}
|
|
72
|
+
animatedRef.current = next;
|
|
73
|
+
setAnimatedByAxis(next);
|
|
74
|
+
},
|
|
75
|
+
onComplete: () => {
|
|
76
|
+
snapDomains(destination, setAnimatedByAxis, animatedRef);
|
|
77
|
+
onSettled?.();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return control;
|
|
81
|
+
}
|
|
82
|
+
function useAnimatedYDomains({
|
|
83
|
+
enabled,
|
|
84
|
+
durationMs,
|
|
85
|
+
chartPhase,
|
|
86
|
+
skeletonByAxis,
|
|
87
|
+
targetByAxis,
|
|
88
|
+
onSettled,
|
|
89
|
+
tweenOnTargetChange = false
|
|
90
|
+
}) {
|
|
91
|
+
const reducedMotion = useReducedMotion();
|
|
92
|
+
const destinationByAxis = resolveAnimatedYDestinationDomains(
|
|
93
|
+
chartPhase,
|
|
94
|
+
skeletonByAxis,
|
|
95
|
+
targetByAxis
|
|
96
|
+
);
|
|
97
|
+
const destinationRef = useRef(destinationByAxis);
|
|
98
|
+
const skeletonRef = useRef(skeletonByAxis);
|
|
99
|
+
const targetRef = useRef(targetByAxis);
|
|
100
|
+
const [animatedByAxis, setAnimatedByAxis] = useState(destinationByAxis);
|
|
101
|
+
const mayTween = isYDomainTweenPhase(chartPhase) || tweenOnTargetChange && chartPhase === "ready" && enabled && !reducedMotion;
|
|
102
|
+
if (!mayTween && animatedByAxis !== destinationByAxis && !domainsEqual(animatedByAxis, destinationByAxis)) {
|
|
103
|
+
setAnimatedByAxis(destinationByAxis);
|
|
104
|
+
}
|
|
105
|
+
const animatedRef = useRef(animatedByAxis);
|
|
106
|
+
const prevPhaseRef = useRef(chartPhase);
|
|
107
|
+
const onSettledRef = useRef(onSettled);
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
destinationRef.current = destinationByAxis;
|
|
110
|
+
skeletonRef.current = skeletonByAxis;
|
|
111
|
+
targetRef.current = targetByAxis;
|
|
112
|
+
onSettledRef.current = onSettled;
|
|
113
|
+
});
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
animatedRef.current = animatedByAxis;
|
|
116
|
+
}, [animatedByAxis]);
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
if (prevPhaseRef.current === chartPhase) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
prevPhaseRef.current = chartPhase;
|
|
122
|
+
const settle = () => {
|
|
123
|
+
onSettledRef.current?.();
|
|
124
|
+
};
|
|
125
|
+
if (chartPhase === "exiting") {
|
|
126
|
+
snapDomains(skeletonRef.current, setAnimatedByAxis, animatedRef);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (chartPhase === "exitingReady") {
|
|
130
|
+
snapDomains(targetRef.current, setAnimatedByAxis, animatedRef);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (chartPhase === "loading") {
|
|
134
|
+
snapDomains(skeletonRef.current, setAnimatedByAxis, animatedRef);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (chartPhase === "revealing" || chartPhase === "ready") {
|
|
138
|
+
snapDomains(targetRef.current, setAnimatedByAxis, animatedRef);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (!isYDomainTweenPhase(chartPhase)) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const control = tweenDomains({
|
|
145
|
+
destination: destinationRef.current,
|
|
146
|
+
durationMs,
|
|
147
|
+
enabled,
|
|
148
|
+
reducedMotion,
|
|
149
|
+
animatedRef,
|
|
150
|
+
setAnimatedByAxis,
|
|
151
|
+
onSettled: settle
|
|
152
|
+
});
|
|
153
|
+
return () => control?.stop();
|
|
154
|
+
}, [chartPhase, durationMs, enabled, reducedMotion]);
|
|
155
|
+
const targetSignature = JSON.stringify(targetByAxis);
|
|
156
|
+
const prevTargetSignatureRef = useRef(targetSignature);
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
const inLivePhase = chartPhase === "ready" || chartPhase === "revealing";
|
|
159
|
+
if (!inLivePhase) {
|
|
160
|
+
prevTargetSignatureRef.current = targetSignature;
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (prevTargetSignatureRef.current === targetSignature) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
prevTargetSignatureRef.current = targetSignature;
|
|
167
|
+
if (tweenOnTargetChange && chartPhase === "ready") {
|
|
168
|
+
const control = tweenDomains({
|
|
169
|
+
destination: targetRef.current,
|
|
170
|
+
durationMs,
|
|
171
|
+
enabled,
|
|
172
|
+
reducedMotion,
|
|
173
|
+
animatedRef,
|
|
174
|
+
setAnimatedByAxis,
|
|
175
|
+
onSettled: () => onSettledRef.current?.()
|
|
176
|
+
});
|
|
177
|
+
return () => control?.stop();
|
|
178
|
+
}
|
|
179
|
+
snapDomains(targetRef.current, setAnimatedByAxis, animatedRef);
|
|
180
|
+
}, [
|
|
181
|
+
chartPhase,
|
|
182
|
+
durationMs,
|
|
183
|
+
enabled,
|
|
184
|
+
reducedMotion,
|
|
185
|
+
targetSignature,
|
|
186
|
+
tweenOnTargetChange
|
|
187
|
+
]);
|
|
188
|
+
return mayTween ? animatedByAxis : destinationByAxis;
|
|
189
|
+
}
|
|
190
|
+
export {
|
|
191
|
+
useAnimatedYDomains
|
|
192
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { useChartStable } from "./chart-context";
|
|
4
|
+
import { detectDateKey, toValidDate } from "./date-ranges";
|
|
5
|
+
function useCategorySlots(dateKey) {
|
|
6
|
+
const { barScale, barXAccessor, data, orientation } = useChartStable();
|
|
7
|
+
return useMemo(() => {
|
|
8
|
+
if (!(barScale && barXAccessor)) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const key = dateKey ?? detectDateKey(data[0]);
|
|
12
|
+
const dates = data.map((row) => key ? toValidDate(row[key]) : null);
|
|
13
|
+
const step = barScale.step();
|
|
14
|
+
const gap = step - barScale.bandwidth();
|
|
15
|
+
return {
|
|
16
|
+
dates,
|
|
17
|
+
step,
|
|
18
|
+
axis: orientation === "horizontal" ? "y" : "x",
|
|
19
|
+
slotStart: (index) => {
|
|
20
|
+
const row = data[index];
|
|
21
|
+
const start = row ? barScale(barXAccessor(row)) : void 0;
|
|
22
|
+
return (start ?? 0) - gap / 2;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}, [barScale, barXAccessor, data, orientation, dateKey]);
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
useCategorySlots
|
|
29
|
+
};
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
createChartHoverStore
|
|
5
|
+
} from "./chart-context";
|
|
6
|
+
import { localPoint } from "./local-point";
|
|
7
|
+
import { useScheduledTooltip } from "./use-scheduled-tooltip";
|
|
8
|
+
import { normalizeYAxisId } from "./y-axis-scales";
|
|
9
|
+
function resolveYPositions(d, lines, bands, yScales, yScale) {
|
|
10
|
+
const yPositions = {};
|
|
11
|
+
const place = (key, yAxisId) => {
|
|
12
|
+
const value = d[key];
|
|
13
|
+
if (typeof value === "number") {
|
|
14
|
+
const axisScale = yScales[normalizeYAxisId(yAxisId)] ?? yScale;
|
|
15
|
+
yPositions[key] = axisScale(value) ?? 0;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
for (const band of bands ?? []) {
|
|
19
|
+
if (band.showInTooltip) {
|
|
20
|
+
place(band.upperKey, band.yAxisId);
|
|
21
|
+
place(band.lowerKey, band.yAxisId);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
for (const line of lines) {
|
|
25
|
+
place(line.dataKey, line.yAxisId);
|
|
26
|
+
}
|
|
27
|
+
return yPositions;
|
|
28
|
+
}
|
|
29
|
+
function useChartInteraction({
|
|
30
|
+
xScale,
|
|
31
|
+
yScale,
|
|
32
|
+
yScales,
|
|
33
|
+
data,
|
|
34
|
+
lines,
|
|
35
|
+
bands,
|
|
36
|
+
margin,
|
|
37
|
+
xAccessor,
|
|
38
|
+
bisectDate,
|
|
39
|
+
canInteract
|
|
40
|
+
}) {
|
|
41
|
+
const [hoverStore] = useState(createChartHoverStore);
|
|
42
|
+
const { setSelection } = hoverStore;
|
|
43
|
+
const { scheduleTooltip, clearTooltip, resetTooltipDedupe } = useScheduledTooltip(hoverStore.setTooltipData);
|
|
44
|
+
const isDraggingRef = useRef(false);
|
|
45
|
+
const dragStartXRef = useRef(0);
|
|
46
|
+
const lastHoveredXRef = useRef(null);
|
|
47
|
+
const resolveTooltipFromX = useCallback(
|
|
48
|
+
(pixelX) => {
|
|
49
|
+
const x0 = xScale.invert(pixelX);
|
|
50
|
+
const index = bisectDate(data, x0, 1);
|
|
51
|
+
const d0 = data[index - 1];
|
|
52
|
+
const d1 = data[index];
|
|
53
|
+
if (!d0) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
let d = d0;
|
|
57
|
+
let finalIndex = index - 1;
|
|
58
|
+
if (d1) {
|
|
59
|
+
const d0Time = xAccessor(d0).getTime();
|
|
60
|
+
const d1Time = xAccessor(d1).getTime();
|
|
61
|
+
if (x0.getTime() - d0Time > d1Time - x0.getTime()) {
|
|
62
|
+
d = d1;
|
|
63
|
+
finalIndex = index;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
point: d,
|
|
68
|
+
index: finalIndex,
|
|
69
|
+
x: xScale(xAccessor(d)) ?? 0,
|
|
70
|
+
yPositions: resolveYPositions(d, lines, bands, yScales, yScale)
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
[xScale, yScale, yScales, data, lines, bands, xAccessor, bisectDate]
|
|
74
|
+
);
|
|
75
|
+
const resolveIndexFromX = useCallback(
|
|
76
|
+
(pixelX) => {
|
|
77
|
+
const x0 = xScale.invert(pixelX);
|
|
78
|
+
const index = bisectDate(data, x0, 1);
|
|
79
|
+
const d0 = data[index - 1];
|
|
80
|
+
const d1 = data[index];
|
|
81
|
+
if (!d0) {
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
if (d1) {
|
|
85
|
+
const d0Time = xAccessor(d0).getTime();
|
|
86
|
+
const d1Time = xAccessor(d1).getTime();
|
|
87
|
+
if (x0.getTime() - d0Time > d1Time - x0.getTime()) {
|
|
88
|
+
return index;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return index - 1;
|
|
92
|
+
},
|
|
93
|
+
[xScale, data, xAccessor, bisectDate]
|
|
94
|
+
);
|
|
95
|
+
const getChartX = useCallback(
|
|
96
|
+
(event, touchIndex = 0) => {
|
|
97
|
+
let point = null;
|
|
98
|
+
if ("touches" in event) {
|
|
99
|
+
const touch = event.touches[touchIndex];
|
|
100
|
+
if (!touch) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const svg = event.currentTarget.ownerSVGElement;
|
|
104
|
+
if (!svg) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
point = localPoint(svg, touch);
|
|
108
|
+
} else {
|
|
109
|
+
point = localPoint(event);
|
|
110
|
+
}
|
|
111
|
+
if (!point) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
return point.x - margin.left;
|
|
115
|
+
},
|
|
116
|
+
[margin.left]
|
|
117
|
+
);
|
|
118
|
+
const handleMouseMove = useCallback(
|
|
119
|
+
(event) => {
|
|
120
|
+
const chartX = getChartX(event);
|
|
121
|
+
if (chartX === null) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (isDraggingRef.current) {
|
|
125
|
+
const startX = Math.min(dragStartXRef.current, chartX);
|
|
126
|
+
const endX = Math.max(dragStartXRef.current, chartX);
|
|
127
|
+
setSelection({
|
|
128
|
+
startX,
|
|
129
|
+
endX,
|
|
130
|
+
startIndex: resolveIndexFromX(startX),
|
|
131
|
+
endIndex: resolveIndexFromX(endX),
|
|
132
|
+
active: true
|
|
133
|
+
});
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
lastHoveredXRef.current = chartX;
|
|
137
|
+
const tooltip = resolveTooltipFromX(chartX);
|
|
138
|
+
if (tooltip) {
|
|
139
|
+
scheduleTooltip(tooltip);
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
[
|
|
143
|
+
getChartX,
|
|
144
|
+
resolveTooltipFromX,
|
|
145
|
+
resolveIndexFromX,
|
|
146
|
+
scheduleTooltip,
|
|
147
|
+
setSelection
|
|
148
|
+
]
|
|
149
|
+
);
|
|
150
|
+
const handleMouseLeave = useCallback(() => {
|
|
151
|
+
lastHoveredXRef.current = null;
|
|
152
|
+
clearTooltip();
|
|
153
|
+
if (isDraggingRef.current) {
|
|
154
|
+
isDraggingRef.current = false;
|
|
155
|
+
}
|
|
156
|
+
setSelection(null);
|
|
157
|
+
}, [clearTooltip, setSelection]);
|
|
158
|
+
const handleMouseDown = useCallback(
|
|
159
|
+
(event) => {
|
|
160
|
+
const chartX = getChartX(event);
|
|
161
|
+
if (chartX === null) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
event.preventDefault();
|
|
165
|
+
isDraggingRef.current = true;
|
|
166
|
+
dragStartXRef.current = chartX;
|
|
167
|
+
clearTooltip();
|
|
168
|
+
setSelection(null);
|
|
169
|
+
},
|
|
170
|
+
[getChartX, clearTooltip, setSelection]
|
|
171
|
+
);
|
|
172
|
+
const handleMouseUp = useCallback(() => {
|
|
173
|
+
if (isDraggingRef.current) {
|
|
174
|
+
isDraggingRef.current = false;
|
|
175
|
+
}
|
|
176
|
+
setSelection(null);
|
|
177
|
+
}, [setSelection]);
|
|
178
|
+
const handleTouchStart = useCallback(
|
|
179
|
+
(event) => {
|
|
180
|
+
if (event.touches.length === 1) {
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
const chartX = getChartX(event, 0);
|
|
183
|
+
if (chartX === null) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
lastHoveredXRef.current = chartX;
|
|
187
|
+
const tooltip = resolveTooltipFromX(chartX);
|
|
188
|
+
if (tooltip) {
|
|
189
|
+
scheduleTooltip(tooltip);
|
|
190
|
+
}
|
|
191
|
+
} else if (event.touches.length === 2) {
|
|
192
|
+
event.preventDefault();
|
|
193
|
+
resetTooltipDedupe();
|
|
194
|
+
clearTooltip();
|
|
195
|
+
const x0 = getChartX(event, 0);
|
|
196
|
+
const x1 = getChartX(event, 1);
|
|
197
|
+
if (x0 === null || x1 === null) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const startX = Math.min(x0, x1);
|
|
201
|
+
const endX = Math.max(x0, x1);
|
|
202
|
+
setSelection({
|
|
203
|
+
startX,
|
|
204
|
+
endX,
|
|
205
|
+
startIndex: resolveIndexFromX(startX),
|
|
206
|
+
endIndex: resolveIndexFromX(endX),
|
|
207
|
+
active: true
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
[
|
|
212
|
+
getChartX,
|
|
213
|
+
resolveTooltipFromX,
|
|
214
|
+
resolveIndexFromX,
|
|
215
|
+
scheduleTooltip,
|
|
216
|
+
resetTooltipDedupe,
|
|
217
|
+
clearTooltip,
|
|
218
|
+
setSelection
|
|
219
|
+
]
|
|
220
|
+
);
|
|
221
|
+
const handleTouchMove = useCallback(
|
|
222
|
+
(event) => {
|
|
223
|
+
if (event.touches.length === 1) {
|
|
224
|
+
event.preventDefault();
|
|
225
|
+
const chartX = getChartX(event, 0);
|
|
226
|
+
if (chartX === null) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
lastHoveredXRef.current = chartX;
|
|
230
|
+
const tooltip = resolveTooltipFromX(chartX);
|
|
231
|
+
if (tooltip) {
|
|
232
|
+
scheduleTooltip(tooltip);
|
|
233
|
+
}
|
|
234
|
+
} else if (event.touches.length === 2) {
|
|
235
|
+
event.preventDefault();
|
|
236
|
+
const x0 = getChartX(event, 0);
|
|
237
|
+
const x1 = getChartX(event, 1);
|
|
238
|
+
if (x0 === null || x1 === null) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const startX = Math.min(x0, x1);
|
|
242
|
+
const endX = Math.max(x0, x1);
|
|
243
|
+
setSelection({
|
|
244
|
+
startX,
|
|
245
|
+
endX,
|
|
246
|
+
startIndex: resolveIndexFromX(startX),
|
|
247
|
+
endIndex: resolveIndexFromX(endX),
|
|
248
|
+
active: true
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
[
|
|
253
|
+
getChartX,
|
|
254
|
+
resolveTooltipFromX,
|
|
255
|
+
resolveIndexFromX,
|
|
256
|
+
scheduleTooltip,
|
|
257
|
+
setSelection
|
|
258
|
+
]
|
|
259
|
+
);
|
|
260
|
+
const handleTouchEnd = useCallback(() => {
|
|
261
|
+
clearTooltip();
|
|
262
|
+
setSelection(null);
|
|
263
|
+
}, [clearTooltip, setSelection]);
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
if (!canInteract || lastHoveredXRef.current === null) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const tooltip = resolveTooltipFromX(lastHoveredXRef.current);
|
|
269
|
+
if (tooltip) {
|
|
270
|
+
scheduleTooltip(tooltip, `${tooltip.index}:${Math.round(tooltip.x)}`);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
clearTooltip();
|
|
274
|
+
}, [canInteract, clearTooltip, resolveTooltipFromX, scheduleTooltip]);
|
|
275
|
+
const interactionHandlers = canInteract ? {
|
|
276
|
+
onMouseMove: handleMouseMove,
|
|
277
|
+
onMouseLeave: handleMouseLeave,
|
|
278
|
+
onMouseDown: handleMouseDown,
|
|
279
|
+
onMouseUp: handleMouseUp,
|
|
280
|
+
onTouchStart: handleTouchStart,
|
|
281
|
+
onTouchMove: handleTouchMove,
|
|
282
|
+
onTouchEnd: handleTouchEnd
|
|
283
|
+
} : {};
|
|
284
|
+
const interactionStyle = {
|
|
285
|
+
cursor: canInteract ? "crosshair" : "default",
|
|
286
|
+
touchAction: "none"
|
|
287
|
+
};
|
|
288
|
+
return {
|
|
289
|
+
hoverStore,
|
|
290
|
+
interactionHandlers,
|
|
291
|
+
interactionStyle
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
export {
|
|
295
|
+
useChartInteraction
|
|
296
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
resolveRestingChartPhase
|
|
5
|
+
} from "./chart-phase";
|
|
6
|
+
function resolveInitialChartPhase(chartStatus, skipEnterReveal, animationDuration) {
|
|
7
|
+
if (chartStatus === "ready" && !skipEnterReveal && animationDuration > 0) {
|
|
8
|
+
return "revealing";
|
|
9
|
+
}
|
|
10
|
+
return resolveRestingChartPhase(chartStatus);
|
|
11
|
+
}
|
|
12
|
+
function resolvePlotData(chartPhase, chartStatus, skeletonData, targetData) {
|
|
13
|
+
if (chartPhase === "exiting") {
|
|
14
|
+
return skeletonData;
|
|
15
|
+
}
|
|
16
|
+
if (chartPhase === "loading" && chartStatus === "loading") {
|
|
17
|
+
return skeletonData;
|
|
18
|
+
}
|
|
19
|
+
return targetData;
|
|
20
|
+
}
|
|
21
|
+
function phaseInputsEqual(a, b) {
|
|
22
|
+
return a.chartStatus === b.chartStatus && a.chartPhase === b.chartPhase && a.animationDuration === b.animationDuration && a.revealSignature === b.revealSignature && a.skipEnterReveal === b.skipEnterReveal;
|
|
23
|
+
}
|
|
24
|
+
function resolveStatusTransition(prevStatus, chartStatus, animationDuration, yDomainTweenDuration) {
|
|
25
|
+
if (chartStatus === "ready" && prevStatus === "loading") {
|
|
26
|
+
if (animationDuration > 0) {
|
|
27
|
+
return { phase: "exiting", conceal: false };
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
phase: yDomainTweenDuration <= 0 ? "revealing" : "gridTweenReady",
|
|
31
|
+
conceal: false
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (chartStatus === "loading" && prevStatus === "ready") {
|
|
35
|
+
if (animationDuration > 0) {
|
|
36
|
+
return { phase: "exitingReady", conceal: true };
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
phase: yDomainTweenDuration <= 0 ? "loading" : "gridTweenLoading",
|
|
40
|
+
conceal: false
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
function shouldReplayReveal(prev, next) {
|
|
46
|
+
if (next.skipEnterReveal || next.chartStatus !== "ready") {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (next.chartPhase !== "ready") {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return prev.animationDuration !== next.animationDuration || prev.revealSignature !== next.revealSignature || prev.skipEnterReveal !== next.skipEnterReveal;
|
|
53
|
+
}
|
|
54
|
+
function resolvePhaseTransition(prev, next, yDomainTweenDuration) {
|
|
55
|
+
let nextPhase = next.chartPhase;
|
|
56
|
+
let resetLoaded = false;
|
|
57
|
+
let bumpConceal = false;
|
|
58
|
+
if (prev.chartStatus === next.chartStatus) {
|
|
59
|
+
if (shouldReplayReveal(prev, next)) {
|
|
60
|
+
nextPhase = "revealing";
|
|
61
|
+
resetLoaded = true;
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
const status = resolveStatusTransition(
|
|
65
|
+
prev.chartStatus,
|
|
66
|
+
next.chartStatus,
|
|
67
|
+
next.animationDuration,
|
|
68
|
+
yDomainTweenDuration
|
|
69
|
+
);
|
|
70
|
+
if (status) {
|
|
71
|
+
nextPhase = status.phase;
|
|
72
|
+
resetLoaded = true;
|
|
73
|
+
bumpConceal = status.conceal;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const bumpReveal = nextPhase === "revealing" && (prev.chartPhase !== "revealing" || nextPhase !== next.chartPhase || prev.animationDuration !== next.animationDuration);
|
|
77
|
+
return { nextPhase, resetLoaded, bumpConceal, bumpReveal };
|
|
78
|
+
}
|
|
79
|
+
function useChartPhaseOrchestrator({
|
|
80
|
+
chartStatus,
|
|
81
|
+
targetData,
|
|
82
|
+
skeletonData,
|
|
83
|
+
animationDuration,
|
|
84
|
+
yDomainTweenDuration,
|
|
85
|
+
revealSignature = "",
|
|
86
|
+
skipEnterReveal = false
|
|
87
|
+
}) {
|
|
88
|
+
const [chartPhase, setChartPhase] = useState(
|
|
89
|
+
() => resolveInitialChartPhase(chartStatus, skipEnterReveal, animationDuration)
|
|
90
|
+
);
|
|
91
|
+
const [revealEpoch, setRevealEpoch] = useState(
|
|
92
|
+
() => chartStatus === "ready" && !skipEnterReveal ? 1 : 0
|
|
93
|
+
);
|
|
94
|
+
const [concealEpoch, setConcealEpoch] = useState(0);
|
|
95
|
+
const [isLoaded, setIsLoaded] = useState(
|
|
96
|
+
() => chartStatus === "ready" && (skipEnterReveal || animationDuration <= 0)
|
|
97
|
+
);
|
|
98
|
+
const [prev, setPrev] = useState({
|
|
99
|
+
chartStatus,
|
|
100
|
+
chartPhase,
|
|
101
|
+
animationDuration,
|
|
102
|
+
revealSignature,
|
|
103
|
+
skipEnterReveal
|
|
104
|
+
});
|
|
105
|
+
const current = {
|
|
106
|
+
chartStatus,
|
|
107
|
+
chartPhase,
|
|
108
|
+
animationDuration,
|
|
109
|
+
revealSignature,
|
|
110
|
+
skipEnterReveal
|
|
111
|
+
};
|
|
112
|
+
if (!phaseInputsEqual(prev, current)) {
|
|
113
|
+
const transition = resolvePhaseTransition(
|
|
114
|
+
prev,
|
|
115
|
+
current,
|
|
116
|
+
yDomainTweenDuration
|
|
117
|
+
);
|
|
118
|
+
if (transition.resetLoaded) {
|
|
119
|
+
setIsLoaded(false);
|
|
120
|
+
}
|
|
121
|
+
if (transition.bumpConceal) {
|
|
122
|
+
setConcealEpoch((epoch) => epoch + 1);
|
|
123
|
+
}
|
|
124
|
+
if (transition.bumpReveal) {
|
|
125
|
+
setRevealEpoch((epoch) => epoch + 1);
|
|
126
|
+
}
|
|
127
|
+
if (transition.nextPhase !== chartPhase) {
|
|
128
|
+
setChartPhase(transition.nextPhase);
|
|
129
|
+
}
|
|
130
|
+
setPrev({ ...current, chartPhase: transition.nextPhase });
|
|
131
|
+
}
|
|
132
|
+
const plotData = resolvePlotData(
|
|
133
|
+
chartPhase,
|
|
134
|
+
chartStatus,
|
|
135
|
+
skeletonData,
|
|
136
|
+
targetData
|
|
137
|
+
);
|
|
138
|
+
const notifyLoadingPulseComplete = useCallback(() => {
|
|
139
|
+
setChartPhase((phase) => phase === "exiting" ? "gridTweenReady" : phase);
|
|
140
|
+
}, []);
|
|
141
|
+
const notifyRevealConcealComplete = useCallback(() => {
|
|
142
|
+
setChartPhase(
|
|
143
|
+
(phase) => phase === "exitingReady" ? "gridTweenLoading" : phase
|
|
144
|
+
);
|
|
145
|
+
}, []);
|
|
146
|
+
const notifyYDomainTweenComplete = useCallback(() => {
|
|
147
|
+
setChartPhase((phase) => {
|
|
148
|
+
if (phase === "gridTweenLoading") {
|
|
149
|
+
return "loading";
|
|
150
|
+
}
|
|
151
|
+
if (phase === "gridTweenReady") {
|
|
152
|
+
return "revealing";
|
|
153
|
+
}
|
|
154
|
+
return phase;
|
|
155
|
+
});
|
|
156
|
+
}, []);
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (chartPhase !== "revealing") {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const timer = window.setTimeout(
|
|
162
|
+
() => {
|
|
163
|
+
setChartPhase("ready");
|
|
164
|
+
setIsLoaded(true);
|
|
165
|
+
},
|
|
166
|
+
Math.max(0, animationDuration)
|
|
167
|
+
);
|
|
168
|
+
return () => window.clearTimeout(timer);
|
|
169
|
+
}, [animationDuration, chartPhase]);
|
|
170
|
+
return {
|
|
171
|
+
chartPhase,
|
|
172
|
+
plotData,
|
|
173
|
+
revealEpoch,
|
|
174
|
+
concealEpoch,
|
|
175
|
+
isLoaded,
|
|
176
|
+
notifyLoadingPulseComplete,
|
|
177
|
+
notifyRevealConcealComplete,
|
|
178
|
+
notifyYDomainTweenComplete
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
export {
|
|
182
|
+
useChartPhaseOrchestrator
|
|
183
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useState, useSyncExternalStore } from "react";
|
|
3
|
+
function useEnterComplete(mountProgress) {
|
|
4
|
+
const subscribe = useCallback(
|
|
5
|
+
(onStoreChange) => mountProgress.on("change", onStoreChange),
|
|
6
|
+
[mountProgress]
|
|
7
|
+
);
|
|
8
|
+
const getSnapshot = () => mountProgress.get() >= 1;
|
|
9
|
+
const reachedEnd = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
10
|
+
const [latched, setLatched] = useState(reachedEnd);
|
|
11
|
+
if (reachedEnd && !latched) {
|
|
12
|
+
setLatched(true);
|
|
13
|
+
}
|
|
14
|
+
return latched || reachedEnd;
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
useEnterComplete
|
|
18
|
+
};
|