@aiconstructions/graficos 0.0.0-stage → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/ALTERACOES.md +53 -0
  2. package/LICENSE-BKLIT +21 -0
  3. package/LICENSE-visx-pattern +21 -0
  4. package/README.md +188 -2
  5. package/dist/aic/cores.js +83 -0
  6. package/dist/aic/index.js +22 -0
  7. package/dist/aic/interacao.js +55 -0
  8. package/dist/charts/animation.js +55 -0
  9. package/dist/charts/arc-geometry.js +58 -0
  10. package/dist/charts/arc-path.js +15 -0
  11. package/dist/charts/area-chart-loading.js +89 -0
  12. package/dist/charts/area-chart.js +149 -0
  13. package/dist/charts/area-gradient-defs.js +90 -0
  14. package/dist/charts/area-value-label-layout.js +70 -0
  15. package/dist/charts/area-value-labels.js +211 -0
  16. package/dist/charts/area.js +272 -0
  17. package/dist/charts/background.js +198 -0
  18. package/dist/charts/band-config.js +82 -0
  19. package/dist/charts/band-geometry.js +186 -0
  20. package/dist/charts/band.js +346 -0
  21. package/dist/charts/bar-chart-loading.js +27 -0
  22. package/dist/charts/bar-chart.js +545 -0
  23. package/dist/charts/bar-depth-geometry.js +18 -0
  24. package/dist/charts/bar-depth.js +608 -0
  25. package/dist/charts/bar-lollipop.js +278 -0
  26. package/dist/charts/bar-squares-layout.js +66 -0
  27. package/dist/charts/bar-squares.js +467 -0
  28. package/dist/charts/bar-value-label-layout.js +42 -0
  29. package/dist/charts/bar-x-axis.js +133 -0
  30. package/dist/charts/bar-y-axis.js +116 -0
  31. package/dist/charts/bar.js +457 -0
  32. package/dist/charts/bollinger.js +49 -0
  33. package/dist/charts/candlestick-chart.js +370 -0
  34. package/dist/charts/candlestick.js +368 -0
  35. package/dist/charts/chart-brush-handle.js +91 -0
  36. package/dist/charts/chart-brush-layout.js +91 -0
  37. package/dist/charts/chart-brush-selection-overlay.js +87 -0
  38. package/dist/charts/chart-brush-state.js +253 -0
  39. package/dist/charts/chart-brush-track-overlay.js +103 -0
  40. package/dist/charts/chart-brush.js +517 -0
  41. package/dist/charts/chart-center-typography.js +8 -0
  42. package/dist/charts/chart-child-passthrough.js +119 -0
  43. package/dist/charts/chart-config-context.js +56 -0
  44. package/dist/charts/chart-context.js +337 -0
  45. package/dist/charts/chart-crosshair.js +262 -0
  46. package/dist/charts/chart-data-override.js +186 -0
  47. package/dist/charts/chart-defs.js +56 -0
  48. package/dist/charts/chart-formatters.js +77 -0
  49. package/dist/charts/chart-legend-hover.js +27 -0
  50. package/dist/charts/chart-legend.js +163 -0
  51. package/dist/charts/chart-loading-label.js +52 -0
  52. package/dist/charts/chart-parent-size.js +138 -0
  53. package/dist/charts/chart-phase.js +29 -0
  54. package/dist/charts/chart-reveal-clip.js +62 -0
  55. package/dist/charts/chart-scale.js +19 -0
  56. package/dist/charts/chart-stat-flow.js +72 -0
  57. package/dist/charts/choropleth/choropleth-background.js +29 -0
  58. package/dist/charts/choropleth/choropleth-camera.js +379 -0
  59. package/dist/charts/choropleth/choropleth-chart.js +644 -0
  60. package/dist/charts/choropleth/choropleth-context.js +152 -0
  61. package/dist/charts/choropleth/choropleth-dot-grid.js +293 -0
  62. package/dist/charts/choropleth/choropleth-feature.js +291 -0
  63. package/dist/charts/choropleth/choropleth-graticule.js +40 -0
  64. package/dist/charts/choropleth/choropleth-marker.js +222 -0
  65. package/dist/charts/choropleth/choropleth-projection.js +37 -0
  66. package/dist/charts/choropleth/choropleth-tooltip.js +82 -0
  67. package/dist/charts/choropleth/choropleth-zoom-matrix.js +150 -0
  68. package/dist/charts/choropleth/index.js +44 -0
  69. package/dist/charts/choropleth/use-choropleth-zoom-state.js +636 -0
  70. package/dist/charts/composed-chart.js +346 -0
  71. package/dist/charts/crosshair-store.js +49 -0
  72. package/dist/charts/dash-tail-stroke.js +58 -0
  73. package/dist/charts/date-pill-store.js +50 -0
  74. package/dist/charts/date-ranges.js +131 -0
  75. package/dist/charts/deadline.js +295 -0
  76. package/dist/charts/decimate-time-series.js +112 -0
  77. package/dist/charts/fade-edges.js +171 -0
  78. package/dist/charts/fast-path.js +78 -0
  79. package/dist/charts/filter-data-by-x-domain.js +45 -0
  80. package/dist/charts/funnel-chart.js +773 -0
  81. package/dist/charts/gauge-arc-layers.js +479 -0
  82. package/dist/charts/gauge-dial.js +329 -0
  83. package/dist/charts/gauge-label-layout.js +148 -0
  84. package/dist/charts/gauge.js +946 -0
  85. package/dist/charts/generate-chart-skeleton-data.js +27 -0
  86. package/dist/charts/gradients.js +158 -0
  87. package/dist/charts/grid-lines.js +114 -0
  88. package/dist/charts/grid.js +225 -0
  89. package/dist/charts/heatmap/generate-heatmap-skeleton-data.js +13 -0
  90. package/dist/charts/heatmap/heatmap-animation.js +128 -0
  91. package/dist/charts/heatmap/heatmap-cells.js +519 -0
  92. package/dist/charts/heatmap/heatmap-chart-loading.js +44 -0
  93. package/dist/charts/heatmap/heatmap-chart.js +548 -0
  94. package/dist/charts/heatmap/heatmap-colors.js +127 -0
  95. package/dist/charts/heatmap/heatmap-context.js +107 -0
  96. package/dist/charts/heatmap/heatmap-legend-gradient.js +97 -0
  97. package/dist/charts/heatmap/heatmap-legend-swatch.js +76 -0
  98. package/dist/charts/heatmap/heatmap-legend.js +165 -0
  99. package/dist/charts/heatmap/heatmap-pattern-defs.js +37 -0
  100. package/dist/charts/heatmap/heatmap-rect-cells.js +39 -0
  101. package/dist/charts/heatmap/heatmap-resolve-separator.js +84 -0
  102. package/dist/charts/heatmap/heatmap-separator.js +168 -0
  103. package/dist/charts/heatmap/heatmap-tooltip.js +73 -0
  104. package/dist/charts/heatmap/heatmap-utils.js +633 -0
  105. package/dist/charts/heatmap/heatmap-x-axis.js +79 -0
  106. package/dist/charts/heatmap/heatmap-y-axis.js +72 -0
  107. package/dist/charts/heatmap/index.js +208 -0
  108. package/dist/charts/highlight-segment-bounds.js +34 -0
  109. package/dist/charts/highlight-segment.js +119 -0
  110. package/dist/charts/index.js +944 -0
  111. package/dist/charts/indicator-fade.js +44 -0
  112. package/dist/charts/legend/index.js +22 -0
  113. package/dist/charts/legend/legend-context.js +47 -0
  114. package/dist/charts/legend/legend-item.js +30 -0
  115. package/dist/charts/legend/legend-label.js +14 -0
  116. package/dist/charts/legend/legend-marker.js +18 -0
  117. package/dist/charts/legend/legend-progress.js +39 -0
  118. package/dist/charts/legend/legend-value.js +31 -0
  119. package/dist/charts/legend/legend.js +69 -0
  120. package/dist/charts/line-backdrop.js +129 -0
  121. package/dist/charts/line-chart-loading.js +85 -0
  122. package/dist/charts/line-chart.js +182 -0
  123. package/dist/charts/line-loading-pulse.js +185 -0
  124. package/dist/charts/line-loading-timing.js +12 -0
  125. package/dist/charts/line-path.js +58 -0
  126. package/dist/charts/line-series-terminal-marker.js +75 -0
  127. package/dist/charts/line.js +499 -0
  128. package/dist/charts/live-line-chart.js +494 -0
  129. package/dist/charts/live-line.js +277 -0
  130. package/dist/charts/live-x-axis.js +116 -0
  131. package/dist/charts/live-y-axis.js +164 -0
  132. package/dist/charts/loading-sweep.js +344 -0
  133. package/dist/charts/local-point.js +56 -0
  134. package/dist/charts/markers/chart-markers.js +149 -0
  135. package/dist/charts/markers/index.js +14 -0
  136. package/dist/charts/markers/marker-group.js +411 -0
  137. package/dist/charts/motion-utils.js +29 -0
  138. package/dist/charts/notch-gauge-shared.js +146 -0
  139. package/dist/charts/particle-line.js +1340 -0
  140. package/dist/charts/path-stroke-utils.js +51 -0
  141. package/dist/charts/pattern-area.js +127 -0
  142. package/dist/charts/pattern-preset.js +287 -0
  143. package/dist/charts/pattern-tile.js +31 -0
  144. package/dist/charts/patterns/circles.js +62 -0
  145. package/dist/charts/patterns/constants.js +9 -0
  146. package/dist/charts/patterns/hexagons.js +38 -0
  147. package/dist/charts/patterns/index.js +16 -0
  148. package/dist/charts/patterns/lines.js +65 -0
  149. package/dist/charts/patterns/path.js +37 -0
  150. package/dist/charts/patterns/pattern.js +16 -0
  151. package/dist/charts/patterns/waves.js +40 -0
  152. package/dist/charts/pie-center-shell.js +127 -0
  153. package/dist/charts/pie-center.js +87 -0
  154. package/dist/charts/pie-chart.js +377 -0
  155. package/dist/charts/pie-context.js +116 -0
  156. package/dist/charts/pie-slice.js +394 -0
  157. package/dist/charts/pie-ticks.js +332 -0
  158. package/dist/charts/profit-loss-legend-hover.js +18 -0
  159. package/dist/charts/profit-loss-legend.js +53 -0
  160. package/dist/charts/profit-loss-line.js +162 -0
  161. package/dist/charts/profit-loss-segments.js +88 -0
  162. package/dist/charts/projection-config.js +90 -0
  163. package/dist/charts/projection-line-end-marker.js +50 -0
  164. package/dist/charts/projection-line.js +466 -0
  165. package/dist/charts/projection-utils.js +303 -0
  166. package/dist/charts/radar-area.js +192 -0
  167. package/dist/charts/radar-axis.js +41 -0
  168. package/dist/charts/radar-chart.js +184 -0
  169. package/dist/charts/radar-context.js +104 -0
  170. package/dist/charts/radar-grid.js +121 -0
  171. package/dist/charts/radar-labels.js +62 -0
  172. package/dist/charts/radial-area.js +498 -0
  173. package/dist/charts/radial-axis.js +652 -0
  174. package/dist/charts/radial-bar.js +316 -0
  175. package/dist/charts/radial-center.js +67 -0
  176. package/dist/charts/radial-chart.js +740 -0
  177. package/dist/charts/radial-dot-bar-layout.js +68 -0
  178. package/dist/charts/radial-dot-bar.js +387 -0
  179. package/dist/charts/radial-geometry.js +114 -0
  180. package/dist/charts/radial-legend.js +66 -0
  181. package/dist/charts/radial-line.js +280 -0
  182. package/dist/charts/radial-ring-bar.js +255 -0
  183. package/dist/charts/radial-scrubber.js +120 -0
  184. package/dist/charts/radial-series-color.js +10 -0
  185. package/dist/charts/reference-area-config.js +43 -0
  186. package/dist/charts/reference-area-geometry.js +76 -0
  187. package/dist/charts/reference-area-registration-context.js +10 -0
  188. package/dist/charts/reference-area.js +241 -0
  189. package/dist/charts/responsive-chart-label-count.js +18 -0
  190. package/dist/charts/ring-center.js +78 -0
  191. package/dist/charts/ring-chart.js +362 -0
  192. package/dist/charts/ring-context.js +122 -0
  193. package/dist/charts/ring-grid.js +175 -0
  194. package/dist/charts/ring-labels.js +109 -0
  195. package/dist/charts/ring.js +237 -0
  196. package/dist/charts/sankey/index.js +22 -0
  197. package/dist/charts/sankey/sankey-chart.js +199 -0
  198. package/dist/charts/sankey/sankey-context.js +32 -0
  199. package/dist/charts/sankey/sankey-link.js +232 -0
  200. package/dist/charts/sankey/sankey-node.js +348 -0
  201. package/dist/charts/sankey/sankey-tooltip.js +94 -0
  202. package/dist/charts/scatter-chart-shell.js +279 -0
  203. package/dist/charts/scatter-chart.js +150 -0
  204. package/dist/charts/scatter-jitter.js +86 -0
  205. package/dist/charts/scatter-svg.js +17 -0
  206. package/dist/charts/scatter.js +92 -0
  207. package/dist/charts/segment.js +107 -0
  208. package/dist/charts/series-bar-layout.js +42 -0
  209. package/dist/charts/series-bar.js +241 -0
  210. package/dist/charts/series-dash-tail-overlay.js +53 -0
  211. package/dist/charts/series-highlight-layer.js +43 -0
  212. package/dist/charts/series-hover-dim.js +32 -0
  213. package/dist/charts/series-markers.js +239 -0
  214. package/dist/charts/series-path-utils.js +185 -0
  215. package/dist/charts/series-point-marker.js +150 -0
  216. package/dist/charts/sparkline-geometry.js +197 -0
  217. package/dist/charts/sparkline.js +910 -0
  218. package/dist/charts/static-chart-preview-context.js +16 -0
  219. package/dist/charts/sunburst-breadcrumb.js +33 -0
  220. package/dist/charts/sunburst-center.js +37 -0
  221. package/dist/charts/sunburst-chart.js +408 -0
  222. package/dist/charts/sunburst-context.js +140 -0
  223. package/dist/charts/sunburst-data.js +0 -0
  224. package/dist/charts/sunburst-hint.js +42 -0
  225. package/dist/charts/sunburst-labels.js +130 -0
  226. package/dist/charts/sunburst-segment.js +144 -0
  227. package/dist/charts/sunburst.js +419 -0
  228. package/dist/charts/time-series-chart-shell.js +688 -0
  229. package/dist/charts/tooltip/chart-tooltip.js +516 -0
  230. package/dist/charts/tooltip/cursor-tooltip-box.js +183 -0
  231. package/dist/charts/tooltip/date-ticker.js +376 -0
  232. package/dist/charts/tooltip/index.js +32 -0
  233. package/dist/charts/tooltip/liquid-glass.js +142 -0
  234. package/dist/charts/tooltip/tooltip-box.js +502 -0
  235. package/dist/charts/tooltip/tooltip-content.js +59 -0
  236. package/dist/charts/tooltip/tooltip-dot.js +170 -0
  237. package/dist/charts/tooltip/tooltip-indicator.js +175 -0
  238. package/dist/charts/tooltip/use-delayed-tooltip-data.js +41 -0
  239. package/dist/charts/tooltip/use-velocity-stretch.js +52 -0
  240. package/dist/charts/trend-line-utils.js +64 -0
  241. package/dist/charts/trend-line.js +318 -0
  242. package/dist/charts/use-animated-band.js +175 -0
  243. package/dist/charts/use-animated-series-path.js +208 -0
  244. package/dist/charts/use-animated-y-domains.js +192 -0
  245. package/dist/charts/use-category-slots.js +29 -0
  246. package/dist/charts/use-chart-interaction.js +296 -0
  247. package/dist/charts/use-chart-phase-orchestrator.js +183 -0
  248. package/dist/charts/use-enter-complete.js +18 -0
  249. package/dist/charts/use-grid-shimmer.js +88 -0
  250. package/dist/charts/use-highlight-segment.js +65 -0
  251. package/dist/charts/use-mount-progress.js +23 -0
  252. package/dist/charts/use-scatter-chart-interaction.js +364 -0
  253. package/dist/charts/use-scheduled-tooltip.js +84 -0
  254. package/dist/charts/visx-pattern.js +30 -0
  255. package/dist/charts/weekends.js +174 -0
  256. package/dist/charts/x-axis-hover.js +46 -0
  257. package/dist/charts/x-axis.js +523 -0
  258. package/dist/charts/y-axis-scales.js +71 -0
  259. package/dist/charts/y-axis-ticks.js +22 -0
  260. package/dist/charts/y-axis.js +233 -0
  261. package/dist/charts/y-domain-utils.js +189 -0
  262. package/dist/index.d.ts +7346 -0
  263. package/dist/index.js +2 -0
  264. package/dist/lib/utils.js +8 -0
  265. package/dist/shimmering-text.js +54 -0
  266. package/package.json +78 -4
  267. package/tema.css +202 -0
@@ -0,0 +1,37 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { cn } from "../../lib/utils";
3
+ import { Pattern } from "./pattern";
4
+ function Path({
5
+ id,
6
+ width,
7
+ height,
8
+ path,
9
+ fill = "transparent",
10
+ stroke,
11
+ strokeWidth,
12
+ strokeDasharray,
13
+ strokeLinecap = "square",
14
+ shapeRendering = "auto",
15
+ background,
16
+ className
17
+ }) {
18
+ return /* @__PURE__ */ jsxs(Pattern, { height, id, width, children: [
19
+ !!background && /* @__PURE__ */ jsx("rect", { fill: background, height, width }),
20
+ /* @__PURE__ */ jsx(
21
+ "path",
22
+ {
23
+ className: cn("visx-pattern-path", className),
24
+ d: path,
25
+ fill,
26
+ shapeRendering,
27
+ stroke,
28
+ strokeDasharray,
29
+ strokeLinecap,
30
+ strokeWidth
31
+ }
32
+ )
33
+ ] });
34
+ }
35
+ export {
36
+ Path
37
+ };
@@ -0,0 +1,16 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ function Pattern({ id, width, height, children }) {
3
+ return /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx(
4
+ "pattern",
5
+ {
6
+ height,
7
+ id,
8
+ patternUnits: "userSpaceOnUse",
9
+ width,
10
+ children
11
+ }
12
+ ) });
13
+ }
14
+ export {
15
+ Pattern
16
+ };
@@ -0,0 +1,40 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { cn } from "../../lib/utils";
3
+ import { Path } from "./path";
4
+ function Waves({
5
+ id,
6
+ width,
7
+ height,
8
+ fill,
9
+ stroke,
10
+ strokeWidth,
11
+ strokeDasharray,
12
+ strokeLinecap,
13
+ shapeRendering,
14
+ background,
15
+ className
16
+ }) {
17
+ return /* @__PURE__ */ jsx(
18
+ Path,
19
+ {
20
+ background,
21
+ className: cn("visx-pattern-wave", className),
22
+ fill,
23
+ height,
24
+ id,
25
+ path: `M 0 ${height / 2} c ${height / 8} ${-height / 4} , ${height * 3 / 8} ${-height / 4} , ${height / 2} 0
26
+ c ${height / 8} ${height / 4} , ${height * 3 / 8} ${height / 4} , ${height / 2} 0 M ${-height / 2} ${height / 2}
27
+ c ${height / 8} ${height / 4} , ${height * 3 / 8} ${height / 4} , ${height / 2} 0 M ${height} ${height / 2}
28
+ c ${height / 8} ${-height / 4} , ${height * 3 / 8} ${-height / 4} , ${height / 2} 0`,
29
+ shapeRendering,
30
+ stroke,
31
+ strokeDasharray,
32
+ strokeLinecap,
33
+ strokeWidth,
34
+ width
35
+ }
36
+ );
37
+ }
38
+ export {
39
+ Waves
40
+ };
@@ -0,0 +1,127 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { pie as d3Pie } from "d3-shape";
4
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
5
+ import { PieCenter } from "./pie-center";
6
+ import {
7
+ defaultPieColors,
8
+ PieProvider
9
+ } from "./pie-context";
10
+ const SHELL_HOVER_OFFSET = 10;
11
+ function PieCenterShell({
12
+ centerValue,
13
+ contextSize,
14
+ innerRadiusPx,
15
+ animateEntrance = true,
16
+ ...pieCenterProps
17
+ }) {
18
+ const containerRef = useRef(null);
19
+ const [introValue, setIntroValue] = useState(null);
20
+ useEffect(() => {
21
+ if (!animateEntrance) {
22
+ return;
23
+ }
24
+ let innerRaf = 0;
25
+ const outerRaf = requestAnimationFrame(() => {
26
+ innerRaf = requestAnimationFrame(() => setIntroValue(centerValue));
27
+ });
28
+ return () => {
29
+ cancelAnimationFrame(outerRaf);
30
+ cancelAnimationFrame(innerRaf);
31
+ setIntroValue(null);
32
+ };
33
+ }, [animateEntrance, centerValue]);
34
+ let flowTotal = centerValue;
35
+ if (animateEntrance && introValue !== centerValue) {
36
+ flowTotal = 0;
37
+ }
38
+ const data = useMemo(
39
+ () => [{ label: "_pieCenterShell", value: Math.max(flowTotal, 0) }],
40
+ [flowTotal]
41
+ );
42
+ const totalValue = flowTotal;
43
+ const arcs = useMemo(() => {
44
+ const v = data[0]?.value ?? 0;
45
+ if (v > 0) {
46
+ const pieGenerator = d3Pie().value((d) => d.value).startAngle(-Math.PI / 2).endAngle(3 * Math.PI / 2).padAngle(0).sort(null);
47
+ const computed = pieGenerator(data);
48
+ return computed.map((arc, index) => ({
49
+ data: arc.data,
50
+ index,
51
+ startAngle: arc.startAngle,
52
+ endAngle: arc.endAngle,
53
+ padAngle: arc.padAngle,
54
+ value: arc.value
55
+ }));
56
+ }
57
+ const d0 = data[0];
58
+ if (!d0) {
59
+ return [];
60
+ }
61
+ return [
62
+ {
63
+ data: d0,
64
+ index: 0,
65
+ startAngle: -Math.PI / 2,
66
+ endAngle: 3 * Math.PI / 2,
67
+ padAngle: 0,
68
+ value: 0
69
+ }
70
+ ];
71
+ }, [data]);
72
+ const getColor = useCallback((index) => {
73
+ return defaultPieColors[index % defaultPieColors.length];
74
+ }, []);
75
+ const getFill = useCallback(
76
+ (index) => {
77
+ const item = data[index];
78
+ if (item?.fill) {
79
+ return item.fill;
80
+ }
81
+ return getColor(index);
82
+ },
83
+ [data, getColor]
84
+ );
85
+ const center = contextSize / 2;
86
+ const outerRadius = center - SHELL_HOVER_OFFSET;
87
+ const contextValue = useMemo(
88
+ () => ({
89
+ data,
90
+ arcs,
91
+ size: contextSize,
92
+ center,
93
+ outerRadius,
94
+ innerRadius: innerRadiusPx,
95
+ padAngle: 0,
96
+ cornerRadius: 0,
97
+ hoverOffset: SHELL_HOVER_OFFSET,
98
+ hoveredIndex: null,
99
+ setHoveredIndex: () => void 0,
100
+ animationKey: 0,
101
+ isLoaded: true,
102
+ enterStaggerScale: 1,
103
+ containerRef,
104
+ totalValue,
105
+ getColor,
106
+ getFill,
107
+ geometryScrubbing: false,
108
+ scrubSlicePaths: null
109
+ }),
110
+ [
111
+ data,
112
+ arcs,
113
+ contextSize,
114
+ center,
115
+ outerRadius,
116
+ innerRadiusPx,
117
+ totalValue,
118
+ getColor,
119
+ getFill
120
+ ]
121
+ );
122
+ return /* @__PURE__ */ jsx(PieProvider, { value: contextValue, children: /* @__PURE__ */ jsx(PieCenter, { ...pieCenterProps }) });
123
+ }
124
+ PieCenterShell.displayName = "PieCenterShell";
125
+ export {
126
+ PieCenterShell
127
+ };
@@ -0,0 +1,87 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { cn } from "../lib/utils";
4
+ import {
5
+ chartCenterContainerClassName,
6
+ chartCenterLabelClassName,
7
+ chartCenterValueClassName
8
+ } from "./chart-center-typography";
9
+ import {
10
+ ChartStatFlow,
11
+ defaultChartStatFlowFormat
12
+ } from "./chart-stat-flow";
13
+ import { usePieHover, usePieStable } from "./pie-context";
14
+ function PieCenter({
15
+ defaultLabel = "Total",
16
+ formatOptions = defaultChartStatFlowFormat,
17
+ children,
18
+ className = "",
19
+ valueClassName = chartCenterValueClassName,
20
+ labelClassName = chartCenterLabelClassName,
21
+ prefix,
22
+ suffix: suffixProp,
23
+ valueDisplay = "value"
24
+ }) {
25
+ const { data, totalValue, innerRadius, geometryScrubbing } = usePieStable();
26
+ const { hoveredIndex } = usePieHover();
27
+ const effectiveHoveredIndex = geometryScrubbing ? null : hoveredIndex;
28
+ const hoveredData = effectiveHoveredIndex === null ? null : data[effectiveHoveredIndex];
29
+ const percentMode = valueDisplay === "percent";
30
+ const suffix = suffixProp ?? (percentMode ? "%" : void 0);
31
+ const rawValue = hoveredData ? hoveredData.value : totalValue;
32
+ const share = totalValue > 0 ? rawValue / totalValue * 100 : 0;
33
+ const displayValue = percentMode ? Math.round(share) : rawValue;
34
+ const displayLabel = hoveredData ? hoveredData.label : defaultLabel;
35
+ const centerSize = innerRadius * 2 - 16;
36
+ if (innerRadius <= 0) {
37
+ return null;
38
+ }
39
+ if (children) {
40
+ return /* @__PURE__ */ jsx(
41
+ "div",
42
+ {
43
+ className: cn(
44
+ chartCenterContainerClassName,
45
+ "flex items-center justify-center",
46
+ className
47
+ ),
48
+ style: { width: centerSize, height: centerSize },
49
+ children: children({
50
+ value: displayValue,
51
+ label: displayLabel,
52
+ isHovered: Boolean(hoveredData),
53
+ data: hoveredData ?? { label: defaultLabel, value: totalValue }
54
+ })
55
+ }
56
+ );
57
+ }
58
+ return /* @__PURE__ */ jsx(
59
+ "div",
60
+ {
61
+ className: cn(
62
+ chartCenterContainerClassName,
63
+ "flex flex-col items-center justify-center text-center",
64
+ className
65
+ ),
66
+ style: { width: centerSize, height: centerSize },
67
+ children: /* @__PURE__ */ jsx(
68
+ ChartStatFlow,
69
+ {
70
+ formatOptions,
71
+ label: displayLabel,
72
+ labelClassName,
73
+ prefix,
74
+ suffix,
75
+ value: displayValue,
76
+ valueClassName
77
+ }
78
+ )
79
+ }
80
+ );
81
+ }
82
+ PieCenter.displayName = "PieCenter";
83
+ var pie_center_default = PieCenter;
84
+ export {
85
+ PieCenter,
86
+ pie_center_default as default
87
+ };
@@ -0,0 +1,377 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { pie as d3Pie } from "d3-shape";
4
+ import { domAnimation, LazyMotion } from "motion/react";
5
+ import {
6
+ Children,
7
+ isValidElement,
8
+ memo,
9
+ useCallback,
10
+ useEffect,
11
+ useMemo,
12
+ useRef,
13
+ useState
14
+ } from "react";
15
+ import { cn } from "../lib/utils";
16
+ import { arcPath } from "./arc-path";
17
+ import { useChartDataOverride } from "./chart-data-override";
18
+ import { InteracaoProvider } from "../aic/interacao";
19
+ import { ParentSize } from "./chart-parent-size";
20
+ import {
21
+ defaultPieColors,
22
+ PieProvider
23
+ } from "./pie-context";
24
+ const DEFAULT_HOVER_OFFSET = 10;
25
+ function isPieCenter(child) {
26
+ return isValidElement(child) && typeof child.type === "function" && (child.type.displayName === "PieCenter" || child.type.name === "PieCenter");
27
+ }
28
+ function isPieSlice(child) {
29
+ return isValidElement(child) && typeof child.type === "function" && (child.type.displayName === "PieSlice" || child.type.name === "PieSlice");
30
+ }
31
+ function isDefsComponent(child) {
32
+ const displayName = child.type?.displayName || child.type?.name || "";
33
+ return displayName.includes("Gradient") || displayName.includes("Pattern") || displayName === "LinearGradient" || displayName === "RadialGradient";
34
+ }
35
+ function PieChartInner(props) {
36
+ const size = Math.min(props.width, props.height);
37
+ if (size < 10) {
38
+ return null;
39
+ }
40
+ return /* @__PURE__ */ jsx(PieChartCore, { ...props });
41
+ }
42
+ const PieChartCore = memo(function PieChartCore2({
43
+ width,
44
+ height,
45
+ data,
46
+ innerRadius: innerRadiusProp,
47
+ padAngle,
48
+ cornerRadius,
49
+ startAngle,
50
+ endAngle,
51
+ hoverOffset,
52
+ children,
53
+ containerRef,
54
+ hoveredIndexProp,
55
+ onHoverChange,
56
+ enterTransition,
57
+ enterStaggerScale,
58
+ geometryScrubbing
59
+ }) {
60
+ const [internalHoveredIndex, setInternalHoveredIndex] = useState(null);
61
+ const [animationKey] = useState(0);
62
+ const [isLoaded, setIsLoaded] = useState(false);
63
+ const isControlled = hoveredIndexProp !== void 0;
64
+ const hoveredIndex = isControlled ? hoveredIndexProp : internalHoveredIndex;
65
+ const setHoveredIndex = useCallback(
66
+ (index) => {
67
+ if (isControlled) {
68
+ onHoverChange?.(index);
69
+ } else {
70
+ setInternalHoveredIndex(index);
71
+ }
72
+ },
73
+ [isControlled, onHoverChange]
74
+ );
75
+ const size = Math.min(width, height);
76
+ const center = size / 2;
77
+ const padding = hoverOffset;
78
+ const outerRadius = center - padding;
79
+ const innerRadius = innerRadiusProp;
80
+ const totalValue = useMemo(
81
+ () => data.reduce((sum, d) => sum + d.value, 0),
82
+ [data]
83
+ );
84
+ const getColor = useCallback(
85
+ (index) => {
86
+ const item = data[index];
87
+ if (item?.color) {
88
+ return item.color;
89
+ }
90
+ return defaultPieColors[index % defaultPieColors.length];
91
+ },
92
+ [data]
93
+ );
94
+ const getFill = useCallback(
95
+ (index) => {
96
+ const item = data[index];
97
+ if (item?.fill) {
98
+ return item.fill;
99
+ }
100
+ return getColor(index);
101
+ },
102
+ [data, getColor]
103
+ );
104
+ const arcs = useMemo(() => {
105
+ const pieGenerator = d3Pie().value((d) => d.value).startAngle(startAngle).endAngle(endAngle).padAngle(padAngle).sort(null);
106
+ const computed = pieGenerator(data);
107
+ return computed.map((arc, index) => ({
108
+ data: arc.data,
109
+ index,
110
+ startAngle: arc.startAngle,
111
+ endAngle: arc.endAngle,
112
+ padAngle: arc.padAngle,
113
+ value: arc.value
114
+ }));
115
+ }, [data, startAngle, endAngle, padAngle]);
116
+ const scrubSlicePaths = useMemo(() => {
117
+ if (!geometryScrubbing) {
118
+ return null;
119
+ }
120
+ return arcs.map(
121
+ (arc) => arcPath(
122
+ innerRadius,
123
+ outerRadius,
124
+ arc.startAngle,
125
+ arc.endAngle,
126
+ cornerRadius,
127
+ arc.padAngle
128
+ )
129
+ );
130
+ }, [geometryScrubbing, arcs, innerRadius, outerRadius, cornerRadius]);
131
+ const effectiveIsLoaded = geometryScrubbing || isLoaded;
132
+ const [enterKey, setEnterKey] = useState({
133
+ enterTransition,
134
+ enterStaggerScale,
135
+ geometryScrubbing
136
+ });
137
+ if (enterKey.enterTransition !== enterTransition || enterKey.enterStaggerScale !== enterStaggerScale || enterKey.geometryScrubbing !== geometryScrubbing) {
138
+ setEnterKey({ enterTransition, enterStaggerScale, geometryScrubbing });
139
+ if (!geometryScrubbing) {
140
+ setIsLoaded(false);
141
+ }
142
+ }
143
+ useEffect(() => {
144
+ if (geometryScrubbing) {
145
+ return;
146
+ }
147
+ const timer = setTimeout(() => {
148
+ setIsLoaded(true);
149
+ }, 100);
150
+ return () => clearTimeout(timer);
151
+ }, [enterTransition, enterStaggerScale, geometryScrubbing]);
152
+ const { svgChildren, centerChildren, defsChildren } = useMemo(() => {
153
+ const svgNodes = [];
154
+ const centerNodes = [];
155
+ const defsNodes = [];
156
+ Children.forEach(children, (child) => {
157
+ if (!isValidElement(child)) {
158
+ svgNodes.push(child);
159
+ return;
160
+ }
161
+ if (isPieCenter(child)) {
162
+ centerNodes.push(child);
163
+ } else if (isDefsComponent(child)) {
164
+ defsNodes.push(child);
165
+ } else if (geometryScrubbing && isPieSlice(child)) {
166
+ return;
167
+ } else {
168
+ svgNodes.push(child);
169
+ }
170
+ });
171
+ return {
172
+ svgChildren: svgNodes,
173
+ centerChildren: centerNodes,
174
+ defsChildren: defsNodes
175
+ };
176
+ }, [children, geometryScrubbing]);
177
+ const scrubSliceFills = useMemo(() => {
178
+ if (!(geometryScrubbing && scrubSlicePaths)) {
179
+ return null;
180
+ }
181
+ return scrubSlicePaths.map((_, index) => getFill(index));
182
+ }, [geometryScrubbing, scrubSlicePaths, getFill]);
183
+ const contextValue = useMemo(
184
+ () => ({
185
+ data,
186
+ arcs,
187
+ size,
188
+ center,
189
+ outerRadius,
190
+ innerRadius,
191
+ padAngle,
192
+ cornerRadius,
193
+ hoverOffset,
194
+ hoveredIndex,
195
+ setHoveredIndex,
196
+ animationKey,
197
+ isLoaded: effectiveIsLoaded,
198
+ enterTransition,
199
+ enterStaggerScale,
200
+ containerRef,
201
+ totalValue,
202
+ getColor,
203
+ getFill,
204
+ geometryScrubbing,
205
+ scrubSlicePaths
206
+ }),
207
+ [
208
+ data,
209
+ arcs,
210
+ size,
211
+ center,
212
+ outerRadius,
213
+ innerRadius,
214
+ padAngle,
215
+ cornerRadius,
216
+ hoverOffset,
217
+ hoveredIndex,
218
+ setHoveredIndex,
219
+ animationKey,
220
+ effectiveIsLoaded,
221
+ enterTransition,
222
+ enterStaggerScale,
223
+ containerRef,
224
+ totalValue,
225
+ getColor,
226
+ getFill,
227
+ geometryScrubbing,
228
+ scrubSlicePaths
229
+ ]
230
+ );
231
+ return /* @__PURE__ */ jsx(PieProvider, { value: contextValue, children: /* @__PURE__ */ jsxs(
232
+ "div",
233
+ {
234
+ className: "grid",
235
+ style: {
236
+ gridTemplateColumns: "1fr",
237
+ gridTemplateRows: "1fr",
238
+ width: size,
239
+ height: size
240
+ },
241
+ children: [
242
+ /* @__PURE__ */ jsxs(
243
+ "svg",
244
+ {
245
+ "aria-hidden": "true",
246
+ height: size,
247
+ style: {
248
+ gridArea: "1 / 1",
249
+ // No `paint` containment: it clips hover glow at the svg box.
250
+ contain: "layout style",
251
+ overflow: "visible"
252
+ },
253
+ width: size,
254
+ children: [
255
+ defsChildren.length > 0 && /* @__PURE__ */ jsx("defs", { children: defsChildren }),
256
+ /* @__PURE__ */ jsxs("g", { transform: `translate(${center}, ${center})`, children: [
257
+ scrubSlicePaths && scrubSliceFills ? scrubSlicePaths.map(
258
+ (d, index) => d ? /* @__PURE__ */ jsx(
259
+ "path",
260
+ {
261
+ d,
262
+ fill: scrubSliceFills[index],
263
+ pointerEvents: "none"
264
+ },
265
+ data[index]?.label ?? index
266
+ ) : null
267
+ ) : null,
268
+ svgChildren
269
+ ] })
270
+ ]
271
+ }
272
+ ),
273
+ centerChildren.length > 0 && /* @__PURE__ */ jsx(
274
+ "div",
275
+ {
276
+ className: "pointer-events-none flex items-center justify-center",
277
+ style: { gridArea: "1 / 1" },
278
+ children: centerChildren
279
+ }
280
+ )
281
+ ]
282
+ }
283
+ ) });
284
+ }, pieChartCorePropsEqual);
285
+ function pieChartCorePropsEqual(prev, next) {
286
+ return prev.width === next.width && prev.height === next.height && prev.data === next.data && prev.innerRadius === next.innerRadius && prev.padAngle === next.padAngle && prev.cornerRadius === next.cornerRadius && prev.startAngle === next.startAngle && prev.endAngle === next.endAngle && prev.hoverOffset === next.hoverOffset && prev.hoveredIndexProp === next.hoveredIndexProp && prev.onHoverChange === next.onHoverChange && prev.enterTransition === next.enterTransition && prev.enterStaggerScale === next.enterStaggerScale && prev.geometryScrubbing === next.geometryScrubbing && prev.children === next.children;
287
+ }
288
+ function PieChart({
289
+ data: dataProp,
290
+ size: fixedSize,
291
+ innerRadius = 0,
292
+ padAngle = 0,
293
+ cornerRadius = 0,
294
+ startAngle = -Math.PI / 2,
295
+ endAngle = 3 * Math.PI / 2,
296
+ className = "",
297
+ hoveredIndex,
298
+ onHoverChange,
299
+ hoverOffset = DEFAULT_HOVER_OFFSET,
300
+ enterTransition,
301
+ enterStaggerScale = 1,
302
+ geometryScrubbing = false,
303
+ children,
304
+ onSliceClick,
305
+ selectedIndex
306
+ }) {
307
+ const { data } = useChartDataOverride("PieChart", {
308
+ data: dataProp
309
+ });
310
+ const containerRef = useRef(null);
311
+ if (fixedSize) {
312
+ return /* @__PURE__ */ jsx(LazyMotion, { features: domAnimation, children: /* @__PURE__ */ jsx(InteracaoProvider, { aoClicar: onSliceClick, data, selecao: selectedIndex, children: /* @__PURE__ */ jsx(
313
+ "div",
314
+ {
315
+ className: cn("relative flex items-center justify-center", className),
316
+ ref: containerRef,
317
+ style: { width: fixedSize, height: fixedSize },
318
+ children: /* @__PURE__ */ jsx(
319
+ PieChartInner,
320
+ {
321
+ containerRef,
322
+ cornerRadius,
323
+ data,
324
+ endAngle,
325
+ enterStaggerScale,
326
+ enterTransition,
327
+ geometryScrubbing,
328
+ height: fixedSize,
329
+ hoveredIndexProp: hoveredIndex,
330
+ hoverOffset,
331
+ innerRadius,
332
+ onHoverChange,
333
+ padAngle,
334
+ startAngle,
335
+ width: fixedSize,
336
+ children
337
+ }
338
+ )
339
+ }
340
+ ) }) });
341
+ }
342
+ return /* @__PURE__ */ jsx(LazyMotion, { features: domAnimation, children: /* @__PURE__ */ jsx(InteracaoProvider, { aoClicar: onSliceClick, data, selecao: selectedIndex, children: /* @__PURE__ */ jsx(
343
+ "div",
344
+ {
345
+ className: cn("relative aspect-square w-full", className),
346
+ ref: containerRef,
347
+ children: /* @__PURE__ */ jsx(ParentSize, { debounceTime: 10, children: ({ width, height }) => /* @__PURE__ */ jsx(
348
+ PieChartInner,
349
+ {
350
+ containerRef,
351
+ cornerRadius,
352
+ data,
353
+ endAngle,
354
+ enterStaggerScale,
355
+ enterTransition,
356
+ geometryScrubbing,
357
+ height,
358
+ hoveredIndexProp: hoveredIndex,
359
+ hoverOffset,
360
+ innerRadius,
361
+ onHoverChange,
362
+ padAngle,
363
+ startAngle,
364
+ width,
365
+ children
366
+ }
367
+ ) })
368
+ }
369
+ ) }) });
370
+ }
371
+ PieChart.displayName = "PieChart";
372
+ var pie_chart_default = PieChart;
373
+ export {
374
+ DEFAULT_HOVER_OFFSET,
375
+ PieChart,
376
+ pie_chart_default as default
377
+ };