@dudousxd/nestjs-catalog-react 0.1.0
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/LICENSE-bklit +21 -0
- package/README.md +282 -0
- package/dist/AccessConsole.d.ts +40 -0
- package/dist/AccessConsole.js +160 -0
- package/dist/CatalogManager.d.ts +12 -0
- package/dist/CatalogManager.js +123 -0
- package/dist/ConnectionPanel.d.ts +41 -0
- package/dist/ConnectionPanel.js +228 -0
- package/dist/CoverageLedger.d.ts +16 -0
- package/dist/CoverageLedger.js +16 -0
- package/dist/DashboardBoard.d.ts +10 -0
- package/dist/DashboardBoard.js +206 -0
- package/dist/EditableField.d.ts +18 -0
- package/dist/EditableField.js +61 -0
- package/dist/FlowView.d.ts +13 -0
- package/dist/FlowView.js +93 -0
- package/dist/GovernanceTimeline.d.ts +16 -0
- package/dist/GovernanceTimeline.js +93 -0
- package/dist/ObjectExplorer.d.ts +9 -0
- package/dist/ObjectExplorer.js +153 -0
- package/dist/PipelineConsole.d.ts +20 -0
- package/dist/PipelineConsole.js +272 -0
- package/dist/QueryConsole.d.ts +11 -0
- package/dist/QueryConsole.js +144 -0
- package/dist/SavedQueryPanel.d.ts +16 -0
- package/dist/SavedQueryPanel.js +78 -0
- package/dist/TraceExplorer.d.ts +54 -0
- package/dist/TraceExplorer.js +342 -0
- package/dist/TransformEditor.d.ts +23 -0
- package/dist/TransformEditor.js +129 -0
- package/dist/WorkflowCanvas.d.ts +24 -0
- package/dist/WorkflowCanvas.js +701 -0
- package/dist/charts/bklit/animation.d.ts +19 -0
- package/dist/charts/bklit/animation.js +28 -0
- package/dist/charts/bklit/area-chart-loading.d.ts +33 -0
- package/dist/charts/bklit/area-chart-loading.js +30 -0
- package/dist/charts/bklit/area-chart.d.ts +47 -0
- package/dist/charts/bklit/area-chart.js +65 -0
- package/dist/charts/bklit/area-gradient-defs.d.ts +28 -0
- package/dist/charts/bklit/area-gradient-defs.js +23 -0
- package/dist/charts/bklit/area.d.ts +75 -0
- package/dist/charts/bklit/area.js +112 -0
- package/dist/charts/bklit/bar-chart-loading.d.ts +16 -0
- package/dist/charts/bklit/bar-chart-loading.js +22 -0
- package/dist/charts/bklit/bar-chart.d.ts +54 -0
- package/dist/charts/bklit/bar-chart.js +440 -0
- package/dist/charts/bklit/bar-depth-geometry.d.ts +41 -0
- package/dist/charts/bklit/bar-depth-geometry.js +46 -0
- package/dist/charts/bklit/bar-squares-layout.d.ts +36 -0
- package/dist/charts/bklit/bar-squares-layout.js +46 -0
- package/dist/charts/bklit/bar-squares.d.ts +48 -0
- package/dist/charts/bklit/bar-squares.js +206 -0
- package/dist/charts/bklit/bar-x-axis.d.ts +13 -0
- package/dist/charts/bklit/bar-x-axis.js +81 -0
- package/dist/charts/bklit/bar-y-axis.d.ts +11 -0
- package/dist/charts/bklit/bar-y-axis.js +72 -0
- package/dist/charts/bklit/bar.d.ts +40 -0
- package/dist/charts/bklit/bar.js +207 -0
- package/dist/charts/bklit/chart-child-passthrough.d.ts +25 -0
- package/dist/charts/bklit/chart-child-passthrough.js +82 -0
- package/dist/charts/bklit/chart-config-context.d.ts +34 -0
- package/dist/charts/bklit/chart-config-context.js +55 -0
- package/dist/charts/bklit/chart-context.d.ts +207 -0
- package/dist/charts/bklit/chart-context.js +200 -0
- package/dist/charts/bklit/chart-defs.d.ts +21 -0
- package/dist/charts/bklit/chart-defs.js +57 -0
- package/dist/charts/bklit/chart-formatters.d.ts +16 -0
- package/dist/charts/bklit/chart-formatters.js +26 -0
- package/dist/charts/bklit/chart-legend-hover.d.ts +21 -0
- package/dist/charts/bklit/chart-legend-hover.js +26 -0
- package/dist/charts/bklit/chart-loading-label.d.ts +9 -0
- package/dist/charts/bklit/chart-loading-label.js +29 -0
- package/dist/charts/bklit/chart-phase.d.ts +39 -0
- package/dist/charts/bklit/chart-phase.js +20 -0
- package/dist/charts/bklit/chart-reveal-clip.d.ts +32 -0
- package/dist/charts/bklit/chart-reveal-clip.js +23 -0
- package/dist/charts/bklit/dash-tail-stroke.d.ts +17 -0
- package/dist/charts/bklit/dash-tail-stroke.js +21 -0
- package/dist/charts/bklit/decimate-time-series.d.ts +18 -0
- package/dist/charts/bklit/decimate-time-series.js +120 -0
- package/dist/charts/bklit/fade-edges.d.ts +42 -0
- package/dist/charts/bklit/fade-edges.js +34 -0
- package/dist/charts/bklit/filter-data-by-x-domain.d.ts +13 -0
- package/dist/charts/bklit/filter-data-by-x-domain.js +50 -0
- package/dist/charts/bklit/generate-chart-skeleton-data.d.ts +24 -0
- package/dist/charts/bklit/generate-chart-skeleton-data.js +33 -0
- package/dist/charts/bklit/grid.d.ts +57 -0
- package/dist/charts/bklit/grid.js +88 -0
- package/dist/charts/bklit/highlight-segment-bounds.d.ts +26 -0
- package/dist/charts/bklit/highlight-segment-bounds.js +35 -0
- package/dist/charts/bklit/highlight-segment.d.ts +30 -0
- package/dist/charts/bklit/highlight-segment.js +22 -0
- package/dist/charts/bklit/indicator-fade.d.ts +23 -0
- package/dist/charts/bklit/indicator-fade.js +41 -0
- package/dist/charts/bklit/line-chart-loading.d.ts +33 -0
- package/dist/charts/bklit/line-chart-loading.js +30 -0
- package/dist/charts/bklit/line-chart.d.ts +45 -0
- package/dist/charts/bklit/line-chart.js +99 -0
- package/dist/charts/bklit/line-loading-pulse.d.ts +19 -0
- package/dist/charts/bklit/line-loading-pulse.js +132 -0
- package/dist/charts/bklit/line-loading-timing.d.ts +18 -0
- package/dist/charts/bklit/line-loading-timing.js +18 -0
- package/dist/charts/bklit/line-series-terminal-marker.d.ts +15 -0
- package/dist/charts/bklit/line-series-terminal-marker.js +54 -0
- package/dist/charts/bklit/line.d.ts +63 -0
- package/dist/charts/bklit/line.js +104 -0
- package/dist/charts/bklit/loading-sweep.d.ts +65 -0
- package/dist/charts/bklit/loading-sweep.js +182 -0
- package/dist/charts/bklit/motion-utils.d.ts +17 -0
- package/dist/charts/bklit/motion-utils.js +27 -0
- package/dist/charts/bklit/path-stroke-utils.d.ts +28 -0
- package/dist/charts/bklit/path-stroke-utils.js +64 -0
- package/dist/charts/bklit/pattern-area.d.ts +20 -0
- package/dist/charts/bklit/pattern-area.js +27 -0
- package/dist/charts/bklit/pattern-preset.d.ts +34 -0
- package/dist/charts/bklit/pattern-preset.js +82 -0
- package/dist/charts/bklit/projection-config.d.ts +19 -0
- package/dist/charts/bklit/projection-config.js +88 -0
- package/dist/charts/bklit/projection-line-end-marker.d.ts +14 -0
- package/dist/charts/bklit/projection-line-end-marker.js +35 -0
- package/dist/charts/bklit/projection-line.d.ts +39 -0
- package/dist/charts/bklit/projection-line.js +87 -0
- package/dist/charts/bklit/projection-utils.d.ts +54 -0
- package/dist/charts/bklit/projection-utils.js +252 -0
- package/dist/charts/bklit/reference-area-config.d.ts +18 -0
- package/dist/charts/bklit/reference-area-config.js +47 -0
- package/dist/charts/bklit/reference-area-registration-context.d.ts +7 -0
- package/dist/charts/bklit/reference-area-registration-context.js +15 -0
- package/dist/charts/bklit/series-bar-layout.d.ts +26 -0
- package/dist/charts/bklit/series-bar-layout.js +39 -0
- package/dist/charts/bklit/series-dash-tail-overlay.d.ts +16 -0
- package/dist/charts/bklit/series-dash-tail-overlay.js +47 -0
- package/dist/charts/bklit/series-highlight-layer.d.ts +31 -0
- package/dist/charts/bklit/series-highlight-layer.js +20 -0
- package/dist/charts/bklit/series-hover-dim.d.ts +28 -0
- package/dist/charts/bklit/series-hover-dim.js +34 -0
- package/dist/charts/bklit/series-markers.d.ts +13 -0
- package/dist/charts/bklit/series-markers.js +106 -0
- package/dist/charts/bklit/series-path-utils.d.ts +18 -0
- package/dist/charts/bklit/series-path-utils.js +68 -0
- package/dist/charts/bklit/series-point-marker.d.ts +47 -0
- package/dist/charts/bklit/series-point-marker.js +47 -0
- package/dist/charts/bklit/static-chart-preview-context.d.ts +15 -0
- package/dist/charts/bklit/static-chart-preview-context.js +20 -0
- package/dist/charts/bklit/time-series-chart-shell.d.ts +46 -0
- package/dist/charts/bklit/time-series-chart-shell.js +398 -0
- package/dist/charts/bklit/tooltip/chart-tooltip.d.ts +75 -0
- package/dist/charts/bklit/tooltip/chart-tooltip.js +158 -0
- package/dist/charts/bklit/tooltip/date-ticker.d.ts +10 -0
- package/dist/charts/bklit/tooltip/date-ticker.js +85 -0
- package/dist/charts/bklit/tooltip/index.d.ts +15 -0
- package/dist/charts/bklit/tooltip/index.js +15 -0
- package/dist/charts/bklit/tooltip/tooltip-box.d.ts +56 -0
- package/dist/charts/bklit/tooltip/tooltip-box.js +122 -0
- package/dist/charts/bklit/tooltip/tooltip-content.d.ts +26 -0
- package/dist/charts/bklit/tooltip/tooltip-content.js +8 -0
- package/dist/charts/bklit/tooltip/tooltip-dot.d.ts +27 -0
- package/dist/charts/bklit/tooltip/tooltip-dot.js +62 -0
- package/dist/charts/bklit/tooltip/tooltip-indicator.d.ts +44 -0
- package/dist/charts/bklit/tooltip/tooltip-indicator.js +73 -0
- package/dist/charts/bklit/use-animated-series-path.d.ts +18 -0
- package/dist/charts/bklit/use-animated-series-path.js +101 -0
- package/dist/charts/bklit/use-animated-y-domains.d.ts +13 -0
- package/dist/charts/bklit/use-animated-y-domains.js +158 -0
- package/dist/charts/bklit/use-chart-interaction.d.ts +40 -0
- package/dist/charts/bklit/use-chart-interaction.js +252 -0
- package/dist/charts/bklit/use-chart-phase-orchestrator.d.ts +22 -0
- package/dist/charts/bklit/use-chart-phase-orchestrator.js +147 -0
- package/dist/charts/bklit/use-enter-complete.d.ts +16 -0
- package/dist/charts/bklit/use-enter-complete.js +22 -0
- package/dist/charts/bklit/use-grid-shimmer.d.ts +15 -0
- package/dist/charts/bklit/use-grid-shimmer.js +71 -0
- package/dist/charts/bklit/use-highlight-segment.d.ts +22 -0
- package/dist/charts/bklit/use-highlight-segment.js +42 -0
- package/dist/charts/bklit/use-mount-progress.d.ts +12 -0
- package/dist/charts/bklit/use-mount-progress.js +30 -0
- package/dist/charts/bklit/use-scheduled-tooltip.d.ts +8 -0
- package/dist/charts/bklit/use-scheduled-tooltip.js +84 -0
- package/dist/charts/bklit/visx-pattern.d.ts +27 -0
- package/dist/charts/bklit/visx-pattern.js +28 -0
- package/dist/charts/bklit/x-axis.d.ts +26 -0
- package/dist/charts/bklit/x-axis.js +423 -0
- package/dist/charts/bklit/y-axis-scales.d.ts +34 -0
- package/dist/charts/bklit/y-axis-scales.js +80 -0
- package/dist/charts/bklit/y-axis-ticks.d.ts +20 -0
- package/dist/charts/bklit/y-axis-ticks.js +32 -0
- package/dist/charts/bklit/y-domain-utils.d.ts +26 -0
- package/dist/charts/bklit/y-domain-utils.js +96 -0
- package/dist/charts/bklit.d.ts +2 -0
- package/dist/charts/bklit.js +90 -0
- package/dist/charts/components/shimmering-text.d.ts +31 -0
- package/dist/charts/components/shimmering-text.js +39 -0
- package/dist/charts/css.d.ts +35 -0
- package/dist/charts/css.js +64 -0
- package/dist/charts/recharts.d.ts +28 -0
- package/dist/charts/recharts.js +48 -0
- package/dist/charts/registry.d.ts +34 -0
- package/dist/charts/registry.js +60 -0
- package/dist/charts/skeleton.d.ts +55 -0
- package/dist/charts/skeleton.js +66 -0
- package/dist/cn.d.ts +10 -0
- package/dist/cn.js +13 -0
- package/dist/context.d.ts +346 -0
- package/dist/context.js +95 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +65 -0
- package/dist/routes.d.ts +70 -0
- package/dist/routes.js +73 -0
- package/dist/source-fields.d.ts +111 -0
- package/dist/source-fields.js +204 -0
- package/dist/ui/chart.d.ts +54 -0
- package/dist/ui/chart.js +122 -0
- package/dist/ui/dialog.d.ts +27 -0
- package/dist/ui/dialog.js +24 -0
- package/dist/ui/field.d.ts +29 -0
- package/dist/ui/field.js +31 -0
- package/dist/ui/select.d.ts +42 -0
- package/dist/ui/select.js +30 -0
- package/dist/ui/sheet.d.ts +38 -0
- package/dist/ui/sheet.js +37 -0
- package/dist/ui/switch.d.ts +17 -0
- package/dist/ui/switch.js +14 -0
- package/dist/ui/tabs.d.ts +30 -0
- package/dist/ui/tabs.js +36 -0
- package/dist/ui/tooltip.d.ts +37 -0
- package/dist/ui/tooltip.js +43 -0
- package/dist/workflow/graph.d.ts +112 -0
- package/dist/workflow/graph.js +297 -0
- package/dist/workflow/index.d.ts +16 -0
- package/dist/workflow/index.js +16 -0
- package/dist/workflow/model.d.ts +151 -0
- package/dist/workflow/model.js +97 -0
- package/dist/workflow/name.d.ts +28 -0
- package/dist/workflow/name.js +28 -0
- package/dist/workflow/nodes.d.ts +40 -0
- package/dist/workflow/nodes.js +86 -0
- package/dist/workflow/validate.d.ts +104 -0
- package/dist/workflow/validate.js +199 -0
- package/package.json +148 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { motion } from 'motion/react';
|
|
4
|
+
import { memo, useId, useMemo } from 'react';
|
|
5
|
+
import { computeSquareColumn } from './bar-squares-layout';
|
|
6
|
+
import { chartCssVars, useChart, useChartStable, useYScale } from './chart-context';
|
|
7
|
+
import { useChartLegendHover } from './chart-legend-hover';
|
|
8
|
+
import { transitionWithDelay } from './motion-utils';
|
|
9
|
+
import { renderPatternPreset } from './pattern-preset';
|
|
10
|
+
function isPatternFill(fill) {
|
|
11
|
+
return fill.startsWith('url(');
|
|
12
|
+
}
|
|
13
|
+
/** Delay between stacked squares within one column (bottom → top). */
|
|
14
|
+
function squareCascadeStepSeconds(enterTransition, animationDurationMs, squareCount) {
|
|
15
|
+
if (squareCount <= 1) {
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
const durationMs = enterTransition?.type === 'tween' && typeof enterTransition.duration === 'number'
|
|
19
|
+
? enterTransition.duration * 1000
|
|
20
|
+
: animationDurationMs;
|
|
21
|
+
const cascadeSpreadMs = durationMs * 0.4;
|
|
22
|
+
return cascadeSpreadMs / 1000 / (squareCount - 1);
|
|
23
|
+
}
|
|
24
|
+
function cascadeColumnTransition(enterTransition, animationDurationMs, columnIndex, columnStaggerDelay, squareCount) {
|
|
25
|
+
const cascadeStep = squareCascadeStepSeconds(enterTransition, animationDurationMs, squareCount);
|
|
26
|
+
const base = transitionWithDelay(enterTransition, columnIndex * columnStaggerDelay);
|
|
27
|
+
if (squareCount <= 1 || base.type !== 'tween') {
|
|
28
|
+
return base;
|
|
29
|
+
}
|
|
30
|
+
const baseDuration = typeof base.duration === 'number' ? base.duration : animationDurationMs / 1000;
|
|
31
|
+
return {
|
|
32
|
+
...base,
|
|
33
|
+
duration: baseDuration + cascadeStep * (squareCount - 1),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function SquareColumn({ x, baselineY, barLengthPx, squareSize, squareGap, squareRadius, squareFit, fill, useGradient, gradientStops, patternPreset, index, isFaded, fadedOpacity, animate, staggerDelay, animationDuration, enterTransition, revealEpoch, }) {
|
|
37
|
+
const layout = useMemo(() => computeSquareColumn({
|
|
38
|
+
barLengthPx,
|
|
39
|
+
squareSize,
|
|
40
|
+
gap: squareGap,
|
|
41
|
+
fit: squareFit,
|
|
42
|
+
}), [barLengthPx, squareSize, squareGap, squareFit]);
|
|
43
|
+
const rx = squareSize * squareRadius;
|
|
44
|
+
const columnTop = baselineY - layout.columnHeight;
|
|
45
|
+
const gradientId = `bar-squares-gradient-${index}-${revealEpoch}`;
|
|
46
|
+
const patternFill = isPatternFill(fill);
|
|
47
|
+
const patternId = `bar-squares-pattern-${index}-${revealEpoch}`;
|
|
48
|
+
const effectiveFill = useMemo(() => {
|
|
49
|
+
if (useGradient) {
|
|
50
|
+
if (patternFill && patternPreset && patternPreset !== 'none') {
|
|
51
|
+
return `url(#${patternId})`;
|
|
52
|
+
}
|
|
53
|
+
return `url(#${gradientId})`;
|
|
54
|
+
}
|
|
55
|
+
return fill;
|
|
56
|
+
}, [useGradient, patternFill, patternPreset, fill, gradientId, patternId]);
|
|
57
|
+
const cascadeStep = squareCascadeStepSeconds(enterTransition, animationDuration, layout.count);
|
|
58
|
+
const squareOpacity = isFaded ? fadedOpacity : 1;
|
|
59
|
+
const gradientPatternNode = useGradient && patternFill && patternPreset && patternPreset !== 'none'
|
|
60
|
+
? renderPatternPreset(patternPreset, patternId, {
|
|
61
|
+
color: `url(#${gradientId})`,
|
|
62
|
+
})
|
|
63
|
+
: null;
|
|
64
|
+
const gradientDefs = useGradient ? (_jsxs("defs", { children: [_jsx("linearGradient", { gradientUnits: "userSpaceOnUse", id: gradientId, x1: 0, x2: 0, y1: baselineY, y2: columnTop, children: gradientStops.map((stop) => (_jsx("stop", { offset: `${stop.offset}%`, stopColor: stop.color }, `${stop.offset}-${stop.color}`))) }), gradientPatternNode] })) : null;
|
|
65
|
+
const squares = layout.positions.map((relY, squareIndex) => {
|
|
66
|
+
const y = columnTop + relY;
|
|
67
|
+
const bottomY = y + squareSize;
|
|
68
|
+
const key = `sq-${index}-${squareIndex}-${revealEpoch}`;
|
|
69
|
+
if (!animate) {
|
|
70
|
+
return (_jsx("rect", { fill: effectiveFill, height: squareSize, opacity: squareOpacity, rx: rx, ry: rx, width: squareSize, x: x, y: y }, key));
|
|
71
|
+
}
|
|
72
|
+
return (_jsx(motion.rect, { animate: { attrY: y, height: squareSize, opacity: squareOpacity }, fill: effectiveFill, height: squareSize, initial: { attrY: bottomY, height: 0, opacity: 1 }, rx: rx, ry: rx, transition: {
|
|
73
|
+
...transitionWithDelay(enterTransition, index * staggerDelay + squareIndex * cascadeStep),
|
|
74
|
+
opacity: { duration: 0.15 },
|
|
75
|
+
}, width: squareSize, x: x }, key));
|
|
76
|
+
});
|
|
77
|
+
return (_jsxs(_Fragment, { children: [gradientDefs, squares] }));
|
|
78
|
+
}
|
|
79
|
+
const BarSquaresInner = memo(function BarSquaresInner({ dataKey, yAxisId, fill = chartCssVars.linePrimary, squareGap = 3, squareRadius = 0.25, squareFit = false, useGradient = false, gradientStops = [], patternPreset, animate = true, fadedOpacity = 0.3, staggerDelay, groupGap = 4, barScale, bandWidth, barXAccessor, }) {
|
|
80
|
+
const { data, innerHeight, hoveredBarIndex, lines, orientation, stacked, animationDuration, enterTransition, revealEpoch = 0, } = useChart();
|
|
81
|
+
const { hoveredIndex: legendHoveredIndex } = useChartLegendHover();
|
|
82
|
+
const uniqueId = useId();
|
|
83
|
+
const isHorizontal = orientation === 'horizontal';
|
|
84
|
+
const isUnsupported = isHorizontal || stacked;
|
|
85
|
+
const seriesIndex = useMemo(() => {
|
|
86
|
+
const idx = lines.findIndex((l) => l.dataKey === dataKey);
|
|
87
|
+
return idx >= 0 ? idx : 0;
|
|
88
|
+
}, [lines, dataKey]);
|
|
89
|
+
const seriesConfig = lines[seriesIndex];
|
|
90
|
+
const valueScale = useYScale(yAxisId ?? seriesConfig?.yAxisId);
|
|
91
|
+
const isLegendDimmed = legendHoveredIndex !== null && legendHoveredIndex !== seriesIndex;
|
|
92
|
+
const seriesCount = lines.length;
|
|
93
|
+
const squareSize = useMemo(() => {
|
|
94
|
+
if (!bandWidth || seriesCount === 0) {
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
const effectiveGroupGap = seriesCount > 1 ? groupGap : 0;
|
|
98
|
+
return (bandWidth - effectiveGroupGap * (seriesCount - 1)) / seriesCount;
|
|
99
|
+
}, [bandWidth, seriesCount, groupGap]);
|
|
100
|
+
const totalAnimDuration = animationDuration || 1100;
|
|
101
|
+
const staggerSpread = totalAnimDuration * 0.4;
|
|
102
|
+
const calculatedStaggerDelay = staggerDelay ?? (data.length > 1 ? staggerSpread / 1000 / data.length : 0);
|
|
103
|
+
const baselineY = valueScale(0) ?? innerHeight;
|
|
104
|
+
const stops = gradientStops.length >= 2
|
|
105
|
+
? gradientStops
|
|
106
|
+
: [
|
|
107
|
+
{ offset: 0, color: fill },
|
|
108
|
+
{ offset: 100, color: fill },
|
|
109
|
+
];
|
|
110
|
+
if (isUnsupported) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return (_jsx("g", { className: `bar-squares-${uniqueId}`, children: data.map((d, i) => {
|
|
114
|
+
const value = d[dataKey];
|
|
115
|
+
if (typeof value !== 'number' || value <= 0) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
const categoryValue = barXAccessor(d);
|
|
119
|
+
const bandPos = barScale(categoryValue) ?? 0;
|
|
120
|
+
const effectiveGroupGap = seriesCount > 1 ? groupGap : 0;
|
|
121
|
+
const x = bandPos + seriesIndex * (squareSize + effectiveGroupGap);
|
|
122
|
+
const valuePos = valueScale(value) ?? 0;
|
|
123
|
+
const barLengthPx = baselineY - valuePos;
|
|
124
|
+
const isFaded = (hoveredBarIndex !== null && hoveredBarIndex !== i) || isLegendDimmed;
|
|
125
|
+
return (_jsx(SquareColumn, { animate: animate, animationDuration: animationDuration || 1100, barLengthPx: barLengthPx, baselineY: baselineY, enterTransition: enterTransition, fadedOpacity: fadedOpacity, fill: fill, gradientStops: stops, index: i, isFaded: isFaded, patternPreset: patternPreset, revealEpoch: revealEpoch, squareFit: squareFit, squareGap: squareGap, squareRadius: squareRadius, squareSize: squareSize, staggerDelay: calculatedStaggerDelay, useGradient: useGradient, x: x }, `bar-squares-${dataKey}-${categoryValue}`));
|
|
126
|
+
}) }));
|
|
127
|
+
});
|
|
128
|
+
export function BarSquares(props) {
|
|
129
|
+
const { barScale, bandWidth, barXAccessor } = useChartStable();
|
|
130
|
+
if (!(barScale && bandWidth && barXAccessor)) {
|
|
131
|
+
console.warn('BarSquares must be used within a BarChart');
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
return (_jsx(BarSquaresInner, { ...props, bandWidth: bandWidth, barScale: barScale, barXAccessor: barXAccessor }));
|
|
135
|
+
}
|
|
136
|
+
BarSquares.displayName = 'BarSquares';
|
|
137
|
+
const BarColumnTrackInner = memo(function BarColumnTrackInner({ fill = chartCssVars.grid, opacity = 0.3, squareGap = 3, squareRadius = 0.25, squareFit = false, groupGap = 4, staggerDelay, barScale, bandWidth, barXAccessor, }) {
|
|
138
|
+
const { data, lines, orientation, stacked, hoveredBarIndex, animationDuration, enterTransition, revealEpoch = 0, } = useChart();
|
|
139
|
+
const uniqueId = useId();
|
|
140
|
+
const isHorizontal = orientation === 'horizontal';
|
|
141
|
+
const isUnsupported = isHorizontal || stacked;
|
|
142
|
+
const seriesCount = lines.length;
|
|
143
|
+
const squareSize = useMemo(() => {
|
|
144
|
+
if (!bandWidth || seriesCount === 0) {
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
147
|
+
const effectiveGroupGap = seriesCount > 1 ? groupGap : 0;
|
|
148
|
+
return (bandWidth - effectiveGroupGap * (seriesCount - 1)) / seriesCount;
|
|
149
|
+
}, [bandWidth, seriesCount, groupGap]);
|
|
150
|
+
const totalAnimDuration = animationDuration || 1100;
|
|
151
|
+
const staggerSpread = totalAnimDuration * 0.4;
|
|
152
|
+
const calculatedStaggerDelay = staggerDelay ?? (data.length > 1 ? staggerSpread / 1000 / data.length : 0);
|
|
153
|
+
if (isUnsupported) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
const rx = squareSize * squareRadius;
|
|
157
|
+
const effectiveOpacity = hoveredBarIndex === null ? opacity : 0;
|
|
158
|
+
return (_jsx("g", { className: `bar-column-track-${uniqueId}`, style: { transition: 'opacity 0.15s ease-in-out' }, children: data.map((d, i) => {
|
|
159
|
+
const categoryValue = barXAccessor(d);
|
|
160
|
+
const bandPos = barScale(categoryValue) ?? 0;
|
|
161
|
+
const effectiveGroupGap = seriesCount > 1 ? groupGap : 0;
|
|
162
|
+
return lines.map((line, seriesIndex) => (_jsx(TrackColumn, { animate: true, bandPos: bandPos, d: d, dataKey: line.dataKey, effectiveGroupGap: effectiveGroupGap, effectiveOpacity: effectiveOpacity, enterTransition: enterTransition, fill: fill, index: i, revealEpoch: revealEpoch, rx: rx, seriesIndex: seriesIndex, squareFit: squareFit, squareGap: squareGap, squareSize: squareSize, staggerDelay: calculatedStaggerDelay, yAxisId: line.yAxisId }, `track-${i}-${line.dataKey}`)));
|
|
163
|
+
}) }));
|
|
164
|
+
});
|
|
165
|
+
function TrackColumn({ d, dataKey, yAxisId, bandPos, seriesIndex, effectiveGroupGap, squareSize, squareGap, squareFit, fill, rx, effectiveOpacity, index, staggerDelay, animate, enterTransition, revealEpoch, }) {
|
|
166
|
+
const { innerHeight, animationDuration: chartAnimationDuration } = useChart();
|
|
167
|
+
const valueScale = useYScale(yAxisId);
|
|
168
|
+
const value = d[dataKey];
|
|
169
|
+
if (typeof value !== 'number' || value <= 0) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
const baselineY = valueScale(0) ?? innerHeight;
|
|
173
|
+
const valuePos = valueScale(value) ?? 0;
|
|
174
|
+
const barLengthPx = baselineY - valuePos;
|
|
175
|
+
const layout = computeSquareColumn({
|
|
176
|
+
barLengthPx,
|
|
177
|
+
squareSize,
|
|
178
|
+
gap: squareGap,
|
|
179
|
+
fit: squareFit,
|
|
180
|
+
});
|
|
181
|
+
const columnTop = baselineY - layout.columnHeight;
|
|
182
|
+
const trackHeight = Math.max(0, columnTop);
|
|
183
|
+
if (trackHeight <= 0 && !animate) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
const x = bandPos + seriesIndex * (squareSize + effectiveGroupGap);
|
|
187
|
+
const enterAnim = cascadeColumnTransition(enterTransition, chartAnimationDuration || 1100, index, staggerDelay, layout.count);
|
|
188
|
+
const animatedHeight = trackHeight > 0 ? trackHeight : 0;
|
|
189
|
+
if (animate) {
|
|
190
|
+
return (_jsx(motion.rect, { animate: { height: animatedHeight, y: 0 }, fill: fill, height: animatedHeight, initial: { height: baselineY, y: 0 }, opacity: effectiveOpacity, rx: rx, ry: rx, transition: enterAnim, width: squareSize, x: x }, `track-${index}-${seriesIndex}-${revealEpoch}`));
|
|
191
|
+
}
|
|
192
|
+
if (trackHeight <= 0) {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
return (_jsx("rect", { fill: fill, height: trackHeight, opacity: effectiveOpacity, rx: rx, ry: rx, width: squareSize, x: x, y: 0 }));
|
|
196
|
+
}
|
|
197
|
+
export function BarColumnTrack(props) {
|
|
198
|
+
const { barScale, bandWidth, barXAccessor } = useChartStable();
|
|
199
|
+
if (!(barScale && bandWidth && barXAccessor)) {
|
|
200
|
+
console.warn('BarColumnTrack must be used within a BarChart');
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
return (_jsx(BarColumnTrackInner, { ...props, bandWidth: bandWidth, barScale: barScale, barXAccessor: barXAccessor }));
|
|
204
|
+
}
|
|
205
|
+
BarColumnTrack.displayName = 'BarColumnTrack';
|
|
206
|
+
export default BarSquares;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface BarXAxisProps {
|
|
2
|
+
/** Width of the date ticker box for fade calculation. Default: 50 */
|
|
3
|
+
tickerHalfWidth?: number;
|
|
4
|
+
/** Whether to show all labels or skip some for dense data. Default: false */
|
|
5
|
+
showAllLabels?: boolean;
|
|
6
|
+
/** Maximum number of labels to show. Default: 12 */
|
|
7
|
+
maxLabels?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function BarXAxis(props: BarXAxisProps): import("react/jsx-runtime").JSX.Element | null;
|
|
10
|
+
export declare namespace BarXAxis {
|
|
11
|
+
var displayName: string;
|
|
12
|
+
}
|
|
13
|
+
export default BarXAxis;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* Vendored from bklit-ui — https://github.com/bklit/bklit-ui
|
|
5
|
+
* Copyright (c) 2026 uixmat. Released under the MIT licence; the full text is in
|
|
6
|
+
* LICENSE-bklit at the root of this package.
|
|
7
|
+
*
|
|
8
|
+
* Local change: the `@/lib/utils` import was repointed at this package's own
|
|
9
|
+
* `cn`, which is the same function. Nothing else is modified, so re-syncing
|
|
10
|
+
* with upstream stays a diff rather than a merge.
|
|
11
|
+
*/
|
|
12
|
+
import { motion } from 'motion/react';
|
|
13
|
+
import { memo, useEffect, useMemo, useState } from 'react';
|
|
14
|
+
import { createPortal } from 'react-dom';
|
|
15
|
+
import { cn } from '../../cn';
|
|
16
|
+
import { useChart, useChartStable } from './chart-context';
|
|
17
|
+
function BarXAxisLabel({ label, x, crosshairX, isHovering, tickerHalfWidth }) {
|
|
18
|
+
const fadeBuffer = 20;
|
|
19
|
+
const fadeRadius = tickerHalfWidth + fadeBuffer;
|
|
20
|
+
let opacity = 1;
|
|
21
|
+
if (isHovering && crosshairX !== null) {
|
|
22
|
+
const distance = Math.abs(x - crosshairX);
|
|
23
|
+
if (distance < tickerHalfWidth) {
|
|
24
|
+
opacity = 0;
|
|
25
|
+
}
|
|
26
|
+
else if (distance < fadeRadius) {
|
|
27
|
+
opacity = (distance - tickerHalfWidth) / fadeBuffer;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// Zero-width container approach for perfect centering
|
|
31
|
+
return (_jsx("div", { className: "absolute", style: {
|
|
32
|
+
left: x,
|
|
33
|
+
bottom: 12,
|
|
34
|
+
width: 0,
|
|
35
|
+
display: 'flex',
|
|
36
|
+
justifyContent: 'center',
|
|
37
|
+
}, children: _jsx(motion.span, { animate: { opacity }, className: cn('whitespace-nowrap text-chart-label text-xs'), initial: { opacity: 1 }, transition: { duration: 0.4, ease: 'easeInOut' }, children: label }) }));
|
|
38
|
+
}
|
|
39
|
+
export function BarXAxis(props) {
|
|
40
|
+
const { containerRef, barScale } = useChartStable();
|
|
41
|
+
const [mounted, setMounted] = useState(false);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
setMounted(true);
|
|
44
|
+
}, []);
|
|
45
|
+
const container = containerRef.current;
|
|
46
|
+
if (!(mounted && container)) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
if (!barScale) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return _jsx(BarXAxisInner, { ...props, container: container });
|
|
53
|
+
}
|
|
54
|
+
const BarXAxisInner = memo(function BarXAxisInner({ tickerHalfWidth = 50, showAllLabels = false, maxLabels = 12, container, }) {
|
|
55
|
+
const { margin, tooltipData, barScale, bandWidth, barXAccessor, data } = useChart();
|
|
56
|
+
// Generate labels for each bar
|
|
57
|
+
const labelsToShow = useMemo(() => {
|
|
58
|
+
if (!(barScale && bandWidth && barXAccessor)) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
const allLabels = data.map((d) => {
|
|
62
|
+
const label = barXAccessor(d);
|
|
63
|
+
const bandX = barScale(label) ?? 0;
|
|
64
|
+
// Center the label under the bar group
|
|
65
|
+
const x = bandX + bandWidth / 2 + margin.left;
|
|
66
|
+
return { label, x };
|
|
67
|
+
});
|
|
68
|
+
// If showAllLabels is true or we have fewer than maxLabels, show all
|
|
69
|
+
if (showAllLabels || allLabels.length <= maxLabels) {
|
|
70
|
+
return allLabels;
|
|
71
|
+
}
|
|
72
|
+
// Otherwise, skip some labels to avoid crowding
|
|
73
|
+
const step = Math.ceil(allLabels.length / maxLabels);
|
|
74
|
+
return allLabels.filter((_, i) => i % step === 0);
|
|
75
|
+
}, [barScale, bandWidth, barXAccessor, data, margin.left, showAllLabels, maxLabels]);
|
|
76
|
+
const isHovering = tooltipData !== null;
|
|
77
|
+
const crosshairX = tooltipData ? tooltipData.x + margin.left : null;
|
|
78
|
+
return createPortal(_jsx("div", { className: "pointer-events-none absolute inset-0", children: labelsToShow.map((item) => (_jsx(BarXAxisLabel, { crosshairX: crosshairX, isHovering: isHovering, label: item.label, tickerHalfWidth: tickerHalfWidth, x: item.x }, `${item.label}-${item.x}`))) }), container);
|
|
79
|
+
});
|
|
80
|
+
BarXAxis.displayName = 'BarXAxis';
|
|
81
|
+
export default BarXAxis;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface BarYAxisProps {
|
|
2
|
+
/** Whether to show all labels or skip some for dense data. Default: true */
|
|
3
|
+
showAllLabels?: boolean;
|
|
4
|
+
/** Maximum number of labels to show. Default: 20 */
|
|
5
|
+
maxLabels?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function BarYAxis(props: BarYAxisProps): import("react/jsx-runtime").JSX.Element | null;
|
|
8
|
+
export declare namespace BarYAxis {
|
|
9
|
+
var displayName: string;
|
|
10
|
+
}
|
|
11
|
+
export default BarYAxis;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* Vendored from bklit-ui — https://github.com/bklit/bklit-ui
|
|
5
|
+
* Copyright (c) 2026 uixmat. Released under the MIT licence; the full text is in
|
|
6
|
+
* LICENSE-bklit at the root of this package.
|
|
7
|
+
*
|
|
8
|
+
* Local change: the `@/lib/utils` import was repointed at this package's own
|
|
9
|
+
* `cn`, which is the same function. Nothing else is modified, so re-syncing
|
|
10
|
+
* with upstream stays a diff rather than a merge.
|
|
11
|
+
*/
|
|
12
|
+
import { motion } from 'motion/react';
|
|
13
|
+
import { memo, useEffect, useMemo, useState } from 'react';
|
|
14
|
+
import { createPortal } from 'react-dom';
|
|
15
|
+
import { cn } from '../../cn';
|
|
16
|
+
import { useChart, useChartStable } from './chart-context';
|
|
17
|
+
function BarYAxisLabel({ label, y, bandHeight, isHovered }) {
|
|
18
|
+
return (_jsx("div", { className: "absolute right-0 flex items-center justify-end pr-2", style: {
|
|
19
|
+
top: y,
|
|
20
|
+
height: bandHeight,
|
|
21
|
+
}, children: _jsx(motion.span, { animate: {
|
|
22
|
+
opacity: isHovered ? 1 : 0.7,
|
|
23
|
+
color: isHovered ? 'var(--foreground)' : 'var(--chart-label, var(--color-zinc-500))',
|
|
24
|
+
}, className: cn('truncate whitespace-nowrap text-right text-xs'), initial: {
|
|
25
|
+
opacity: 0.7,
|
|
26
|
+
color: 'var(--chart-label, var(--color-zinc-500))',
|
|
27
|
+
}, style: { maxWidth: 70 }, transition: { duration: 0.15 }, children: label }) }));
|
|
28
|
+
}
|
|
29
|
+
export function BarYAxis(props) {
|
|
30
|
+
const { containerRef, barScale } = useChartStable();
|
|
31
|
+
const [mounted, setMounted] = useState(false);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
setMounted(true);
|
|
34
|
+
}, []);
|
|
35
|
+
const container = containerRef.current;
|
|
36
|
+
if (!(mounted && container)) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (!barScale) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return _jsx(BarYAxisInner, { ...props, container: container });
|
|
43
|
+
}
|
|
44
|
+
const BarYAxisInner = memo(function BarYAxisInner({ showAllLabels = true, maxLabels = 20, container, }) {
|
|
45
|
+
const { margin, barScale, bandWidth, barXAccessor, data, hoveredBarIndex } = useChart();
|
|
46
|
+
// Generate labels for each bar
|
|
47
|
+
const labelsToShow = useMemo(() => {
|
|
48
|
+
if (!(barScale && bandWidth && barXAccessor)) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
const allLabels = data.map((d, i) => {
|
|
52
|
+
const label = barXAccessor(d);
|
|
53
|
+
const bandY = barScale(label) ?? 0;
|
|
54
|
+
// Center the label vertically within the band
|
|
55
|
+
const y = bandY + margin.top;
|
|
56
|
+
return { label, y, bandHeight: bandWidth, index: i };
|
|
57
|
+
});
|
|
58
|
+
// If showAllLabels is true or we have fewer than maxLabels, show all
|
|
59
|
+
if (showAllLabels || allLabels.length <= maxLabels) {
|
|
60
|
+
return allLabels;
|
|
61
|
+
}
|
|
62
|
+
// Otherwise, skip some labels to avoid crowding
|
|
63
|
+
const step = Math.ceil(allLabels.length / maxLabels);
|
|
64
|
+
return allLabels.filter((_, i) => i % step === 0);
|
|
65
|
+
}, [barScale, bandWidth, barXAccessor, data, margin.top, showAllLabels, maxLabels]);
|
|
66
|
+
return createPortal(_jsx("div", { className: "pointer-events-none absolute top-0 bottom-0", style: {
|
|
67
|
+
left: 0,
|
|
68
|
+
width: margin.left,
|
|
69
|
+
}, children: labelsToShow.map((item) => (_jsx(BarYAxisLabel, { bandHeight: item.bandHeight, isHovered: hoveredBarIndex === item.index, label: item.label, y: item.y }, `${item.label}-${item.y}`))) }), container);
|
|
70
|
+
});
|
|
71
|
+
BarYAxis.displayName = 'BarYAxis';
|
|
72
|
+
export default BarYAxis;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type BarLineCap = 'round' | 'butt' | number;
|
|
2
|
+
export type BarAnimationType = 'grow' | 'fade';
|
|
3
|
+
export interface BarProps {
|
|
4
|
+
/** Key in data to use for y values */
|
|
5
|
+
dataKey: string;
|
|
6
|
+
/** Y-scale group id for vertical bars (Recharts `yAxisId`). Default: `"left"`. */
|
|
7
|
+
yAxisId?: string | number;
|
|
8
|
+
/** Fill color for the bar. Can be a color, gradient url, or pattern url. Default: var(--chart-line-primary) */
|
|
9
|
+
fill?: string;
|
|
10
|
+
/** Color for tooltip dot. Use when fill is a gradient/pattern. Default: uses fill value */
|
|
11
|
+
stroke?: string;
|
|
12
|
+
/** Line cap style for bar ends: "round", "butt", or a number for custom radius. Default: "round" */
|
|
13
|
+
lineCap?: BarLineCap;
|
|
14
|
+
/** Whether to animate the bars. Default: true */
|
|
15
|
+
animate?: boolean;
|
|
16
|
+
/** Animation type: "grow" (height) or "fade" (opacity + blur). Default: "grow" */
|
|
17
|
+
animationType?: BarAnimationType;
|
|
18
|
+
/** Opacity when not hovered (when another bar is hovered). Default: 0.3 */
|
|
19
|
+
fadedOpacity?: number;
|
|
20
|
+
/** Stagger delay between bars in seconds. Auto-calculated if not provided. */
|
|
21
|
+
staggerDelay?: number;
|
|
22
|
+
/** Gap between stacked bars in pixels. Default: 0 */
|
|
23
|
+
stackGap?: number;
|
|
24
|
+
/** Gap between grouped bars in pixels. Default: 4 */
|
|
25
|
+
groupGap?: number;
|
|
26
|
+
/** Shrink each positive bar's top by its perspective rise so the front face
|
|
27
|
+
* lines up with `<BarDepthBack>`'s lid (instead of the lid sitting above the
|
|
28
|
+
* front face). Pass `true` whenever the chart also renders the bar-depth 3D
|
|
29
|
+
* surfaces. Default: false */
|
|
30
|
+
perspective?: boolean;
|
|
31
|
+
/** Minimum rendered bar height in px (non-stacked, vertical). Floors short or
|
|
32
|
+
* zero-value bars so they stay visible. Pair with the same value on
|
|
33
|
+
* `<BarDepthProvider minBarHeight>` when using the 3D surfaces. Default: 0 */
|
|
34
|
+
minBarHeight?: number;
|
|
35
|
+
}
|
|
36
|
+
export declare function Bar(props: BarProps): import("react/jsx-runtime").JSX.Element | null;
|
|
37
|
+
export declare namespace Bar {
|
|
38
|
+
var displayName: string;
|
|
39
|
+
}
|
|
40
|
+
export default Bar;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { motion } from 'motion/react';
|
|
4
|
+
import { memo, useId, useMemo } from 'react';
|
|
5
|
+
import { barDepthAndRise, barDepthMaxDepth } from './bar-depth-geometry';
|
|
6
|
+
import { chartCssVars, useChart, useChartStable, useYScale } from './chart-context';
|
|
7
|
+
import { useChartLegendHover } from './chart-legend-hover';
|
|
8
|
+
import { transitionWithDelay } from './motion-utils';
|
|
9
|
+
// ── Bar-depth perspective trim ───────────────────────────────────────────
|
|
10
|
+
// Uses the SHARED geometry (`bar-depth-geometry.ts`) so a
|
|
11
|
+
// `<Bar perspective>` front face lines up exactly with
|
|
12
|
+
// `<BarDepthBack>`'s lid — the formula lives in one place for both.
|
|
13
|
+
/** perspectiveRise for a positive bar whose visual top sits at `topY`.
|
|
14
|
+
* Returns 0 for a dead-center bar or a dense chart (degenerate depth). */
|
|
15
|
+
function barDepthPerspectiveRise(barScale, bandWidth, barXAccessor, innerWidth, datum, topY, baselineY) {
|
|
16
|
+
const centerX = innerWidth / 2;
|
|
17
|
+
if (centerX <= 0) {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
const step = barScale.step?.() ?? bandWidth;
|
|
21
|
+
const maxDepth = barDepthMaxDepth(step, bandWidth);
|
|
22
|
+
const bandX = barScale(barXAccessor(datum)) ?? 0;
|
|
23
|
+
const cx = bandX + bandWidth / 2;
|
|
24
|
+
const absOffset = Math.min(1, Math.abs((cx - centerX) / centerX));
|
|
25
|
+
const naturalHeight = Math.abs(baselineY - topY);
|
|
26
|
+
return barDepthAndRise(absOffset, naturalHeight, maxDepth).perspectiveRise;
|
|
27
|
+
}
|
|
28
|
+
function AnimatedBar({ x, y, width, height, fill, rx, ry, index, isFaded, animationType, innerHeight, fadedOpacity, staggerDelay, enterTransition, revealEpoch, isHorizontal, }) {
|
|
29
|
+
const enterAnim = transitionWithDelay(enterTransition, index * staggerDelay);
|
|
30
|
+
if (animationType === 'fade') {
|
|
31
|
+
return (_jsx(motion.rect, { animate: {
|
|
32
|
+
opacity: isFaded ? fadedOpacity : 1,
|
|
33
|
+
filter: 'blur(0px)',
|
|
34
|
+
}, fill: fill, height: height, initial: { opacity: 0, filter: 'blur(2px)' }, rx: rx, ry: ry, transition: enterAnim, width: width, x: x, y: y }, `fade-${index}-${revealEpoch}`));
|
|
35
|
+
}
|
|
36
|
+
const initial = isHorizontal
|
|
37
|
+
? { width: 0, height, x: 0, y }
|
|
38
|
+
: { width, height: 0, x, y: innerHeight };
|
|
39
|
+
const target = isHorizontal ? { width, height, x: 0, y } : { width, height, x, y };
|
|
40
|
+
return (_jsx("g", { opacity: isFaded ? fadedOpacity : 1, style: { transition: 'opacity 0.15s ease-in-out' }, children: _jsx(motion.rect, { animate: target, fill: fill, initial: initial, rx: rx, ry: ry, transition: enterAnim }, `grow-${index}-${revealEpoch}`) }));
|
|
41
|
+
}
|
|
42
|
+
const BarInner = memo(function BarInner({ dataKey, yAxisId, fill = chartCssVars.linePrimary, lineCap = 'round', animate = true, animationType = 'grow', fadedOpacity = 0.3, staggerDelay, stackGap = 0, groupGap = 4, perspective = false, minBarHeight = 0, barScale, bandWidth, barXAccessor, }) {
|
|
43
|
+
const { data, yScale: chartYScale, innerHeight, innerWidth, isLoaded, hoveredBarIndex, lines, orientation, stacked, stackOffsets, animationDuration, enterTransition, revealEpoch = 0, } = useChart();
|
|
44
|
+
// Calculate stagger delay automatically if not provided
|
|
45
|
+
// Total animation duration is ~1200ms, with 40% for stagger spread and 60% for bar animation
|
|
46
|
+
const totalAnimDuration = animationDuration || 1100;
|
|
47
|
+
const staggerSpread = totalAnimDuration * 0.4; // 40% of time for stagger spread
|
|
48
|
+
const calculatedStaggerDelay = staggerDelay ?? (data.length > 1 ? staggerSpread / 1000 / data.length : 0);
|
|
49
|
+
const uniqueId = useId();
|
|
50
|
+
const isHorizontal = orientation === 'horizontal';
|
|
51
|
+
// Find the index of this bar series among all bar series
|
|
52
|
+
const { hoveredIndex: legendHoveredIndex } = useChartLegendHover();
|
|
53
|
+
const seriesIndex = useMemo(() => {
|
|
54
|
+
const idx = lines.findIndex((l) => l.dataKey === dataKey);
|
|
55
|
+
return idx >= 0 ? idx : 0;
|
|
56
|
+
}, [lines, dataKey]);
|
|
57
|
+
const seriesConfig = lines[seriesIndex];
|
|
58
|
+
const valueScale = useYScale(yAxisId ?? seriesConfig?.yAxisId);
|
|
59
|
+
const isLegendDimmed = legendHoveredIndex !== null && legendHoveredIndex !== seriesIndex;
|
|
60
|
+
const seriesCount = lines.length;
|
|
61
|
+
const isLastSeries = seriesIndex === seriesCount - 1;
|
|
62
|
+
// Calculate the width for each bar within a group (for non-stacked)
|
|
63
|
+
const barWidth = useMemo(() => {
|
|
64
|
+
if (!bandWidth || seriesCount === 0) {
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
if (stacked) {
|
|
68
|
+
// Stacked bars use full band width
|
|
69
|
+
return bandWidth;
|
|
70
|
+
}
|
|
71
|
+
// Leave a gap between grouped bars (controlled by groupGap prop)
|
|
72
|
+
const effectiveGroupGap = seriesCount > 1 ? groupGap : 0;
|
|
73
|
+
return (bandWidth - effectiveGroupGap * (seriesCount - 1)) / seriesCount;
|
|
74
|
+
}, [bandWidth, seriesCount, stacked, groupGap]);
|
|
75
|
+
// Calculate corner radius based on lineCap. Perspective bars force a flat
|
|
76
|
+
// top (radius 0) so the 3D lid from `<BarDepthBack>` meets the bar with no
|
|
77
|
+
// gap — rounded corners would leave a wedge, so `perspective` overrides it.
|
|
78
|
+
const cornerRadius = useMemo(() => {
|
|
79
|
+
if (perspective) {
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
if (typeof lineCap === 'number') {
|
|
83
|
+
return lineCap;
|
|
84
|
+
}
|
|
85
|
+
if (lineCap === 'round' && barWidth) {
|
|
86
|
+
return Math.min(barWidth / 2, 8);
|
|
87
|
+
}
|
|
88
|
+
return 0;
|
|
89
|
+
}, [lineCap, barWidth, perspective]);
|
|
90
|
+
return (_jsx("g", { className: `bar-series-${uniqueId}`, children: data.map((d, i) => {
|
|
91
|
+
const value = d[dataKey];
|
|
92
|
+
if (typeof value !== 'number') {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
const categoryValue = barXAccessor(d);
|
|
96
|
+
const bandPos = barScale(categoryValue) ?? 0;
|
|
97
|
+
let x;
|
|
98
|
+
let y;
|
|
99
|
+
let barHeight;
|
|
100
|
+
let barW;
|
|
101
|
+
const scale = isHorizontal ? chartYScale : valueScale;
|
|
102
|
+
if (isHorizontal) {
|
|
103
|
+
// Horizontal bars: category on y-axis, value on x-axis
|
|
104
|
+
const valuePos = scale(value) ?? 0;
|
|
105
|
+
barW = valuePos; // Width is the value position (grows from left)
|
|
106
|
+
barHeight = barWidth;
|
|
107
|
+
if (stacked && stackOffsets) {
|
|
108
|
+
const offset = stackOffsets.get(i)?.get(dataKey) ?? 0;
|
|
109
|
+
x = scale(offset) ?? 0;
|
|
110
|
+
barW = valuePos - x;
|
|
111
|
+
// Apply stack gap for horizontal: shift right and reduce width
|
|
112
|
+
const gapOffset = seriesIndex * stackGap;
|
|
113
|
+
x += gapOffset;
|
|
114
|
+
if (!isLastSeries && stackGap > 0) {
|
|
115
|
+
barW = Math.max(0, barW - stackGap);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
x = 0;
|
|
120
|
+
// For grouped bars, offset y position
|
|
121
|
+
const effectiveGroupGap = seriesCount > 1 ? groupGap : 0;
|
|
122
|
+
y = bandPos + seriesIndex * (barWidth + effectiveGroupGap);
|
|
123
|
+
}
|
|
124
|
+
y = stacked
|
|
125
|
+
? bandPos
|
|
126
|
+
: bandPos + seriesIndex * (barWidth + (seriesCount > 1 ? groupGap : 0));
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
// Vertical bars: category on x-axis, value on y-axis
|
|
130
|
+
const valuePos = scale(value) ?? 0;
|
|
131
|
+
barHeight = innerHeight - valuePos;
|
|
132
|
+
barW = barWidth;
|
|
133
|
+
if (stacked && stackOffsets) {
|
|
134
|
+
const offset = stackOffsets.get(i)?.get(dataKey) ?? 0;
|
|
135
|
+
const offsetY = scale(offset) ?? innerHeight;
|
|
136
|
+
// Apply stack gap: shift up and reduce height
|
|
137
|
+
const gapOffset = seriesIndex * stackGap;
|
|
138
|
+
y = offsetY - barHeight - gapOffset;
|
|
139
|
+
// Reduce height slightly for non-last bars to create visual gap
|
|
140
|
+
if (!isLastSeries && stackGap > 0) {
|
|
141
|
+
barHeight = Math.max(0, barHeight - stackGap);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
y = valuePos;
|
|
146
|
+
// For grouped bars, offset x position
|
|
147
|
+
const effectiveGroupGap = seriesCount > 1 ? groupGap : 0;
|
|
148
|
+
x = bandPos + seriesIndex * (barWidth + effectiveGroupGap);
|
|
149
|
+
}
|
|
150
|
+
x = stacked
|
|
151
|
+
? bandPos
|
|
152
|
+
: bandPos + seriesIndex * (barWidth + (seriesCount > 1 ? groupGap : 0));
|
|
153
|
+
// Minimum visible height — floor short/zero non-stacked bars so a
|
|
154
|
+
// zero-value data point still reads as a tiny bar instead of
|
|
155
|
+
// vanishing. Grows up from the baseline. Floored bars skip the
|
|
156
|
+
// perspective trim (sub-pixel on a 3px bar; keeps the front aligned
|
|
157
|
+
// with bar-depth, which also skips trim for floored bars).
|
|
158
|
+
let isFloored = false;
|
|
159
|
+
if (!stacked && minBarHeight > 0 && value >= 0 && barHeight < minBarHeight) {
|
|
160
|
+
const baselineY = scale(0) ?? innerHeight;
|
|
161
|
+
barHeight = minBarHeight;
|
|
162
|
+
y = baselineY - minBarHeight;
|
|
163
|
+
isFloored = true;
|
|
164
|
+
}
|
|
165
|
+
// Perspective trim — shrink the topmost positive bar's front-face
|
|
166
|
+
// top down by its perspective rise so it meets `<BarDepthBack>`'s
|
|
167
|
+
// lid back edge. Stacked: only the last (topmost) series; grouped or
|
|
168
|
+
// single: every positive bar. Clamped to `barHeight - 1` so very
|
|
169
|
+
// short bars keep a positive height (matches bar-depth's clamp).
|
|
170
|
+
if (perspective && value > 0 && !isFloored && (!stacked || isLastSeries)) {
|
|
171
|
+
const baselineY = scale(0) ?? innerHeight;
|
|
172
|
+
const rise = barDepthPerspectiveRise(barScale, bandWidth, barXAccessor, innerWidth, d, y, baselineY);
|
|
173
|
+
const trim = Math.min(rise, Math.max(0, barHeight - 1));
|
|
174
|
+
y += trim;
|
|
175
|
+
barHeight -= trim;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const isFaded = (hoveredBarIndex !== null && hoveredBarIndex !== i) || isLegendDimmed;
|
|
179
|
+
// Use categoryValue as key since it's the unique identifier from data
|
|
180
|
+
const barKey = `bar-${dataKey}-${categoryValue}`;
|
|
181
|
+
// Apply rounded corners:
|
|
182
|
+
// - For non-stacked: always apply
|
|
183
|
+
// - For stacked with gap: apply to all bars
|
|
184
|
+
// - For stacked without gap: only apply to the last series
|
|
185
|
+
const applyRounding = !stacked || stackGap > 0 || isLastSeries;
|
|
186
|
+
const effectiveRx = applyRounding ? cornerRadius : 0;
|
|
187
|
+
const effectiveRy = applyRounding ? cornerRadius : 0;
|
|
188
|
+
if (animate && !isLoaded) {
|
|
189
|
+
return (_jsx(AnimatedBar, { animationType: animationType, enterTransition: enterTransition, fadedOpacity: fadedOpacity, fill: fill, height: barHeight, index: i, innerHeight: innerHeight, isFaded: isFaded, isHorizontal: isHorizontal, revealEpoch: revealEpoch, rx: effectiveRx, ry: effectiveRy, staggerDelay: calculatedStaggerDelay, width: barW, x: x, y: y }, barKey));
|
|
190
|
+
}
|
|
191
|
+
// Static bar after animation completes
|
|
192
|
+
return (_jsx("rect", { fill: fill, height: barHeight, opacity: isFaded ? fadedOpacity : 1, rx: effectiveRx, ry: effectiveRy, style: {
|
|
193
|
+
cursor: 'default',
|
|
194
|
+
transition: 'opacity 0.15s ease-in-out',
|
|
195
|
+
}, width: barW, x: x, y: y }, barKey));
|
|
196
|
+
}) }));
|
|
197
|
+
});
|
|
198
|
+
export function Bar(props) {
|
|
199
|
+
const { barScale, bandWidth, barXAccessor } = useChartStable();
|
|
200
|
+
if (!(barScale && bandWidth && barXAccessor)) {
|
|
201
|
+
console.warn('Bar component must be used within a BarChart');
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
return (_jsx(BarInner, { ...props, bandWidth: bandWidth, barScale: barScale, barXAccessor: barXAccessor }));
|
|
205
|
+
}
|
|
206
|
+
Bar.displayName = 'Bar';
|
|
207
|
+
export default Bar;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendored from bklit-ui — https://github.com/bklit/bklit-ui
|
|
3
|
+
* Copyright (c) 2026 uixmat. Released under the MIT licence; the full text is in
|
|
4
|
+
* LICENSE-bklit at the root of this package.
|
|
5
|
+
*
|
|
6
|
+
* Local change: the `@/lib/utils` import was repointed at this package's own
|
|
7
|
+
* `cn`, which is the same function. Nothing else is modified, so re-syncing
|
|
8
|
+
* with upstream stays a diff rather than a merge.
|
|
9
|
+
*/
|
|
10
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
11
|
+
/** Marker on wrapper components whose single child should inherit clip classification. */
|
|
12
|
+
export declare const CHART_CLIP_PASSTHROUGH: "__chartClipPassthrough";
|
|
13
|
+
export declare function isChartClipPassthrough(type: unknown): boolean;
|
|
14
|
+
/** Unwrap visibility wrappers so `Grid` / axes stay outside the series clip. */
|
|
15
|
+
export declare function resolveChartChildElement(child: ReactElement): ReactElement;
|
|
16
|
+
/** Walk chart children, flattening React fragments (studio often groups layers in `<>...</>`). */
|
|
17
|
+
export declare function forEachChartChild(children: ReactNode, callback: (child: ReactElement, index: number) => void): void;
|
|
18
|
+
/** Markers render after the interaction overlay so they stay clickable. */
|
|
19
|
+
export declare function isPostOverlayComponent(child: ReactElement): boolean;
|
|
20
|
+
/** Renders above grid/axes but below series; excluded from grow-clip reveal. */
|
|
21
|
+
export declare function isUnderlayComponent(child: ReactElement): boolean;
|
|
22
|
+
/** Grid and axes stay visible during series clip reveal (e.g. loading → ready). */
|
|
23
|
+
export declare function isClipExcludedComponent(child: ReactElement): boolean;
|
|
24
|
+
/** SVG layer lists from chart shells need stable keys when rendered as arrays. */
|
|
25
|
+
export declare function renderKeyedChartLayers(children: ReactElement[]): ReactElement<unknown, string | import("react").JSXElementConstructor<any>>[];
|