@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,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext } from "react";
|
|
4
|
+
const StaticChartPreviewContext = createContext(false);
|
|
5
|
+
function StaticChartPreviewProvider({
|
|
6
|
+
children
|
|
7
|
+
}) {
|
|
8
|
+
return /* @__PURE__ */ jsx(StaticChartPreviewContext.Provider, { value: true, children });
|
|
9
|
+
}
|
|
10
|
+
function useStaticChartPreview() {
|
|
11
|
+
return useContext(StaticChartPreviewContext);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
StaticChartPreviewProvider,
|
|
15
|
+
useStaticChartPreview
|
|
16
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { memo, useMemo } from "react";
|
|
4
|
+
import { useSunburstStable } from "./sunburst-context";
|
|
5
|
+
function useSunburstBreadcrumbItems() {
|
|
6
|
+
const { data, focus, focusById, rootId, zoomTo } = useSunburstStable();
|
|
7
|
+
const rootName = data.name;
|
|
8
|
+
const items = useMemo(() => {
|
|
9
|
+
const crumbs = [];
|
|
10
|
+
let cur = focus;
|
|
11
|
+
while (cur) {
|
|
12
|
+
crumbs.unshift(cur);
|
|
13
|
+
cur = cur.parentId ? focusById.get(cur.parentId) : void 0;
|
|
14
|
+
}
|
|
15
|
+
return crumbs.map((c, index) => ({
|
|
16
|
+
id: c.id,
|
|
17
|
+
label: c.id === rootId ? rootName : c.name,
|
|
18
|
+
isCurrent: index === crumbs.length - 1
|
|
19
|
+
}));
|
|
20
|
+
}, [rootName, focus, focusById, rootId]);
|
|
21
|
+
return { items, zoomTo };
|
|
22
|
+
}
|
|
23
|
+
const SunburstBreadcrumb = memo(function SunburstBreadcrumb2({
|
|
24
|
+
className,
|
|
25
|
+
children
|
|
26
|
+
}) {
|
|
27
|
+
return /* @__PURE__ */ jsx("nav", { "aria-label": "Caminho de detalhamento", className: className ?? "mb-4", children });
|
|
28
|
+
});
|
|
29
|
+
SunburstBreadcrumb.displayName = "SunburstBreadcrumb";
|
|
30
|
+
export {
|
|
31
|
+
SunburstBreadcrumb,
|
|
32
|
+
useSunburstBreadcrumbItems
|
|
33
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { memo } from "react";
|
|
4
|
+
import { ringOptions } from "./sunburst";
|
|
5
|
+
import { sunburstCssVars, useSunburstStable } from "./sunburst-context";
|
|
6
|
+
const SunburstCenter = memo(function SunburstCenter2({
|
|
7
|
+
className
|
|
8
|
+
}) {
|
|
9
|
+
const { focus, prevFocus, maxDepth, radius, zoomT, zoomTo, getColor } = useSunburstStable();
|
|
10
|
+
const { centerR } = ringOptions(focus.depth, maxDepth, radius);
|
|
11
|
+
const liveCenterR = centerR * zoomT + ringOptions(prevFocus.depth, maxDepth, radius).centerR * (1 - zoomT);
|
|
12
|
+
if (liveCenterR <= 1) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const centerColor = focus.depth === 0 ? sunburstCssVars.background : getColor(focus.categoryIndex);
|
|
16
|
+
return (
|
|
17
|
+
/* biome-ignore lint/a11y/noStaticElementInteractions: Center zoom-out control */
|
|
18
|
+
/* @__PURE__ */ jsx(
|
|
19
|
+
"circle",
|
|
20
|
+
{
|
|
21
|
+
className,
|
|
22
|
+
cx: 0,
|
|
23
|
+
cy: 0,
|
|
24
|
+
fill: centerColor,
|
|
25
|
+
onClick: () => focus.parentId && zoomTo(focus.parentId),
|
|
26
|
+
r: Math.max(liveCenterR - 2, 0),
|
|
27
|
+
stroke: sunburstCssVars.ring,
|
|
28
|
+
strokeWidth: 1,
|
|
29
|
+
style: { cursor: focus.parentId ? "pointer" : "default" }
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
SunburstCenter.displayName = "SunburstCenter";
|
|
35
|
+
export {
|
|
36
|
+
SunburstCenter
|
|
37
|
+
};
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { animate, domAnimation, LazyMotion, m } from "motion/react";
|
|
4
|
+
import {
|
|
5
|
+
Children,
|
|
6
|
+
isValidElement,
|
|
7
|
+
memo,
|
|
8
|
+
useCallback,
|
|
9
|
+
useEffect,
|
|
10
|
+
useMemo,
|
|
11
|
+
useRef,
|
|
12
|
+
useState,
|
|
13
|
+
useSyncExternalStore
|
|
14
|
+
} from "react";
|
|
15
|
+
import { useChartDataOverride } from "./chart-data-override";
|
|
16
|
+
import {
|
|
17
|
+
buildArcs,
|
|
18
|
+
buildHoverGrowTargets,
|
|
19
|
+
buildSunburstEnterTiming,
|
|
20
|
+
defaultSunburstGrowPadding,
|
|
21
|
+
maxHoverSegmentThickness
|
|
22
|
+
} from "./sunburst";
|
|
23
|
+
import {
|
|
24
|
+
defaultSunburstColors,
|
|
25
|
+
opacityForRelativeDepth,
|
|
26
|
+
SunburstProvider
|
|
27
|
+
} from "./sunburst-context";
|
|
28
|
+
const DEFAULT_HOVER_POP = 8;
|
|
29
|
+
function componentDisplayName(child) {
|
|
30
|
+
return child.type.displayName || child.type.name || "";
|
|
31
|
+
}
|
|
32
|
+
function isDefsComponent(child) {
|
|
33
|
+
const name = componentDisplayName(child);
|
|
34
|
+
return name.includes("Gradient") || name.includes("Pattern") || name === "LinearGradient" || name === "RadialGradient";
|
|
35
|
+
}
|
|
36
|
+
function isOutsideSvgComponent(name) {
|
|
37
|
+
return name === "SunburstBreadcrumb" || name === "SunburstHint";
|
|
38
|
+
}
|
|
39
|
+
function isSunburstSegment(child) {
|
|
40
|
+
return isValidElement(child) && componentDisplayName(child) === "SunburstSegment";
|
|
41
|
+
}
|
|
42
|
+
function sortSunburstSegments(segments, arcs) {
|
|
43
|
+
return [...segments].sort((a, b) => {
|
|
44
|
+
const arcA = arcs[a.props.index];
|
|
45
|
+
const arcB = arcs[b.props.index];
|
|
46
|
+
const depthA = arcA?.depth ?? 0;
|
|
47
|
+
const depthB = arcB?.depth ?? 0;
|
|
48
|
+
if (depthA !== depthB) {
|
|
49
|
+
return depthB - depthA;
|
|
50
|
+
}
|
|
51
|
+
return (b.props.index ?? 0) - (a.props.index ?? 0);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
|
|
55
|
+
function subscribeReducedMotion(onStoreChange) {
|
|
56
|
+
if (typeof window === "undefined" || !window.matchMedia) {
|
|
57
|
+
return () => void 0;
|
|
58
|
+
}
|
|
59
|
+
const query = window.matchMedia(REDUCED_MOTION_QUERY);
|
|
60
|
+
query.addEventListener?.("change", onStoreChange);
|
|
61
|
+
return () => query.removeEventListener?.("change", onStoreChange);
|
|
62
|
+
}
|
|
63
|
+
function getReducedMotionSnapshot() {
|
|
64
|
+
return typeof window !== "undefined" && window.matchMedia?.(REDUCED_MOTION_QUERY).matches === true;
|
|
65
|
+
}
|
|
66
|
+
function getReducedMotionServerSnapshot() {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
const SunburstChartCore = memo(function SunburstChartCore2({
|
|
70
|
+
data,
|
|
71
|
+
size = 520,
|
|
72
|
+
playKey = 0,
|
|
73
|
+
className,
|
|
74
|
+
focusId: focusIdProp,
|
|
75
|
+
onFocusChange,
|
|
76
|
+
hoveredIndex: hoveredIndexProp,
|
|
77
|
+
onHoverChange,
|
|
78
|
+
hoverPop = DEFAULT_HOVER_POP,
|
|
79
|
+
padding: paddingProp,
|
|
80
|
+
enterTransition,
|
|
81
|
+
enterStaggerScale = 1,
|
|
82
|
+
children
|
|
83
|
+
}) {
|
|
84
|
+
const fullRadius = size / 2;
|
|
85
|
+
const containerRef = useRef(null);
|
|
86
|
+
const { arcs, maxDepth, focusById, rootId } = useMemo(
|
|
87
|
+
() => buildArcs(data),
|
|
88
|
+
[data]
|
|
89
|
+
);
|
|
90
|
+
const growPadding = useMemo(
|
|
91
|
+
() => paddingProp ?? defaultSunburstGrowPadding(maxDepth, size, hoverPop),
|
|
92
|
+
[paddingProp, maxDepth, size, hoverPop]
|
|
93
|
+
);
|
|
94
|
+
const radius = Math.max(8, fullRadius - growPadding);
|
|
95
|
+
const prefersReducedMotion = useSyncExternalStore(
|
|
96
|
+
subscribeReducedMotion,
|
|
97
|
+
getReducedMotionSnapshot,
|
|
98
|
+
getReducedMotionServerSnapshot
|
|
99
|
+
);
|
|
100
|
+
const skipEnterAnimation = prefersReducedMotion;
|
|
101
|
+
const [internalHoveredArc, setInternalHoveredArc] = useState(
|
|
102
|
+
null
|
|
103
|
+
);
|
|
104
|
+
const [internalHoveredIndex, setInternalHoveredIndex] = useState(null);
|
|
105
|
+
const growRef = useRef(/* @__PURE__ */ new Map());
|
|
106
|
+
const [grow, setGrow] = useState(() => /* @__PURE__ */ new Map());
|
|
107
|
+
const [internalFocusId, setInternalFocusId] = useState(rootId);
|
|
108
|
+
const [prevFocusId, setPrevFocusId] = useState(rootId);
|
|
109
|
+
const [zoomT, setZoomT] = useState(1);
|
|
110
|
+
const isFocusControlled = focusIdProp !== void 0;
|
|
111
|
+
const focusId = isFocusControlled ? focusIdProp : internalFocusId;
|
|
112
|
+
const isHoverControlled = hoveredIndexProp !== void 0;
|
|
113
|
+
const hoveredArcIndex = isHoverControlled ? hoveredIndexProp : internalHoveredIndex;
|
|
114
|
+
const hoveredArc = useMemo(() => {
|
|
115
|
+
if (hoveredArcIndex != null) {
|
|
116
|
+
return arcs[hoveredArcIndex] ?? null;
|
|
117
|
+
}
|
|
118
|
+
return internalHoveredArc;
|
|
119
|
+
}, [arcs, hoveredArcIndex, internalHoveredArc]);
|
|
120
|
+
const setHoveredArcIndex = useCallback(
|
|
121
|
+
(index) => {
|
|
122
|
+
if (isHoverControlled) {
|
|
123
|
+
onHoverChange?.(index);
|
|
124
|
+
} else {
|
|
125
|
+
setInternalHoveredIndex(index);
|
|
126
|
+
setInternalHoveredArc(index == null ? null : arcs[index] ?? null);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
[arcs, isHoverControlled, onHoverChange]
|
|
130
|
+
);
|
|
131
|
+
const setHoveredArc = useCallback(
|
|
132
|
+
(arc) => {
|
|
133
|
+
setHoveredArcIndex(arc ? arc.arcIndex : null);
|
|
134
|
+
},
|
|
135
|
+
[setHoveredArcIndex]
|
|
136
|
+
);
|
|
137
|
+
const setFocusId = useCallback(
|
|
138
|
+
(nextId) => {
|
|
139
|
+
if (isFocusControlled) {
|
|
140
|
+
onFocusChange?.(nextId);
|
|
141
|
+
} else {
|
|
142
|
+
setInternalFocusId(nextId);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
[isFocusControlled, onFocusChange]
|
|
146
|
+
);
|
|
147
|
+
const rootFocus = focusById.get(rootId);
|
|
148
|
+
const focus = focusById.get(focusId) ?? rootFocus;
|
|
149
|
+
const prevFocus = focusById.get(prevFocusId) ?? focus;
|
|
150
|
+
const [focusResetKey, setFocusResetKey] = useState({
|
|
151
|
+
rootId,
|
|
152
|
+
isFocusControlled
|
|
153
|
+
});
|
|
154
|
+
if (focusResetKey.rootId !== rootId || focusResetKey.isFocusControlled !== isFocusControlled) {
|
|
155
|
+
setFocusResetKey({ rootId, isFocusControlled });
|
|
156
|
+
if (!isFocusControlled) {
|
|
157
|
+
setInternalFocusId(rootId);
|
|
158
|
+
}
|
|
159
|
+
setPrevFocusId(rootId);
|
|
160
|
+
setZoomT(1);
|
|
161
|
+
}
|
|
162
|
+
const enterTiming = useMemo(
|
|
163
|
+
() => buildSunburstEnterTiming(arcs, enterStaggerScale),
|
|
164
|
+
[arcs, enterStaggerScale]
|
|
165
|
+
);
|
|
166
|
+
const growControls = useRef(null);
|
|
167
|
+
const zoomControls = useRef(null);
|
|
168
|
+
const zoomGen = useRef(0);
|
|
169
|
+
const zoomTo = useCallback(
|
|
170
|
+
(nextId) => {
|
|
171
|
+
if (nextId === focusId) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
setHoveredArc(null);
|
|
175
|
+
growControls.current?.stop();
|
|
176
|
+
growRef.current = /* @__PURE__ */ new Map();
|
|
177
|
+
setGrow(growRef.current);
|
|
178
|
+
setPrevFocusId(focusId);
|
|
179
|
+
setFocusId(nextId);
|
|
180
|
+
zoomControls.current?.stop();
|
|
181
|
+
const gen = ++zoomGen.current;
|
|
182
|
+
if (getReducedMotionSnapshot()) {
|
|
183
|
+
setZoomT(1);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
setZoomT(0);
|
|
187
|
+
zoomControls.current = animate(0, 1, {
|
|
188
|
+
duration: 0.75,
|
|
189
|
+
ease: [0.22, 1, 0.36, 1],
|
|
190
|
+
onUpdate: (value) => {
|
|
191
|
+
if (zoomGen.current === gen) {
|
|
192
|
+
setZoomT(value);
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
onComplete: () => {
|
|
196
|
+
if (zoomGen.current === gen) {
|
|
197
|
+
setZoomT(1);
|
|
198
|
+
setPrevFocusId(nextId);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
},
|
|
203
|
+
[focusId, setFocusId, setHoveredArc]
|
|
204
|
+
);
|
|
205
|
+
const isDescendant = useCallback(
|
|
206
|
+
(d, ancestorId) => d.id === ancestorId || d.id.startsWith(`${ancestorId} / `),
|
|
207
|
+
[]
|
|
208
|
+
);
|
|
209
|
+
const isOnHoverPath = useCallback(
|
|
210
|
+
(d, hoveredId) => d.id === hoveredId || hoveredId.startsWith(`${d.id} / `),
|
|
211
|
+
[]
|
|
212
|
+
);
|
|
213
|
+
const isRelated = useCallback(
|
|
214
|
+
(d) => {
|
|
215
|
+
if (!hoveredArc) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
return isDescendant(d, hoveredArc.id) || hoveredArc.id.startsWith(`${d.id} / `);
|
|
219
|
+
},
|
|
220
|
+
[hoveredArc, isDescendant]
|
|
221
|
+
);
|
|
222
|
+
const growTargets = useMemo(
|
|
223
|
+
() => hoveredArc && focus ? buildHoverGrowTargets(
|
|
224
|
+
arcs,
|
|
225
|
+
hoveredArc,
|
|
226
|
+
focus,
|
|
227
|
+
maxDepth,
|
|
228
|
+
radius,
|
|
229
|
+
hoverPop,
|
|
230
|
+
isOnHoverPath
|
|
231
|
+
) : /* @__PURE__ */ new Map(),
|
|
232
|
+
[hoveredArc, arcs, hoverPop, isOnHoverPath, focus, maxDepth, radius]
|
|
233
|
+
);
|
|
234
|
+
useEffect(() => {
|
|
235
|
+
const targets = growTargets;
|
|
236
|
+
const starts = new Map(growRef.current);
|
|
237
|
+
const ids = /* @__PURE__ */ new Set([...starts.keys(), ...targets.keys()]);
|
|
238
|
+
growControls.current?.stop();
|
|
239
|
+
if (prefersReducedMotion) {
|
|
240
|
+
growRef.current = targets;
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
growControls.current = animate(0, 1, {
|
|
244
|
+
duration: 0.42,
|
|
245
|
+
ease: [0.22, 1, 0.36, 1],
|
|
246
|
+
onUpdate: (p) => {
|
|
247
|
+
const next = /* @__PURE__ */ new Map();
|
|
248
|
+
for (const id of ids) {
|
|
249
|
+
const start = starts.get(id) ?? 0;
|
|
250
|
+
const target = targets.get(id) ?? 0;
|
|
251
|
+
const val = start + (target - start) * p;
|
|
252
|
+
if (val > 0.01) {
|
|
253
|
+
next.set(id, val);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
growRef.current = next;
|
|
257
|
+
setGrow(next);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
return () => growControls.current?.stop();
|
|
261
|
+
}, [growTargets, prefersReducedMotion]);
|
|
262
|
+
const displayedGrow = prefersReducedMotion ? growTargets : grow;
|
|
263
|
+
const getColor = useCallback((categoryIndex, nodeColor) => {
|
|
264
|
+
if (nodeColor) {
|
|
265
|
+
return nodeColor;
|
|
266
|
+
}
|
|
267
|
+
return defaultSunburstColors[categoryIndex % defaultSunburstColors.length];
|
|
268
|
+
}, []);
|
|
269
|
+
const getFill = useCallback(
|
|
270
|
+
(arcIndex, fillOverride, colorOverride) => {
|
|
271
|
+
if (fillOverride) {
|
|
272
|
+
return fillOverride;
|
|
273
|
+
}
|
|
274
|
+
const arc = arcs[arcIndex];
|
|
275
|
+
if (!arc) {
|
|
276
|
+
return defaultSunburstColors[0];
|
|
277
|
+
}
|
|
278
|
+
return colorOverride ?? arc.fill ?? arc.color ?? getColor(arc.categoryIndex);
|
|
279
|
+
},
|
|
280
|
+
[arcs, getColor]
|
|
281
|
+
);
|
|
282
|
+
const getFillOpacity = useCallback(
|
|
283
|
+
(relativeDepth, override) => override ?? opacityForRelativeDepth(relativeDepth),
|
|
284
|
+
[]
|
|
285
|
+
);
|
|
286
|
+
const growAmountForArc = useCallback(
|
|
287
|
+
(arcId) => displayedGrow.get(arcId) ?? 0,
|
|
288
|
+
[displayedGrow]
|
|
289
|
+
);
|
|
290
|
+
const maxExpandedThickness = useMemo(
|
|
291
|
+
() => maxHoverSegmentThickness(maxDepth, radius, hoverPop),
|
|
292
|
+
[maxDepth, radius, hoverPop]
|
|
293
|
+
);
|
|
294
|
+
if (!(focus && prevFocus)) {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
const childArray = Children.toArray(children);
|
|
298
|
+
const defsChildren = childArray.filter(
|
|
299
|
+
(child) => isValidElement(child) && isDefsComponent(child)
|
|
300
|
+
);
|
|
301
|
+
const outsideChildren = [];
|
|
302
|
+
const svgChildren = [];
|
|
303
|
+
for (const child of childArray) {
|
|
304
|
+
if (!isValidElement(child)) {
|
|
305
|
+
svgChildren.push(child);
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
if (isDefsComponent(child)) {
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const name = componentDisplayName(child);
|
|
312
|
+
if (isOutsideSvgComponent(name)) {
|
|
313
|
+
outsideChildren.push(child);
|
|
314
|
+
} else {
|
|
315
|
+
svgChildren.push(child);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const segmentChildren = svgChildren.filter(isSunburstSegment);
|
|
319
|
+
const otherSvgChildren = svgChildren.filter(
|
|
320
|
+
(child) => !isSunburstSegment(child)
|
|
321
|
+
);
|
|
322
|
+
const orderedSegments = sortSunburstSegments(segmentChildren, arcs);
|
|
323
|
+
const orderedSvgChildren = [...orderedSegments, ...otherSvgChildren];
|
|
324
|
+
const providerValue = {
|
|
325
|
+
data,
|
|
326
|
+
arcs,
|
|
327
|
+
focusById,
|
|
328
|
+
rootId,
|
|
329
|
+
maxDepth,
|
|
330
|
+
radius,
|
|
331
|
+
size,
|
|
332
|
+
focus,
|
|
333
|
+
prevFocus,
|
|
334
|
+
focusId,
|
|
335
|
+
zoomTo,
|
|
336
|
+
zoomT,
|
|
337
|
+
enterTiming,
|
|
338
|
+
skipEnterAnimation,
|
|
339
|
+
growAmountForArc,
|
|
340
|
+
getColor,
|
|
341
|
+
getFill,
|
|
342
|
+
getFillOpacity,
|
|
343
|
+
isRelated,
|
|
344
|
+
isDescendant,
|
|
345
|
+
enterTransition,
|
|
346
|
+
enterStaggerScale,
|
|
347
|
+
playKey,
|
|
348
|
+
hoverPop,
|
|
349
|
+
maxExpandedThickness,
|
|
350
|
+
containerRef,
|
|
351
|
+
hoveredArcIndex,
|
|
352
|
+
setHoveredArcIndex,
|
|
353
|
+
hoveredArc,
|
|
354
|
+
setHoveredArc
|
|
355
|
+
};
|
|
356
|
+
return /* @__PURE__ */ jsx(SunburstProvider, { value: providerValue, children: /* @__PURE__ */ jsxs(
|
|
357
|
+
"div",
|
|
358
|
+
{
|
|
359
|
+
className,
|
|
360
|
+
ref: containerRef,
|
|
361
|
+
style: { maxWidth: "100%", width: size },
|
|
362
|
+
children: [
|
|
363
|
+
outsideChildren.filter(
|
|
364
|
+
(child) => isValidElement(child) && componentDisplayName(child) === "SunburstBreadcrumb"
|
|
365
|
+
),
|
|
366
|
+
/* @__PURE__ */ jsx(
|
|
367
|
+
"div",
|
|
368
|
+
{
|
|
369
|
+
className: "mx-auto w-full",
|
|
370
|
+
style: { aspectRatio: "1 / 1", maxWidth: size },
|
|
371
|
+
children: /* @__PURE__ */ jsxs(
|
|
372
|
+
m.svg,
|
|
373
|
+
{
|
|
374
|
+
animate: { opacity: 1 },
|
|
375
|
+
"aria-label": `Sunburst chart of ${data.name}`,
|
|
376
|
+
initial: { opacity: 0 },
|
|
377
|
+
onPointerLeave: () => setHoveredArc(null),
|
|
378
|
+
role: "img",
|
|
379
|
+
style: { display: "block", overflow: "visible" },
|
|
380
|
+
transition: { duration: 0.35, ease: [0.22, 1, 0.36, 1] },
|
|
381
|
+
viewBox: `${-fullRadius} ${-fullRadius} ${size} ${size}`,
|
|
382
|
+
width: "100%",
|
|
383
|
+
children: [
|
|
384
|
+
defsChildren.length > 0 ? /* @__PURE__ */ jsx("defs", { children: defsChildren }) : null,
|
|
385
|
+
orderedSvgChildren
|
|
386
|
+
]
|
|
387
|
+
}
|
|
388
|
+
)
|
|
389
|
+
}
|
|
390
|
+
),
|
|
391
|
+
outsideChildren.filter(
|
|
392
|
+
(child) => isValidElement(child) && componentDisplayName(child) === "SunburstHint"
|
|
393
|
+
)
|
|
394
|
+
]
|
|
395
|
+
}
|
|
396
|
+
) });
|
|
397
|
+
});
|
|
398
|
+
function SunburstChart({
|
|
399
|
+
data: dataProp,
|
|
400
|
+
...props
|
|
401
|
+
}) {
|
|
402
|
+
const { data } = useChartDataOverride("SunburstChart", { data: dataProp });
|
|
403
|
+
return /* @__PURE__ */ jsx(LazyMotion, { features: domAnimation, children: /* @__PURE__ */ jsx(SunburstChartCore, { ...props, data }) });
|
|
404
|
+
}
|
|
405
|
+
SunburstChart.displayName = "SunburstChart";
|
|
406
|
+
export {
|
|
407
|
+
SunburstChart
|
|
408
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useContext,
|
|
6
|
+
useMemo
|
|
7
|
+
} from "react";
|
|
8
|
+
const sunburstCssVars = {
|
|
9
|
+
background: "var(--chart-background)",
|
|
10
|
+
foreground: "var(--chart-foreground)",
|
|
11
|
+
foregroundMuted: "var(--chart-foreground-muted)",
|
|
12
|
+
label: "var(--chart-label)",
|
|
13
|
+
ring: "var(--chart-background)",
|
|
14
|
+
slice1: "var(--chart-1)",
|
|
15
|
+
slice2: "var(--chart-2)",
|
|
16
|
+
slice3: "var(--chart-3)",
|
|
17
|
+
slice4: "var(--chart-4)",
|
|
18
|
+
slice5: "var(--chart-5)"
|
|
19
|
+
};
|
|
20
|
+
const defaultSunburstColors = [
|
|
21
|
+
sunburstCssVars.slice1,
|
|
22
|
+
sunburstCssVars.slice2,
|
|
23
|
+
sunburstCssVars.slice3,
|
|
24
|
+
sunburstCssVars.slice4,
|
|
25
|
+
sunburstCssVars.slice5
|
|
26
|
+
];
|
|
27
|
+
const OPACITY_STEP = 0.15;
|
|
28
|
+
const OPACITY_FLOOR = 0.45;
|
|
29
|
+
function opacityForRelativeDepth(relativeDepth) {
|
|
30
|
+
if (relativeDepth <= 1) {
|
|
31
|
+
return 1;
|
|
32
|
+
}
|
|
33
|
+
return Math.max(OPACITY_FLOOR, 1 - (relativeDepth - 1) * OPACITY_STEP);
|
|
34
|
+
}
|
|
35
|
+
const SunburstStableContext = createContext(
|
|
36
|
+
null
|
|
37
|
+
);
|
|
38
|
+
const SunburstHoverContext = createContext(
|
|
39
|
+
null
|
|
40
|
+
);
|
|
41
|
+
function SunburstProvider({
|
|
42
|
+
children,
|
|
43
|
+
value
|
|
44
|
+
}) {
|
|
45
|
+
const stable = useMemo(
|
|
46
|
+
() => ({
|
|
47
|
+
data: value.data,
|
|
48
|
+
arcs: value.arcs,
|
|
49
|
+
focusById: value.focusById,
|
|
50
|
+
rootId: value.rootId,
|
|
51
|
+
maxDepth: value.maxDepth,
|
|
52
|
+
radius: value.radius,
|
|
53
|
+
size: value.size,
|
|
54
|
+
focus: value.focus,
|
|
55
|
+
prevFocus: value.prevFocus,
|
|
56
|
+
focusId: value.focusId,
|
|
57
|
+
zoomTo: value.zoomTo,
|
|
58
|
+
zoomT: value.zoomT,
|
|
59
|
+
enterTiming: value.enterTiming,
|
|
60
|
+
skipEnterAnimation: value.skipEnterAnimation,
|
|
61
|
+
growAmountForArc: value.growAmountForArc,
|
|
62
|
+
getColor: value.getColor,
|
|
63
|
+
getFill: value.getFill,
|
|
64
|
+
getFillOpacity: value.getFillOpacity,
|
|
65
|
+
isRelated: value.isRelated,
|
|
66
|
+
isDescendant: value.isDescendant,
|
|
67
|
+
enterTransition: value.enterTransition,
|
|
68
|
+
enterStaggerScale: value.enterStaggerScale,
|
|
69
|
+
playKey: value.playKey,
|
|
70
|
+
hoverPop: value.hoverPop,
|
|
71
|
+
maxExpandedThickness: value.maxExpandedThickness,
|
|
72
|
+
containerRef: value.containerRef
|
|
73
|
+
}),
|
|
74
|
+
[
|
|
75
|
+
value.data,
|
|
76
|
+
value.arcs,
|
|
77
|
+
value.focusById,
|
|
78
|
+
value.rootId,
|
|
79
|
+
value.maxDepth,
|
|
80
|
+
value.radius,
|
|
81
|
+
value.size,
|
|
82
|
+
value.focus,
|
|
83
|
+
value.prevFocus,
|
|
84
|
+
value.focusId,
|
|
85
|
+
value.zoomTo,
|
|
86
|
+
value.zoomT,
|
|
87
|
+
value.enterTiming,
|
|
88
|
+
value.skipEnterAnimation,
|
|
89
|
+
value.growAmountForArc,
|
|
90
|
+
value.getColor,
|
|
91
|
+
value.getFill,
|
|
92
|
+
value.getFillOpacity,
|
|
93
|
+
value.isRelated,
|
|
94
|
+
value.isDescendant,
|
|
95
|
+
value.enterTransition,
|
|
96
|
+
value.enterStaggerScale,
|
|
97
|
+
value.playKey,
|
|
98
|
+
value.hoverPop,
|
|
99
|
+
value.maxExpandedThickness,
|
|
100
|
+
value.containerRef
|
|
101
|
+
]
|
|
102
|
+
);
|
|
103
|
+
const hover = useMemo(
|
|
104
|
+
() => ({
|
|
105
|
+
hoveredArcIndex: value.hoveredArcIndex,
|
|
106
|
+
setHoveredArcIndex: value.setHoveredArcIndex,
|
|
107
|
+
hoveredArc: value.hoveredArc,
|
|
108
|
+
setHoveredArc: value.setHoveredArc
|
|
109
|
+
}),
|
|
110
|
+
[
|
|
111
|
+
value.hoveredArcIndex,
|
|
112
|
+
value.setHoveredArcIndex,
|
|
113
|
+
value.hoveredArc,
|
|
114
|
+
value.setHoveredArc
|
|
115
|
+
]
|
|
116
|
+
);
|
|
117
|
+
return /* @__PURE__ */ jsx(SunburstStableContext.Provider, { value: stable, children: /* @__PURE__ */ jsx(SunburstHoverContext.Provider, { value: hover, children }) });
|
|
118
|
+
}
|
|
119
|
+
function useSunburstStable() {
|
|
120
|
+
const ctx = useContext(SunburstStableContext);
|
|
121
|
+
if (!ctx) {
|
|
122
|
+
throw new Error("useSunburstStable must be used within SunburstChart");
|
|
123
|
+
}
|
|
124
|
+
return ctx;
|
|
125
|
+
}
|
|
126
|
+
function useSunburstHover() {
|
|
127
|
+
const ctx = useContext(SunburstHoverContext);
|
|
128
|
+
if (!ctx) {
|
|
129
|
+
throw new Error("useSunburstHover must be used within SunburstChart");
|
|
130
|
+
}
|
|
131
|
+
return ctx;
|
|
132
|
+
}
|
|
133
|
+
export {
|
|
134
|
+
SunburstProvider,
|
|
135
|
+
defaultSunburstColors,
|
|
136
|
+
opacityForRelativeDepth,
|
|
137
|
+
sunburstCssVars,
|
|
138
|
+
useSunburstHover,
|
|
139
|
+
useSunburstStable
|
|
140
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { memo } from "react";
|
|
4
|
+
import { useSunburstHover, useSunburstStable } from "./sunburst-context";
|
|
5
|
+
const SunburstHint = memo(function SunburstHint2({
|
|
6
|
+
className,
|
|
7
|
+
children
|
|
8
|
+
}) {
|
|
9
|
+
const { focus } = useSunburstStable();
|
|
10
|
+
const { hoveredArc } = useSunburstHover();
|
|
11
|
+
const hintText = (() => {
|
|
12
|
+
if (hoveredArc) {
|
|
13
|
+
return hoveredArc.trail.join(" \u203A ");
|
|
14
|
+
}
|
|
15
|
+
if (focus.depth === 0) {
|
|
16
|
+
return "Clique num segmento para aproximar \xB7 passe o mouse para ver";
|
|
17
|
+
}
|
|
18
|
+
return "Clique no centro para voltar";
|
|
19
|
+
})();
|
|
20
|
+
const context = { hintText, hoveredArc, focus };
|
|
21
|
+
let content;
|
|
22
|
+
if (typeof children === "function") {
|
|
23
|
+
content = children(context);
|
|
24
|
+
} else if (children == null) {
|
|
25
|
+
content = hintText;
|
|
26
|
+
} else {
|
|
27
|
+
content = children;
|
|
28
|
+
}
|
|
29
|
+
return /* @__PURE__ */ jsx(
|
|
30
|
+
"div",
|
|
31
|
+
{
|
|
32
|
+
"aria-live": "polite",
|
|
33
|
+
className: className ?? "mt-3 min-h-5 text-center text-chart-foreground-muted text-sm",
|
|
34
|
+
style: { minHeight: 20 },
|
|
35
|
+
children: content
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
SunburstHint.displayName = "SunburstHint";
|
|
40
|
+
export {
|
|
41
|
+
SunburstHint
|
|
42
|
+
};
|