@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.
Files changed (267) hide show
  1. package/ALTERACOES.md +53 -0
  2. package/LICENSE-BKLIT +21 -0
  3. package/LICENSE-visx-pattern +21 -0
  4. package/README.md +188 -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,494 @@
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 { domAnimation, LazyMotion } from "motion/react";
6
+ import {
7
+ Children,
8
+ isValidElement,
9
+ memo,
10
+ startTransition,
11
+ useCallback,
12
+ useEffect,
13
+ useMemo,
14
+ useRef,
15
+ useState
16
+ } from "react";
17
+ import { cn } from "../lib/utils";
18
+ import {
19
+ isClipExcludedComponent,
20
+ isUnderlayComponent
21
+ } from "./chart-child-passthrough";
22
+ import {
23
+ ChartProvider
24
+ } from "./chart-context";
25
+ import { hmsTimeFmt } from "./chart-formatters";
26
+ import { ParentSize } from "./chart-parent-size";
27
+ import { DEFAULT_CHART_LIFECYCLE } from "./chart-phase";
28
+ import { localPoint } from "./local-point";
29
+ import { extractReferenceAreaConfigs } from "./reference-area-config";
30
+ import { wrapSingleYScale } from "./y-axis-scales";
31
+ const LERP_SPEED = 0.08;
32
+ const DEFAULT_MARGIN = { top: 24, right: 16, bottom: 32, left: 16 };
33
+ const LIVE_FRAME_COMMIT_MS = 32;
34
+ function computeTargetRange(data, value, exaggerate) {
35
+ if (data.length === 0) {
36
+ return { yMin: 0, yMax: 100 };
37
+ }
38
+ let min = Number.POSITIVE_INFINITY;
39
+ let max = Number.NEGATIVE_INFINITY;
40
+ for (const d of data) {
41
+ if (d.value < min) {
42
+ min = d.value;
43
+ }
44
+ if (d.value > max) {
45
+ max = d.value;
46
+ }
47
+ }
48
+ if (value < min) {
49
+ min = value;
50
+ }
51
+ if (value > max) {
52
+ max = value;
53
+ }
54
+ const rawRange = max - min;
55
+ const paddingFactor = exaggerate ? 0.03 : 0.15;
56
+ const rangePad = rawRange * paddingFactor || (exaggerate ? 0.04 : 10);
57
+ return { yMin: min - rangePad, yMax: max + rangePad };
58
+ }
59
+ function nextAnimFrame(prev, targetRange, targetValue, speed, isPaused) {
60
+ const nextNow = isPaused ? prev.now : Date.now();
61
+ const nextYMin = targetRange.yMin < prev.yMin ? targetRange.yMin : prev.yMin + (targetRange.yMin - prev.yMin) * speed;
62
+ const nextYMax = targetRange.yMax > prev.yMax ? targetRange.yMax : prev.yMax + (targetRange.yMax - prev.yMax) * speed;
63
+ const nextValue = prev.displayValue + (targetValue - prev.displayValue) * speed;
64
+ return {
65
+ now: nextNow,
66
+ yMin: nextYMin,
67
+ yMax: nextYMax,
68
+ displayValue: nextValue
69
+ };
70
+ }
71
+ function interpolateAtTime(points, timeSec) {
72
+ if (points.length === 0) {
73
+ return null;
74
+ }
75
+ const firstPt = points[0];
76
+ const lastPt = points.at(-1);
77
+ if (timeSec <= firstPt.time) {
78
+ return firstPt.value;
79
+ }
80
+ if (timeSec >= lastPt.time) {
81
+ return lastPt.value;
82
+ }
83
+ let lo = 0;
84
+ let hi = points.length - 1;
85
+ while (hi - lo > 1) {
86
+ const mid = Math.floor((lo + hi) / 2);
87
+ const midPt = points[mid];
88
+ if (midPt && midPt.time <= timeSec) {
89
+ lo = mid;
90
+ } else {
91
+ hi = mid;
92
+ }
93
+ }
94
+ const p1 = points[lo];
95
+ if (!p1) {
96
+ return null;
97
+ }
98
+ const p2 = points[hi];
99
+ if (!p2) {
100
+ return null;
101
+ }
102
+ const dt = p2.time - p1.time;
103
+ if (dt === 0) {
104
+ return p1.value;
105
+ }
106
+ const t = (timeSec - p1.time) / dt;
107
+ return p1.value + (p2.value - p1.value) * t;
108
+ }
109
+ const bisectTime = bisector((d) => d.time).left;
110
+ function extractLiveLineConfigs(children) {
111
+ const configs = [];
112
+ Children.forEach(children, (child) => {
113
+ if (!isValidElement(child)) {
114
+ return;
115
+ }
116
+ const childType = child.type;
117
+ const name = typeof child.type === "function" ? childType.displayName || childType.name || "" : "";
118
+ const props = child.props;
119
+ if ((name === "LiveLine" || props && "dataKey" in props) && props?.dataKey) {
120
+ configs.push({
121
+ dataKey: props.dataKey,
122
+ stroke: props.stroke || "var(--chart-line-primary)",
123
+ strokeWidth: props.strokeWidth || 2
124
+ });
125
+ }
126
+ });
127
+ return configs;
128
+ }
129
+ function liveTooltipKey(tooltip, dataKey) {
130
+ if (!tooltip) {
131
+ return null;
132
+ }
133
+ return `${Math.round(tooltip.x)}:${Math.round(tooltip.yPositions[dataKey] ?? 0)}`;
134
+ }
135
+ function resolveLiveTooltip(cursorX, innerWidth, innerHeight, frame, leadingMs, windowMs, xTickUnitMs, data, dataKey) {
136
+ if (cursorX === null || innerWidth <= 0 || innerHeight <= 0) {
137
+ return null;
138
+ }
139
+ const domainEndMs = frame.now + leadingMs;
140
+ const xScaleNext = scaleTime().domain([new Date(domainEndMs - windowMs), new Date(domainEndMs)]).range([0, innerWidth]);
141
+ const yScaleNext = scaleLinear().domain([frame.yMin, frame.yMax]).nice().range([innerHeight, 0]);
142
+ const timeMs = xScaleNext.invert(cursorX).getTime();
143
+ const timeSec = timeMs / 1e3;
144
+ const visible = data.filter((p) => p.time >= (domainEndMs - windowMs) / 1e3);
145
+ visible.push({ time: frame.now / 1e3, value: frame.displayValue });
146
+ visible.push({
147
+ time: (frame.now + xTickUnitMs) / 1e3,
148
+ value: frame.displayValue
149
+ });
150
+ const val = interpolateAtTime(visible, timeSec);
151
+ if (val === null) {
152
+ return null;
153
+ }
154
+ return {
155
+ point: { date: new Date(timeMs), [dataKey]: val },
156
+ index: 0,
157
+ x: cursorX,
158
+ yPositions: { [dataKey]: yScaleNext(val) ?? 0 }
159
+ };
160
+ }
161
+ function shouldCommitLiveUpdates(now, lastFrameCommit, tooltipKey, lastTooltipKey) {
162
+ const commitFrame = now - lastFrameCommit >= LIVE_FRAME_COMMIT_MS;
163
+ const commitTooltip = tooltipKey !== lastTooltipKey;
164
+ return { commitFrame, commitTooltip };
165
+ }
166
+ function LiveLineChartInner(props) {
167
+ const { width, height, margin } = props;
168
+ const innerWidth = width - margin.left - margin.right;
169
+ const innerHeight = height - margin.top - margin.bottom;
170
+ if (innerWidth <= 0 || innerHeight <= 0) {
171
+ return null;
172
+ }
173
+ return /* @__PURE__ */ jsx(LiveLineChartCore, { ...props });
174
+ }
175
+ const LiveLineChartCore = memo(function LiveLineChartCore2({
176
+ data,
177
+ value,
178
+ dataKey,
179
+ windowSecs,
180
+ numXTicks,
181
+ nowOffsetUnits,
182
+ exaggerate,
183
+ lerpSpeed,
184
+ margin,
185
+ paused,
186
+ width,
187
+ height,
188
+ containerRef,
189
+ children
190
+ }) {
191
+ const windowMs = windowSecs * 1e3;
192
+ const innerWidth = width - margin.left - margin.right;
193
+ const innerHeight = height - margin.top - margin.bottom;
194
+ const [frame, setFrame] = useState(() => ({
195
+ now: Date.now(),
196
+ yMin: 0,
197
+ yMax: 100,
198
+ displayValue: value
199
+ }));
200
+ const animRef = useRef(frame);
201
+ const pausedRef = useRef(paused);
202
+ const dataRef = useRef(data);
203
+ const dataKeyRef = useRef(dataKey);
204
+ useEffect(() => {
205
+ pausedRef.current = paused;
206
+ dataRef.current = data;
207
+ dataKeyRef.current = dataKey;
208
+ }, [paused, data, dataKey]);
209
+ const targetRange = useMemo(
210
+ () => computeTargetRange(data, value, exaggerate),
211
+ [data, value, exaggerate]
212
+ );
213
+ const lines = useMemo(() => extractLiveLineConfigs(children), [children]);
214
+ const xTickUnitMs = windowMs / (numXTicks - 1);
215
+ const leadingMs = nowOffsetUnits * xTickUnitMs;
216
+ const cursorXRef = useRef(null);
217
+ const [tooltipData, setTooltipData] = useState(null);
218
+ const lastFrameCommitRef = useRef(0);
219
+ const lastTooltipKeyRef = useRef(null);
220
+ useEffect(() => {
221
+ let raf;
222
+ const tick = () => {
223
+ const next = nextAnimFrame(
224
+ animRef.current,
225
+ targetRange,
226
+ value,
227
+ lerpSpeed,
228
+ pausedRef.current
229
+ );
230
+ animRef.current = next;
231
+ const nextTooltip = resolveLiveTooltip(
232
+ cursorXRef.current,
233
+ innerWidth,
234
+ innerHeight,
235
+ next,
236
+ leadingMs,
237
+ windowMs,
238
+ xTickUnitMs,
239
+ dataRef.current,
240
+ dataKeyRef.current
241
+ );
242
+ const now = performance.now();
243
+ const tooltipKey = liveTooltipKey(nextTooltip, dataKeyRef.current);
244
+ const { commitFrame, commitTooltip } = shouldCommitLiveUpdates(
245
+ now,
246
+ lastFrameCommitRef.current,
247
+ tooltipKey,
248
+ lastTooltipKeyRef.current
249
+ );
250
+ if (!(commitFrame || commitTooltip)) {
251
+ raf = requestAnimationFrame(tick);
252
+ return;
253
+ }
254
+ if (commitFrame) {
255
+ lastFrameCommitRef.current = now;
256
+ }
257
+ if (commitTooltip) {
258
+ lastTooltipKeyRef.current = tooltipKey;
259
+ }
260
+ startTransition(() => {
261
+ if (commitFrame) {
262
+ setFrame(next);
263
+ }
264
+ if (commitTooltip) {
265
+ setTooltipData(nextTooltip);
266
+ }
267
+ });
268
+ raf = requestAnimationFrame(tick);
269
+ };
270
+ raf = requestAnimationFrame(tick);
271
+ return () => cancelAnimationFrame(raf);
272
+ }, [
273
+ targetRange,
274
+ value,
275
+ lerpSpeed,
276
+ leadingMs,
277
+ windowMs,
278
+ xTickUnitMs,
279
+ innerWidth,
280
+ innerHeight
281
+ ]);
282
+ const domainEndMs = frame.now + leadingMs;
283
+ const xScale = useMemo(
284
+ () => scaleTime().domain([new Date(domainEndMs - windowMs), new Date(domainEndMs)]).range([0, innerWidth]),
285
+ [domainEndMs, windowMs, innerWidth]
286
+ );
287
+ const yScale = useMemo(
288
+ () => scaleLinear().domain([frame.yMin, frame.yMax]).nice().range([innerHeight, 0]),
289
+ [frame.yMin, frame.yMax, innerHeight]
290
+ );
291
+ const contextData = useMemo(() => {
292
+ const windowStart = domainEndMs - windowMs;
293
+ let startIdx = bisectTime(data, windowStart / 1e3, 0);
294
+ if (startIdx > 0) {
295
+ startIdx--;
296
+ }
297
+ const sliced = data.slice(startIdx);
298
+ const records = sliced.map((p) => ({
299
+ date: new Date(p.time * 1e3),
300
+ [dataKey]: p.value
301
+ }));
302
+ records.push({
303
+ date: new Date(frame.now),
304
+ [dataKey]: frame.displayValue
305
+ });
306
+ records.push({
307
+ date: new Date(frame.now + xTickUnitMs),
308
+ [dataKey]: frame.displayValue
309
+ });
310
+ return records;
311
+ }, [
312
+ data,
313
+ frame.now,
314
+ frame.displayValue,
315
+ domainEndMs,
316
+ windowMs,
317
+ dataKey,
318
+ xTickUnitMs
319
+ ]);
320
+ const xAccessor = useCallback(
321
+ (d) => d.date instanceof Date ? d.date : new Date(d.date),
322
+ []
323
+ );
324
+ const handleMouseMove = useCallback(
325
+ (event) => {
326
+ const coords = localPoint(event);
327
+ if (!coords) {
328
+ return;
329
+ }
330
+ const x = coords.x - margin.left;
331
+ cursorXRef.current = x >= 0 && x <= innerWidth ? x : null;
332
+ },
333
+ [margin.left, innerWidth]
334
+ );
335
+ const handleMouseLeave = useCallback(() => {
336
+ cursorXRef.current = null;
337
+ lastTooltipKeyRef.current = null;
338
+ setTooltipData(null);
339
+ }, []);
340
+ const dateLabels = useMemo(
341
+ () => contextData.map((d) => hmsTimeFmt.format(xAccessor(d))),
342
+ [contextData, xAccessor]
343
+ );
344
+ const columnWidth = useMemo(() => {
345
+ if (contextData.length < 2) {
346
+ return 0;
347
+ }
348
+ return innerWidth / (contextData.length - 1);
349
+ }, [innerWidth, contextData.length]);
350
+ const clipExcludedChildren = [];
351
+ const underlayChildren = [];
352
+ const seriesChildren = [];
353
+ Children.forEach(children, (child) => {
354
+ if (!isValidElement(child)) {
355
+ return;
356
+ }
357
+ if (isClipExcludedComponent(child)) {
358
+ clipExcludedChildren.push(child);
359
+ } else if (isUnderlayComponent(child)) {
360
+ underlayChildren.push(child);
361
+ } else {
362
+ seriesChildren.push(child);
363
+ }
364
+ });
365
+ const referenceAreas = useMemo(
366
+ () => extractReferenceAreaConfigs(children),
367
+ [children]
368
+ );
369
+ const contextValue = useMemo(
370
+ () => ({
371
+ ...DEFAULT_CHART_LIFECYCLE,
372
+ data: contextData,
373
+ renderData: contextData,
374
+ xScale,
375
+ yScale,
376
+ yScales: wrapSingleYScale(yScale),
377
+ width,
378
+ height,
379
+ innerWidth,
380
+ innerHeight,
381
+ margin,
382
+ columnWidth,
383
+ tooltipData,
384
+ setTooltipData,
385
+ containerRef,
386
+ lines,
387
+ referenceAreas,
388
+ isLoaded: true,
389
+ animationDuration: 0,
390
+ xAccessor,
391
+ dateLabels
392
+ }),
393
+ [
394
+ contextData,
395
+ xScale,
396
+ yScale,
397
+ width,
398
+ height,
399
+ innerWidth,
400
+ innerHeight,
401
+ margin,
402
+ columnWidth,
403
+ tooltipData,
404
+ containerRef,
405
+ lines,
406
+ referenceAreas,
407
+ xAccessor,
408
+ dateLabels
409
+ ]
410
+ );
411
+ return /* @__PURE__ */ jsx(ChartProvider, { value: contextValue, children: /* @__PURE__ */ jsx(
412
+ "svg",
413
+ {
414
+ "aria-hidden": "true",
415
+ className: "overflow-visible",
416
+ height,
417
+ width,
418
+ children: /* @__PURE__ */ jsxs(
419
+ "g",
420
+ {
421
+ onMouseLeave: handleMouseLeave,
422
+ onMouseMove: handleMouseMove,
423
+ style: { cursor: "crosshair" },
424
+ transform: `translate(${margin.left},${margin.top})`,
425
+ children: [
426
+ /* @__PURE__ */ jsx(
427
+ "rect",
428
+ {
429
+ fill: "transparent",
430
+ height: innerHeight,
431
+ width: innerWidth,
432
+ x: 0,
433
+ y: 0
434
+ }
435
+ ),
436
+ clipExcludedChildren,
437
+ underlayChildren,
438
+ seriesChildren
439
+ ]
440
+ }
441
+ )
442
+ }
443
+ ) });
444
+ });
445
+ function LiveLineChart({
446
+ data,
447
+ value,
448
+ dataKey = "value",
449
+ window: windowSecs = 30,
450
+ numXTicks = 5,
451
+ nowOffsetUnits = 0,
452
+ exaggerate = false,
453
+ lerpSpeed = LERP_SPEED,
454
+ margin: marginProp,
455
+ paused = false,
456
+ children,
457
+ className,
458
+ style
459
+ }) {
460
+ const containerRef = useRef(null);
461
+ const margin = { ...DEFAULT_MARGIN, ...marginProp };
462
+ return /* @__PURE__ */ jsx(LazyMotion, { features: domAnimation, children: /* @__PURE__ */ jsx(
463
+ "div",
464
+ {
465
+ className: cn("relative w-full", className),
466
+ ref: containerRef,
467
+ style: { height: 300, touchAction: "none", ...style },
468
+ children: /* @__PURE__ */ jsx(ParentSize, { debounceTime: 10, children: ({ width, height }) => /* @__PURE__ */ jsx(
469
+ LiveLineChartInner,
470
+ {
471
+ containerRef,
472
+ data,
473
+ dataKey,
474
+ exaggerate,
475
+ height,
476
+ lerpSpeed,
477
+ margin,
478
+ nowOffsetUnits,
479
+ numXTicks,
480
+ paused,
481
+ value,
482
+ width,
483
+ windowSecs,
484
+ children
485
+ }
486
+ ) })
487
+ }
488
+ ) });
489
+ }
490
+ var live_line_chart_default = LiveLineChart;
491
+ export {
492
+ LiveLineChart,
493
+ live_line_chart_default as default
494
+ };