@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.
Files changed (267) hide show
  1. package/ALTERACOES.md +57 -0
  2. package/LICENSE-BKLIT +21 -0
  3. package/LICENSE-visx-pattern +21 -0
  4. package/README.md +189 -2
  5. package/dist/aic/cores.js +83 -0
  6. package/dist/aic/index.js +22 -0
  7. package/dist/aic/interacao.js +55 -0
  8. package/dist/charts/animation.js +55 -0
  9. package/dist/charts/arc-geometry.js +58 -0
  10. package/dist/charts/arc-path.js +15 -0
  11. package/dist/charts/area-chart-loading.js +89 -0
  12. package/dist/charts/area-chart.js +149 -0
  13. package/dist/charts/area-gradient-defs.js +90 -0
  14. package/dist/charts/area-value-label-layout.js +70 -0
  15. package/dist/charts/area-value-labels.js +211 -0
  16. package/dist/charts/area.js +272 -0
  17. package/dist/charts/background.js +198 -0
  18. package/dist/charts/band-config.js +82 -0
  19. package/dist/charts/band-geometry.js +186 -0
  20. package/dist/charts/band.js +346 -0
  21. package/dist/charts/bar-chart-loading.js +27 -0
  22. package/dist/charts/bar-chart.js +545 -0
  23. package/dist/charts/bar-depth-geometry.js +18 -0
  24. package/dist/charts/bar-depth.js +608 -0
  25. package/dist/charts/bar-lollipop.js +278 -0
  26. package/dist/charts/bar-squares-layout.js +66 -0
  27. package/dist/charts/bar-squares.js +467 -0
  28. package/dist/charts/bar-value-label-layout.js +42 -0
  29. package/dist/charts/bar-x-axis.js +133 -0
  30. package/dist/charts/bar-y-axis.js +116 -0
  31. package/dist/charts/bar.js +457 -0
  32. package/dist/charts/bollinger.js +49 -0
  33. package/dist/charts/candlestick-chart.js +370 -0
  34. package/dist/charts/candlestick.js +368 -0
  35. package/dist/charts/chart-brush-handle.js +91 -0
  36. package/dist/charts/chart-brush-layout.js +91 -0
  37. package/dist/charts/chart-brush-selection-overlay.js +87 -0
  38. package/dist/charts/chart-brush-state.js +253 -0
  39. package/dist/charts/chart-brush-track-overlay.js +103 -0
  40. package/dist/charts/chart-brush.js +517 -0
  41. package/dist/charts/chart-center-typography.js +8 -0
  42. package/dist/charts/chart-child-passthrough.js +119 -0
  43. package/dist/charts/chart-config-context.js +56 -0
  44. package/dist/charts/chart-context.js +337 -0
  45. package/dist/charts/chart-crosshair.js +262 -0
  46. package/dist/charts/chart-data-override.js +186 -0
  47. package/dist/charts/chart-defs.js +56 -0
  48. package/dist/charts/chart-formatters.js +77 -0
  49. package/dist/charts/chart-legend-hover.js +27 -0
  50. package/dist/charts/chart-legend.js +163 -0
  51. package/dist/charts/chart-loading-label.js +52 -0
  52. package/dist/charts/chart-parent-size.js +138 -0
  53. package/dist/charts/chart-phase.js +29 -0
  54. package/dist/charts/chart-reveal-clip.js +62 -0
  55. package/dist/charts/chart-scale.js +19 -0
  56. package/dist/charts/chart-stat-flow.js +72 -0
  57. package/dist/charts/choropleth/choropleth-background.js +29 -0
  58. package/dist/charts/choropleth/choropleth-camera.js +379 -0
  59. package/dist/charts/choropleth/choropleth-chart.js +644 -0
  60. package/dist/charts/choropleth/choropleth-context.js +152 -0
  61. package/dist/charts/choropleth/choropleth-dot-grid.js +293 -0
  62. package/dist/charts/choropleth/choropleth-feature.js +291 -0
  63. package/dist/charts/choropleth/choropleth-graticule.js +40 -0
  64. package/dist/charts/choropleth/choropleth-marker.js +222 -0
  65. package/dist/charts/choropleth/choropleth-projection.js +37 -0
  66. package/dist/charts/choropleth/choropleth-tooltip.js +82 -0
  67. package/dist/charts/choropleth/choropleth-zoom-matrix.js +150 -0
  68. package/dist/charts/choropleth/index.js +44 -0
  69. package/dist/charts/choropleth/use-choropleth-zoom-state.js +636 -0
  70. package/dist/charts/composed-chart.js +346 -0
  71. package/dist/charts/crosshair-store.js +49 -0
  72. package/dist/charts/dash-tail-stroke.js +58 -0
  73. package/dist/charts/date-pill-store.js +50 -0
  74. package/dist/charts/date-ranges.js +131 -0
  75. package/dist/charts/deadline.js +295 -0
  76. package/dist/charts/decimate-time-series.js +112 -0
  77. package/dist/charts/fade-edges.js +171 -0
  78. package/dist/charts/fast-path.js +78 -0
  79. package/dist/charts/filter-data-by-x-domain.js +45 -0
  80. package/dist/charts/funnel-chart.js +773 -0
  81. package/dist/charts/gauge-arc-layers.js +479 -0
  82. package/dist/charts/gauge-dial.js +329 -0
  83. package/dist/charts/gauge-label-layout.js +148 -0
  84. package/dist/charts/gauge.js +946 -0
  85. package/dist/charts/generate-chart-skeleton-data.js +27 -0
  86. package/dist/charts/gradients.js +158 -0
  87. package/dist/charts/grid-lines.js +114 -0
  88. package/dist/charts/grid.js +225 -0
  89. package/dist/charts/heatmap/generate-heatmap-skeleton-data.js +13 -0
  90. package/dist/charts/heatmap/heatmap-animation.js +128 -0
  91. package/dist/charts/heatmap/heatmap-cells.js +519 -0
  92. package/dist/charts/heatmap/heatmap-chart-loading.js +44 -0
  93. package/dist/charts/heatmap/heatmap-chart.js +548 -0
  94. package/dist/charts/heatmap/heatmap-colors.js +127 -0
  95. package/dist/charts/heatmap/heatmap-context.js +107 -0
  96. package/dist/charts/heatmap/heatmap-legend-gradient.js +97 -0
  97. package/dist/charts/heatmap/heatmap-legend-swatch.js +76 -0
  98. package/dist/charts/heatmap/heatmap-legend.js +165 -0
  99. package/dist/charts/heatmap/heatmap-pattern-defs.js +37 -0
  100. package/dist/charts/heatmap/heatmap-rect-cells.js +39 -0
  101. package/dist/charts/heatmap/heatmap-resolve-separator.js +84 -0
  102. package/dist/charts/heatmap/heatmap-separator.js +168 -0
  103. package/dist/charts/heatmap/heatmap-tooltip.js +73 -0
  104. package/dist/charts/heatmap/heatmap-utils.js +633 -0
  105. package/dist/charts/heatmap/heatmap-x-axis.js +79 -0
  106. package/dist/charts/heatmap/heatmap-y-axis.js +72 -0
  107. package/dist/charts/heatmap/index.js +208 -0
  108. package/dist/charts/highlight-segment-bounds.js +34 -0
  109. package/dist/charts/highlight-segment.js +119 -0
  110. package/dist/charts/index.js +944 -0
  111. package/dist/charts/indicator-fade.js +44 -0
  112. package/dist/charts/legend/index.js +22 -0
  113. package/dist/charts/legend/legend-context.js +47 -0
  114. package/dist/charts/legend/legend-item.js +30 -0
  115. package/dist/charts/legend/legend-label.js +14 -0
  116. package/dist/charts/legend/legend-marker.js +18 -0
  117. package/dist/charts/legend/legend-progress.js +39 -0
  118. package/dist/charts/legend/legend-value.js +31 -0
  119. package/dist/charts/legend/legend.js +69 -0
  120. package/dist/charts/line-backdrop.js +129 -0
  121. package/dist/charts/line-chart-loading.js +85 -0
  122. package/dist/charts/line-chart.js +182 -0
  123. package/dist/charts/line-loading-pulse.js +185 -0
  124. package/dist/charts/line-loading-timing.js +12 -0
  125. package/dist/charts/line-path.js +58 -0
  126. package/dist/charts/line-series-terminal-marker.js +75 -0
  127. package/dist/charts/line.js +499 -0
  128. package/dist/charts/live-line-chart.js +494 -0
  129. package/dist/charts/live-line.js +277 -0
  130. package/dist/charts/live-x-axis.js +116 -0
  131. package/dist/charts/live-y-axis.js +164 -0
  132. package/dist/charts/loading-sweep.js +344 -0
  133. package/dist/charts/local-point.js +56 -0
  134. package/dist/charts/markers/chart-markers.js +149 -0
  135. package/dist/charts/markers/index.js +14 -0
  136. package/dist/charts/markers/marker-group.js +411 -0
  137. package/dist/charts/motion-utils.js +29 -0
  138. package/dist/charts/notch-gauge-shared.js +146 -0
  139. package/dist/charts/particle-line.js +1340 -0
  140. package/dist/charts/path-stroke-utils.js +51 -0
  141. package/dist/charts/pattern-area.js +127 -0
  142. package/dist/charts/pattern-preset.js +287 -0
  143. package/dist/charts/pattern-tile.js +31 -0
  144. package/dist/charts/patterns/circles.js +62 -0
  145. package/dist/charts/patterns/constants.js +9 -0
  146. package/dist/charts/patterns/hexagons.js +38 -0
  147. package/dist/charts/patterns/index.js +16 -0
  148. package/dist/charts/patterns/lines.js +65 -0
  149. package/dist/charts/patterns/path.js +37 -0
  150. package/dist/charts/patterns/pattern.js +16 -0
  151. package/dist/charts/patterns/waves.js +40 -0
  152. package/dist/charts/pie-center-shell.js +127 -0
  153. package/dist/charts/pie-center.js +87 -0
  154. package/dist/charts/pie-chart.js +377 -0
  155. package/dist/charts/pie-context.js +116 -0
  156. package/dist/charts/pie-slice.js +394 -0
  157. package/dist/charts/pie-ticks.js +332 -0
  158. package/dist/charts/profit-loss-legend-hover.js +18 -0
  159. package/dist/charts/profit-loss-legend.js +53 -0
  160. package/dist/charts/profit-loss-line.js +162 -0
  161. package/dist/charts/profit-loss-segments.js +88 -0
  162. package/dist/charts/projection-config.js +90 -0
  163. package/dist/charts/projection-line-end-marker.js +50 -0
  164. package/dist/charts/projection-line.js +466 -0
  165. package/dist/charts/projection-utils.js +303 -0
  166. package/dist/charts/radar-area.js +192 -0
  167. package/dist/charts/radar-axis.js +41 -0
  168. package/dist/charts/radar-chart.js +184 -0
  169. package/dist/charts/radar-context.js +104 -0
  170. package/dist/charts/radar-grid.js +121 -0
  171. package/dist/charts/radar-labels.js +62 -0
  172. package/dist/charts/radial-area.js +498 -0
  173. package/dist/charts/radial-axis.js +652 -0
  174. package/dist/charts/radial-bar.js +316 -0
  175. package/dist/charts/radial-center.js +67 -0
  176. package/dist/charts/radial-chart.js +740 -0
  177. package/dist/charts/radial-dot-bar-layout.js +68 -0
  178. package/dist/charts/radial-dot-bar.js +387 -0
  179. package/dist/charts/radial-geometry.js +114 -0
  180. package/dist/charts/radial-legend.js +66 -0
  181. package/dist/charts/radial-line.js +280 -0
  182. package/dist/charts/radial-ring-bar.js +255 -0
  183. package/dist/charts/radial-scrubber.js +120 -0
  184. package/dist/charts/radial-series-color.js +10 -0
  185. package/dist/charts/reference-area-config.js +43 -0
  186. package/dist/charts/reference-area-geometry.js +76 -0
  187. package/dist/charts/reference-area-registration-context.js +10 -0
  188. package/dist/charts/reference-area.js +241 -0
  189. package/dist/charts/responsive-chart-label-count.js +18 -0
  190. package/dist/charts/ring-center.js +78 -0
  191. package/dist/charts/ring-chart.js +362 -0
  192. package/dist/charts/ring-context.js +122 -0
  193. package/dist/charts/ring-grid.js +175 -0
  194. package/dist/charts/ring-labels.js +109 -0
  195. package/dist/charts/ring.js +237 -0
  196. package/dist/charts/sankey/index.js +22 -0
  197. package/dist/charts/sankey/sankey-chart.js +199 -0
  198. package/dist/charts/sankey/sankey-context.js +32 -0
  199. package/dist/charts/sankey/sankey-link.js +232 -0
  200. package/dist/charts/sankey/sankey-node.js +348 -0
  201. package/dist/charts/sankey/sankey-tooltip.js +94 -0
  202. package/dist/charts/scatter-chart-shell.js +279 -0
  203. package/dist/charts/scatter-chart.js +150 -0
  204. package/dist/charts/scatter-jitter.js +86 -0
  205. package/dist/charts/scatter-svg.js +17 -0
  206. package/dist/charts/scatter.js +92 -0
  207. package/dist/charts/segment.js +107 -0
  208. package/dist/charts/series-bar-layout.js +42 -0
  209. package/dist/charts/series-bar.js +241 -0
  210. package/dist/charts/series-dash-tail-overlay.js +53 -0
  211. package/dist/charts/series-highlight-layer.js +43 -0
  212. package/dist/charts/series-hover-dim.js +32 -0
  213. package/dist/charts/series-markers.js +239 -0
  214. package/dist/charts/series-path-utils.js +185 -0
  215. package/dist/charts/series-point-marker.js +150 -0
  216. package/dist/charts/sparkline-geometry.js +197 -0
  217. package/dist/charts/sparkline.js +910 -0
  218. package/dist/charts/static-chart-preview-context.js +16 -0
  219. package/dist/charts/sunburst-breadcrumb.js +33 -0
  220. package/dist/charts/sunburst-center.js +37 -0
  221. package/dist/charts/sunburst-chart.js +408 -0
  222. package/dist/charts/sunburst-context.js +140 -0
  223. package/dist/charts/sunburst-data.js +0 -0
  224. package/dist/charts/sunburst-hint.js +42 -0
  225. package/dist/charts/sunburst-labels.js +130 -0
  226. package/dist/charts/sunburst-segment.js +144 -0
  227. package/dist/charts/sunburst.js +419 -0
  228. package/dist/charts/time-series-chart-shell.js +688 -0
  229. package/dist/charts/tooltip/chart-tooltip.js +516 -0
  230. package/dist/charts/tooltip/cursor-tooltip-box.js +183 -0
  231. package/dist/charts/tooltip/date-ticker.js +376 -0
  232. package/dist/charts/tooltip/index.js +32 -0
  233. package/dist/charts/tooltip/liquid-glass.js +142 -0
  234. package/dist/charts/tooltip/tooltip-box.js +502 -0
  235. package/dist/charts/tooltip/tooltip-content.js +59 -0
  236. package/dist/charts/tooltip/tooltip-dot.js +170 -0
  237. package/dist/charts/tooltip/tooltip-indicator.js +175 -0
  238. package/dist/charts/tooltip/use-delayed-tooltip-data.js +41 -0
  239. package/dist/charts/tooltip/use-velocity-stretch.js +52 -0
  240. package/dist/charts/trend-line-utils.js +64 -0
  241. package/dist/charts/trend-line.js +318 -0
  242. package/dist/charts/use-animated-band.js +175 -0
  243. package/dist/charts/use-animated-series-path.js +208 -0
  244. package/dist/charts/use-animated-y-domains.js +192 -0
  245. package/dist/charts/use-category-slots.js +29 -0
  246. package/dist/charts/use-chart-interaction.js +296 -0
  247. package/dist/charts/use-chart-phase-orchestrator.js +183 -0
  248. package/dist/charts/use-enter-complete.js +18 -0
  249. package/dist/charts/use-grid-shimmer.js +88 -0
  250. package/dist/charts/use-highlight-segment.js +65 -0
  251. package/dist/charts/use-mount-progress.js +23 -0
  252. package/dist/charts/use-scatter-chart-interaction.js +364 -0
  253. package/dist/charts/use-scheduled-tooltip.js +84 -0
  254. package/dist/charts/visx-pattern.js +30 -0
  255. package/dist/charts/weekends.js +174 -0
  256. package/dist/charts/x-axis-hover.js +46 -0
  257. package/dist/charts/x-axis.js +523 -0
  258. package/dist/charts/y-axis-scales.js +71 -0
  259. package/dist/charts/y-axis-ticks.js +22 -0
  260. package/dist/charts/y-axis.js +233 -0
  261. package/dist/charts/y-domain-utils.js +189 -0
  262. package/dist/index.d.ts +7346 -0
  263. package/dist/index.js +2 -0
  264. package/dist/lib/utils.js +8 -0
  265. package/dist/shimmering-text.js +54 -0
  266. package/package.json +78 -4
  267. package/tema.css +202 -0
@@ -0,0 +1,318 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import {
4
+ animate as animateValue,
5
+ m,
6
+ useReducedMotion
7
+ } from "motion/react";
8
+ import {
9
+ useEffect,
10
+ useId,
11
+ useLayoutEffect,
12
+ useMemo,
13
+ useRef,
14
+ useState
15
+ } from "react";
16
+ import { chartCssVars, useChartStable, useYScale } from "./chart-context";
17
+ import { resolveFadeSides } from "./fade-edges";
18
+ import { LINE_LOADING_PULSE_EASE } from "./line-loading-timing";
19
+ import {
20
+ computeTrendSegment,
21
+ interpolateTrendSegment
22
+ } from "./trend-line-utils";
23
+ const ENTER_FADE_MS = 420;
24
+ function clampFadeLength(length) {
25
+ return Math.min(50, Math.max(0, length));
26
+ }
27
+ function isVisiblePhase(phase) {
28
+ return phase === "revealing" || phase === "ready" || phase === "exitingReady";
29
+ }
30
+ function resolveFadeTransition(skipMotion, enterTransition) {
31
+ if (skipMotion) {
32
+ return { duration: 0 };
33
+ }
34
+ return enterTransition && typeof enterTransition === "object" ? enterTransition : { duration: ENTER_FADE_MS / 1e3, ease: "easeOut" };
35
+ }
36
+ function segmentSignature(segment) {
37
+ return segment ? `${segment.x1}|${segment.y1}|${segment.x2}|${segment.y2}` : "";
38
+ }
39
+ function projectTrendSegment(segment, mapAlong, valueScale, swapAxes) {
40
+ const along1 = mapAlong(segment.x1);
41
+ const along2 = mapAlong(segment.x2);
42
+ const value1 = valueScale(segment.y1) ?? 0;
43
+ const value2 = valueScale(segment.y2) ?? 0;
44
+ return swapAxes ? { x1: value1, y1: along1, x2: value2, y2: along2 } : { x1: along1, y1: value1, x2: along2, y2: value2 };
45
+ }
46
+ function lineGradientVector(pixels) {
47
+ return {
48
+ gradientUnits: "userSpaceOnUse",
49
+ x1: pixels.x1,
50
+ x2: pixels.x2,
51
+ y1: pixels.y1,
52
+ y2: pixels.y2
53
+ };
54
+ }
55
+ function TrendLineFadeMask({
56
+ fadeLength,
57
+ id,
58
+ pad,
59
+ pixels,
60
+ sides
61
+ }) {
62
+ const gradientId = `${id}-gradient`;
63
+ const x = Math.min(pixels.x1, pixels.x2) - pad;
64
+ const y = Math.min(pixels.y1, pixels.y2) - pad;
65
+ const width = Math.abs(pixels.x2 - pixels.x1) + pad * 2;
66
+ const height = Math.abs(pixels.y2 - pixels.y1) + pad * 2;
67
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
68
+ /* @__PURE__ */ jsxs("linearGradient", { id: gradientId, ...lineGradientVector(pixels), children: [
69
+ /* @__PURE__ */ jsx(
70
+ "stop",
71
+ {
72
+ offset: "0%",
73
+ style: { stopColor: "white", stopOpacity: sides.left ? 0 : 1 }
74
+ }
75
+ ),
76
+ /* @__PURE__ */ jsx(
77
+ "stop",
78
+ {
79
+ offset: `${sides.left ? fadeLength : 0}%`,
80
+ style: { stopColor: "white", stopOpacity: 1 }
81
+ }
82
+ ),
83
+ /* @__PURE__ */ jsx(
84
+ "stop",
85
+ {
86
+ offset: `${sides.right ? 100 - fadeLength : 100}%`,
87
+ style: { stopColor: "white", stopOpacity: 1 }
88
+ }
89
+ ),
90
+ /* @__PURE__ */ jsx(
91
+ "stop",
92
+ {
93
+ offset: "100%",
94
+ style: { stopColor: "white", stopOpacity: sides.right ? 0 : 1 }
95
+ }
96
+ )
97
+ ] }),
98
+ /* @__PURE__ */ jsx(
99
+ "mask",
100
+ {
101
+ height,
102
+ id,
103
+ maskUnits: "userSpaceOnUse",
104
+ width,
105
+ x,
106
+ y,
107
+ children: /* @__PURE__ */ jsx(
108
+ "rect",
109
+ {
110
+ fill: `url(#${gradientId})`,
111
+ height,
112
+ width,
113
+ x,
114
+ y
115
+ }
116
+ )
117
+ }
118
+ )
119
+ ] });
120
+ }
121
+ function useAnimatedTrendPixels({
122
+ dataSignature,
123
+ durationMs,
124
+ enabled,
125
+ targetPixels
126
+ }) {
127
+ const reducedMotion = useReducedMotion();
128
+ const [animated, setAnimated] = useState(null);
129
+ const displayedRef = useRef(targetPixels);
130
+ const animatingRef = useRef(false);
131
+ const prevSignatureRef = useRef(dataSignature);
132
+ const latestTargetRef = useRef(targetPixels);
133
+ useLayoutEffect(() => {
134
+ latestTargetRef.current = targetPixels;
135
+ });
136
+ const shouldAnimate = enabled && !reducedMotion && durationMs > 0;
137
+ useLayoutEffect(() => {
138
+ const dataChanged = prevSignatureRef.current !== dataSignature;
139
+ prevSignatureRef.current = dataSignature;
140
+ const from = displayedRef.current;
141
+ const target = latestTargetRef.current;
142
+ if (!(shouldAnimate && dataChanged && from && target)) {
143
+ animatingRef.current = false;
144
+ displayedRef.current = target;
145
+ setAnimated(null);
146
+ return;
147
+ }
148
+ animatingRef.current = true;
149
+ const renderFrame = (progress) => {
150
+ const to = latestTargetRef.current;
151
+ if (!to) {
152
+ return;
153
+ }
154
+ const next = interpolateTrendSegment(from, to, progress);
155
+ displayedRef.current = next;
156
+ setAnimated(next);
157
+ };
158
+ renderFrame(0);
159
+ const control = animateValue(0, 1, {
160
+ duration: durationMs / 1e3,
161
+ ease: [...LINE_LOADING_PULSE_EASE],
162
+ onUpdate: renderFrame,
163
+ onComplete: () => {
164
+ animatingRef.current = false;
165
+ displayedRef.current = latestTargetRef.current;
166
+ setAnimated(null);
167
+ }
168
+ });
169
+ return () => {
170
+ control.stop();
171
+ animatingRef.current = false;
172
+ };
173
+ }, [dataSignature, durationMs, shouldAnimate]);
174
+ useEffect(() => {
175
+ if (!animatingRef.current) {
176
+ displayedRef.current = targetPixels;
177
+ }
178
+ }, [targetPixels]);
179
+ return animated ?? targetPixels;
180
+ }
181
+ function TrendLine({
182
+ dataKey,
183
+ stroke = chartCssVars.linePrimary,
184
+ strokeWidth = 2,
185
+ strokeStyle = "dashed",
186
+ strokeDasharray = "6,4",
187
+ gradientStart,
188
+ gradientEnd = "var(--chart-5)",
189
+ fadeEdges = false,
190
+ fadeEdgesLength = 15,
191
+ opacity = 1,
192
+ yAxisId,
193
+ animate = true,
194
+ className
195
+ }) {
196
+ const {
197
+ data,
198
+ xScale,
199
+ xAccessor,
200
+ barScale,
201
+ barXAccessor,
202
+ bandWidth = 0,
203
+ orientation,
204
+ chartPhase,
205
+ enterTransition,
206
+ isLoaded,
207
+ yDomainTweenDuration
208
+ } = useChartStable();
209
+ const valueScale = useYScale(yAxisId);
210
+ const uniqueId = useId().replace(/:/g, "");
211
+ const gradientId = `chart-trend-line-gradient-${uniqueId}`;
212
+ const maskId = `chart-trend-line-fade-${uniqueId}`;
213
+ const isBar = barScale != null && barXAccessor != null;
214
+ const isHorizontal = isBar && orientation === "horizontal";
215
+ const points = useMemo(
216
+ () => data.map((d, index) => {
217
+ const value = d[dataKey];
218
+ return {
219
+ x: isBar ? index : xAccessor(d).getTime(),
220
+ y: typeof value === "number" ? value : Number.NaN
221
+ };
222
+ }),
223
+ [data, dataKey, isBar, xAccessor]
224
+ );
225
+ const segment = useMemo(() => computeTrendSegment(points), [points]);
226
+ const targetPixels = useMemo(() => {
227
+ if (!segment) {
228
+ return null;
229
+ }
230
+ let mapAlong;
231
+ if (isBar) {
232
+ const bandCenter = (d) => (d ? barScale(barXAccessor(d)) ?? 0 : 0) + bandWidth / 2;
233
+ const firstCenter = bandCenter(data[0]);
234
+ const lastCenter = bandCenter(data.at(-1));
235
+ const span = Math.max(1, data.length - 1);
236
+ mapAlong = (x) => firstCenter + (lastCenter - firstCenter) * x / span;
237
+ } else {
238
+ mapAlong = (x) => xScale(new Date(x)) ?? 0;
239
+ }
240
+ return projectTrendSegment(segment, mapAlong, valueScale, isHorizontal);
241
+ }, [
242
+ bandWidth,
243
+ barScale,
244
+ barXAccessor,
245
+ data,
246
+ isBar,
247
+ isHorizontal,
248
+ segment,
249
+ valueScale,
250
+ xScale
251
+ ]);
252
+ const reducedMotion = useReducedMotion();
253
+ const pixels = useAnimatedTrendPixels({
254
+ dataSignature: segmentSignature(segment),
255
+ durationMs: yDomainTweenDuration,
256
+ enabled: animate && chartPhase === "ready",
257
+ targetPixels
258
+ });
259
+ if (!pixels) {
260
+ return null;
261
+ }
262
+ const visible = isVisiblePhase(chartPhase) && (!isBar || isLoaded || !animate);
263
+ const skipMotion = !animate || reducedMotion === true;
264
+ const fadeTransition = resolveFadeTransition(skipMotion, enterTransition);
265
+ const fadeSides = resolveFadeSides(fadeEdges);
266
+ const fadeLength = clampFadeLength(fadeEdgesLength);
267
+ const gradientVector = lineGradientVector(pixels);
268
+ const isGradient = strokeStyle === "gradient";
269
+ return /* @__PURE__ */ jsxs(
270
+ m.g,
271
+ {
272
+ animate: { opacity: visible ? opacity : 0 },
273
+ "aria-hidden": "true",
274
+ className: className ?? "chart-trend-line",
275
+ initial: skipMotion ? false : { opacity: 0 },
276
+ transition: fadeTransition,
277
+ children: [
278
+ isGradient || fadeSides.any ? /* @__PURE__ */ jsxs("defs", { children: [
279
+ isGradient ? /* @__PURE__ */ jsxs("linearGradient", { id: gradientId, ...gradientVector, children: [
280
+ /* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: gradientStart ?? stroke }),
281
+ /* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: gradientEnd })
282
+ ] }) : null,
283
+ fadeSides.any ? /* @__PURE__ */ jsx(
284
+ TrendLineFadeMask,
285
+ {
286
+ fadeLength,
287
+ id: maskId,
288
+ pad: strokeWidth + 2,
289
+ pixels,
290
+ sides: fadeSides
291
+ }
292
+ ) : null
293
+ ] }) : null,
294
+ /* @__PURE__ */ jsx(
295
+ "line",
296
+ {
297
+ fill: "none",
298
+ mask: fadeSides.any ? `url(#${maskId})` : void 0,
299
+ stroke: isGradient ? `url(#${gradientId})` : stroke,
300
+ strokeDasharray: strokeStyle === "dashed" ? strokeDasharray : void 0,
301
+ strokeLinecap: "round",
302
+ strokeWidth,
303
+ x1: pixels.x1,
304
+ x2: pixels.x2,
305
+ y1: pixels.y1,
306
+ y2: pixels.y2
307
+ }
308
+ )
309
+ ]
310
+ }
311
+ );
312
+ }
313
+ TrendLine.displayName = "TrendLine";
314
+ var trend_line_default = TrendLine;
315
+ export {
316
+ TrendLine,
317
+ trend_line_default as default
318
+ };
@@ -0,0 +1,175 @@
1
+ "use client";
2
+ import { animate, useReducedMotion } from "motion/react";
3
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
4
+ import {
5
+ bandDataSignature,
6
+ computeBandSegments,
7
+ flattenBandEdges,
8
+ interpolateBandSegments,
9
+ morphBandSegments
10
+ } from "./band-geometry";
11
+ import { LINE_LOADING_PULSE_EASE } from "./line-loading-timing";
12
+ function segmentsFor(inputs) {
13
+ return computeBandSegments(
14
+ inputs.renderData,
15
+ inputs.xAccessor,
16
+ inputs.xScale,
17
+ inputs.yScale,
18
+ inputs.upperKey,
19
+ inputs.lowerKey
20
+ );
21
+ }
22
+ function useAnimatedBand({
23
+ renderData,
24
+ xAccessor,
25
+ xScale,
26
+ yScale,
27
+ upperKey,
28
+ lowerKey,
29
+ curve,
30
+ chartPhase,
31
+ durationMs,
32
+ innerWidth,
33
+ enabled
34
+ }) {
35
+ const reducedMotion = useReducedMotion();
36
+ const [animatedBand, setAnimatedBand] = useState(null);
37
+ const displayedRef = useRef(null);
38
+ const animatingRef = useRef(false);
39
+ const xScaleDomain = useMemo(() => {
40
+ const scaleWithDomain = xScale;
41
+ return scaleWithDomain.domain?.() ?? [/* @__PURE__ */ new Date(0), /* @__PURE__ */ new Date(0)];
42
+ }, [xScale]);
43
+ const dataSignature = useMemo(
44
+ () => bandDataSignature(renderData, xAccessor, upperKey, lowerKey),
45
+ [renderData, xAccessor, upperKey, lowerKey]
46
+ );
47
+ const transitionSignature = `${innerWidth}|${xScaleDomain[0]?.getTime?.() ?? 0}|${xScaleDomain[1]?.getTime?.() ?? 0}|${dataSignature}`;
48
+ const targetSegments = useMemo(
49
+ () => segmentsFor({
50
+ curve,
51
+ lowerKey,
52
+ renderData,
53
+ upperKey,
54
+ xAccessor,
55
+ xScale,
56
+ yScale
57
+ }),
58
+ [renderData, xAccessor, xScale, yScale, upperKey, lowerKey, curve]
59
+ );
60
+ const prevTransitionSignatureRef = useRef(transitionSignature);
61
+ const prevDataSignatureRef = useRef(dataSignature);
62
+ const latestRef = useRef({
63
+ renderData,
64
+ xAccessor,
65
+ xScale,
66
+ yScale,
67
+ upperKey,
68
+ lowerKey,
69
+ curve
70
+ });
71
+ useLayoutEffect(() => {
72
+ latestRef.current = {
73
+ renderData,
74
+ xAccessor,
75
+ xScale,
76
+ yScale,
77
+ upperKey,
78
+ lowerKey,
79
+ curve
80
+ };
81
+ });
82
+ const shouldAnimate = enabled && !reducedMotion && chartPhase === "ready" && durationMs > 0 && renderData.length > 0;
83
+ if (!shouldAnimate && animatedBand !== null) {
84
+ setAnimatedBand(null);
85
+ }
86
+ useLayoutEffect(() => {
87
+ const computeLatestTarget = () => segmentsFor(latestRef.current);
88
+ const dataChanged = prevDataSignatureRef.current !== dataSignature;
89
+ prevDataSignatureRef.current = dataSignature;
90
+ if (!shouldAnimate) {
91
+ animatingRef.current = false;
92
+ displayedRef.current = {
93
+ segments: computeLatestTarget(),
94
+ polyline: false
95
+ };
96
+ prevTransitionSignatureRef.current = transitionSignature;
97
+ return;
98
+ }
99
+ if (prevTransitionSignatureRef.current === transitionSignature) {
100
+ return;
101
+ }
102
+ prevTransitionSignatureRef.current = transitionSignature;
103
+ const from = displayedRef.current ?? {
104
+ segments: computeLatestTarget(),
105
+ polyline: false
106
+ };
107
+ if (from.segments.length === 0) {
108
+ displayedRef.current = {
109
+ segments: computeLatestTarget(),
110
+ polyline: false
111
+ };
112
+ return;
113
+ }
114
+ animatingRef.current = true;
115
+ const morph = dataChanged || from.polyline;
116
+ const fromPolylines = morph ? flattenBandEdges(from.segments, latestRef.current.curve, from.polyline) : null;
117
+ const renderFrame = (progress) => {
118
+ const currentTarget = computeLatestTarget();
119
+ const next = fromPolylines ? {
120
+ segments: morphBandSegments(
121
+ fromPolylines,
122
+ currentTarget,
123
+ latestRef.current.curve,
124
+ progress
125
+ ),
126
+ polyline: true
127
+ } : {
128
+ segments: interpolateBandSegments(
129
+ from.segments,
130
+ currentTarget,
131
+ progress
132
+ ),
133
+ polyline: false
134
+ };
135
+ displayedRef.current = next;
136
+ setAnimatedBand(next);
137
+ };
138
+ renderFrame(0);
139
+ const control = animate(0, 1, {
140
+ duration: durationMs / 1e3,
141
+ ease: [...LINE_LOADING_PULSE_EASE],
142
+ onUpdate: renderFrame,
143
+ onComplete: () => {
144
+ animatingRef.current = false;
145
+ displayedRef.current = {
146
+ segments: computeLatestTarget(),
147
+ polyline: false
148
+ };
149
+ setAnimatedBand(null);
150
+ }
151
+ });
152
+ return () => {
153
+ control.stop();
154
+ animatingRef.current = false;
155
+ };
156
+ }, [
157
+ transitionSignature,
158
+ dataSignature,
159
+ shouldAnimate,
160
+ chartPhase,
161
+ durationMs,
162
+ enabled,
163
+ reducedMotion,
164
+ renderData.length
165
+ ]);
166
+ useEffect(() => {
167
+ if (!animatingRef.current) {
168
+ displayedRef.current = { segments: targetSegments, polyline: false };
169
+ }
170
+ }, [targetSegments]);
171
+ return animatedBand ?? { segments: targetSegments, polyline: false };
172
+ }
173
+ export {
174
+ useAnimatedBand
175
+ };
@@ -0,0 +1,208 @@
1
+ "use client";
2
+ import { curveLinear } from "d3-shape";
3
+ import { animate, useReducedMotion } from "motion/react";
4
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
5
+ import { LINE_LOADING_PULSE_EASE } from "./line-loading-timing";
6
+ import {
7
+ computeSeriesPathPoints,
8
+ flattenSeriesPath,
9
+ interpolateSeriesPathPoints,
10
+ morphSeriesPolylines,
11
+ seriesDataSignature,
12
+ seriesPathFromPoints,
13
+ seriesPathTransitionSignatureFromData
14
+ } from "./series-path-utils";
15
+ function useAnimatedSeriesPath({
16
+ renderData,
17
+ xAccessor,
18
+ xScale,
19
+ yScale,
20
+ settledYScale = yScale,
21
+ dataKey,
22
+ curve,
23
+ chartPhase,
24
+ durationMs,
25
+ innerWidth,
26
+ enabled
27
+ }) {
28
+ const reducedMotion = useReducedMotion();
29
+ const [animatedPath, setAnimatedPath] = useState(
30
+ null
31
+ );
32
+ const displayedRef = useRef(null);
33
+ const animatingRef = useRef(false);
34
+ const xScaleDomain = useMemo(() => {
35
+ const scaleWithDomain = xScale;
36
+ return scaleWithDomain.domain?.() ?? [/* @__PURE__ */ new Date(0), /* @__PURE__ */ new Date(0)];
37
+ }, [xScale]);
38
+ const targetPoints = useMemo(
39
+ () => computeSeriesPathPoints(renderData, xAccessor, xScale, yScale, dataKey),
40
+ [renderData, xAccessor, xScale, yScale, dataKey]
41
+ );
42
+ const dataSignature = useMemo(
43
+ () => seriesDataSignature(renderData, xAccessor, dataKey),
44
+ [renderData, xAccessor, dataKey]
45
+ );
46
+ const transitionSignature = useMemo(
47
+ () => seriesPathTransitionSignatureFromData(dataSignature, {
48
+ innerWidth,
49
+ xDomainMin: xScaleDomain[0]?.getTime?.() ?? 0,
50
+ xDomainMax: xScaleDomain[1]?.getTime?.() ?? 0
51
+ }),
52
+ [dataSignature, innerWidth, xScaleDomain]
53
+ );
54
+ const settledYDomainKey = settledYScale.domain?.().join(",") ?? "";
55
+ const prevTransitionSignatureRef = useRef(transitionSignature);
56
+ const prevDataSignatureRef = useRef(dataSignature);
57
+ const prevSettledYDomainKeyRef = useRef(settledYDomainKey);
58
+ const latestRef = useRef({
59
+ renderData,
60
+ xAccessor,
61
+ xScale,
62
+ yScale,
63
+ settledYScale,
64
+ dataKey,
65
+ curve
66
+ });
67
+ useLayoutEffect(() => {
68
+ latestRef.current = {
69
+ renderData,
70
+ xAccessor,
71
+ xScale,
72
+ yScale,
73
+ settledYScale,
74
+ dataKey,
75
+ curve
76
+ };
77
+ });
78
+ const computeLatestTarget = (settled = false) => {
79
+ const latest = latestRef.current;
80
+ return computeSeriesPathPoints(
81
+ latest.renderData,
82
+ latest.xAccessor,
83
+ latest.xScale,
84
+ settled ? latest.settledYScale : latest.yScale,
85
+ latest.dataKey
86
+ );
87
+ };
88
+ const shouldAnimate = enabled && !reducedMotion && chartPhase === "ready" && durationMs > 0 && renderData.length > 0;
89
+ if (!shouldAnimate && animatedPath !== null) {
90
+ setAnimatedPath(null);
91
+ }
92
+ useLayoutEffect(() => {
93
+ const dataChanged = prevDataSignatureRef.current !== dataSignature;
94
+ prevDataSignatureRef.current = dataSignature;
95
+ const yDomainChanged = prevSettledYDomainKeyRef.current !== settledYDomainKey;
96
+ prevSettledYDomainKeyRef.current = settledYDomainKey;
97
+ if (!shouldAnimate) {
98
+ animatingRef.current = false;
99
+ displayedRef.current = { points: targetPoints, polyline: false };
100
+ prevTransitionSignatureRef.current = transitionSignature;
101
+ return;
102
+ }
103
+ if (prevTransitionSignatureRef.current === transitionSignature) {
104
+ return;
105
+ }
106
+ prevTransitionSignatureRef.current = transitionSignature;
107
+ const from = displayedRef.current ?? {
108
+ points: targetPoints,
109
+ polyline: false
110
+ };
111
+ if (from.points.length === 0) {
112
+ displayedRef.current = { points: targetPoints, polyline: false };
113
+ return;
114
+ }
115
+ animatingRef.current = true;
116
+ const morph = dataChanged || from.polyline;
117
+ const fromPolyline = from.polyline ? from.points : flattenSeriesPath(from.points, curve);
118
+ const holdForYDomain = morph && dataChanged && yDomainChanged;
119
+ let targetPolylineCache = null;
120
+ const settledTargetPolyline = () => {
121
+ const latest = latestRef.current;
122
+ const inputs = [
123
+ latest.renderData,
124
+ latest.xAccessor,
125
+ latest.xScale,
126
+ latest.settledYScale,
127
+ latest.dataKey,
128
+ latest.curve
129
+ ];
130
+ const cached = targetPolylineCache;
131
+ if (cached && inputs.every((input, i) => input === cached.inputs[i])) {
132
+ return cached.polyline;
133
+ }
134
+ const polyline = flattenSeriesPath(
135
+ computeLatestTarget(true),
136
+ latest.curve
137
+ );
138
+ targetPolylineCache = { inputs, polyline };
139
+ return polyline;
140
+ };
141
+ const renderFrame = (progress) => {
142
+ const next = morph ? {
143
+ points: morphSeriesPolylines(
144
+ fromPolyline,
145
+ settledTargetPolyline(),
146
+ progress
147
+ ),
148
+ polyline: true
149
+ } : {
150
+ points: interpolateSeriesPathPoints(
151
+ from.points,
152
+ computeLatestTarget(false),
153
+ progress
154
+ ),
155
+ polyline: false
156
+ };
157
+ displayedRef.current = next;
158
+ setAnimatedPath(next);
159
+ };
160
+ renderFrame(0);
161
+ const control = animate(0, 1, {
162
+ delay: holdForYDomain ? durationMs / 1e3 : 0,
163
+ duration: durationMs / 1e3,
164
+ ease: [...LINE_LOADING_PULSE_EASE],
165
+ onUpdate: renderFrame,
166
+ onComplete: () => {
167
+ animatingRef.current = false;
168
+ displayedRef.current = {
169
+ points: computeLatestTarget(),
170
+ polyline: false
171
+ };
172
+ setAnimatedPath(null);
173
+ }
174
+ });
175
+ return () => {
176
+ control.stop();
177
+ animatingRef.current = false;
178
+ };
179
+ }, [
180
+ transitionSignature,
181
+ dataSignature,
182
+ shouldAnimate,
183
+ chartPhase,
184
+ durationMs,
185
+ enabled,
186
+ reducedMotion,
187
+ renderData.length
188
+ ]);
189
+ useEffect(() => {
190
+ if (!animatingRef.current) {
191
+ displayedRef.current = { points: targetPoints, polyline: false };
192
+ }
193
+ }, [targetPoints]);
194
+ const pathD = useMemo(
195
+ () => animatedPath ? seriesPathFromPoints(
196
+ animatedPath.points,
197
+ animatedPath.polyline ? curveLinear : curve
198
+ ) : seriesPathFromPoints(targetPoints, curve),
199
+ [animatedPath, targetPoints, curve]
200
+ );
201
+ return {
202
+ pathD,
203
+ isPathAnimating: animatedPath != null
204
+ };
205
+ }
206
+ export {
207
+ useAnimatedSeriesPath
208
+ };