@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.
- package/ALTERACOES.md +57 -0
- package/LICENSE-BKLIT +21 -0
- package/LICENSE-visx-pattern +21 -0
- package/README.md +189 -2
- package/dist/aic/cores.js +83 -0
- package/dist/aic/index.js +22 -0
- package/dist/aic/interacao.js +55 -0
- package/dist/charts/animation.js +55 -0
- package/dist/charts/arc-geometry.js +58 -0
- package/dist/charts/arc-path.js +15 -0
- package/dist/charts/area-chart-loading.js +89 -0
- package/dist/charts/area-chart.js +149 -0
- package/dist/charts/area-gradient-defs.js +90 -0
- package/dist/charts/area-value-label-layout.js +70 -0
- package/dist/charts/area-value-labels.js +211 -0
- package/dist/charts/area.js +272 -0
- package/dist/charts/background.js +198 -0
- package/dist/charts/band-config.js +82 -0
- package/dist/charts/band-geometry.js +186 -0
- package/dist/charts/band.js +346 -0
- package/dist/charts/bar-chart-loading.js +27 -0
- package/dist/charts/bar-chart.js +545 -0
- package/dist/charts/bar-depth-geometry.js +18 -0
- package/dist/charts/bar-depth.js +608 -0
- package/dist/charts/bar-lollipop.js +278 -0
- package/dist/charts/bar-squares-layout.js +66 -0
- package/dist/charts/bar-squares.js +467 -0
- package/dist/charts/bar-value-label-layout.js +42 -0
- package/dist/charts/bar-x-axis.js +133 -0
- package/dist/charts/bar-y-axis.js +116 -0
- package/dist/charts/bar.js +457 -0
- package/dist/charts/bollinger.js +49 -0
- package/dist/charts/candlestick-chart.js +370 -0
- package/dist/charts/candlestick.js +368 -0
- package/dist/charts/chart-brush-handle.js +91 -0
- package/dist/charts/chart-brush-layout.js +91 -0
- package/dist/charts/chart-brush-selection-overlay.js +87 -0
- package/dist/charts/chart-brush-state.js +253 -0
- package/dist/charts/chart-brush-track-overlay.js +103 -0
- package/dist/charts/chart-brush.js +517 -0
- package/dist/charts/chart-center-typography.js +8 -0
- package/dist/charts/chart-child-passthrough.js +119 -0
- package/dist/charts/chart-config-context.js +56 -0
- package/dist/charts/chart-context.js +337 -0
- package/dist/charts/chart-crosshair.js +262 -0
- package/dist/charts/chart-data-override.js +186 -0
- package/dist/charts/chart-defs.js +56 -0
- package/dist/charts/chart-formatters.js +77 -0
- package/dist/charts/chart-legend-hover.js +27 -0
- package/dist/charts/chart-legend.js +163 -0
- package/dist/charts/chart-loading-label.js +52 -0
- package/dist/charts/chart-parent-size.js +138 -0
- package/dist/charts/chart-phase.js +29 -0
- package/dist/charts/chart-reveal-clip.js +62 -0
- package/dist/charts/chart-scale.js +19 -0
- package/dist/charts/chart-stat-flow.js +72 -0
- package/dist/charts/choropleth/choropleth-background.js +29 -0
- package/dist/charts/choropleth/choropleth-camera.js +379 -0
- package/dist/charts/choropleth/choropleth-chart.js +644 -0
- package/dist/charts/choropleth/choropleth-context.js +152 -0
- package/dist/charts/choropleth/choropleth-dot-grid.js +293 -0
- package/dist/charts/choropleth/choropleth-feature.js +291 -0
- package/dist/charts/choropleth/choropleth-graticule.js +40 -0
- package/dist/charts/choropleth/choropleth-marker.js +222 -0
- package/dist/charts/choropleth/choropleth-projection.js +37 -0
- package/dist/charts/choropleth/choropleth-tooltip.js +82 -0
- package/dist/charts/choropleth/choropleth-zoom-matrix.js +150 -0
- package/dist/charts/choropleth/index.js +44 -0
- package/dist/charts/choropleth/use-choropleth-zoom-state.js +636 -0
- package/dist/charts/composed-chart.js +346 -0
- package/dist/charts/crosshair-store.js +49 -0
- package/dist/charts/dash-tail-stroke.js +58 -0
- package/dist/charts/date-pill-store.js +50 -0
- package/dist/charts/date-ranges.js +131 -0
- package/dist/charts/deadline.js +295 -0
- package/dist/charts/decimate-time-series.js +112 -0
- package/dist/charts/fade-edges.js +171 -0
- package/dist/charts/fast-path.js +78 -0
- package/dist/charts/filter-data-by-x-domain.js +45 -0
- package/dist/charts/funnel-chart.js +773 -0
- package/dist/charts/gauge-arc-layers.js +479 -0
- package/dist/charts/gauge-dial.js +329 -0
- package/dist/charts/gauge-label-layout.js +148 -0
- package/dist/charts/gauge.js +946 -0
- package/dist/charts/generate-chart-skeleton-data.js +27 -0
- package/dist/charts/gradients.js +158 -0
- package/dist/charts/grid-lines.js +114 -0
- package/dist/charts/grid.js +225 -0
- package/dist/charts/heatmap/generate-heatmap-skeleton-data.js +13 -0
- package/dist/charts/heatmap/heatmap-animation.js +128 -0
- package/dist/charts/heatmap/heatmap-cells.js +519 -0
- package/dist/charts/heatmap/heatmap-chart-loading.js +44 -0
- package/dist/charts/heatmap/heatmap-chart.js +548 -0
- package/dist/charts/heatmap/heatmap-colors.js +127 -0
- package/dist/charts/heatmap/heatmap-context.js +107 -0
- package/dist/charts/heatmap/heatmap-legend-gradient.js +97 -0
- package/dist/charts/heatmap/heatmap-legend-swatch.js +76 -0
- package/dist/charts/heatmap/heatmap-legend.js +165 -0
- package/dist/charts/heatmap/heatmap-pattern-defs.js +37 -0
- package/dist/charts/heatmap/heatmap-rect-cells.js +39 -0
- package/dist/charts/heatmap/heatmap-resolve-separator.js +84 -0
- package/dist/charts/heatmap/heatmap-separator.js +168 -0
- package/dist/charts/heatmap/heatmap-tooltip.js +73 -0
- package/dist/charts/heatmap/heatmap-utils.js +633 -0
- package/dist/charts/heatmap/heatmap-x-axis.js +79 -0
- package/dist/charts/heatmap/heatmap-y-axis.js +72 -0
- package/dist/charts/heatmap/index.js +208 -0
- package/dist/charts/highlight-segment-bounds.js +34 -0
- package/dist/charts/highlight-segment.js +119 -0
- package/dist/charts/index.js +944 -0
- package/dist/charts/indicator-fade.js +44 -0
- package/dist/charts/legend/index.js +22 -0
- package/dist/charts/legend/legend-context.js +47 -0
- package/dist/charts/legend/legend-item.js +30 -0
- package/dist/charts/legend/legend-label.js +14 -0
- package/dist/charts/legend/legend-marker.js +18 -0
- package/dist/charts/legend/legend-progress.js +39 -0
- package/dist/charts/legend/legend-value.js +31 -0
- package/dist/charts/legend/legend.js +69 -0
- package/dist/charts/line-backdrop.js +129 -0
- package/dist/charts/line-chart-loading.js +85 -0
- package/dist/charts/line-chart.js +182 -0
- package/dist/charts/line-loading-pulse.js +185 -0
- package/dist/charts/line-loading-timing.js +12 -0
- package/dist/charts/line-path.js +58 -0
- package/dist/charts/line-series-terminal-marker.js +75 -0
- package/dist/charts/line.js +499 -0
- package/dist/charts/live-line-chart.js +494 -0
- package/dist/charts/live-line.js +277 -0
- package/dist/charts/live-x-axis.js +116 -0
- package/dist/charts/live-y-axis.js +164 -0
- package/dist/charts/loading-sweep.js +344 -0
- package/dist/charts/local-point.js +56 -0
- package/dist/charts/markers/chart-markers.js +149 -0
- package/dist/charts/markers/index.js +14 -0
- package/dist/charts/markers/marker-group.js +411 -0
- package/dist/charts/motion-utils.js +29 -0
- package/dist/charts/notch-gauge-shared.js +146 -0
- package/dist/charts/particle-line.js +1340 -0
- package/dist/charts/path-stroke-utils.js +51 -0
- package/dist/charts/pattern-area.js +127 -0
- package/dist/charts/pattern-preset.js +287 -0
- package/dist/charts/pattern-tile.js +31 -0
- package/dist/charts/patterns/circles.js +62 -0
- package/dist/charts/patterns/constants.js +9 -0
- package/dist/charts/patterns/hexagons.js +38 -0
- package/dist/charts/patterns/index.js +16 -0
- package/dist/charts/patterns/lines.js +65 -0
- package/dist/charts/patterns/path.js +37 -0
- package/dist/charts/patterns/pattern.js +16 -0
- package/dist/charts/patterns/waves.js +40 -0
- package/dist/charts/pie-center-shell.js +127 -0
- package/dist/charts/pie-center.js +87 -0
- package/dist/charts/pie-chart.js +377 -0
- package/dist/charts/pie-context.js +116 -0
- package/dist/charts/pie-slice.js +394 -0
- package/dist/charts/pie-ticks.js +332 -0
- package/dist/charts/profit-loss-legend-hover.js +18 -0
- package/dist/charts/profit-loss-legend.js +53 -0
- package/dist/charts/profit-loss-line.js +162 -0
- package/dist/charts/profit-loss-segments.js +88 -0
- package/dist/charts/projection-config.js +90 -0
- package/dist/charts/projection-line-end-marker.js +50 -0
- package/dist/charts/projection-line.js +466 -0
- package/dist/charts/projection-utils.js +303 -0
- package/dist/charts/radar-area.js +192 -0
- package/dist/charts/radar-axis.js +41 -0
- package/dist/charts/radar-chart.js +184 -0
- package/dist/charts/radar-context.js +104 -0
- package/dist/charts/radar-grid.js +121 -0
- package/dist/charts/radar-labels.js +62 -0
- package/dist/charts/radial-area.js +498 -0
- package/dist/charts/radial-axis.js +652 -0
- package/dist/charts/radial-bar.js +316 -0
- package/dist/charts/radial-center.js +67 -0
- package/dist/charts/radial-chart.js +740 -0
- package/dist/charts/radial-dot-bar-layout.js +68 -0
- package/dist/charts/radial-dot-bar.js +387 -0
- package/dist/charts/radial-geometry.js +114 -0
- package/dist/charts/radial-legend.js +66 -0
- package/dist/charts/radial-line.js +280 -0
- package/dist/charts/radial-ring-bar.js +255 -0
- package/dist/charts/radial-scrubber.js +120 -0
- package/dist/charts/radial-series-color.js +10 -0
- package/dist/charts/reference-area-config.js +43 -0
- package/dist/charts/reference-area-geometry.js +76 -0
- package/dist/charts/reference-area-registration-context.js +10 -0
- package/dist/charts/reference-area.js +241 -0
- package/dist/charts/responsive-chart-label-count.js +18 -0
- package/dist/charts/ring-center.js +78 -0
- package/dist/charts/ring-chart.js +362 -0
- package/dist/charts/ring-context.js +122 -0
- package/dist/charts/ring-grid.js +175 -0
- package/dist/charts/ring-labels.js +109 -0
- package/dist/charts/ring.js +237 -0
- package/dist/charts/sankey/index.js +22 -0
- package/dist/charts/sankey/sankey-chart.js +199 -0
- package/dist/charts/sankey/sankey-context.js +32 -0
- package/dist/charts/sankey/sankey-link.js +232 -0
- package/dist/charts/sankey/sankey-node.js +348 -0
- package/dist/charts/sankey/sankey-tooltip.js +94 -0
- package/dist/charts/scatter-chart-shell.js +279 -0
- package/dist/charts/scatter-chart.js +150 -0
- package/dist/charts/scatter-jitter.js +86 -0
- package/dist/charts/scatter-svg.js +17 -0
- package/dist/charts/scatter.js +92 -0
- package/dist/charts/segment.js +107 -0
- package/dist/charts/series-bar-layout.js +42 -0
- package/dist/charts/series-bar.js +241 -0
- package/dist/charts/series-dash-tail-overlay.js +53 -0
- package/dist/charts/series-highlight-layer.js +43 -0
- package/dist/charts/series-hover-dim.js +32 -0
- package/dist/charts/series-markers.js +239 -0
- package/dist/charts/series-path-utils.js +185 -0
- package/dist/charts/series-point-marker.js +150 -0
- package/dist/charts/sparkline-geometry.js +197 -0
- package/dist/charts/sparkline.js +910 -0
- package/dist/charts/static-chart-preview-context.js +16 -0
- package/dist/charts/sunburst-breadcrumb.js +33 -0
- package/dist/charts/sunburst-center.js +37 -0
- package/dist/charts/sunburst-chart.js +408 -0
- package/dist/charts/sunburst-context.js +140 -0
- package/dist/charts/sunburst-data.js +0 -0
- package/dist/charts/sunburst-hint.js +42 -0
- package/dist/charts/sunburst-labels.js +130 -0
- package/dist/charts/sunburst-segment.js +144 -0
- package/dist/charts/sunburst.js +419 -0
- package/dist/charts/time-series-chart-shell.js +688 -0
- package/dist/charts/tooltip/chart-tooltip.js +516 -0
- package/dist/charts/tooltip/cursor-tooltip-box.js +183 -0
- package/dist/charts/tooltip/date-ticker.js +376 -0
- package/dist/charts/tooltip/index.js +32 -0
- package/dist/charts/tooltip/liquid-glass.js +142 -0
- package/dist/charts/tooltip/tooltip-box.js +502 -0
- package/dist/charts/tooltip/tooltip-content.js +59 -0
- package/dist/charts/tooltip/tooltip-dot.js +170 -0
- package/dist/charts/tooltip/tooltip-indicator.js +175 -0
- package/dist/charts/tooltip/use-delayed-tooltip-data.js +41 -0
- package/dist/charts/tooltip/use-velocity-stretch.js +52 -0
- package/dist/charts/trend-line-utils.js +64 -0
- package/dist/charts/trend-line.js +318 -0
- package/dist/charts/use-animated-band.js +175 -0
- package/dist/charts/use-animated-series-path.js +208 -0
- package/dist/charts/use-animated-y-domains.js +192 -0
- package/dist/charts/use-category-slots.js +29 -0
- package/dist/charts/use-chart-interaction.js +296 -0
- package/dist/charts/use-chart-phase-orchestrator.js +183 -0
- package/dist/charts/use-enter-complete.js +18 -0
- package/dist/charts/use-grid-shimmer.js +88 -0
- package/dist/charts/use-highlight-segment.js +65 -0
- package/dist/charts/use-mount-progress.js +23 -0
- package/dist/charts/use-scatter-chart-interaction.js +364 -0
- package/dist/charts/use-scheduled-tooltip.js +84 -0
- package/dist/charts/visx-pattern.js +30 -0
- package/dist/charts/weekends.js +174 -0
- package/dist/charts/x-axis-hover.js +46 -0
- package/dist/charts/x-axis.js +523 -0
- package/dist/charts/y-axis-scales.js +71 -0
- package/dist/charts/y-axis-ticks.js +22 -0
- package/dist/charts/y-axis.js +233 -0
- package/dist/charts/y-domain-utils.js +189 -0
- package/dist/index.d.ts +7346 -0
- package/dist/index.js +2 -0
- package/dist/lib/utils.js +8 -0
- package/dist/shimmering-text.js +54 -0
- package/package.json +78 -4
- package/tema.css +202 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useContext,
|
|
6
|
+
useMemo,
|
|
7
|
+
useState
|
|
8
|
+
} from "react";
|
|
9
|
+
const ChoroplethZoomContext = createContext({
|
|
10
|
+
zoom: null
|
|
11
|
+
});
|
|
12
|
+
function useChoroplethZoom() {
|
|
13
|
+
return useContext(ChoroplethZoomContext);
|
|
14
|
+
}
|
|
15
|
+
const ChoroplethStableContext = createContext(null);
|
|
16
|
+
const ChoroplethInteractionContext = createContext(null);
|
|
17
|
+
function ChoroplethStableProvider({
|
|
18
|
+
children,
|
|
19
|
+
value
|
|
20
|
+
}) {
|
|
21
|
+
return /* @__PURE__ */ jsx(ChoroplethStableContext.Provider, { value, children });
|
|
22
|
+
}
|
|
23
|
+
function ChoroplethInteractionShell({
|
|
24
|
+
children
|
|
25
|
+
}) {
|
|
26
|
+
const [hoveredFeatureIndex, setHoveredFeatureIndex] = useState(
|
|
27
|
+
null
|
|
28
|
+
);
|
|
29
|
+
const [tooltipData, setTooltipData] = useState(
|
|
30
|
+
null
|
|
31
|
+
);
|
|
32
|
+
const [markerTooltip, setMarkerTooltip] = useState(null);
|
|
33
|
+
const interaction = useMemo(
|
|
34
|
+
() => ({
|
|
35
|
+
hoveredFeatureIndex,
|
|
36
|
+
setHoveredFeatureIndex,
|
|
37
|
+
tooltipData,
|
|
38
|
+
setTooltipData,
|
|
39
|
+
markerTooltip,
|
|
40
|
+
setMarkerTooltip
|
|
41
|
+
}),
|
|
42
|
+
[hoveredFeatureIndex, tooltipData, markerTooltip]
|
|
43
|
+
);
|
|
44
|
+
return /* @__PURE__ */ jsx(ChoroplethInteractionContext.Provider, { value: interaction, children });
|
|
45
|
+
}
|
|
46
|
+
function ChoroplethProvider({
|
|
47
|
+
children,
|
|
48
|
+
value
|
|
49
|
+
}) {
|
|
50
|
+
const stable = useMemo(
|
|
51
|
+
() => ({
|
|
52
|
+
features: value.features,
|
|
53
|
+
featureCollection: value.featureCollection,
|
|
54
|
+
featurePaths: value.featurePaths,
|
|
55
|
+
pathGenerator: value.pathGenerator,
|
|
56
|
+
rawPathGenerator: value.rawPathGenerator,
|
|
57
|
+
projectPoint: value.projectPoint,
|
|
58
|
+
width: value.width,
|
|
59
|
+
height: value.height,
|
|
60
|
+
innerWidth: value.innerWidth,
|
|
61
|
+
innerHeight: value.innerHeight,
|
|
62
|
+
margin: value.margin,
|
|
63
|
+
containerRef: value.containerRef,
|
|
64
|
+
isLoaded: value.isLoaded,
|
|
65
|
+
animationDuration: value.animationDuration,
|
|
66
|
+
enterTransition: value.enterTransition,
|
|
67
|
+
revealEpoch: value.revealEpoch
|
|
68
|
+
}),
|
|
69
|
+
[
|
|
70
|
+
value.features,
|
|
71
|
+
value.featureCollection,
|
|
72
|
+
value.featurePaths,
|
|
73
|
+
value.pathGenerator,
|
|
74
|
+
value.rawPathGenerator,
|
|
75
|
+
value.projectPoint,
|
|
76
|
+
value.width,
|
|
77
|
+
value.height,
|
|
78
|
+
value.innerWidth,
|
|
79
|
+
value.innerHeight,
|
|
80
|
+
value.margin,
|
|
81
|
+
value.containerRef,
|
|
82
|
+
value.isLoaded,
|
|
83
|
+
value.animationDuration,
|
|
84
|
+
value.enterTransition,
|
|
85
|
+
value.revealEpoch
|
|
86
|
+
]
|
|
87
|
+
);
|
|
88
|
+
const interaction = useMemo(
|
|
89
|
+
() => ({
|
|
90
|
+
hoveredFeatureIndex: value.hoveredFeatureIndex,
|
|
91
|
+
setHoveredFeatureIndex: value.setHoveredFeatureIndex,
|
|
92
|
+
tooltipData: value.tooltipData,
|
|
93
|
+
setTooltipData: value.setTooltipData,
|
|
94
|
+
markerTooltip: value.markerTooltip,
|
|
95
|
+
setMarkerTooltip: value.setMarkerTooltip
|
|
96
|
+
}),
|
|
97
|
+
[
|
|
98
|
+
value.markerTooltip,
|
|
99
|
+
value.setMarkerTooltip,
|
|
100
|
+
value.hoveredFeatureIndex,
|
|
101
|
+
value.setHoveredFeatureIndex,
|
|
102
|
+
value.tooltipData,
|
|
103
|
+
value.setTooltipData
|
|
104
|
+
]
|
|
105
|
+
);
|
|
106
|
+
return /* @__PURE__ */ jsx(ChoroplethStableProvider, { value: stable, children: /* @__PURE__ */ jsx(ChoroplethInteractionContext.Provider, { value: interaction, children }) });
|
|
107
|
+
}
|
|
108
|
+
function useChoroplethStable() {
|
|
109
|
+
const context = useContext(ChoroplethStableContext);
|
|
110
|
+
if (!context) {
|
|
111
|
+
throw new Error(
|
|
112
|
+
"useChoroplethStable must be used within a ChoroplethProvider"
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
return context;
|
|
116
|
+
}
|
|
117
|
+
function useChoroplethInteraction() {
|
|
118
|
+
const context = useContext(ChoroplethInteractionContext);
|
|
119
|
+
if (!context) {
|
|
120
|
+
throw new Error(
|
|
121
|
+
"useChoroplethInteraction must be used within a ChoroplethProvider"
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
return context;
|
|
125
|
+
}
|
|
126
|
+
function useChoropleth() {
|
|
127
|
+
return { ...useChoroplethStable(), ...useChoroplethInteraction() };
|
|
128
|
+
}
|
|
129
|
+
import { CHART_SCALE_VARS, chartScaleCssVars } from "../chart-scale";
|
|
130
|
+
const choroplethCssVars = {
|
|
131
|
+
scale01: chartScaleCssVars.scale01,
|
|
132
|
+
scale02: chartScaleCssVars.scale02,
|
|
133
|
+
scale03: chartScaleCssVars.scale03,
|
|
134
|
+
scale04: chartScaleCssVars.scale04,
|
|
135
|
+
scale05: chartScaleCssVars.scale05,
|
|
136
|
+
patternColor: chartScaleCssVars.patternColor,
|
|
137
|
+
stroke: "var(--chart-grid)",
|
|
138
|
+
background: "var(--chart-background)"
|
|
139
|
+
};
|
|
140
|
+
const defaultChoroplethColors = [...CHART_SCALE_VARS];
|
|
141
|
+
export {
|
|
142
|
+
ChoroplethInteractionShell,
|
|
143
|
+
ChoroplethProvider,
|
|
144
|
+
ChoroplethStableProvider,
|
|
145
|
+
ChoroplethZoomContext,
|
|
146
|
+
choroplethCssVars,
|
|
147
|
+
defaultChoroplethColors,
|
|
148
|
+
useChoropleth,
|
|
149
|
+
useChoroplethInteraction,
|
|
150
|
+
useChoroplethStable,
|
|
151
|
+
useChoroplethZoom
|
|
152
|
+
};
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { m } from "motion/react";
|
|
4
|
+
import { memo, useCallback, useId, useMemo } from "react";
|
|
5
|
+
import { useMountProgress } from "../use-mount-progress";
|
|
6
|
+
import {
|
|
7
|
+
CHOROPLETH_CAMERA_SCALE_VAR,
|
|
8
|
+
useChoroplethCamera
|
|
9
|
+
} from "./choropleth-camera";
|
|
10
|
+
import {
|
|
11
|
+
defaultChoroplethColors,
|
|
12
|
+
useChoroplethInteraction,
|
|
13
|
+
useChoroplethStable
|
|
14
|
+
} from "./choropleth-context";
|
|
15
|
+
function buildChoroplethLattice(featurePaths, width, height, gap, lattice) {
|
|
16
|
+
if (typeof document === "undefined" || width < 1 || height < 1 || gap < 1) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
const canvas = document.createElement("canvas");
|
|
20
|
+
canvas.width = Math.ceil(width);
|
|
21
|
+
canvas.height = Math.ceil(height);
|
|
22
|
+
const ctx = canvas.getContext("2d", { willReadFrequently: true });
|
|
23
|
+
if (!ctx) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
featurePaths.forEach((d, index) => {
|
|
27
|
+
if (!d) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const id = index + 1;
|
|
31
|
+
ctx.fillStyle = `rgb(${id % 256},${Math.floor(id / 256) % 256},${Math.floor(id / 65536)})`;
|
|
32
|
+
ctx.fill(new Path2D(d));
|
|
33
|
+
});
|
|
34
|
+
const pixels = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
|
|
35
|
+
const rowStep = lattice === "hex" ? gap * 0.866 : gap;
|
|
36
|
+
const dots = [];
|
|
37
|
+
let row = 0;
|
|
38
|
+
for (let y = gap / 2; y < height; y += rowStep, row++) {
|
|
39
|
+
const offset = lattice === "hex" && row % 2 === 1 ? gap / 2 : 0;
|
|
40
|
+
for (let x = gap / 2 + offset; x < width; x += gap) {
|
|
41
|
+
const id = regionIdAt(pixels, canvas.width, x, y);
|
|
42
|
+
dots.push({
|
|
43
|
+
x,
|
|
44
|
+
y,
|
|
45
|
+
feature: id > 0 && id <= featurePaths.length ? id - 1 : -1
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return dots;
|
|
50
|
+
}
|
|
51
|
+
function regionIdAt(pixels, canvasWidth, x, y) {
|
|
52
|
+
const p = (Math.floor(y) * canvasWidth + Math.floor(x)) * 4;
|
|
53
|
+
if ((pixels[p + 3] ?? 0) === 0) {
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
return (pixels[p] ?? 0) + (pixels[p + 1] ?? 0) * 256 + (pixels[p + 2] ?? 0) * 65536;
|
|
57
|
+
}
|
|
58
|
+
function dot(x, y) {
|
|
59
|
+
return `M${x} ${y}h0`;
|
|
60
|
+
}
|
|
61
|
+
function fadeStops(lengthPercent) {
|
|
62
|
+
const edge = Math.min(45, Math.max(0, lengthPercent));
|
|
63
|
+
return [
|
|
64
|
+
{ offset: "0%", opacity: 0 },
|
|
65
|
+
{ offset: `${edge}%`, opacity: 1 },
|
|
66
|
+
{ offset: `${100 - edge}%`, opacity: 1 },
|
|
67
|
+
{ offset: "100%", opacity: 0 }
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
const ChoroplethDotGrid = memo(function ChoroplethDotGrid2({
|
|
71
|
+
gap = 7,
|
|
72
|
+
dotSize = 0.7,
|
|
73
|
+
zoomDotSize = 0.9,
|
|
74
|
+
hideOceanOnFocus = true,
|
|
75
|
+
lattice = "hex",
|
|
76
|
+
showOcean = true,
|
|
77
|
+
oceanColor = "var(--chart-scale-01)",
|
|
78
|
+
oceanOpacity = 0.55,
|
|
79
|
+
oceanDotScale = 0.55,
|
|
80
|
+
edgeFade = 12,
|
|
81
|
+
fill,
|
|
82
|
+
getFeatureColor,
|
|
83
|
+
fadedOpacity = 0.4
|
|
84
|
+
}) {
|
|
85
|
+
const {
|
|
86
|
+
features,
|
|
87
|
+
featurePaths,
|
|
88
|
+
width,
|
|
89
|
+
height,
|
|
90
|
+
enterTransition,
|
|
91
|
+
revealEpoch
|
|
92
|
+
} = useChoroplethStable();
|
|
93
|
+
const { hoveredFeatureIndex, setHoveredFeatureIndex, setTooltipData } = useChoroplethInteraction();
|
|
94
|
+
const camera = useChoroplethCamera();
|
|
95
|
+
const uid = useId().replace(/:/g, "");
|
|
96
|
+
const dots = useMemo(
|
|
97
|
+
() => buildChoroplethLattice(featurePaths, width, height, gap, lattice),
|
|
98
|
+
[featurePaths, width, height, gap, lattice]
|
|
99
|
+
);
|
|
100
|
+
const layers = useMemo(() => {
|
|
101
|
+
const byFeature = /* @__PURE__ */ new Map();
|
|
102
|
+
const ocean = [];
|
|
103
|
+
for (const { x, y, feature } of dots) {
|
|
104
|
+
if (feature < 0) {
|
|
105
|
+
ocean.push(dot(x, y));
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const list = byFeature.get(feature);
|
|
109
|
+
if (list) {
|
|
110
|
+
list.push(dot(x, y));
|
|
111
|
+
} else {
|
|
112
|
+
byFeature.set(feature, [dot(x, y)]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const regions = [...byFeature.entries()].map(([index, parts]) => {
|
|
116
|
+
const feature = features[index];
|
|
117
|
+
let color = fill;
|
|
118
|
+
if (!color && feature && getFeatureColor) {
|
|
119
|
+
color = getFeatureColor(feature, index);
|
|
120
|
+
}
|
|
121
|
+
color ??= defaultChoroplethColors[index % defaultChoroplethColors.length] ?? "var(--chart-1)";
|
|
122
|
+
return { index, d: parts.join(""), fill: color };
|
|
123
|
+
});
|
|
124
|
+
return { ocean: ocean.join(""), regions };
|
|
125
|
+
}, [dots, features, fill, getFeatureColor]);
|
|
126
|
+
const clampSize = (size) => Math.min(1, Math.max(0.05, size));
|
|
127
|
+
const baseSize = clampSize(dotSize);
|
|
128
|
+
const growth = clampSize(zoomDotSize) - baseSize;
|
|
129
|
+
const zoomProgress = `min(1, max(0, (var(${CHOROPLETH_CAMERA_SCALE_VAR}, 1) - 1) / ${Math.max(0.01, camera.maxZoom - 1)}))`;
|
|
130
|
+
const landStrokeWidth = growth === 0 ? `${gap * baseSize}px` : `calc(${gap}px * (${baseSize} + ${growth} * ${zoomProgress}))`;
|
|
131
|
+
const oceanStrokeWidth = `${gap * baseSize * oceanDotScale}px`;
|
|
132
|
+
const oceanHidden = hideOceanOnFocus && camera.focusedKey !== null;
|
|
133
|
+
const enterProgress = useMountProgress(
|
|
134
|
+
enterTransition,
|
|
135
|
+
0,
|
|
136
|
+
`choropleth-dots-${revealEpoch}`
|
|
137
|
+
);
|
|
138
|
+
const handleEnter = useCallback(
|
|
139
|
+
(index, event) => {
|
|
140
|
+
const feature = features[index];
|
|
141
|
+
if (!(feature && camera.isHoverable(`feature:${index}`))) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const target = event.currentTarget;
|
|
145
|
+
const box = (target.ownerSVGElement ?? target).getBoundingClientRect();
|
|
146
|
+
setHoveredFeatureIndex(index);
|
|
147
|
+
setTooltipData({
|
|
148
|
+
featureIndex: index,
|
|
149
|
+
x: event.clientX - box.left,
|
|
150
|
+
y: event.clientY - box.top,
|
|
151
|
+
feature
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
[camera, features, setHoveredFeatureIndex, setTooltipData]
|
|
155
|
+
);
|
|
156
|
+
const handleLeave = useCallback(() => {
|
|
157
|
+
setHoveredFeatureIndex(null);
|
|
158
|
+
setTooltipData(null);
|
|
159
|
+
}, [setHoveredFeatureIndex, setTooltipData]);
|
|
160
|
+
const focusedIndex = camera.focusedFeatureIndex;
|
|
161
|
+
const lit = layers.regions.filter(
|
|
162
|
+
(region) => region.index === hoveredFeatureIndex || region.index === focusedIndex
|
|
163
|
+
).sort((a) => a.index === hoveredFeatureIndex ? 1 : -1);
|
|
164
|
+
const dimmed = hoveredFeatureIndex !== null;
|
|
165
|
+
const maskId = `choropleth-dots-fade-${uid}`;
|
|
166
|
+
const hGradient = `${maskId}-h`;
|
|
167
|
+
const vGradient = `${maskId}-v`;
|
|
168
|
+
const hMask = `${maskId}-hm`;
|
|
169
|
+
const stops = fadeStops(edgeFade);
|
|
170
|
+
return /* @__PURE__ */ jsxs("g", { className: "choropleth-dot-grid", children: [
|
|
171
|
+
edgeFade > 0 ? /* @__PURE__ */ jsxs("defs", { children: [
|
|
172
|
+
/* @__PURE__ */ jsx("linearGradient", { id: hGradient, x1: "0", x2: "1", y1: "0", y2: "0", children: stops.map((stop) => /* @__PURE__ */ jsx(
|
|
173
|
+
"stop",
|
|
174
|
+
{
|
|
175
|
+
offset: stop.offset,
|
|
176
|
+
stopColor: "white",
|
|
177
|
+
stopOpacity: stop.opacity
|
|
178
|
+
},
|
|
179
|
+
stop.offset
|
|
180
|
+
)) }),
|
|
181
|
+
/* @__PURE__ */ jsx("linearGradient", { id: vGradient, x1: "0", x2: "0", y1: "0", y2: "1", children: stops.map((stop) => /* @__PURE__ */ jsx(
|
|
182
|
+
"stop",
|
|
183
|
+
{
|
|
184
|
+
offset: stop.offset,
|
|
185
|
+
stopColor: "white",
|
|
186
|
+
stopOpacity: stop.opacity
|
|
187
|
+
},
|
|
188
|
+
stop.offset
|
|
189
|
+
)) }),
|
|
190
|
+
/* @__PURE__ */ jsx(
|
|
191
|
+
"mask",
|
|
192
|
+
{
|
|
193
|
+
height,
|
|
194
|
+
id: hMask,
|
|
195
|
+
maskUnits: "userSpaceOnUse",
|
|
196
|
+
width,
|
|
197
|
+
x: 0,
|
|
198
|
+
y: 0,
|
|
199
|
+
children: /* @__PURE__ */ jsx("rect", { fill: `url(#${hGradient})`, height, width })
|
|
200
|
+
}
|
|
201
|
+
),
|
|
202
|
+
/* @__PURE__ */ jsx(
|
|
203
|
+
"mask",
|
|
204
|
+
{
|
|
205
|
+
height,
|
|
206
|
+
id: maskId,
|
|
207
|
+
maskUnits: "userSpaceOnUse",
|
|
208
|
+
width,
|
|
209
|
+
x: 0,
|
|
210
|
+
y: 0,
|
|
211
|
+
children: /* @__PURE__ */ jsx("g", { mask: `url(#${hMask})`, children: /* @__PURE__ */ jsx("rect", { fill: `url(#${vGradient})`, height, width }) })
|
|
212
|
+
}
|
|
213
|
+
)
|
|
214
|
+
] }) : null,
|
|
215
|
+
/* @__PURE__ */ jsxs(
|
|
216
|
+
m.g,
|
|
217
|
+
{
|
|
218
|
+
mask: edgeFade > 0 ? `url(#${maskId})` : void 0,
|
|
219
|
+
pointerEvents: "none",
|
|
220
|
+
style: { opacity: enterProgress },
|
|
221
|
+
children: [
|
|
222
|
+
showOcean && layers.ocean ? /* @__PURE__ */ jsx(
|
|
223
|
+
"path",
|
|
224
|
+
{
|
|
225
|
+
d: layers.ocean,
|
|
226
|
+
fill: "none",
|
|
227
|
+
stroke: oceanColor,
|
|
228
|
+
strokeLinecap: "round",
|
|
229
|
+
style: {
|
|
230
|
+
opacity: oceanHidden ? 0 : oceanOpacity,
|
|
231
|
+
strokeWidth: oceanStrokeWidth,
|
|
232
|
+
transition: "opacity 0.3s ease-out"
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
) : null,
|
|
236
|
+
/* @__PURE__ */ jsxs(
|
|
237
|
+
"g",
|
|
238
|
+
{
|
|
239
|
+
fill: "none",
|
|
240
|
+
strokeLinecap: "round",
|
|
241
|
+
style: { strokeWidth: landStrokeWidth },
|
|
242
|
+
children: [
|
|
243
|
+
/* @__PURE__ */ jsx(
|
|
244
|
+
"g",
|
|
245
|
+
{
|
|
246
|
+
opacity: dimmed ? fadedOpacity : 1,
|
|
247
|
+
style: { transition: "opacity 0.18s ease-out" },
|
|
248
|
+
children: layers.regions.map((region) => /* @__PURE__ */ jsx("path", { d: region.d, stroke: region.fill }, region.index))
|
|
249
|
+
}
|
|
250
|
+
),
|
|
251
|
+
dimmed ? lit.map((region) => /* @__PURE__ */ jsx(
|
|
252
|
+
"path",
|
|
253
|
+
{
|
|
254
|
+
d: region.d,
|
|
255
|
+
stroke: region.fill
|
|
256
|
+
},
|
|
257
|
+
`lit-${region.index}`
|
|
258
|
+
)) : null
|
|
259
|
+
]
|
|
260
|
+
}
|
|
261
|
+
)
|
|
262
|
+
]
|
|
263
|
+
}
|
|
264
|
+
),
|
|
265
|
+
/* @__PURE__ */ jsx("g", { fill: "transparent", children: featurePaths.map(
|
|
266
|
+
(d, index) => d ? (
|
|
267
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: SVG path used as hover hitbox
|
|
268
|
+
/* @__PURE__ */ jsx(
|
|
269
|
+
"path",
|
|
270
|
+
{
|
|
271
|
+
className: "cursor-pointer",
|
|
272
|
+
d,
|
|
273
|
+
onClick: () => {
|
|
274
|
+
if (camera.enabled && !camera.wasDrag()) {
|
|
275
|
+
camera.focusFeature(index);
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
onMouseEnter: (event) => handleEnter(index, event),
|
|
279
|
+
onMouseLeave: handleLeave
|
|
280
|
+
},
|
|
281
|
+
index
|
|
282
|
+
)
|
|
283
|
+
) : null
|
|
284
|
+
) })
|
|
285
|
+
] });
|
|
286
|
+
});
|
|
287
|
+
ChoroplethDotGrid.displayName = "ChoroplethDotGrid";
|
|
288
|
+
var choropleth_dot_grid_default = ChoroplethDotGrid;
|
|
289
|
+
export {
|
|
290
|
+
ChoroplethDotGrid,
|
|
291
|
+
buildChoroplethLattice,
|
|
292
|
+
choropleth_dot_grid_default as default
|
|
293
|
+
};
|