@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,149 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { domAnimation, LazyMotion } from "motion/react";
|
|
4
|
+
import {
|
|
5
|
+
Children,
|
|
6
|
+
isValidElement,
|
|
7
|
+
useCallback,
|
|
8
|
+
useMemo,
|
|
9
|
+
useRef,
|
|
10
|
+
useState
|
|
11
|
+
} from "react";
|
|
12
|
+
import { cn } from "../lib/utils";
|
|
13
|
+
import { Area } from "./area";
|
|
14
|
+
import { AreaValueLabels } from "./area-value-labels";
|
|
15
|
+
import { useStableMargin } from "./chart-context";
|
|
16
|
+
import { useChartDataOverride } from "./chart-data-override";
|
|
17
|
+
import { InteracaoProvider } from "../aic/interacao";
|
|
18
|
+
import { ChartLoadingLabel } from "./chart-loading-label";
|
|
19
|
+
import { ParentSize } from "./chart-parent-size";
|
|
20
|
+
import {
|
|
21
|
+
DEFAULT_CHART_STATUS,
|
|
22
|
+
DEFAULT_Y_DOMAIN_TWEEN_MS,
|
|
23
|
+
resolveRestingChartPhase
|
|
24
|
+
} from "./chart-phase";
|
|
25
|
+
import { PatternArea } from "./pattern-area";
|
|
26
|
+
import {
|
|
27
|
+
TimeSeriesChartInner,
|
|
28
|
+
timeSeriesChartHasRoom
|
|
29
|
+
} from "./time-series-chart-shell";
|
|
30
|
+
const DEFAULT_MARGIN = { top: 40, right: 40, bottom: 40, left: 40 };
|
|
31
|
+
function extractAreaConfigs(children) {
|
|
32
|
+
const configs = [];
|
|
33
|
+
Children.forEach(children, (child) => {
|
|
34
|
+
if (!isValidElement(child)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const childType = child.type;
|
|
38
|
+
const componentName = typeof child.type === "function" ? childType.displayName || childType.name || "" : "";
|
|
39
|
+
const props = child.props;
|
|
40
|
+
const isPatternArea = componentName === "PatternArea" || child.type === PatternArea;
|
|
41
|
+
const isSeriesOverlay = componentName === "TrendLine" || componentName === "LineSeriesTerminalMarker" || componentName === "LineBackdrop";
|
|
42
|
+
const isAreaComponent = componentName === "Area" || child.type === Area || props && typeof props.dataKey === "string" && props.dataKey.length > 0 && !isPatternArea && !isSeriesOverlay;
|
|
43
|
+
if (isAreaComponent && props?.dataKey) {
|
|
44
|
+
configs.push({
|
|
45
|
+
...props,
|
|
46
|
+
dataKey: props.dataKey,
|
|
47
|
+
stroke: props.stroke || props.fill || "var(--chart-line-primary)",
|
|
48
|
+
strokeWidth: props.strokeWidth || 2,
|
|
49
|
+
yAxisId: props.yAxisId
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return configs;
|
|
54
|
+
}
|
|
55
|
+
function AreaChart({
|
|
56
|
+
data: dataProp,
|
|
57
|
+
xDataKey = "date",
|
|
58
|
+
margin: marginProp,
|
|
59
|
+
animationDuration = 1100,
|
|
60
|
+
animationEasing,
|
|
61
|
+
enterTransition,
|
|
62
|
+
revealSignature,
|
|
63
|
+
aspectRatio = "2 / 1",
|
|
64
|
+
className = "",
|
|
65
|
+
status = DEFAULT_CHART_STATUS,
|
|
66
|
+
loadingLabel,
|
|
67
|
+
yDomainTweenDuration = DEFAULT_Y_DOMAIN_TWEEN_MS,
|
|
68
|
+
yDomainTween = true,
|
|
69
|
+
xDomain,
|
|
70
|
+
xDomainSlotCount,
|
|
71
|
+
tweenYDomainOnXDomainChange = false,
|
|
72
|
+
style,
|
|
73
|
+
onPhaseChange,
|
|
74
|
+
children,
|
|
75
|
+
onPointClick
|
|
76
|
+
}) {
|
|
77
|
+
const { data } = useChartDataOverride("AreaChart", {
|
|
78
|
+
data: dataProp
|
|
79
|
+
});
|
|
80
|
+
const containerRef = useRef(null);
|
|
81
|
+
const margin = useStableMargin({ ...DEFAULT_MARGIN, ...marginProp });
|
|
82
|
+
const lines = useMemo(() => extractAreaConfigs(children), [children]);
|
|
83
|
+
const [chartPhase, setChartPhase] = useState(
|
|
84
|
+
() => resolveRestingChartPhase(status)
|
|
85
|
+
);
|
|
86
|
+
const handlePhaseChange = useCallback(
|
|
87
|
+
(phase) => {
|
|
88
|
+
setChartPhase(phase);
|
|
89
|
+
onPhaseChange?.(phase);
|
|
90
|
+
},
|
|
91
|
+
[onPhaseChange]
|
|
92
|
+
);
|
|
93
|
+
const showLoadingLabel = Boolean(
|
|
94
|
+
loadingLabel?.trim() && (chartPhase === "loading" || chartPhase === "exiting" || chartPhase === "gridTweenReady" || chartPhase === "revealingLoading")
|
|
95
|
+
);
|
|
96
|
+
return /* @__PURE__ */ jsx(LazyMotion, { features: domAnimation, children: /* @__PURE__ */ jsx(InteracaoProvider, { aoClicar: onPointClick, data, selecao: void 0, children: /* @__PURE__ */ jsxs(
|
|
97
|
+
"div",
|
|
98
|
+
{
|
|
99
|
+
className: cn("relative w-full", className),
|
|
100
|
+
ref: containerRef,
|
|
101
|
+
style: { aspectRatio, touchAction: "none", ...style },
|
|
102
|
+
children: [
|
|
103
|
+
/* @__PURE__ */ jsx(ParentSize, { debounceTime: 10, children: ({ width, height }) => timeSeriesChartHasRoom(width, height) ? /* @__PURE__ */ jsxs(
|
|
104
|
+
TimeSeriesChartInner,
|
|
105
|
+
{
|
|
106
|
+
animationDuration,
|
|
107
|
+
animationEasing,
|
|
108
|
+
chartStatus: status,
|
|
109
|
+
clipPathId: "chart-area-grow-clip",
|
|
110
|
+
containerRef,
|
|
111
|
+
data,
|
|
112
|
+
enterTransition,
|
|
113
|
+
height,
|
|
114
|
+
lines,
|
|
115
|
+
loadingLabel,
|
|
116
|
+
margin,
|
|
117
|
+
onPhaseChange: handlePhaseChange,
|
|
118
|
+
revealSignature,
|
|
119
|
+
tweenYDomainOnXDomainChange,
|
|
120
|
+
width,
|
|
121
|
+
xDataKey,
|
|
122
|
+
xDomain,
|
|
123
|
+
xDomainSlotCount,
|
|
124
|
+
yDomainTween,
|
|
125
|
+
yDomainTweenDuration,
|
|
126
|
+
children: [
|
|
127
|
+
children,
|
|
128
|
+
/* @__PURE__ */ jsx(AreaValueLabels, { series: lines })
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
) : null }),
|
|
132
|
+
showLoadingLabel ? /* @__PURE__ */ jsx(
|
|
133
|
+
ChartLoadingLabel,
|
|
134
|
+
{
|
|
135
|
+
exiting: chartPhase !== "loading",
|
|
136
|
+
text: loadingLabel
|
|
137
|
+
}
|
|
138
|
+
) : null
|
|
139
|
+
]
|
|
140
|
+
}
|
|
141
|
+
) }) });
|
|
142
|
+
}
|
|
143
|
+
import { Area as Area2 } from "./area";
|
|
144
|
+
var area_chart_default = AreaChart;
|
|
145
|
+
export {
|
|
146
|
+
Area2 as Area,
|
|
147
|
+
AreaChart,
|
|
148
|
+
area_chart_default as default
|
|
149
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { memo } from "react";
|
|
3
|
+
import {
|
|
4
|
+
areaVerticalFadeStops,
|
|
5
|
+
fadeGradientStops,
|
|
6
|
+
resolveFadeSides,
|
|
7
|
+
viewportFadeGradientAttrs
|
|
8
|
+
} from "./fade-edges";
|
|
9
|
+
const AreaGradientDefs = memo(function AreaGradientDefs2({
|
|
10
|
+
gradientId,
|
|
11
|
+
strokeGradientId,
|
|
12
|
+
edgeMaskId,
|
|
13
|
+
edgeGradientId,
|
|
14
|
+
fill,
|
|
15
|
+
fillOpacity,
|
|
16
|
+
gradientToOpacity,
|
|
17
|
+
gradientSpan = 1,
|
|
18
|
+
resolvedStroke,
|
|
19
|
+
isPatternFill,
|
|
20
|
+
fadeEdges,
|
|
21
|
+
fadeBottom,
|
|
22
|
+
innerWidth,
|
|
23
|
+
innerHeight
|
|
24
|
+
}) {
|
|
25
|
+
const sides = resolveFadeSides(fadeEdges);
|
|
26
|
+
const strokeStops = sides.any ? fadeGradientStops(sides) : null;
|
|
27
|
+
const showEdgeMask = sides.any && !isPatternFill;
|
|
28
|
+
const edgeStops = showEdgeMask ? fadeGradientStops(sides) : null;
|
|
29
|
+
const verticalStops = areaVerticalFadeStops({
|
|
30
|
+
topOpacity: fillOpacity,
|
|
31
|
+
fadeBottom,
|
|
32
|
+
gradientToOpacity,
|
|
33
|
+
gradientSpan
|
|
34
|
+
});
|
|
35
|
+
return /* @__PURE__ */ jsxs("defs", { children: [
|
|
36
|
+
isPatternFill ? null : /* @__PURE__ */ jsx("linearGradient", { id: gradientId, x1: "0%", x2: "0%", y1: "0%", y2: "100%", children: verticalStops.map((stop) => /* @__PURE__ */ jsx(
|
|
37
|
+
"stop",
|
|
38
|
+
{
|
|
39
|
+
offset: stop.offset,
|
|
40
|
+
style: { stopColor: fill, stopOpacity: stop.opacity }
|
|
41
|
+
},
|
|
42
|
+
stop.offset
|
|
43
|
+
)) }),
|
|
44
|
+
strokeStops ? /* @__PURE__ */ jsx(
|
|
45
|
+
"linearGradient",
|
|
46
|
+
{
|
|
47
|
+
id: strokeGradientId,
|
|
48
|
+
...viewportFadeGradientAttrs(innerWidth),
|
|
49
|
+
children: strokeStops.map((stop) => /* @__PURE__ */ jsx(
|
|
50
|
+
"stop",
|
|
51
|
+
{
|
|
52
|
+
offset: stop.offset,
|
|
53
|
+
style: { stopColor: resolvedStroke, stopOpacity: stop.opacity }
|
|
54
|
+
},
|
|
55
|
+
stop.offset
|
|
56
|
+
))
|
|
57
|
+
}
|
|
58
|
+
) : null,
|
|
59
|
+
edgeStops ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
60
|
+
/* @__PURE__ */ jsx(
|
|
61
|
+
"linearGradient",
|
|
62
|
+
{
|
|
63
|
+
id: edgeGradientId,
|
|
64
|
+
...viewportFadeGradientAttrs(innerWidth),
|
|
65
|
+
children: edgeStops.map((stop) => /* @__PURE__ */ jsx(
|
|
66
|
+
"stop",
|
|
67
|
+
{
|
|
68
|
+
offset: stop.offset,
|
|
69
|
+
style: { stopColor: "white", stopOpacity: stop.opacity }
|
|
70
|
+
},
|
|
71
|
+
stop.offset
|
|
72
|
+
))
|
|
73
|
+
}
|
|
74
|
+
),
|
|
75
|
+
/* @__PURE__ */ jsx("mask", { id: edgeMaskId, children: /* @__PURE__ */ jsx(
|
|
76
|
+
"rect",
|
|
77
|
+
{
|
|
78
|
+
fill: `url(#${edgeGradientId})`,
|
|
79
|
+
height: innerHeight,
|
|
80
|
+
width: innerWidth,
|
|
81
|
+
x: "0",
|
|
82
|
+
y: "0"
|
|
83
|
+
}
|
|
84
|
+
) })
|
|
85
|
+
] }) : null
|
|
86
|
+
] });
|
|
87
|
+
});
|
|
88
|
+
export {
|
|
89
|
+
AreaGradientDefs
|
|
90
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
function layoutAreaValueLabels(boxes, width, height) {
|
|
2
|
+
const placed = [];
|
|
3
|
+
const padding = 4;
|
|
4
|
+
const gap = 6;
|
|
5
|
+
const visible = boxes.map((box, source) => ({ ...box, source })).filter(
|
|
6
|
+
(box) => [box.index, box.x, box.y, box.width, box.height].every(
|
|
7
|
+
Number.isFinite
|
|
8
|
+
) && box.x >= 0 && box.x <= width && box.y >= 0 && box.y <= height && box.width > 0 && box.height > 0 && box.width + padding * 2 <= width && box.height + padding * 2 <= height
|
|
9
|
+
);
|
|
10
|
+
const first = Math.min(...visible.map((box) => box.index));
|
|
11
|
+
const last = Math.max(...visible.map((box) => box.index));
|
|
12
|
+
const edge = (index) => index === first || index === last ? 0 : 1;
|
|
13
|
+
visible.sort(
|
|
14
|
+
(a, b) => edge(a.index) - edge(b.index) || a.x - b.x || a.y - b.y
|
|
15
|
+
);
|
|
16
|
+
for (const box of visible) {
|
|
17
|
+
const x = Math.max(
|
|
18
|
+
padding + box.width / 2,
|
|
19
|
+
Math.min(width - padding - box.width / 2, box.x)
|
|
20
|
+
);
|
|
21
|
+
const offset = box.height / 2 + gap;
|
|
22
|
+
for (const y of [box.y - offset, box.y + offset]) {
|
|
23
|
+
if (y - box.height / 2 < padding || y + box.height / 2 > height - padding) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const collision = placed.some(
|
|
27
|
+
(other) => Math.abs(x - other.x) < (box.width + other.width) / 2 + gap && Math.abs(y - other.y) < (box.height + other.height) / 2 + gap
|
|
28
|
+
);
|
|
29
|
+
if (collision) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
placed.push({ ...box, x, y });
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return placed;
|
|
37
|
+
}
|
|
38
|
+
function resolveAreaValueLabelCount(length, width, min = 2, max) {
|
|
39
|
+
const minimum = Number.isFinite(min) ? Math.max(0, Math.floor(min)) : 2;
|
|
40
|
+
const maximum = max != null && Number.isFinite(max) ? Math.max(0, Math.floor(max)) : length;
|
|
41
|
+
return Math.min(
|
|
42
|
+
length,
|
|
43
|
+
maximum,
|
|
44
|
+
Math.max(minimum, Math.floor(Math.max(0, width) / 48))
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
function resolveSharedAreaValueLabelCount(counts) {
|
|
48
|
+
const enabledCounts = counts.filter((count) => count > 0);
|
|
49
|
+
return enabledCounts.length ? Math.min(...enabledCounts) : 0;
|
|
50
|
+
}
|
|
51
|
+
function evenlySpacedLabelIndices(length, count) {
|
|
52
|
+
const visibleCount = Math.min(Math.max(0, Math.floor(count)), length);
|
|
53
|
+
if (visibleCount === 0) {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
if (visibleCount === 1) {
|
|
57
|
+
return [0];
|
|
58
|
+
}
|
|
59
|
+
const lastIndex = length - 1;
|
|
60
|
+
return Array.from(
|
|
61
|
+
{ length: visibleCount },
|
|
62
|
+
(_, index) => Math.round(index * lastIndex / (visibleCount - 1))
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
evenlySpacedLabelIndices,
|
|
67
|
+
layoutAreaValueLabels,
|
|
68
|
+
resolveAreaValueLabelCount,
|
|
69
|
+
resolveSharedAreaValueLabelCount
|
|
70
|
+
};
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId, useLayoutEffect, useMemo, useRef } from "react";
|
|
4
|
+
import {
|
|
5
|
+
evenlySpacedLabelIndices,
|
|
6
|
+
layoutAreaValueLabels,
|
|
7
|
+
resolveAreaValueLabelCount,
|
|
8
|
+
resolveSharedAreaValueLabelCount
|
|
9
|
+
} from "./area-value-label-layout";
|
|
10
|
+
import { chartCssVars, useChartStable } from "./chart-context";
|
|
11
|
+
import { valueLabelFmt } from "./chart-formatters";
|
|
12
|
+
import {
|
|
13
|
+
fadeGradientStops,
|
|
14
|
+
resolveFadeSides,
|
|
15
|
+
viewportFadeGradientAttrs
|
|
16
|
+
} from "./fade-edges";
|
|
17
|
+
function AreaValueLabels({ series }) {
|
|
18
|
+
const {
|
|
19
|
+
data,
|
|
20
|
+
xScale,
|
|
21
|
+
xAccessor,
|
|
22
|
+
yScale,
|
|
23
|
+
yScales,
|
|
24
|
+
innerWidth,
|
|
25
|
+
innerHeight,
|
|
26
|
+
chartPhase
|
|
27
|
+
} = useChartStable();
|
|
28
|
+
const layerRef = useRef(null);
|
|
29
|
+
const id = useId();
|
|
30
|
+
const labels = useMemo(() => {
|
|
31
|
+
if (!["revealing", "ready", "exitingReady"].includes(chartPhase)) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
const visible = data.map((datum, index) => ({ datum, index, x: xScale(xAccessor(datum)) })).filter(({ x }) => Number.isFinite(x) && x >= 0 && x <= innerWidth);
|
|
35
|
+
const visibleSeries = series.map((area, seriesIndex) => ({
|
|
36
|
+
area,
|
|
37
|
+
seriesIndex,
|
|
38
|
+
points: visible.filter(
|
|
39
|
+
({ datum }) => typeof datum[area.dataKey] === "number" && Number.isFinite(datum[area.dataKey])
|
|
40
|
+
)
|
|
41
|
+
})).filter(({ area }) => area.showValue);
|
|
42
|
+
const counts = visibleSeries.map(
|
|
43
|
+
({ area, points }) => resolveAreaValueLabelCount(
|
|
44
|
+
points.length,
|
|
45
|
+
innerWidth,
|
|
46
|
+
area.valueLabelMinCount,
|
|
47
|
+
area.valueLabelMaxCount
|
|
48
|
+
)
|
|
49
|
+
);
|
|
50
|
+
const sharedCount = resolveSharedAreaValueLabelCount(counts);
|
|
51
|
+
return visibleSeries.flatMap(({ area, seriesIndex, points }, i) => {
|
|
52
|
+
const count = Math.min(sharedCount, counts[i] ?? 0);
|
|
53
|
+
if (count === 0) {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
const indices = evenlySpacedLabelIndices(points.length, count);
|
|
57
|
+
return indices.flatMap((position) => {
|
|
58
|
+
const point = position == null ? void 0 : points[position];
|
|
59
|
+
if (!point) {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
const { datum, index, x } = point;
|
|
63
|
+
const value = datum[area.dataKey];
|
|
64
|
+
const scale = yScales[String(area.yAxisId ?? "left")] ?? yScale;
|
|
65
|
+
const y = scale(value);
|
|
66
|
+
if (!Number.isFinite(y)) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
index,
|
|
72
|
+
seriesIndex,
|
|
73
|
+
x,
|
|
74
|
+
y,
|
|
75
|
+
text: area.valueLabelFormatter?.(value) ?? valueLabelFmt(value)
|
|
76
|
+
}
|
|
77
|
+
];
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}, [
|
|
81
|
+
data,
|
|
82
|
+
series,
|
|
83
|
+
xScale,
|
|
84
|
+
xAccessor,
|
|
85
|
+
yScale,
|
|
86
|
+
yScales,
|
|
87
|
+
innerWidth,
|
|
88
|
+
chartPhase
|
|
89
|
+
]);
|
|
90
|
+
useLayoutEffect(() => {
|
|
91
|
+
const layer = layerRef.current;
|
|
92
|
+
if (!layer) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
let active = true;
|
|
96
|
+
const arrange = () => {
|
|
97
|
+
if (!active) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const elements = Array.from(layer.querySelectorAll("text"));
|
|
101
|
+
const boxes = labels.map((label, index) => {
|
|
102
|
+
const bounds = elements[index]?.getBBox();
|
|
103
|
+
return {
|
|
104
|
+
...label,
|
|
105
|
+
width: bounds?.width ?? 0,
|
|
106
|
+
height: bounds?.height ?? 0
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
for (const element of elements) {
|
|
110
|
+
element.style.visibility = "hidden";
|
|
111
|
+
}
|
|
112
|
+
for (const box of layoutAreaValueLabels(boxes, innerWidth, innerHeight)) {
|
|
113
|
+
const element = elements[box.source];
|
|
114
|
+
if (!element) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const bounds = element.getBBox();
|
|
118
|
+
element.setAttribute(
|
|
119
|
+
"transform",
|
|
120
|
+
`translate(${box.x - bounds.x - bounds.width / 2}, ${box.y - bounds.y - bounds.height / 2})`
|
|
121
|
+
);
|
|
122
|
+
element.style.visibility = "visible";
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
arrange();
|
|
126
|
+
document.fonts.ready.then(arrange);
|
|
127
|
+
document.fonts.addEventListener("loadingdone", arrange);
|
|
128
|
+
return () => {
|
|
129
|
+
active = false;
|
|
130
|
+
document.fonts.removeEventListener("loadingdone", arrange);
|
|
131
|
+
};
|
|
132
|
+
}, [labels, innerWidth, innerHeight]);
|
|
133
|
+
if (!series.some((area) => area.showValue)) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
return /* @__PURE__ */ jsxs("g", { pointerEvents: "none", ref: layerRef, children: [
|
|
137
|
+
/* @__PURE__ */ jsx("defs", { children: series.map(
|
|
138
|
+
(area, index) => area.fadeValueLabels && /* @__PURE__ */ jsxs("g", { children: [
|
|
139
|
+
/* @__PURE__ */ jsx(
|
|
140
|
+
"linearGradient",
|
|
141
|
+
{
|
|
142
|
+
id: `${id}-${index}`,
|
|
143
|
+
...viewportFadeGradientAttrs(innerWidth),
|
|
144
|
+
children: fadeGradientStops(
|
|
145
|
+
resolveFadeSides(area.fadeEdges ?? false)
|
|
146
|
+
).map((stop) => /* @__PURE__ */ jsx(
|
|
147
|
+
"stop",
|
|
148
|
+
{
|
|
149
|
+
offset: stop.offset,
|
|
150
|
+
stopColor: "white",
|
|
151
|
+
stopOpacity: stop.opacity
|
|
152
|
+
},
|
|
153
|
+
stop.offset
|
|
154
|
+
))
|
|
155
|
+
}
|
|
156
|
+
),
|
|
157
|
+
/* @__PURE__ */ jsx(
|
|
158
|
+
"mask",
|
|
159
|
+
{
|
|
160
|
+
height: innerHeight,
|
|
161
|
+
id: `${id}-${index}-mask`,
|
|
162
|
+
maskUnits: "userSpaceOnUse",
|
|
163
|
+
width: innerWidth,
|
|
164
|
+
x: 0,
|
|
165
|
+
y: 0,
|
|
166
|
+
children: /* @__PURE__ */ jsx(
|
|
167
|
+
"rect",
|
|
168
|
+
{
|
|
169
|
+
fill: `url(#${id}-${index})`,
|
|
170
|
+
height: innerHeight,
|
|
171
|
+
width: innerWidth
|
|
172
|
+
}
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
)
|
|
176
|
+
] }, area.dataKey)
|
|
177
|
+
) }),
|
|
178
|
+
labels.map((label) => {
|
|
179
|
+
const area = series[label.seriesIndex];
|
|
180
|
+
if (!area) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
return /* @__PURE__ */ jsx(
|
|
184
|
+
"g",
|
|
185
|
+
{
|
|
186
|
+
mask: area.fadeValueLabels ? `url(#${id}-${label.seriesIndex}-mask)` : void 0,
|
|
187
|
+
children: /* @__PURE__ */ jsx(
|
|
188
|
+
"text",
|
|
189
|
+
{
|
|
190
|
+
className: "font-medium text-[10px]",
|
|
191
|
+
fill: area.valueLabelColor ?? area.stroke ?? (area.fill?.startsWith("url(") ? void 0 : area.fill) ?? chartCssVars.linePrimary,
|
|
192
|
+
style: {
|
|
193
|
+
visibility: "hidden",
|
|
194
|
+
paintOrder: "stroke",
|
|
195
|
+
stroke: "var(--chart-background)",
|
|
196
|
+
strokeWidth: 3
|
|
197
|
+
},
|
|
198
|
+
x: 0,
|
|
199
|
+
y: 0,
|
|
200
|
+
children: label.text
|
|
201
|
+
}
|
|
202
|
+
)
|
|
203
|
+
},
|
|
204
|
+
`${label.seriesIndex}-${label.index}`
|
|
205
|
+
);
|
|
206
|
+
})
|
|
207
|
+
] });
|
|
208
|
+
}
|
|
209
|
+
export {
|
|
210
|
+
AreaValueLabels
|
|
211
|
+
};
|