@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,233 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
AnimatePresence,
|
|
5
|
+
m,
|
|
6
|
+
useReducedMotion
|
|
7
|
+
} from "motion/react";
|
|
8
|
+
import { memo, useEffect, useMemo, useRef, useState } from "react";
|
|
9
|
+
import { createPortal } from "react-dom";
|
|
10
|
+
import {
|
|
11
|
+
useChartPortalContainer,
|
|
12
|
+
useChartStable,
|
|
13
|
+
useSettledYScale,
|
|
14
|
+
useYScale
|
|
15
|
+
} from "./chart-context";
|
|
16
|
+
import { crosshairTickOpacity, subscribeCrosshair } from "./crosshair-store";
|
|
17
|
+
import { resolveReferenceDataRange } from "./reference-area-geometry";
|
|
18
|
+
import { normalizeYAxisId } from "./y-axis-scales";
|
|
19
|
+
import {
|
|
20
|
+
resolveYAxisTickCount,
|
|
21
|
+
Y_AXIS_DEFAULT_TICK_COUNT
|
|
22
|
+
} from "./y-axis-ticks";
|
|
23
|
+
const CROSSHAIR_PILL_HALF_HEIGHT = 16;
|
|
24
|
+
const Y_AXIS_LABEL_SHIFT_PX = 8;
|
|
25
|
+
const Y_AXIS_LABEL_EASE_OUT = [0.23, 1, 0.32, 1];
|
|
26
|
+
const Y_AXIS_LABEL_ENTER_S = 0.4;
|
|
27
|
+
const Y_AXIS_LABEL_EXIT_S = 0.25;
|
|
28
|
+
const Y_AXIS_LABEL_CLIP_BLEED_PX = 12;
|
|
29
|
+
const Y_AXIS_LABEL_STAGGER_S = 0.05;
|
|
30
|
+
const labelVariants = {
|
|
31
|
+
hidden: ({ drift }) => ({
|
|
32
|
+
opacity: 0,
|
|
33
|
+
y: -drift * Y_AXIS_LABEL_SHIFT_PX
|
|
34
|
+
}),
|
|
35
|
+
visible: { opacity: 1, y: 0 },
|
|
36
|
+
exit: ({ drift, reducedMotion }) => ({
|
|
37
|
+
opacity: 0,
|
|
38
|
+
y: drift * Y_AXIS_LABEL_SHIFT_PX,
|
|
39
|
+
transition: {
|
|
40
|
+
duration: reducedMotion ? 0 : Y_AXIS_LABEL_EXIT_S,
|
|
41
|
+
ease: Y_AXIS_LABEL_EASE_OUT
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
function formatLabel(value, formatLargeNumbers, formatValue) {
|
|
46
|
+
if (formatValue) {
|
|
47
|
+
return formatValue(value);
|
|
48
|
+
}
|
|
49
|
+
if (formatLargeNumbers && value >= 1e3) {
|
|
50
|
+
return `${(value / 1e3).toLocaleString("pt-BR", { maximumFractionDigits: 1 })} mil`;
|
|
51
|
+
}
|
|
52
|
+
return String(value);
|
|
53
|
+
}
|
|
54
|
+
function resolveTickLabelColor(tickY, axisId, yScale, referenceAreas) {
|
|
55
|
+
for (const area of referenceAreas) {
|
|
56
|
+
if (!area.axisLabelColor) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (normalizeYAxisId(area.yAxisId) !== axisId) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const [low, high] = resolveReferenceDataRange(
|
|
63
|
+
area.y1,
|
|
64
|
+
area.y2,
|
|
65
|
+
yScale.domain()
|
|
66
|
+
);
|
|
67
|
+
const topPixel = yScale(high) ?? 0;
|
|
68
|
+
const bottomPixel = yScale(low) ?? 0;
|
|
69
|
+
const bandTop = Math.min(topPixel, bottomPixel);
|
|
70
|
+
const bandBottom = Math.max(topPixel, bottomPixel);
|
|
71
|
+
if (tickY >= bandTop && tickY <= bandBottom) {
|
|
72
|
+
return area.axisLabelColor;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return void 0;
|
|
76
|
+
}
|
|
77
|
+
function YAxis(props) {
|
|
78
|
+
const { containerRef } = useChartStable();
|
|
79
|
+
const container = useChartPortalContainer(containerRef);
|
|
80
|
+
if (!container) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return /* @__PURE__ */ jsx(YAxisInner, { ...props, container });
|
|
84
|
+
}
|
|
85
|
+
const YAxisInner = memo(function YAxisInner2({
|
|
86
|
+
yAxisId,
|
|
87
|
+
orientation = "left",
|
|
88
|
+
numTicks = Y_AXIS_DEFAULT_TICK_COUNT,
|
|
89
|
+
formatLargeNumbers = true,
|
|
90
|
+
formatValue,
|
|
91
|
+
container
|
|
92
|
+
}) {
|
|
93
|
+
const { margin, referenceAreas } = useChartStable();
|
|
94
|
+
const yScale = useYScale(yAxisId);
|
|
95
|
+
const settledYScale = useSettledYScale(yAxisId);
|
|
96
|
+
const reducedMotion = useReducedMotion() ?? false;
|
|
97
|
+
const isLeft = orientation === "left";
|
|
98
|
+
const axisId = normalizeYAxisId(yAxisId);
|
|
99
|
+
const [settledMin, settledMax] = settledYScale.domain();
|
|
100
|
+
const settledSpan = settledMax - settledMin;
|
|
101
|
+
const [prevSettledSpan, setPrevSettledSpan] = useState(settledSpan);
|
|
102
|
+
const [drift, setDrift] = useState(-1);
|
|
103
|
+
if (settledSpan !== prevSettledSpan) {
|
|
104
|
+
setPrevSettledSpan(settledSpan);
|
|
105
|
+
setDrift(settledSpan < prevSettledSpan ? -1 : 1);
|
|
106
|
+
}
|
|
107
|
+
const tickValues = useMemo(
|
|
108
|
+
() => settledYScale.ticks(resolveYAxisTickCount(numTicks)),
|
|
109
|
+
[settledYScale, numTicks]
|
|
110
|
+
);
|
|
111
|
+
const ticks = useMemo(() => {
|
|
112
|
+
return tickValues.map((value) => {
|
|
113
|
+
const y = (yScale(value) ?? 0) + margin.top;
|
|
114
|
+
return {
|
|
115
|
+
value,
|
|
116
|
+
y,
|
|
117
|
+
label: formatLabel(value, formatLargeNumbers, formatValue),
|
|
118
|
+
labelColor: resolveTickLabelColor(
|
|
119
|
+
y - margin.top,
|
|
120
|
+
axisId,
|
|
121
|
+
yScale,
|
|
122
|
+
referenceAreas
|
|
123
|
+
)
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
}, [
|
|
127
|
+
tickValues,
|
|
128
|
+
yScale,
|
|
129
|
+
margin.top,
|
|
130
|
+
formatLargeNumbers,
|
|
131
|
+
formatValue,
|
|
132
|
+
axisId,
|
|
133
|
+
referenceAreas
|
|
134
|
+
]);
|
|
135
|
+
return createPortal(
|
|
136
|
+
/* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-0", children: /* @__PURE__ */ jsx(
|
|
137
|
+
"div",
|
|
138
|
+
{
|
|
139
|
+
className: "absolute overflow-hidden",
|
|
140
|
+
style: {
|
|
141
|
+
// Clip labels tweening in from far off-scale, with room for a
|
|
142
|
+
// half-height edge label when the chart margin is tight.
|
|
143
|
+
top: -Y_AXIS_LABEL_CLIP_BLEED_PX,
|
|
144
|
+
bottom: -Y_AXIS_LABEL_CLIP_BLEED_PX,
|
|
145
|
+
...isLeft ? { left: 0, width: margin.left } : { right: 0, width: margin.right }
|
|
146
|
+
},
|
|
147
|
+
children: /* @__PURE__ */ jsx(
|
|
148
|
+
AnimatePresence,
|
|
149
|
+
{
|
|
150
|
+
custom: { drift, reducedMotion },
|
|
151
|
+
initial: false,
|
|
152
|
+
children: ticks.map((tick, index) => {
|
|
153
|
+
const cascadeIndex = drift < 0 ? index : ticks.length - 1 - index;
|
|
154
|
+
return /* @__PURE__ */ jsx(
|
|
155
|
+
m.div,
|
|
156
|
+
{
|
|
157
|
+
animate: "visible",
|
|
158
|
+
className: "absolute flex h-0 items-center",
|
|
159
|
+
custom: { drift, reducedMotion },
|
|
160
|
+
exit: "exit",
|
|
161
|
+
initial: "hidden",
|
|
162
|
+
style: {
|
|
163
|
+
top: tick.y + Y_AXIS_LABEL_CLIP_BLEED_PX,
|
|
164
|
+
...isLeft ? { right: 0, justifyContent: "flex-end", paddingRight: 8 } : {
|
|
165
|
+
left: 0,
|
|
166
|
+
justifyContent: "flex-start",
|
|
167
|
+
paddingLeft: 8
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
transition: reducedMotion ? { duration: 0 } : {
|
|
171
|
+
delay: cascadeIndex * Y_AXIS_LABEL_STAGGER_S,
|
|
172
|
+
duration: Y_AXIS_LABEL_ENTER_S,
|
|
173
|
+
ease: Y_AXIS_LABEL_EASE_OUT
|
|
174
|
+
},
|
|
175
|
+
variants: labelVariants,
|
|
176
|
+
children: /* @__PURE__ */ jsx(
|
|
177
|
+
YAxisTickLabel,
|
|
178
|
+
{
|
|
179
|
+
axisId,
|
|
180
|
+
color: tick.labelColor,
|
|
181
|
+
container,
|
|
182
|
+
label: tick.label,
|
|
183
|
+
plotY: tick.y - margin.top
|
|
184
|
+
}
|
|
185
|
+
)
|
|
186
|
+
},
|
|
187
|
+
tick.value
|
|
188
|
+
);
|
|
189
|
+
})
|
|
190
|
+
}
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
) }),
|
|
194
|
+
container
|
|
195
|
+
);
|
|
196
|
+
});
|
|
197
|
+
YAxis.displayName = "YAxis";
|
|
198
|
+
function YAxisTickLabel({
|
|
199
|
+
label,
|
|
200
|
+
color,
|
|
201
|
+
container,
|
|
202
|
+
axisId,
|
|
203
|
+
plotY
|
|
204
|
+
}) {
|
|
205
|
+
const ref = useRef(null);
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
let current = 1;
|
|
208
|
+
return subscribeCrosshair(container, (state) => {
|
|
209
|
+
const next = crosshairTickOpacity(
|
|
210
|
+
state,
|
|
211
|
+
axisId,
|
|
212
|
+
plotY,
|
|
213
|
+
CROSSHAIR_PILL_HALF_HEIGHT
|
|
214
|
+
);
|
|
215
|
+
if (next !== current && ref.current) {
|
|
216
|
+
current = next;
|
|
217
|
+
ref.current.style.opacity = String(next);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}, [container, axisId, plotY]);
|
|
221
|
+
return /* @__PURE__ */ jsx(
|
|
222
|
+
"span",
|
|
223
|
+
{
|
|
224
|
+
className: "whitespace-nowrap text-chart-label text-xs",
|
|
225
|
+
ref,
|
|
226
|
+
style: { color, transition: "opacity 0.4s ease-in-out" },
|
|
227
|
+
children: label
|
|
228
|
+
}
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
export {
|
|
232
|
+
YAxis
|
|
233
|
+
};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { scaleLinear } from "d3-scale";
|
|
2
|
+
import { Y_DOMAIN_TWEEN_SKIP_THRESHOLD } from "./chart-phase";
|
|
3
|
+
import { groupLinesByYAxisId, normalizeYAxisId } from "./y-axis-scales";
|
|
4
|
+
function applyYDomainOverride(auto, override) {
|
|
5
|
+
if (!override) {
|
|
6
|
+
return auto;
|
|
7
|
+
}
|
|
8
|
+
return typeof override === "function" ? override(auto) : override;
|
|
9
|
+
}
|
|
10
|
+
function collectNumericExtents(data, dataKeys) {
|
|
11
|
+
let minValue = Number.POSITIVE_INFINITY;
|
|
12
|
+
let maxValue = Number.NEGATIVE_INFINITY;
|
|
13
|
+
for (const d of data) {
|
|
14
|
+
for (const key of dataKeys) {
|
|
15
|
+
const value = d[key];
|
|
16
|
+
if (typeof value === "number") {
|
|
17
|
+
if (value < minValue) {
|
|
18
|
+
minValue = value;
|
|
19
|
+
}
|
|
20
|
+
if (value > maxValue) {
|
|
21
|
+
maxValue = value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (minValue === Number.POSITIVE_INFINITY) {
|
|
27
|
+
return { minValue: 0, maxValue: 100 };
|
|
28
|
+
}
|
|
29
|
+
return { minValue, maxValue };
|
|
30
|
+
}
|
|
31
|
+
function resolveTimeSeriesYDomain(data, dataKeys, yScaleDomainMax) {
|
|
32
|
+
if (yScaleDomainMax != null && yScaleDomainMax > 0) {
|
|
33
|
+
return [0, yScaleDomainMax * 1.1];
|
|
34
|
+
}
|
|
35
|
+
const { minValue, maxValue } = collectNumericExtents(data, dataKeys);
|
|
36
|
+
if (minValue >= 0) {
|
|
37
|
+
const top = maxValue <= 0 ? 100 : maxValue * 1.1;
|
|
38
|
+
return [0, top];
|
|
39
|
+
}
|
|
40
|
+
const padding = (maxValue - minValue) * 0.05 || 1;
|
|
41
|
+
return [minValue - padding, maxValue + padding];
|
|
42
|
+
}
|
|
43
|
+
function resolveFloatingYDomain(data, dataKeys) {
|
|
44
|
+
const { minValue, maxValue } = collectNumericExtents(data, dataKeys);
|
|
45
|
+
const padding = (maxValue - minValue) * 0.05 || 1;
|
|
46
|
+
return [minValue - padding, maxValue + padding];
|
|
47
|
+
}
|
|
48
|
+
function collectBarValueExtents(data, dataKeys, stacked) {
|
|
49
|
+
if (!stacked) {
|
|
50
|
+
return collectNumericExtents(data, dataKeys);
|
|
51
|
+
}
|
|
52
|
+
let minValue = 0;
|
|
53
|
+
let maxValue = 0;
|
|
54
|
+
for (const d of data) {
|
|
55
|
+
let sum = 0;
|
|
56
|
+
for (const key of dataKeys) {
|
|
57
|
+
const value = d[key];
|
|
58
|
+
if (typeof value === "number") {
|
|
59
|
+
sum += value;
|
|
60
|
+
minValue = Math.min(minValue, sum);
|
|
61
|
+
maxValue = Math.max(maxValue, sum);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return { minValue, maxValue };
|
|
66
|
+
}
|
|
67
|
+
function resolveBarValueDomain({
|
|
68
|
+
minValue,
|
|
69
|
+
maxValue
|
|
70
|
+
}) {
|
|
71
|
+
if (minValue >= 0) {
|
|
72
|
+
return [0, (maxValue > 0 ? maxValue : 100) * 1.1];
|
|
73
|
+
}
|
|
74
|
+
const padding = (maxValue - minValue) * 0.05 || 1;
|
|
75
|
+
return [Math.min(0, minValue - padding), Math.max(0, maxValue + padding)];
|
|
76
|
+
}
|
|
77
|
+
function niceYDomain(domain) {
|
|
78
|
+
const scale = scaleLinear().domain(domain).nice().range([0, 1]);
|
|
79
|
+
const niceDomain = scale.domain();
|
|
80
|
+
return [niceDomain[0] ?? domain[0], niceDomain[1] ?? domain[1]];
|
|
81
|
+
}
|
|
82
|
+
function shouldTweenYDomain(from, to) {
|
|
83
|
+
const span = Math.max(
|
|
84
|
+
Math.abs(to[1] - to[0]),
|
|
85
|
+
Math.abs(from[1] - from[0]),
|
|
86
|
+
1
|
|
87
|
+
);
|
|
88
|
+
const deltaMin = Math.abs(to[0] - from[0]) / span;
|
|
89
|
+
const deltaMax = Math.abs(to[1] - from[1]) / span;
|
|
90
|
+
return deltaMin >= Y_DOMAIN_TWEEN_SKIP_THRESHOLD || deltaMax >= Y_DOMAIN_TWEEN_SKIP_THRESHOLD;
|
|
91
|
+
}
|
|
92
|
+
function isLoadingChromePhase(phase) {
|
|
93
|
+
return phase === "loading" || phase === "revealingLoading";
|
|
94
|
+
}
|
|
95
|
+
function isLoadingGridChromePhase(phase) {
|
|
96
|
+
return phase === "loading" || phase === "exiting" || phase === "gridTweenLoading";
|
|
97
|
+
}
|
|
98
|
+
function isYDomainTweenPhase(phase) {
|
|
99
|
+
return phase === "gridTweenLoading" || phase === "gridTweenReady";
|
|
100
|
+
}
|
|
101
|
+
function isReferenceAreaVisiblePhase(phase) {
|
|
102
|
+
return phase === "ready" || phase === "revealing" || phase === "gridTweenReady";
|
|
103
|
+
}
|
|
104
|
+
function resolveAnimatedYDestinationDomains(chartPhase, skeletonByAxis, targetByAxis) {
|
|
105
|
+
switch (chartPhase) {
|
|
106
|
+
case "loading":
|
|
107
|
+
case "exiting":
|
|
108
|
+
case "gridTweenLoading":
|
|
109
|
+
return skeletonByAxis;
|
|
110
|
+
case "exitingReady":
|
|
111
|
+
case "gridTweenReady":
|
|
112
|
+
case "revealing":
|
|
113
|
+
case "ready":
|
|
114
|
+
return targetByAxis;
|
|
115
|
+
default:
|
|
116
|
+
return targetByAxis;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function computeYDomainsByAxis({
|
|
120
|
+
lines,
|
|
121
|
+
resolveDomain,
|
|
122
|
+
extraKeysByAxis
|
|
123
|
+
}) {
|
|
124
|
+
const keysByAxis = /* @__PURE__ */ new Map();
|
|
125
|
+
for (const [axisId, axisLines] of groupLinesByYAxisId(lines)) {
|
|
126
|
+
keysByAxis.set(
|
|
127
|
+
normalizeYAxisId(axisId),
|
|
128
|
+
axisLines.map((line) => line.dataKey)
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
for (const [axisId, extraKeys] of Object.entries(extraKeysByAxis ?? {})) {
|
|
132
|
+
const id = normalizeYAxisId(axisId);
|
|
133
|
+
const keys = keysByAxis.get(id) ?? [];
|
|
134
|
+
keysByAxis.set(id, [
|
|
135
|
+
...keys,
|
|
136
|
+
...extraKeys.filter((key) => !keys.includes(key))
|
|
137
|
+
]);
|
|
138
|
+
}
|
|
139
|
+
const domains = {};
|
|
140
|
+
for (const [axisId, dataKeys] of keysByAxis) {
|
|
141
|
+
domains[axisId] = niceYDomain(resolveDomain(dataKeys, axisId));
|
|
142
|
+
}
|
|
143
|
+
if (!domains.left) {
|
|
144
|
+
domains.left = niceYDomain([0, 100]);
|
|
145
|
+
}
|
|
146
|
+
return domains;
|
|
147
|
+
}
|
|
148
|
+
function mergeYDomainRecords(...records) {
|
|
149
|
+
const merged = {};
|
|
150
|
+
for (const record of records) {
|
|
151
|
+
for (const [axisId, domain] of Object.entries(record)) {
|
|
152
|
+
merged[normalizeYAxisId(axisId)] = domain;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return merged;
|
|
156
|
+
}
|
|
157
|
+
function domainsEqual(left, right) {
|
|
158
|
+
const leftKeys = Object.keys(left);
|
|
159
|
+
const rightKeys = Object.keys(right);
|
|
160
|
+
if (leftKeys.length !== rightKeys.length) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
for (const axisId of leftKeys) {
|
|
164
|
+
const from = left[axisId];
|
|
165
|
+
const to = right[axisId];
|
|
166
|
+
if (!(from && to) || from[0] !== to[0] || from[1] !== to[1]) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
export {
|
|
173
|
+
applyYDomainOverride,
|
|
174
|
+
collectBarValueExtents,
|
|
175
|
+
collectNumericExtents,
|
|
176
|
+
computeYDomainsByAxis,
|
|
177
|
+
domainsEqual,
|
|
178
|
+
isLoadingChromePhase,
|
|
179
|
+
isLoadingGridChromePhase,
|
|
180
|
+
isReferenceAreaVisiblePhase,
|
|
181
|
+
isYDomainTweenPhase,
|
|
182
|
+
mergeYDomainRecords,
|
|
183
|
+
niceYDomain,
|
|
184
|
+
resolveAnimatedYDestinationDomains,
|
|
185
|
+
resolveBarValueDomain,
|
|
186
|
+
resolveFloatingYDomain,
|
|
187
|
+
resolveTimeSeriesYDomain,
|
|
188
|
+
shouldTweenYDomain
|
|
189
|
+
};
|