@mui/x-charts 6.0.0-alpha.5 → 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 +14 -6
- package/BarChart/formatter.js +23 -12
- package/CHANGELOG.md +92 -0
- package/ChartContainer/index.js +3 -0
- package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/LineChart/AreaPlot.d.ts +1 -1
- package/LineChart/AreaPlot.js +4 -3
- package/LineChart/LineChart.js +14 -6
- 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 +9 -4
- package/ScatterChart/ScatterChart.js +9 -4
- 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/SeriesContextProvider.d.ts +3 -2
- package/context/SeriesContextProvider.js +5 -3
- package/esm/BarChart/BarChart.js +17 -6
- package/esm/BarChart/formatter.js +23 -12
- package/esm/ChartContainer/index.js +3 -0
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/esm/LineChart/AreaPlot.js +4 -3
- package/esm/LineChart/LineChart.js +17 -6
- 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 +9 -4
- package/esm/ScatterChart/ScatterChart.js +9 -4
- package/esm/SparkLineChart/SparkLineChart.js +187 -0
- package/esm/SparkLineChart/index.js +1 -0
- package/esm/context/CartesianContextProvider.js +36 -6
- 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 +15 -6
- package/legacy/BarChart/formatter.js +23 -10
- package/legacy/ChartContainer/index.js +3 -0
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/legacy/LineChart/AreaPlot.js +4 -3
- package/legacy/LineChart/LineChart.js +15 -6
- 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 +9 -4
- package/legacy/ScatterChart/ScatterChart.js +9 -4
- package/legacy/SparkLineChart/SparkLineChart.js +191 -0
- package/legacy/SparkLineChart/index.js +1 -0
- package/legacy/context/CartesianContextProvider.js +45 -7
- 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 +14 -6
- package/modern/BarChart/formatter.js +23 -12
- package/modern/ChartContainer/index.js +3 -0
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/modern/LineChart/AreaPlot.js +4 -3
- package/modern/LineChart/LineChart.js +14 -6
- 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 +9 -4
- package/modern/ScatterChart/ScatterChart.js +9 -4
- package/modern/SparkLineChart/SparkLineChart.js +187 -0
- package/modern/SparkLineChart/index.js +1 -0
- package/modern/context/CartesianContextProvider.js +36 -6
- 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
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ResponsiveChartContainerProps } from '../ResponsiveChartContainer';
|
|
3
|
+
import { ChartsTooltipProps } from '../ChartsTooltip';
|
|
4
|
+
import { ChartsAxisHighlightProps } from '../ChartsAxisHighlight';
|
|
5
|
+
import { AxisConfig } from '../models/axis';
|
|
6
|
+
import { MakeOptional } from '../models/helpers';
|
|
7
|
+
import { LineSeriesType } from '../models/seriesType/line';
|
|
8
|
+
export interface SparkLineChartProps extends Omit<ResponsiveChartContainerProps, 'series' | 'xAxis' | 'yAxis'> {
|
|
9
|
+
/**
|
|
10
|
+
* The xAxis configuration.
|
|
11
|
+
* Notice it is a single configuration object, not an array of configuration.
|
|
12
|
+
*/
|
|
13
|
+
xAxis?: MakeOptional<AxisConfig, 'id'>;
|
|
14
|
+
tooltip?: ChartsTooltipProps;
|
|
15
|
+
axisHighlight?: ChartsAxisHighlightProps;
|
|
16
|
+
/**
|
|
17
|
+
* Type of plot used.
|
|
18
|
+
* @default 'line'
|
|
19
|
+
*/
|
|
20
|
+
plotType?: 'line' | 'bar';
|
|
21
|
+
/**
|
|
22
|
+
* Data to plot.
|
|
23
|
+
*/
|
|
24
|
+
data: number[];
|
|
25
|
+
/**
|
|
26
|
+
* Formatter used by the tooltip.
|
|
27
|
+
* @param {number} value The value to format.
|
|
28
|
+
* @returns {string} the formatted value.
|
|
29
|
+
*/
|
|
30
|
+
valueFormatter?: (value: number) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Set to `true` to enable the tooltip in the sparkline.
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
showTooltip?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Set to `true` to highlight the value.
|
|
38
|
+
* With line, it shows a point.
|
|
39
|
+
* With bar, it shows a highlight band.
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
showHighlight?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Set to `true` to fill spark line area.
|
|
45
|
+
* Has no effect if plotType='bar'.
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
area?: LineSeriesType['area'];
|
|
49
|
+
/**
|
|
50
|
+
* @default 'linear'
|
|
51
|
+
*/
|
|
52
|
+
curve?: LineSeriesType['curve'];
|
|
53
|
+
}
|
|
54
|
+
declare const SparkLineChart: React.ForwardRefExoticComponent<SparkLineChartProps & React.RefAttributes<unknown>>;
|
|
55
|
+
export { SparkLineChart };
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.SparkLineChart = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var _styles = require("@mui/material/styles");
|
|
12
|
+
var _BarChart = require("../BarChart");
|
|
13
|
+
var _LineChart = require("../LineChart");
|
|
14
|
+
var _ResponsiveChartContainer = require("../ResponsiveChartContainer");
|
|
15
|
+
var _constants = require("../constants");
|
|
16
|
+
var _ChartsTooltip = require("../ChartsTooltip");
|
|
17
|
+
var _ChartsAxisHighlight = require("../ChartsAxisHighlight");
|
|
18
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
20
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
+
const SparkLineMarkPlot = (0, _styles.styled)(_LineChart.MarkPlot)({
|
|
22
|
+
[`& .${_LineChart.markElementClasses.root}`]: {
|
|
23
|
+
display: 'none',
|
|
24
|
+
[`&.${_LineChart.markElementClasses.highlighted}`]: {
|
|
25
|
+
display: 'inherit'
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const SPARKLINE_DEFAULT_MARGIN = {
|
|
30
|
+
top: 5,
|
|
31
|
+
bottom: 5,
|
|
32
|
+
left: 5,
|
|
33
|
+
right: 5
|
|
34
|
+
};
|
|
35
|
+
const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props, ref) {
|
|
36
|
+
const {
|
|
37
|
+
xAxis,
|
|
38
|
+
width,
|
|
39
|
+
height,
|
|
40
|
+
margin = SPARKLINE_DEFAULT_MARGIN,
|
|
41
|
+
colors,
|
|
42
|
+
sx,
|
|
43
|
+
showTooltip,
|
|
44
|
+
tooltip,
|
|
45
|
+
showHighlight,
|
|
46
|
+
axisHighlight: inAxisHighlight,
|
|
47
|
+
children,
|
|
48
|
+
data,
|
|
49
|
+
plotType = 'line',
|
|
50
|
+
valueFormatter = v => v.toString(),
|
|
51
|
+
area,
|
|
52
|
+
curve = 'linear'
|
|
53
|
+
} = props;
|
|
54
|
+
const defaultXHighlight = showHighlight && plotType === 'bar' ? {
|
|
55
|
+
x: 'band'
|
|
56
|
+
} : {
|
|
57
|
+
x: 'none'
|
|
58
|
+
};
|
|
59
|
+
const axisHighlight = (0, _extends2.default)({}, defaultXHighlight, inAxisHighlight);
|
|
60
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ResponsiveChartContainer.ResponsiveChartContainer, {
|
|
61
|
+
ref: ref,
|
|
62
|
+
series: [(0, _extends2.default)({
|
|
63
|
+
type: plotType,
|
|
64
|
+
data,
|
|
65
|
+
valueFormatter
|
|
66
|
+
}, plotType === 'bar' ? {} : {
|
|
67
|
+
area,
|
|
68
|
+
curve
|
|
69
|
+
})],
|
|
70
|
+
width: width,
|
|
71
|
+
height: height,
|
|
72
|
+
margin: margin,
|
|
73
|
+
xAxis: [(0, _extends2.default)({
|
|
74
|
+
id: _constants.DEFAULT_X_AXIS_KEY,
|
|
75
|
+
scaleType: plotType === 'bar' ? 'band' : 'linear',
|
|
76
|
+
data: Array.from({
|
|
77
|
+
length: data.length
|
|
78
|
+
}, (_, index) => index),
|
|
79
|
+
hideTooltip: xAxis === undefined
|
|
80
|
+
}, xAxis)],
|
|
81
|
+
colors: colors,
|
|
82
|
+
sx: sx,
|
|
83
|
+
disableAxisListener: (!showTooltip || tooltip?.trigger !== 'axis') && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
|
|
84
|
+
children: [plotType === 'bar' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarChart.BarPlot, {}), plotType === 'line' && /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
|
|
85
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_LineChart.AreaPlot, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_LineChart.LinePlot, {}), showHighlight && /*#__PURE__*/(0, _jsxRuntime.jsx)(SparkLineMarkPlot, {})]
|
|
86
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxisHighlight.ChartsAxisHighlight, (0, _extends2.default)({}, axisHighlight)), showTooltip && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsTooltip.ChartsTooltip, (0, _extends2.default)({}, tooltip)), children]
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
exports.SparkLineChart = SparkLineChart;
|
|
90
|
+
process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
91
|
+
// ----------------------------- Warning --------------------------------
|
|
92
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
93
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
94
|
+
// ----------------------------------------------------------------------
|
|
95
|
+
/**
|
|
96
|
+
* Set to `true` to fill spark line area.
|
|
97
|
+
* Has no effect if plotType='bar'.
|
|
98
|
+
* @default false
|
|
99
|
+
*/
|
|
100
|
+
area: _propTypes.default.bool,
|
|
101
|
+
axisHighlight: _propTypes.default.shape({
|
|
102
|
+
x: _propTypes.default.oneOf(['band', 'line', 'none']),
|
|
103
|
+
y: _propTypes.default.oneOf(['line', 'none'])
|
|
104
|
+
}),
|
|
105
|
+
children: _propTypes.default.node,
|
|
106
|
+
className: _propTypes.default.string,
|
|
107
|
+
/**
|
|
108
|
+
* Color palette used to colorize multiple series.
|
|
109
|
+
*/
|
|
110
|
+
colors: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.func]),
|
|
111
|
+
/**
|
|
112
|
+
* @default 'linear'
|
|
113
|
+
*/
|
|
114
|
+
curve: _propTypes.default.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
|
|
115
|
+
/**
|
|
116
|
+
* Data to plot.
|
|
117
|
+
*/
|
|
118
|
+
data: _propTypes.default.arrayOf(_propTypes.default.number).isRequired,
|
|
119
|
+
dataset: _propTypes.default.arrayOf(_propTypes.default.object),
|
|
120
|
+
desc: _propTypes.default.string,
|
|
121
|
+
disableAxisListener: _propTypes.default.bool,
|
|
122
|
+
height: _propTypes.default.number,
|
|
123
|
+
margin: _propTypes.default.shape({
|
|
124
|
+
bottom: _propTypes.default.number,
|
|
125
|
+
left: _propTypes.default.number,
|
|
126
|
+
right: _propTypes.default.number,
|
|
127
|
+
top: _propTypes.default.number
|
|
128
|
+
}),
|
|
129
|
+
/**
|
|
130
|
+
* Type of plot used.
|
|
131
|
+
* @default 'line'
|
|
132
|
+
*/
|
|
133
|
+
plotType: _propTypes.default.oneOf(['bar', 'line']),
|
|
134
|
+
/**
|
|
135
|
+
* Set to `true` to highlight the value.
|
|
136
|
+
* With line, it shows a point.
|
|
137
|
+
* With bar, it shows a highlight band.
|
|
138
|
+
* @default false
|
|
139
|
+
*/
|
|
140
|
+
showHighlight: _propTypes.default.bool,
|
|
141
|
+
/**
|
|
142
|
+
* Set to `true` to enable the tooltip in the sparkline.
|
|
143
|
+
* @default false
|
|
144
|
+
*/
|
|
145
|
+
showTooltip: _propTypes.default.bool,
|
|
146
|
+
sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
|
|
147
|
+
title: _propTypes.default.string,
|
|
148
|
+
tooltip: _propTypes.default.shape({
|
|
149
|
+
axisContent: _propTypes.default.elementType,
|
|
150
|
+
classes: _propTypes.default.object,
|
|
151
|
+
itemContent: _propTypes.default.elementType,
|
|
152
|
+
trigger: _propTypes.default.oneOf(['axis', 'item', 'none'])
|
|
153
|
+
}),
|
|
154
|
+
/**
|
|
155
|
+
* Formatter used by the tooltip.
|
|
156
|
+
* @param {number} value The value to format.
|
|
157
|
+
* @returns {string} the formatted value.
|
|
158
|
+
*/
|
|
159
|
+
valueFormatter: _propTypes.default.func,
|
|
160
|
+
viewBox: _propTypes.default.shape({
|
|
161
|
+
height: _propTypes.default.number,
|
|
162
|
+
width: _propTypes.default.number,
|
|
163
|
+
x: _propTypes.default.number,
|
|
164
|
+
y: _propTypes.default.number
|
|
165
|
+
}),
|
|
166
|
+
width: _propTypes.default.number,
|
|
167
|
+
/**
|
|
168
|
+
* The xAxis configuration.
|
|
169
|
+
* Notice it is a single configuration object, not an array of configuration.
|
|
170
|
+
*/
|
|
171
|
+
xAxis: _propTypes.default.shape({
|
|
172
|
+
axisId: _propTypes.default.string,
|
|
173
|
+
classes: _propTypes.default.object,
|
|
174
|
+
data: _propTypes.default.array,
|
|
175
|
+
dataKey: _propTypes.default.string,
|
|
176
|
+
disableLine: _propTypes.default.bool,
|
|
177
|
+
disableTicks: _propTypes.default.bool,
|
|
178
|
+
fill: _propTypes.default.string,
|
|
179
|
+
hideTooltip: _propTypes.default.bool,
|
|
180
|
+
id: _propTypes.default.string,
|
|
181
|
+
label: _propTypes.default.string,
|
|
182
|
+
labelFontSize: _propTypes.default.number,
|
|
183
|
+
max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
184
|
+
maxTicks: _propTypes.default.number,
|
|
185
|
+
min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
186
|
+
minTicks: _propTypes.default.number,
|
|
187
|
+
position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
|
|
188
|
+
scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
189
|
+
stroke: _propTypes.default.string,
|
|
190
|
+
tickFontSize: _propTypes.default.number,
|
|
191
|
+
tickSize: _propTypes.default.number,
|
|
192
|
+
tickSpacing: _propTypes.default.number,
|
|
193
|
+
valueFormatter: _propTypes.default.func
|
|
194
|
+
})
|
|
195
|
+
} : void 0;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SparkLineChart } from './SparkLineChart';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "SparkLineChart", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _SparkLineChart.SparkLineChart;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _SparkLineChart = require("./SparkLineChart");
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { AxisConfig, AxisDefaultized } from '../models/axis';
|
|
3
3
|
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
4
|
+
import { DatasetType } from '../models/seriesType/config';
|
|
4
5
|
import { MakeOptional } from '../models/helpers';
|
|
5
6
|
export type CartesianContextProviderProps = {
|
|
6
7
|
xAxis?: MakeOptional<AxisConfig, 'id'>[];
|
|
7
8
|
yAxis?: MakeOptional<AxisConfig, 'id'>[];
|
|
9
|
+
dataset?: DatasetType;
|
|
8
10
|
children: React.ReactNode;
|
|
9
11
|
};
|
|
10
12
|
type DefaultizedAxisConfig = {
|
|
@@ -23,7 +25,7 @@ export declare const CartesianContext: React.Context<{
|
|
|
23
25
|
xAxisIds: string[];
|
|
24
26
|
yAxisIds: string[];
|
|
25
27
|
}>;
|
|
26
|
-
declare function CartesianContextProvider({ xAxis, yAxis, children }: CartesianContextProviderProps): React.JSX.Element;
|
|
28
|
+
declare function CartesianContextProvider({ xAxis: inXAxis, yAxis: inYAxis, dataset, children, }: CartesianContextProviderProps): React.JSX.Element;
|
|
27
29
|
declare namespace CartesianContextProvider {
|
|
28
30
|
var propTypes: any;
|
|
29
31
|
}
|
|
@@ -43,12 +43,37 @@ const CartesianContext = /*#__PURE__*/React.createContext({
|
|
|
43
43
|
});
|
|
44
44
|
exports.CartesianContext = CartesianContext;
|
|
45
45
|
function CartesianContextProvider({
|
|
46
|
-
xAxis,
|
|
47
|
-
yAxis,
|
|
46
|
+
xAxis: inXAxis,
|
|
47
|
+
yAxis: inYAxis,
|
|
48
|
+
dataset,
|
|
48
49
|
children
|
|
49
50
|
}) {
|
|
50
51
|
const formattedSeries = React.useContext(_SeriesContextProvider.SeriesContext);
|
|
51
52
|
const drawingArea = React.useContext(_DrawingProvider.DrawingContext);
|
|
53
|
+
const xAxis = React.useMemo(() => inXAxis?.map(axisConfig => {
|
|
54
|
+
const dataKey = axisConfig.dataKey;
|
|
55
|
+
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
56
|
+
return axisConfig;
|
|
57
|
+
}
|
|
58
|
+
if (dataset === undefined) {
|
|
59
|
+
throw Error('MUI: x-axis uses `dataKey` but no `dataset` is provided.');
|
|
60
|
+
}
|
|
61
|
+
return (0, _extends2.default)({}, axisConfig, {
|
|
62
|
+
data: dataset.map(d => d[dataKey])
|
|
63
|
+
});
|
|
64
|
+
}), [inXAxis, dataset]);
|
|
65
|
+
const yAxis = React.useMemo(() => inYAxis?.map(axisConfig => {
|
|
66
|
+
const dataKey = axisConfig.dataKey;
|
|
67
|
+
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
68
|
+
return axisConfig;
|
|
69
|
+
}
|
|
70
|
+
if (dataset === undefined) {
|
|
71
|
+
throw Error('MUI: y-axis uses `dataKey` but no `dataset` is provided.');
|
|
72
|
+
}
|
|
73
|
+
return (0, _extends2.default)({}, axisConfig, {
|
|
74
|
+
data: dataset.map(d => d[dataKey])
|
|
75
|
+
});
|
|
76
|
+
}), [inYAxis, dataset]);
|
|
52
77
|
const value = React.useMemo(() => {
|
|
53
78
|
const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis) => {
|
|
54
79
|
const getter = getters[chartType];
|
|
@@ -191,19 +216,22 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
191
216
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
192
217
|
// ----------------------------------------------------------------------
|
|
193
218
|
children: _propTypes.default.node,
|
|
219
|
+
dataset: _propTypes.default.arrayOf(_propTypes.default.object),
|
|
194
220
|
xAxis: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
195
221
|
axisId: _propTypes.default.string,
|
|
196
222
|
classes: _propTypes.default.object,
|
|
197
223
|
data: _propTypes.default.array,
|
|
224
|
+
dataKey: _propTypes.default.string,
|
|
198
225
|
disableLine: _propTypes.default.bool,
|
|
199
226
|
disableTicks: _propTypes.default.bool,
|
|
200
227
|
fill: _propTypes.default.string,
|
|
228
|
+
hideTooltip: _propTypes.default.bool,
|
|
201
229
|
id: _propTypes.default.string,
|
|
202
230
|
label: _propTypes.default.string,
|
|
203
231
|
labelFontSize: _propTypes.default.number,
|
|
204
|
-
max: _propTypes.default.number,
|
|
232
|
+
max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
205
233
|
maxTicks: _propTypes.default.number,
|
|
206
|
-
min: _propTypes.default.number,
|
|
234
|
+
min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
207
235
|
minTicks: _propTypes.default.number,
|
|
208
236
|
position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
|
|
209
237
|
scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -217,15 +245,17 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
217
245
|
axisId: _propTypes.default.string,
|
|
218
246
|
classes: _propTypes.default.object,
|
|
219
247
|
data: _propTypes.default.array,
|
|
248
|
+
dataKey: _propTypes.default.string,
|
|
220
249
|
disableLine: _propTypes.default.bool,
|
|
221
250
|
disableTicks: _propTypes.default.bool,
|
|
222
251
|
fill: _propTypes.default.string,
|
|
252
|
+
hideTooltip: _propTypes.default.bool,
|
|
223
253
|
id: _propTypes.default.string,
|
|
224
254
|
label: _propTypes.default.string,
|
|
225
255
|
labelFontSize: _propTypes.default.number,
|
|
226
|
-
max: _propTypes.default.number,
|
|
256
|
+
max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
227
257
|
maxTicks: _propTypes.default.number,
|
|
228
|
-
min: _propTypes.default.number,
|
|
258
|
+
min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
229
259
|
minTicks: _propTypes.default.number,
|
|
230
260
|
position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
|
|
231
261
|
scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { AllSeriesType } from '../models/seriesType';
|
|
3
|
-
import { ChartSeriesType, FormatterResult } from '../models/seriesType/config';
|
|
3
|
+
import { ChartSeriesType, DatasetType, FormatterResult } from '../models/seriesType/config';
|
|
4
4
|
import { ChartsColorPalette } from '../colorPalettes';
|
|
5
5
|
export type SeriesContextProviderProps = {
|
|
6
|
+
dataset?: DatasetType;
|
|
6
7
|
series: AllSeriesType[];
|
|
7
8
|
/**
|
|
8
9
|
* Color palette used to colorize multiple series.
|
|
@@ -14,4 +15,4 @@ export type FormattedSeries = {
|
|
|
14
15
|
[type in ChartSeriesType]?: FormatterResult<type>;
|
|
15
16
|
};
|
|
16
17
|
export declare const SeriesContext: React.Context<FormattedSeries>;
|
|
17
|
-
export declare function SeriesContextProvider({ series, colors, children, }: SeriesContextProviderProps): React.JSX.Element;
|
|
18
|
+
export declare function SeriesContextProvider({ series, dataset, colors, children, }: SeriesContextProviderProps): React.JSX.Element;
|
|
@@ -26,6 +26,7 @@ const seriesTypeFormatter = {
|
|
|
26
26
|
line: _formatter3.default,
|
|
27
27
|
pie: _formatter4.default
|
|
28
28
|
};
|
|
29
|
+
|
|
29
30
|
/**
|
|
30
31
|
* This methods is the interface between what the developer is providing and what components receives
|
|
31
32
|
* To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if some line data are modified
|
|
@@ -34,7 +35,7 @@ const seriesTypeFormatter = {
|
|
|
34
35
|
* @param colors The color palette used to defaultize series colors
|
|
35
36
|
* @returns An object structuring all the series by type.
|
|
36
37
|
*/
|
|
37
|
-
const formatSeries = (series, colors) => {
|
|
38
|
+
const formatSeries = (series, colors, dataset) => {
|
|
38
39
|
// Group series by type
|
|
39
40
|
const seriesGroups = {};
|
|
40
41
|
series.forEach((seriesData, seriesIndex) => {
|
|
@@ -60,18 +61,19 @@ const formatSeries = (series, colors) => {
|
|
|
60
61
|
// Apply formater on a type group
|
|
61
62
|
Object.keys(seriesTypeFormatter).forEach(type => {
|
|
62
63
|
if (seriesGroups[type] !== undefined) {
|
|
63
|
-
formattedSeries[type] = seriesTypeFormatter[type]?.(seriesGroups[type]) ?? seriesGroups[type];
|
|
64
|
+
formattedSeries[type] = seriesTypeFormatter[type]?.(seriesGroups[type], dataset) ?? seriesGroups[type];
|
|
64
65
|
}
|
|
65
66
|
});
|
|
66
67
|
return formattedSeries;
|
|
67
68
|
};
|
|
68
69
|
function SeriesContextProvider({
|
|
69
70
|
series,
|
|
71
|
+
dataset,
|
|
70
72
|
colors = _colorPalettes.blueberryTwilightPalette,
|
|
71
73
|
children
|
|
72
74
|
}) {
|
|
73
75
|
const theme = (0, _styles.useTheme)();
|
|
74
|
-
const formattedSeries = React.useMemo(() => formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors), [series, colors, theme.palette.mode]);
|
|
76
|
+
const formattedSeries = React.useMemo(() => formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors, dataset), [series, colors, theme.palette.mode, dataset]);
|
|
75
77
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(SeriesContext.Provider, {
|
|
76
78
|
value: formattedSeries,
|
|
77
79
|
children: children
|
package/esm/BarChart/BarChart.js
CHANGED
|
@@ -21,6 +21,7 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
21
21
|
height,
|
|
22
22
|
margin,
|
|
23
23
|
colors,
|
|
24
|
+
dataset,
|
|
24
25
|
sx,
|
|
25
26
|
tooltip,
|
|
26
27
|
axisHighlight,
|
|
@@ -45,11 +46,15 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
45
46
|
id: DEFAULT_X_AXIS_KEY,
|
|
46
47
|
scaleType: 'band',
|
|
47
48
|
data: Array.from({
|
|
48
|
-
length: Math.max(...series.map(s =>
|
|
49
|
+
length: Math.max(...series.map(s => {
|
|
50
|
+
var _ref, _s$data;
|
|
51
|
+
return ((_ref = (_s$data = s.data) != null ? _s$data : dataset) != null ? _ref : []).length;
|
|
52
|
+
}))
|
|
49
53
|
}, (_, index) => index)
|
|
50
54
|
}],
|
|
51
55
|
yAxis: yAxis,
|
|
52
56
|
colors: colors,
|
|
57
|
+
dataset: dataset,
|
|
53
58
|
sx: sx,
|
|
54
59
|
disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
|
|
55
60
|
children: [/*#__PURE__*/_jsx("g", {
|
|
@@ -100,6 +105,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
100
105
|
* Color palette used to colorize multiple series.
|
|
101
106
|
*/
|
|
102
107
|
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
108
|
+
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
103
109
|
desc: PropTypes.string,
|
|
104
110
|
disableAxisListener: PropTypes.bool,
|
|
105
111
|
height: PropTypes.number,
|
|
@@ -163,7 +169,8 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
163
169
|
}), PropTypes.string]),
|
|
164
170
|
series: PropTypes.arrayOf(PropTypes.shape({
|
|
165
171
|
color: PropTypes.string,
|
|
166
|
-
data: PropTypes.arrayOf(PropTypes.number)
|
|
172
|
+
data: PropTypes.arrayOf(PropTypes.number),
|
|
173
|
+
dataKey: PropTypes.string,
|
|
167
174
|
highlightScope: PropTypes.shape({
|
|
168
175
|
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
169
176
|
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
@@ -215,15 +222,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
215
222
|
axisId: PropTypes.string,
|
|
216
223
|
classes: PropTypes.object,
|
|
217
224
|
data: PropTypes.array,
|
|
225
|
+
dataKey: PropTypes.string,
|
|
218
226
|
disableLine: PropTypes.bool,
|
|
219
227
|
disableTicks: PropTypes.bool,
|
|
220
228
|
fill: PropTypes.string,
|
|
229
|
+
hideTooltip: PropTypes.bool,
|
|
221
230
|
id: PropTypes.string,
|
|
222
231
|
label: PropTypes.string,
|
|
223
232
|
labelFontSize: PropTypes.number,
|
|
224
|
-
max: PropTypes.number,
|
|
233
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
225
234
|
maxTicks: PropTypes.number,
|
|
226
|
-
min: PropTypes.number,
|
|
235
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
227
236
|
minTicks: PropTypes.number,
|
|
228
237
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
229
238
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -237,15 +246,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
237
246
|
axisId: PropTypes.string,
|
|
238
247
|
classes: PropTypes.object,
|
|
239
248
|
data: PropTypes.array,
|
|
249
|
+
dataKey: PropTypes.string,
|
|
240
250
|
disableLine: PropTypes.bool,
|
|
241
251
|
disableTicks: PropTypes.bool,
|
|
242
252
|
fill: PropTypes.string,
|
|
253
|
+
hideTooltip: PropTypes.bool,
|
|
243
254
|
id: PropTypes.string,
|
|
244
255
|
label: PropTypes.string,
|
|
245
256
|
labelFontSize: PropTypes.number,
|
|
246
|
-
max: PropTypes.number,
|
|
257
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
247
258
|
maxTicks: PropTypes.number,
|
|
248
|
-
min: PropTypes.number,
|
|
259
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
249
260
|
minTicks: PropTypes.number,
|
|
250
261
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
251
262
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import { stack as d3Stack } from 'd3-shape';
|
|
3
3
|
import { getStackingGroups } from '../internals/stackSeries';
|
|
4
4
|
import defaultizeValueFormatter from '../internals/defaultizeValueFormatter';
|
|
5
|
-
const formatter = params => {
|
|
5
|
+
const formatter = (params, dataset) => {
|
|
6
6
|
const {
|
|
7
7
|
seriesOrder,
|
|
8
8
|
series
|
|
@@ -10,17 +10,22 @@ const formatter = params => {
|
|
|
10
10
|
const stackingGroups = getStackingGroups(params);
|
|
11
11
|
|
|
12
12
|
// Create a data set with format adapted to d3
|
|
13
|
-
const d3Dataset = [];
|
|
13
|
+
const d3Dataset = dataset != null ? dataset : [];
|
|
14
14
|
seriesOrder.forEach(id => {
|
|
15
|
-
series[id].data
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
const data = series[id].data;
|
|
16
|
+
if (data !== undefined) {
|
|
17
|
+
data.forEach((value, index) => {
|
|
18
|
+
if (d3Dataset.length <= index) {
|
|
19
|
+
d3Dataset.push({
|
|
20
|
+
[id]: value
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
d3Dataset[index][id] = value;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
} else if (dataset === undefined) {
|
|
27
|
+
throw new Error([`MUI: bar series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
|
|
28
|
+
}
|
|
24
29
|
});
|
|
25
30
|
const completedSeries = {};
|
|
26
31
|
stackingGroups.forEach(stackingGroup => {
|
|
@@ -30,9 +35,15 @@ const formatter = params => {
|
|
|
30
35
|
stackingOrder
|
|
31
36
|
} = stackingGroup;
|
|
32
37
|
// Get stacked values, and derive the domain
|
|
33
|
-
const stackedSeries = d3Stack().keys(ids
|
|
38
|
+
const stackedSeries = d3Stack().keys(ids.map(id => {
|
|
39
|
+
// Use dataKey if needed and available
|
|
40
|
+
const dataKey = series[id].dataKey;
|
|
41
|
+
return series[id].data === undefined && dataKey !== undefined ? dataKey : id;
|
|
42
|
+
})).order(stackingOrder).offset(stackingOffset)(d3Dataset);
|
|
34
43
|
ids.forEach((id, index) => {
|
|
44
|
+
const dataKey = series[id].dataKey;
|
|
35
45
|
completedSeries[id] = _extends({}, series[id], {
|
|
46
|
+
data: dataKey ? dataset.map(d => d[dataKey]) : series[id].data,
|
|
36
47
|
stackedData: stackedSeries[index].map(([a, b]) => [a, b])
|
|
37
48
|
});
|
|
38
49
|
});
|
|
@@ -16,6 +16,7 @@ export const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContai
|
|
|
16
16
|
xAxis,
|
|
17
17
|
yAxis,
|
|
18
18
|
colors,
|
|
19
|
+
dataset,
|
|
19
20
|
sx,
|
|
20
21
|
title,
|
|
21
22
|
desc,
|
|
@@ -32,9 +33,11 @@ export const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContai
|
|
|
32
33
|
children: /*#__PURE__*/_jsx(SeriesContextProvider, {
|
|
33
34
|
series: series,
|
|
34
35
|
colors: colors,
|
|
36
|
+
dataset: dataset,
|
|
35
37
|
children: /*#__PURE__*/_jsx(CartesianContextProvider, {
|
|
36
38
|
xAxis: xAxis,
|
|
37
39
|
yAxis: yAxis,
|
|
40
|
+
dataset: dataset,
|
|
38
41
|
children: /*#__PURE__*/_jsx(InteractionProvider, {
|
|
39
42
|
children: /*#__PURE__*/_jsx(HighlightProvider, {
|
|
40
43
|
children: /*#__PURE__*/_jsx(ChartsSurface, {
|
|
@@ -24,7 +24,7 @@ export function DefaultChartsAxisContent(props) {
|
|
|
24
24
|
variant: "outlined",
|
|
25
25
|
className: classes.root,
|
|
26
26
|
children: /*#__PURE__*/_jsxs(ChartsTooltipTable, {
|
|
27
|
-
children: [axisValue != null && /*#__PURE__*/_jsx("thead", {
|
|
27
|
+
children: [axisValue != null && !axis.hideTooltip && /*#__PURE__*/_jsx("thead", {
|
|
28
28
|
children: /*#__PURE__*/_jsx(ChartsTooltipRow, {
|
|
29
29
|
children: /*#__PURE__*/_jsx(ChartsTooltipCell, {
|
|
30
30
|
colSpan: 3,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import { area as d3Area } from 'd3-shape';
|
|
3
4
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
@@ -6,7 +7,7 @@ import { AreaElement } from './AreaElement';
|
|
|
6
7
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
7
8
|
import getCurveFactory from '../internals/getCurve';
|
|
8
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
-
export function AreaPlot() {
|
|
10
|
+
export function AreaPlot(props) {
|
|
10
11
|
const seriesData = React.useContext(SeriesContext).line;
|
|
11
12
|
const axisData = React.useContext(CartesianContext);
|
|
12
13
|
if (seriesData === undefined) {
|
|
@@ -24,7 +25,7 @@ export function AreaPlot() {
|
|
|
24
25
|
} = axisData;
|
|
25
26
|
const defaultXAxisId = xAxisIds[0];
|
|
26
27
|
const defaultYAxisId = yAxisIds[0];
|
|
27
|
-
return /*#__PURE__*/_jsx("g", {
|
|
28
|
+
return /*#__PURE__*/_jsx("g", _extends({}, props, {
|
|
28
29
|
children: stackingGroups.flatMap(({
|
|
29
30
|
ids: groupIds
|
|
30
31
|
}) => {
|
|
@@ -54,5 +55,5 @@ export function AreaPlot() {
|
|
|
54
55
|
}, seriesId);
|
|
55
56
|
});
|
|
56
57
|
})
|
|
57
|
-
});
|
|
58
|
+
}));
|
|
58
59
|
}
|