@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,291 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { geoCentroid } from "d3-geo";
4
+ import { m, useTransform } from "motion/react";
5
+ import { memo, useCallback, useMemo } from "react";
6
+ import { useEnterComplete } from "../use-enter-complete";
7
+ import { useMountProgress } from "../use-mount-progress";
8
+ import { useChoroplethCamera } from "./choropleth-camera";
9
+ import {
10
+ defaultChoroplethColors,
11
+ useChoroplethInteraction,
12
+ useChoroplethStable
13
+ } from "./choropleth-context";
14
+ function resolveFeatureFill(feature, index, fill, getFeatureColor, getFeaturePattern) {
15
+ const patternId = getFeaturePattern?.(feature, index);
16
+ if (patternId) {
17
+ return `url(#${patternId})`;
18
+ }
19
+ if (fill) {
20
+ return fill;
21
+ }
22
+ if (getFeatureColor) {
23
+ return getFeatureColor(feature, index);
24
+ }
25
+ return defaultChoroplethColors[index % defaultChoroplethColors.length] ?? "var(--chart-1)";
26
+ }
27
+ const StaticFeatureLayer = memo(function StaticFeatureLayer2({
28
+ records,
29
+ stroke,
30
+ strokeWidth,
31
+ baseOpacity,
32
+ dimOpacity,
33
+ hoveredIndex,
34
+ focusedIndex,
35
+ onFeatureEnter,
36
+ onFeatureLeave,
37
+ onFeatureClick
38
+ }) {
39
+ const isDimmed = hoveredIndex !== null;
40
+ if (!isDimmed) {
41
+ return /* @__PURE__ */ jsx("g", { opacity: baseOpacity, children: records.map((record) => (
42
+ // biome-ignore lint/a11y/noStaticElementInteractions: SVG path used as hover hitbox
43
+ /* @__PURE__ */ jsx(
44
+ "path",
45
+ {
46
+ className: "cursor-pointer",
47
+ d: record.path,
48
+ fill: record.fill,
49
+ onClick: () => onFeatureClick(record.index),
50
+ onMouseEnter: () => onFeatureEnter(record),
51
+ onMouseLeave: onFeatureLeave,
52
+ stroke,
53
+ strokeWidth
54
+ },
55
+ `base-${record.index}`
56
+ )
57
+ )) });
58
+ }
59
+ const isLit = (index) => index === hoveredIndex || index === focusedIndex;
60
+ const highlighted = records.filter((record) => isLit(record.index)).sort((a) => a.index === hoveredIndex ? 1 : -1);
61
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
62
+ /* @__PURE__ */ jsx("g", { opacity: dimOpacity, style: { transition: "opacity 0.18s ease-out" }, children: records.filter((record) => !isLit(record.index)).map((record) => (
63
+ // biome-ignore lint/a11y/noStaticElementInteractions: SVG path used as hover hitbox
64
+ /* @__PURE__ */ jsx(
65
+ "path",
66
+ {
67
+ className: "cursor-pointer",
68
+ d: record.path,
69
+ fill: record.fill,
70
+ onClick: () => onFeatureClick(record.index),
71
+ onMouseEnter: () => onFeatureEnter(record),
72
+ onMouseLeave: onFeatureLeave,
73
+ stroke,
74
+ strokeWidth
75
+ },
76
+ `base-${record.index}`
77
+ )
78
+ )) }),
79
+ highlighted.map((record) => (
80
+ // biome-ignore lint/a11y/noStaticElementInteractions: SVG path used as hover hitbox
81
+ /* @__PURE__ */ jsx(
82
+ "path",
83
+ {
84
+ className: "cursor-pointer",
85
+ d: record.path,
86
+ fill: record.fill,
87
+ onClick: () => onFeatureClick(record.index),
88
+ onMouseEnter: () => onFeatureEnter(record),
89
+ onMouseLeave: onFeatureLeave,
90
+ opacity: 1,
91
+ stroke,
92
+ strokeWidth,
93
+ style: { transition: "opacity 0.18s ease-out" }
94
+ },
95
+ `highlight-${record.index}`
96
+ )
97
+ ))
98
+ ] });
99
+ });
100
+ const EnterFeatureLayer = memo(function EnterFeatureLayer2({
101
+ records,
102
+ stroke,
103
+ strokeWidth,
104
+ baseOpacity,
105
+ dimOpacity,
106
+ hoveredIndex,
107
+ focusedIndex,
108
+ onFeatureEnter,
109
+ onFeatureLeave,
110
+ onFeatureClick,
111
+ revealEpoch
112
+ }) {
113
+ const { enterTransition, animationDuration } = useChoroplethStable();
114
+ const mountProgress = useMountProgress(
115
+ enterTransition,
116
+ 0,
117
+ `choropleth-layer-${revealEpoch}`
118
+ );
119
+ const enterComplete = useEnterComplete(mountProgress);
120
+ const layerOpacity = useTransform(mountProgress, (t) => t * baseOpacity);
121
+ if (enterComplete) {
122
+ return /* @__PURE__ */ jsx(
123
+ StaticFeatureLayer,
124
+ {
125
+ baseOpacity,
126
+ dimOpacity,
127
+ focusedIndex,
128
+ hoveredIndex,
129
+ onFeatureClick,
130
+ onFeatureEnter,
131
+ onFeatureLeave,
132
+ records,
133
+ stroke,
134
+ strokeWidth
135
+ }
136
+ );
137
+ }
138
+ return /* @__PURE__ */ jsx(
139
+ m.g,
140
+ {
141
+ opacity: layerOpacity,
142
+ transition: {
143
+ duration: animationDuration / 1e3,
144
+ ease: "easeOut"
145
+ },
146
+ children: records.map((record) => (
147
+ // biome-ignore lint/a11y/noStaticElementInteractions: SVG path used as hover hitbox
148
+ /* @__PURE__ */ jsx(
149
+ "path",
150
+ {
151
+ className: "cursor-pointer",
152
+ d: record.path,
153
+ fill: record.fill,
154
+ onClick: () => onFeatureClick(record.index),
155
+ onMouseEnter: () => onFeatureEnter(record),
156
+ onMouseLeave: onFeatureLeave,
157
+ stroke,
158
+ strokeWidth
159
+ },
160
+ `enter-${record.index}`
161
+ )
162
+ ))
163
+ },
164
+ `enter-${revealEpoch}`
165
+ );
166
+ });
167
+ const ChoroplethFeature = memo(function ChoroplethFeature2({
168
+ fill,
169
+ stroke = "var(--chart-background)",
170
+ strokeWidth = 0.5,
171
+ fadedOpacity = 0.4,
172
+ getFeatureColor,
173
+ patterns,
174
+ getFeaturePattern
175
+ }) {
176
+ const {
177
+ features,
178
+ featurePaths,
179
+ pathGenerator,
180
+ projectPoint,
181
+ isLoaded,
182
+ revealEpoch,
183
+ width,
184
+ height
185
+ } = useChoroplethStable();
186
+ const { hoveredFeatureIndex, setHoveredFeatureIndex, setTooltipData } = useChoroplethInteraction();
187
+ const featureCentroids = useMemo(() => {
188
+ return features.map((feature) => {
189
+ try {
190
+ const centroid = geoCentroid(feature);
191
+ if (centroid && !Number.isNaN(centroid[0]) && !Number.isNaN(centroid[1])) {
192
+ const projected = projectPoint(centroid);
193
+ if (projected) {
194
+ const padding = 60;
195
+ return {
196
+ x: Math.max(padding, Math.min(width - padding, projected[0])),
197
+ y: Math.max(padding, Math.min(height - padding, projected[1]))
198
+ };
199
+ }
200
+ }
201
+ } catch {
202
+ }
203
+ return null;
204
+ });
205
+ }, [features, projectPoint, width, height]);
206
+ const records = useMemo(() => {
207
+ const items = [];
208
+ for (let index = 0; index < features.length; index++) {
209
+ const feature = features[index];
210
+ if (!feature) {
211
+ continue;
212
+ }
213
+ const path = featurePaths[index] ?? pathGenerator(feature);
214
+ if (!path) {
215
+ continue;
216
+ }
217
+ items.push({
218
+ index,
219
+ path,
220
+ fill: resolveFeatureFill(
221
+ feature,
222
+ index,
223
+ fill,
224
+ getFeatureColor,
225
+ getFeaturePattern
226
+ ),
227
+ feature,
228
+ centroid: featureCentroids[index] ?? null
229
+ });
230
+ }
231
+ return items;
232
+ }, [
233
+ featureCentroids,
234
+ featurePaths,
235
+ features,
236
+ fill,
237
+ getFeatureColor,
238
+ getFeaturePattern,
239
+ pathGenerator
240
+ ]);
241
+ const camera = useChoroplethCamera();
242
+ const handleFeatureEnter = useCallback(
243
+ (record) => {
244
+ if (!camera.isHoverable(`feature:${record.index}`)) {
245
+ return;
246
+ }
247
+ setHoveredFeatureIndex(record.index);
248
+ setTooltipData({
249
+ featureIndex: record.index,
250
+ x: record.centroid?.x ?? width / 2,
251
+ y: record.centroid?.y ?? height / 2,
252
+ feature: record.feature
253
+ });
254
+ },
255
+ [camera, height, setHoveredFeatureIndex, setTooltipData, width]
256
+ );
257
+ const handleFeatureLeave = useCallback(() => {
258
+ setHoveredFeatureIndex(null);
259
+ setTooltipData(null);
260
+ }, [setHoveredFeatureIndex, setTooltipData]);
261
+ const handleFeatureClick = useCallback(
262
+ (index) => {
263
+ if (camera.enabled && !camera.wasDrag()) {
264
+ camera.focusFeature(index);
265
+ }
266
+ },
267
+ [camera]
268
+ );
269
+ const layerProps = {
270
+ baseOpacity: 0.85,
271
+ onFeatureClick: handleFeatureClick,
272
+ dimOpacity: fadedOpacity,
273
+ hoveredIndex: hoveredFeatureIndex,
274
+ focusedIndex: camera.focusedFeatureIndex,
275
+ onFeatureEnter: handleFeatureEnter,
276
+ onFeatureLeave: handleFeatureLeave,
277
+ records,
278
+ stroke,
279
+ strokeWidth
280
+ };
281
+ return /* @__PURE__ */ jsxs("g", { className: "choropleth-features", children: [
282
+ patterns ? /* @__PURE__ */ jsx("defs", { children: patterns }) : null,
283
+ isLoaded ? /* @__PURE__ */ jsx(StaticFeatureLayer, { ...layerProps }) : /* @__PURE__ */ jsx(EnterFeatureLayer, { ...layerProps, revealEpoch })
284
+ ] });
285
+ });
286
+ ChoroplethFeature.displayName = "ChoroplethFeature";
287
+ var choropleth_feature_default = ChoroplethFeature;
288
+ export {
289
+ ChoroplethFeature,
290
+ choropleth_feature_default as default
291
+ };
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { memo, useMemo } from "react";
4
+ import { useChoroplethCamera } from "./choropleth-camera";
5
+ import { useChoroplethStable } from "./choropleth-context";
6
+ import { graticulePath } from "./choropleth-projection";
7
+ const ChoroplethGraticule = memo(function ChoroplethGraticule2({
8
+ stroke = "rgba(255,255,255,0.1)",
9
+ strokeWidth = 0.5,
10
+ step,
11
+ hideOnFocus = true
12
+ }) {
13
+ const { rawPathGenerator } = useChoroplethStable();
14
+ const { focusedKey } = useChoroplethCamera();
15
+ const hidden = hideOnFocus && focusedKey !== null;
16
+ const stepX = step?.[0];
17
+ const stepY = step?.[1];
18
+ const d = useMemo(
19
+ () => graticulePath(
20
+ rawPathGenerator,
21
+ stepX === void 0 || stepY === void 0 ? void 0 : [stepX, stepY]
22
+ ),
23
+ [rawPathGenerator, stepX, stepY]
24
+ );
25
+ return /* @__PURE__ */ jsx(
26
+ "g",
27
+ {
28
+ className: "visx-group visx-geo-graticule",
29
+ style: { opacity: hidden ? 0 : 1, transition: "opacity 0.3s ease-out" },
30
+ transform: "translate(0, 0)",
31
+ children: /* @__PURE__ */ jsx("path", { d, fill: "none", stroke, strokeWidth })
32
+ }
33
+ );
34
+ });
35
+ ChoroplethGraticule.displayName = "ChoroplethGraticule";
36
+ var choropleth_graticule_default = ChoroplethGraticule;
37
+ export {
38
+ ChoroplethGraticule,
39
+ choropleth_graticule_default as default
40
+ };
@@ -0,0 +1,222 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { memo, useCallback, useId } from "react";
4
+ import { cn } from "../../lib/utils";
5
+ import {
6
+ CHOROPLETH_CAMERA_SCALE_VAR,
7
+ useChoroplethCamera
8
+ } from "./choropleth-camera";
9
+ import {
10
+ useChoroplethInteraction,
11
+ useChoroplethStable,
12
+ useChoroplethZoom
13
+ } from "./choropleth-context";
14
+ function shapePath(shape, r) {
15
+ switch (shape) {
16
+ case "triangle":
17
+ return `M0,${-r * 1.15}L${r * 1.05},${r * 0.7}L${-r * 1.05},${r * 0.7}Z`;
18
+ case "square": {
19
+ const s = r * 0.88;
20
+ return `M${-s},${-s}H${s}V${s}H${-s}Z`;
21
+ }
22
+ case "diamond":
23
+ return `M0,${-r * 1.2}L${r * 1.2},0L0,${r * 1.2}L${-r * 1.2},0Z`;
24
+ case "pin": {
25
+ const cy = -r * 1.9;
26
+ const hx = r * 0.82;
27
+ const hy = cy + r * 0.57;
28
+ return `M0,0L${-hx},${hy}A${r},${r} 0 1,1 ${hx},${hy}Z`;
29
+ }
30
+ default:
31
+ return `M${-r},0a${r},${r} 0 1,0 ${2 * r},0a${r},${r} 0 1,0 ${-2 * r},0`;
32
+ }
33
+ }
34
+ const PULSE_CLASS = {
35
+ always: "animate-ping",
36
+ hover: "group-hover/marker:animate-ping group-focus-visible/marker:animate-ping",
37
+ none: "hidden"
38
+ };
39
+ function pulseDelay(label) {
40
+ let h = 0;
41
+ for (let i = 0; i < label.length; i++) {
42
+ h = (h * 31 + label.charCodeAt(i)) % 997;
43
+ }
44
+ return `${-(h % 10) * 110}ms`;
45
+ }
46
+ const ChoroplethMarker = memo(function ChoroplethMarker2({
47
+ coordinates,
48
+ label,
49
+ shape = "circle",
50
+ size = 9,
51
+ color = "var(--chart-foreground)",
52
+ stroke,
53
+ strokeWidth = 1.5,
54
+ pulse = "hover",
55
+ glow = 0,
56
+ showLabel = false,
57
+ className
58
+ }) {
59
+ const { projectPoint } = useChoroplethStable();
60
+ const { setMarkerTooltip, setHoveredFeatureIndex, setTooltipData } = useChoroplethInteraction();
61
+ const { zoom } = useChoroplethZoom();
62
+ const camera = useChoroplethCamera();
63
+ const glowId = `choropleth-marker-glow-${useId().replace(/:/g, "")}`;
64
+ const [lon, lat] = coordinates;
65
+ const point = projectPoint([lon, lat]);
66
+ const hoverable = camera.isHoverable(`point:${label}`);
67
+ const show = useCallback(() => {
68
+ if (!hoverable) {
69
+ return;
70
+ }
71
+ setHoveredFeatureIndex(null);
72
+ setTooltipData(null);
73
+ setMarkerTooltip?.({ label, coordinates: [lon, lat] });
74
+ }, [
75
+ hoverable,
76
+ label,
77
+ lat,
78
+ lon,
79
+ setHoveredFeatureIndex,
80
+ setMarkerTooltip,
81
+ setTooltipData
82
+ ]);
83
+ const hide = useCallback(() => setMarkerTooltip?.(null), [setMarkerTooltip]);
84
+ const focus = useCallback(() => {
85
+ if (camera.enabled) {
86
+ camera.focusPoint([lon, lat], label);
87
+ }
88
+ }, [camera, label, lat, lon]);
89
+ if (!point) {
90
+ return null;
91
+ }
92
+ const r = size / 2;
93
+ const d = shapePath(shape, r);
94
+ const isPin = shape === "pin";
95
+ const headY = isPin ? -r * 1.9 : 0;
96
+ const zoomScale = zoom?.transformMatrix.scaleX ?? 1;
97
+ const interactive = camera.enabled;
98
+ const pulseClass = pulse === "hover" && !hoverable ? "hidden" : PULSE_CLASS[pulse];
99
+ const hoverScale = hoverable ? "group-hover/marker:scale-115" : "";
100
+ return /* @__PURE__ */ jsx("g", { transform: `translate(${point[0]} ${point[1]})`, children: /* @__PURE__ */ jsxs(
101
+ "g",
102
+ {
103
+ "aria-label": interactive ? `Zoom to ${label}` : void 0,
104
+ className: cn(
105
+ "group/marker outline-none",
106
+ interactive && "cursor-pointer",
107
+ className
108
+ ),
109
+ onBlur: hide,
110
+ onClick: (event) => {
111
+ event.stopPropagation();
112
+ if (!camera.wasDrag()) {
113
+ focus();
114
+ }
115
+ },
116
+ onFocus: show,
117
+ onKeyDown: (event) => {
118
+ if (event.key === "Enter" || event.key === " ") {
119
+ event.preventDefault();
120
+ focus();
121
+ }
122
+ },
123
+ onMouseEnter: show,
124
+ onMouseLeave: hide,
125
+ role: interactive ? "button" : void 0,
126
+ style: {
127
+ // Constant on-screen size while the camera and drag-zoom scale the map.
128
+ transform: `scale(calc(1 / (var(${CHOROPLETH_CAMERA_SCALE_VAR}, 1) * ${zoomScale})))`
129
+ },
130
+ tabIndex: interactive ? 0 : void 0,
131
+ children: [
132
+ /* @__PURE__ */ jsx("circle", { cy: headY * 0.6, fill: "transparent", r: Math.max(r * 2, 22) }),
133
+ /* @__PURE__ */ jsx(
134
+ "circle",
135
+ {
136
+ className: cn(
137
+ "pointer-events-none origin-center [transform-box:fill-box] motion-reduce:animate-none",
138
+ pulseClass
139
+ ),
140
+ cy: headY,
141
+ fill: "none",
142
+ r,
143
+ stroke: color,
144
+ strokeWidth: 1.5,
145
+ style: pulse === "always" ? { animationDelay: pulseDelay(label) } : void 0
146
+ }
147
+ ),
148
+ glow > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
149
+ /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx(
150
+ "filter",
151
+ {
152
+ height: "500%",
153
+ id: glowId,
154
+ width: "500%",
155
+ x: "-200%",
156
+ y: "-200%",
157
+ children: /* @__PURE__ */ jsx("feGaussianBlur", { stdDeviation: glow })
158
+ }
159
+ ) }),
160
+ /* @__PURE__ */ jsx(
161
+ "path",
162
+ {
163
+ className: cn(
164
+ hoverable && "group-hover/marker:scale-115 group-hover/marker:opacity-100",
165
+ "pointer-events-none opacity-55 transition-[opacity,scale] duration-150 ease-out [transform-box:fill-box] group-focus-visible/marker:opacity-100 group-focus-visible/marker:opacity-100 motion-reduce:transition-none",
166
+ isPin ? "origin-bottom" : "origin-center"
167
+ ),
168
+ d,
169
+ fill: color,
170
+ filter: `url(#${glowId})`
171
+ }
172
+ )
173
+ ] }) : null,
174
+ /* @__PURE__ */ jsx(
175
+ "path",
176
+ {
177
+ className: cn(
178
+ hoverScale,
179
+ "transition-[scale] duration-150 ease-out [transform-box:fill-box] group-focus-visible/marker:stroke-chart-foreground motion-reduce:transition-none",
180
+ isPin ? "origin-bottom" : "origin-center"
181
+ ),
182
+ d,
183
+ fill: color,
184
+ paintOrder: "stroke",
185
+ stroke: stroke ?? "none",
186
+ strokeWidth: stroke ? strokeWidth : 2
187
+ }
188
+ ),
189
+ isPin ? /* @__PURE__ */ jsx(
190
+ "circle",
191
+ {
192
+ className: "pointer-events-none",
193
+ cy: headY,
194
+ fill: "var(--chart-background)",
195
+ r: r * 0.38
196
+ }
197
+ ) : null,
198
+ showLabel ? /* @__PURE__ */ jsx(
199
+ "text",
200
+ {
201
+ className: "pointer-events-none select-none font-medium text-[11px]",
202
+ dy: "0.35em",
203
+ fill: "var(--chart-foreground)",
204
+ paintOrder: "stroke",
205
+ stroke: "var(--chart-background)",
206
+ strokeLinejoin: "round",
207
+ strokeWidth: 3,
208
+ x: r + 6,
209
+ y: headY,
210
+ children: label
211
+ }
212
+ ) : null
213
+ ]
214
+ }
215
+ ) });
216
+ });
217
+ ChoroplethMarker.displayName = "ChoroplethMarker";
218
+ var choropleth_marker_default = ChoroplethMarker;
219
+ export {
220
+ ChoroplethMarker,
221
+ choropleth_marker_default as default
222
+ };
@@ -0,0 +1,37 @@
1
+ import {
2
+ geoGraticule,
3
+ geoMercator,
4
+ geoPath
5
+ } from "d3-geo";
6
+ function createChoroplethMercator({
7
+ scale,
8
+ translate,
9
+ center
10
+ }) {
11
+ const projection = geoMercator();
12
+ if (scale) {
13
+ projection.scale(scale);
14
+ }
15
+ if (translate) {
16
+ projection.translate(translate);
17
+ }
18
+ if (center) {
19
+ projection.center(center);
20
+ }
21
+ return { path: geoPath(projection), projection };
22
+ }
23
+ function projectFeaturePaths(mercator, features) {
24
+ return features.map((feature) => mercator.path(feature) ?? null);
25
+ }
26
+ function graticulePath(path, step) {
27
+ const graticule = geoGraticule();
28
+ if (step) {
29
+ graticule.step(step);
30
+ }
31
+ return path(graticule()) || "";
32
+ }
33
+ export {
34
+ createChoroplethMercator,
35
+ graticulePath,
36
+ projectFeaturePaths
37
+ };
@@ -0,0 +1,82 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { intFmt } from "../chart-formatters";
4
+ import { CursorTooltipBox } from "../tooltip/cursor-tooltip-box";
5
+ import { TooltipContent } from "../tooltip/tooltip-content";
6
+ import {
7
+ TOOLTIP_HIDE_DELAY_MS,
8
+ useDelayedTooltipData
9
+ } from "../tooltip/use-delayed-tooltip-data";
10
+ import {
11
+ useChoroplethInteraction,
12
+ useChoroplethStable
13
+ } from "./choropleth-context";
14
+ function ChoroplethTooltip({
15
+ content,
16
+ formatValue = intFmt,
17
+ getFeatureName,
18
+ getFeatureValue,
19
+ valueLabel = "Valor",
20
+ className = "",
21
+ panelStyle,
22
+ backgroundColor,
23
+ exit = true,
24
+ hideDelay = TOOLTIP_HIDE_DELAY_MS
25
+ }) {
26
+ const { containerRef, features } = useChoroplethStable();
27
+ const { tooltipData: hoverData, markerTooltip: hoverMarker } = useChoroplethInteraction();
28
+ const tooltipData = useDelayedTooltipData(hoverData, 0, hideDelay);
29
+ const marker = useDelayedTooltipData(hoverMarker ?? null, 0, hideDelay);
30
+ const feature = tooltipData ? features[tooltipData.featureIndex] : void 0;
31
+ let body = null;
32
+ if (marker) {
33
+ const [lon, lat] = marker.coordinates;
34
+ body = /* @__PURE__ */ jsx(
35
+ TooltipContent,
36
+ {
37
+ rows: [
38
+ {
39
+ color: "var(--chart-foreground-muted)",
40
+ label: "Location",
41
+ value: `${lat.toFixed(2)}\xB0, ${lon.toFixed(2)}\xB0`
42
+ }
43
+ ],
44
+ title: marker.label
45
+ }
46
+ );
47
+ } else if (tooltipData && feature) {
48
+ const index = tooltipData.featureIndex;
49
+ if (content) {
50
+ body = content({ feature, index });
51
+ } else {
52
+ const featureName = getFeatureName ? getFeatureName(feature, index) : feature.properties?.name ?? `Feature ${index}`;
53
+ const value = getFeatureValue?.(feature, index);
54
+ const rows = value === void 0 ? [] : [
55
+ {
56
+ color: "var(--chart-1)",
57
+ label: valueLabel,
58
+ value: formatValue(value)
59
+ }
60
+ ];
61
+ body = /* @__PURE__ */ jsx(TooltipContent, { rows, title: featureName });
62
+ }
63
+ }
64
+ return /* @__PURE__ */ jsx(
65
+ CursorTooltipBox,
66
+ {
67
+ backgroundColor,
68
+ className,
69
+ containerRef,
70
+ exit,
71
+ panelStyle,
72
+ visible: Boolean(marker || tooltipData && feature),
73
+ children: body
74
+ }
75
+ );
76
+ }
77
+ ChoroplethTooltip.displayName = "ChoroplethTooltip";
78
+ var choropleth_tooltip_default = ChoroplethTooltip;
79
+ export {
80
+ ChoroplethTooltip,
81
+ choropleth_tooltip_default as default
82
+ };