@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,88 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
animate,
|
|
4
|
+
useMotionValue,
|
|
5
|
+
useReducedMotion,
|
|
6
|
+
useTransform
|
|
7
|
+
} from "motion/react";
|
|
8
|
+
import { useEffect } from "react";
|
|
9
|
+
import {
|
|
10
|
+
LINE_LOADING_LOOP_PAUSE_MS,
|
|
11
|
+
LINE_LOADING_PULSE_CYCLE_S,
|
|
12
|
+
LINE_LOADING_PULSE_EASE
|
|
13
|
+
} from "./line-loading-timing";
|
|
14
|
+
function useGridShimmer({
|
|
15
|
+
innerWidth,
|
|
16
|
+
shimmer,
|
|
17
|
+
shimmerLength,
|
|
18
|
+
shimmerSpeed,
|
|
19
|
+
shimmerSync,
|
|
20
|
+
active,
|
|
21
|
+
oneShot = false
|
|
22
|
+
}) {
|
|
23
|
+
const progress = useMotionValue(0);
|
|
24
|
+
const reducedMotion = useReducedMotion();
|
|
25
|
+
const shimmerCycleS = LINE_LOADING_PULSE_CYCLE_S / Math.max(shimmerSpeed, 0.1);
|
|
26
|
+
const shimmerEnabled = active && shimmer && reducedMotion !== true && innerWidth > 0;
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (!shimmerEnabled) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let cancelled = false;
|
|
32
|
+
let timeoutId;
|
|
33
|
+
let controls;
|
|
34
|
+
const runSyncedCycle = () => {
|
|
35
|
+
if (cancelled) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
progress.set(0);
|
|
39
|
+
controls = animate(progress, 1, {
|
|
40
|
+
duration: shimmerCycleS,
|
|
41
|
+
ease: [...LINE_LOADING_PULSE_EASE],
|
|
42
|
+
onComplete: () => {
|
|
43
|
+
if (cancelled) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
timeoutId = window.setTimeout(
|
|
47
|
+
runSyncedCycle,
|
|
48
|
+
LINE_LOADING_LOOP_PAUSE_MS
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
if (shimmerSync && oneShot) {
|
|
54
|
+
progress.set(0);
|
|
55
|
+
controls = animate(progress, 1, {
|
|
56
|
+
duration: shimmerCycleS / 2,
|
|
57
|
+
ease: [...LINE_LOADING_PULSE_EASE]
|
|
58
|
+
});
|
|
59
|
+
return () => controls?.stop();
|
|
60
|
+
}
|
|
61
|
+
if (shimmerSync) {
|
|
62
|
+
runSyncedCycle();
|
|
63
|
+
return () => {
|
|
64
|
+
cancelled = true;
|
|
65
|
+
controls?.stop();
|
|
66
|
+
if (timeoutId !== void 0) {
|
|
67
|
+
window.clearTimeout(timeoutId);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
progress.set(0);
|
|
72
|
+
controls = animate(progress, 1, {
|
|
73
|
+
duration: shimmerCycleS,
|
|
74
|
+
repeat: Number.POSITIVE_INFINITY,
|
|
75
|
+
ease: [...LINE_LOADING_PULSE_EASE]
|
|
76
|
+
});
|
|
77
|
+
return () => controls?.stop();
|
|
78
|
+
}, [oneShot, progress, shimmerCycleS, shimmerEnabled, shimmerSync]);
|
|
79
|
+
const shimmerX = useTransform(
|
|
80
|
+
progress,
|
|
81
|
+
(value) => -shimmerLength + value * (innerWidth + shimmerLength * 2)
|
|
82
|
+
);
|
|
83
|
+
const shimmerTransform = useTransform(shimmerX, (x) => `translate(${x}, 0)`);
|
|
84
|
+
return { shimmerEnabled, shimmerTransform };
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
useGridShimmer
|
|
88
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useSpring } from "motion/react";
|
|
3
|
+
import { useCallback, useLayoutEffect, useRef } from "react";
|
|
4
|
+
import { useChartConfig } from "./chart-config-context";
|
|
5
|
+
import {
|
|
6
|
+
DISCRETE_INTERACTION_LABEL_THRESHOLD,
|
|
7
|
+
useChartHoverSelector,
|
|
8
|
+
useChartHoverStore,
|
|
9
|
+
useChartStable
|
|
10
|
+
} from "./chart-context";
|
|
11
|
+
import {
|
|
12
|
+
computeSegmentBounds,
|
|
13
|
+
INACTIVE_SEGMENT
|
|
14
|
+
} from "./highlight-segment-bounds";
|
|
15
|
+
function useHighlightSegment({
|
|
16
|
+
enabled = true,
|
|
17
|
+
span = 1
|
|
18
|
+
} = {}) {
|
|
19
|
+
const { data, xScale, xAccessor, dateLabels } = useChartStable();
|
|
20
|
+
const snap = dateLabels.length > DISCRETE_INTERACTION_LABEL_THRESHOLD;
|
|
21
|
+
const store = useChartHoverStore();
|
|
22
|
+
const { highlightSpring } = useChartConfig();
|
|
23
|
+
const resolveBounds = useCallback(
|
|
24
|
+
(hover) => enabled ? computeSegmentBounds(
|
|
25
|
+
data,
|
|
26
|
+
xScale,
|
|
27
|
+
xAccessor,
|
|
28
|
+
hover.tooltipData,
|
|
29
|
+
hover.selection,
|
|
30
|
+
span
|
|
31
|
+
) : INACTIVE_SEGMENT,
|
|
32
|
+
[enabled, data, xScale, xAccessor, span]
|
|
33
|
+
);
|
|
34
|
+
const isActive = useChartHoverSelector(
|
|
35
|
+
(hover) => resolveBounds(hover).isActive
|
|
36
|
+
);
|
|
37
|
+
const xSpring = useSpring(0, highlightSpring);
|
|
38
|
+
const widthSpring = useSpring(0, highlightSpring);
|
|
39
|
+
const wasActive = useRef(false);
|
|
40
|
+
useLayoutEffect(() => {
|
|
41
|
+
if (!store) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const drive = () => {
|
|
45
|
+
const bounds = resolveBounds(store.getSnapshot());
|
|
46
|
+
if (!bounds.isActive) {
|
|
47
|
+
wasActive.current = false;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (!wasActive.current || snap) {
|
|
51
|
+
xSpring.jump(bounds.x);
|
|
52
|
+
widthSpring.jump(bounds.width);
|
|
53
|
+
}
|
|
54
|
+
xSpring.set(bounds.x);
|
|
55
|
+
widthSpring.set(bounds.width);
|
|
56
|
+
wasActive.current = true;
|
|
57
|
+
};
|
|
58
|
+
drive();
|
|
59
|
+
return store.subscribe(drive);
|
|
60
|
+
}, [resolveBounds, snap, store, xSpring, widthSpring]);
|
|
61
|
+
return { xSpring, widthSpring, isActive };
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
useHighlightSegment
|
|
65
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { animate, useMotionValue } from "motion/react";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
import { DEFAULT_CHART_ENTER_TRANSITION } from "./animation";
|
|
5
|
+
function useMountProgress(enterTransition, delaySeconds, replayKey) {
|
|
6
|
+
const progress = useMotionValue(0);
|
|
7
|
+
const transitionRef = useRef(enterTransition);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
transitionRef.current = enterTransition;
|
|
10
|
+
});
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
progress.set(0);
|
|
13
|
+
const controls = animate(progress, 1, {
|
|
14
|
+
...transitionRef.current ?? DEFAULT_CHART_ENTER_TRANSITION,
|
|
15
|
+
delay: delaySeconds
|
|
16
|
+
});
|
|
17
|
+
return () => controls.stop();
|
|
18
|
+
}, [delaySeconds, replayKey, progress]);
|
|
19
|
+
return progress;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
useMountProgress
|
|
23
|
+
};
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useMemo, useRef, useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
scatterJitterOffset
|
|
5
|
+
} from "./scatter-jitter";
|
|
6
|
+
import { localPointFromSvg } from "./scatter-svg";
|
|
7
|
+
import { useScheduledTooltip } from "./use-scheduled-tooltip";
|
|
8
|
+
import { normalizeYAxisId } from "./y-axis-scales";
|
|
9
|
+
function useScatterChartInteraction({
|
|
10
|
+
xScale,
|
|
11
|
+
yScale,
|
|
12
|
+
yScales,
|
|
13
|
+
data,
|
|
14
|
+
lines,
|
|
15
|
+
margin,
|
|
16
|
+
xAccessor,
|
|
17
|
+
bisectDate,
|
|
18
|
+
canInteract,
|
|
19
|
+
jitter = null
|
|
20
|
+
}) {
|
|
21
|
+
const [selection, setSelection] = useState(null);
|
|
22
|
+
const {
|
|
23
|
+
tooltipData,
|
|
24
|
+
setTooltipData,
|
|
25
|
+
scheduleTooltip,
|
|
26
|
+
clearTooltip,
|
|
27
|
+
resetTooltipDedupe
|
|
28
|
+
} = useScheduledTooltip();
|
|
29
|
+
const isDraggingRef = useRef(false);
|
|
30
|
+
const dragStartXRef = useRef(0);
|
|
31
|
+
const resolveTooltipFromX = useCallback(
|
|
32
|
+
(pixelX) => {
|
|
33
|
+
const x0 = xScale.invert(pixelX);
|
|
34
|
+
const index = bisectDate(data, x0, 1);
|
|
35
|
+
const d0 = data[index - 1];
|
|
36
|
+
const d1 = data[index];
|
|
37
|
+
if (!d0) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
let d = d0;
|
|
41
|
+
let finalIndex = index - 1;
|
|
42
|
+
if (d1) {
|
|
43
|
+
const d0Time = xAccessor(d0).getTime();
|
|
44
|
+
const d1Time = xAccessor(d1).getTime();
|
|
45
|
+
if (x0.getTime() - d0Time > d1Time - x0.getTime()) {
|
|
46
|
+
d = d1;
|
|
47
|
+
finalIndex = index;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const yPositions = {};
|
|
51
|
+
for (const line of lines) {
|
|
52
|
+
const value = d[line.dataKey];
|
|
53
|
+
if (typeof value === "number") {
|
|
54
|
+
const axisScale = yScales[normalizeYAxisId(line.yAxisId)] ?? yScale;
|
|
55
|
+
yPositions[line.dataKey] = axisScale(value) ?? 0;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
point: d,
|
|
60
|
+
index: finalIndex,
|
|
61
|
+
x: xScale(xAccessor(d)) ?? 0,
|
|
62
|
+
yPositions
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
[xScale, yScale, yScales, data, lines, xAccessor, bisectDate]
|
|
66
|
+
);
|
|
67
|
+
const jitteredPoints = useMemo(() => {
|
|
68
|
+
if (!jitter) {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
const points = [];
|
|
72
|
+
for (const [seriesIndex, line] of lines.entries()) {
|
|
73
|
+
const axisScale = yScales[normalizeYAxisId(line.yAxisId)] ?? yScale;
|
|
74
|
+
for (const [index, d] of data.entries()) {
|
|
75
|
+
const value = d[line.dataKey];
|
|
76
|
+
if (typeof value !== "number") {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const offset = scatterJitterOffset(jitter, index, seriesIndex);
|
|
80
|
+
points.push({
|
|
81
|
+
index,
|
|
82
|
+
dataKey: line.dataKey,
|
|
83
|
+
x: (xScale(xAccessor(d)) ?? 0) + offset.x,
|
|
84
|
+
y: (axisScale(value) ?? 0) + offset.y
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return points;
|
|
89
|
+
}, [jitter, lines, data, xScale, xAccessor, yScale, yScales]);
|
|
90
|
+
const resolveTooltipFromPoint = useCallback(
|
|
91
|
+
(pixelX, pixelY) => {
|
|
92
|
+
if (!jitter || jitteredPoints.length === 0) {
|
|
93
|
+
return resolveTooltipFromX(pixelX);
|
|
94
|
+
}
|
|
95
|
+
let nearest = null;
|
|
96
|
+
let nearestDistance = Number.POSITIVE_INFINITY;
|
|
97
|
+
for (const point of jitteredPoints) {
|
|
98
|
+
const dx = point.x - pixelX;
|
|
99
|
+
const dy = point.y - pixelY;
|
|
100
|
+
const distance = dx * dx + dy * dy;
|
|
101
|
+
if (distance < nearestDistance) {
|
|
102
|
+
nearestDistance = distance;
|
|
103
|
+
nearest = point;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (!nearest) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
const d = data[nearest.index];
|
|
110
|
+
if (!d) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
const xPositions = {};
|
|
114
|
+
const yPositions = {};
|
|
115
|
+
const baseX = xScale(xAccessor(d)) ?? 0;
|
|
116
|
+
for (const [seriesIndex, line] of lines.entries()) {
|
|
117
|
+
const value = d[line.dataKey];
|
|
118
|
+
if (typeof value !== "number") {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const axisScale = yScales[normalizeYAxisId(line.yAxisId)] ?? yScale;
|
|
122
|
+
const offset = scatterJitterOffset(jitter, nearest.index, seriesIndex);
|
|
123
|
+
xPositions[line.dataKey] = baseX + offset.x;
|
|
124
|
+
yPositions[line.dataKey] = (axisScale(value) ?? 0) + offset.y;
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
point: d,
|
|
128
|
+
index: nearest.index,
|
|
129
|
+
x: baseX,
|
|
130
|
+
xPositions,
|
|
131
|
+
yPositions,
|
|
132
|
+
activeDataKey: nearest.dataKey
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
[
|
|
136
|
+
jitter,
|
|
137
|
+
jitteredPoints,
|
|
138
|
+
resolveTooltipFromX,
|
|
139
|
+
data,
|
|
140
|
+
lines,
|
|
141
|
+
xScale,
|
|
142
|
+
xAccessor,
|
|
143
|
+
yScale,
|
|
144
|
+
yScales
|
|
145
|
+
]
|
|
146
|
+
);
|
|
147
|
+
const resolveIndexFromX = useCallback(
|
|
148
|
+
(pixelX) => {
|
|
149
|
+
const x0 = xScale.invert(pixelX);
|
|
150
|
+
const index = bisectDate(data, x0, 1);
|
|
151
|
+
const d0 = data[index - 1];
|
|
152
|
+
const d1 = data[index];
|
|
153
|
+
if (!d0) {
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
if (d1) {
|
|
157
|
+
const d0Time = xAccessor(d0).getTime();
|
|
158
|
+
const d1Time = xAccessor(d1).getTime();
|
|
159
|
+
if (x0.getTime() - d0Time > d1Time - x0.getTime()) {
|
|
160
|
+
return index;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return index - 1;
|
|
164
|
+
},
|
|
165
|
+
[xScale, data, xAccessor, bisectDate]
|
|
166
|
+
);
|
|
167
|
+
const getChartPoint = useCallback(
|
|
168
|
+
(event, touchIndex = 0) => {
|
|
169
|
+
const svg = event.currentTarget.ownerSVGElement;
|
|
170
|
+
let clientX;
|
|
171
|
+
let clientY;
|
|
172
|
+
if ("touches" in event) {
|
|
173
|
+
const touch = event.touches[touchIndex];
|
|
174
|
+
if (!touch) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
clientX = touch.clientX;
|
|
178
|
+
clientY = touch.clientY;
|
|
179
|
+
} else {
|
|
180
|
+
clientX = event.clientX;
|
|
181
|
+
clientY = event.clientY;
|
|
182
|
+
}
|
|
183
|
+
const point = localPointFromSvg(svg, clientX, clientY);
|
|
184
|
+
if (!point) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
return { x: point.x - margin.left, y: point.y - margin.top };
|
|
188
|
+
},
|
|
189
|
+
[margin.left, margin.top]
|
|
190
|
+
);
|
|
191
|
+
const getChartX = useCallback(
|
|
192
|
+
(event, touchIndex = 0) => getChartPoint(event, touchIndex)?.x ?? null,
|
|
193
|
+
[getChartPoint]
|
|
194
|
+
);
|
|
195
|
+
const handleMouseMove = useCallback(
|
|
196
|
+
(event) => {
|
|
197
|
+
const chartX = getChartX(event);
|
|
198
|
+
if (chartX === null) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (isDraggingRef.current) {
|
|
202
|
+
const startX = Math.min(dragStartXRef.current, chartX);
|
|
203
|
+
const endX = Math.max(dragStartXRef.current, chartX);
|
|
204
|
+
setSelection({
|
|
205
|
+
startX,
|
|
206
|
+
endX,
|
|
207
|
+
startIndex: resolveIndexFromX(startX),
|
|
208
|
+
endIndex: resolveIndexFromX(endX),
|
|
209
|
+
active: true
|
|
210
|
+
});
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const chartPoint = getChartPoint(event);
|
|
214
|
+
const tooltip = chartPoint ? resolveTooltipFromPoint(chartPoint.x, chartPoint.y) : null;
|
|
215
|
+
if (tooltip) {
|
|
216
|
+
scheduleTooltip(tooltip);
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
[
|
|
220
|
+
getChartX,
|
|
221
|
+
getChartPoint,
|
|
222
|
+
resolveTooltipFromPoint,
|
|
223
|
+
resolveIndexFromX,
|
|
224
|
+
scheduleTooltip
|
|
225
|
+
]
|
|
226
|
+
);
|
|
227
|
+
const handleMouseLeave = useCallback(() => {
|
|
228
|
+
clearTooltip();
|
|
229
|
+
if (isDraggingRef.current) {
|
|
230
|
+
isDraggingRef.current = false;
|
|
231
|
+
}
|
|
232
|
+
setSelection(null);
|
|
233
|
+
}, [clearTooltip]);
|
|
234
|
+
const handleMouseDown = useCallback(
|
|
235
|
+
(event) => {
|
|
236
|
+
const chartX = getChartX(event);
|
|
237
|
+
if (chartX === null) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
isDraggingRef.current = true;
|
|
241
|
+
dragStartXRef.current = chartX;
|
|
242
|
+
clearTooltip();
|
|
243
|
+
setSelection(null);
|
|
244
|
+
},
|
|
245
|
+
[getChartX, clearTooltip]
|
|
246
|
+
);
|
|
247
|
+
const handleMouseUp = useCallback(() => {
|
|
248
|
+
if (isDraggingRef.current) {
|
|
249
|
+
isDraggingRef.current = false;
|
|
250
|
+
}
|
|
251
|
+
setSelection(null);
|
|
252
|
+
}, []);
|
|
253
|
+
const handleTouchStart = useCallback(
|
|
254
|
+
(event) => {
|
|
255
|
+
if (event.touches.length === 1) {
|
|
256
|
+
event.preventDefault();
|
|
257
|
+
const chartPoint = getChartPoint(event, 0);
|
|
258
|
+
if (chartPoint === null) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const tooltip = resolveTooltipFromPoint(chartPoint.x, chartPoint.y);
|
|
262
|
+
if (tooltip) {
|
|
263
|
+
scheduleTooltip(tooltip);
|
|
264
|
+
}
|
|
265
|
+
} else if (event.touches.length === 2) {
|
|
266
|
+
event.preventDefault();
|
|
267
|
+
resetTooltipDedupe();
|
|
268
|
+
clearTooltip();
|
|
269
|
+
const x0 = getChartX(event, 0);
|
|
270
|
+
const x1 = getChartX(event, 1);
|
|
271
|
+
if (x0 === null || x1 === null) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const startX = Math.min(x0, x1);
|
|
275
|
+
const endX = Math.max(x0, x1);
|
|
276
|
+
setSelection({
|
|
277
|
+
startX,
|
|
278
|
+
endX,
|
|
279
|
+
startIndex: resolveIndexFromX(startX),
|
|
280
|
+
endIndex: resolveIndexFromX(endX),
|
|
281
|
+
active: true
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
[
|
|
286
|
+
getChartX,
|
|
287
|
+
getChartPoint,
|
|
288
|
+
resolveTooltipFromPoint,
|
|
289
|
+
resolveIndexFromX,
|
|
290
|
+
scheduleTooltip,
|
|
291
|
+
resetTooltipDedupe,
|
|
292
|
+
clearTooltip
|
|
293
|
+
]
|
|
294
|
+
);
|
|
295
|
+
const handleTouchMove = useCallback(
|
|
296
|
+
(event) => {
|
|
297
|
+
if (event.touches.length === 1) {
|
|
298
|
+
event.preventDefault();
|
|
299
|
+
const chartPoint = getChartPoint(event, 0);
|
|
300
|
+
if (chartPoint === null) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
const tooltip = resolveTooltipFromPoint(chartPoint.x, chartPoint.y);
|
|
304
|
+
if (tooltip) {
|
|
305
|
+
scheduleTooltip(tooltip);
|
|
306
|
+
}
|
|
307
|
+
} else if (event.touches.length === 2) {
|
|
308
|
+
event.preventDefault();
|
|
309
|
+
const x0 = getChartX(event, 0);
|
|
310
|
+
const x1 = getChartX(event, 1);
|
|
311
|
+
if (x0 === null || x1 === null) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const startX = Math.min(x0, x1);
|
|
315
|
+
const endX = Math.max(x0, x1);
|
|
316
|
+
setSelection({
|
|
317
|
+
startX,
|
|
318
|
+
endX,
|
|
319
|
+
startIndex: resolveIndexFromX(startX),
|
|
320
|
+
endIndex: resolveIndexFromX(endX),
|
|
321
|
+
active: true
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
[
|
|
326
|
+
getChartX,
|
|
327
|
+
getChartPoint,
|
|
328
|
+
resolveTooltipFromPoint,
|
|
329
|
+
resolveIndexFromX,
|
|
330
|
+
scheduleTooltip
|
|
331
|
+
]
|
|
332
|
+
);
|
|
333
|
+
const handleTouchEnd = useCallback(() => {
|
|
334
|
+
clearTooltip();
|
|
335
|
+
setSelection(null);
|
|
336
|
+
}, [clearTooltip]);
|
|
337
|
+
const clearSelection = useCallback(() => {
|
|
338
|
+
setSelection(null);
|
|
339
|
+
}, []);
|
|
340
|
+
const interactionHandlers = canInteract ? {
|
|
341
|
+
onMouseMove: handleMouseMove,
|
|
342
|
+
onMouseLeave: handleMouseLeave,
|
|
343
|
+
onMouseDown: handleMouseDown,
|
|
344
|
+
onMouseUp: handleMouseUp,
|
|
345
|
+
onTouchStart: handleTouchStart,
|
|
346
|
+
onTouchMove: handleTouchMove,
|
|
347
|
+
onTouchEnd: handleTouchEnd
|
|
348
|
+
} : {};
|
|
349
|
+
const interactionStyle = {
|
|
350
|
+
cursor: canInteract ? "crosshair" : "default",
|
|
351
|
+
touchAction: "none"
|
|
352
|
+
};
|
|
353
|
+
return {
|
|
354
|
+
tooltipData,
|
|
355
|
+
setTooltipData,
|
|
356
|
+
selection,
|
|
357
|
+
clearSelection,
|
|
358
|
+
interactionHandlers,
|
|
359
|
+
interactionStyle
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
export {
|
|
363
|
+
useScatterChartInteraction
|
|
364
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { flushSync } from "react-dom";
|
|
4
|
+
function defaultDedupeKey(tooltip) {
|
|
5
|
+
if (typeof tooltip === "object" && tooltip !== null && "index" in tooltip && typeof tooltip.index === "number") {
|
|
6
|
+
const { index, x, activeDataKey } = tooltip;
|
|
7
|
+
const suffix = activeDataKey === void 0 ? "" : `:${activeDataKey}`;
|
|
8
|
+
if (typeof x === "number") {
|
|
9
|
+
return `${index}:${Math.round(x)}${suffix}`;
|
|
10
|
+
}
|
|
11
|
+
return `${index}${suffix}`;
|
|
12
|
+
}
|
|
13
|
+
return JSON.stringify(tooltip);
|
|
14
|
+
}
|
|
15
|
+
function useScheduledTooltip(setExternal) {
|
|
16
|
+
const [tooltipData, setLocalTooltipData] = useState(null);
|
|
17
|
+
const setTooltipData = setExternal ?? setLocalTooltipData;
|
|
18
|
+
const lastKeyRef = useRef(null);
|
|
19
|
+
const pendingRef = useRef(null);
|
|
20
|
+
const rafRef = useRef(null);
|
|
21
|
+
const pendingKeyRef = useRef(null);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
return () => {
|
|
24
|
+
if (rafRef.current !== null) {
|
|
25
|
+
cancelAnimationFrame(rafRef.current);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}, []);
|
|
29
|
+
const commitTooltip = useCallback(
|
|
30
|
+
(tooltip, dedupeKey) => {
|
|
31
|
+
if (dedupeKey === lastKeyRef.current) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
lastKeyRef.current = dedupeKey;
|
|
35
|
+
setTooltipData(tooltip);
|
|
36
|
+
},
|
|
37
|
+
[setTooltipData]
|
|
38
|
+
);
|
|
39
|
+
const scheduleTooltip = useCallback(
|
|
40
|
+
(tooltip, dedupeKey) => {
|
|
41
|
+
const key = dedupeKey ?? defaultDedupeKey(tooltip);
|
|
42
|
+
pendingRef.current = tooltip;
|
|
43
|
+
pendingKeyRef.current = key;
|
|
44
|
+
if (key === lastKeyRef.current) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (rafRef.current !== null) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
rafRef.current = requestAnimationFrame(() => {
|
|
51
|
+
rafRef.current = null;
|
|
52
|
+
const next = pendingRef.current;
|
|
53
|
+
const nextKey = pendingKeyRef.current;
|
|
54
|
+
if (next && nextKey) {
|
|
55
|
+
flushSync(() => commitTooltip(next, nextKey));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
[commitTooltip]
|
|
60
|
+
);
|
|
61
|
+
const clearTooltip = useCallback(() => {
|
|
62
|
+
if (rafRef.current !== null) {
|
|
63
|
+
cancelAnimationFrame(rafRef.current);
|
|
64
|
+
rafRef.current = null;
|
|
65
|
+
}
|
|
66
|
+
pendingRef.current = null;
|
|
67
|
+
pendingKeyRef.current = null;
|
|
68
|
+
lastKeyRef.current = null;
|
|
69
|
+
setTooltipData(null);
|
|
70
|
+
}, [setTooltipData]);
|
|
71
|
+
const resetTooltipDedupe = useCallback(() => {
|
|
72
|
+
lastKeyRef.current = null;
|
|
73
|
+
}, []);
|
|
74
|
+
return {
|
|
75
|
+
tooltipData,
|
|
76
|
+
setTooltipData,
|
|
77
|
+
scheduleTooltip,
|
|
78
|
+
clearTooltip,
|
|
79
|
+
resetTooltipDedupe
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
useScheduledTooltip
|
|
84
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
PatternCircles as VisxPatternCircles,
|
|
5
|
+
PatternHexagons as VisxPatternHexagons,
|
|
6
|
+
PatternLines as VisxPatternLines,
|
|
7
|
+
PatternWaves as VisxPatternWaves
|
|
8
|
+
} from "./patterns/index";
|
|
9
|
+
function PatternLines(props) {
|
|
10
|
+
return /* @__PURE__ */ jsx(VisxPatternLines, { ...props });
|
|
11
|
+
}
|
|
12
|
+
PatternLines.displayName = "PatternLines";
|
|
13
|
+
function PatternCircles(props) {
|
|
14
|
+
return /* @__PURE__ */ jsx(VisxPatternCircles, { ...props });
|
|
15
|
+
}
|
|
16
|
+
PatternCircles.displayName = "PatternCircles";
|
|
17
|
+
function PatternWaves(props) {
|
|
18
|
+
return /* @__PURE__ */ jsx(VisxPatternWaves, { ...props });
|
|
19
|
+
}
|
|
20
|
+
PatternWaves.displayName = "PatternWaves";
|
|
21
|
+
function PatternHexagons(props) {
|
|
22
|
+
return /* @__PURE__ */ jsx(VisxPatternHexagons, { ...props });
|
|
23
|
+
}
|
|
24
|
+
PatternHexagons.displayName = "PatternHexagons";
|
|
25
|
+
export {
|
|
26
|
+
PatternCircles,
|
|
27
|
+
PatternHexagons,
|
|
28
|
+
PatternLines,
|
|
29
|
+
PatternWaves
|
|
30
|
+
};
|