@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,337 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import {
4
+ scaleLinear
5
+ } from "d3-scale";
6
+ import {
7
+ createContext,
8
+ useContext,
9
+ useEffect,
10
+ useLayoutEffect,
11
+ useMemo,
12
+ useState,
13
+ useSyncExternalStore
14
+ } from "react";
15
+ import { DEFAULT_Y_AXIS_ID } from "./y-axis-scales";
16
+ const chartCssVars = {
17
+ background: "var(--chart-background)",
18
+ foreground: "var(--chart-foreground)",
19
+ foregroundMuted: "var(--chart-foreground-muted)",
20
+ label: "var(--chart-label)",
21
+ linePrimary: "var(--chart-line-primary)",
22
+ lineSecondary: "var(--chart-line-secondary)",
23
+ crosshair: "var(--chart-crosshair)",
24
+ grid: "var(--chart-grid)",
25
+ indicatorColor: "var(--chart-indicator-color)",
26
+ indicatorSecondaryColor: "var(--chart-indicator-secondary-color)",
27
+ markerBackground: "var(--chart-marker-background)",
28
+ markerBorder: "var(--chart-marker-border)",
29
+ markerForeground: "var(--chart-marker-foreground)",
30
+ badgeBackground: "var(--chart-marker-badge-background)",
31
+ badgeForeground: "var(--chart-marker-badge-foreground)",
32
+ segmentBackground: "var(--chart-segment-background)",
33
+ segmentLine: "var(--chart-segment-line)",
34
+ brushBorder: "var(--chart-brush-border)",
35
+ tooltipBackground: "var(--chart-tooltip-background)"
36
+ };
37
+ const defaultScatterColors = [
38
+ "var(--chart-1)",
39
+ "var(--chart-2)",
40
+ "var(--chart-3)",
41
+ "var(--chart-4)",
42
+ "var(--chart-5)"
43
+ ];
44
+ const DISCRETE_INTERACTION_LABEL_THRESHOLD = 60;
45
+ const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
46
+ const ChartStableContext = createContext(null);
47
+ const ChartHoverContext = createContext(null);
48
+ const ChartHoverStoreContext = createContext(null);
49
+ function createChartHoverStore() {
50
+ const listeners = /* @__PURE__ */ new Set();
51
+ let tooltipData = null;
52
+ let selection = null;
53
+ const emit = () => {
54
+ snapshot = { ...snapshot, tooltipData, selection };
55
+ for (const listener of listeners) {
56
+ listener();
57
+ }
58
+ };
59
+ const setTooltipData = (action) => {
60
+ const next = typeof action === "function" ? action(tooltipData) : action;
61
+ if (next === tooltipData) {
62
+ return;
63
+ }
64
+ tooltipData = next;
65
+ emit();
66
+ };
67
+ const setSelection = (next) => {
68
+ if (next === selection) {
69
+ return;
70
+ }
71
+ selection = next;
72
+ emit();
73
+ };
74
+ let snapshot = {
75
+ tooltipData,
76
+ setTooltipData,
77
+ selection,
78
+ clearSelection: () => setSelection(null)
79
+ };
80
+ return {
81
+ getSnapshot: () => snapshot,
82
+ subscribe: (listener) => {
83
+ listeners.add(listener);
84
+ return () => {
85
+ listeners.delete(listener);
86
+ };
87
+ },
88
+ setTooltipData,
89
+ setSelection
90
+ };
91
+ }
92
+ const noop = () => void 0;
93
+ function staticChartHoverStore(value) {
94
+ return {
95
+ getSnapshot: () => value,
96
+ subscribe: () => noop
97
+ };
98
+ }
99
+ function ChartHoverStoreProvider({
100
+ children,
101
+ store
102
+ }) {
103
+ const hover = useSyncExternalStore(
104
+ store.subscribe,
105
+ store.getSnapshot,
106
+ store.getSnapshot
107
+ );
108
+ return /* @__PURE__ */ jsx(ChartHoverStoreContext.Provider, { value: store, children: /* @__PURE__ */ jsx(ChartHoverContext.Provider, { value: hover, children }) });
109
+ }
110
+ function ChartProvider({
111
+ children,
112
+ value
113
+ }) {
114
+ const stable = useMemo(
115
+ () => ({
116
+ data: value.data,
117
+ renderData: value.renderData,
118
+ xScale: value.xScale,
119
+ yScale: value.yScale,
120
+ yScales: value.yScales,
121
+ width: value.width,
122
+ height: value.height,
123
+ innerWidth: value.innerWidth,
124
+ innerHeight: value.innerHeight,
125
+ margin: value.margin,
126
+ columnWidth: value.columnWidth,
127
+ containerRef: value.containerRef,
128
+ lines: value.lines,
129
+ bands: value.bands,
130
+ referenceAreas: value.referenceAreas,
131
+ chartPhase: value.chartPhase,
132
+ chartStatus: value.chartStatus,
133
+ loadingLabel: value.loadingLabel,
134
+ yDomainTweenDuration: value.yDomainTweenDuration,
135
+ yDomainSkeletonByAxis: value.yDomainSkeletonByAxis,
136
+ yDomainTargetByAxis: value.yDomainTargetByAxis,
137
+ isLoaded: value.isLoaded,
138
+ animationDuration: value.animationDuration,
139
+ animationEasing: value.animationEasing,
140
+ enterTransition: value.enterTransition,
141
+ revealEpoch: value.revealEpoch,
142
+ notifyLoadingPulseComplete: value.notifyLoadingPulseComplete,
143
+ xAccessor: value.xAccessor,
144
+ dateLabels: value.dateLabels,
145
+ xDomain: value.xDomain,
146
+ xDomainSlotCount: value.xDomainSlotCount,
147
+ barScale: value.barScale,
148
+ bandWidth: value.bandWidth,
149
+ barXAccessor: value.barXAccessor,
150
+ orientation: value.orientation,
151
+ stacked: value.stacked,
152
+ stackOffsets: value.stackOffsets,
153
+ composedBarDataKeys: value.composedBarDataKeys,
154
+ composedBarSize: value.composedBarSize,
155
+ composedMaxBarSize: value.composedMaxBarSize,
156
+ composedBarGap: value.composedBarGap,
157
+ composedStacked: value.composedStacked,
158
+ composedStackOffsets: value.composedStackOffsets,
159
+ composedStackGap: value.composedStackGap,
160
+ nearestPointHover: value.nearestPointHover
161
+ }),
162
+ [
163
+ value.data,
164
+ value.renderData,
165
+ value.xScale,
166
+ value.yScale,
167
+ value.yScales,
168
+ value.width,
169
+ value.height,
170
+ value.innerWidth,
171
+ value.innerHeight,
172
+ value.margin,
173
+ value.columnWidth,
174
+ value.containerRef,
175
+ value.lines,
176
+ value.bands,
177
+ value.referenceAreas,
178
+ value.chartPhase,
179
+ value.chartStatus,
180
+ value.loadingLabel,
181
+ value.yDomainTweenDuration,
182
+ value.yDomainSkeletonByAxis,
183
+ value.yDomainTargetByAxis,
184
+ value.isLoaded,
185
+ value.animationDuration,
186
+ value.animationEasing,
187
+ value.enterTransition,
188
+ value.revealEpoch,
189
+ value.notifyLoadingPulseComplete,
190
+ value.xAccessor,
191
+ value.dateLabels,
192
+ value.xDomain,
193
+ value.xDomainSlotCount,
194
+ value.barScale,
195
+ value.bandWidth,
196
+ value.barXAccessor,
197
+ value.orientation,
198
+ value.stacked,
199
+ value.stackOffsets,
200
+ value.composedBarDataKeys,
201
+ value.composedBarSize,
202
+ value.composedMaxBarSize,
203
+ value.composedBarGap,
204
+ value.composedStacked,
205
+ value.composedStackOffsets,
206
+ value.composedStackGap,
207
+ value.nearestPointHover
208
+ ]
209
+ );
210
+ const hover = useMemo(
211
+ () => ({
212
+ tooltipData: value.tooltipData,
213
+ setTooltipData: value.setTooltipData,
214
+ selection: value.selection,
215
+ clearSelection: value.clearSelection,
216
+ hoveredBarIndex: value.hoveredBarIndex,
217
+ setHoveredBarIndex: value.setHoveredBarIndex,
218
+ hoveredCandleIndex: value.hoveredCandleIndex,
219
+ setHoveredCandleIndex: value.setHoveredCandleIndex
220
+ }),
221
+ [
222
+ value.tooltipData,
223
+ value.setTooltipData,
224
+ value.selection,
225
+ value.clearSelection,
226
+ value.hoveredBarIndex,
227
+ value.setHoveredBarIndex,
228
+ value.hoveredCandleIndex,
229
+ value.setHoveredCandleIndex
230
+ ]
231
+ );
232
+ const hoverStore = useMemo(() => staticChartHoverStore(hover), [hover]);
233
+ return /* @__PURE__ */ jsx(ChartStableContext.Provider, { value: stable, children: /* @__PURE__ */ jsx(ChartHoverStoreContext.Provider, { value: hoverStore, children: /* @__PURE__ */ jsx(ChartHoverContext.Provider, { value: hover, children }) }) });
234
+ }
235
+ const ChartStableContextProvider = ChartStableContext.Provider;
236
+ function useChartStable() {
237
+ const context = useContext(ChartStableContext);
238
+ if (!context) {
239
+ throw new Error(
240
+ "useChartStable must be used within a ChartProvider. Make sure your component is wrapped in <LineChart>, <AreaChart>, <BarChart>, or <ComposedChart>."
241
+ );
242
+ }
243
+ return context;
244
+ }
245
+ function useChartPortalContainer(containerRef) {
246
+ const [container, setContainer] = useState(
247
+ () => containerRef?.current ?? null
248
+ );
249
+ useIsomorphicLayoutEffect(() => {
250
+ setContainer(containerRef?.current ?? null);
251
+ }, [containerRef]);
252
+ useEffect(() => {
253
+ const element = containerRef?.current ?? null;
254
+ setContainer((previous) => previous === element ? previous : element);
255
+ }, [containerRef]);
256
+ return container;
257
+ }
258
+ function useStableMargin(margin) {
259
+ const { top, right, bottom, left } = margin;
260
+ return useMemo(
261
+ () => ({ top, right, bottom, left }),
262
+ [top, right, bottom, left]
263
+ );
264
+ }
265
+ function useYScale(yAxisId) {
266
+ const { yScales, yScale } = useChartStable();
267
+ const id = yAxisId == null || yAxisId === "" ? DEFAULT_Y_AXIS_ID : String(yAxisId);
268
+ return yScales[id] ?? yScale;
269
+ }
270
+ function useSettledYScale(yAxisId) {
271
+ const { yDomainTargetByAxis, innerHeight } = useChartStable();
272
+ const liveScale = useYScale(yAxisId);
273
+ const id = yAxisId == null || yAxisId === "" ? DEFAULT_Y_AXIS_ID : String(yAxisId);
274
+ const domain = yDomainTargetByAxis?.[id] ?? yDomainTargetByAxis?.[DEFAULT_Y_AXIS_ID];
275
+ const min = domain?.[0];
276
+ const max = domain?.[1];
277
+ const settled = useMemo(
278
+ () => min == null || max == null ? null : scaleLinear().domain([min, max]).range([innerHeight, 0]),
279
+ [min, max, innerHeight]
280
+ );
281
+ return settled ?? liveScale;
282
+ }
283
+ function useChartHover() {
284
+ const context = useContext(ChartHoverContext);
285
+ if (!context) {
286
+ throw new Error(
287
+ "useChartHover must be used within a ChartProvider. Make sure your component is wrapped in <LineChart>, <AreaChart>, <BarChart>, or <ComposedChart>."
288
+ );
289
+ }
290
+ return context;
291
+ }
292
+ function useChartHoverSelector(selector) {
293
+ const store = useContext(ChartHoverStoreContext);
294
+ if (!store) {
295
+ throw new Error(
296
+ "useChartHoverSelector must be used within a ChartProvider. Make sure your component is wrapped in <LineChart>, <AreaChart>, <BarChart>, or <ComposedChart>."
297
+ );
298
+ }
299
+ const getSelected = () => selector(store.getSnapshot());
300
+ return useSyncExternalStore(store.subscribe, getSelected, getSelected);
301
+ }
302
+ function useChartHoverStore() {
303
+ return useContext(ChartHoverStoreContext);
304
+ }
305
+ function selectTooltipData(hover) {
306
+ return hover.tooltipData;
307
+ }
308
+ function selectIsChartHovering(hover) {
309
+ return hover.tooltipData !== null || hover.selection?.active === true;
310
+ }
311
+ function useChart() {
312
+ const stable = useChartStable();
313
+ const hover = useChartHover();
314
+ return { ...stable, ...hover };
315
+ }
316
+ var chart_context_default = ChartStableContext;
317
+ export {
318
+ ChartHoverStoreProvider,
319
+ ChartProvider,
320
+ ChartStableContextProvider,
321
+ DISCRETE_INTERACTION_LABEL_THRESHOLD,
322
+ chartCssVars,
323
+ createChartHoverStore,
324
+ chart_context_default as default,
325
+ defaultScatterColors,
326
+ selectIsChartHovering,
327
+ selectTooltipData,
328
+ useChart,
329
+ useChartHover,
330
+ useChartHoverSelector,
331
+ useChartHoverStore,
332
+ useChartPortalContainer,
333
+ useChartStable,
334
+ useSettledYScale,
335
+ useStableMargin,
336
+ useYScale
337
+ };
@@ -0,0 +1,262 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import NumberFlow from "@number-flow/react";
4
+ import { m, useReducedMotion, useSpring } from "motion/react";
5
+ import { memo, useEffect, useMemo, useRef, useState } from "react";
6
+ import { createPortal } from "react-dom";
7
+ import { useChartConfig } from "./chart-config-context";
8
+ import {
9
+ chartCssVars,
10
+ useChartHoverStore,
11
+ useChartPortalContainer,
12
+ useChartStable
13
+ } from "./chart-context";
14
+ import {
15
+ useNumberFlowElementReady
16
+ } from "./chart-stat-flow";
17
+ import { setCrosshairY } from "./crosshair-store";
18
+ import { normalizeYAxisId } from "./y-axis-scales";
19
+ const DEFAULT_FORMAT = { maximumFractionDigits: 2 };
20
+ const PILL_TEXT_INSET = 8 - 16;
21
+ const NUMBER_FLOW_UPDATE_MS = 120;
22
+ const NUMBER_FLOW_TIMING = {
23
+ duration: 350,
24
+ easing: "cubic-bezier(0.23, 1, 0.32, 1)"
25
+ };
26
+ function drive(value, target, instant) {
27
+ if (instant) {
28
+ value.jump(target);
29
+ } else {
30
+ value.set(target);
31
+ }
32
+ }
33
+ function ChartCrosshair(props) {
34
+ const { containerRef } = useChartStable();
35
+ const container = useChartPortalContainer(containerRef);
36
+ if (!container) {
37
+ return null;
38
+ }
39
+ return /* @__PURE__ */ jsx(ChartCrosshairInner, { ...props, container });
40
+ }
41
+ ChartCrosshair.displayName = "ChartCrosshair";
42
+ const ChartCrosshairInner = memo(function ChartCrosshairInner2({
43
+ container,
44
+ yAxisId,
45
+ horizontal = true,
46
+ vertical = true,
47
+ snap = true,
48
+ side,
49
+ showValueLabel = true,
50
+ numberFlow = false,
51
+ format = DEFAULT_FORMAT,
52
+ prefix,
53
+ suffix,
54
+ formatValue,
55
+ stroke = chartCssVars.crosshair,
56
+ strokeDasharray = "3,3",
57
+ strokeWidth = 1,
58
+ springConfig
59
+ }) {
60
+ const { margin, innerWidth, innerHeight, yScales, yScale } = useChartStable();
61
+ const hoverStore = useChartHoverStore();
62
+ const { tooltipSpring } = useChartConfig();
63
+ const reduceMotion = useReducedMotion() === true;
64
+ const numberFlowReady = useNumberFlowElementReady();
65
+ const spring = springConfig ?? tooltipSpring;
66
+ const axisId = normalizeYAxisId(yAxisId);
67
+ const scale = yScales[axisId] ?? yScale;
68
+ const resolvedSide = side ?? (axisId === "right" ? "right" : "left");
69
+ const showPill = horizontal && showValueLabel;
70
+ const useFlow = showPill && numberFlow && numberFlowReady;
71
+ const springX = useSpring(0, spring);
72
+ const springY = useSpring(0, spring);
73
+ const rootRef = useRef(null);
74
+ const labelRef = useRef(null);
75
+ const [flowValue, setFlowValue] = useState(0);
76
+ const formatLabel = useMemo(() => {
77
+ if (formatValue) {
78
+ return formatValue;
79
+ }
80
+ const intl = new Intl.NumberFormat(void 0, format);
81
+ return (value) => `${prefix ?? ""}${intl.format(value)}${suffix ?? ""}`;
82
+ }, [formatValue, format, prefix, suffix]);
83
+ const latest = {
84
+ scale,
85
+ margin,
86
+ innerWidth,
87
+ innerHeight,
88
+ snap,
89
+ axisId,
90
+ showPill,
91
+ useFlow,
92
+ reduceMotion,
93
+ formatLabel
94
+ };
95
+ const live = useRef(latest);
96
+ live.current = latest;
97
+ useEffect(() => {
98
+ let rect = null;
99
+ let visible = false;
100
+ let lastLabel = "";
101
+ let lastFlowAt = 0;
102
+ let flowTimer;
103
+ let pendingFlow = null;
104
+ const snappedX = () => hoverStore?.getSnapshot().tooltipData?.x ?? null;
105
+ const flushFlow = () => {
106
+ flowTimer = void 0;
107
+ if (pendingFlow !== null) {
108
+ lastFlowAt = performance.now();
109
+ setFlowValue(pendingFlow);
110
+ pendingFlow = null;
111
+ }
112
+ };
113
+ const setVisible = (next) => {
114
+ if (visible === next) {
115
+ return;
116
+ }
117
+ visible = next;
118
+ if (rootRef.current) {
119
+ rootRef.current.style.visibility = next ? "visible" : "hidden";
120
+ }
121
+ if (!next) {
122
+ lastLabel = "";
123
+ setCrosshairY(container, null);
124
+ }
125
+ };
126
+ const updateLabel = (y) => {
127
+ const s = live.current;
128
+ setCrosshairY(container, { y, axisId: s.axisId });
129
+ const value = s.scale.invert(y);
130
+ const label = s.formatLabel(value);
131
+ if (label === lastLabel) {
132
+ return;
133
+ }
134
+ lastLabel = label;
135
+ if (!s.useFlow) {
136
+ if (labelRef.current) {
137
+ labelRef.current.textContent = label;
138
+ }
139
+ return;
140
+ }
141
+ pendingFlow = value;
142
+ const wait = NUMBER_FLOW_UPDATE_MS - (performance.now() - lastFlowAt);
143
+ if (wait <= 0) {
144
+ flushFlow();
145
+ } else {
146
+ flowTimer ??= setTimeout(flushFlow, wait);
147
+ }
148
+ };
149
+ const onMove = (event) => {
150
+ rect ??= container.getBoundingClientRect();
151
+ const s = live.current;
152
+ const x = event.clientX - rect.left - s.margin.left;
153
+ const y = event.clientY - rect.top - s.margin.top;
154
+ if (x < 0 || x > s.innerWidth || y < 0 || y > s.innerHeight) {
155
+ setVisible(false);
156
+ return;
157
+ }
158
+ const instant = !visible || s.reduceMotion;
159
+ drive(springY, y, instant);
160
+ drive(springX, s.snap ? snappedX() ?? x : x, instant);
161
+ setVisible(true);
162
+ if (s.showPill) {
163
+ updateLabel(y);
164
+ }
165
+ };
166
+ const onLeave = () => {
167
+ rect = null;
168
+ setVisible(false);
169
+ };
170
+ const invalidate = () => {
171
+ rect = null;
172
+ };
173
+ const unsubscribe = hoverStore?.subscribe(() => {
174
+ if (!(visible && live.current.snap)) {
175
+ return;
176
+ }
177
+ const x = snappedX();
178
+ if (x !== null) {
179
+ drive(springX, x, live.current.reduceMotion);
180
+ }
181
+ });
182
+ container.addEventListener("pointermove", onMove);
183
+ container.addEventListener("pointerleave", onLeave);
184
+ window.addEventListener("scroll", invalidate, {
185
+ capture: true,
186
+ passive: true
187
+ });
188
+ window.addEventListener("resize", invalidate, { passive: true });
189
+ return () => {
190
+ container.removeEventListener("pointermove", onMove);
191
+ container.removeEventListener("pointerleave", onLeave);
192
+ window.removeEventListener("scroll", invalidate, { capture: true });
193
+ window.removeEventListener("resize", invalidate);
194
+ unsubscribe?.();
195
+ clearTimeout(flowTimer);
196
+ setCrosshairY(container, null);
197
+ };
198
+ }, [container, hoverStore, springX, springY]);
199
+ return createPortal(
200
+ /* @__PURE__ */ jsxs(
201
+ "div",
202
+ {
203
+ "aria-hidden": "true",
204
+ className: "pointer-events-none absolute inset-0",
205
+ ref: rootRef,
206
+ style: { visibility: "hidden" },
207
+ children: [
208
+ /* @__PURE__ */ jsx(
209
+ "svg",
210
+ {
211
+ "aria-hidden": "true",
212
+ className: "absolute inset-0 overflow-visible",
213
+ height: "100%",
214
+ width: "100%",
215
+ children: /* @__PURE__ */ jsxs(
216
+ "g",
217
+ {
218
+ shapeRendering: "crispEdges",
219
+ stroke,
220
+ strokeDasharray,
221
+ strokeWidth,
222
+ transform: `translate(${margin.left},${margin.top})`,
223
+ children: [
224
+ horizontal && /* @__PURE__ */ jsx(m.line, { x1: 0, x2: innerWidth, y1: springY, y2: springY }),
225
+ vertical && /* @__PURE__ */ jsx(m.line, { x1: springX, x2: springX, y1: 0, y2: innerHeight })
226
+ ]
227
+ }
228
+ )
229
+ }
230
+ ),
231
+ showPill && /* @__PURE__ */ jsx(
232
+ m.div,
233
+ {
234
+ className: "absolute z-50 w-max",
235
+ style: {
236
+ top: margin.top,
237
+ y: springY,
238
+ ...resolvedSide === "right" ? { left: margin.left + innerWidth + PILL_TEXT_INSET } : { right: `calc(100% - ${margin.left - PILL_TEXT_INSET}px)` }
239
+ },
240
+ children: /* @__PURE__ */ jsx("div", { className: "-translate-y-1/2 overflow-hidden rounded-full bg-chart-pill px-4 py-1 text-chart-pill-foreground shadow-lg", children: /* @__PURE__ */ jsx("div", { className: "flex h-6 items-center whitespace-nowrap font-medium text-sm tabular-nums", children: useFlow ? /* @__PURE__ */ jsx(
241
+ NumberFlow,
242
+ {
243
+ format,
244
+ isolate: true,
245
+ prefix,
246
+ spinTiming: NUMBER_FLOW_TIMING,
247
+ suffix,
248
+ transformTiming: NUMBER_FLOW_TIMING,
249
+ value: flowValue
250
+ }
251
+ ) : /* @__PURE__ */ jsx("span", { ref: labelRef }) }) })
252
+ }
253
+ )
254
+ ]
255
+ }
256
+ ),
257
+ container
258
+ );
259
+ });
260
+ export {
261
+ ChartCrosshair
262
+ };