@coinbase/cds-web-visualization 3.4.0-beta.22 → 3.4.0-beta.24
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 +10 -0
- package/dts/chart/CartesianChart.d.ts +23 -4
- package/dts/chart/CartesianChart.d.ts.map +1 -1
- package/dts/chart/Path.d.ts.map +1 -1
- package/dts/chart/area/Area.d.ts +7 -0
- package/dts/chart/area/Area.d.ts.map +1 -1
- package/dts/chart/area/AreaChart.d.ts +3 -3
- package/dts/chart/area/AreaChart.d.ts.map +1 -1
- package/dts/chart/area/DottedArea.d.ts.map +1 -1
- package/dts/chart/area/GradientArea.d.ts.map +1 -1
- package/dts/chart/area/SolidArea.d.ts.map +1 -1
- package/dts/chart/axis/Axis.d.ts +10 -10
- package/dts/chart/axis/Axis.d.ts.map +1 -1
- package/dts/chart/axis/XAxis.d.ts +6 -0
- package/dts/chart/axis/XAxis.d.ts.map +1 -1
- package/dts/chart/axis/YAxis.d.ts +1 -0
- package/dts/chart/axis/YAxis.d.ts.map +1 -1
- package/dts/chart/bar/Bar.d.ts +4 -3
- package/dts/chart/bar/Bar.d.ts.map +1 -1
- package/dts/chart/bar/BarChart.d.ts +25 -5
- package/dts/chart/bar/BarChart.d.ts.map +1 -1
- package/dts/chart/bar/BarPlot.d.ts.map +1 -1
- package/dts/chart/bar/BarStack.d.ts +47 -12
- package/dts/chart/bar/BarStack.d.ts.map +1 -1
- package/dts/chart/bar/BarStackGroup.d.ts +1 -1
- package/dts/chart/bar/BarStackGroup.d.ts.map +1 -1
- package/dts/chart/bar/DefaultBar.d.ts.map +1 -1
- package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -1
- package/dts/chart/gradient/Gradient.d.ts +7 -0
- package/dts/chart/gradient/Gradient.d.ts.map +1 -1
- package/dts/chart/line/DottedLine.d.ts.map +1 -1
- package/dts/chart/line/Line.d.ts +7 -0
- package/dts/chart/line/Line.d.ts.map +1 -1
- package/dts/chart/line/LineChart.d.ts +3 -3
- package/dts/chart/line/LineChart.d.ts.map +1 -1
- package/dts/chart/line/ReferenceLine.d.ts +1 -0
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -1
- package/dts/chart/line/SolidLine.d.ts.map +1 -1
- package/dts/chart/point/Point.d.ts +7 -0
- package/dts/chart/point/Point.d.ts.map +1 -1
- package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts.map +1 -1
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts +2 -1
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts.map +1 -1
- package/dts/chart/scrubber/Scrubber.d.ts +8 -0
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -1
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +1 -1
- package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -1
- package/dts/chart/utils/axis.d.ts +23 -8
- package/dts/chart/utils/axis.d.ts.map +1 -1
- package/dts/chart/utils/bar.d.ts +4 -3
- package/dts/chart/utils/bar.d.ts.map +1 -1
- package/dts/chart/utils/chart.d.ts +13 -0
- package/dts/chart/utils/chart.d.ts.map +1 -1
- package/dts/chart/utils/context.d.ts +20 -4
- package/dts/chart/utils/context.d.ts.map +1 -1
- package/dts/chart/utils/gradient.d.ts +3 -1
- package/dts/chart/utils/gradient.d.ts.map +1 -1
- package/dts/chart/utils/path.d.ts +20 -0
- package/dts/chart/utils/path.d.ts.map +1 -1
- package/dts/chart/utils/point.d.ts +7 -0
- package/dts/chart/utils/point.d.ts.map +1 -1
- package/esm/chart/CartesianChart.js +89 -57
- package/esm/chart/Path.js +15 -6
- package/esm/chart/area/Area.js +19 -9
- package/esm/chart/area/AreaChart.js +16 -14
- package/esm/chart/area/DottedArea.js +11 -6
- package/esm/chart/area/GradientArea.js +11 -6
- package/esm/chart/area/SolidArea.js +3 -1
- package/esm/chart/axis/XAxis.js +11 -12
- package/esm/chart/axis/YAxis.js +4 -4
- package/esm/chart/bar/Bar.js +11 -5
- package/esm/chart/bar/BarChart.js +34 -31
- package/esm/chart/bar/BarPlot.js +6 -3
- package/esm/chart/bar/BarStack.js +155 -356
- package/esm/chart/bar/BarStackGroup.js +36 -27
- package/esm/chart/bar/DefaultBar.js +26 -10
- package/esm/chart/bar/DefaultBarStack.js +27 -13
- package/esm/chart/gradient/Gradient.js +3 -2
- package/esm/chart/line/DottedLine.js +3 -1
- package/esm/chart/line/Line.js +29 -16
- package/esm/chart/line/LineChart.js +10 -8
- package/esm/chart/line/SolidLine.js +3 -1
- package/esm/chart/point/Point.js +3 -2
- package/esm/chart/scrubber/DefaultScrubberBeacon.js +1 -1
- package/esm/chart/scrubber/DefaultScrubberLabel.js +26 -8
- package/esm/chart/scrubber/Scrubber.js +34 -27
- package/esm/chart/scrubber/ScrubberBeaconGroup.js +49 -32
- package/esm/chart/scrubber/ScrubberProvider.js +44 -39
- package/esm/chart/utils/axis.js +44 -13
- package/esm/chart/utils/bar.js +5 -4
- package/esm/chart/utils/chart.js +18 -5
- package/esm/chart/utils/context.js +7 -0
- package/esm/chart/utils/gradient.js +6 -4
- package/esm/chart/utils/path.js +87 -61
- package/esm/chart/utils/point.js +30 -21
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["series", "children", "animate", "xAxis", "yAxis", "inset", "enableScrubbing", "onScrubberPositionChange", "legend", "legendPosition", "legendAccessibilityLabel", "width", "height", "className", "classNames", "style", "styles", "accessibilityLabel"];
|
|
1
|
+
const _excluded = ["series", "children", "layout", "animate", "xAxis", "yAxis", "inset", "enableScrubbing", "onScrubberPositionChange", "legend", "legendPosition", "legendAccessibilityLabel", "width", "height", "className", "classNames", "style", "styles", "accessibilityLabel"];
|
|
2
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
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
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; }
|
|
@@ -13,13 +13,14 @@ import { Box } from '@coinbase/cds-web/layout';
|
|
|
13
13
|
import { ScrubberProvider } from './scrubber/ScrubberProvider';
|
|
14
14
|
import { CartesianChartProvider } from './ChartProvider';
|
|
15
15
|
import { Legend } from './legend';
|
|
16
|
-
import { defaultAxisId,
|
|
16
|
+
import { defaultAxisId, defaultHorizontalLayoutChartInset, defaultVerticalLayoutChartInset, getAxisConfig, getAxisRange, getCartesianAxisDomain, getCartesianAxisScale, getChartInset, getStackedSeriesData as calculateStackedSeriesData, useTotalAxisPadding } from './utils';
|
|
17
17
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
18
|
const focusStylesCss = "cds-focusStylesCss-f4oy7ru";
|
|
19
19
|
export const CartesianChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
20
20
|
let {
|
|
21
21
|
series,
|
|
22
22
|
children,
|
|
23
|
+
layout = 'vertical',
|
|
23
24
|
animate = true,
|
|
24
25
|
xAxis: xAxisConfigProp,
|
|
25
26
|
yAxis: yAxisConfigProp,
|
|
@@ -44,12 +45,20 @@ export const CartesianChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, r
|
|
|
44
45
|
height: chartHeight
|
|
45
46
|
} = useDimensions();
|
|
46
47
|
const svgRef = useRef(null);
|
|
47
|
-
const calculatedInset = useMemo(() => getChartInset(inset,
|
|
48
|
+
const calculatedInset = useMemo(() => getChartInset(inset, layout === 'horizontal' ? defaultHorizontalLayoutChartInset : defaultVerticalLayoutChartInset), [inset, layout]);
|
|
48
49
|
|
|
49
50
|
// Axis configs store the properties of each axis, such as id, scale type, domain limit, etc.
|
|
50
|
-
|
|
51
|
-
const xAxisConfig = useMemo(() => getAxisConfig('x', xAxisConfigProp)[0], [xAxisConfigProp]);
|
|
51
|
+
const xAxisConfig = useMemo(() => getAxisConfig('x', xAxisConfigProp), [xAxisConfigProp]);
|
|
52
52
|
const yAxisConfig = useMemo(() => getAxisConfig('y', yAxisConfigProp), [yAxisConfigProp]);
|
|
53
|
+
|
|
54
|
+
// Horizontal layout supports multiple value axes on x, but only a single category axis on y.
|
|
55
|
+
// Vertical layout keeps a single x-axis to preserve existing behavior.
|
|
56
|
+
if (layout === 'horizontal' && yAxisConfig.length > 1) {
|
|
57
|
+
throw new Error('When layout="horizontal", only one y-axis is supported. See https://cds.coinbase.com/components/charts/CartesianChart.');
|
|
58
|
+
}
|
|
59
|
+
if (layout !== 'horizontal' && xAxisConfig.length > 1) {
|
|
60
|
+
throw new Error('Multiple x-axes are only supported when layout="horizontal". See https://cds.coinbase.com/components/charts/CartesianChart.');
|
|
61
|
+
}
|
|
53
62
|
const {
|
|
54
63
|
renderedAxes,
|
|
55
64
|
registerAxis,
|
|
@@ -79,50 +88,64 @@ export const CartesianChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, r
|
|
|
79
88
|
};
|
|
80
89
|
}, [chartHeight, chartWidth, calculatedInset, axisPadding]);
|
|
81
90
|
const {
|
|
82
|
-
|
|
83
|
-
|
|
91
|
+
xAxes,
|
|
92
|
+
xScales
|
|
84
93
|
} = useMemo(() => {
|
|
94
|
+
const axes = new Map();
|
|
95
|
+
const scales = new Map();
|
|
85
96
|
if (!chartRect || chartRect.width <= 0 || chartRect.height <= 0) return {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
};
|
|
89
|
-
const domain = getAxisDomain(xAxisConfig, series !== null && series !== void 0 ? series : [], 'x');
|
|
90
|
-
const range = getAxisRange(xAxisConfig, chartRect, 'x');
|
|
91
|
-
const axisConfig = {
|
|
92
|
-
scaleType: xAxisConfig.scaleType,
|
|
93
|
-
domain,
|
|
94
|
-
range,
|
|
95
|
-
data: xAxisConfig.data,
|
|
96
|
-
categoryPadding: xAxisConfig.categoryPadding,
|
|
97
|
-
domainLimit: xAxisConfig.domainLimit
|
|
97
|
+
xAxes: axes,
|
|
98
|
+
xScales: scales
|
|
98
99
|
};
|
|
100
|
+
xAxisConfig.forEach(axisParam => {
|
|
101
|
+
var _axisParam$id, _series$filter, _axisParam$domainLimi;
|
|
102
|
+
const axisId = (_axisParam$id = axisParam.id) !== null && _axisParam$id !== void 0 ? _axisParam$id : defaultAxisId;
|
|
99
103
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
dataDomain: axisConfig.domain
|
|
106
|
-
});
|
|
107
|
-
if (!scale) return {
|
|
108
|
-
xAxis: undefined,
|
|
109
|
-
xScale: undefined
|
|
110
|
-
};
|
|
104
|
+
// Get relevant series data
|
|
105
|
+
const relevantSeries = xAxisConfig.length > 1 ? (_series$filter = series === null || series === void 0 ? void 0 : series.filter(s => {
|
|
106
|
+
var _s$xAxisId;
|
|
107
|
+
return ((_s$xAxisId = s.xAxisId) !== null && _s$xAxisId !== void 0 ? _s$xAxisId : defaultAxisId) === axisId;
|
|
108
|
+
})) !== null && _series$filter !== void 0 ? _series$filter : [] : series !== null && series !== void 0 ? series : [];
|
|
111
109
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
110
|
+
// Calculate domain and range
|
|
111
|
+
const dataDomain = getCartesianAxisDomain(axisParam, relevantSeries, 'x', layout);
|
|
112
|
+
const range = getAxisRange(axisParam, chartRect, 'x');
|
|
113
|
+
const axisConfig = {
|
|
114
|
+
scaleType: axisParam.scaleType,
|
|
115
|
+
domain: dataDomain,
|
|
116
|
+
range,
|
|
117
|
+
data: axisParam.data,
|
|
118
|
+
categoryPadding: axisParam.categoryPadding,
|
|
119
|
+
domainLimit: (_axisParam$domainLimi = axisParam.domainLimit) !== null && _axisParam$domainLimi !== void 0 ? _axisParam$domainLimi : layout === 'horizontal' ? 'nice' : 'strict'
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// Create the scale
|
|
123
|
+
const scale = getCartesianAxisScale({
|
|
124
|
+
config: axisConfig,
|
|
125
|
+
type: 'x',
|
|
126
|
+
range: axisConfig.range,
|
|
127
|
+
dataDomain: axisConfig.domain,
|
|
128
|
+
layout
|
|
129
|
+
});
|
|
130
|
+
if (scale) {
|
|
131
|
+
scales.set(axisId, scale);
|
|
132
|
+
|
|
133
|
+
// Update axis config with actual scale domain (after .nice() or other adjustments)
|
|
134
|
+
const scaleDomain = scale.domain();
|
|
135
|
+
const actualDomain = Array.isArray(scaleDomain) && scaleDomain.length === 2 ? {
|
|
136
|
+
min: scaleDomain[0],
|
|
137
|
+
max: scaleDomain[1]
|
|
138
|
+
} : axisConfig.domain;
|
|
139
|
+
axes.set(axisId, _objectSpread(_objectSpread({}, axisConfig), {}, {
|
|
140
|
+
domain: actualDomain
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
120
143
|
});
|
|
121
144
|
return {
|
|
122
|
-
|
|
123
|
-
|
|
145
|
+
xAxes: axes,
|
|
146
|
+
xScales: scales
|
|
124
147
|
};
|
|
125
|
-
}, [xAxisConfig, series, chartRect]);
|
|
148
|
+
}, [xAxisConfig, series, chartRect, layout]);
|
|
126
149
|
const {
|
|
127
150
|
yAxes,
|
|
128
151
|
yScales
|
|
@@ -134,17 +157,17 @@ export const CartesianChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, r
|
|
|
134
157
|
yScales: scales
|
|
135
158
|
};
|
|
136
159
|
yAxisConfig.forEach(axisParam => {
|
|
137
|
-
var _axisParam$
|
|
138
|
-
const axisId = (_axisParam$
|
|
160
|
+
var _axisParam$id2, _series$filter2, _axisParam$domainLimi2;
|
|
161
|
+
const axisId = (_axisParam$id2 = axisParam.id) !== null && _axisParam$id2 !== void 0 ? _axisParam$id2 : defaultAxisId;
|
|
139
162
|
|
|
140
163
|
// Get relevant series data
|
|
141
|
-
const relevantSeries = (_series$
|
|
164
|
+
const relevantSeries = yAxisConfig.length > 1 ? (_series$filter2 = series === null || series === void 0 ? void 0 : series.filter(s => {
|
|
142
165
|
var _s$yAxisId;
|
|
143
166
|
return ((_s$yAxisId = s.yAxisId) !== null && _s$yAxisId !== void 0 ? _s$yAxisId : defaultAxisId) === axisId;
|
|
144
|
-
})) !== null && _series$
|
|
167
|
+
})) !== null && _series$filter2 !== void 0 ? _series$filter2 : [] : series !== null && series !== void 0 ? series : [];
|
|
145
168
|
|
|
146
169
|
// Calculate domain and range
|
|
147
|
-
const dataDomain =
|
|
170
|
+
const dataDomain = getCartesianAxisDomain(axisParam, relevantSeries, 'y', layout);
|
|
148
171
|
const range = getAxisRange(axisParam, chartRect, 'y');
|
|
149
172
|
const axisConfig = {
|
|
150
173
|
scaleType: axisParam.scaleType,
|
|
@@ -152,15 +175,16 @@ export const CartesianChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, r
|
|
|
152
175
|
range,
|
|
153
176
|
data: axisParam.data,
|
|
154
177
|
categoryPadding: axisParam.categoryPadding,
|
|
155
|
-
domainLimit: (_axisParam$
|
|
178
|
+
domainLimit: (_axisParam$domainLimi2 = axisParam.domainLimit) !== null && _axisParam$domainLimi2 !== void 0 ? _axisParam$domainLimi2 : layout === 'horizontal' ? 'strict' : 'nice'
|
|
156
179
|
};
|
|
157
180
|
|
|
158
181
|
// Create the scale
|
|
159
|
-
const scale =
|
|
182
|
+
const scale = getCartesianAxisScale({
|
|
160
183
|
config: axisConfig,
|
|
161
184
|
type: 'y',
|
|
162
185
|
range: axisConfig.range,
|
|
163
|
-
dataDomain: axisConfig.domain
|
|
186
|
+
dataDomain: axisConfig.domain,
|
|
187
|
+
layout
|
|
164
188
|
});
|
|
165
189
|
if (scale) {
|
|
166
190
|
scales.set(axisId, scale);
|
|
@@ -180,10 +204,10 @@ export const CartesianChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, r
|
|
|
180
204
|
yAxes: axes,
|
|
181
205
|
yScales: scales
|
|
182
206
|
};
|
|
183
|
-
}, [yAxisConfig, series, chartRect]);
|
|
184
|
-
const getXAxis = useCallback(
|
|
207
|
+
}, [yAxisConfig, series, chartRect, layout]);
|
|
208
|
+
const getXAxis = useCallback(id => xAxes.get(id !== null && id !== void 0 ? id : defaultAxisId), [xAxes]);
|
|
185
209
|
const getYAxis = useCallback(id => yAxes.get(id !== null && id !== void 0 ? id : defaultAxisId), [yAxes]);
|
|
186
|
-
const getXScale = useCallback(
|
|
210
|
+
const getXScale = useCallback(id => xScales.get(id !== null && id !== void 0 ? id : defaultAxisId), [xScales]);
|
|
187
211
|
const getYScale = useCallback(id => yScales.get(id !== null && id !== void 0 ? id : defaultAxisId), [yScales]);
|
|
188
212
|
const getSeries = useCallback(seriesId => series === null || series === void 0 ? void 0 : series.find(s => s.id === seriesId), [series]);
|
|
189
213
|
const stackedDataMap = useMemo(() => {
|
|
@@ -194,10 +218,17 @@ export const CartesianChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, r
|
|
|
194
218
|
if (!seriesId) return undefined;
|
|
195
219
|
return stackedDataMap.get(seriesId);
|
|
196
220
|
}, [stackedDataMap]);
|
|
221
|
+
const categoryAxisIsX = useMemo(() => {
|
|
222
|
+
return layout !== 'horizontal';
|
|
223
|
+
}, [layout]);
|
|
224
|
+
const categoryAxisConfig = useMemo(() => {
|
|
225
|
+
var _xAxisConfig$, _yAxisConfig$;
|
|
226
|
+
return categoryAxisIsX ? (_xAxisConfig$ = xAxisConfig[0]) !== null && _xAxisConfig$ !== void 0 ? _xAxisConfig$ : yAxisConfig[0] : (_yAxisConfig$ = yAxisConfig[0]) !== null && _yAxisConfig$ !== void 0 ? _yAxisConfig$ : xAxisConfig[0];
|
|
227
|
+
}, [categoryAxisIsX, xAxisConfig, yAxisConfig]);
|
|
197
228
|
const dataLength = useMemo(() => {
|
|
198
|
-
// If
|
|
199
|
-
if (
|
|
200
|
-
return
|
|
229
|
+
// If category axis has categorical data, use that length
|
|
230
|
+
if (categoryAxisConfig.data && categoryAxisConfig.data.length > 0) {
|
|
231
|
+
return categoryAxisConfig.data.length;
|
|
201
232
|
}
|
|
202
233
|
|
|
203
234
|
// Otherwise, find the longest series
|
|
@@ -207,7 +238,7 @@ export const CartesianChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, r
|
|
|
207
238
|
const seriesData = getStackedSeriesData(s.id);
|
|
208
239
|
return Math.max(max, (_seriesData$length = seriesData === null || seriesData === void 0 ? void 0 : seriesData.length) !== null && _seriesData$length !== void 0 ? _seriesData$length : 0);
|
|
209
240
|
}, 0);
|
|
210
|
-
}, [
|
|
241
|
+
}, [categoryAxisConfig, series, getStackedSeriesData]);
|
|
211
242
|
const getAxisBounds = useCallback(axisId => {
|
|
212
243
|
const axis = renderedAxes.get(axisId);
|
|
213
244
|
if (!axis || !chartRect) return;
|
|
@@ -256,6 +287,7 @@ export const CartesianChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, r
|
|
|
256
287
|
}
|
|
257
288
|
}, [renderedAxes, chartRect, calculatedInset]);
|
|
258
289
|
const contextValue = useMemo(() => ({
|
|
290
|
+
layout,
|
|
259
291
|
series: series !== null && series !== void 0 ? series : [],
|
|
260
292
|
getSeries,
|
|
261
293
|
getSeriesData: getStackedSeriesData,
|
|
@@ -271,7 +303,7 @@ export const CartesianChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, r
|
|
|
271
303
|
registerAxis,
|
|
272
304
|
unregisterAxis,
|
|
273
305
|
getAxisBounds
|
|
274
|
-
}), [series, getSeries, getStackedSeriesData, animate, chartWidth, chartHeight, getXAxis, getYAxis, getXScale, getYScale, chartRect, dataLength, registerAxis, unregisterAxis, getAxisBounds]);
|
|
306
|
+
}), [layout, series, getSeries, getStackedSeriesData, animate, chartWidth, chartHeight, getXAxis, getYAxis, getXScale, getYScale, chartRect, dataLength, registerAxis, unregisterAxis, getAxisBounds]);
|
|
275
307
|
const rootClassNames = useMemo(() => cx(className, classNames === null || classNames === void 0 ? void 0 : classNames.root), [className, classNames]);
|
|
276
308
|
const rootStyles = useMemo(() => _objectSpread(_objectSpread({}, style), styles === null || styles === void 0 ? void 0 : styles.root), [style, styles === null || styles === void 0 ? void 0 : styles.root]);
|
|
277
309
|
const legendElement = useMemo(() => {
|
package/esm/chart/Path.js
CHANGED
|
@@ -49,6 +49,7 @@ export const Path = /*#__PURE__*/memo(_ref2 => {
|
|
|
49
49
|
const context = useCartesianChartContext();
|
|
50
50
|
const rect = clipRect !== undefined ? clipRect : context.drawingArea;
|
|
51
51
|
const animate = animateProp !== null && animateProp !== void 0 ? animateProp : context.animate;
|
|
52
|
+
const clipPath = rect !== null ? "url(#".concat(clipPathId, ")") : undefined;
|
|
52
53
|
const enterTransition = useMemo(() => getTransition(transitions === null || transitions === void 0 ? void 0 : transitions.enter, animate, defaultPathEnterTransition), [animate, transitions === null || transitions === void 0 ? void 0 : transitions.enter]);
|
|
53
54
|
const updateTransition = useMemo(() => getTransition((transitions === null || transitions === void 0 ? void 0 : transitions.update) !== undefined ? transitions.update : transition, animate, defaultTransition), [animate, transitions === null || transitions === void 0 ? void 0 : transitions.update, transition]);
|
|
54
55
|
const shouldAnimateClip = animate && enterTransition !== null;
|
|
@@ -58,18 +59,25 @@ export const Path = /*#__PURE__*/memo(_ref2 => {
|
|
|
58
59
|
const totalOffset = clipOffset * 2; // Applied on both sides
|
|
59
60
|
|
|
60
61
|
const clipPathAnimation = useMemo(() => {
|
|
61
|
-
if (rect === null
|
|
62
|
+
if (rect === null) return;
|
|
63
|
+
const categoryAxisIsX = context.layout !== 'horizontal';
|
|
64
|
+
const fullWidth = rect.width + totalOffset;
|
|
65
|
+
const fullHeight = rect.height + totalOffset;
|
|
62
66
|
return {
|
|
63
67
|
hidden: {
|
|
64
|
-
width: 0
|
|
68
|
+
width: categoryAxisIsX ? 0 : fullWidth,
|
|
69
|
+
height: categoryAxisIsX ? fullHeight : 0
|
|
65
70
|
},
|
|
66
71
|
visible: {
|
|
67
|
-
width:
|
|
68
|
-
|
|
72
|
+
width: fullWidth,
|
|
73
|
+
height: fullHeight,
|
|
74
|
+
transition: {
|
|
75
|
+
type: 'timing',
|
|
76
|
+
duration: pathEnterTransitionDuration
|
|
77
|
+
}
|
|
69
78
|
}
|
|
70
79
|
};
|
|
71
|
-
}, [rect, totalOffset,
|
|
72
|
-
const clipPath = useMemo(() => rect !== null ? "url(#".concat(clipPathId, ")") : undefined, [rect, clipPathId]);
|
|
80
|
+
}, [rect, totalOffset, context.layout]);
|
|
73
81
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
74
82
|
children: [rect !== null && /*#__PURE__*/_jsx("defs", {
|
|
75
83
|
children: /*#__PURE__*/_jsx("clipPath", {
|
|
@@ -79,6 +87,7 @@ export const Path = /*#__PURE__*/memo(_ref2 => {
|
|
|
79
87
|
height: rect.height + totalOffset,
|
|
80
88
|
initial: "hidden",
|
|
81
89
|
variants: clipPathAnimation,
|
|
90
|
+
width: rect.width + totalOffset,
|
|
82
91
|
x: rect.x - clipOffset,
|
|
83
92
|
y: rect.y - clipOffset
|
|
84
93
|
}) : /*#__PURE__*/_jsx("rect", {
|
package/esm/chart/area/Area.js
CHANGED
|
@@ -21,33 +21,42 @@ export const Area = /*#__PURE__*/memo(_ref => {
|
|
|
21
21
|
animate
|
|
22
22
|
} = _ref;
|
|
23
23
|
const {
|
|
24
|
+
layout,
|
|
24
25
|
getSeries,
|
|
25
26
|
getSeriesData,
|
|
26
27
|
getXScale,
|
|
27
28
|
getYScale,
|
|
28
|
-
getXAxis
|
|
29
|
+
getXAxis,
|
|
30
|
+
getYAxis
|
|
29
31
|
} = useCartesianChartContext();
|
|
30
32
|
const matchedSeries = useMemo(() => getSeries(seriesId), [seriesId, getSeries]);
|
|
31
33
|
const gradient = useMemo(() => gradientProp !== null && gradientProp !== void 0 ? gradientProp : matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.gradient, [gradientProp, matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.gradient]);
|
|
32
34
|
const fill = useMemo(() => fillProp !== null && fillProp !== void 0 ? fillProp : matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.color, [fillProp, matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.color]);
|
|
33
35
|
const sourceData = useMemo(() => getSeriesData(seriesId), [seriesId, getSeriesData]);
|
|
34
|
-
const xAxis = getXAxis();
|
|
35
|
-
const xScale = getXScale();
|
|
36
|
+
const xAxis = getXAxis(matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.xAxisId);
|
|
37
|
+
const xScale = getXScale(matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.xAxisId);
|
|
36
38
|
const yScale = getYScale(matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.yAxisId);
|
|
39
|
+
const yAxis = getYAxis(matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.yAxisId);
|
|
40
|
+
const categoryAxisIsX = useMemo(() => {
|
|
41
|
+
return layout !== 'horizontal';
|
|
42
|
+
}, [layout]);
|
|
43
|
+
const categoryAxis = useMemo(() => {
|
|
44
|
+
return categoryAxisIsX ? xAxis : yAxis;
|
|
45
|
+
}, [categoryAxisIsX, xAxis, yAxis]);
|
|
37
46
|
const area = useMemo(() => {
|
|
38
47
|
if (!sourceData || sourceData.length === 0 || !xScale || !yScale) return '';
|
|
39
|
-
|
|
40
|
-
// Get numeric x-axis data if available
|
|
41
|
-
const xData = xAxis !== null && xAxis !== void 0 && xAxis.data && Array.isArray(xAxis.data) && typeof xAxis.data[0] === 'number' ? xAxis.data : undefined;
|
|
48
|
+
const indexData = categoryAxis !== null && categoryAxis !== void 0 && categoryAxis.data && Array.isArray(categoryAxis.data) && typeof categoryAxis.data[0] === 'number' ? categoryAxis.data : undefined;
|
|
42
49
|
return getAreaPath({
|
|
43
50
|
data: sourceData,
|
|
44
51
|
xScale,
|
|
45
52
|
yScale,
|
|
46
53
|
curve,
|
|
47
|
-
xData,
|
|
48
|
-
|
|
54
|
+
xData: categoryAxisIsX ? indexData : undefined,
|
|
55
|
+
yData: !categoryAxisIsX ? indexData : undefined,
|
|
56
|
+
connectNulls,
|
|
57
|
+
layout
|
|
49
58
|
});
|
|
50
|
-
}, [sourceData, xScale, yScale, curve,
|
|
59
|
+
}, [sourceData, xScale, yScale, curve, categoryAxis, categoryAxisIsX, connectNulls, layout]);
|
|
51
60
|
const AreaComponent = useMemo(() => {
|
|
52
61
|
if (AreaComponentProp) {
|
|
53
62
|
return AreaComponentProp;
|
|
@@ -72,6 +81,7 @@ export const Area = /*#__PURE__*/memo(_ref => {
|
|
|
72
81
|
gradient: gradient,
|
|
73
82
|
transition: transition,
|
|
74
83
|
transitions: transitions,
|
|
84
|
+
xAxisId: matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.xAxisId,
|
|
75
85
|
yAxisId: matchedSeries === null || matchedSeries === void 0 ? void 0 : matchedSeries.yAxisId
|
|
76
86
|
});
|
|
77
87
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const _excluded = ["series", "stacked", "AreaComponent", "curve", "fillOpacity", "type", "connectNulls", "transitions", "transition", "LineComponent", "strokeWidth", "showXAxis", "showYAxis", "showLines", "lineType", "xAxis", "yAxis", "inset", "children"],
|
|
2
|
-
_excluded2 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range"],
|
|
2
|
+
_excluded2 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range", "id"],
|
|
3
3
|
_excluded3 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range", "id"],
|
|
4
4
|
_excluded4 = ["id", "data", "label", "color", "yAxisId", "opacity", "LineComponent", "stackId", "legendShape"],
|
|
5
5
|
_excluded5 = ["id", "data", "label", "color", "yAxisId", "fill", "fillOpacity", "stackId", "legendShape", "type"];
|
|
@@ -14,7 +14,7 @@ import { forwardRef, memo, useMemo } from 'react';
|
|
|
14
14
|
import { XAxis, YAxis } from '../axis';
|
|
15
15
|
import { CartesianChart } from '../CartesianChart';
|
|
16
16
|
import { Line } from '../line/Line';
|
|
17
|
-
import {
|
|
17
|
+
import { defaultStackId } from '../utils';
|
|
18
18
|
import { Area } from './Area';
|
|
19
19
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
20
|
export const AreaChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
@@ -40,8 +40,6 @@ export const AreaChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =
|
|
|
40
40
|
children
|
|
41
41
|
} = _ref,
|
|
42
42
|
chartProps = _objectWithoutProperties(_ref, _excluded);
|
|
43
|
-
const calculatedInset = useMemo(() => getChartInset(inset, defaultChartInset), [inset]);
|
|
44
|
-
|
|
45
43
|
// Convert AreaSeries to Series for Chart context
|
|
46
44
|
const chartSeries = useMemo(() => {
|
|
47
45
|
return series === null || series === void 0 ? void 0 : series.map(s => ({
|
|
@@ -49,6 +47,7 @@ export const AreaChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =
|
|
|
49
47
|
data: s.data,
|
|
50
48
|
label: s.label,
|
|
51
49
|
color: s.color,
|
|
50
|
+
xAxisId: s.xAxisId,
|
|
52
51
|
yAxisId: s.yAxisId,
|
|
53
52
|
stackId: s.stackId,
|
|
54
53
|
gradient: s.gradient
|
|
@@ -73,7 +72,8 @@ export const AreaChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =
|
|
|
73
72
|
categoryPadding: xCategoryPadding,
|
|
74
73
|
domain: xDomain,
|
|
75
74
|
domainLimit: xDomainLimit,
|
|
76
|
-
range: xRange
|
|
75
|
+
range: xRange,
|
|
76
|
+
id: xAxisId
|
|
77
77
|
} = _ref2,
|
|
78
78
|
xAxisVisualProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
79
79
|
const _ref3 = yAxis || {},
|
|
@@ -87,6 +87,13 @@ export const AreaChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =
|
|
|
87
87
|
id: yAxisId
|
|
88
88
|
} = _ref3,
|
|
89
89
|
yAxisVisualProps = _objectWithoutProperties(_ref3, _excluded3);
|
|
90
|
+
const hasNegativeValues = useMemo(() => {
|
|
91
|
+
if (!series) return false;
|
|
92
|
+
return series.some(s => {
|
|
93
|
+
var _s$data;
|
|
94
|
+
return (_s$data = s.data) === null || _s$data === void 0 ? void 0 : _s$data.some(value => typeof value === 'number' && value < 0 || Array.isArray(value) && value.some(v => typeof v === 'number' && v < 0));
|
|
95
|
+
});
|
|
96
|
+
}, [series]);
|
|
90
97
|
const xAxisConfig = {
|
|
91
98
|
scaleType: xScaleType,
|
|
92
99
|
data: xData,
|
|
@@ -95,13 +102,6 @@ export const AreaChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =
|
|
|
95
102
|
domainLimit: xDomainLimit,
|
|
96
103
|
range: xRange
|
|
97
104
|
};
|
|
98
|
-
const hasNegativeValues = useMemo(() => {
|
|
99
|
-
if (!series) return false;
|
|
100
|
-
return series.some(s => {
|
|
101
|
-
var _s$data;
|
|
102
|
-
return (_s$data = s.data) === null || _s$data === void 0 ? void 0 : _s$data.some(value => typeof value === 'number' && value < 0 || Array.isArray(value) && value.some(v => typeof v === 'number' && v < 0));
|
|
103
|
-
});
|
|
104
|
-
}, [series]);
|
|
105
105
|
|
|
106
106
|
// Set default min domain to 0 for area chart, but only if there are no negative values
|
|
107
107
|
const yAxisConfig = {
|
|
@@ -116,11 +116,13 @@ export const AreaChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) =
|
|
|
116
116
|
};
|
|
117
117
|
return /*#__PURE__*/_jsxs(CartesianChart, _objectSpread(_objectSpread({}, chartProps), {}, {
|
|
118
118
|
ref: ref,
|
|
119
|
-
inset:
|
|
119
|
+
inset: inset,
|
|
120
120
|
series: seriesToRender,
|
|
121
121
|
xAxis: xAxisConfig,
|
|
122
122
|
yAxis: yAxisConfig,
|
|
123
|
-
children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _objectSpread({
|
|
123
|
+
children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _objectSpread({
|
|
124
|
+
axisId: xAxisId
|
|
125
|
+
}, xAxisVisualProps)), showYAxis && /*#__PURE__*/_jsx(YAxis, _objectSpread({
|
|
124
126
|
axisId: yAxisId
|
|
125
127
|
}, yAxisVisualProps)), series === null || series === void 0 ? void 0 : series.map(_ref4 => {
|
|
126
128
|
let {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["d", "fill", "patternSize", "dotSize", "peakOpacity", "baselineOpacity", "baseline", "yAxisId", "gradient", "animate", "transitions", "transition"];
|
|
1
|
+
const _excluded = ["d", "fill", "patternSize", "dotSize", "peakOpacity", "baselineOpacity", "baseline", "xAxisId", "yAxisId", "gradient", "animate", "transitions", "transition"];
|
|
2
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
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
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; }
|
|
@@ -27,6 +27,7 @@ export const DottedArea = /*#__PURE__*/memo(_ref => {
|
|
|
27
27
|
peakOpacity = 1,
|
|
28
28
|
baselineOpacity = 0,
|
|
29
29
|
baseline,
|
|
30
|
+
xAxisId,
|
|
30
31
|
yAxisId,
|
|
31
32
|
gradient: gradientProp,
|
|
32
33
|
animate,
|
|
@@ -35,19 +36,22 @@ export const DottedArea = /*#__PURE__*/memo(_ref => {
|
|
|
35
36
|
} = _ref,
|
|
36
37
|
pathProps = _objectWithoutProperties(_ref, _excluded);
|
|
37
38
|
const {
|
|
39
|
+
layout,
|
|
40
|
+
getXAxis,
|
|
38
41
|
getYAxis
|
|
39
42
|
} = useCartesianChartContext();
|
|
40
43
|
const patternId = useId();
|
|
41
44
|
const gradientId = useId();
|
|
42
45
|
const maskId = useId();
|
|
43
46
|
const dotCenterPosition = patternSize / 2;
|
|
44
|
-
const
|
|
47
|
+
const valueAxisConfig = layout !== 'horizontal' ? getYAxis(yAxisId) : getXAxis(xAxisId);
|
|
48
|
+
const gradientAxis = layout !== 'horizontal' ? 'y' : 'x';
|
|
45
49
|
const gradient = useMemo(() => {
|
|
46
50
|
if (gradientProp) return gradientProp;
|
|
47
|
-
if (!
|
|
48
|
-
const baselineValue = getBaseline(
|
|
49
|
-
return createGradient(
|
|
50
|
-
}, [gradientProp,
|
|
51
|
+
if (!valueAxisConfig) return;
|
|
52
|
+
const baselineValue = getBaseline(valueAxisConfig.domain, baseline);
|
|
53
|
+
return createGradient(valueAxisConfig.domain, baselineValue, fill, peakOpacity, baselineOpacity, gradientAxis);
|
|
54
|
+
}, [gradientProp, valueAxisConfig, fill, baseline, peakOpacity, baselineOpacity, gradientAxis]);
|
|
51
55
|
return /*#__PURE__*/_jsxs("g", {
|
|
52
56
|
children: [/*#__PURE__*/_jsxs("defs", {
|
|
53
57
|
children: [/*#__PURE__*/_jsx("pattern", {
|
|
@@ -77,6 +81,7 @@ export const DottedArea = /*#__PURE__*/memo(_ref => {
|
|
|
77
81
|
gradient: gradient,
|
|
78
82
|
id: gradientId,
|
|
79
83
|
transition: (_transitions$update = transitions === null || transitions === void 0 ? void 0 : transitions.update) !== null && _transitions$update !== void 0 ? _transitions$update : transition,
|
|
84
|
+
xAxisId: xAxisId,
|
|
80
85
|
yAxisId: yAxisId
|
|
81
86
|
})]
|
|
82
87
|
}), /*#__PURE__*/_jsx(Path, _objectSpread({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["d", "fill", "fillOpacity", "peakOpacity", "baselineOpacity", "baseline", "yAxisId", "gradient", "animate", "transitions", "transition"];
|
|
1
|
+
const _excluded = ["d", "fill", "fillOpacity", "peakOpacity", "baselineOpacity", "baseline", "xAxisId", "yAxisId", "gradient", "animate", "transitions", "transition"];
|
|
2
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
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
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; }
|
|
@@ -29,6 +29,7 @@ export const GradientArea = /*#__PURE__*/memo(_ref => {
|
|
|
29
29
|
peakOpacity = 0.3,
|
|
30
30
|
baselineOpacity = 0,
|
|
31
31
|
baseline,
|
|
32
|
+
xAxisId,
|
|
32
33
|
yAxisId,
|
|
33
34
|
gradient: gradientProp,
|
|
34
35
|
animate,
|
|
@@ -37,16 +38,19 @@ export const GradientArea = /*#__PURE__*/memo(_ref => {
|
|
|
37
38
|
} = _ref,
|
|
38
39
|
pathProps = _objectWithoutProperties(_ref, _excluded);
|
|
39
40
|
const {
|
|
41
|
+
layout,
|
|
42
|
+
getXAxis,
|
|
40
43
|
getYAxis
|
|
41
44
|
} = useCartesianChartContext();
|
|
42
45
|
const patternId = useId();
|
|
43
|
-
const
|
|
46
|
+
const valueAxisConfig = layout !== 'horizontal' ? getYAxis(yAxisId) : getXAxis(xAxisId);
|
|
47
|
+
const gradientAxis = layout !== 'horizontal' ? 'y' : 'x';
|
|
44
48
|
const gradient = useMemo(() => {
|
|
45
49
|
if (gradientProp) return gradientProp;
|
|
46
|
-
if (!
|
|
47
|
-
const baselineValue = getBaseline(
|
|
48
|
-
return createGradient(
|
|
49
|
-
}, [gradientProp,
|
|
50
|
+
if (!valueAxisConfig) return;
|
|
51
|
+
const baselineValue = getBaseline(valueAxisConfig.domain, baseline);
|
|
52
|
+
return createGradient(valueAxisConfig.domain, baselineValue, fill, peakOpacity, baselineOpacity, gradientAxis);
|
|
53
|
+
}, [gradientProp, valueAxisConfig, fill, baseline, peakOpacity, baselineOpacity, gradientAxis]);
|
|
50
54
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
51
55
|
children: [gradient && /*#__PURE__*/_jsx("defs", {
|
|
52
56
|
children: /*#__PURE__*/_jsx(Gradient, {
|
|
@@ -54,6 +58,7 @@ export const GradientArea = /*#__PURE__*/memo(_ref => {
|
|
|
54
58
|
gradient: gradient,
|
|
55
59
|
id: patternId,
|
|
56
60
|
transition: (_transitions$update = transitions === null || transitions === void 0 ? void 0 : transitions.update) !== null && _transitions$update !== void 0 ? _transitions$update : transition,
|
|
61
|
+
xAxisId: xAxisId,
|
|
57
62
|
yAxisId: yAxisId
|
|
58
63
|
})
|
|
59
64
|
}), /*#__PURE__*/_jsx(Path, _objectSpread({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["d", "fill", "fillOpacity", "yAxisId", "animate", "transitions", "transition", "gradient"];
|
|
1
|
+
const _excluded = ["d", "fill", "fillOpacity", "xAxisId", "yAxisId", "animate", "transitions", "transition", "gradient"];
|
|
2
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
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
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; }
|
|
@@ -21,6 +21,7 @@ export const SolidArea = /*#__PURE__*/memo(_ref => {
|
|
|
21
21
|
d,
|
|
22
22
|
fill = 'var(--color-fgPrimary)',
|
|
23
23
|
fillOpacity = 1,
|
|
24
|
+
xAxisId,
|
|
24
25
|
yAxisId,
|
|
25
26
|
animate,
|
|
26
27
|
transitions,
|
|
@@ -36,6 +37,7 @@ export const SolidArea = /*#__PURE__*/memo(_ref => {
|
|
|
36
37
|
gradient: gradient,
|
|
37
38
|
id: patternId,
|
|
38
39
|
transition: (_transitions$update = transitions === null || transitions === void 0 ? void 0 : transitions.update) !== null && _transitions$update !== void 0 ? _transitions$update : transition,
|
|
40
|
+
xAxisId: xAxisId,
|
|
39
41
|
yAxisId: yAxisId
|
|
40
42
|
})
|
|
41
43
|
}), /*#__PURE__*/_jsx(Path, _objectSpread({
|
package/esm/chart/axis/XAxis.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["position", "showGrid", "requestedTickCount", "ticks", "tickLabelFormatter", "TickLabelComponent", "style", "className", "styles", "classNames", "GridLineComponent", "LineComponent", "TickMarkLineComponent", "tickMarkLabelGap", "minTickLabelGap", "showTickMarks", "showLine", "tickMarkSize", "tickInterval", "tickMinStep", "tickMaxStep", "label", "labelGap", "height", "testID", "bandGridLinePlacement", "bandTickMarkPlacement"];
|
|
1
|
+
const _excluded = ["axisId", "position", "showGrid", "requestedTickCount", "ticks", "tickLabelFormatter", "TickLabelComponent", "style", "className", "styles", "classNames", "GridLineComponent", "LineComponent", "TickMarkLineComponent", "tickMarkLabelGap", "minTickLabelGap", "showTickMarks", "showLine", "tickMarkSize", "tickInterval", "tickMinStep", "tickMaxStep", "label", "labelGap", "height", "testID", "bandGridLinePlacement", "bandTickMarkPlacement"];
|
|
2
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
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
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; }
|
|
@@ -24,6 +24,7 @@ const axisTickMarkCss = "cds-axisTickMarkCss-a6j4s2q";
|
|
|
24
24
|
const axisLineCss = "cds-axisLineCss-a12llxjj";
|
|
25
25
|
export const XAxis = /*#__PURE__*/memo(_ref => {
|
|
26
26
|
let {
|
|
27
|
+
axisId,
|
|
27
28
|
position = 'bottom',
|
|
28
29
|
showGrid,
|
|
29
30
|
requestedTickCount,
|
|
@@ -56,6 +57,7 @@ export const XAxis = /*#__PURE__*/memo(_ref => {
|
|
|
56
57
|
const registrationId = useId();
|
|
57
58
|
const {
|
|
58
59
|
animate,
|
|
60
|
+
layout,
|
|
59
61
|
getXScale,
|
|
60
62
|
getXAxis,
|
|
61
63
|
registerAxis,
|
|
@@ -63,8 +65,8 @@ export const XAxis = /*#__PURE__*/memo(_ref => {
|
|
|
63
65
|
getAxisBounds,
|
|
64
66
|
drawingArea
|
|
65
67
|
} = useCartesianChartContext();
|
|
66
|
-
const xScale = getXScale();
|
|
67
|
-
const xAxis = getXAxis();
|
|
68
|
+
const xScale = getXScale(axisId);
|
|
69
|
+
const xAxis = getXAxis(axisId);
|
|
68
70
|
const axisBounds = getAxisBounds(registrationId);
|
|
69
71
|
useEffect(() => {
|
|
70
72
|
registerAxis(registrationId, position, height);
|
|
@@ -75,15 +77,12 @@ export const XAxis = /*#__PURE__*/memo(_ref => {
|
|
|
75
77
|
// If we have string labels and no custom formatter, use the labels
|
|
76
78
|
const axisData = xAxis === null || xAxis === void 0 ? void 0 : xAxis.data;
|
|
77
79
|
const hasStringLabels = axisData && Array.isArray(axisData) && typeof axisData[0] === 'string';
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
// For band scales with string data, value is an index
|
|
81
|
-
if (hasStringLabels && typeof value === 'number' && axisData[value] !== undefined) {
|
|
82
|
-
finalValue = axisData[value];
|
|
80
|
+
if (hasStringLabels && !tickLabelFormatter && axisData[value] !== undefined) {
|
|
81
|
+
return axisData[value];
|
|
83
82
|
}
|
|
84
83
|
|
|
85
|
-
//
|
|
86
|
-
return (_tickLabelFormatter = tickLabelFormatter === null || tickLabelFormatter === void 0 ? void 0 : tickLabelFormatter(
|
|
84
|
+
// Otherwise passes raw index to formatter
|
|
85
|
+
return (_tickLabelFormatter = tickLabelFormatter === null || tickLabelFormatter === void 0 ? void 0 : tickLabelFormatter(value)) !== null && _tickLabelFormatter !== void 0 ? _tickLabelFormatter : value;
|
|
87
86
|
}, [xAxis === null || xAxis === void 0 ? void 0 : xAxis.data, tickLabelFormatter]);
|
|
88
87
|
const ticksData = useMemo(() => {
|
|
89
88
|
if (!xScale) return [];
|
|
@@ -105,7 +104,7 @@ export const XAxis = /*#__PURE__*/memo(_ref => {
|
|
|
105
104
|
return getAxisTicksData({
|
|
106
105
|
scaleFunction: xScale,
|
|
107
106
|
ticks,
|
|
108
|
-
requestedTickCount,
|
|
107
|
+
requestedTickCount: requestedTickCount !== null && requestedTickCount !== void 0 ? requestedTickCount : layout === 'horizontal' ? 5 : undefined,
|
|
109
108
|
categories,
|
|
110
109
|
possibleTickValues: axisData && Array.isArray(axisData) && typeof axisData[0] === 'string' ? Array.from({
|
|
111
110
|
length: axisData.length
|
|
@@ -116,7 +115,7 @@ export const XAxis = /*#__PURE__*/memo(_ref => {
|
|
|
116
115
|
maxStep: tickMaxStep
|
|
117
116
|
}
|
|
118
117
|
});
|
|
119
|
-
}, [ticks, xScale, requestedTickCount, tickInterval, tickMinStep, tickMaxStep, xAxis === null || xAxis === void 0 ? void 0 : xAxis.data]);
|
|
118
|
+
}, [ticks, xScale, requestedTickCount, tickInterval, tickMinStep, tickMaxStep, xAxis === null || xAxis === void 0 ? void 0 : xAxis.data, layout]);
|
|
120
119
|
const isBandScale = useMemo(() => {
|
|
121
120
|
if (!xScale) return false;
|
|
122
121
|
return isCategoricalScale(xScale);
|