@mui/x-charts 6.0.0-alpha.4 → 6.0.0-alpha.6
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 +18 -10
- package/BarChart/formatter.js +23 -12
- package/CHANGELOG.md +156 -0
- package/ChartContainer/index.js +3 -0
- package/ChartsAxis/ChartsAxis.d.ts +4 -4
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/LineChart/AreaPlot.d.ts +1 -1
- package/LineChart/AreaPlot.js +4 -3
- package/LineChart/LineChart.js +18 -10
- package/LineChart/LinePlot.d.ts +1 -1
- package/LineChart/LinePlot.js +4 -3
- package/LineChart/MarkElement.js +1 -1
- package/LineChart/MarkPlot.d.ts +1 -1
- package/LineChart/MarkPlot.js +5 -3
- package/LineChart/formatter.js +23 -12
- package/PieChart/PieChart.js +13 -8
- package/ScatterChart/Scatter.js +39 -53
- package/ScatterChart/ScatterChart.js +13 -8
- package/SparkLineChart/SparkLineChart.d.ts +55 -0
- package/SparkLineChart/SparkLineChart.js +195 -0
- package/SparkLineChart/index.d.ts +1 -0
- package/SparkLineChart/index.js +12 -0
- package/SparkLineChart/package.json +6 -0
- package/context/CartesianContextProvider.d.ts +3 -1
- package/context/CartesianContextProvider.js +36 -6
- package/context/DrawingProvider.d.ts +1 -1
- package/context/DrawingProvider.js +1 -1
- package/context/SeriesContextProvider.d.ts +3 -2
- package/context/SeriesContextProvider.js +5 -3
- package/esm/BarChart/BarChart.js +21 -10
- package/esm/BarChart/formatter.js +23 -12
- package/esm/ChartContainer/index.js +3 -0
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/esm/LineChart/AreaPlot.js +4 -3
- package/esm/LineChart/LineChart.js +21 -10
- package/esm/LineChart/LinePlot.js +4 -3
- package/esm/LineChart/MarkElement.js +1 -1
- package/esm/LineChart/MarkPlot.js +4 -3
- package/esm/LineChart/formatter.js +23 -13
- package/esm/PieChart/PieChart.js +13 -8
- package/esm/ScatterChart/Scatter.js +39 -53
- package/esm/ScatterChart/ScatterChart.js +13 -8
- package/esm/SparkLineChart/SparkLineChart.js +187 -0
- package/esm/SparkLineChart/index.js +1 -0
- package/esm/context/CartesianContextProvider.js +36 -6
- package/esm/context/DrawingProvider.js +1 -1
- package/esm/context/SeriesContextProvider.js +5 -3
- package/esm/index.js +1 -0
- package/esm/models/index.js +3 -1
- package/index.d.ts +1 -0
- package/index.js +12 -1
- package/internals/defaultizeColor.d.ts +4 -2
- package/legacy/BarChart/BarChart.js +19 -10
- package/legacy/BarChart/formatter.js +23 -10
- package/legacy/ChartContainer/index.js +3 -0
- package/legacy/ChartsAxis/ChartsAxis.js +4 -4
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/legacy/LineChart/AreaPlot.js +4 -3
- package/legacy/LineChart/LineChart.js +19 -10
- package/legacy/LineChart/LinePlot.js +4 -3
- package/legacy/LineChart/MarkElement.js +1 -1
- package/legacy/LineChart/MarkPlot.js +4 -3
- package/legacy/LineChart/formatter.js +23 -11
- package/legacy/PieChart/PieChart.js +13 -8
- package/legacy/ScatterChart/Scatter.js +35 -46
- package/legacy/ScatterChart/ScatterChart.js +13 -8
- package/legacy/SparkLineChart/SparkLineChart.js +191 -0
- package/legacy/SparkLineChart/index.js +1 -0
- package/legacy/context/CartesianContextProvider.js +45 -7
- package/legacy/context/DrawingProvider.js +1 -1
- package/legacy/context/SeriesContextProvider.js +6 -4
- package/legacy/index.js +2 -1
- package/legacy/models/index.js +3 -1
- package/models/axis.d.ts +10 -2
- package/models/index.d.ts +2 -0
- package/models/index.js +11 -0
- package/models/seriesType/bar.d.ts +8 -1
- package/models/seriesType/common.d.ts +2 -2
- package/models/seriesType/config.d.ts +4 -1
- package/models/seriesType/line.d.ts +8 -1
- package/modern/BarChart/BarChart.js +18 -10
- package/modern/BarChart/formatter.js +23 -12
- package/modern/ChartContainer/index.js +3 -0
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/modern/LineChart/AreaPlot.js +4 -3
- package/modern/LineChart/LineChart.js +18 -10
- package/modern/LineChart/LinePlot.js +4 -3
- package/modern/LineChart/MarkElement.js +1 -1
- package/modern/LineChart/MarkPlot.js +4 -3
- package/modern/LineChart/formatter.js +23 -13
- package/modern/PieChart/PieChart.js +13 -8
- package/modern/ScatterChart/Scatter.js +39 -53
- package/modern/ScatterChart/ScatterChart.js +13 -8
- package/modern/SparkLineChart/SparkLineChart.js +187 -0
- package/modern/SparkLineChart/index.js +1 -0
- package/modern/context/CartesianContextProvider.js +36 -6
- package/modern/context/DrawingProvider.js +1 -1
- package/modern/context/SeriesContextProvider.js +5 -3
- package/modern/index.js +2 -1
- package/modern/models/index.js +3 -1
- package/package.json +3 -1
|
@@ -14,60 +14,49 @@ function Scatter(props) {
|
|
|
14
14
|
markerSize = props.markerSize;
|
|
15
15
|
var _React$useContext = React.useContext(InteractionContext),
|
|
16
16
|
item = _React$useContext.item;
|
|
17
|
-
var getXPosition = getValueToPositionMapper(xScale);
|
|
18
|
-
var getYPosition = getValueToPositionMapper(yScale);
|
|
19
17
|
var getInteractionItemProps = useInteractionItemProps(series.highlightScope);
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var
|
|
36
|
-
y = _ref2.y,
|
|
37
|
-
id = _ref2.id;
|
|
38
|
-
return {
|
|
39
|
-
x: getXPosition(x),
|
|
40
|
-
y: getYPosition(y),
|
|
41
|
-
id: id,
|
|
42
|
-
dataIndex: index
|
|
43
|
-
};
|
|
44
|
-
}).filter(isInRange).map(function (_ref3) {
|
|
45
|
-
var x = _ref3.x,
|
|
46
|
-
y = _ref3.y,
|
|
47
|
-
id = _ref3.id,
|
|
48
|
-
dataIndex = _ref3.dataIndex;
|
|
49
|
-
var isHighlighted = getIsHighlighted(item, {
|
|
50
|
-
type: 'scatter',
|
|
51
|
-
seriesId: series.id,
|
|
52
|
-
dataIndex: dataIndex
|
|
53
|
-
}, series.highlightScope);
|
|
54
|
-
var isFaded = !isHighlighted && getIsFaded(item, {
|
|
18
|
+
var cleanData = React.useMemo(function () {
|
|
19
|
+
var getXPosition = getValueToPositionMapper(xScale);
|
|
20
|
+
var getYPosition = getValueToPositionMapper(yScale);
|
|
21
|
+
var xRange = xScale.range();
|
|
22
|
+
var yRange = yScale.range();
|
|
23
|
+
var minXRange = Math.min.apply(Math, _toConsumableArray(xRange));
|
|
24
|
+
var maxXRange = Math.max.apply(Math, _toConsumableArray(xRange));
|
|
25
|
+
var minYRange = Math.min.apply(Math, _toConsumableArray(yRange));
|
|
26
|
+
var maxYRange = Math.max.apply(Math, _toConsumableArray(yRange));
|
|
27
|
+
var temp = [];
|
|
28
|
+
for (var i = 0; i < series.data.length; i += 1) {
|
|
29
|
+
var scatterPoint = series.data[i];
|
|
30
|
+
var x = getXPosition(scatterPoint.x);
|
|
31
|
+
var y = getYPosition(scatterPoint.y);
|
|
32
|
+
var isInRange = x >= minXRange && x <= maxXRange && y >= minYRange && y <= maxYRange;
|
|
33
|
+
var pointCtx = {
|
|
55
34
|
type: 'scatter',
|
|
56
35
|
seriesId: series.id,
|
|
57
|
-
dataIndex:
|
|
58
|
-
}
|
|
36
|
+
dataIndex: i
|
|
37
|
+
};
|
|
38
|
+
if (isInRange) {
|
|
39
|
+
temp.push({
|
|
40
|
+
x: x,
|
|
41
|
+
y: y,
|
|
42
|
+
isFaded: !getIsHighlighted(item, pointCtx, series.highlightScope) && getIsFaded(item, pointCtx, series.highlightScope),
|
|
43
|
+
interactionProps: getInteractionItemProps(pointCtx),
|
|
44
|
+
id: scatterPoint.id
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return temp;
|
|
49
|
+
}, [yScale, xScale, getInteractionItemProps, item, series.data, series.highlightScope, series.id]);
|
|
50
|
+
return /*#__PURE__*/_jsx("g", {
|
|
51
|
+
children: cleanData.map(function (dataPoint) {
|
|
59
52
|
return /*#__PURE__*/_jsx("circle", _extends({
|
|
60
53
|
cx: 0,
|
|
61
54
|
cy: 0,
|
|
62
55
|
r: markerSize,
|
|
63
|
-
transform: "translate(".concat(x, ", ").concat(y, ")"),
|
|
56
|
+
transform: "translate(".concat(dataPoint.x, ", ").concat(dataPoint.y, ")"),
|
|
64
57
|
fill: color,
|
|
65
|
-
opacity: isFaded && 0.3 || 1
|
|
66
|
-
},
|
|
67
|
-
type: 'scatter',
|
|
68
|
-
seriesId: series.id,
|
|
69
|
-
dataIndex: dataIndex
|
|
70
|
-
})), id);
|
|
58
|
+
opacity: dataPoint.isFaded && 0.3 || 1
|
|
59
|
+
}, dataPoint.interactionProps), dataPoint.id);
|
|
71
60
|
})
|
|
72
61
|
});
|
|
73
62
|
}
|
|
@@ -64,7 +64,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
64
64
|
}),
|
|
65
65
|
/**
|
|
66
66
|
* Indicate which axis to display the bottom of the charts.
|
|
67
|
-
* Can be a string (the id of the axis) or an object `ChartsXAxisProps
|
|
67
|
+
* Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
|
|
68
68
|
* @default xAxisIds[0] The id of the first provided axis
|
|
69
69
|
*/
|
|
70
70
|
bottomAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
@@ -86,12 +86,13 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
86
86
|
* Color palette used to colorize multiple series.
|
|
87
87
|
*/
|
|
88
88
|
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
89
|
+
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
89
90
|
desc: PropTypes.string,
|
|
90
91
|
disableAxisListener: PropTypes.bool,
|
|
91
92
|
height: PropTypes.number,
|
|
92
93
|
/**
|
|
93
94
|
* Indicate which axis to display the left of the charts.
|
|
94
|
-
* Can be a string (the id of the axis) or an object `ChartsYAxisProps
|
|
95
|
+
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
95
96
|
* @default yAxisIds[0] The id of the first provided axis
|
|
96
97
|
*/
|
|
97
98
|
leftAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
@@ -131,7 +132,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
131
132
|
}),
|
|
132
133
|
/**
|
|
133
134
|
* Indicate which axis to display the right of the charts.
|
|
134
|
-
* Can be a string (the id of the axis) or an object `ChartsYAxisProps
|
|
135
|
+
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
135
136
|
* @default null
|
|
136
137
|
*/
|
|
137
138
|
rightAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
@@ -176,7 +177,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
176
177
|
}),
|
|
177
178
|
/**
|
|
178
179
|
* Indicate which axis to display the top of the charts.
|
|
179
|
-
* Can be a string (the id of the axis) or an object `ChartsXAxisProps
|
|
180
|
+
* Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
|
|
180
181
|
* @default null
|
|
181
182
|
*/
|
|
182
183
|
topAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
@@ -203,15 +204,17 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
203
204
|
axisId: PropTypes.string,
|
|
204
205
|
classes: PropTypes.object,
|
|
205
206
|
data: PropTypes.array,
|
|
207
|
+
dataKey: PropTypes.string,
|
|
206
208
|
disableLine: PropTypes.bool,
|
|
207
209
|
disableTicks: PropTypes.bool,
|
|
208
210
|
fill: PropTypes.string,
|
|
211
|
+
hideTooltip: PropTypes.bool,
|
|
209
212
|
id: PropTypes.string,
|
|
210
213
|
label: PropTypes.string,
|
|
211
214
|
labelFontSize: PropTypes.number,
|
|
212
|
-
max: PropTypes.number,
|
|
215
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
213
216
|
maxTicks: PropTypes.number,
|
|
214
|
-
min: PropTypes.number,
|
|
217
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
215
218
|
minTicks: PropTypes.number,
|
|
216
219
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
217
220
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -225,15 +228,17 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
225
228
|
axisId: PropTypes.string,
|
|
226
229
|
classes: PropTypes.object,
|
|
227
230
|
data: PropTypes.array,
|
|
231
|
+
dataKey: PropTypes.string,
|
|
228
232
|
disableLine: PropTypes.bool,
|
|
229
233
|
disableTicks: PropTypes.bool,
|
|
230
234
|
fill: PropTypes.string,
|
|
235
|
+
hideTooltip: PropTypes.bool,
|
|
231
236
|
id: PropTypes.string,
|
|
232
237
|
label: PropTypes.string,
|
|
233
238
|
labelFontSize: PropTypes.number,
|
|
234
|
-
max: PropTypes.number,
|
|
239
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
235
240
|
maxTicks: PropTypes.number,
|
|
236
|
-
min: PropTypes.number,
|
|
241
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
237
242
|
minTicks: PropTypes.number,
|
|
238
243
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
239
244
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import { styled } from '@mui/material/styles';
|
|
6
|
+
import { BarPlot } from '../BarChart';
|
|
7
|
+
import { LinePlot, MarkPlot, AreaPlot, markElementClasses } from '../LineChart';
|
|
8
|
+
import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
|
|
9
|
+
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
10
|
+
import { ChartsTooltip } from '../ChartsTooltip';
|
|
11
|
+
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
var SparkLineMarkPlot = styled(MarkPlot)(_defineProperty({}, "& .".concat(markElementClasses.root), _defineProperty({
|
|
15
|
+
display: 'none'
|
|
16
|
+
}, "&.".concat(markElementClasses.highlighted), {
|
|
17
|
+
display: 'inherit'
|
|
18
|
+
})));
|
|
19
|
+
var SPARKLINE_DEFAULT_MARGIN = {
|
|
20
|
+
top: 5,
|
|
21
|
+
bottom: 5,
|
|
22
|
+
left: 5,
|
|
23
|
+
right: 5
|
|
24
|
+
};
|
|
25
|
+
var SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props, ref) {
|
|
26
|
+
var xAxis = props.xAxis,
|
|
27
|
+
width = props.width,
|
|
28
|
+
height = props.height,
|
|
29
|
+
_props$margin = props.margin,
|
|
30
|
+
margin = _props$margin === void 0 ? SPARKLINE_DEFAULT_MARGIN : _props$margin,
|
|
31
|
+
colors = props.colors,
|
|
32
|
+
sx = props.sx,
|
|
33
|
+
showTooltip = props.showTooltip,
|
|
34
|
+
tooltip = props.tooltip,
|
|
35
|
+
showHighlight = props.showHighlight,
|
|
36
|
+
inAxisHighlight = props.axisHighlight,
|
|
37
|
+
children = props.children,
|
|
38
|
+
data = props.data,
|
|
39
|
+
_props$plotType = props.plotType,
|
|
40
|
+
plotType = _props$plotType === void 0 ? 'line' : _props$plotType,
|
|
41
|
+
_props$valueFormatter = props.valueFormatter,
|
|
42
|
+
valueFormatter = _props$valueFormatter === void 0 ? function (v) {
|
|
43
|
+
return v.toString();
|
|
44
|
+
} : _props$valueFormatter,
|
|
45
|
+
area = props.area,
|
|
46
|
+
_props$curve = props.curve,
|
|
47
|
+
curve = _props$curve === void 0 ? 'linear' : _props$curve;
|
|
48
|
+
var defaultXHighlight = showHighlight && plotType === 'bar' ? {
|
|
49
|
+
x: 'band'
|
|
50
|
+
} : {
|
|
51
|
+
x: 'none'
|
|
52
|
+
};
|
|
53
|
+
var axisHighlight = _extends({}, defaultXHighlight, inAxisHighlight);
|
|
54
|
+
return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
|
|
55
|
+
ref: ref,
|
|
56
|
+
series: [_extends({
|
|
57
|
+
type: plotType,
|
|
58
|
+
data: data,
|
|
59
|
+
valueFormatter: valueFormatter
|
|
60
|
+
}, plotType === 'bar' ? {} : {
|
|
61
|
+
area: area,
|
|
62
|
+
curve: curve
|
|
63
|
+
})],
|
|
64
|
+
width: width,
|
|
65
|
+
height: height,
|
|
66
|
+
margin: margin,
|
|
67
|
+
xAxis: [_extends({
|
|
68
|
+
id: DEFAULT_X_AXIS_KEY,
|
|
69
|
+
scaleType: plotType === 'bar' ? 'band' : 'linear',
|
|
70
|
+
data: Array.from({
|
|
71
|
+
length: data.length
|
|
72
|
+
}, function (_, index) {
|
|
73
|
+
return index;
|
|
74
|
+
}),
|
|
75
|
+
hideTooltip: xAxis === undefined
|
|
76
|
+
}, xAxis)],
|
|
77
|
+
colors: colors,
|
|
78
|
+
sx: sx,
|
|
79
|
+
disableAxisListener: (!showTooltip || (tooltip == null ? void 0 : tooltip.trigger) !== 'axis') && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
|
|
80
|
+
children: [plotType === 'bar' && /*#__PURE__*/_jsx(BarPlot, {}), plotType === 'line' && /*#__PURE__*/_jsxs(React.Fragment, {
|
|
81
|
+
children: [/*#__PURE__*/_jsx(AreaPlot, {}), /*#__PURE__*/_jsx(LinePlot, {}), showHighlight && /*#__PURE__*/_jsx(SparkLineMarkPlot, {})]
|
|
82
|
+
}), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), showTooltip && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), children]
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
86
|
+
// ----------------------------- Warning --------------------------------
|
|
87
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
88
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
89
|
+
// ----------------------------------------------------------------------
|
|
90
|
+
/**
|
|
91
|
+
* Set to `true` to fill spark line area.
|
|
92
|
+
* Has no effect if plotType='bar'.
|
|
93
|
+
* @default false
|
|
94
|
+
*/
|
|
95
|
+
area: PropTypes.bool,
|
|
96
|
+
axisHighlight: PropTypes.shape({
|
|
97
|
+
x: PropTypes.oneOf(['band', 'line', 'none']),
|
|
98
|
+
y: PropTypes.oneOf(['line', 'none'])
|
|
99
|
+
}),
|
|
100
|
+
children: PropTypes.node,
|
|
101
|
+
className: PropTypes.string,
|
|
102
|
+
/**
|
|
103
|
+
* Color palette used to colorize multiple series.
|
|
104
|
+
*/
|
|
105
|
+
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
106
|
+
/**
|
|
107
|
+
* @default 'linear'
|
|
108
|
+
*/
|
|
109
|
+
curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
|
|
110
|
+
/**
|
|
111
|
+
* Data to plot.
|
|
112
|
+
*/
|
|
113
|
+
data: PropTypes.arrayOf(PropTypes.number).isRequired,
|
|
114
|
+
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
115
|
+
desc: PropTypes.string,
|
|
116
|
+
disableAxisListener: PropTypes.bool,
|
|
117
|
+
height: PropTypes.number,
|
|
118
|
+
margin: PropTypes.shape({
|
|
119
|
+
bottom: PropTypes.number,
|
|
120
|
+
left: PropTypes.number,
|
|
121
|
+
right: PropTypes.number,
|
|
122
|
+
top: PropTypes.number
|
|
123
|
+
}),
|
|
124
|
+
/**
|
|
125
|
+
* Type of plot used.
|
|
126
|
+
* @default 'line'
|
|
127
|
+
*/
|
|
128
|
+
plotType: PropTypes.oneOf(['bar', 'line']),
|
|
129
|
+
/**
|
|
130
|
+
* Set to `true` to highlight the value.
|
|
131
|
+
* With line, it shows a point.
|
|
132
|
+
* With bar, it shows a highlight band.
|
|
133
|
+
* @default false
|
|
134
|
+
*/
|
|
135
|
+
showHighlight: PropTypes.bool,
|
|
136
|
+
/**
|
|
137
|
+
* Set to `true` to enable the tooltip in the sparkline.
|
|
138
|
+
* @default false
|
|
139
|
+
*/
|
|
140
|
+
showTooltip: PropTypes.bool,
|
|
141
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
142
|
+
title: PropTypes.string,
|
|
143
|
+
tooltip: PropTypes.shape({
|
|
144
|
+
axisContent: PropTypes.elementType,
|
|
145
|
+
classes: PropTypes.object,
|
|
146
|
+
itemContent: PropTypes.elementType,
|
|
147
|
+
trigger: PropTypes.oneOf(['axis', 'item', 'none'])
|
|
148
|
+
}),
|
|
149
|
+
/**
|
|
150
|
+
* Formatter used by the tooltip.
|
|
151
|
+
* @param {number} value The value to format.
|
|
152
|
+
* @returns {string} the formatted value.
|
|
153
|
+
*/
|
|
154
|
+
valueFormatter: PropTypes.func,
|
|
155
|
+
viewBox: PropTypes.shape({
|
|
156
|
+
height: PropTypes.number,
|
|
157
|
+
width: PropTypes.number,
|
|
158
|
+
x: PropTypes.number,
|
|
159
|
+
y: PropTypes.number
|
|
160
|
+
}),
|
|
161
|
+
width: PropTypes.number,
|
|
162
|
+
/**
|
|
163
|
+
* The xAxis configuration.
|
|
164
|
+
* Notice it is a single configuration object, not an array of configuration.
|
|
165
|
+
*/
|
|
166
|
+
xAxis: PropTypes.shape({
|
|
167
|
+
axisId: PropTypes.string,
|
|
168
|
+
classes: PropTypes.object,
|
|
169
|
+
data: PropTypes.array,
|
|
170
|
+
dataKey: PropTypes.string,
|
|
171
|
+
disableLine: PropTypes.bool,
|
|
172
|
+
disableTicks: PropTypes.bool,
|
|
173
|
+
fill: PropTypes.string,
|
|
174
|
+
hideTooltip: PropTypes.bool,
|
|
175
|
+
id: PropTypes.string,
|
|
176
|
+
label: PropTypes.string,
|
|
177
|
+
labelFontSize: PropTypes.number,
|
|
178
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
179
|
+
maxTicks: PropTypes.number,
|
|
180
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
181
|
+
minTicks: PropTypes.number,
|
|
182
|
+
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
183
|
+
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
184
|
+
stroke: PropTypes.string,
|
|
185
|
+
tickFontSize: PropTypes.number,
|
|
186
|
+
tickSize: PropTypes.number,
|
|
187
|
+
tickSpacing: PropTypes.number,
|
|
188
|
+
valueFormatter: PropTypes.func
|
|
189
|
+
})
|
|
190
|
+
} : void 0;
|
|
191
|
+
export { SparkLineChart };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SparkLineChart } from './SparkLineChart';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { scaleBand, scalePoint } from 'd3-scale';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
@@ -34,11 +34,44 @@ export var CartesianContext = /*#__PURE__*/React.createContext({
|
|
|
34
34
|
yAxisIds: []
|
|
35
35
|
});
|
|
36
36
|
function CartesianContextProvider(_ref) {
|
|
37
|
-
var
|
|
38
|
-
|
|
37
|
+
var inXAxis = _ref.xAxis,
|
|
38
|
+
inYAxis = _ref.yAxis,
|
|
39
|
+
dataset = _ref.dataset,
|
|
39
40
|
children = _ref.children;
|
|
40
41
|
var formattedSeries = React.useContext(SeriesContext);
|
|
41
42
|
var drawingArea = React.useContext(DrawingContext);
|
|
43
|
+
var xAxis = React.useMemo(function () {
|
|
44
|
+
return inXAxis == null ? void 0 : inXAxis.map(function (axisConfig) {
|
|
45
|
+
var dataKey = axisConfig.dataKey;
|
|
46
|
+
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
47
|
+
return axisConfig;
|
|
48
|
+
}
|
|
49
|
+
if (dataset === undefined) {
|
|
50
|
+
throw Error('MUI: x-axis uses `dataKey` but no `dataset` is provided.');
|
|
51
|
+
}
|
|
52
|
+
return _extends({}, axisConfig, {
|
|
53
|
+
data: dataset.map(function (d) {
|
|
54
|
+
return d[dataKey];
|
|
55
|
+
})
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}, [inXAxis, dataset]);
|
|
59
|
+
var yAxis = React.useMemo(function () {
|
|
60
|
+
return inYAxis == null ? void 0 : inYAxis.map(function (axisConfig) {
|
|
61
|
+
var dataKey = axisConfig.dataKey;
|
|
62
|
+
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
63
|
+
return axisConfig;
|
|
64
|
+
}
|
|
65
|
+
if (dataset === undefined) {
|
|
66
|
+
throw Error('MUI: y-axis uses `dataKey` but no `dataset` is provided.');
|
|
67
|
+
}
|
|
68
|
+
return _extends({}, axisConfig, {
|
|
69
|
+
data: dataset.map(function (d) {
|
|
70
|
+
return d[dataKey];
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}, [inYAxis, dataset]);
|
|
42
75
|
var value = React.useMemo(function () {
|
|
43
76
|
var _xAxis$map, _yAxis$map;
|
|
44
77
|
var axisExtremumCallback = function axisExtremumCallback(acc, chartType, axis, getters, isDefaultAxis) {
|
|
@@ -206,19 +239,22 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
206
239
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
207
240
|
// ----------------------------------------------------------------------
|
|
208
241
|
children: PropTypes.node,
|
|
242
|
+
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
209
243
|
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
210
244
|
axisId: PropTypes.string,
|
|
211
245
|
classes: PropTypes.object,
|
|
212
246
|
data: PropTypes.array,
|
|
247
|
+
dataKey: PropTypes.string,
|
|
213
248
|
disableLine: PropTypes.bool,
|
|
214
249
|
disableTicks: PropTypes.bool,
|
|
215
250
|
fill: PropTypes.string,
|
|
251
|
+
hideTooltip: PropTypes.bool,
|
|
216
252
|
id: PropTypes.string,
|
|
217
253
|
label: PropTypes.string,
|
|
218
254
|
labelFontSize: PropTypes.number,
|
|
219
|
-
max: PropTypes.number,
|
|
255
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
220
256
|
maxTicks: PropTypes.number,
|
|
221
|
-
min: PropTypes.number,
|
|
257
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
222
258
|
minTicks: PropTypes.number,
|
|
223
259
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
224
260
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -232,15 +268,17 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
232
268
|
axisId: PropTypes.string,
|
|
233
269
|
classes: PropTypes.object,
|
|
234
270
|
data: PropTypes.array,
|
|
271
|
+
dataKey: PropTypes.string,
|
|
235
272
|
disableLine: PropTypes.bool,
|
|
236
273
|
disableTicks: PropTypes.bool,
|
|
237
274
|
fill: PropTypes.string,
|
|
275
|
+
hideTooltip: PropTypes.bool,
|
|
238
276
|
id: PropTypes.string,
|
|
239
277
|
label: PropTypes.string,
|
|
240
278
|
labelFontSize: PropTypes.number,
|
|
241
|
-
max: PropTypes.number,
|
|
279
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
242
280
|
maxTicks: PropTypes.number,
|
|
243
|
-
min: PropTypes.number,
|
|
281
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
244
282
|
minTicks: PropTypes.number,
|
|
245
283
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
246
284
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import useChartDimensions from '../hooks/useChartDimensions';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Defines the area in which it is possible to draw the charts
|
|
6
|
+
* Defines the area in which it is possible to draw the charts.
|
|
7
7
|
*/
|
|
8
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
9
|
export var DrawingContext = /*#__PURE__*/React.createContext({
|
|
@@ -15,6 +15,7 @@ var seriesTypeFormatter = {
|
|
|
15
15
|
line: lineSeriesFormatter,
|
|
16
16
|
pie: pieSeriesFormatter
|
|
17
17
|
};
|
|
18
|
+
|
|
18
19
|
/**
|
|
19
20
|
* This methods is the interface between what the developer is providing and what components receives
|
|
20
21
|
* To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if some line data are modified
|
|
@@ -23,7 +24,7 @@ var seriesTypeFormatter = {
|
|
|
23
24
|
* @param colors The color palette used to defaultize series colors
|
|
24
25
|
* @returns An object structuring all the series by type.
|
|
25
26
|
*/
|
|
26
|
-
var formatSeries = function formatSeries(series, colors) {
|
|
27
|
+
var formatSeries = function formatSeries(series, colors, dataset) {
|
|
27
28
|
// Group series by type
|
|
28
29
|
var seriesGroups = {};
|
|
29
30
|
series.forEach(function (seriesData, seriesIndex) {
|
|
@@ -50,20 +51,21 @@ var formatSeries = function formatSeries(series, colors) {
|
|
|
50
51
|
Object.keys(seriesTypeFormatter).forEach(function (type) {
|
|
51
52
|
if (seriesGroups[type] !== undefined) {
|
|
52
53
|
var _seriesTypeFormatter$, _seriesTypeFormatter$2;
|
|
53
|
-
formattedSeries[type] = (_seriesTypeFormatter$ = (_seriesTypeFormatter$2 = seriesTypeFormatter[type]) == null ? void 0 : _seriesTypeFormatter$2.call(seriesTypeFormatter, seriesGroups[type])) != null ? _seriesTypeFormatter$ : seriesGroups[type];
|
|
54
|
+
formattedSeries[type] = (_seriesTypeFormatter$ = (_seriesTypeFormatter$2 = seriesTypeFormatter[type]) == null ? void 0 : _seriesTypeFormatter$2.call(seriesTypeFormatter, seriesGroups[type], dataset)) != null ? _seriesTypeFormatter$ : seriesGroups[type];
|
|
54
55
|
}
|
|
55
56
|
});
|
|
56
57
|
return formattedSeries;
|
|
57
58
|
};
|
|
58
59
|
export function SeriesContextProvider(_ref) {
|
|
59
60
|
var series = _ref.series,
|
|
61
|
+
dataset = _ref.dataset,
|
|
60
62
|
_ref$colors = _ref.colors,
|
|
61
63
|
colors = _ref$colors === void 0 ? blueberryTwilightPalette : _ref$colors,
|
|
62
64
|
children = _ref.children;
|
|
63
65
|
var theme = useTheme();
|
|
64
66
|
var formattedSeries = React.useMemo(function () {
|
|
65
|
-
return formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors);
|
|
66
|
-
}, [series, colors, theme.palette.mode]);
|
|
67
|
+
return formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors, dataset);
|
|
68
|
+
}, [series, colors, theme.palette.mode, dataset]);
|
|
67
69
|
return /*#__PURE__*/_jsx(SeriesContext.Provider, {
|
|
68
70
|
value: formattedSeries,
|
|
69
71
|
children: children
|
package/legacy/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/x-charts v6.0.0-alpha.
|
|
2
|
+
* @mui/x-charts v6.0.0-alpha.6
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -20,5 +20,6 @@ export * from './BarChart';
|
|
|
20
20
|
export * from './LineChart';
|
|
21
21
|
export * from './PieChart';
|
|
22
22
|
export * from './ScatterChart';
|
|
23
|
+
export * from './SparkLineChart';
|
|
23
24
|
export * from './ChartContainer';
|
|
24
25
|
export * from './ResponsiveChartContainer';
|
package/legacy/models/index.js
CHANGED
package/models/axis.d.ts
CHANGED
|
@@ -114,10 +114,18 @@ interface AxisScaleConfig {
|
|
|
114
114
|
}
|
|
115
115
|
export type AxisConfig<S extends ScaleName = ScaleName, V = any> = {
|
|
116
116
|
id: string;
|
|
117
|
-
min?: number;
|
|
118
|
-
max?: number;
|
|
117
|
+
min?: number | Date;
|
|
118
|
+
max?: number | Date;
|
|
119
119
|
data?: V[];
|
|
120
|
+
/**
|
|
121
|
+
* The key used to retrieve data from the dataset prop.
|
|
122
|
+
*/
|
|
123
|
+
dataKey?: string;
|
|
120
124
|
valueFormatter?: (value: V) => string;
|
|
125
|
+
/**
|
|
126
|
+
* If `true`, hide this value in the tooltip
|
|
127
|
+
*/
|
|
128
|
+
hideTooltip?: boolean;
|
|
121
129
|
} & Partial<ChartsXAxisProps | ChartsYAxisProps> & Partial<Omit<AxisScaleConfig[S], 'scale'>> & TickParams;
|
|
122
130
|
export type AxisDefaultized<S extends ScaleName = ScaleName, V = any> = Omit<AxisConfig<S, V>, 'scaleType'> & AxisScaleConfig[S] & {
|
|
123
131
|
ticksNumber: number;
|
package/models/index.d.ts
CHANGED
package/models/index.js
CHANGED
|
@@ -13,4 +13,15 @@ Object.keys(_seriesType).forEach(function (key) {
|
|
|
13
13
|
return _seriesType[key];
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
+
});
|
|
17
|
+
var _layout = require("./layout");
|
|
18
|
+
Object.keys(_layout).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _layout[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _layout[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
16
27
|
});
|
|
@@ -2,7 +2,14 @@ import { DefaultizedProps } from '../helpers';
|
|
|
2
2
|
import { CartesianSeriesType, CommonSeriesType, CommonDefaultizedProps, StackableSeriesType } from './common';
|
|
3
3
|
export interface BarSeriesType extends CommonSeriesType<number>, CartesianSeriesType, StackableSeriesType {
|
|
4
4
|
type: 'bar';
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Data associated to each bar.
|
|
7
|
+
*/
|
|
8
|
+
data?: number[];
|
|
9
|
+
/**
|
|
10
|
+
* The key used to retrive data from the dataset.
|
|
11
|
+
*/
|
|
12
|
+
dataKey?: string;
|
|
6
13
|
label?: string;
|
|
7
14
|
}
|
|
8
15
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HighlightScope } from '
|
|
1
|
+
import type { HighlightScope } from '../../context/HighlightProvider';
|
|
2
2
|
import type { StackOffset, StackOrder } from '../../internals/stackSeries';
|
|
3
3
|
export type CommonSeriesType<TValue> = {
|
|
4
4
|
id?: string;
|
|
@@ -11,7 +11,7 @@ export type CommonSeriesType<TValue> = {
|
|
|
11
11
|
valueFormatter?: (value: TValue) => string;
|
|
12
12
|
highlightScope?: Partial<HighlightScope>;
|
|
13
13
|
};
|
|
14
|
-
export type CommonDefaultizedProps = 'id' | 'valueFormatter';
|
|
14
|
+
export type CommonDefaultizedProps = 'id' | 'valueFormatter' | 'data';
|
|
15
15
|
export type CartesianSeriesType = {
|
|
16
16
|
xAxisKey?: string;
|
|
17
17
|
yAxisKey?: string;
|
|
@@ -73,7 +73,10 @@ export type FormatterResult<T extends ChartSeriesType> = {
|
|
|
73
73
|
} ? {
|
|
74
74
|
stackingGroups: StackingGroupsType;
|
|
75
75
|
} : {});
|
|
76
|
-
export type
|
|
76
|
+
export type DatasetType<T extends number | string | Date = number | string | Date> = {
|
|
77
|
+
[key: string]: T;
|
|
78
|
+
}[];
|
|
79
|
+
export type Formatter<T extends ChartSeriesType> = (params: FormatterParams<T>, dataset?: DatasetType<number>) => FormatterResult<T>;
|
|
77
80
|
export type LegendParams = {
|
|
78
81
|
/**
|
|
79
82
|
* The color used in the legend
|
|
@@ -3,7 +3,14 @@ import { CartesianSeriesType, CommonDefaultizedProps, CommonSeriesType, Stackabl
|
|
|
3
3
|
export type CurveType = 'catmullRom' | 'linear' | 'monotoneX' | 'monotoneY' | 'natural' | 'step' | 'stepBefore' | 'stepAfter';
|
|
4
4
|
export interface LineSeriesType extends CommonSeriesType<number>, CartesianSeriesType, StackableSeriesType {
|
|
5
5
|
type: 'line';
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Data associated to the line.
|
|
8
|
+
*/
|
|
9
|
+
data?: number[];
|
|
10
|
+
/**
|
|
11
|
+
* The key used to retrive data from the dataset.
|
|
12
|
+
*/
|
|
13
|
+
dataKey?: string;
|
|
7
14
|
stack?: string;
|
|
8
15
|
area?: boolean;
|
|
9
16
|
label?: string;
|