@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,279 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { bisector } from "d3-array";
|
|
4
|
+
import { scaleLinear, scaleTime } from "d3-scale";
|
|
5
|
+
import {
|
|
6
|
+
Children,
|
|
7
|
+
isValidElement,
|
|
8
|
+
useCallback,
|
|
9
|
+
useEffect,
|
|
10
|
+
useMemo,
|
|
11
|
+
useState
|
|
12
|
+
} from "react";
|
|
13
|
+
import { DEFAULT_ANIMATION_EASING } from "./animation";
|
|
14
|
+
import {
|
|
15
|
+
isClipExcludedComponent,
|
|
16
|
+
isPostOverlayComponent,
|
|
17
|
+
isUnderlayComponent,
|
|
18
|
+
resolveLazyChartChild
|
|
19
|
+
} from "./chart-child-passthrough";
|
|
20
|
+
import {
|
|
21
|
+
ChartProvider
|
|
22
|
+
} from "./chart-context";
|
|
23
|
+
import { isGradientDefComponent, isPatternDefComponent } from "./chart-defs";
|
|
24
|
+
import { lazyLabels, shortDateFmt } from "./chart-formatters";
|
|
25
|
+
import { DEFAULT_CHART_LIFECYCLE } from "./chart-phase";
|
|
26
|
+
import { extractReferenceAreaConfigs } from "./reference-area-config";
|
|
27
|
+
import {
|
|
28
|
+
minDistinctStepRatio,
|
|
29
|
+
ScatterJitterContext,
|
|
30
|
+
scatterJitterRangePadding
|
|
31
|
+
} from "./scatter-jitter";
|
|
32
|
+
import { useScatterChartInteraction } from "./use-scatter-chart-interaction";
|
|
33
|
+
import { buildYScalesForLines, getPrimaryYScale } from "./y-axis-scales";
|
|
34
|
+
function ScatterChartInner({
|
|
35
|
+
width,
|
|
36
|
+
height,
|
|
37
|
+
data,
|
|
38
|
+
xDataKey,
|
|
39
|
+
margin,
|
|
40
|
+
animationDuration,
|
|
41
|
+
animationEasing = DEFAULT_ANIMATION_EASING,
|
|
42
|
+
enterTransition,
|
|
43
|
+
revealSignature = "",
|
|
44
|
+
children,
|
|
45
|
+
containerRef,
|
|
46
|
+
lines,
|
|
47
|
+
jitter = null,
|
|
48
|
+
formatXLabel,
|
|
49
|
+
onPhaseChange
|
|
50
|
+
}) {
|
|
51
|
+
const [isLoaded, setIsLoaded] = useState(() => animationDuration <= 0);
|
|
52
|
+
const [revealEpoch, setRevealEpoch] = useState(1);
|
|
53
|
+
const innerWidth = width - margin.left - margin.right;
|
|
54
|
+
const innerHeight = height - margin.top - margin.bottom;
|
|
55
|
+
const xAccessor = useCallback(
|
|
56
|
+
(d) => {
|
|
57
|
+
const value = d[xDataKey];
|
|
58
|
+
return value instanceof Date ? value : new Date(value);
|
|
59
|
+
},
|
|
60
|
+
[xDataKey]
|
|
61
|
+
);
|
|
62
|
+
const bisectDate = useMemo(
|
|
63
|
+
() => bisector((d) => xAccessor(d)).left,
|
|
64
|
+
[xAccessor]
|
|
65
|
+
);
|
|
66
|
+
const baseRangePadding = useMemo(() => {
|
|
67
|
+
if (lines.length === 0) {
|
|
68
|
+
return 12;
|
|
69
|
+
}
|
|
70
|
+
const maxRadius = Math.max(...lines.map((line) => line.strokeWidth ?? 5));
|
|
71
|
+
return maxRadius + 10;
|
|
72
|
+
}, [lines]);
|
|
73
|
+
const stepRatio = useMemo(
|
|
74
|
+
() => jitter && jitter.x > 0 ? minDistinctStepRatio(data.map((d) => xAccessor(d).getTime())) : 0,
|
|
75
|
+
[data, jitter, xAccessor]
|
|
76
|
+
);
|
|
77
|
+
const xRangePadding = scatterJitterRangePadding(
|
|
78
|
+
baseRangePadding,
|
|
79
|
+
innerWidth,
|
|
80
|
+
stepRatio,
|
|
81
|
+
jitter?.x ?? 0
|
|
82
|
+
);
|
|
83
|
+
const xScale = useMemo(() => {
|
|
84
|
+
const dates = data.map((d) => xAccessor(d));
|
|
85
|
+
const minTime = Math.min(...dates.map((d) => d.getTime()));
|
|
86
|
+
const maxTime = Math.max(...dates.map((d) => d.getTime()));
|
|
87
|
+
return scaleTime().range([
|
|
88
|
+
xRangePadding,
|
|
89
|
+
Math.max(xRangePadding, innerWidth - xRangePadding)
|
|
90
|
+
]).domain([minTime, maxTime]);
|
|
91
|
+
}, [innerWidth, data, xAccessor, xRangePadding]);
|
|
92
|
+
const jitterOffsets = useMemo(() => {
|
|
93
|
+
if (!jitter) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const plotWidth = Math.max(0, innerWidth - 2 * xRangePadding);
|
|
97
|
+
return {
|
|
98
|
+
x: jitter.x / 2 * plotWidth * stepRatio,
|
|
99
|
+
y: jitter.y,
|
|
100
|
+
seed: jitter.seed
|
|
101
|
+
};
|
|
102
|
+
}, [jitter, innerWidth, xRangePadding, stepRatio]);
|
|
103
|
+
const columnWidth = useMemo(() => {
|
|
104
|
+
if (data.length < 2) {
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
return innerWidth / (data.length - 1);
|
|
108
|
+
}, [innerWidth, data.length]);
|
|
109
|
+
const yScales = useMemo(
|
|
110
|
+
() => buildYScalesForLines({
|
|
111
|
+
lines,
|
|
112
|
+
data,
|
|
113
|
+
innerHeight,
|
|
114
|
+
resolveDomain: (dataKeys) => {
|
|
115
|
+
let maxValue = 0;
|
|
116
|
+
for (const d of data) {
|
|
117
|
+
for (const key of dataKeys) {
|
|
118
|
+
const value = d[key];
|
|
119
|
+
if (typeof value === "number" && value > maxValue) {
|
|
120
|
+
maxValue = value;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const top = maxValue <= 0 ? 100 : maxValue * 1.1;
|
|
125
|
+
return [0, top];
|
|
126
|
+
}
|
|
127
|
+
}),
|
|
128
|
+
[innerHeight, data, lines]
|
|
129
|
+
);
|
|
130
|
+
const yScale = getPrimaryYScale(
|
|
131
|
+
yScales,
|
|
132
|
+
scaleLinear().range([innerHeight, 0]).domain([0, 100])
|
|
133
|
+
);
|
|
134
|
+
const dateLabels = useMemo(
|
|
135
|
+
() => lazyLabels(data.length, (index) => {
|
|
136
|
+
const date = xAccessor(data[index]);
|
|
137
|
+
return formatXLabel ? formatXLabel(date) : shortDateFmt.format(date);
|
|
138
|
+
}),
|
|
139
|
+
[data, xAccessor, formatXLabel]
|
|
140
|
+
);
|
|
141
|
+
const [revealKey, setRevealKey] = useState({
|
|
142
|
+
animationDuration,
|
|
143
|
+
revealSignature
|
|
144
|
+
});
|
|
145
|
+
if (revealKey.animationDuration !== animationDuration || revealKey.revealSignature !== revealSignature) {
|
|
146
|
+
setRevealKey({ animationDuration, revealSignature });
|
|
147
|
+
setRevealEpoch((n) => n + 1);
|
|
148
|
+
setIsLoaded(animationDuration <= 0);
|
|
149
|
+
}
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
const timer = setTimeout(() => {
|
|
152
|
+
setIsLoaded(true);
|
|
153
|
+
}, animationDuration);
|
|
154
|
+
return () => clearTimeout(timer);
|
|
155
|
+
}, [animationDuration, revealSignature]);
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
onPhaseChange?.(isLoaded ? "ready" : "revealing");
|
|
158
|
+
}, [isLoaded, onPhaseChange]);
|
|
159
|
+
const canInteract = isLoaded;
|
|
160
|
+
const {
|
|
161
|
+
tooltipData,
|
|
162
|
+
setTooltipData,
|
|
163
|
+
selection,
|
|
164
|
+
clearSelection,
|
|
165
|
+
interactionHandlers,
|
|
166
|
+
interactionStyle
|
|
167
|
+
} = useScatterChartInteraction({
|
|
168
|
+
xScale,
|
|
169
|
+
yScale,
|
|
170
|
+
yScales,
|
|
171
|
+
data,
|
|
172
|
+
lines,
|
|
173
|
+
margin,
|
|
174
|
+
xAccessor,
|
|
175
|
+
bisectDate,
|
|
176
|
+
canInteract,
|
|
177
|
+
jitter: jitterOffsets
|
|
178
|
+
});
|
|
179
|
+
const referenceAreas = useMemo(
|
|
180
|
+
() => extractReferenceAreaConfigs(children),
|
|
181
|
+
[children]
|
|
182
|
+
);
|
|
183
|
+
if (width < 10 || height < 10) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
const defsChildren = [];
|
|
187
|
+
const clipExcludedChildren = [];
|
|
188
|
+
const underlayChildren = [];
|
|
189
|
+
const preOverlayChildren = [];
|
|
190
|
+
const postOverlayChildren = [];
|
|
191
|
+
Children.forEach(children, (rawChild) => {
|
|
192
|
+
if (!isValidElement(rawChild)) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const child = resolveLazyChartChild(rawChild);
|
|
196
|
+
if (isGradientDefComponent(child)) {
|
|
197
|
+
defsChildren.push(child);
|
|
198
|
+
} else if (isPatternDefComponent(child)) {
|
|
199
|
+
preOverlayChildren.push(child);
|
|
200
|
+
} else if (isPostOverlayComponent(child)) {
|
|
201
|
+
postOverlayChildren.push(child);
|
|
202
|
+
} else if (isClipExcludedComponent(child)) {
|
|
203
|
+
clipExcludedChildren.push(child);
|
|
204
|
+
} else if (isUnderlayComponent(child)) {
|
|
205
|
+
underlayChildren.push(child);
|
|
206
|
+
} else {
|
|
207
|
+
preOverlayChildren.push(child);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
const contextValue = {
|
|
211
|
+
...DEFAULT_CHART_LIFECYCLE,
|
|
212
|
+
data,
|
|
213
|
+
renderData: data,
|
|
214
|
+
xScale,
|
|
215
|
+
yScale,
|
|
216
|
+
yScales,
|
|
217
|
+
width,
|
|
218
|
+
height,
|
|
219
|
+
innerWidth,
|
|
220
|
+
innerHeight,
|
|
221
|
+
margin,
|
|
222
|
+
columnWidth,
|
|
223
|
+
tooltipData,
|
|
224
|
+
setTooltipData,
|
|
225
|
+
containerRef,
|
|
226
|
+
lines,
|
|
227
|
+
referenceAreas,
|
|
228
|
+
isLoaded,
|
|
229
|
+
animationDuration,
|
|
230
|
+
animationEasing,
|
|
231
|
+
enterTransition,
|
|
232
|
+
revealEpoch,
|
|
233
|
+
xAccessor,
|
|
234
|
+
dateLabels,
|
|
235
|
+
selection,
|
|
236
|
+
clearSelection,
|
|
237
|
+
nearestPointHover: jitterOffsets !== null
|
|
238
|
+
};
|
|
239
|
+
return /* @__PURE__ */ jsx(ChartProvider, { value: contextValue, children: /* @__PURE__ */ jsx(ScatterJitterContext.Provider, { value: jitterOffsets, children: /* @__PURE__ */ jsxs(
|
|
240
|
+
"svg",
|
|
241
|
+
{
|
|
242
|
+
"aria-hidden": "true",
|
|
243
|
+
className: "overflow-visible",
|
|
244
|
+
height,
|
|
245
|
+
width,
|
|
246
|
+
children: [
|
|
247
|
+
defsChildren.length > 0 && /* @__PURE__ */ jsx("defs", { children: defsChildren }),
|
|
248
|
+
/* @__PURE__ */ jsx("rect", { fill: "transparent", height, width, x: 0, y: 0 }),
|
|
249
|
+
/* @__PURE__ */ jsxs(
|
|
250
|
+
"g",
|
|
251
|
+
{
|
|
252
|
+
...interactionHandlers,
|
|
253
|
+
style: interactionStyle,
|
|
254
|
+
transform: `translate(${margin.left},${margin.top})`,
|
|
255
|
+
children: [
|
|
256
|
+
/* @__PURE__ */ jsx(
|
|
257
|
+
"rect",
|
|
258
|
+
{
|
|
259
|
+
fill: "transparent",
|
|
260
|
+
height: innerHeight,
|
|
261
|
+
width: innerWidth,
|
|
262
|
+
x: 0,
|
|
263
|
+
y: 0
|
|
264
|
+
}
|
|
265
|
+
),
|
|
266
|
+
clipExcludedChildren,
|
|
267
|
+
underlayChildren,
|
|
268
|
+
preOverlayChildren,
|
|
269
|
+
postOverlayChildren
|
|
270
|
+
]
|
|
271
|
+
}
|
|
272
|
+
)
|
|
273
|
+
]
|
|
274
|
+
}
|
|
275
|
+
) }) });
|
|
276
|
+
}
|
|
277
|
+
export {
|
|
278
|
+
ScatterChartInner
|
|
279
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { domAnimation, LazyMotion } from "motion/react";
|
|
4
|
+
import {
|
|
5
|
+
Children,
|
|
6
|
+
isValidElement,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef
|
|
9
|
+
} from "react";
|
|
10
|
+
import { cn } from "../lib/utils";
|
|
11
|
+
import { DEFAULT_CHART_ENTER_TRANSITION } from "./animation";
|
|
12
|
+
import {
|
|
13
|
+
defaultScatterColors
|
|
14
|
+
} from "./chart-context";
|
|
15
|
+
import { useChartDataOverride } from "./chart-data-override";
|
|
16
|
+
import { useElementSize } from "./chart-parent-size";
|
|
17
|
+
import { Scatter } from "./scatter";
|
|
18
|
+
import { ScatterChartInner } from "./scatter-chart-shell";
|
|
19
|
+
import {
|
|
20
|
+
resolveScatterJitterConfig
|
|
21
|
+
} from "./scatter-jitter";
|
|
22
|
+
const DEFAULT_MARGIN = { top: 40, right: 40, bottom: 40, left: 40 };
|
|
23
|
+
function extractScatterConfigs(children) {
|
|
24
|
+
const configs = [];
|
|
25
|
+
let seriesIndex = 0;
|
|
26
|
+
Children.forEach(children, (child) => {
|
|
27
|
+
if (!isValidElement(child)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const childType = child.type;
|
|
31
|
+
const componentName = typeof child.type === "function" ? childType.displayName || childType.name || "" : "";
|
|
32
|
+
const props = child.props;
|
|
33
|
+
const isScatterComponent = componentName === "Scatter" || child.type === Scatter || props && typeof props.dataKey === "string" && props.dataKey.length > 0;
|
|
34
|
+
if (isScatterComponent && props?.dataKey) {
|
|
35
|
+
const seriesColor = defaultScatterColors[seriesIndex % defaultScatterColors.length] ?? defaultScatterColors[0];
|
|
36
|
+
configs.push({
|
|
37
|
+
dataKey: props.dataKey,
|
|
38
|
+
stroke: props.fill || props.stroke || seriesColor,
|
|
39
|
+
strokeWidth: props.radius ?? 5,
|
|
40
|
+
yAxisId: props.yAxisId
|
|
41
|
+
});
|
|
42
|
+
seriesIndex += 1;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return configs;
|
|
46
|
+
}
|
|
47
|
+
function ChartInner({
|
|
48
|
+
width,
|
|
49
|
+
height,
|
|
50
|
+
data,
|
|
51
|
+
xDataKey,
|
|
52
|
+
margin,
|
|
53
|
+
animationDuration,
|
|
54
|
+
animationEasing,
|
|
55
|
+
enterTransition,
|
|
56
|
+
revealSignature,
|
|
57
|
+
children,
|
|
58
|
+
containerRef,
|
|
59
|
+
jitter,
|
|
60
|
+
formatXLabel,
|
|
61
|
+
onPhaseChange
|
|
62
|
+
}) {
|
|
63
|
+
const lines = useMemo(() => extractScatterConfigs(children), [children]);
|
|
64
|
+
return /* @__PURE__ */ jsx(
|
|
65
|
+
ScatterChartInner,
|
|
66
|
+
{
|
|
67
|
+
animationDuration,
|
|
68
|
+
animationEasing,
|
|
69
|
+
containerRef,
|
|
70
|
+
data,
|
|
71
|
+
enterTransition,
|
|
72
|
+
formatXLabel,
|
|
73
|
+
height,
|
|
74
|
+
jitter,
|
|
75
|
+
lines,
|
|
76
|
+
margin,
|
|
77
|
+
onPhaseChange,
|
|
78
|
+
revealSignature,
|
|
79
|
+
width,
|
|
80
|
+
xDataKey,
|
|
81
|
+
children
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
function ScatterChart({
|
|
86
|
+
data: dataProp,
|
|
87
|
+
xDataKey = "date",
|
|
88
|
+
margin: marginProp,
|
|
89
|
+
animationDuration = 1100,
|
|
90
|
+
animationEasing,
|
|
91
|
+
enterTransition = DEFAULT_CHART_ENTER_TRANSITION,
|
|
92
|
+
revealSignature,
|
|
93
|
+
aspectRatio = "2 / 1",
|
|
94
|
+
className = "",
|
|
95
|
+
children,
|
|
96
|
+
jitter: jitterProp,
|
|
97
|
+
formatXLabel,
|
|
98
|
+
onPhaseChange
|
|
99
|
+
}) {
|
|
100
|
+
const { data } = useChartDataOverride("ScatterChart", {
|
|
101
|
+
data: dataProp
|
|
102
|
+
});
|
|
103
|
+
const containerRef = useRef(null);
|
|
104
|
+
const margin = { ...DEFAULT_MARGIN, ...marginProp };
|
|
105
|
+
const { width, height } = useElementSize(containerRef, 10);
|
|
106
|
+
const resolvedJitter = resolveScatterJitterConfig(jitterProp);
|
|
107
|
+
const hasJitter = resolvedJitter !== null;
|
|
108
|
+
const jitterX = resolvedJitter?.x ?? 0;
|
|
109
|
+
const jitterY = resolvedJitter?.y ?? 0;
|
|
110
|
+
const jitterSeed = resolvedJitter?.seed ?? 0;
|
|
111
|
+
const jitter = useMemo(
|
|
112
|
+
() => hasJitter ? { x: jitterX, y: jitterY, seed: jitterSeed } : null,
|
|
113
|
+
[hasJitter, jitterX, jitterY, jitterSeed]
|
|
114
|
+
);
|
|
115
|
+
return /* @__PURE__ */ jsx(LazyMotion, { features: domAnimation, children: /* @__PURE__ */ jsx(
|
|
116
|
+
"div",
|
|
117
|
+
{
|
|
118
|
+
className: cn("relative w-full", className),
|
|
119
|
+
ref: containerRef,
|
|
120
|
+
style: { aspectRatio, touchAction: "none" },
|
|
121
|
+
children: width > 0 && height > 0 ? /* @__PURE__ */ jsx(
|
|
122
|
+
ChartInner,
|
|
123
|
+
{
|
|
124
|
+
animationDuration,
|
|
125
|
+
animationEasing,
|
|
126
|
+
containerRef,
|
|
127
|
+
data,
|
|
128
|
+
enterTransition,
|
|
129
|
+
formatXLabel,
|
|
130
|
+
height,
|
|
131
|
+
jitter,
|
|
132
|
+
margin,
|
|
133
|
+
onPhaseChange,
|
|
134
|
+
revealSignature,
|
|
135
|
+
width,
|
|
136
|
+
xDataKey,
|
|
137
|
+
children
|
|
138
|
+
}
|
|
139
|
+
) : null
|
|
140
|
+
}
|
|
141
|
+
) });
|
|
142
|
+
}
|
|
143
|
+
ScatterChart.displayName = "ScatterChart";
|
|
144
|
+
import { Scatter as Scatter2 } from "./scatter";
|
|
145
|
+
var scatter_chart_default = ScatterChart;
|
|
146
|
+
export {
|
|
147
|
+
Scatter2 as Scatter,
|
|
148
|
+
ScatterChart,
|
|
149
|
+
scatter_chart_default as default
|
|
150
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
const DEFAULT_SCATTER_JITTER_X = 0.35;
|
|
4
|
+
function resolveScatterJitterConfig(jitter) {
|
|
5
|
+
if (jitter === void 0 || jitter === false) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
if (jitter === true) {
|
|
9
|
+
return { x: DEFAULT_SCATTER_JITTER_X, y: 0, seed: 0 };
|
|
10
|
+
}
|
|
11
|
+
if (typeof jitter === "number") {
|
|
12
|
+
return jitter > 0 ? { x: jitter, y: 0, seed: 0 } : null;
|
|
13
|
+
}
|
|
14
|
+
const x = Math.max(0, jitter.x ?? DEFAULT_SCATTER_JITTER_X);
|
|
15
|
+
const y = Math.max(0, jitter.y ?? 0);
|
|
16
|
+
if (x === 0 && y === 0) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return { x, y, seed: jitter.seed ?? 0 };
|
|
20
|
+
}
|
|
21
|
+
function minDistinctStepRatio(times) {
|
|
22
|
+
const distinct = [...new Set(times.filter(Number.isFinite))].sort(
|
|
23
|
+
(a, b) => a - b
|
|
24
|
+
);
|
|
25
|
+
if (distinct.length < 2) {
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
const first = distinct[0] ?? 0;
|
|
29
|
+
const last = distinct.at(-1) ?? 0;
|
|
30
|
+
const span = last - first;
|
|
31
|
+
if (span <= 0) {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
let minGap = Number.POSITIVE_INFINITY;
|
|
35
|
+
for (let i = 1; i < distinct.length; i++) {
|
|
36
|
+
const gap = (distinct[i] ?? 0) - (distinct[i - 1] ?? 0);
|
|
37
|
+
if (gap < minGap) {
|
|
38
|
+
minGap = gap;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return minGap / span;
|
|
42
|
+
}
|
|
43
|
+
function scatterJitterRangePadding(basePadding, innerWidth, stepRatio, jitterX) {
|
|
44
|
+
if (jitterX <= 0 || stepRatio <= 0) {
|
|
45
|
+
return basePadding;
|
|
46
|
+
}
|
|
47
|
+
return (basePadding + jitterX / 2 * innerWidth * stepRatio) / (1 + jitterX * stepRatio);
|
|
48
|
+
}
|
|
49
|
+
const HASH_MODULUS = 2147483647;
|
|
50
|
+
const HASH_SPLIT = 65536;
|
|
51
|
+
const HASH_ROUND_CONSTANT = 1013904223;
|
|
52
|
+
function mulMod(a, b) {
|
|
53
|
+
const high = Math.floor(b / HASH_SPLIT);
|
|
54
|
+
const low = b % HASH_SPLIT;
|
|
55
|
+
return (a * high % HASH_MODULUS * HASH_SPLIT + a * low) % HASH_MODULUS;
|
|
56
|
+
}
|
|
57
|
+
function scatterJitterUnit(seed, index, seriesIndex, axis) {
|
|
58
|
+
let state = (Math.abs(Math.trunc(seed)) * 7919 + index * 104729 + seriesIndex * 1299709 + axis * 15485863 + 1) % HASH_MODULUS;
|
|
59
|
+
for (let round = 0; round < 4; round++) {
|
|
60
|
+
state = (mulMod(state, state) + HASH_ROUND_CONSTANT) % HASH_MODULUS;
|
|
61
|
+
state = mulMod(state, 48271);
|
|
62
|
+
}
|
|
63
|
+
return state / (HASH_MODULUS - 1) * 2 - 1;
|
|
64
|
+
}
|
|
65
|
+
function scatterJitterOffset(jitter, index, seriesIndex) {
|
|
66
|
+
return {
|
|
67
|
+
x: jitter.x > 0 ? scatterJitterUnit(jitter.seed, index, seriesIndex, 0) * jitter.x : 0,
|
|
68
|
+
y: jitter.y > 0 ? scatterJitterUnit(jitter.seed, index, seriesIndex, 1) * jitter.y : 0
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const ScatterJitterContext = createContext(
|
|
72
|
+
null
|
|
73
|
+
);
|
|
74
|
+
function useScatterJitter() {
|
|
75
|
+
return useContext(ScatterJitterContext);
|
|
76
|
+
}
|
|
77
|
+
export {
|
|
78
|
+
DEFAULT_SCATTER_JITTER_X,
|
|
79
|
+
ScatterJitterContext,
|
|
80
|
+
minDistinctStepRatio,
|
|
81
|
+
resolveScatterJitterConfig,
|
|
82
|
+
scatterJitterOffset,
|
|
83
|
+
scatterJitterRangePadding,
|
|
84
|
+
scatterJitterUnit,
|
|
85
|
+
useScatterJitter
|
|
86
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function localPointFromSvg(svg, clientX, clientY) {
|
|
2
|
+
if (!svg) {
|
|
3
|
+
return null;
|
|
4
|
+
}
|
|
5
|
+
const point = svg.createSVGPoint();
|
|
6
|
+
point.x = clientX;
|
|
7
|
+
point.y = clientY;
|
|
8
|
+
const matrix = svg.getScreenCTM();
|
|
9
|
+
if (!matrix) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const transformed = point.matrixTransform(matrix.inverse());
|
|
13
|
+
return { x: transformed.x, y: transformed.y };
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
localPointFromSvg
|
|
17
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useId } from "react";
|
|
4
|
+
import { useChartStable } from "./chart-context";
|
|
5
|
+
import { scatterJitterOffset, useScatterJitter } from "./scatter-jitter";
|
|
6
|
+
import { SeriesMarkers } from "./series-markers";
|
|
7
|
+
const DEFAULT_Y_GRADIENT_FROM = "var(--chart-negative, var(--chart-negative))";
|
|
8
|
+
const DEFAULT_Y_GRADIENT_TO = "var(--chart-positive, var(--chart-positive))";
|
|
9
|
+
function Scatter({
|
|
10
|
+
dataKey,
|
|
11
|
+
fill,
|
|
12
|
+
stroke,
|
|
13
|
+
strokeWidth = 0,
|
|
14
|
+
ringGap = 2,
|
|
15
|
+
outlineWidth = 0,
|
|
16
|
+
outlineColor,
|
|
17
|
+
radius = 5,
|
|
18
|
+
animate = true,
|
|
19
|
+
fadeOnHover = true,
|
|
20
|
+
inactiveOpacity = 0.3,
|
|
21
|
+
inactiveMode = "opacity",
|
|
22
|
+
inactiveBlur = 2,
|
|
23
|
+
enterBlur = 2,
|
|
24
|
+
showActiveHighlight = true,
|
|
25
|
+
yGradient
|
|
26
|
+
}) {
|
|
27
|
+
const { innerHeight } = useChartStable();
|
|
28
|
+
const jitter = useScatterJitter();
|
|
29
|
+
const getPointOffset = useCallback(
|
|
30
|
+
(index, seriesIndex) => jitter ? scatterJitterOffset(jitter, index, seriesIndex) : { x: 0, y: 0 },
|
|
31
|
+
[jitter]
|
|
32
|
+
);
|
|
33
|
+
const yGradientConfig = (() => {
|
|
34
|
+
if (!yGradient) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
if (yGradient === true) {
|
|
38
|
+
return { from: DEFAULT_Y_GRADIENT_FROM, to: DEFAULT_Y_GRADIENT_TO };
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
from: yGradient.from ?? DEFAULT_Y_GRADIENT_FROM,
|
|
42
|
+
to: yGradient.to ?? DEFAULT_Y_GRADIENT_TO
|
|
43
|
+
};
|
|
44
|
+
})();
|
|
45
|
+
const yGradientId = `scatter-y-gradient-${useId().replace(/:/g, "")}`;
|
|
46
|
+
const gradientFill = yGradientConfig ? `url(#${yGradientId})` : void 0;
|
|
47
|
+
const resolvedFill = gradientFill ?? fill;
|
|
48
|
+
const resolvedStroke = stroke ?? (gradientFill ? gradientFill : void 0);
|
|
49
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
50
|
+
yGradientConfig ? /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs(
|
|
51
|
+
"linearGradient",
|
|
52
|
+
{
|
|
53
|
+
gradientUnits: "userSpaceOnUse",
|
|
54
|
+
id: yGradientId,
|
|
55
|
+
x1: 0,
|
|
56
|
+
x2: 0,
|
|
57
|
+
y1: innerHeight,
|
|
58
|
+
y2: 0,
|
|
59
|
+
children: [
|
|
60
|
+
/* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: yGradientConfig.from }),
|
|
61
|
+
/* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: yGradientConfig.to })
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
) }) : null,
|
|
65
|
+
/* @__PURE__ */ jsx(
|
|
66
|
+
SeriesMarkers,
|
|
67
|
+
{
|
|
68
|
+
animate,
|
|
69
|
+
dataKey,
|
|
70
|
+
enterBlur,
|
|
71
|
+
fadeOnHover,
|
|
72
|
+
fill: resolvedFill,
|
|
73
|
+
getPointOffset: jitter ? getPointOffset : void 0,
|
|
74
|
+
inactiveBlur: inactiveMode === "blur" ? inactiveBlur : 0,
|
|
75
|
+
inactiveOpacity,
|
|
76
|
+
outlineColor,
|
|
77
|
+
outlineWidth,
|
|
78
|
+
radius,
|
|
79
|
+
ringGap,
|
|
80
|
+
showActiveHighlight,
|
|
81
|
+
stroke: resolvedStroke,
|
|
82
|
+
strokeWidth
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
] });
|
|
86
|
+
}
|
|
87
|
+
Scatter.displayName = "Scatter";
|
|
88
|
+
var scatter_default = Scatter;
|
|
89
|
+
export {
|
|
90
|
+
Scatter,
|
|
91
|
+
scatter_default as default
|
|
92
|
+
};
|