@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,516 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { m, useReducedMotion, useSpring } from "motion/react";
4
+ import { memo, useEffect, useMemo } from "react";
5
+ import { createPortal } from "react-dom";
6
+ import {
7
+ resolveTooltipBoxMotion,
8
+ useChartConfig
9
+ } from "../chart-config-context";
10
+ import {
11
+ chartCssVars,
12
+ DISCRETE_INTERACTION_LABEL_THRESHOLD,
13
+ useChart,
14
+ useChartPortalContainer,
15
+ useChartStable
16
+ } from "../chart-context";
17
+ import { formatBandRange, weekdayDateFmt } from "../chart-formatters";
18
+ import { registerDatePill } from "../date-pill-store";
19
+ import {
20
+ DateTicker
21
+ } from "./date-ticker";
22
+ import { TooltipBox } from "./tooltip-box";
23
+ import { TooltipContent } from "./tooltip-content";
24
+ import { TooltipDot } from "./tooltip-dot";
25
+ import { TooltipIndicator } from "./tooltip-indicator";
26
+ import {
27
+ resolveDatePillVelocity,
28
+ useVelocityStretch
29
+ } from "./use-velocity-stretch";
30
+ function resolveActivePoint(tooltipData, lines) {
31
+ if (!tooltipData) {
32
+ return null;
33
+ }
34
+ const { activeDataKey, xPositions, yPositions } = tooltipData;
35
+ const hasY = (line2) => yPositions[line2.dataKey] !== void 0;
36
+ const line = lines.find((l) => l.dataKey === activeDataKey && hasY(l)) ?? lines.find(hasY);
37
+ const y = line ? yPositions[line.dataKey] : void 0;
38
+ if (!line || y === void 0) {
39
+ return null;
40
+ }
41
+ return {
42
+ line,
43
+ index: lines.indexOf(line),
44
+ x: xPositions?.[line.dataKey] ?? tooltipData.x,
45
+ y
46
+ };
47
+ }
48
+ function resolveTopmostPointY(tooltipData, lines) {
49
+ if (!tooltipData) {
50
+ return void 0;
51
+ }
52
+ let topmost;
53
+ for (const line of lines) {
54
+ const y = tooltipData.yPositions[line.dataKey];
55
+ if (y !== void 0 && (topmost === void 0 || y < topmost)) {
56
+ topmost = y;
57
+ }
58
+ }
59
+ return topmost;
60
+ }
61
+ function resolveBoxPlacement({
62
+ activePoint,
63
+ tooltipData,
64
+ lines,
65
+ margin,
66
+ isHorizontal,
67
+ xWithMargin,
68
+ topOffset
69
+ }) {
70
+ if (activePoint) {
71
+ return {
72
+ flipX: xWithMargin,
73
+ replayOnFlip: false,
74
+ x: activePoint.x + margin.left,
75
+ y: activePoint.y + margin.top
76
+ };
77
+ }
78
+ if (isHorizontal) {
79
+ const firstLineDataKey = lines[0]?.dataKey;
80
+ const firstLineY = firstLineDataKey ? tooltipData?.yPositions[firstLineDataKey] ?? 0 : 0;
81
+ return { x: xWithMargin, y: firstLineY + margin.top };
82
+ }
83
+ const top = margin.top + topOffset;
84
+ return { top, x: xWithMargin, y: top };
85
+ }
86
+ const ChartTooltipInner = memo(function ChartTooltipInner2({
87
+ showDatePill = true,
88
+ datePillAnimation,
89
+ datePillVariant,
90
+ datePillVelocity,
91
+ datePillClassName,
92
+ datePillStyle,
93
+ datePill,
94
+ showCrosshair: showCrosshairProp,
95
+ showDots = true,
96
+ dotVariant = "dot",
97
+ dotSize = 5,
98
+ dotHaloScale,
99
+ dotHaloOpacity,
100
+ dotHaloBlur,
101
+ dotRadiusFraction,
102
+ dotScale = 1,
103
+ dotStrokeWidth,
104
+ indicatorColor: indicatorColorProp,
105
+ indicatorEndColor,
106
+ indicatorEnd = "plot",
107
+ content,
108
+ rows: rowsRenderer,
109
+ dotColor: dotColorProp,
110
+ children,
111
+ className = "",
112
+ container,
113
+ springConfig,
114
+ matchCrosshair = false,
115
+ damping,
116
+ indicatorDasharray,
117
+ indicatorFadeEdges,
118
+ indicatorFadeLength,
119
+ boxSpringConfig,
120
+ panelStyle,
121
+ backgroundColor,
122
+ dateLabels: dateLabelsProp,
123
+ exit = true,
124
+ animateSize = true,
125
+ topOffset = 0
126
+ }) {
127
+ const {
128
+ tooltipData,
129
+ width,
130
+ height,
131
+ innerHeight,
132
+ margin,
133
+ columnWidth,
134
+ lines,
135
+ bands,
136
+ xAccessor,
137
+ dateLabels: contextDateLabels,
138
+ containerRef,
139
+ orientation,
140
+ barXAccessor,
141
+ bandWidth,
142
+ squareSnap,
143
+ nearestPointHover
144
+ } = useChart();
145
+ const tooltipBands = useMemo(
146
+ () => (bands ?? []).filter((band) => band.showInTooltip),
147
+ [bands]
148
+ );
149
+ const { tooltipSpring } = useChartConfig();
150
+ const dateLabels = dateLabelsProp ?? contextDateLabels;
151
+ const isHorizontal = orientation === "horizontal";
152
+ const datePillEnabled = showDatePill && !isHorizontal && dateLabels.length > 0;
153
+ useEffect(() => {
154
+ if (!datePillEnabled) {
155
+ return;
156
+ }
157
+ return registerDatePill(container);
158
+ }, [container, datePillEnabled]);
159
+ const showCrosshair = showCrosshairProp ?? !(barXAccessor || nearestPointHover);
160
+ const discreteInteraction = dateLabels.length > DISCRETE_INTERACTION_LABEL_THRESHOLD;
161
+ const resolvedDotSize = useMemo(() => {
162
+ if (dotVariant !== "ring" || !bandWidth || lines.length === 0) {
163
+ return dotSize * dotScale;
164
+ }
165
+ const seriesCount = lines.length;
166
+ const gap = squareSnap?.groupGap ?? (seriesCount > 1 ? 4 : 0);
167
+ const squareSize = (bandWidth - gap * (seriesCount - 1)) / seriesCount;
168
+ return squareSize / 2 * dotScale;
169
+ }, [
170
+ bandWidth,
171
+ dotScale,
172
+ dotSize,
173
+ dotVariant,
174
+ lines.length,
175
+ squareSnap?.groupGap
176
+ ]);
177
+ const boxMotion = useMemo(() => {
178
+ if (boxSpringConfig) {
179
+ return {
180
+ animate: !discreteInteraction,
181
+ springConfig: boxSpringConfig
182
+ };
183
+ }
184
+ if (matchCrosshair) {
185
+ return {
186
+ animate: !discreteInteraction,
187
+ springConfig: springConfig ?? tooltipSpring
188
+ };
189
+ }
190
+ return resolveTooltipBoxMotion(damping);
191
+ }, [
192
+ boxSpringConfig,
193
+ damping,
194
+ discreteInteraction,
195
+ matchCrosshair,
196
+ springConfig,
197
+ tooltipSpring
198
+ ]);
199
+ const visible = tooltipData !== null;
200
+ const x = tooltipData?.x ?? 0;
201
+ const xWithMargin = x + margin.left;
202
+ const activePoint = nearestPointHover ? resolveActivePoint(tooltipData, lines) : null;
203
+ const boxPlacement = resolveBoxPlacement({
204
+ activePoint,
205
+ tooltipData,
206
+ lines,
207
+ margin,
208
+ isHorizontal,
209
+ xWithMargin,
210
+ topOffset
211
+ });
212
+ const tooltipRows = useMemo(() => {
213
+ if (!tooltipData) {
214
+ return [];
215
+ }
216
+ if (rowsRenderer) {
217
+ return rowsRenderer(tooltipData.point);
218
+ }
219
+ const rowLines = nearestPointHover ? lines.filter(
220
+ (line) => typeof tooltipData.point[line.dataKey] === "number"
221
+ ) : lines;
222
+ const rows = rowLines.map((line) => ({
223
+ color: line.stroke,
224
+ label: line.dataKey,
225
+ value: tooltipData.point[line.dataKey] ?? 0
226
+ }));
227
+ for (const band of tooltipBands) {
228
+ const value = formatBandRange(
229
+ tooltipData.point,
230
+ band.upperKey,
231
+ band.lowerKey
232
+ );
233
+ if (value != null) {
234
+ rows.push({ color: band.color, label: band.label, value });
235
+ }
236
+ }
237
+ return rows;
238
+ }, [tooltipData, lines, tooltipBands, rowsRenderer, nearestPointHover]);
239
+ const bandDots = useMemo(() => {
240
+ const lineKeys = new Set(lines.map((line) => line.dataKey));
241
+ const seen = /* @__PURE__ */ new Set();
242
+ const dots = [];
243
+ for (const band of tooltipBands) {
244
+ for (const key of [band.upperKey, band.lowerKey]) {
245
+ if (lineKeys.has(key) || seen.has(key)) {
246
+ continue;
247
+ }
248
+ seen.add(key);
249
+ dots.push({ key, color: band.color });
250
+ }
251
+ }
252
+ return dots;
253
+ }, [lines, tooltipBands]);
254
+ const resolveDotColor = useMemo(() => {
255
+ return (line, index) => {
256
+ if (rowsRenderer && tooltipRows[index]?.color) {
257
+ return tooltipRows[index].color;
258
+ }
259
+ if (dotColorProp != null) {
260
+ if (typeof dotColorProp === "function" && tooltipData) {
261
+ return dotColorProp(tooltipData.point, line);
262
+ }
263
+ if (typeof dotColorProp === "string") {
264
+ return dotColorProp;
265
+ }
266
+ }
267
+ return line.stroke;
268
+ };
269
+ }, [dotColorProp, rowsRenderer, tooltipData, tooltipRows]);
270
+ const indicatorColor = useMemo(() => {
271
+ if (indicatorColorProp == null) {
272
+ return chartCssVars.crosshair;
273
+ }
274
+ if (typeof indicatorColorProp === "function") {
275
+ return tooltipData ? indicatorColorProp(tooltipData.point) : chartCssVars.crosshair;
276
+ }
277
+ return indicatorColorProp;
278
+ }, [indicatorColorProp, tooltipData]);
279
+ const indicatorBottom = indicatorEnd === "point" ? resolveTopmostPointY(tooltipData, lines) : void 0;
280
+ const title = useMemo(() => {
281
+ if (!tooltipData) {
282
+ return void 0;
283
+ }
284
+ if (barXAccessor) {
285
+ return barXAccessor(tooltipData.point);
286
+ }
287
+ return weekdayDateFmt.format(xAccessor(tooltipData.point));
288
+ }, [tooltipData, barXAccessor, xAccessor]);
289
+ const tooltipContent = /* @__PURE__ */ jsxs(Fragment, { children: [
290
+ showCrosshair && visible && /* @__PURE__ */ jsx(
291
+ "svg",
292
+ {
293
+ "aria-hidden": "true",
294
+ className: "pointer-events-none absolute inset-0 overflow-visible",
295
+ height: "100%",
296
+ width: "100%",
297
+ children: /* @__PURE__ */ jsx("g", { transform: `translate(${margin.left},${margin.top})`, children: /* @__PURE__ */ jsx(
298
+ TooltipIndicator,
299
+ {
300
+ animate: !discreteInteraction,
301
+ bottom: indicatorBottom,
302
+ colorEdge: indicatorColor,
303
+ colorEnd: indicatorEndColor,
304
+ colorMid: indicatorColor,
305
+ columnWidth,
306
+ fadeEdges: indicatorDasharray ? "none" : indicatorFadeEdges ?? "both",
307
+ fadeLength: indicatorFadeLength,
308
+ height: innerHeight,
309
+ springConfig,
310
+ strokeDasharray: indicatorDasharray,
311
+ visible,
312
+ width: "line",
313
+ x
314
+ }
315
+ ) })
316
+ }
317
+ ),
318
+ showDots && visible && !isHorizontal && /* @__PURE__ */ jsx(
319
+ "svg",
320
+ {
321
+ "aria-hidden": "true",
322
+ className: "pointer-events-none absolute inset-0 overflow-visible",
323
+ height: "100%",
324
+ width: "100%",
325
+ children: /* @__PURE__ */ jsxs("g", { transform: `translate(${margin.left},${margin.top})`, children: [
326
+ nearestPointHover ? (
327
+ // One dot that springs between points (any series) instead of
328
+ // one per series mounting / unmounting as rows change.
329
+ activePoint && /* @__PURE__ */ jsx(
330
+ TooltipDot,
331
+ {
332
+ animate: !discreteInteraction,
333
+ color: resolveDotColor(activePoint.line, activePoint.index),
334
+ cornerRadiusFraction: dotVariant === "ring" ? dotRadiusFraction : void 0,
335
+ haloBlur: dotHaloBlur,
336
+ haloOpacity: dotHaloOpacity,
337
+ haloScale: dotHaloScale,
338
+ size: resolvedDotSize,
339
+ springConfig,
340
+ strokeColor: chartCssVars.background,
341
+ strokeWidth: dotStrokeWidth,
342
+ variant: dotVariant,
343
+ visible,
344
+ x: activePoint.x,
345
+ y: activePoint.y
346
+ }
347
+ )
348
+ ) : lines.map((line, index) => /* @__PURE__ */ jsx(
349
+ TooltipDot,
350
+ {
351
+ animate: !discreteInteraction,
352
+ color: resolveDotColor(line, index),
353
+ cornerRadiusFraction: dotVariant === "ring" ? dotRadiusFraction : void 0,
354
+ haloBlur: dotHaloBlur,
355
+ haloOpacity: dotHaloOpacity,
356
+ haloScale: dotHaloScale,
357
+ size: resolvedDotSize,
358
+ springConfig,
359
+ strokeColor: chartCssVars.background,
360
+ strokeWidth: dotStrokeWidth,
361
+ variant: dotVariant,
362
+ visible,
363
+ x: tooltipData?.xPositions?.[line.dataKey] ?? x,
364
+ y: tooltipData?.yPositions[line.dataKey] ?? 0
365
+ },
366
+ line.dataKey
367
+ )),
368
+ bandDots.map((dot) => {
369
+ const y = tooltipData?.yPositions[dot.key];
370
+ if (y == null) {
371
+ return null;
372
+ }
373
+ return /* @__PURE__ */ jsx(
374
+ TooltipDot,
375
+ {
376
+ animate: !discreteInteraction,
377
+ color: typeof dotColorProp === "string" ? dotColorProp : dot.color,
378
+ cornerRadiusFraction: dotVariant === "ring" ? dotRadiusFraction : void 0,
379
+ haloBlur: dotHaloBlur,
380
+ haloOpacity: dotHaloOpacity,
381
+ haloScale: dotHaloScale,
382
+ size: resolvedDotSize,
383
+ springConfig,
384
+ strokeColor: chartCssVars.background,
385
+ strokeWidth: dotStrokeWidth,
386
+ variant: dotVariant,
387
+ visible,
388
+ x,
389
+ y
390
+ },
391
+ `band-${dot.key}`
392
+ );
393
+ })
394
+ ] })
395
+ }
396
+ ),
397
+ /* @__PURE__ */ jsx(
398
+ TooltipBox,
399
+ {
400
+ animate: boxMotion.animate,
401
+ animateSize,
402
+ backgroundColor,
403
+ className,
404
+ containerHeight: height,
405
+ containerRef,
406
+ containerWidth: width,
407
+ exit,
408
+ panelStyle,
409
+ springConfig: boxMotion.springConfig,
410
+ ...boxPlacement,
411
+ visible,
412
+ children: content && tooltipData ? content({
413
+ point: tooltipData.point,
414
+ index: tooltipData.index
415
+ }) : !content && /* @__PURE__ */ jsx(TooltipContent, { rows: tooltipRows, title, children })
416
+ }
417
+ ),
418
+ /* @__PURE__ */ jsx(
419
+ DatePillTracker,
420
+ {
421
+ animation: datePillAnimation,
422
+ className: datePillClassName,
423
+ currentIndex: tooltipData?.index ?? 0,
424
+ discreteInteraction,
425
+ enabled: datePillEnabled,
426
+ labels: dateLabels,
427
+ point: tooltipData?.point,
428
+ render: datePill,
429
+ springConfig,
430
+ style: datePillStyle,
431
+ variant: datePillVariant,
432
+ velocity: datePillVelocity,
433
+ visible,
434
+ xWithMargin
435
+ }
436
+ )
437
+ ] });
438
+ return createPortal(tooltipContent, container);
439
+ });
440
+ function ChartTooltip(props) {
441
+ const { containerRef } = useChartStable();
442
+ const container = useChartPortalContainer(containerRef);
443
+ if (!container) {
444
+ return null;
445
+ }
446
+ return /* @__PURE__ */ jsx(ChartTooltipInner, { ...props, container });
447
+ }
448
+ ChartTooltip.displayName = "ChartTooltip";
449
+ function DatePillTracker(props) {
450
+ if (!(props.enabled && props.visible && props.labels.length > 0)) {
451
+ return null;
452
+ }
453
+ return /* @__PURE__ */ jsx(DatePillTrackerInner, { ...props });
454
+ }
455
+ function DatePillTrackerInner({
456
+ labels,
457
+ currentIndex,
458
+ xWithMargin,
459
+ discreteInteraction,
460
+ springConfig,
461
+ visible,
462
+ point,
463
+ animation,
464
+ className,
465
+ style,
466
+ render,
467
+ variant,
468
+ velocity
469
+ }) {
470
+ const { tooltipSpring } = useChartConfig();
471
+ const reduceMotion = useReducedMotion() === true;
472
+ const effectiveSpring = springConfig ?? tooltipSpring;
473
+ const animatedX = useSpring(xWithMargin, effectiveSpring);
474
+ const swell = useVelocityStretch(
475
+ animatedX,
476
+ reduceMotion || discreteInteraction ? null : resolveDatePillVelocity(velocity)
477
+ );
478
+ if (!discreteInteraction) {
479
+ animatedX.set(xWithMargin);
480
+ }
481
+ useEffect(() => {
482
+ animatedX.set(xWithMargin);
483
+ }, [animatedX, visible]);
484
+ return /* @__PURE__ */ jsx(
485
+ m.div,
486
+ {
487
+ className: "pointer-events-none absolute z-50 w-max",
488
+ style: {
489
+ left: discreteInteraction ? xWithMargin : animatedX,
490
+ transform: "translateX(-50%)",
491
+ bottom: 4
492
+ },
493
+ children: /* @__PURE__ */ jsx(m.div, { style: { scaleX: swell.scaleX, scaleY: swell.scaleY }, children: render && point ? render({
494
+ label: labels[currentIndex] ?? "",
495
+ index: currentIndex,
496
+ point
497
+ }) : /* @__PURE__ */ jsx(
498
+ DateTicker,
499
+ {
500
+ animation,
501
+ className,
502
+ currentIndex,
503
+ labels,
504
+ style,
505
+ variant,
506
+ visible
507
+ }
508
+ ) })
509
+ }
510
+ );
511
+ }
512
+ var chart_tooltip_default = ChartTooltip;
513
+ export {
514
+ ChartTooltip,
515
+ chart_tooltip_default as default
516
+ };
@@ -0,0 +1,183 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { createElement } from "react";
4
+ import {
5
+ AnimatePresence,
6
+ domAnimation,
7
+ LazyMotion,
8
+ m,
9
+ useReducedMotion,
10
+ useSpring
11
+ } from "motion/react";
12
+ import {
13
+ useCallback,
14
+ useEffect,
15
+ useLayoutEffect,
16
+ useRef,
17
+ useState
18
+ } from "react";
19
+ import { createPortal } from "react-dom";
20
+ import { cn } from "../../lib/utils";
21
+ import { useChartConfig } from "../chart-config-context";
22
+ import { chartCssVars, useChartPortalContainer } from "../chart-context";
23
+ import { TOOLTIP_PANEL_CLASS_NAME, TooltipPanel } from "./tooltip-box";
24
+ const DEFAULT_TOOLTIP_WIDTH = 180;
25
+ const DEFAULT_TOOLTIP_HEIGHT = 80;
26
+ function CursorTooltipBox({
27
+ visible,
28
+ containerRef,
29
+ offset = 16,
30
+ exit = true,
31
+ springConfig,
32
+ ...panelProps
33
+ }) {
34
+ const container = useChartPortalContainer(containerRef);
35
+ const { tooltipBoxSpring } = useChartConfig();
36
+ const reducedMotion = useReducedMotion() === true;
37
+ const x = useSpring(0, springConfig ?? tooltipBoxSpring);
38
+ const y = useSpring(0, springConfig ?? tooltipBoxSpring);
39
+ const visibleRef = useRef(visible);
40
+ useLayoutEffect(() => {
41
+ visibleRef.current = visible;
42
+ }, [visible]);
43
+ const pointerRef = useRef({ x: 0, y: 0 });
44
+ const sizeRef = useRef({
45
+ width: DEFAULT_TOOLTIP_WIDTH,
46
+ height: DEFAULT_TOOLTIP_HEIGHT
47
+ });
48
+ const [flipped, setFlipped] = useState(false);
49
+ const flippedRef = useRef(false);
50
+ const place = useCallback(() => {
51
+ if (!container) {
52
+ return;
53
+ }
54
+ const { width, height } = sizeRef.current;
55
+ const pointer = pointerRef.current;
56
+ const flip = pointer.x + offset + width > container.clientWidth;
57
+ const left = flip ? pointer.x - offset - width : pointer.x + offset;
58
+ const top = Math.max(
59
+ offset,
60
+ Math.min(pointer.y - height / 2, container.clientHeight - height - offset)
61
+ );
62
+ if (reducedMotion || !visibleRef.current) {
63
+ x.jump(left);
64
+ y.jump(top);
65
+ } else {
66
+ x.set(left);
67
+ y.set(top);
68
+ }
69
+ if (flip !== flippedRef.current) {
70
+ flippedRef.current = flip;
71
+ setFlipped(flip);
72
+ }
73
+ }, [container, offset, reducedMotion, x, y]);
74
+ useEffect(() => {
75
+ if (!container) {
76
+ return;
77
+ }
78
+ const track = (event) => {
79
+ const rect = container.getBoundingClientRect();
80
+ pointerRef.current = {
81
+ x: event.clientX - rect.left,
82
+ y: event.clientY - rect.top
83
+ };
84
+ place();
85
+ };
86
+ container.addEventListener("pointerover", track, { passive: true });
87
+ container.addEventListener("pointermove", track, { passive: true });
88
+ return () => {
89
+ container.removeEventListener("pointerover", track);
90
+ container.removeEventListener("pointermove", track);
91
+ };
92
+ }, [container, place]);
93
+ const onMeasure = useCallback(
94
+ (width, height) => {
95
+ if (width > 0 && height > 0) {
96
+ sizeRef.current = { width, height };
97
+ place();
98
+ }
99
+ },
100
+ [place]
101
+ );
102
+ if (!container) {
103
+ return null;
104
+ }
105
+ const inner = visible ? /* @__PURE__ */ createElement(
106
+ CursorTooltipPanel,
107
+ {
108
+ ...panelProps,
109
+ container,
110
+ flipped,
111
+ key: "cursor-tooltip",
112
+ onMeasure,
113
+ x,
114
+ y
115
+ }
116
+ ) : null;
117
+ return /* @__PURE__ */ jsx(LazyMotion, { features: domAnimation, children: exit ? /* @__PURE__ */ jsx(AnimatePresence, { children: inner }) : inner });
118
+ }
119
+ function CursorTooltipPanel({
120
+ container,
121
+ x,
122
+ y,
123
+ flipped,
124
+ onMeasure,
125
+ className,
126
+ children,
127
+ animateSize = true,
128
+ panelStyle,
129
+ backgroundColor = chartCssVars.tooltipBackground
130
+ }) {
131
+ const reducedMotion = useReducedMotion() === true;
132
+ const panelRef = useRef(null);
133
+ useLayoutEffect(() => {
134
+ const element = panelRef.current;
135
+ if (element) {
136
+ onMeasure(element.offsetWidth, element.offsetHeight);
137
+ }
138
+ }, [children, onMeasure]);
139
+ return createPortal(
140
+ /* @__PURE__ */ jsx(
141
+ m.div,
142
+ {
143
+ animate: { opacity: 1 },
144
+ className: cn(
145
+ "pointer-events-none absolute top-0 left-0 z-50",
146
+ className
147
+ ),
148
+ exit: { opacity: 0 },
149
+ initial: { opacity: 0 },
150
+ ref: panelRef,
151
+ style: { x, y },
152
+ transition: { duration: 0.1 },
153
+ children: /* @__PURE__ */ jsx(
154
+ TooltipPanel,
155
+ {
156
+ animateSize: animateSize && !reducedMotion,
157
+ className: cn(
158
+ TOOLTIP_PANEL_CLASS_NAME,
159
+ panelStyle?.backgroundColor === void 0 && backgroundColor === chartCssVars.tooltipBackground && "bg-chart-tooltip-background",
160
+ panelStyle?.backdropFilter === void 0 && "backdrop-blur-md"
161
+ ),
162
+ entrance: reducedMotion ? false : { scale: 0.85 },
163
+ style: {
164
+ ...panelStyle?.backgroundColor === void 0 && {
165
+ backgroundColor
166
+ },
167
+ ...panelStyle
168
+ },
169
+ transformOrigin: flipped ? "right center" : "left center",
170
+ children
171
+ }
172
+ )
173
+ }
174
+ ),
175
+ container
176
+ );
177
+ }
178
+ CursorTooltipBox.displayName = "CursorTooltipBox";
179
+ var cursor_tooltip_box_default = CursorTooltipBox;
180
+ export {
181
+ CursorTooltipBox,
182
+ cursor_tooltip_box_default as default
183
+ };