@coinbase/cds-web-visualization 3.3.0 → 3.4.0-beta.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/CHANGELOG.md +30 -0
- package/dts/chart/CartesianChart.d.ts +36 -0
- package/dts/chart/CartesianChart.d.ts.map +1 -0
- package/dts/chart/ChartProvider.d.ts +6 -0
- package/dts/chart/ChartProvider.d.ts.map +1 -0
- package/dts/chart/Path.d.ts +34 -0
- package/dts/chart/Path.d.ts.map +1 -0
- package/dts/chart/PeriodSelector.d.ts +61 -0
- package/dts/chart/PeriodSelector.d.ts.map +1 -0
- package/dts/chart/Point.d.ts +153 -0
- package/dts/chart/Point.d.ts.map +1 -0
- package/dts/chart/area/Area.d.ts +48 -0
- package/dts/chart/area/Area.d.ts.map +1 -0
- package/dts/chart/area/AreaChart.d.ts +52 -0
- package/dts/chart/area/AreaChart.d.ts.map +1 -0
- package/dts/chart/area/DottedArea.d.ts +68 -0
- package/dts/chart/area/DottedArea.d.ts.map +1 -0
- package/dts/chart/area/GradientArea.d.ts +30 -0
- package/dts/chart/area/GradientArea.d.ts.map +1 -0
- package/dts/chart/area/SolidArea.d.ts +8 -0
- package/dts/chart/area/SolidArea.d.ts.map +1 -0
- package/dts/chart/area/index.d.ts +6 -0
- package/dts/chart/area/index.d.ts.map +1 -0
- package/dts/chart/axis/Axis.d.ts +208 -0
- package/dts/chart/axis/Axis.d.ts.map +1 -0
- package/dts/chart/axis/XAxis.d.ts +16 -0
- package/dts/chart/axis/XAxis.d.ts.map +1 -0
- package/dts/chart/axis/YAxis.d.ts +21 -0
- package/dts/chart/axis/YAxis.d.ts.map +1 -0
- package/dts/chart/axis/index.d.ts +4 -0
- package/dts/chart/axis/index.d.ts.map +1 -0
- package/dts/chart/bar/Bar.d.ts +91 -0
- package/dts/chart/bar/Bar.d.ts.map +1 -0
- package/dts/chart/bar/BarChart.d.ts +53 -0
- package/dts/chart/bar/BarChart.d.ts.map +1 -0
- package/dts/chart/bar/BarPlot.d.ts +29 -0
- package/dts/chart/bar/BarPlot.d.ts.map +1 -0
- package/dts/chart/bar/BarStack.d.ts +111 -0
- package/dts/chart/bar/BarStack.d.ts.map +1 -0
- package/dts/chart/bar/BarStackGroup.d.ts +35 -0
- package/dts/chart/bar/BarStackGroup.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBar.d.ts +17 -0
- package/dts/chart/bar/DefaultBar.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBarStack.d.ts +16 -0
- package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -0
- package/dts/chart/bar/index.d.ts +8 -0
- package/dts/chart/bar/index.d.ts.map +1 -0
- package/dts/chart/index.d.ts +13 -0
- package/dts/chart/index.d.ts.map +1 -0
- package/dts/chart/line/DottedLine.d.ts +14 -0
- package/dts/chart/line/DottedLine.d.ts.map +1 -0
- package/dts/chart/line/GradientLine.d.ts +42 -0
- package/dts/chart/line/GradientLine.d.ts.map +1 -0
- package/dts/chart/line/Line.d.ts +80 -0
- package/dts/chart/line/Line.d.ts.map +1 -0
- package/dts/chart/line/LineChart.d.ts +59 -0
- package/dts/chart/line/LineChart.d.ts.map +1 -0
- package/dts/chart/line/ReferenceLine.d.ts +131 -0
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -0
- package/dts/chart/line/SolidLine.d.ts +14 -0
- package/dts/chart/line/SolidLine.d.ts.map +1 -0
- package/dts/chart/line/index.d.ts +7 -0
- package/dts/chart/line/index.d.ts.map +1 -0
- package/dts/chart/scrubber/Scrubber.d.ts +149 -0
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeacon.d.ts +93 -0
- package/dts/chart/scrubber/ScrubberBeacon.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts +7 -0
- package/dts/chart/scrubber/ScrubberBeaconLabel.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts +17 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -0
- package/dts/chart/scrubber/index.d.ts +2 -0
- package/dts/chart/scrubber/index.d.ts.map +1 -0
- package/dts/chart/text/ChartText.d.ts +114 -0
- package/dts/chart/text/ChartText.d.ts.map +1 -0
- package/dts/chart/text/SmartChartTextGroup.d.ts +55 -0
- package/dts/chart/text/SmartChartTextGroup.d.ts.map +1 -0
- package/dts/chart/text/index.d.ts +3 -0
- package/dts/chart/text/index.d.ts.map +1 -0
- package/dts/chart/utils/axis.d.ts +342 -0
- package/dts/chart/utils/axis.d.ts.map +1 -0
- package/dts/chart/utils/bar.d.ts +20 -0
- package/dts/chart/utils/bar.d.ts.map +1 -0
- package/dts/chart/utils/chart.d.ts +97 -0
- package/dts/chart/utils/chart.d.ts.map +1 -0
- package/dts/chart/utils/context.d.ts +95 -0
- package/dts/chart/utils/context.d.ts.map +1 -0
- package/dts/chart/utils/index.d.ts +8 -0
- package/dts/chart/utils/index.d.ts.map +1 -0
- package/dts/chart/utils/path.d.ts +107 -0
- package/dts/chart/utils/path.d.ts.map +1 -0
- package/dts/chart/utils/point.d.ts +75 -0
- package/dts/chart/utils/point.d.ts.map +1 -0
- package/dts/chart/utils/scale.d.ts +43 -0
- package/dts/chart/utils/scale.d.ts.map +1 -0
- package/dts/index.d.ts +2 -1
- package/dts/index.d.ts.map +1 -1
- package/dts/sparkline/Counter.d.ts +7 -2
- package/dts/sparkline/Sparkline.d.ts +61 -16
- package/dts/sparkline/Sparkline.d.ts.map +1 -1
- package/dts/sparkline/SparklineArea.d.ts +12 -4
- package/dts/sparkline/SparklineArea.d.ts.map +1 -1
- package/dts/sparkline/SparklineAreaPattern.d.ts +12 -4
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -1
- package/dts/sparkline/SparklineGradient.d.ts +21 -10
- package/dts/sparkline/SparklineGradient.d.ts.map +1 -1
- package/dts/sparkline/SparklinePath.d.ts +8 -6
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts +1 -1
- package/dts/sparkline/generateSparklineWithId.d.ts +8 -2
- package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -1
- package/dts/sparkline/index.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive/InnerSparklineInteractiveProvider.d.ts +9 -5
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +168 -118
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +22 -9
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +4 -2
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverPrice.d.ts +4 -2
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +5 -3
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +11 -6
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +21 -7
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +21 -16
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +17 -12
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubHandler.d.ts +23 -10
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveScrubProvider.d.ts +12 -12
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +22 -14
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive/fade.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +11 -11
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +101 -93
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +1 -1
- package/esm/chart/CartesianChart.css +1 -0
- package/esm/chart/CartesianChart.js +258 -0
- package/esm/chart/ChartProvider.js +10 -0
- package/esm/chart/Path.js +89 -0
- package/esm/chart/PeriodSelector.css +1 -0
- package/esm/chart/PeriodSelector.js +126 -0
- package/esm/chart/Point.css +2 -0
- package/esm/chart/Point.js +171 -0
- package/esm/chart/area/Area.js +85 -0
- package/esm/chart/area/AreaChart.js +164 -0
- package/esm/chart/area/DottedArea.js +141 -0
- package/esm/chart/area/GradientArea.js +111 -0
- package/esm/chart/area/SolidArea.js +29 -0
- package/esm/chart/area/index.js +7 -0
- package/esm/chart/axis/Axis.js +46 -0
- package/esm/chart/axis/XAxis.css +2 -0
- package/esm/chart/axis/XAxis.js +195 -0
- package/esm/chart/axis/YAxis.css +2 -0
- package/esm/chart/axis/YAxis.js +183 -0
- package/esm/chart/axis/index.js +5 -0
- package/esm/chart/bar/Bar.js +59 -0
- package/esm/chart/bar/BarChart.js +147 -0
- package/esm/chart/bar/BarPlot.js +96 -0
- package/esm/chart/bar/BarStack.js +519 -0
- package/esm/chart/bar/BarStackGroup.js +96 -0
- package/esm/chart/bar/DefaultBar.js +64 -0
- package/esm/chart/bar/DefaultBarStack.js +60 -0
- package/esm/chart/bar/index.js +9 -0
- package/esm/chart/index.js +14 -0
- package/esm/chart/line/DottedLine.js +38 -0
- package/esm/chart/line/GradientLine.js +58 -0
- package/esm/chart/line/Line.js +159 -0
- package/esm/chart/line/LineChart.js +120 -0
- package/esm/chart/line/ReferenceLine.js +142 -0
- package/esm/chart/line/SolidLine.js +34 -0
- package/esm/chart/line/index.js +8 -0
- package/esm/chart/scrubber/Scrubber.js +483 -0
- package/esm/chart/scrubber/ScrubberBeacon.js +195 -0
- package/esm/chart/scrubber/ScrubberBeaconLabel.js +33 -0
- package/esm/chart/scrubber/ScrubberProvider.js +228 -0
- package/esm/chart/scrubber/index.js +2 -0
- package/esm/chart/text/ChartText.js +236 -0
- package/esm/chart/text/SmartChartTextGroup.js +226 -0
- package/esm/chart/text/index.js +4 -0
- package/esm/chart/utils/axis.js +593 -0
- package/esm/chart/utils/bar.js +24 -0
- package/esm/chart/utils/chart.js +229 -0
- package/esm/chart/utils/context.js +15 -0
- package/esm/chart/utils/index.js +9 -0
- package/esm/chart/utils/path.js +204 -0
- package/esm/chart/utils/point.js +118 -0
- package/esm/chart/utils/scale.js +48 -0
- package/esm/index.js +4 -1
- package/esm/sparkline/Sparkline.js +129 -15
- package/esm/sparkline/SparklineArea.js +7 -2
- package/esm/sparkline/SparklineAreaPattern.js +4 -2
- package/esm/sparkline/SparklineGradient.js +16 -58
- package/esm/sparkline/generateSparklineWithId.js +3 -2
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +5 -1
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +5 -2
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +4 -0
- package/package.json +15 -11
- package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts +0 -374
- package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts +0 -87
- package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts.map +0 -1
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
3
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
4
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
5
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
|
+
import React, { memo, useMemo } from 'react';
|
|
7
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
8
|
+
import { Bar } from './Bar';
|
|
9
|
+
import { DefaultBarStack } from './DefaultBarStack';
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
/**
|
|
12
|
+
* BarStack component that renders a single stack of bars at a specific category index.
|
|
13
|
+
* Handles the stacking logic for bars within a single category.
|
|
14
|
+
*/
|
|
15
|
+
export const BarStack = /*#__PURE__*/memo(_ref => {
|
|
16
|
+
let {
|
|
17
|
+
series,
|
|
18
|
+
categoryIndex,
|
|
19
|
+
x,
|
|
20
|
+
width,
|
|
21
|
+
yScale,
|
|
22
|
+
rect,
|
|
23
|
+
BarComponent: defaultBarComponent,
|
|
24
|
+
fillOpacity: defaultFillOpacity,
|
|
25
|
+
stroke: defaultStroke,
|
|
26
|
+
strokeWidth: defaultStrokeWidth,
|
|
27
|
+
borderRadius = 4,
|
|
28
|
+
BarStackComponent = DefaultBarStack,
|
|
29
|
+
stackGap,
|
|
30
|
+
barMinSize,
|
|
31
|
+
stackMinSize,
|
|
32
|
+
roundBaseline
|
|
33
|
+
} = _ref;
|
|
34
|
+
const {
|
|
35
|
+
getSeriesData,
|
|
36
|
+
getXAxis
|
|
37
|
+
} = useCartesianChartContext();
|
|
38
|
+
const stackGapPx = stackGap;
|
|
39
|
+
const barMinSizePx = barMinSize;
|
|
40
|
+
const stackMinSizePx = stackMinSize;
|
|
41
|
+
const xAxis = getXAxis();
|
|
42
|
+
const baseline = useMemo(() => {
|
|
43
|
+
var _yScale;
|
|
44
|
+
const domain = yScale.domain();
|
|
45
|
+
const [domainMin, domainMax] = domain;
|
|
46
|
+
const baselineValue = domainMin >= 0 ? domainMin : domainMax <= 0 ? domainMax : 0;
|
|
47
|
+
const baseline = (_yScale = yScale(baselineValue)) !== null && _yScale !== void 0 ? _yScale : rect.y + rect.height;
|
|
48
|
+
return Math.max(rect.y, Math.min(baseline, rect.y + rect.height));
|
|
49
|
+
}, [rect.height, rect.y, yScale]);
|
|
50
|
+
|
|
51
|
+
// Calculate bars for this specific category
|
|
52
|
+
const {
|
|
53
|
+
bars,
|
|
54
|
+
stackRect
|
|
55
|
+
} = useMemo(() => {
|
|
56
|
+
let allBars = [];
|
|
57
|
+
|
|
58
|
+
// Track how many bars we've stacked in each direction for gap calculation
|
|
59
|
+
let positiveBarCount = 0;
|
|
60
|
+
let negativeBarCount = 0;
|
|
61
|
+
|
|
62
|
+
// Track stack bounds for clipping
|
|
63
|
+
let minY = Infinity;
|
|
64
|
+
let maxY = -Infinity;
|
|
65
|
+
|
|
66
|
+
// Process each series in the stack
|
|
67
|
+
series.forEach(s => {
|
|
68
|
+
var _yScale2, _yScale3;
|
|
69
|
+
const data = getSeriesData(s.id);
|
|
70
|
+
if (!data) return;
|
|
71
|
+
const value = data[categoryIndex];
|
|
72
|
+
if (value === null || value === undefined) return;
|
|
73
|
+
const originalData = s.data;
|
|
74
|
+
const originalValue = originalData === null || originalData === void 0 ? void 0 : originalData[categoryIndex];
|
|
75
|
+
// Only apply gap logic if the original data wasn't tuple format
|
|
76
|
+
const shouldApplyGap = !Array.isArray(originalValue);
|
|
77
|
+
|
|
78
|
+
// Sort to be in ascending order
|
|
79
|
+
const [bottom, top] = value.sort((a, b) => a - b);
|
|
80
|
+
const isAboveBaseline = bottom >= 0 && top !== bottom;
|
|
81
|
+
const isBelowBaseline = bottom <= 0 && bottom !== top;
|
|
82
|
+
const barBottom = (_yScale2 = yScale(bottom)) !== null && _yScale2 !== void 0 ? _yScale2 : baseline;
|
|
83
|
+
const barTop = (_yScale3 = yScale(top)) !== null && _yScale3 !== void 0 ? _yScale3 : baseline;
|
|
84
|
+
|
|
85
|
+
// Track bar counts for later gap calculations
|
|
86
|
+
if (shouldApplyGap) {
|
|
87
|
+
if (isAboveBaseline) {
|
|
88
|
+
positiveBarCount++;
|
|
89
|
+
} else if (isBelowBaseline) {
|
|
90
|
+
negativeBarCount++;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Calculate height (remember SVG y coordinates are inverted)
|
|
95
|
+
const height = Math.abs(barBottom - barTop);
|
|
96
|
+
const y = Math.min(barBottom, barTop);
|
|
97
|
+
|
|
98
|
+
// Skip bars that would have zero or negative height
|
|
99
|
+
if (height <= 0) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Update stack bounds
|
|
104
|
+
minY = Math.min(minY, y);
|
|
105
|
+
maxY = Math.max(maxY, y + height);
|
|
106
|
+
allBars.push({
|
|
107
|
+
seriesId: s.id,
|
|
108
|
+
x,
|
|
109
|
+
y,
|
|
110
|
+
width,
|
|
111
|
+
height,
|
|
112
|
+
dataY: value,
|
|
113
|
+
// Store the actual data value
|
|
114
|
+
// Use series-specific properties, falling back to defaults
|
|
115
|
+
BarComponent: s.BarComponent,
|
|
116
|
+
fill: s.fill || s.color || 'var(--color-fgPrimary)',
|
|
117
|
+
fillOpacity: s.fillOpacity,
|
|
118
|
+
stroke: s.stroke,
|
|
119
|
+
strokeWidth: s.strokeWidth,
|
|
120
|
+
// Pass context data for custom components
|
|
121
|
+
roundTop: roundBaseline || barTop !== baseline,
|
|
122
|
+
roundBottom: roundBaseline || barBottom !== baseline,
|
|
123
|
+
shouldApplyGap
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Apply proportional gap distribution to maintain total stack height
|
|
128
|
+
if (stackGapPx && allBars.length > 1) {
|
|
129
|
+
// Separate bars by baseline side
|
|
130
|
+
const barsAboveBaseline = allBars.filter(bar => {
|
|
131
|
+
const [bottom, top] = bar.dataY.sort((a, b) => a - b);
|
|
132
|
+
return bottom >= 0 && top !== bottom && bar.shouldApplyGap;
|
|
133
|
+
});
|
|
134
|
+
const barsBelowBaseline = allBars.filter(bar => {
|
|
135
|
+
const [bottom, top] = bar.dataY.sort((a, b) => a - b);
|
|
136
|
+
return bottom <= 0 && bottom !== top && bar.shouldApplyGap;
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Apply proportional gaps to bars above baseline
|
|
140
|
+
if (barsAboveBaseline.length > 1) {
|
|
141
|
+
const totalGapSpace = stackGapPx * (barsAboveBaseline.length - 1);
|
|
142
|
+
const totalDataHeight = barsAboveBaseline.reduce((sum, bar) => sum + bar.height, 0);
|
|
143
|
+
const heightReduction = totalGapSpace / totalDataHeight;
|
|
144
|
+
|
|
145
|
+
// Sort bars by position (from baseline upward)
|
|
146
|
+
const sortedBars = barsAboveBaseline.sort((a, b) => b.y - a.y);
|
|
147
|
+
let currentY = baseline;
|
|
148
|
+
sortedBars.forEach((bar, index) => {
|
|
149
|
+
// Reduce bar height proportionally
|
|
150
|
+
const newHeight = bar.height * (1 - heightReduction);
|
|
151
|
+
const newY = currentY - newHeight;
|
|
152
|
+
|
|
153
|
+
// Update the bar in allBars array
|
|
154
|
+
const barIndex = allBars.findIndex(b => b.seriesId === bar.seriesId);
|
|
155
|
+
if (barIndex !== -1) {
|
|
156
|
+
allBars[barIndex] = _objectSpread(_objectSpread({}, allBars[barIndex]), {}, {
|
|
157
|
+
height: newHeight,
|
|
158
|
+
y: newY
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Move to next position (include gap for next bar)
|
|
163
|
+
currentY = newY - (index < sortedBars.length - 1 ? stackGapPx : 0);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Apply proportional gaps to bars below baseline
|
|
168
|
+
if (barsBelowBaseline.length > 1) {
|
|
169
|
+
const totalGapSpace = stackGapPx * (barsBelowBaseline.length - 1);
|
|
170
|
+
const totalDataHeight = barsBelowBaseline.reduce((sum, bar) => sum + bar.height, 0);
|
|
171
|
+
const heightReduction = totalGapSpace / totalDataHeight;
|
|
172
|
+
|
|
173
|
+
// Sort bars by position (from baseline downward)
|
|
174
|
+
const sortedBars = barsBelowBaseline.sort((a, b) => a.y - b.y);
|
|
175
|
+
let currentY = baseline;
|
|
176
|
+
sortedBars.forEach((bar, index) => {
|
|
177
|
+
// Reduce bar height proportionally
|
|
178
|
+
const newHeight = bar.height * (1 - heightReduction);
|
|
179
|
+
|
|
180
|
+
// Update the bar in allBars array
|
|
181
|
+
const barIndex = allBars.findIndex(b => b.seriesId === bar.seriesId);
|
|
182
|
+
if (barIndex !== -1) {
|
|
183
|
+
allBars[barIndex] = _objectSpread(_objectSpread({}, allBars[barIndex]), {}, {
|
|
184
|
+
height: newHeight,
|
|
185
|
+
y: currentY
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Move to next position (include gap for next bar)
|
|
190
|
+
currentY = currentY + newHeight + (index < sortedBars.length - 1 ? stackGapPx : 0);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Recalculate stack bounds after gap adjustments
|
|
195
|
+
if (allBars.length > 0) {
|
|
196
|
+
minY = Math.min(...allBars.map(bar => bar.y));
|
|
197
|
+
maxY = Math.max(...allBars.map(bar => bar.y + bar.height));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Apply barMinSize constraints
|
|
202
|
+
if (barMinSizePx) {
|
|
203
|
+
// First, expand bars that need it and track the expansion
|
|
204
|
+
const expandedBars = allBars.map((bar, index) => {
|
|
205
|
+
if (bar.height < barMinSizePx) {
|
|
206
|
+
var _yScale4, _yScale5, _yScale6, _yScale7;
|
|
207
|
+
const heightIncrease = barMinSizePx - bar.height;
|
|
208
|
+
const bottom = 0;
|
|
209
|
+
const top = 0;
|
|
210
|
+
|
|
211
|
+
// Determine how to expand the bar
|
|
212
|
+
let newBottom = bottom;
|
|
213
|
+
let newTop = top;
|
|
214
|
+
const scaleUnit = Math.abs(((_yScale4 = yScale(1)) !== null && _yScale4 !== void 0 ? _yScale4 : 0) - ((_yScale5 = yScale(0)) !== null && _yScale5 !== void 0 ? _yScale5 : 0));
|
|
215
|
+
if (bottom === 0) {
|
|
216
|
+
// Expand away from baseline (upward for positive)
|
|
217
|
+
newTop = top + heightIncrease / scaleUnit;
|
|
218
|
+
} else if (top === 0) {
|
|
219
|
+
// Expand away from baseline (downward for negative)
|
|
220
|
+
newBottom = bottom - heightIncrease / scaleUnit;
|
|
221
|
+
} else {
|
|
222
|
+
// Expand in both directions
|
|
223
|
+
const halfIncrease = heightIncrease / scaleUnit / 2;
|
|
224
|
+
newBottom = bottom - halfIncrease;
|
|
225
|
+
newTop = top + halfIncrease;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Recalculate bar position with new data values
|
|
229
|
+
const newBarBottom = (_yScale6 = yScale(newBottom)) !== null && _yScale6 !== void 0 ? _yScale6 : baseline;
|
|
230
|
+
const newBarTop = (_yScale7 = yScale(newTop)) !== null && _yScale7 !== void 0 ? _yScale7 : baseline;
|
|
231
|
+
const newHeight = Math.abs(newBarBottom - newBarTop);
|
|
232
|
+
const newY = Math.min(newBarBottom, newBarTop);
|
|
233
|
+
return _objectSpread(_objectSpread({}, bar), {}, {
|
|
234
|
+
height: newHeight,
|
|
235
|
+
y: newY,
|
|
236
|
+
wasExpanded: true
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return _objectSpread(_objectSpread({}, bar), {}, {
|
|
240
|
+
wasExpanded: false
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// Now reposition all bars to avoid overlaps, similar to stackMinSize logic
|
|
245
|
+
|
|
246
|
+
// Sort bars by position to maintain order
|
|
247
|
+
const sortedExpandedBars = [...expandedBars].sort((a, b) => a.y - b.y);
|
|
248
|
+
|
|
249
|
+
// Determine if we have bars above and below baseline
|
|
250
|
+
const barsAboveBaseline = sortedExpandedBars.filter(bar => bar.y + bar.height <= baseline);
|
|
251
|
+
const barsBelowBaseline = sortedExpandedBars.filter(bar => bar.y >= baseline);
|
|
252
|
+
|
|
253
|
+
// Create a map of new positions
|
|
254
|
+
const newPositions = new Map();
|
|
255
|
+
|
|
256
|
+
// Start positioning from the baseline and work outward
|
|
257
|
+
let currentYAbove = baseline; // Start at baseline, work upward (decreasing Y)
|
|
258
|
+
let currentYBelow = baseline; // Start at baseline, work downward (increasing Y)
|
|
259
|
+
|
|
260
|
+
// Position bars above baseline (positive values, decreasing Y)
|
|
261
|
+
for (let i = barsAboveBaseline.length - 1; i >= 0; i--) {
|
|
262
|
+
const bar = barsAboveBaseline[i];
|
|
263
|
+
const newY = currentYAbove - bar.height;
|
|
264
|
+
newPositions.set(bar.seriesId, {
|
|
265
|
+
y: newY,
|
|
266
|
+
height: bar.height
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// Update currentYAbove for next bar (preserve gaps)
|
|
270
|
+
if (i > 0) {
|
|
271
|
+
const currentBar = barsAboveBaseline[i];
|
|
272
|
+
const nextBar = barsAboveBaseline[i - 1];
|
|
273
|
+
// Find original bars to get original gap
|
|
274
|
+
const originalCurrent = allBars.find(b => b.seriesId === currentBar.seriesId);
|
|
275
|
+
const originalNext = allBars.find(b => b.seriesId === nextBar.seriesId);
|
|
276
|
+
const originalGap = originalCurrent.y - (originalNext.y + originalNext.height);
|
|
277
|
+
currentYAbove = newY - originalGap;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Position bars below baseline (negative values, increasing Y)
|
|
282
|
+
for (let i = 0; i < barsBelowBaseline.length; i++) {
|
|
283
|
+
const bar = barsBelowBaseline[i];
|
|
284
|
+
const newY = currentYBelow;
|
|
285
|
+
newPositions.set(bar.seriesId, {
|
|
286
|
+
y: newY,
|
|
287
|
+
height: bar.height
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// Update currentYBelow for next bar (preserve gaps)
|
|
291
|
+
if (i < barsBelowBaseline.length - 1) {
|
|
292
|
+
const currentBar = barsBelowBaseline[i];
|
|
293
|
+
const nextBar = barsBelowBaseline[i + 1];
|
|
294
|
+
// Find original bars to get original gap
|
|
295
|
+
const originalCurrent = allBars.find(b => b.seriesId === currentBar.seriesId);
|
|
296
|
+
const originalNext = allBars.find(b => b.seriesId === nextBar.seriesId);
|
|
297
|
+
const originalGap = originalNext.y - (originalCurrent.y + originalCurrent.height);
|
|
298
|
+
currentYBelow = newY + bar.height + originalGap;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Apply new positions to all bars
|
|
303
|
+
allBars = expandedBars.map(bar => {
|
|
304
|
+
const newPos = newPositions.get(bar.seriesId);
|
|
305
|
+
if (newPos) {
|
|
306
|
+
return _objectSpread(_objectSpread({}, bar), {}, {
|
|
307
|
+
y: newPos.y,
|
|
308
|
+
height: newPos.height
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
return bar;
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
// Recalculate stack bounds after barMinSize expansion and repositioning
|
|
315
|
+
if (allBars.length > 0) {
|
|
316
|
+
minY = Math.min(...allBars.map(bar => bar.y));
|
|
317
|
+
maxY = Math.max(...allBars.map(bar => bar.y + bar.height));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Apply border radius logic (will be reapplied after stackMinSize if needed)
|
|
322
|
+
const applyBorderRadiusLogic = bars => {
|
|
323
|
+
return bars.sort((a, b) => b.y - a.y).map((a, index) => {
|
|
324
|
+
const barBefore = index > 0 ? bars[index - 1] : null;
|
|
325
|
+
const barAfter = index < bars.length - 1 ? bars[index + 1] : null;
|
|
326
|
+
const shouldRoundTop = index === bars.length - 1 || a.shouldApplyGap && stackGapPx || !a.shouldApplyGap && barAfter && barAfter.y + barAfter.height !== a.y;
|
|
327
|
+
const shouldRoundBottom = index === 0 || a.shouldApplyGap && stackGapPx || !a.shouldApplyGap && barBefore && barBefore.y !== a.y + a.height;
|
|
328
|
+
return _objectSpread(_objectSpread({}, a), {}, {
|
|
329
|
+
roundTop: Boolean(a.roundTop && shouldRoundTop),
|
|
330
|
+
roundBottom: Boolean(a.roundBottom && shouldRoundBottom)
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
allBars = applyBorderRadiusLogic(allBars);
|
|
335
|
+
|
|
336
|
+
// Calculate the bounding rect for the entire stack
|
|
337
|
+
let stackBounds = {
|
|
338
|
+
x,
|
|
339
|
+
y: minY === Infinity ? baseline : minY,
|
|
340
|
+
width,
|
|
341
|
+
height: maxY === -Infinity ? 0 : maxY - minY
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
// Apply stackMinSize constraints
|
|
345
|
+
if (stackMinSizePx) {
|
|
346
|
+
if (allBars.length === 1 && stackBounds.height < stackMinSizePx) {
|
|
347
|
+
var _yScale8, _yScale9, _yScale0, _yScale1;
|
|
348
|
+
// For single bars (non-stacked), treat stackMinSize like barMinSize
|
|
349
|
+
|
|
350
|
+
const bar = allBars[0];
|
|
351
|
+
const heightIncrease = stackMinSizePx - bar.height;
|
|
352
|
+
const bottom = 0;
|
|
353
|
+
const top = 0;
|
|
354
|
+
|
|
355
|
+
// Determine how to expand the bar (same logic as barMinSize)
|
|
356
|
+
let newBottom = bottom;
|
|
357
|
+
let newTop = top;
|
|
358
|
+
const scaleUnit = Math.abs(((_yScale8 = yScale(1)) !== null && _yScale8 !== void 0 ? _yScale8 : 0) - ((_yScale9 = yScale(0)) !== null && _yScale9 !== void 0 ? _yScale9 : 0));
|
|
359
|
+
if (bottom === 0) {
|
|
360
|
+
// Expand away from baseline (upward for positive)
|
|
361
|
+
newTop = top + heightIncrease / scaleUnit;
|
|
362
|
+
} else if (top === 0) {
|
|
363
|
+
// Expand away from baseline (downward for negative)
|
|
364
|
+
newBottom = bottom - heightIncrease / scaleUnit;
|
|
365
|
+
} else {
|
|
366
|
+
// Expand in both directions
|
|
367
|
+
const halfIncrease = heightIncrease / scaleUnit / 2;
|
|
368
|
+
newBottom = bottom - halfIncrease;
|
|
369
|
+
newTop = top + halfIncrease;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Recalculate bar position with new data values
|
|
373
|
+
const newBarBottom = (_yScale0 = yScale(newBottom)) !== null && _yScale0 !== void 0 ? _yScale0 : baseline;
|
|
374
|
+
const newBarTop = (_yScale1 = yScale(newTop)) !== null && _yScale1 !== void 0 ? _yScale1 : baseline;
|
|
375
|
+
const newHeight = Math.abs(newBarBottom - newBarTop);
|
|
376
|
+
const newY = Math.min(newBarBottom, newBarTop);
|
|
377
|
+
allBars[0] = _objectSpread(_objectSpread({}, bar), {}, {
|
|
378
|
+
height: newHeight,
|
|
379
|
+
y: newY
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
// Recalculate stack bounds
|
|
383
|
+
stackBounds = {
|
|
384
|
+
x,
|
|
385
|
+
y: newY,
|
|
386
|
+
width,
|
|
387
|
+
height: newHeight
|
|
388
|
+
};
|
|
389
|
+
} else if (allBars.length > 1 && stackBounds.height < stackMinSizePx) {
|
|
390
|
+
// For multiple bars (stacked), scale heights while preserving gaps
|
|
391
|
+
|
|
392
|
+
// Calculate total bar height (excluding gaps)
|
|
393
|
+
const totalBarHeight = allBars.reduce((sum, bar) => sum + bar.height, 0);
|
|
394
|
+
const totalGapHeight = stackBounds.height - totalBarHeight;
|
|
395
|
+
|
|
396
|
+
// Calculate how much we need to increase bar heights
|
|
397
|
+
const requiredBarHeight = stackMinSizePx - totalGapHeight;
|
|
398
|
+
const barScaleFactor = requiredBarHeight / totalBarHeight;
|
|
399
|
+
|
|
400
|
+
// Sort bars by position to maintain order
|
|
401
|
+
const sortedBars = [...allBars].sort((a, b) => a.y - b.y);
|
|
402
|
+
|
|
403
|
+
// Determine if we have bars above and below baseline
|
|
404
|
+
const barsAboveBaseline = sortedBars.filter(bar => bar.y + bar.height <= baseline);
|
|
405
|
+
const barsBelowBaseline = sortedBars.filter(bar => bar.y >= baseline);
|
|
406
|
+
|
|
407
|
+
// Create a map of new positions
|
|
408
|
+
const newPositions = new Map();
|
|
409
|
+
|
|
410
|
+
// Start positioning from the baseline and work outward
|
|
411
|
+
let currentYAbove = baseline; // Start at baseline, work upward (decreasing Y)
|
|
412
|
+
let currentYBelow = baseline; // Start at baseline, work downward (increasing Y)
|
|
413
|
+
|
|
414
|
+
// Position bars above baseline (positive values, decreasing Y)
|
|
415
|
+
for (let i = barsAboveBaseline.length - 1; i >= 0; i--) {
|
|
416
|
+
const bar = barsAboveBaseline[i];
|
|
417
|
+
const newHeight = bar.height * barScaleFactor;
|
|
418
|
+
const newY = currentYAbove - newHeight;
|
|
419
|
+
newPositions.set(bar.seriesId, {
|
|
420
|
+
y: newY,
|
|
421
|
+
height: newHeight
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
// Update currentYAbove for next bar (preserve gaps)
|
|
425
|
+
if (i > 0) {
|
|
426
|
+
const currentBar = barsAboveBaseline[i];
|
|
427
|
+
const nextBar = barsAboveBaseline[i - 1];
|
|
428
|
+
const originalGap = currentBar.y - (nextBar.y + nextBar.height);
|
|
429
|
+
currentYAbove = newY - originalGap;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Position bars below baseline (negative values, increasing Y)
|
|
434
|
+
for (let i = 0; i < barsBelowBaseline.length; i++) {
|
|
435
|
+
const bar = barsBelowBaseline[i];
|
|
436
|
+
const newHeight = bar.height * barScaleFactor;
|
|
437
|
+
const newY = currentYBelow;
|
|
438
|
+
newPositions.set(bar.seriesId, {
|
|
439
|
+
y: newY,
|
|
440
|
+
height: newHeight
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
// Update currentYBelow for next bar (preserve gaps)
|
|
444
|
+
if (i < barsBelowBaseline.length - 1) {
|
|
445
|
+
const currentBar = barsBelowBaseline[i];
|
|
446
|
+
const nextBar = barsBelowBaseline[i + 1];
|
|
447
|
+
const originalGap = nextBar.y - (currentBar.y + currentBar.height);
|
|
448
|
+
currentYBelow = newY + newHeight + originalGap;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// Apply new positions to all bars
|
|
453
|
+
allBars = allBars.map(bar => {
|
|
454
|
+
const newPos = newPositions.get(bar.seriesId);
|
|
455
|
+
if (!newPos) return bar;
|
|
456
|
+
return _objectSpread(_objectSpread({}, bar), {}, {
|
|
457
|
+
height: newPos.height,
|
|
458
|
+
y: newPos.y
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
// Recalculate stack bounds
|
|
463
|
+
const newMinY = Math.min(...allBars.map(bar => bar.y));
|
|
464
|
+
const newMaxY = Math.max(...allBars.map(bar => bar.y + bar.height));
|
|
465
|
+
stackBounds = {
|
|
466
|
+
x,
|
|
467
|
+
y: newMinY,
|
|
468
|
+
width,
|
|
469
|
+
height: newMaxY - newMinY
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// Reapply border radius logic only if we actually scaled
|
|
474
|
+
if (stackBounds.height < stackMinSizePx) {
|
|
475
|
+
allBars = applyBorderRadiusLogic(allBars);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
return {
|
|
479
|
+
bars: allBars,
|
|
480
|
+
stackRect: stackBounds
|
|
481
|
+
};
|
|
482
|
+
}, [series, x, width, getSeriesData, categoryIndex, roundBaseline, baseline, stackGapPx, barMinSizePx, stackMinSizePx, yScale]);
|
|
483
|
+
const xData = xAxis !== null && xAxis !== void 0 && xAxis.data && Array.isArray(xAxis.data) && typeof xAxis.data[0] === 'number' ? xAxis.data : undefined;
|
|
484
|
+
const dataX = xData ? xData[categoryIndex] : categoryIndex;
|
|
485
|
+
const barElements = bars.map((bar, index) => {
|
|
486
|
+
var _bar$fillOpacity, _bar$stroke, _bar$strokeWidth;
|
|
487
|
+
return /*#__PURE__*/_jsx(Bar, {
|
|
488
|
+
BarComponent: bar.BarComponent || defaultBarComponent,
|
|
489
|
+
borderRadius: borderRadius,
|
|
490
|
+
dataX: dataX,
|
|
491
|
+
dataY: bar.dataY,
|
|
492
|
+
fill: bar.fill,
|
|
493
|
+
fillOpacity: (_bar$fillOpacity = bar.fillOpacity) !== null && _bar$fillOpacity !== void 0 ? _bar$fillOpacity : defaultFillOpacity,
|
|
494
|
+
height: bar.height,
|
|
495
|
+
originY: baseline,
|
|
496
|
+
roundBottom: bar.roundBottom,
|
|
497
|
+
roundTop: bar.roundTop,
|
|
498
|
+
stroke: (_bar$stroke = bar.stroke) !== null && _bar$stroke !== void 0 ? _bar$stroke : defaultStroke,
|
|
499
|
+
strokeWidth: (_bar$strokeWidth = bar.strokeWidth) !== null && _bar$strokeWidth !== void 0 ? _bar$strokeWidth : defaultStrokeWidth,
|
|
500
|
+
width: bar.width,
|
|
501
|
+
x: bar.x,
|
|
502
|
+
y: bar.y
|
|
503
|
+
}, "".concat(bar.seriesId, "-").concat(categoryIndex, "-").concat(index));
|
|
504
|
+
});
|
|
505
|
+
const stackRoundBottom = roundBaseline || stackRect.y + stackRect.height !== baseline;
|
|
506
|
+
const stackRoundTop = roundBaseline || stackRect.y !== baseline;
|
|
507
|
+
return /*#__PURE__*/_jsx(BarStackComponent, {
|
|
508
|
+
borderRadius: borderRadius,
|
|
509
|
+
categoryIndex: categoryIndex,
|
|
510
|
+
height: stackRect.height,
|
|
511
|
+
roundBottom: stackRoundBottom,
|
|
512
|
+
roundTop: stackRoundTop,
|
|
513
|
+
width: stackRect.width,
|
|
514
|
+
x: stackRect.x,
|
|
515
|
+
y: stackRect.y,
|
|
516
|
+
yOrigin: baseline,
|
|
517
|
+
children: barElements
|
|
518
|
+
});
|
|
519
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const _excluded = ["series", "yAxisId", "stackIndex", "totalStacks", "barPadding"];
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
8
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
9
|
+
import { memo, useMemo, createElement as _createElement } from 'react';
|
|
10
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
11
|
+
import { getBarSizeAdjustment } from '../utils/bar';
|
|
12
|
+
import { isCategoricalScale } from '../utils/scale';
|
|
13
|
+
import { BarStack } from './BarStack';
|
|
14
|
+
/**
|
|
15
|
+
* BarStackGroup component that renders a group of stacks across all categories.
|
|
16
|
+
* Delegates the actual stacking logic to BarStack for each category.
|
|
17
|
+
*/
|
|
18
|
+
export const BarStackGroup = /*#__PURE__*/memo(_ref => {
|
|
19
|
+
let {
|
|
20
|
+
series,
|
|
21
|
+
yAxisId,
|
|
22
|
+
stackIndex,
|
|
23
|
+
totalStacks,
|
|
24
|
+
barPadding = 0.1
|
|
25
|
+
} = _ref,
|
|
26
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
27
|
+
const {
|
|
28
|
+
getSeriesData,
|
|
29
|
+
getXScale,
|
|
30
|
+
getYScale,
|
|
31
|
+
drawingArea
|
|
32
|
+
} = useCartesianChartContext();
|
|
33
|
+
const xScale = getXScale();
|
|
34
|
+
const yScale = getYScale(yAxisId);
|
|
35
|
+
const maxDataLength = useMemo(() => {
|
|
36
|
+
if (!series || series.length === 0) return 0;
|
|
37
|
+
let maxLength = 0;
|
|
38
|
+
series.forEach(s => {
|
|
39
|
+
const data = getSeriesData(s.id);
|
|
40
|
+
if (data && data.length > maxLength) {
|
|
41
|
+
maxLength = data.length;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return maxLength;
|
|
45
|
+
}, [series, getSeriesData]);
|
|
46
|
+
const stackConfigs = useMemo(() => {
|
|
47
|
+
if (!xScale || !yScale || !drawingArea || maxDataLength === 0) return [];
|
|
48
|
+
if (!isCategoricalScale(xScale)) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
const categoryWidth = xScale.bandwidth();
|
|
52
|
+
|
|
53
|
+
// Calculate width for each stack within a category
|
|
54
|
+
// Only apply barPadding when there are multiple stacks
|
|
55
|
+
const gapWidth = totalStacks > 1 ? categoryWidth * barPadding / (totalStacks - 1) : 0;
|
|
56
|
+
const barWidth = categoryWidth / totalStacks - getBarSizeAdjustment(totalStacks, gapWidth);
|
|
57
|
+
const configs = [];
|
|
58
|
+
|
|
59
|
+
// Calculate position for each category
|
|
60
|
+
for (let categoryIndex = 0; categoryIndex < maxDataLength; categoryIndex++) {
|
|
61
|
+
// Get x position for this category
|
|
62
|
+
const categoryX = xScale(categoryIndex);
|
|
63
|
+
if (categoryX !== undefined) {
|
|
64
|
+
// Calculate x position for this specific stack within the category
|
|
65
|
+
const stackX = categoryX + stackIndex * (barWidth + gapWidth);
|
|
66
|
+
configs.push({
|
|
67
|
+
categoryIndex,
|
|
68
|
+
x: stackX,
|
|
69
|
+
width: barWidth
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return configs;
|
|
74
|
+
}, [xScale, yScale, drawingArea, maxDataLength, stackIndex, totalStacks, barPadding]);
|
|
75
|
+
if (xScale && !isCategoricalScale(xScale)) {
|
|
76
|
+
throw new Error('BarStackGroup requires a band scale for x-axis. See https://cds.coinbase.com/components/graphs/XAxis/#scale-type');
|
|
77
|
+
}
|
|
78
|
+
if (!yScale || !drawingArea || stackConfigs.length === 0) return;
|
|
79
|
+
return stackConfigs.map(_ref2 => {
|
|
80
|
+
let {
|
|
81
|
+
categoryIndex,
|
|
82
|
+
x,
|
|
83
|
+
width
|
|
84
|
+
} = _ref2;
|
|
85
|
+
return /*#__PURE__*/_createElement(BarStack, _objectSpread(_objectSpread({}, props), {}, {
|
|
86
|
+
key: "stack-".concat(stackIndex, "-category-").concat(categoryIndex),
|
|
87
|
+
categoryIndex: categoryIndex,
|
|
88
|
+
rect: drawingArea,
|
|
89
|
+
series: series,
|
|
90
|
+
width: width,
|
|
91
|
+
x: x,
|
|
92
|
+
yAxisId: yAxisId,
|
|
93
|
+
yScale: yScale
|
|
94
|
+
}));
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const _excluded = ["x", "width", "borderRadius", "roundTop", "roundBottom", "originY", "d", "fill", "fillOpacity", "dataX", "dataY"];
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
8
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
9
|
+
import React, { memo, useMemo } from 'react';
|
|
10
|
+
import { m as motion } from 'framer-motion';
|
|
11
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
12
|
+
import { getBarPath } from '../utils';
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
/**
|
|
15
|
+
* Default bar component that renders a solid bar with animation.
|
|
16
|
+
*/
|
|
17
|
+
export const DefaultBar = /*#__PURE__*/memo(_ref => {
|
|
18
|
+
let {
|
|
19
|
+
x,
|
|
20
|
+
width,
|
|
21
|
+
borderRadius = 4,
|
|
22
|
+
roundTop,
|
|
23
|
+
roundBottom,
|
|
24
|
+
originY,
|
|
25
|
+
d,
|
|
26
|
+
fill = 'var(--color-fgPrimary)',
|
|
27
|
+
fillOpacity = 1,
|
|
28
|
+
dataX,
|
|
29
|
+
dataY
|
|
30
|
+
} = _ref,
|
|
31
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
32
|
+
const {
|
|
33
|
+
animate
|
|
34
|
+
} = useCartesianChartContext();
|
|
35
|
+
const initialPath = useMemo(() => {
|
|
36
|
+
if (!animate) return undefined;
|
|
37
|
+
// Need a minimum height to allow for animation
|
|
38
|
+
const minHeight = 1;
|
|
39
|
+
const initialY = (originY !== null && originY !== void 0 ? originY : 0) - minHeight;
|
|
40
|
+
return getBarPath(x, initialY, width, minHeight, borderRadius, !!roundTop, !!roundBottom);
|
|
41
|
+
}, [animate, x, originY, width, borderRadius, roundTop, roundBottom]);
|
|
42
|
+
if (animate && initialPath) {
|
|
43
|
+
return /*#__PURE__*/_jsx(motion.path, _objectSpread(_objectSpread({}, props), {}, {
|
|
44
|
+
animate: {
|
|
45
|
+
d
|
|
46
|
+
},
|
|
47
|
+
fill: fill,
|
|
48
|
+
fillOpacity: fillOpacity,
|
|
49
|
+
initial: {
|
|
50
|
+
d: initialPath
|
|
51
|
+
},
|
|
52
|
+
transition: {
|
|
53
|
+
type: 'spring',
|
|
54
|
+
duration: 1,
|
|
55
|
+
bounce: 0
|
|
56
|
+
}
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
return /*#__PURE__*/_jsx("path", _objectSpread(_objectSpread({}, props), {}, {
|
|
60
|
+
d: d,
|
|
61
|
+
fill: fill,
|
|
62
|
+
fillOpacity: fillOpacity
|
|
63
|
+
}));
|
|
64
|
+
});
|