@mui/x-charts 7.0.0-alpha.8 → 7.0.0-beta.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/BarChart/BarChart.js +1 -19
- package/BarChart/formatter.js +1 -1
- package/CHANGELOG.md +508 -30
- package/ChartContainer/ChartContainer.d.ts +12 -0
- package/ChartContainer/ChartContainer.js +197 -0
- package/ChartContainer/index.d.ts +1 -11
- package/ChartContainer/index.js +9 -63
- package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -54
- package/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +2 -54
- package/ChartsTooltip/DefaultChartsItemTooltipContent.js +3 -15
- package/LineChart/LineChart.js +1 -23
- package/LineChart/formatter.js +6 -2
- package/PieChart/PieArcLabel.js +1 -1
- package/PieChart/PieChart.js +1 -46
- package/README.md +3 -3
- package/ResponsiveChartContainer/ResponsiveChartContainer.d.ts +16 -0
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +250 -0
- package/ResponsiveChartContainer/index.d.ts +1 -15
- package/ResponsiveChartContainer/index.js +8 -113
- package/ScatterChart/Scatter.js +1 -20
- package/ScatterChart/ScatterChart.js +1 -20
- package/SparkLineChart/SparkLineChart.d.ts +2 -2
- package/SparkLineChart/SparkLineChart.js +2 -2
- package/esm/BarChart/BarChart.js +1 -19
- package/esm/BarChart/formatter.js +1 -1
- package/esm/ChartContainer/ChartContainer.js +189 -0
- package/esm/ChartContainer/index.js +1 -61
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +2 -54
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +2 -54
- package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +4 -15
- package/esm/LineChart/LineChart.js +1 -23
- package/esm/LineChart/formatter.js +6 -2
- package/esm/PieChart/PieArcLabel.js +1 -1
- package/esm/PieChart/PieChart.js +1 -46
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +245 -0
- package/esm/ResponsiveChartContainer/index.js +1 -115
- package/esm/ScatterChart/Scatter.js +1 -20
- package/esm/ScatterChart/ScatterChart.js +1 -20
- package/esm/SparkLineChart/SparkLineChart.js +2 -2
- package/esm/hooks/useAxisEvents.js +1 -3
- package/esm/internals/stackSeries.js +5 -3
- package/esm/models/index.js +1 -0
- package/esm/models/stacking.js +1 -0
- package/hooks/useAxisEvents.js +1 -3
- package/index.js +1 -1
- package/internals/defaultizeColor.d.ts +9 -9
- package/internals/stackSeries.d.ts +8 -3
- package/internals/stackSeries.js +4 -3
- package/legacy/BarChart/BarChart.js +1 -19
- package/legacy/BarChart/formatter.js +1 -1
- package/legacy/ChartContainer/ChartContainer.js +187 -0
- package/legacy/ChartContainer/index.js +1 -59
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +2 -54
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
- package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +2 -54
- package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +4 -15
- package/legacy/LineChart/LineChart.js +1 -23
- package/legacy/LineChart/formatter.js +7 -3
- package/legacy/PieChart/PieArcLabel.js +3 -1
- package/legacy/PieChart/PieChart.js +1 -46
- package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +253 -0
- package/legacy/ResponsiveChartContainer/index.js +1 -123
- package/legacy/ScatterChart/Scatter.js +1 -20
- package/legacy/ScatterChart/ScatterChart.js +1 -20
- package/legacy/SparkLineChart/SparkLineChart.js +2 -2
- package/legacy/hooks/useAxisEvents.js +1 -3
- package/legacy/index.js +1 -1
- package/legacy/internals/stackSeries.js +5 -3
- package/legacy/models/index.js +1 -0
- package/legacy/models/stacking.js +1 -0
- package/models/index.d.ts +1 -0
- package/models/index.js +11 -0
- package/models/seriesType/bar.d.ts +8 -2
- package/models/seriesType/common.d.ts +3 -4
- package/models/seriesType/index.d.ts +0 -1
- package/models/seriesType/line.d.ts +7 -1
- package/models/stacking.d.ts +2 -0
- package/models/stacking.js +5 -0
- package/modern/BarChart/BarChart.js +1 -19
- package/modern/BarChart/formatter.js +1 -1
- package/modern/ChartContainer/ChartContainer.js +189 -0
- package/modern/ChartContainer/index.js +1 -61
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +2 -54
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +2 -54
- package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +3 -15
- package/modern/LineChart/LineChart.js +1 -23
- package/modern/LineChart/formatter.js +6 -2
- package/modern/PieChart/PieArcLabel.js +1 -1
- package/modern/PieChart/PieChart.js +1 -46
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +242 -0
- package/modern/ResponsiveChartContainer/index.js +1 -112
- package/modern/ScatterChart/Scatter.js +1 -20
- package/modern/ScatterChart/ScatterChart.js +1 -20
- package/modern/SparkLineChart/SparkLineChart.js +2 -2
- package/modern/hooks/useAxisEvents.js +1 -3
- package/modern/index.js +1 -1
- package/modern/internals/stackSeries.js +4 -3
- package/modern/models/index.js +1 -0
- package/modern/models/stacking.js +1 -0
- package/package.json +7 -7
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["width", "height"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
7
|
+
import ownerWindow from '@mui/utils/ownerWindow';
|
|
8
|
+
import { styled } from '@mui/material/styles';
|
|
9
|
+
import { ChartContainer } from '../ChartContainer';
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
const useChartDimensions = (inWidth, inHeight) => {
|
|
12
|
+
const rootRef = React.useRef(null);
|
|
13
|
+
const displayError = React.useRef(false);
|
|
14
|
+
const [width, setWidth] = React.useState(0);
|
|
15
|
+
const [height, setHeight] = React.useState(0);
|
|
16
|
+
|
|
17
|
+
// Adaptation of the `computeSizeAndPublishResizeEvent` from the grid.
|
|
18
|
+
const computeSize = React.useCallback(() => {
|
|
19
|
+
const mainEl = rootRef == null ? void 0 : rootRef.current;
|
|
20
|
+
if (!mainEl) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const win = ownerWindow(mainEl);
|
|
24
|
+
const computedStyle = win.getComputedStyle(mainEl);
|
|
25
|
+
const newHeight = Math.floor(parseFloat(computedStyle.height)) || 0;
|
|
26
|
+
const newWidth = Math.floor(parseFloat(computedStyle.width)) || 0;
|
|
27
|
+
setWidth(newWidth);
|
|
28
|
+
setHeight(newHeight);
|
|
29
|
+
}, []);
|
|
30
|
+
React.useEffect(() => {
|
|
31
|
+
// Ensure the error detection occurs after the first rendering.
|
|
32
|
+
displayError.current = true;
|
|
33
|
+
}, []);
|
|
34
|
+
useEnhancedEffect(() => {
|
|
35
|
+
if (inWidth !== undefined && inHeight !== undefined) {
|
|
36
|
+
return () => {};
|
|
37
|
+
}
|
|
38
|
+
computeSize();
|
|
39
|
+
const elementToObserve = rootRef.current;
|
|
40
|
+
if (typeof ResizeObserver === 'undefined') {
|
|
41
|
+
return () => {};
|
|
42
|
+
}
|
|
43
|
+
let animationFrame;
|
|
44
|
+
const observer = new ResizeObserver(() => {
|
|
45
|
+
// See https://github.com/mui/mui-x/issues/8733
|
|
46
|
+
animationFrame = requestAnimationFrame(() => {
|
|
47
|
+
computeSize();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
if (elementToObserve) {
|
|
51
|
+
observer.observe(elementToObserve);
|
|
52
|
+
}
|
|
53
|
+
return () => {
|
|
54
|
+
if (animationFrame) {
|
|
55
|
+
window.cancelAnimationFrame(animationFrame);
|
|
56
|
+
}
|
|
57
|
+
if (elementToObserve) {
|
|
58
|
+
observer.unobserve(elementToObserve);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}, [computeSize, inHeight, inWidth]);
|
|
62
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
63
|
+
if (displayError.current && inWidth === undefined && width === 0) {
|
|
64
|
+
console.error(`MUI X Charts: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
|
|
65
|
+
displayError.current = false;
|
|
66
|
+
}
|
|
67
|
+
if (displayError.current && inHeight === undefined && height === 0) {
|
|
68
|
+
console.error(`MUI X Charts: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`);
|
|
69
|
+
displayError.current = false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return [rootRef, inWidth != null ? inWidth : width, inHeight != null ? inHeight : height];
|
|
73
|
+
};
|
|
74
|
+
const ResizableContainer = styled('div', {
|
|
75
|
+
name: 'MuiResponsiveChart',
|
|
76
|
+
slot: 'Container'
|
|
77
|
+
})(({
|
|
78
|
+
ownerState
|
|
79
|
+
}) => {
|
|
80
|
+
var _ownerState$width, _ownerState$height;
|
|
81
|
+
return {
|
|
82
|
+
width: (_ownerState$width = ownerState.width) != null ? _ownerState$width : '100%',
|
|
83
|
+
height: (_ownerState$height = ownerState.height) != null ? _ownerState$height : '100%',
|
|
84
|
+
display: 'flex',
|
|
85
|
+
position: 'relative',
|
|
86
|
+
flexGrow: 1,
|
|
87
|
+
flexDirection: 'column',
|
|
88
|
+
alignItems: 'center',
|
|
89
|
+
justifyContent: 'center',
|
|
90
|
+
overflow: 'hidden',
|
|
91
|
+
'&>svg': {
|
|
92
|
+
width: '100%',
|
|
93
|
+
height: '100%'
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
const ResponsiveChartContainer = /*#__PURE__*/React.forwardRef(function ResponsiveChartContainer(props, ref) {
|
|
98
|
+
const {
|
|
99
|
+
width: inWidth,
|
|
100
|
+
height: inHeight
|
|
101
|
+
} = props,
|
|
102
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
103
|
+
const [containerRef, width, height] = useChartDimensions(inWidth, inHeight);
|
|
104
|
+
return /*#__PURE__*/_jsx(ResizableContainer, {
|
|
105
|
+
ref: containerRef,
|
|
106
|
+
ownerState: {
|
|
107
|
+
width: inWidth,
|
|
108
|
+
height: inHeight
|
|
109
|
+
},
|
|
110
|
+
children: width && height ? /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
|
|
111
|
+
width: width,
|
|
112
|
+
height: height,
|
|
113
|
+
ref: ref
|
|
114
|
+
})) : null
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
|
|
118
|
+
// ----------------------------- Warning --------------------------------
|
|
119
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
120
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
121
|
+
// ----------------------------------------------------------------------
|
|
122
|
+
children: PropTypes.node,
|
|
123
|
+
className: PropTypes.string,
|
|
124
|
+
/**
|
|
125
|
+
* Color palette used to colorize multiple series.
|
|
126
|
+
* @default blueberryTwilightPalette
|
|
127
|
+
*/
|
|
128
|
+
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
129
|
+
/**
|
|
130
|
+
* An array of objects that can be used to populate series and axes data using their `dataKey` property.
|
|
131
|
+
*/
|
|
132
|
+
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
133
|
+
desc: PropTypes.string,
|
|
134
|
+
/**
|
|
135
|
+
* If `true`, the charts will not listen to the mouse move event.
|
|
136
|
+
* It might break interactive features, but will improve performance.
|
|
137
|
+
* @default false
|
|
138
|
+
*/
|
|
139
|
+
disableAxisListener: PropTypes.bool,
|
|
140
|
+
/**
|
|
141
|
+
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
142
|
+
* @default undefined
|
|
143
|
+
*/
|
|
144
|
+
height: PropTypes.number,
|
|
145
|
+
/**
|
|
146
|
+
* The margin between the SVG and the drawing area.
|
|
147
|
+
* It's used for leaving some space for extra information such as the x- and y-axis or legend.
|
|
148
|
+
* Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
|
|
149
|
+
* @default object Depends on the charts type.
|
|
150
|
+
*/
|
|
151
|
+
margin: PropTypes.shape({
|
|
152
|
+
bottom: PropTypes.number,
|
|
153
|
+
left: PropTypes.number,
|
|
154
|
+
right: PropTypes.number,
|
|
155
|
+
top: PropTypes.number
|
|
156
|
+
}),
|
|
157
|
+
/**
|
|
158
|
+
* The array of series to display.
|
|
159
|
+
* Each type of series has its own specificity.
|
|
160
|
+
* Please refer to the appropriate docs page to learn more about it.
|
|
161
|
+
*/
|
|
162
|
+
series: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
163
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
164
|
+
title: PropTypes.string,
|
|
165
|
+
viewBox: PropTypes.shape({
|
|
166
|
+
height: PropTypes.number,
|
|
167
|
+
width: PropTypes.number,
|
|
168
|
+
x: PropTypes.number,
|
|
169
|
+
y: PropTypes.number
|
|
170
|
+
}),
|
|
171
|
+
/**
|
|
172
|
+
* The width of the chart in px. If not defined, it takes the width of the parent element.
|
|
173
|
+
* @default undefined
|
|
174
|
+
*/
|
|
175
|
+
width: PropTypes.number,
|
|
176
|
+
/**
|
|
177
|
+
* The configuration of the x-axes.
|
|
178
|
+
* If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
|
|
179
|
+
*/
|
|
180
|
+
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
181
|
+
axisId: PropTypes.string,
|
|
182
|
+
classes: PropTypes.object,
|
|
183
|
+
data: PropTypes.array,
|
|
184
|
+
dataKey: PropTypes.string,
|
|
185
|
+
disableLine: PropTypes.bool,
|
|
186
|
+
disableTicks: PropTypes.bool,
|
|
187
|
+
fill: PropTypes.string,
|
|
188
|
+
hideTooltip: PropTypes.bool,
|
|
189
|
+
id: PropTypes.string,
|
|
190
|
+
label: PropTypes.string,
|
|
191
|
+
labelFontSize: PropTypes.number,
|
|
192
|
+
labelStyle: PropTypes.object,
|
|
193
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
194
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
195
|
+
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
196
|
+
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
197
|
+
slotProps: PropTypes.object,
|
|
198
|
+
slots: PropTypes.object,
|
|
199
|
+
stroke: PropTypes.string,
|
|
200
|
+
tickFontSize: PropTypes.number,
|
|
201
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
202
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
203
|
+
tickLabelStyle: PropTypes.object,
|
|
204
|
+
tickMaxStep: PropTypes.number,
|
|
205
|
+
tickMinStep: PropTypes.number,
|
|
206
|
+
tickNumber: PropTypes.number,
|
|
207
|
+
tickSize: PropTypes.number,
|
|
208
|
+
valueFormatter: PropTypes.func
|
|
209
|
+
})),
|
|
210
|
+
/**
|
|
211
|
+
* The configuration of the y-axes.
|
|
212
|
+
* If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
|
|
213
|
+
*/
|
|
214
|
+
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
215
|
+
axisId: PropTypes.string,
|
|
216
|
+
classes: PropTypes.object,
|
|
217
|
+
data: PropTypes.array,
|
|
218
|
+
dataKey: PropTypes.string,
|
|
219
|
+
disableLine: PropTypes.bool,
|
|
220
|
+
disableTicks: PropTypes.bool,
|
|
221
|
+
fill: PropTypes.string,
|
|
222
|
+
hideTooltip: PropTypes.bool,
|
|
223
|
+
id: PropTypes.string,
|
|
224
|
+
label: PropTypes.string,
|
|
225
|
+
labelFontSize: PropTypes.number,
|
|
226
|
+
labelStyle: PropTypes.object,
|
|
227
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
228
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
229
|
+
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
230
|
+
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
231
|
+
slotProps: PropTypes.object,
|
|
232
|
+
slots: PropTypes.object,
|
|
233
|
+
stroke: PropTypes.string,
|
|
234
|
+
tickFontSize: PropTypes.number,
|
|
235
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
236
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
237
|
+
tickLabelStyle: PropTypes.object,
|
|
238
|
+
tickMaxStep: PropTypes.number,
|
|
239
|
+
tickMinStep: PropTypes.number,
|
|
240
|
+
tickNumber: PropTypes.number,
|
|
241
|
+
tickSize: PropTypes.number,
|
|
242
|
+
valueFormatter: PropTypes.func
|
|
243
|
+
}))
|
|
244
|
+
} : void 0;
|
|
245
|
+
export { ResponsiveChartContainer };
|
|
@@ -1,115 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["width", "height"];
|
|
4
|
-
import * as React from 'react';
|
|
5
|
-
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
6
|
-
import ownerWindow from '@mui/utils/ownerWindow';
|
|
7
|
-
import { styled } from '@mui/material/styles';
|
|
8
|
-
import { ChartContainer } from '../ChartContainer';
|
|
9
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
-
const useChartDimensions = (inWidth, inHeight) => {
|
|
11
|
-
const rootRef = React.useRef(null);
|
|
12
|
-
const displayError = React.useRef(false);
|
|
13
|
-
const [width, setWidth] = React.useState(0);
|
|
14
|
-
const [height, setHeight] = React.useState(0);
|
|
15
|
-
|
|
16
|
-
// Adaptation of the `computeSizeAndPublishResizeEvent` from the grid.
|
|
17
|
-
const computeSize = React.useCallback(() => {
|
|
18
|
-
const mainEl = rootRef == null ? void 0 : rootRef.current;
|
|
19
|
-
if (!mainEl) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const win = ownerWindow(mainEl);
|
|
23
|
-
const computedStyle = win.getComputedStyle(mainEl);
|
|
24
|
-
const newHeight = Math.floor(parseFloat(computedStyle.height)) || 0;
|
|
25
|
-
const newWidth = Math.floor(parseFloat(computedStyle.width)) || 0;
|
|
26
|
-
setWidth(newWidth);
|
|
27
|
-
setHeight(newHeight);
|
|
28
|
-
}, []);
|
|
29
|
-
React.useEffect(() => {
|
|
30
|
-
// Ensure the error detection occurs after the first rendering.
|
|
31
|
-
displayError.current = true;
|
|
32
|
-
}, []);
|
|
33
|
-
useEnhancedEffect(() => {
|
|
34
|
-
if (inWidth !== undefined && inHeight !== undefined) {
|
|
35
|
-
return () => {};
|
|
36
|
-
}
|
|
37
|
-
computeSize();
|
|
38
|
-
const elementToObserve = rootRef.current;
|
|
39
|
-
if (typeof ResizeObserver === 'undefined') {
|
|
40
|
-
return () => {};
|
|
41
|
-
}
|
|
42
|
-
let animationFrame;
|
|
43
|
-
const observer = new ResizeObserver(() => {
|
|
44
|
-
// See https://github.com/mui/mui-x/issues/8733
|
|
45
|
-
animationFrame = requestAnimationFrame(() => {
|
|
46
|
-
computeSize();
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
if (elementToObserve) {
|
|
50
|
-
observer.observe(elementToObserve);
|
|
51
|
-
}
|
|
52
|
-
return () => {
|
|
53
|
-
if (animationFrame) {
|
|
54
|
-
window.cancelAnimationFrame(animationFrame);
|
|
55
|
-
}
|
|
56
|
-
if (elementToObserve) {
|
|
57
|
-
observer.unobserve(elementToObserve);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}, [computeSize, inHeight, inWidth]);
|
|
61
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
62
|
-
if (displayError.current && inWidth === undefined && width === 0) {
|
|
63
|
-
console.error(`MUI X Charts: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
|
|
64
|
-
displayError.current = false;
|
|
65
|
-
}
|
|
66
|
-
if (displayError.current && inHeight === undefined && height === 0) {
|
|
67
|
-
console.error(`MUI X Charts: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`);
|
|
68
|
-
displayError.current = false;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return [rootRef, inWidth != null ? inWidth : width, inHeight != null ? inHeight : height];
|
|
72
|
-
};
|
|
73
|
-
const ResizableContainer = styled('div', {
|
|
74
|
-
name: 'MuiResponsiveChart',
|
|
75
|
-
slot: 'Container'
|
|
76
|
-
})(({
|
|
77
|
-
ownerState
|
|
78
|
-
}) => {
|
|
79
|
-
var _ownerState$width, _ownerState$height;
|
|
80
|
-
return {
|
|
81
|
-
width: (_ownerState$width = ownerState.width) != null ? _ownerState$width : '100%',
|
|
82
|
-
height: (_ownerState$height = ownerState.height) != null ? _ownerState$height : '100%',
|
|
83
|
-
display: 'flex',
|
|
84
|
-
position: 'relative',
|
|
85
|
-
flexGrow: 1,
|
|
86
|
-
flexDirection: 'column',
|
|
87
|
-
alignItems: 'center',
|
|
88
|
-
justifyContent: 'center',
|
|
89
|
-
overflow: 'hidden',
|
|
90
|
-
'&>svg': {
|
|
91
|
-
width: '100%',
|
|
92
|
-
height: '100%'
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
});
|
|
96
|
-
export const ResponsiveChartContainer = /*#__PURE__*/React.forwardRef(function ResponsiveChartContainer(props, ref) {
|
|
97
|
-
const {
|
|
98
|
-
width: inWidth,
|
|
99
|
-
height: inHeight
|
|
100
|
-
} = props,
|
|
101
|
-
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
102
|
-
const [containerRef, width, height] = useChartDimensions(inWidth, inHeight);
|
|
103
|
-
return /*#__PURE__*/_jsx(ResizableContainer, {
|
|
104
|
-
ref: containerRef,
|
|
105
|
-
ownerState: {
|
|
106
|
-
width: inWidth,
|
|
107
|
-
height: inHeight
|
|
108
|
-
},
|
|
109
|
-
children: width && height ? /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
|
|
110
|
-
width: width,
|
|
111
|
-
height: height,
|
|
112
|
-
ref: ref
|
|
113
|
-
})) : null
|
|
114
|
-
});
|
|
115
|
-
});
|
|
1
|
+
export * from './ResponsiveChartContainer';
|
|
@@ -85,26 +85,7 @@ process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
|
|
|
85
85
|
// ----------------------------------------------------------------------
|
|
86
86
|
color: PropTypes.string.isRequired,
|
|
87
87
|
markerSize: PropTypes.number.isRequired,
|
|
88
|
-
series: PropTypes.
|
|
89
|
-
color: PropTypes.string.isRequired,
|
|
90
|
-
data: PropTypes.arrayOf(PropTypes.shape({
|
|
91
|
-
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
92
|
-
x: PropTypes.number.isRequired,
|
|
93
|
-
y: PropTypes.number.isRequired
|
|
94
|
-
})).isRequired,
|
|
95
|
-
disableHover: PropTypes.bool,
|
|
96
|
-
highlightScope: PropTypes.shape({
|
|
97
|
-
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
98
|
-
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
99
|
-
}),
|
|
100
|
-
id: PropTypes.string.isRequired,
|
|
101
|
-
label: PropTypes.string,
|
|
102
|
-
markerSize: PropTypes.number,
|
|
103
|
-
type: PropTypes.oneOf(['scatter']).isRequired,
|
|
104
|
-
valueFormatter: PropTypes.func.isRequired,
|
|
105
|
-
xAxisKey: PropTypes.string,
|
|
106
|
-
yAxisKey: PropTypes.string
|
|
107
|
-
}).isRequired,
|
|
88
|
+
series: PropTypes.object.isRequired,
|
|
108
89
|
xScale: PropTypes.func.isRequired,
|
|
109
90
|
yScale: PropTypes.func.isRequired
|
|
110
91
|
} : void 0;
|
|
@@ -222,26 +222,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
222
222
|
tickNumber: PropTypes.number,
|
|
223
223
|
tickSize: PropTypes.number
|
|
224
224
|
}), PropTypes.string]),
|
|
225
|
-
series: PropTypes.arrayOf(PropTypes.
|
|
226
|
-
color: PropTypes.string,
|
|
227
|
-
data: PropTypes.arrayOf(PropTypes.shape({
|
|
228
|
-
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
229
|
-
x: PropTypes.number.isRequired,
|
|
230
|
-
y: PropTypes.number.isRequired
|
|
231
|
-
})).isRequired,
|
|
232
|
-
disableHover: PropTypes.bool,
|
|
233
|
-
highlightScope: PropTypes.shape({
|
|
234
|
-
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
235
|
-
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
236
|
-
}),
|
|
237
|
-
id: PropTypes.string,
|
|
238
|
-
label: PropTypes.string,
|
|
239
|
-
markerSize: PropTypes.number,
|
|
240
|
-
type: PropTypes.oneOf(['scatter']),
|
|
241
|
-
valueFormatter: PropTypes.func,
|
|
242
|
-
xAxisKey: PropTypes.string,
|
|
243
|
-
yAxisKey: PropTypes.string
|
|
244
|
-
})).isRequired,
|
|
225
|
+
series: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
245
226
|
/**
|
|
246
227
|
* The props used for each component slot.
|
|
247
228
|
* @default {}
|
|
@@ -42,7 +42,7 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
|
|
|
42
42
|
slotProps,
|
|
43
43
|
data,
|
|
44
44
|
plotType = 'line',
|
|
45
|
-
valueFormatter = v => v.toString(),
|
|
45
|
+
valueFormatter = v => v === null ? '' : v.toString(),
|
|
46
46
|
area,
|
|
47
47
|
curve = 'linear'
|
|
48
48
|
} = props;
|
|
@@ -205,7 +205,7 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
205
205
|
* Formatter used by the tooltip.
|
|
206
206
|
* @param {number} value The value to format.
|
|
207
207
|
* @returns {string} the formatted value.
|
|
208
|
-
* @default (v: number) => v.toString()
|
|
208
|
+
* @default (v: number | null) => (v === null ? '' : v.toString())
|
|
209
209
|
*/
|
|
210
210
|
valueFormatter: PropTypes.func,
|
|
211
211
|
viewBox: PropTypes.shape({
|
|
@@ -61,9 +61,7 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
if (v <= valueAsNumber) {
|
|
64
|
-
if (index === axisData.length - 1 ||
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
Math.abs(value - v) < Math.abs(value - getAsANumber(axisData[index + 1]))) {
|
|
64
|
+
if (index === axisData.length - 1 || Math.abs(getAsANumber(value) - v) < Math.abs(getAsANumber(value) - getAsANumber(axisData[index + 1]))) {
|
|
67
65
|
return true;
|
|
68
66
|
}
|
|
69
67
|
}
|
|
@@ -56,7 +56,8 @@ export const StackOffset = {
|
|
|
56
56
|
export const getStackingGroups = params => {
|
|
57
57
|
const {
|
|
58
58
|
series,
|
|
59
|
-
seriesOrder
|
|
59
|
+
seriesOrder,
|
|
60
|
+
defaultStrategy
|
|
60
61
|
} = params;
|
|
61
62
|
const stackingGroups = [];
|
|
62
63
|
const stackIndex = {};
|
|
@@ -73,11 +74,12 @@ export const getStackingGroups = params => {
|
|
|
73
74
|
stackingOffset: StackOffset.none
|
|
74
75
|
});
|
|
75
76
|
} else if (stackIndex[stack] === undefined) {
|
|
77
|
+
var _ref, _ref2;
|
|
76
78
|
stackIndex[stack] = stackingGroups.length;
|
|
77
79
|
stackingGroups.push({
|
|
78
80
|
ids: [id],
|
|
79
|
-
stackingOrder: StackOrder[stackOrder != null ? stackOrder : 'none'],
|
|
80
|
-
stackingOffset: StackOffset[stackOffset != null ? stackOffset : 'diverging']
|
|
81
|
+
stackingOrder: StackOrder[(_ref = stackOrder != null ? stackOrder : defaultStrategy == null ? void 0 : defaultStrategy.stackOrder) != null ? _ref : 'none'],
|
|
82
|
+
stackingOffset: StackOffset[(_ref2 = stackOffset != null ? stackOffset : defaultStrategy == null ? void 0 : defaultStrategy.stackOffset) != null ? _ref2 : 'diverging']
|
|
81
83
|
});
|
|
82
84
|
} else {
|
|
83
85
|
stackingGroups[stackIndex[stack]].ids.push(id);
|
package/esm/models/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/hooks/useAxisEvents.js
CHANGED
|
@@ -69,9 +69,7 @@ const useAxisEvents = disableAxisListener => {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
if (v <= valueAsNumber) {
|
|
72
|
-
if (index === axisData.length - 1 ||
|
|
73
|
-
// @ts-ignore
|
|
74
|
-
Math.abs(value - v) < Math.abs(value - getAsANumber(axisData[index + 1]))) {
|
|
72
|
+
if (index === axisData.length - 1 || Math.abs(getAsANumber(value) - v) < Math.abs(getAsANumber(value) - getAsANumber(axisData[index + 1]))) {
|
|
75
73
|
return true;
|
|
76
74
|
}
|
|
77
75
|
}
|
package/index.js
CHANGED
|
@@ -39,23 +39,23 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
39
39
|
} | undefined;
|
|
40
40
|
id?: string | undefined;
|
|
41
41
|
color?: string | undefined;
|
|
42
|
-
valueFormatter?: (
|
|
42
|
+
valueFormatter?: (<V extends import("../models/helpers").MakeOptional<import("../models/seriesType").PieValueType, "id">>(value: V) => string) | undefined;
|
|
43
43
|
highlightScope?: Partial<import("..").HighlightScope> | undefined;
|
|
44
44
|
} | {
|
|
45
45
|
type: "bar";
|
|
46
|
-
data?: number[] | undefined;
|
|
46
|
+
data?: (number | null)[] | undefined;
|
|
47
47
|
dataKey?: string | undefined;
|
|
48
48
|
label?: string | undefined;
|
|
49
49
|
layout?: "horizontal" | "vertical" | undefined;
|
|
50
|
+
stackOffset?: import("..").StackOffsetType | undefined;
|
|
50
51
|
id?: string | undefined;
|
|
51
52
|
color: string;
|
|
52
|
-
valueFormatter?: ((value:
|
|
53
|
+
valueFormatter?: (<V_1 extends number | null>(value: V_1) => string) | undefined;
|
|
53
54
|
highlightScope?: Partial<import("..").HighlightScope> | undefined;
|
|
54
55
|
xAxisKey?: string | undefined;
|
|
55
56
|
yAxisKey?: string | undefined;
|
|
56
57
|
stack?: string | undefined;
|
|
57
|
-
|
|
58
|
-
stackOrder?: "reverse" | "none" | "appearance" | "ascending" | "descending" | "insideOut" | undefined;
|
|
58
|
+
stackOrder?: import("..").StackOrderType | undefined;
|
|
59
59
|
} | {
|
|
60
60
|
type: "line";
|
|
61
61
|
data?: (number | null)[] | undefined;
|
|
@@ -67,14 +67,14 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
67
67
|
showMark?: boolean | ((params: import("../models/seriesType").ShowMarkParams<number | Date>) => boolean) | undefined;
|
|
68
68
|
disableHighlight?: boolean | undefined;
|
|
69
69
|
connectNulls?: boolean | undefined;
|
|
70
|
+
stackOffset?: import("..").StackOffsetType | undefined;
|
|
70
71
|
id?: string | undefined;
|
|
71
72
|
color: string;
|
|
72
|
-
valueFormatter?: ((value:
|
|
73
|
+
valueFormatter?: (<V_1 extends number | null>(value: V_1) => string) | undefined;
|
|
73
74
|
highlightScope?: Partial<import("..").HighlightScope> | undefined;
|
|
74
75
|
xAxisKey?: string | undefined;
|
|
75
76
|
yAxisKey?: string | undefined;
|
|
76
|
-
|
|
77
|
-
stackOrder?: "reverse" | "none" | "appearance" | "ascending" | "descending" | "insideOut" | undefined;
|
|
77
|
+
stackOrder?: import("..").StackOrderType | undefined;
|
|
78
78
|
} | {
|
|
79
79
|
type: "scatter";
|
|
80
80
|
data: import("../models/seriesType").ScatterValueType[];
|
|
@@ -83,7 +83,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
83
83
|
disableHover?: boolean | undefined;
|
|
84
84
|
id?: string | undefined;
|
|
85
85
|
color: string;
|
|
86
|
-
valueFormatter?: (
|
|
86
|
+
valueFormatter?: (<V_2 extends import("../models/seriesType").ScatterValueType>(value: V_2) => string) | undefined;
|
|
87
87
|
highlightScope?: Partial<import("..").HighlightScope> | undefined;
|
|
88
88
|
xAxisKey?: string | undefined;
|
|
89
89
|
yAxisKey?: string | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Series } from 'd3-shape';
|
|
2
|
-
import { BarSeriesType, LineSeriesType } from '../models/seriesType';
|
|
2
|
+
import type { BarSeriesType, LineSeriesType } from '../models/seriesType';
|
|
3
|
+
import type { StackOffsetType, StackOrderType } from '../models/stacking';
|
|
3
4
|
type StackableSeries = {
|
|
4
5
|
[id: string]: BarSeriesType;
|
|
5
6
|
} | {
|
|
@@ -8,6 +9,10 @@ type StackableSeries = {
|
|
|
8
9
|
type FormatterParams = {
|
|
9
10
|
series: StackableSeries;
|
|
10
11
|
seriesOrder: string[];
|
|
12
|
+
defaultStrategy?: {
|
|
13
|
+
stackOrder?: StackOrderType;
|
|
14
|
+
stackOffset?: StackOffsetType;
|
|
15
|
+
};
|
|
11
16
|
};
|
|
12
17
|
export type StackingGroupsType = {
|
|
13
18
|
ids: string[];
|
|
@@ -15,10 +20,10 @@ export type StackingGroupsType = {
|
|
|
15
20
|
stackingOffset: (series: Series<any, any>, order: Iterable<number>) => void;
|
|
16
21
|
}[];
|
|
17
22
|
export declare const StackOrder: {
|
|
18
|
-
[key in
|
|
23
|
+
[key in StackOrderType]: (series: Series<any, any>) => number[];
|
|
19
24
|
};
|
|
20
25
|
export declare const StackOffset: {
|
|
21
|
-
[key in
|
|
26
|
+
[key in StackOffsetType]: (series: Series<any, any>, order: Iterable<number>) => void;
|
|
22
27
|
};
|
|
23
28
|
/**
|
|
24
29
|
* Takes a set of series and groups their ids
|
package/internals/stackSeries.js
CHANGED
|
@@ -62,7 +62,8 @@ const StackOffset = exports.StackOffset = {
|
|
|
62
62
|
const getStackingGroups = params => {
|
|
63
63
|
const {
|
|
64
64
|
series,
|
|
65
|
-
seriesOrder
|
|
65
|
+
seriesOrder,
|
|
66
|
+
defaultStrategy
|
|
66
67
|
} = params;
|
|
67
68
|
const stackingGroups = [];
|
|
68
69
|
const stackIndex = {};
|
|
@@ -82,8 +83,8 @@ const getStackingGroups = params => {
|
|
|
82
83
|
stackIndex[stack] = stackingGroups.length;
|
|
83
84
|
stackingGroups.push({
|
|
84
85
|
ids: [id],
|
|
85
|
-
stackingOrder: StackOrder[stackOrder ?? 'none'],
|
|
86
|
-
stackingOffset: StackOffset[stackOffset ?? 'diverging']
|
|
86
|
+
stackingOrder: StackOrder[stackOrder ?? defaultStrategy?.stackOrder ?? 'none'],
|
|
87
|
+
stackingOffset: StackOffset[stackOffset ?? defaultStrategy?.stackOffset ?? 'diverging']
|
|
87
88
|
});
|
|
88
89
|
} else {
|
|
89
90
|
stackingGroups[stackIndex[stack]].ids.push(id);
|
|
@@ -261,25 +261,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
261
261
|
tickNumber: PropTypes.number,
|
|
262
262
|
tickSize: PropTypes.number
|
|
263
263
|
}), PropTypes.string]),
|
|
264
|
-
series: PropTypes.arrayOf(PropTypes.
|
|
265
|
-
color: PropTypes.string,
|
|
266
|
-
data: PropTypes.arrayOf(PropTypes.number),
|
|
267
|
-
dataKey: PropTypes.string,
|
|
268
|
-
highlightScope: PropTypes.shape({
|
|
269
|
-
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
270
|
-
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
271
|
-
}),
|
|
272
|
-
id: PropTypes.string,
|
|
273
|
-
label: PropTypes.string,
|
|
274
|
-
layout: PropTypes.oneOf(['horizontal', 'vertical']),
|
|
275
|
-
stack: PropTypes.string,
|
|
276
|
-
stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
|
|
277
|
-
stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
|
|
278
|
-
type: PropTypes.oneOf(['bar']),
|
|
279
|
-
valueFormatter: PropTypes.func,
|
|
280
|
-
xAxisKey: PropTypes.string,
|
|
281
|
-
yAxisKey: PropTypes.string
|
|
282
|
-
})).isRequired,
|
|
264
|
+
series: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
283
265
|
/**
|
|
284
266
|
* If `true`, animations are skiped.
|
|
285
267
|
* @default false
|
|
@@ -71,7 +71,7 @@ var formatter = function formatter(params, dataset) {
|
|
|
71
71
|
seriesOrder: seriesOrder,
|
|
72
72
|
stackingGroups: stackingGroups,
|
|
73
73
|
series: defaultizeValueFormatter(completedSeries, function (v) {
|
|
74
|
-
return v
|
|
74
|
+
return v === null ? '' : v.toLocaleString();
|
|
75
75
|
})
|
|
76
76
|
};
|
|
77
77
|
};
|