@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,467 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { m } from "motion/react";
|
|
4
|
+
import { memo, useId, useMemo } from "react";
|
|
5
|
+
import { computeSquareColumn } from "./bar-squares-layout";
|
|
6
|
+
import {
|
|
7
|
+
chartCssVars,
|
|
8
|
+
useChart,
|
|
9
|
+
useChartStable,
|
|
10
|
+
useYScale
|
|
11
|
+
} from "./chart-context";
|
|
12
|
+
import { useChartLegendHover } from "./chart-legend-hover";
|
|
13
|
+
import { transitionWithDelay } from "./motion-utils";
|
|
14
|
+
import { renderPatternPreset } from "./pattern-preset";
|
|
15
|
+
function isPatternFill(fill) {
|
|
16
|
+
return fill.startsWith("url(");
|
|
17
|
+
}
|
|
18
|
+
function squareCascadeStepSeconds(enterTransition, animationDurationMs, squareCount) {
|
|
19
|
+
if (squareCount <= 1) {
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
const durationMs = enterTransition?.type === "tween" && typeof enterTransition.duration === "number" ? enterTransition.duration * 1e3 : animationDurationMs;
|
|
23
|
+
const cascadeSpreadMs = durationMs * 0.4;
|
|
24
|
+
return cascadeSpreadMs / 1e3 / (squareCount - 1);
|
|
25
|
+
}
|
|
26
|
+
function cascadeColumnTransition(enterTransition, animationDurationMs, columnIndex, columnStaggerDelay, squareCount) {
|
|
27
|
+
const cascadeStep = squareCascadeStepSeconds(
|
|
28
|
+
enterTransition,
|
|
29
|
+
animationDurationMs,
|
|
30
|
+
squareCount
|
|
31
|
+
);
|
|
32
|
+
const base = transitionWithDelay(
|
|
33
|
+
enterTransition,
|
|
34
|
+
columnIndex * columnStaggerDelay
|
|
35
|
+
);
|
|
36
|
+
if (squareCount <= 1 || base.type !== "tween") {
|
|
37
|
+
return base;
|
|
38
|
+
}
|
|
39
|
+
const baseDuration = typeof base.duration === "number" ? base.duration : animationDurationMs / 1e3;
|
|
40
|
+
return {
|
|
41
|
+
...base,
|
|
42
|
+
duration: baseDuration + cascadeStep * (squareCount - 1)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function SquareColumn({
|
|
46
|
+
x,
|
|
47
|
+
baselineY,
|
|
48
|
+
barLengthPx,
|
|
49
|
+
squareSize,
|
|
50
|
+
squareGap,
|
|
51
|
+
squareRadius,
|
|
52
|
+
squareFit,
|
|
53
|
+
fill,
|
|
54
|
+
useGradient,
|
|
55
|
+
gradientStops,
|
|
56
|
+
patternPreset,
|
|
57
|
+
index,
|
|
58
|
+
isFaded,
|
|
59
|
+
fadedOpacity,
|
|
60
|
+
animate,
|
|
61
|
+
staggerDelay,
|
|
62
|
+
animationDuration,
|
|
63
|
+
enterTransition,
|
|
64
|
+
revealEpoch
|
|
65
|
+
}) {
|
|
66
|
+
const layout = useMemo(
|
|
67
|
+
() => computeSquareColumn({
|
|
68
|
+
barLengthPx,
|
|
69
|
+
squareSize,
|
|
70
|
+
gap: squareGap,
|
|
71
|
+
fit: squareFit
|
|
72
|
+
}),
|
|
73
|
+
[barLengthPx, squareSize, squareGap, squareFit]
|
|
74
|
+
);
|
|
75
|
+
const rx = squareSize * squareRadius;
|
|
76
|
+
const columnTop = baselineY - layout.columnHeight;
|
|
77
|
+
const gradientId = `bar-squares-gradient-${index}-${revealEpoch}`;
|
|
78
|
+
const patternFill = isPatternFill(fill);
|
|
79
|
+
const patternId = `bar-squares-pattern-${index}-${revealEpoch}`;
|
|
80
|
+
const effectiveFill = useMemo(() => {
|
|
81
|
+
if (useGradient) {
|
|
82
|
+
if (patternFill && patternPreset && patternPreset !== "none") {
|
|
83
|
+
return `url(#${patternId})`;
|
|
84
|
+
}
|
|
85
|
+
return `url(#${gradientId})`;
|
|
86
|
+
}
|
|
87
|
+
return fill;
|
|
88
|
+
}, [useGradient, patternFill, patternPreset, fill, gradientId, patternId]);
|
|
89
|
+
const cascadeStep = squareCascadeStepSeconds(
|
|
90
|
+
enterTransition,
|
|
91
|
+
animationDuration,
|
|
92
|
+
layout.count
|
|
93
|
+
);
|
|
94
|
+
const squareOpacity = isFaded ? fadedOpacity : 1;
|
|
95
|
+
const gradientPatternNode = useGradient && patternFill && patternPreset && patternPreset !== "none" ? renderPatternPreset(patternPreset, patternId, {
|
|
96
|
+
color: `url(#${gradientId})`
|
|
97
|
+
}) : null;
|
|
98
|
+
const gradientDefs = useGradient ? /* @__PURE__ */ jsxs("defs", { children: [
|
|
99
|
+
/* @__PURE__ */ jsx(
|
|
100
|
+
"linearGradient",
|
|
101
|
+
{
|
|
102
|
+
gradientUnits: "userSpaceOnUse",
|
|
103
|
+
id: gradientId,
|
|
104
|
+
x1: 0,
|
|
105
|
+
x2: 0,
|
|
106
|
+
y1: baselineY,
|
|
107
|
+
y2: columnTop,
|
|
108
|
+
children: gradientStops.map((stop) => /* @__PURE__ */ jsx(
|
|
109
|
+
"stop",
|
|
110
|
+
{
|
|
111
|
+
offset: `${stop.offset}%`,
|
|
112
|
+
stopColor: stop.color
|
|
113
|
+
},
|
|
114
|
+
`${stop.offset}-${stop.color}`
|
|
115
|
+
))
|
|
116
|
+
}
|
|
117
|
+
),
|
|
118
|
+
gradientPatternNode
|
|
119
|
+
] }) : null;
|
|
120
|
+
const squares = layout.positions.map((relY, squareIndex) => {
|
|
121
|
+
const y = columnTop + relY;
|
|
122
|
+
const bottomY = y + squareSize;
|
|
123
|
+
const key = `sq-${index}-${squareIndex}-${revealEpoch}`;
|
|
124
|
+
if (!animate) {
|
|
125
|
+
return /* @__PURE__ */ jsx(
|
|
126
|
+
"rect",
|
|
127
|
+
{
|
|
128
|
+
fill: effectiveFill,
|
|
129
|
+
height: squareSize,
|
|
130
|
+
opacity: squareOpacity,
|
|
131
|
+
rx,
|
|
132
|
+
ry: rx,
|
|
133
|
+
width: squareSize,
|
|
134
|
+
x,
|
|
135
|
+
y
|
|
136
|
+
},
|
|
137
|
+
key
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
return /* @__PURE__ */ jsx(
|
|
141
|
+
m.rect,
|
|
142
|
+
{
|
|
143
|
+
animate: { attrY: y, height: squareSize, opacity: squareOpacity },
|
|
144
|
+
fill: effectiveFill,
|
|
145
|
+
height: squareSize,
|
|
146
|
+
initial: { attrY: bottomY, height: 0, opacity: 1 },
|
|
147
|
+
rx,
|
|
148
|
+
ry: rx,
|
|
149
|
+
transition: {
|
|
150
|
+
...transitionWithDelay(
|
|
151
|
+
enterTransition,
|
|
152
|
+
index * staggerDelay + squareIndex * cascadeStep
|
|
153
|
+
),
|
|
154
|
+
opacity: { duration: 0.15 }
|
|
155
|
+
},
|
|
156
|
+
width: squareSize,
|
|
157
|
+
x
|
|
158
|
+
},
|
|
159
|
+
key
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
163
|
+
gradientDefs,
|
|
164
|
+
squares
|
|
165
|
+
] });
|
|
166
|
+
}
|
|
167
|
+
const BarSquaresInner = memo(function BarSquaresInner2({
|
|
168
|
+
dataKey,
|
|
169
|
+
yAxisId,
|
|
170
|
+
fill = chartCssVars.linePrimary,
|
|
171
|
+
colorKey,
|
|
172
|
+
squareGap = 3,
|
|
173
|
+
squareRadius = 0.25,
|
|
174
|
+
squareFit = false,
|
|
175
|
+
useGradient = false,
|
|
176
|
+
gradientStops = [],
|
|
177
|
+
patternPreset,
|
|
178
|
+
animate = true,
|
|
179
|
+
fadedOpacity = 0.3,
|
|
180
|
+
staggerDelay,
|
|
181
|
+
groupGap = 4,
|
|
182
|
+
barScale,
|
|
183
|
+
bandWidth,
|
|
184
|
+
barXAccessor
|
|
185
|
+
}) {
|
|
186
|
+
const {
|
|
187
|
+
data,
|
|
188
|
+
innerHeight,
|
|
189
|
+
hoveredBarIndex,
|
|
190
|
+
lines,
|
|
191
|
+
orientation,
|
|
192
|
+
stacked,
|
|
193
|
+
animationDuration,
|
|
194
|
+
enterTransition,
|
|
195
|
+
revealEpoch = 0
|
|
196
|
+
} = useChart();
|
|
197
|
+
const { hoveredIndex: legendHoveredIndex } = useChartLegendHover();
|
|
198
|
+
const uniqueId = useId();
|
|
199
|
+
const isHorizontal = orientation === "horizontal";
|
|
200
|
+
const isUnsupported = isHorizontal || stacked;
|
|
201
|
+
const seriesIndex = useMemo(() => {
|
|
202
|
+
const idx = lines.findIndex((l) => l.dataKey === dataKey);
|
|
203
|
+
return idx >= 0 ? idx : 0;
|
|
204
|
+
}, [lines, dataKey]);
|
|
205
|
+
const seriesConfig = lines[seriesIndex];
|
|
206
|
+
const valueScale = useYScale(yAxisId ?? seriesConfig?.yAxisId);
|
|
207
|
+
const isLegendDimmed = legendHoveredIndex !== null && legendHoveredIndex !== seriesIndex;
|
|
208
|
+
const seriesCount = lines.length;
|
|
209
|
+
const squareSize = useMemo(() => {
|
|
210
|
+
if (!bandWidth || seriesCount === 0) {
|
|
211
|
+
return 0;
|
|
212
|
+
}
|
|
213
|
+
const effectiveGroupGap = seriesCount > 1 ? groupGap : 0;
|
|
214
|
+
return (bandWidth - effectiveGroupGap * (seriesCount - 1)) / seriesCount;
|
|
215
|
+
}, [bandWidth, seriesCount, groupGap]);
|
|
216
|
+
const totalAnimDuration = animationDuration || 1100;
|
|
217
|
+
const staggerSpread = totalAnimDuration * 0.4;
|
|
218
|
+
const calculatedStaggerDelay = staggerDelay ?? (data.length > 1 ? staggerSpread / 1e3 / data.length : 0);
|
|
219
|
+
const baselineY = valueScale(0) ?? innerHeight;
|
|
220
|
+
const stops = gradientStops.length >= 2 ? gradientStops : [
|
|
221
|
+
{ offset: 0, color: fill },
|
|
222
|
+
{ offset: 100, color: fill }
|
|
223
|
+
];
|
|
224
|
+
if (isUnsupported) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
return /* @__PURE__ */ jsx("g", { className: `bar-squares-${uniqueId}`, children: data.map((d, i) => {
|
|
228
|
+
const value = d[dataKey];
|
|
229
|
+
if (typeof value !== "number" || value <= 0) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
const categoryValue = barXAccessor(d);
|
|
233
|
+
const bandPos = barScale(categoryValue) ?? 0;
|
|
234
|
+
const effectiveGroupGap = seriesCount > 1 ? groupGap : 0;
|
|
235
|
+
const x = bandPos + seriesIndex * (squareSize + effectiveGroupGap);
|
|
236
|
+
const valuePos = valueScale(value) ?? 0;
|
|
237
|
+
const barLengthPx = baselineY - valuePos;
|
|
238
|
+
const isFaded = hoveredBarIndex !== null && hoveredBarIndex !== i || isLegendDimmed;
|
|
239
|
+
const columnColor = colorKey ? d[colorKey] : void 0;
|
|
240
|
+
const hasColumnColor = typeof columnColor === "string";
|
|
241
|
+
return /* @__PURE__ */ jsx(
|
|
242
|
+
SquareColumn,
|
|
243
|
+
{
|
|
244
|
+
animate,
|
|
245
|
+
animationDuration: animationDuration || 1100,
|
|
246
|
+
barLengthPx,
|
|
247
|
+
baselineY,
|
|
248
|
+
enterTransition,
|
|
249
|
+
fadedOpacity,
|
|
250
|
+
fill: hasColumnColor ? columnColor : fill,
|
|
251
|
+
gradientStops: stops,
|
|
252
|
+
index: i,
|
|
253
|
+
isFaded,
|
|
254
|
+
patternPreset,
|
|
255
|
+
revealEpoch,
|
|
256
|
+
squareFit,
|
|
257
|
+
squareGap,
|
|
258
|
+
squareRadius,
|
|
259
|
+
squareSize,
|
|
260
|
+
staggerDelay: calculatedStaggerDelay,
|
|
261
|
+
useGradient: useGradient && !hasColumnColor,
|
|
262
|
+
x
|
|
263
|
+
},
|
|
264
|
+
`bar-squares-${dataKey}-${categoryValue}`
|
|
265
|
+
);
|
|
266
|
+
}) });
|
|
267
|
+
});
|
|
268
|
+
function BarSquares(props) {
|
|
269
|
+
const { barScale, bandWidth, barXAccessor } = useChartStable();
|
|
270
|
+
if (!(barScale && bandWidth && barXAccessor)) {
|
|
271
|
+
console.warn("BarSquares must be used within a BarChart");
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
return /* @__PURE__ */ jsx(
|
|
275
|
+
BarSquaresInner,
|
|
276
|
+
{
|
|
277
|
+
...props,
|
|
278
|
+
bandWidth,
|
|
279
|
+
barScale,
|
|
280
|
+
barXAccessor
|
|
281
|
+
}
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
BarSquares.displayName = "BarSquares";
|
|
285
|
+
const BarColumnTrackInner = memo(function BarColumnTrackInner2({
|
|
286
|
+
fill = chartCssVars.grid,
|
|
287
|
+
opacity = 0.3,
|
|
288
|
+
squareGap = 3,
|
|
289
|
+
squareRadius = 0.25,
|
|
290
|
+
squareFit = false,
|
|
291
|
+
groupGap = 4,
|
|
292
|
+
staggerDelay,
|
|
293
|
+
barScale,
|
|
294
|
+
bandWidth,
|
|
295
|
+
barXAccessor
|
|
296
|
+
}) {
|
|
297
|
+
const {
|
|
298
|
+
data,
|
|
299
|
+
lines,
|
|
300
|
+
orientation,
|
|
301
|
+
stacked,
|
|
302
|
+
hoveredBarIndex,
|
|
303
|
+
animationDuration,
|
|
304
|
+
enterTransition,
|
|
305
|
+
revealEpoch = 0
|
|
306
|
+
} = useChart();
|
|
307
|
+
const uniqueId = useId();
|
|
308
|
+
const isHorizontal = orientation === "horizontal";
|
|
309
|
+
const isUnsupported = isHorizontal || stacked;
|
|
310
|
+
const seriesCount = lines.length;
|
|
311
|
+
const squareSize = useMemo(() => {
|
|
312
|
+
if (!bandWidth || seriesCount === 0) {
|
|
313
|
+
return 0;
|
|
314
|
+
}
|
|
315
|
+
const effectiveGroupGap = seriesCount > 1 ? groupGap : 0;
|
|
316
|
+
return (bandWidth - effectiveGroupGap * (seriesCount - 1)) / seriesCount;
|
|
317
|
+
}, [bandWidth, seriesCount, groupGap]);
|
|
318
|
+
const totalAnimDuration = animationDuration || 1100;
|
|
319
|
+
const staggerSpread = totalAnimDuration * 0.4;
|
|
320
|
+
const calculatedStaggerDelay = staggerDelay ?? (data.length > 1 ? staggerSpread / 1e3 / data.length : 0);
|
|
321
|
+
if (isUnsupported) {
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
const rx = squareSize * squareRadius;
|
|
325
|
+
const effectiveOpacity = hoveredBarIndex === null ? opacity : 0;
|
|
326
|
+
return /* @__PURE__ */ jsx(
|
|
327
|
+
"g",
|
|
328
|
+
{
|
|
329
|
+
className: `bar-column-track-${uniqueId}`,
|
|
330
|
+
style: { transition: "opacity 0.15s ease-in-out" },
|
|
331
|
+
children: data.map((d, i) => {
|
|
332
|
+
const categoryValue = barXAccessor(d);
|
|
333
|
+
const bandPos = barScale(categoryValue) ?? 0;
|
|
334
|
+
const effectiveGroupGap = seriesCount > 1 ? groupGap : 0;
|
|
335
|
+
return lines.map((line, seriesIndex) => /* @__PURE__ */ jsx(
|
|
336
|
+
TrackColumn,
|
|
337
|
+
{
|
|
338
|
+
animate: true,
|
|
339
|
+
bandPos,
|
|
340
|
+
d,
|
|
341
|
+
dataKey: line.dataKey,
|
|
342
|
+
effectiveGroupGap,
|
|
343
|
+
effectiveOpacity,
|
|
344
|
+
enterTransition,
|
|
345
|
+
fill,
|
|
346
|
+
index: i,
|
|
347
|
+
revealEpoch,
|
|
348
|
+
rx,
|
|
349
|
+
seriesIndex,
|
|
350
|
+
squareFit,
|
|
351
|
+
squareGap,
|
|
352
|
+
squareSize,
|
|
353
|
+
staggerDelay: calculatedStaggerDelay,
|
|
354
|
+
yAxisId: line.yAxisId
|
|
355
|
+
},
|
|
356
|
+
`track-${i}-${line.dataKey}`
|
|
357
|
+
));
|
|
358
|
+
})
|
|
359
|
+
}
|
|
360
|
+
);
|
|
361
|
+
});
|
|
362
|
+
function TrackColumn({
|
|
363
|
+
d,
|
|
364
|
+
dataKey,
|
|
365
|
+
yAxisId,
|
|
366
|
+
bandPos,
|
|
367
|
+
seriesIndex,
|
|
368
|
+
effectiveGroupGap,
|
|
369
|
+
squareSize,
|
|
370
|
+
squareGap,
|
|
371
|
+
squareFit,
|
|
372
|
+
fill,
|
|
373
|
+
rx,
|
|
374
|
+
effectiveOpacity,
|
|
375
|
+
index,
|
|
376
|
+
staggerDelay,
|
|
377
|
+
animate,
|
|
378
|
+
enterTransition,
|
|
379
|
+
revealEpoch
|
|
380
|
+
}) {
|
|
381
|
+
const { innerHeight, animationDuration: chartAnimationDuration } = useChart();
|
|
382
|
+
const valueScale = useYScale(yAxisId);
|
|
383
|
+
const value = d[dataKey];
|
|
384
|
+
if (typeof value !== "number" || value <= 0) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
const baselineY = valueScale(0) ?? innerHeight;
|
|
388
|
+
const valuePos = valueScale(value) ?? 0;
|
|
389
|
+
const barLengthPx = baselineY - valuePos;
|
|
390
|
+
const layout = computeSquareColumn({
|
|
391
|
+
barLengthPx,
|
|
392
|
+
squareSize,
|
|
393
|
+
gap: squareGap,
|
|
394
|
+
fit: squareFit
|
|
395
|
+
});
|
|
396
|
+
const columnTop = baselineY - layout.columnHeight;
|
|
397
|
+
const trackHeight = Math.max(0, columnTop);
|
|
398
|
+
if (trackHeight <= 0 && !animate) {
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
const x = bandPos + seriesIndex * (squareSize + effectiveGroupGap);
|
|
402
|
+
const enterAnim = cascadeColumnTransition(
|
|
403
|
+
enterTransition,
|
|
404
|
+
chartAnimationDuration || 1100,
|
|
405
|
+
index,
|
|
406
|
+
staggerDelay,
|
|
407
|
+
layout.count
|
|
408
|
+
);
|
|
409
|
+
const animatedHeight = trackHeight > 0 ? trackHeight : 0;
|
|
410
|
+
if (animate) {
|
|
411
|
+
return /* @__PURE__ */ jsx(
|
|
412
|
+
m.rect,
|
|
413
|
+
{
|
|
414
|
+
animate: { height: animatedHeight, y: 0 },
|
|
415
|
+
fill,
|
|
416
|
+
height: animatedHeight,
|
|
417
|
+
initial: { height: baselineY, y: 0 },
|
|
418
|
+
opacity: effectiveOpacity,
|
|
419
|
+
rx,
|
|
420
|
+
ry: rx,
|
|
421
|
+
transition: enterAnim,
|
|
422
|
+
width: squareSize,
|
|
423
|
+
x
|
|
424
|
+
},
|
|
425
|
+
`track-${index}-${seriesIndex}-${revealEpoch}`
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
if (trackHeight <= 0) {
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
return /* @__PURE__ */ jsx(
|
|
432
|
+
"rect",
|
|
433
|
+
{
|
|
434
|
+
fill,
|
|
435
|
+
height: trackHeight,
|
|
436
|
+
opacity: effectiveOpacity,
|
|
437
|
+
rx,
|
|
438
|
+
ry: rx,
|
|
439
|
+
width: squareSize,
|
|
440
|
+
x,
|
|
441
|
+
y: 0
|
|
442
|
+
}
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
function BarColumnTrack(props) {
|
|
446
|
+
const { barScale, bandWidth, barXAccessor } = useChartStable();
|
|
447
|
+
if (!(barScale && bandWidth && barXAccessor)) {
|
|
448
|
+
console.warn("BarColumnTrack must be used within a BarChart");
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
return /* @__PURE__ */ jsx(
|
|
452
|
+
BarColumnTrackInner,
|
|
453
|
+
{
|
|
454
|
+
...props,
|
|
455
|
+
bandWidth,
|
|
456
|
+
barScale,
|
|
457
|
+
barXAccessor
|
|
458
|
+
}
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
BarColumnTrack.displayName = "BarColumnTrack";
|
|
462
|
+
var bar_squares_default = BarSquares;
|
|
463
|
+
export {
|
|
464
|
+
BarColumnTrack,
|
|
465
|
+
BarSquares,
|
|
466
|
+
bar_squares_default as default
|
|
467
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const LABEL_LINE_HEIGHT = 12;
|
|
2
|
+
const LABEL_INSET = 6;
|
|
3
|
+
const MIN_CROSS_SIZE = LABEL_LINE_HEIGHT + 6;
|
|
4
|
+
function getBarValueLabelLayout({
|
|
5
|
+
x,
|
|
6
|
+
y,
|
|
7
|
+
width,
|
|
8
|
+
height,
|
|
9
|
+
labelWidth,
|
|
10
|
+
isHorizontal,
|
|
11
|
+
orientation,
|
|
12
|
+
position
|
|
13
|
+
}) {
|
|
14
|
+
const normalFits = width >= labelWidth + 10 && height >= MIN_CROSS_SIZE;
|
|
15
|
+
const rotatedFits = height >= labelWidth + 10 && width >= MIN_CROSS_SIZE;
|
|
16
|
+
let fits = normalFits || rotatedFits;
|
|
17
|
+
if (orientation === "horizontal") {
|
|
18
|
+
fits = normalFits;
|
|
19
|
+
} else if (orientation === "vertical") {
|
|
20
|
+
fits = rotatedFits;
|
|
21
|
+
}
|
|
22
|
+
const rotated = fits && (orientation === "vertical" || orientation === "auto" && !normalFits);
|
|
23
|
+
const extentX = rotated ? LABEL_LINE_HEIGHT : labelWidth;
|
|
24
|
+
const extentY = rotated ? labelWidth : LABEL_LINE_HEIGHT;
|
|
25
|
+
let labelX = x + width / 2;
|
|
26
|
+
let labelY = y + height / 2;
|
|
27
|
+
if (isHorizontal) {
|
|
28
|
+
if (position === "top") {
|
|
29
|
+
labelX = x + width - LABEL_INSET - extentX / 2;
|
|
30
|
+
} else if (position === "bottom") {
|
|
31
|
+
labelX = x + LABEL_INSET + extentX / 2;
|
|
32
|
+
}
|
|
33
|
+
} else if (position === "top") {
|
|
34
|
+
labelY = y + LABEL_INSET + extentY / 2;
|
|
35
|
+
} else if (position === "bottom") {
|
|
36
|
+
labelY = y + height - LABEL_INSET - extentY / 2;
|
|
37
|
+
}
|
|
38
|
+
return { fits, rotated, x: labelX, y: labelY };
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
getBarValueLabelLayout
|
|
42
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { m } from "motion/react";
|
|
4
|
+
import { memo, useMemo } from "react";
|
|
5
|
+
import { createPortal } from "react-dom";
|
|
6
|
+
import { cn } from "../lib/utils";
|
|
7
|
+
import {
|
|
8
|
+
useChart,
|
|
9
|
+
useChartPortalContainer,
|
|
10
|
+
useChartStable
|
|
11
|
+
} from "./chart-context";
|
|
12
|
+
import {
|
|
13
|
+
resolveResponsiveChartLabelCount
|
|
14
|
+
} from "./responsive-chart-label-count";
|
|
15
|
+
function BarXAxisLabel({
|
|
16
|
+
label,
|
|
17
|
+
x,
|
|
18
|
+
crosshairX,
|
|
19
|
+
isHovering,
|
|
20
|
+
tickerHalfWidth
|
|
21
|
+
}) {
|
|
22
|
+
const fadeBuffer = 20;
|
|
23
|
+
const fadeRadius = tickerHalfWidth + fadeBuffer;
|
|
24
|
+
let opacity = 1;
|
|
25
|
+
if (isHovering && crosshairX !== null) {
|
|
26
|
+
const distance = Math.abs(x - crosshairX);
|
|
27
|
+
if (distance < tickerHalfWidth) {
|
|
28
|
+
opacity = 0;
|
|
29
|
+
} else if (distance < fadeRadius) {
|
|
30
|
+
opacity = (distance - tickerHalfWidth) / fadeBuffer;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return /* @__PURE__ */ jsx(
|
|
34
|
+
"div",
|
|
35
|
+
{
|
|
36
|
+
className: "absolute",
|
|
37
|
+
style: {
|
|
38
|
+
left: x,
|
|
39
|
+
bottom: 12,
|
|
40
|
+
width: 0,
|
|
41
|
+
display: "flex",
|
|
42
|
+
justifyContent: "center"
|
|
43
|
+
},
|
|
44
|
+
children: /* @__PURE__ */ jsx(
|
|
45
|
+
m.span,
|
|
46
|
+
{
|
|
47
|
+
animate: { opacity },
|
|
48
|
+
className: cn("whitespace-nowrap text-chart-label text-xs"),
|
|
49
|
+
initial: { opacity: 1 },
|
|
50
|
+
transition: { duration: 0.4, ease: "easeInOut" },
|
|
51
|
+
children: label
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
function BarXAxis(props) {
|
|
58
|
+
const { containerRef, barScale } = useChartStable();
|
|
59
|
+
const container = useChartPortalContainer(containerRef);
|
|
60
|
+
if (!container) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
if (!barScale) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return /* @__PURE__ */ jsx(BarXAxisInner, { ...props, container });
|
|
67
|
+
}
|
|
68
|
+
const BarXAxisInner = memo(function BarXAxisInner2({
|
|
69
|
+
tickerHalfWidth = 50,
|
|
70
|
+
showAllLabels = false,
|
|
71
|
+
maxLabels = 12,
|
|
72
|
+
container
|
|
73
|
+
}) {
|
|
74
|
+
const {
|
|
75
|
+
margin,
|
|
76
|
+
tooltipData,
|
|
77
|
+
barScale,
|
|
78
|
+
bandWidth,
|
|
79
|
+
barXAccessor,
|
|
80
|
+
data,
|
|
81
|
+
width
|
|
82
|
+
} = useChart();
|
|
83
|
+
const resolvedMaxLabels = useMemo(
|
|
84
|
+
() => resolveResponsiveChartLabelCount(maxLabels, width, 12),
|
|
85
|
+
[maxLabels, width]
|
|
86
|
+
);
|
|
87
|
+
const labelsToShow = useMemo(() => {
|
|
88
|
+
if (!(barScale && bandWidth && barXAccessor)) {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
const allLabels = data.map((d) => {
|
|
92
|
+
const label = barXAccessor(d);
|
|
93
|
+
const bandX = barScale(label) ?? 0;
|
|
94
|
+
const x = bandX + bandWidth / 2 + margin.left;
|
|
95
|
+
return { label, x };
|
|
96
|
+
});
|
|
97
|
+
if (showAllLabels || allLabels.length <= resolvedMaxLabels) {
|
|
98
|
+
return allLabels;
|
|
99
|
+
}
|
|
100
|
+
const step = Math.ceil(allLabels.length / Math.max(1, resolvedMaxLabels));
|
|
101
|
+
return allLabels.filter((_, i) => i % step === 0);
|
|
102
|
+
}, [
|
|
103
|
+
barScale,
|
|
104
|
+
bandWidth,
|
|
105
|
+
barXAccessor,
|
|
106
|
+
data,
|
|
107
|
+
margin.left,
|
|
108
|
+
showAllLabels,
|
|
109
|
+
resolvedMaxLabels
|
|
110
|
+
]);
|
|
111
|
+
const isHovering = tooltipData !== null;
|
|
112
|
+
const crosshairX = tooltipData ? tooltipData.x + margin.left : null;
|
|
113
|
+
return createPortal(
|
|
114
|
+
/* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-0", children: labelsToShow.map((item) => /* @__PURE__ */ jsx(
|
|
115
|
+
BarXAxisLabel,
|
|
116
|
+
{
|
|
117
|
+
crosshairX,
|
|
118
|
+
isHovering,
|
|
119
|
+
label: item.label,
|
|
120
|
+
tickerHalfWidth,
|
|
121
|
+
x: item.x
|
|
122
|
+
},
|
|
123
|
+
`${item.label}-${item.x}`
|
|
124
|
+
)) }),
|
|
125
|
+
container
|
|
126
|
+
);
|
|
127
|
+
});
|
|
128
|
+
BarXAxis.displayName = "BarXAxis";
|
|
129
|
+
var bar_x_axis_default = BarXAxis;
|
|
130
|
+
export {
|
|
131
|
+
BarXAxis,
|
|
132
|
+
bar_x_axis_default as default
|
|
133
|
+
};
|