@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,740 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import {
4
+ domAnimation,
5
+ LazyMotion,
6
+ useReducedMotion,
7
+ useSpring
8
+ } from "motion/react";
9
+ import {
10
+ Children,
11
+ createContext,
12
+ isValidElement,
13
+ useCallback,
14
+ useContext,
15
+ useEffect,
16
+ useLayoutEffect,
17
+ useMemo,
18
+ useRef,
19
+ useState
20
+ } from "react";
21
+ import { cn } from "../lib/utils";
22
+ import { useChartDataOverride } from "./chart-data-override";
23
+ import { useElementSize } from "./chart-parent-size";
24
+ import {
25
+ cartesianToAngle,
26
+ createRadialScale,
27
+ defaultRadialLayout,
28
+ degreesToRadians,
29
+ isFullArc,
30
+ niceRadialDomain,
31
+ polarToCartesian,
32
+ radialArcBounds,
33
+ radialArcFraction,
34
+ radialWedgePath,
35
+ TAU
36
+ } from "./radial-geometry";
37
+ const RadialChartContext = createContext(null);
38
+ function useRadialChart() {
39
+ const context = useContext(RadialChartContext);
40
+ if (!context) {
41
+ throw new Error(
42
+ "useRadialChart must be used within a <RadialChart> component."
43
+ );
44
+ }
45
+ return context;
46
+ }
47
+ function radialNumberAt(datum, key) {
48
+ const value = datum?.[key];
49
+ return typeof value === "number" && Number.isFinite(value) ? value : null;
50
+ }
51
+ function radialTimeOf(value) {
52
+ let time = Number.NaN;
53
+ if (value instanceof Date) {
54
+ time = value.getTime();
55
+ } else if (typeof value === "number") {
56
+ time = value;
57
+ } else if (typeof value === "string") {
58
+ time = Date.parse(value);
59
+ }
60
+ return Number.isFinite(time) ? time : null;
61
+ }
62
+ const RADIAL_CROSSHAIR_SPRING = {
63
+ stiffness: 420,
64
+ damping: 42
65
+ };
66
+ const RADIAL_DOT_SPRING = {
67
+ stiffness: 240,
68
+ damping: 24
69
+ };
70
+ function useRadialAngleSpring({
71
+ angle,
72
+ hidden,
73
+ isFullCircle,
74
+ snap,
75
+ spring: springOptions = RADIAL_CROSSHAIR_SPRING
76
+ }) {
77
+ const spring = useSpring(angle, springOptions);
78
+ const targetRef = useRef(angle);
79
+ const wasHiddenRef = useRef(hidden);
80
+ useLayoutEffect(() => {
81
+ const wasHidden = wasHiddenRef.current;
82
+ wasHiddenRef.current = hidden;
83
+ if (hidden) {
84
+ return;
85
+ }
86
+ if (wasHidden) {
87
+ targetRef.current = angle;
88
+ spring.jump(angle);
89
+ return;
90
+ }
91
+ const previous = targetRef.current;
92
+ let next = angle;
93
+ if (isFullCircle) {
94
+ let delta = (angle - previous) % TAU;
95
+ if (delta > Math.PI) {
96
+ delta -= TAU;
97
+ } else if (delta < -Math.PI) {
98
+ delta += TAU;
99
+ }
100
+ next = previous + delta;
101
+ }
102
+ targetRef.current = next;
103
+ if (snap) {
104
+ spring.jump(next);
105
+ } else {
106
+ spring.set(next);
107
+ }
108
+ }, [spring, angle, snap, isFullCircle, hidden]);
109
+ return spring;
110
+ }
111
+ function useRadialDotAngle(motion, spring = RADIAL_DOT_SPRING) {
112
+ const {
113
+ crosshairAngle,
114
+ hoveredIndex,
115
+ binAngle,
116
+ isFullCircle,
117
+ reducedMotion
118
+ } = useRadialChart();
119
+ const own = useRadialAngleSpring({
120
+ angle: binAngle(hoveredIndex ?? 0),
121
+ hidden: hoveredIndex === null || motion === "crosshair",
122
+ isFullCircle,
123
+ snap: motion === "none" || reducedMotion,
124
+ spring
125
+ });
126
+ return motion === "crosshair" ? crosshairAngle : own;
127
+ }
128
+ const BEZIER_STEPS = 10;
129
+ function createRadialEdgeLookup(draw) {
130
+ const segments = [];
131
+ let startX = 0;
132
+ let startY = 0;
133
+ let x = 0;
134
+ let y = 0;
135
+ const push = (nx, ny) => {
136
+ segments.push(x, y, nx, ny);
137
+ x = nx;
138
+ y = ny;
139
+ };
140
+ const context = {
141
+ moveTo(nx, ny) {
142
+ startX = nx;
143
+ startY = ny;
144
+ x = nx;
145
+ y = ny;
146
+ },
147
+ lineTo: push,
148
+ bezierCurveTo(x1, y1, x2, y2, x3, y3) {
149
+ const x0 = x;
150
+ const y0 = y;
151
+ for (let k = 1; k <= BEZIER_STEPS; k++) {
152
+ const t = k / BEZIER_STEPS;
153
+ const u = 1 - t;
154
+ const a = u * u * u;
155
+ const b = 3 * u * u * t;
156
+ const c = 3 * u * t * t;
157
+ const d = t * t * t;
158
+ push(
159
+ a * x0 + b * x1 + c * x2 + d * x3,
160
+ a * y0 + b * y1 + c * y2 + d * y3
161
+ );
162
+ }
163
+ },
164
+ quadraticCurveTo(x1, y1, x2, y2) {
165
+ const x0 = x;
166
+ const y0 = y;
167
+ for (let k = 1; k <= BEZIER_STEPS; k++) {
168
+ const t = k / BEZIER_STEPS;
169
+ const u = 1 - t;
170
+ push(
171
+ u * u * x0 + 2 * u * t * x1 + t * t * x2,
172
+ u * u * y0 + 2 * u * t * y1 + t * t * y2
173
+ );
174
+ }
175
+ },
176
+ closePath() {
177
+ if (x !== startX || y !== startY) {
178
+ push(startX, startY);
179
+ }
180
+ }
181
+ };
182
+ draw(context);
183
+ const flat = Float64Array.from(segments);
184
+ return (angle) => {
185
+ const dx = Math.sin(angle);
186
+ const dy = -Math.cos(angle);
187
+ let best = -1;
188
+ for (let i = 0; i < flat.length; i += 4) {
189
+ const x0 = flat[i] ?? 0;
190
+ const y0 = flat[i + 1] ?? 0;
191
+ const ex = (flat[i + 2] ?? 0) - x0;
192
+ const ey = (flat[i + 3] ?? 0) - y0;
193
+ const denom = dx * ey - dy * ex;
194
+ if (Math.abs(denom) < 1e-9) {
195
+ continue;
196
+ }
197
+ const t = (x0 * dy - y0 * dx) / denom;
198
+ if (t < -1e-6 || t > 1 + 1e-6) {
199
+ continue;
200
+ }
201
+ const s = (x0 * ey - y0 * ex) / denom;
202
+ if (s > best) {
203
+ best = s;
204
+ }
205
+ }
206
+ return best > 0 ? best : null;
207
+ };
208
+ }
209
+ function RadialHoverDot({
210
+ angle,
211
+ lookup,
212
+ ...props
213
+ }) {
214
+ const ref = useRef(null);
215
+ const place = useCallback(
216
+ (a) => {
217
+ const r = lookup(a);
218
+ return r === null ? null : polarToCartesian(a, r);
219
+ },
220
+ [lookup]
221
+ );
222
+ useLayoutEffect(() => {
223
+ const apply = (a) => {
224
+ const el = ref.current;
225
+ if (!el) {
226
+ return;
227
+ }
228
+ const p = place(a);
229
+ if (!p) {
230
+ el.setAttribute("visibility", "hidden");
231
+ return;
232
+ }
233
+ el.removeAttribute("visibility");
234
+ el.setAttribute("cx", String(p.x));
235
+ el.setAttribute("cy", String(p.y));
236
+ };
237
+ apply(angle.get());
238
+ return angle.on("change", apply);
239
+ }, [angle, place]);
240
+ const initial = place(angle.get());
241
+ return /* @__PURE__ */ jsx(
242
+ "circle",
243
+ {
244
+ ...props,
245
+ cx: initial?.x ?? 0,
246
+ cy: initial?.y ?? 0,
247
+ ref,
248
+ visibility: initial ? void 0 : "hidden"
249
+ }
250
+ );
251
+ }
252
+ const CENTER_CHILDREN = /* @__PURE__ */ new Set(["RadialCenter"]);
253
+ const BELOW_CHILDREN = /* @__PURE__ */ new Set(["RadialLegend"]);
254
+ function childDisplayName(child) {
255
+ if (!isValidElement(child)) {
256
+ return "";
257
+ }
258
+ return child.type.displayName ?? "";
259
+ }
260
+ function scanValues(data, series, keys) {
261
+ let lo = Number.POSITIVE_INFINITY;
262
+ let hi = 0;
263
+ let stack = 0;
264
+ for (const d of data) {
265
+ for (const key of keys) {
266
+ const v = radialNumberAt(d, key);
267
+ if (v !== null) {
268
+ lo = Math.min(lo, v);
269
+ hi = Math.max(hi, v);
270
+ }
271
+ }
272
+ const sum = series.reduce(
273
+ (total, s) => total + Math.max(0, radialNumberAt(d, s.dataKey) ?? 0),
274
+ 0
275
+ );
276
+ stack = Math.max(stack, sum);
277
+ }
278
+ return { lo: Number.isFinite(lo) ? lo : 0, hi, stack };
279
+ }
280
+ function computeValueDomain({
281
+ data,
282
+ series,
283
+ valueKeys,
284
+ maxValue,
285
+ minValue,
286
+ nice
287
+ }) {
288
+ const keys = [...series.map((s) => s.dataKey), ...valueKeys];
289
+ const { lo, hi, stack } = scanValues(data, series, keys);
290
+ const autoMin = minValue === "auto";
291
+ const fixedMax = typeof maxValue === "number";
292
+ const min = autoMin ? lo : minValue;
293
+ let max = Math.max(hi, maxValue === "stacked" ? stack : 0);
294
+ if (fixedMax) {
295
+ max = maxValue;
296
+ }
297
+ if (!nice || fixedMax && !autoMin) {
298
+ return [min, max];
299
+ }
300
+ const [niceMin, niceMax] = niceRadialDomain([min, Math.max(max, min)]);
301
+ return [autoMin ? niceMin : min, fixedMax ? max : niceMax];
302
+ }
303
+ function RadialChart({
304
+ data: dataProp,
305
+ xDataKey = "time",
306
+ series,
307
+ layout: layoutProp,
308
+ angleType = "clock",
309
+ orientation = "radial",
310
+ startAngle: startAngleDeg = 0,
311
+ endAngle: endAngleDeg,
312
+ fitArc = true,
313
+ trackNow: trackNowProp,
314
+ nowIndex: nowIndexProp,
315
+ maxValue: maxValueProp,
316
+ minValue = 0,
317
+ valueKeys,
318
+ niceValues = true,
319
+ ringGap = 0.3,
320
+ animate = true,
321
+ hoveredIndex: hoveredIndexProp,
322
+ onHoverChange,
323
+ maxWidth = 640,
324
+ className,
325
+ children
326
+ }) {
327
+ const { data } = useChartDataOverride("RadialChart", {
328
+ data: dataProp
329
+ });
330
+ const stageRef = useRef(null);
331
+ const { width } = useElementSize(stageRef, 100);
332
+ const layout = useMemo(
333
+ () => ({ ...defaultRadialLayout, ...layoutProp }),
334
+ [layoutProp]
335
+ );
336
+ const startAngle = degreesToRadians(startAngleDeg);
337
+ const endAngle = degreesToRadians(endAngleDeg ?? startAngleDeg + 360);
338
+ const isFullCircle = isFullArc(startAngle, endAngle);
339
+ const span = endAngle - startAngle;
340
+ const bounds = useMemo(
341
+ () => isFullCircle || !fitArc ? { minX: -1, maxX: 1, minY: -1, maxY: 1 } : (() => {
342
+ const b = radialArcBounds(startAngle, endAngle);
343
+ const pad = 0.12;
344
+ return {
345
+ minX: Math.min(b.minX, -pad),
346
+ maxX: Math.max(b.maxX, pad),
347
+ minY: Math.min(b.minY, -pad),
348
+ maxY: Math.max(b.maxY, pad)
349
+ };
350
+ })(),
351
+ [isFullCircle, fitArc, startAngle, endAngle]
352
+ );
353
+ const boundsWidth = bounds.maxX - bounds.minX;
354
+ const boundsHeight = bounds.maxY - bounds.minY;
355
+ const stageWidth = Math.max(0, width);
356
+ const radius = stageWidth / boundsWidth;
357
+ const stageHeight = radius * boundsHeight;
358
+ const cx = -bounds.minX * radius;
359
+ const cy = -bounds.minY * radius;
360
+ const size = radius * 2;
361
+ const reducedMotion = useReducedMotion() === true;
362
+ const shouldAnimate = animate && !reducedMotion;
363
+ const [internalHovered, setInternalHovered] = useState(null);
364
+ const isControlled = hoveredIndexProp !== void 0;
365
+ const hoveredIndex = isControlled ? hoveredIndexProp : internalHovered;
366
+ const setHoveredIndex = useCallback(
367
+ (index) => {
368
+ if (!isControlled) {
369
+ setInternalHovered(index);
370
+ }
371
+ onHoverChange?.(index);
372
+ },
373
+ [isControlled, onHoverChange]
374
+ );
375
+ const [hoveredSeries, setHoveredSeries] = useState(null);
376
+ const binCount = data.length;
377
+ const trackNow = trackNowProp ?? angleType === "clock";
378
+ const futureBins = useMemo(
379
+ () => data.map(
380
+ (d) => trackNow && series.every((s) => radialNumberAt(d, s.dataKey) === null)
381
+ ),
382
+ [data, series, trackNow]
383
+ );
384
+ const nowIndex = useMemo(() => {
385
+ if (nowIndexProp !== void 0) {
386
+ return nowIndexProp;
387
+ }
388
+ for (let i = binCount - 1; i >= 0; i--) {
389
+ if (series.some((s) => radialNumberAt(data[i], s.dataKey) !== null)) {
390
+ return i;
391
+ }
392
+ }
393
+ return binCount - 1;
394
+ }, [nowIndexProp, data, series, binCount]);
395
+ const totals = useMemo(() => {
396
+ const result = {};
397
+ for (const s of series) {
398
+ result[s.dataKey] = 0;
399
+ }
400
+ data.forEach((d, i) => {
401
+ if (futureBins[i]) {
402
+ return;
403
+ }
404
+ for (const s of series) {
405
+ result[s.dataKey] = (result[s.dataKey] ?? 0) + (radialNumberAt(d, s.dataKey) ?? 0);
406
+ }
407
+ });
408
+ return result;
409
+ }, [data, series, futureBins]);
410
+ const sharedValueScale = maxValueProp !== void 0 || orientation === "angular";
411
+ const valueKeysKey = valueKeys?.join("\0") ?? "";
412
+ const valueDomain = useMemo(
413
+ () => computeValueDomain({
414
+ data,
415
+ series,
416
+ valueKeys: valueKeys ?? [],
417
+ maxValue: maxValueProp ?? "stacked",
418
+ minValue,
419
+ nice: niceValues
420
+ }),
421
+ [data, series, valueKeysKey, maxValueProp, minValue, niceValues]
422
+ );
423
+ const innerRadius = radius * layout.bandInner;
424
+ const outerRadius = radius * layout.bandOuter;
425
+ const valueScale = useMemo(() => {
426
+ const scale = createRadialScale({
427
+ minValue: valueDomain[0],
428
+ maxValue: valueDomain[1],
429
+ innerRadius,
430
+ outerRadius
431
+ });
432
+ return (value) => scale(value) ?? innerRadius;
433
+ }, [valueDomain, innerRadius, outerRadius]);
434
+ const valueToAngle = useCallback(
435
+ (value) => {
436
+ const [lo, hi] = valueDomain;
437
+ const t = hi > lo ? (value - lo) / (hi - lo) : 0;
438
+ return startAngle + Math.min(1, Math.max(0, t)) * span;
439
+ },
440
+ [valueDomain, startAngle, span]
441
+ );
442
+ const ringBand = useCallback(
443
+ (index) => {
444
+ const step = (outerRadius - innerRadius) / Math.max(1, binCount);
445
+ const gap = step * Math.min(0.95, Math.max(0, ringGap));
446
+ const inner = innerRadius + index * step + gap / 2;
447
+ const outer = innerRadius + (index + 1) * step - gap / 2;
448
+ return { inner, outer, center: (inner + outer) / 2 };
449
+ },
450
+ [innerRadius, outerRadius, binCount, ringGap]
451
+ );
452
+ const timeDomain = useMemo(() => {
453
+ if (angleType !== "time" || binCount === 0) {
454
+ return null;
455
+ }
456
+ const first = radialTimeOf(data[0]?.[xDataKey]);
457
+ const last = radialTimeOf(data[binCount - 1]?.[xDataKey]);
458
+ if (first === null || last === null) {
459
+ return null;
460
+ }
461
+ const step = binCount > 1 ? (last - first) / (binCount - 1) : 1;
462
+ return [first, first + step * binCount];
463
+ }, [angleType, binCount, data, xDataKey]);
464
+ const timeToAngle = useCallback(
465
+ (time) => {
466
+ if (!timeDomain) {
467
+ return null;
468
+ }
469
+ const t = typeof time === "number" ? time : time.getTime();
470
+ const [t0, t1] = timeDomain;
471
+ if (t < t0 || t > t1 || t1 <= t0) {
472
+ return null;
473
+ }
474
+ return startAngle + (t - t0) / (t1 - t0) * span;
475
+ },
476
+ [timeDomain, startAngle, span]
477
+ );
478
+ const [revealed, setRevealed] = useState(false);
479
+ const hasSize = stageWidth > 0;
480
+ useEffect(() => {
481
+ if (!hasSize) {
482
+ return;
483
+ }
484
+ if (!shouldAnimate) {
485
+ setRevealed(true);
486
+ return;
487
+ }
488
+ let inner = 0;
489
+ const outer = requestAnimationFrame(() => {
490
+ inner = requestAnimationFrame(() => setRevealed(true));
491
+ });
492
+ return () => {
493
+ cancelAnimationFrame(outer);
494
+ cancelAnimationFrame(inner);
495
+ };
496
+ }, [hasSize, shouldAnimate]);
497
+ const centerRadius = radius * layout.center;
498
+ const binWidth = binCount > 0 ? span / binCount : 0;
499
+ const binStartAngle = useCallback(
500
+ (index) => startAngle + index / Math.max(1, binCount) * span,
501
+ [startAngle, span, binCount]
502
+ );
503
+ const binAngle = useCallback(
504
+ (index) => startAngle + (index + 0.5) / Math.max(1, binCount) * span,
505
+ [startAngle, span, binCount]
506
+ );
507
+ const fractionToAngle = useCallback(
508
+ (fraction) => startAngle + fraction * span,
509
+ [startAngle, span]
510
+ );
511
+ const angleToBin = useCallback(
512
+ (angle) => {
513
+ const fraction = radialArcFraction(angle, startAngle, endAngle);
514
+ if (fraction === null || binCount === 0) {
515
+ return null;
516
+ }
517
+ return Math.min(binCount - 1, Math.floor(fraction * binCount));
518
+ },
519
+ [startAngle, endAngle, binCount]
520
+ );
521
+ const fallbackCrosshair = useRadialAngleSpring({
522
+ angle: binAngle(hoveredIndex ?? 0),
523
+ hidden: hoveredIndex === null,
524
+ isFullCircle,
525
+ snap: reducedMotion
526
+ });
527
+ const [scrubberCrosshair, setScrubberCrosshair] = useState(null);
528
+ const registerCrosshair = useCallback((angle) => {
529
+ setScrubberCrosshair(angle);
530
+ return () => setScrubberCrosshair((current) => current === angle ? null : current);
531
+ }, []);
532
+ const crosshairAngle = scrubberCrosshair ?? fallbackCrosshair;
533
+ const handlePointerMove = useCallback(
534
+ (event) => {
535
+ if (binCount === 0) {
536
+ return;
537
+ }
538
+ const rect = event.currentTarget.getBoundingClientRect();
539
+ const dx = event.clientX - rect.left - cx;
540
+ const dy = event.clientY - rect.top - cy;
541
+ const distance = Math.hypot(dx, dy);
542
+ let next = null;
543
+ if (orientation === "angular") {
544
+ const step = (outerRadius - innerRadius) / binCount;
545
+ const ring = Math.floor((distance - innerRadius) / step);
546
+ next = ring >= 0 && ring < binCount ? ring : null;
547
+ } else if (distance >= centerRadius * 0.5) {
548
+ next = angleToBin(cartesianToAngle(dx, dy));
549
+ }
550
+ if (next !== hoveredIndex) {
551
+ setHoveredIndex(next);
552
+ }
553
+ },
554
+ [
555
+ binCount,
556
+ cx,
557
+ cy,
558
+ orientation,
559
+ outerRadius,
560
+ innerRadius,
561
+ centerRadius,
562
+ angleToBin,
563
+ hoveredIndex,
564
+ setHoveredIndex
565
+ ]
566
+ );
567
+ const handlePointerLeave = useCallback(() => {
568
+ setHoveredIndex(null);
569
+ }, [setHoveredIndex]);
570
+ const contextValue = useMemo(
571
+ () => ({
572
+ data,
573
+ xDataKey,
574
+ series,
575
+ binCount,
576
+ size,
577
+ radius,
578
+ layout,
579
+ centerRadius,
580
+ innerRadius,
581
+ outerRadius,
582
+ futureBins,
583
+ nowIndex,
584
+ trackNow,
585
+ totals,
586
+ hoveredIndex,
587
+ setHoveredIndex,
588
+ crosshairAngle,
589
+ registerCrosshair,
590
+ hoveredSeries,
591
+ setHoveredSeries,
592
+ revealed,
593
+ animate: shouldAnimate,
594
+ reducedMotion,
595
+ angleType,
596
+ orientation,
597
+ startAngle,
598
+ endAngle,
599
+ isFullCircle,
600
+ binWidth,
601
+ binAngle,
602
+ binStartAngle,
603
+ angleToBin,
604
+ fractionToAngle,
605
+ timeToAngle,
606
+ timeDomain,
607
+ valueDomain,
608
+ maxValue: valueDomain[1],
609
+ sharedValueScale,
610
+ valueScale,
611
+ valueToAngle,
612
+ ringBand
613
+ }),
614
+ [
615
+ data,
616
+ xDataKey,
617
+ series,
618
+ binCount,
619
+ size,
620
+ radius,
621
+ layout,
622
+ centerRadius,
623
+ innerRadius,
624
+ outerRadius,
625
+ futureBins,
626
+ nowIndex,
627
+ trackNow,
628
+ totals,
629
+ hoveredIndex,
630
+ setHoveredIndex,
631
+ crosshairAngle,
632
+ registerCrosshair,
633
+ hoveredSeries,
634
+ revealed,
635
+ shouldAnimate,
636
+ reducedMotion,
637
+ angleType,
638
+ orientation,
639
+ startAngle,
640
+ endAngle,
641
+ isFullCircle,
642
+ binWidth,
643
+ binAngle,
644
+ binStartAngle,
645
+ angleToBin,
646
+ fractionToAngle,
647
+ timeToAngle,
648
+ timeDomain,
649
+ valueDomain,
650
+ sharedValueScale,
651
+ valueScale,
652
+ valueToAngle,
653
+ ringBand
654
+ ]
655
+ );
656
+ const svgChildren = [];
657
+ const centerChildren = [];
658
+ const belowChildren = [];
659
+ Children.forEach(children, (child) => {
660
+ const name = childDisplayName(child);
661
+ if (CENTER_CHILDREN.has(name)) {
662
+ centerChildren.push(child);
663
+ } else if (BELOW_CHILDREN.has(name)) {
664
+ belowChildren.push(child);
665
+ } else if (child !== null && child !== void 0 && child !== false) {
666
+ svgChildren.push(child);
667
+ }
668
+ });
669
+ const centerSize = Math.max(0, centerRadius * 2 - 16);
670
+ return /* @__PURE__ */ jsx(LazyMotion, { features: domAnimation, children: /* @__PURE__ */ jsx(RadialChartContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxs(
671
+ "div",
672
+ {
673
+ className: cn("mx-auto flex w-full flex-col items-center", className),
674
+ style: { maxWidth },
675
+ children: [
676
+ /* @__PURE__ */ jsx(
677
+ "div",
678
+ {
679
+ className: "relative w-full",
680
+ ref: stageRef,
681
+ style: { aspectRatio: `${boundsWidth} / ${boundsHeight}` },
682
+ children: hasSize ? /* @__PURE__ */ jsxs(Fragment, { children: [
683
+ /* @__PURE__ */ jsx(
684
+ "svg",
685
+ {
686
+ "aria-hidden": "true",
687
+ className: "absolute inset-0 touch-pan-y select-none",
688
+ height: stageHeight,
689
+ onPointerLeave: handlePointerLeave,
690
+ onPointerMove: handlePointerMove,
691
+ style: { overflow: "visible" },
692
+ width: stageWidth,
693
+ children: /* @__PURE__ */ jsxs("g", { transform: `translate(${cx},${cy})`, children: [
694
+ isFullCircle ? /* @__PURE__ */ jsx("circle", { fill: "transparent", r: radius }) : /* @__PURE__ */ jsx(
695
+ "path",
696
+ {
697
+ d: radialWedgePath(radius, startAngle, endAngle),
698
+ fill: "transparent"
699
+ }
700
+ ),
701
+ svgChildren
702
+ ] })
703
+ }
704
+ ),
705
+ centerChildren.length > 0 ? /* @__PURE__ */ jsx(
706
+ "div",
707
+ {
708
+ className: "pointer-events-none absolute flex -translate-x-1/2 -translate-y-1/2 items-center justify-center",
709
+ style: {
710
+ left: cx,
711
+ top: cy,
712
+ width: centerSize,
713
+ height: centerSize
714
+ },
715
+ children: centerChildren
716
+ }
717
+ ) : null
718
+ ] }) : null
719
+ }
720
+ ),
721
+ belowChildren
722
+ ]
723
+ }
724
+ ) }) });
725
+ }
726
+ RadialChart.displayName = "RadialChart";
727
+ var radial_chart_default = RadialChart;
728
+ export {
729
+ RADIAL_CROSSHAIR_SPRING,
730
+ RADIAL_DOT_SPRING,
731
+ RadialChart,
732
+ RadialHoverDot,
733
+ createRadialEdgeLookup,
734
+ radial_chart_default as default,
735
+ radialNumberAt,
736
+ radialTimeOf,
737
+ useRadialAngleSpring,
738
+ useRadialChart,
739
+ useRadialDotAngle
740
+ };