@mui/x-charts 6.0.0-alpha.5 → 6.0.0-alpha.7
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.d.ts +18 -2
- package/BarChart/BarChart.js +74 -17
- package/BarChart/BarElement.d.ts +22 -0
- package/BarChart/BarElement.js +21 -10
- package/BarChart/BarPlot.d.ts +14 -1
- package/BarChart/BarPlot.js +23 -4
- package/BarChart/formatter.js +23 -12
- package/CHANGELOG.md +154 -0
- package/ChartContainer/index.js +3 -0
- package/ChartsAxis/ChartsAxis.d.ts +11 -1
- package/ChartsAxis/ChartsAxis.js +51 -6
- package/ChartsLegend/ChartsLegend.d.ts +25 -2
- package/ChartsLegend/ChartsLegend.js +49 -17
- package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/ChartsTooltip/ChartsTooltipTable.d.ts +2 -9
- package/ChartsXAxis/ChartsXAxis.js +44 -9
- package/ChartsYAxis/ChartsYAxis.js +44 -9
- package/LineChart/AreaElement.d.ts +22 -0
- package/LineChart/AreaElement.js +31 -11
- package/LineChart/AreaPlot.d.ts +14 -1
- package/LineChart/AreaPlot.js +32 -5
- package/LineChart/LineChart.d.ts +20 -2
- package/LineChart/LineChart.js +76 -16
- package/LineChart/LineElement.d.ts +22 -0
- package/LineChart/LineElement.js +31 -10
- package/LineChart/LinePlot.d.ts +14 -1
- package/LineChart/LinePlot.js +38 -6
- package/LineChart/MarkElement.js +1 -1
- package/LineChart/MarkPlot.d.ts +24 -1
- package/LineChart/MarkPlot.js +30 -6
- package/LineChart/formatter.js +23 -12
- package/PieChart/PieArcLabel.js +0 -1
- package/PieChart/PieChart.d.ts +14 -2
- package/PieChart/PieChart.js +60 -13
- package/PieChart/PiePlot.d.ts +27 -1
- package/PieChart/PiePlot.js +29 -6
- package/ScatterChart/ScatterChart.d.ts +18 -2
- package/ScatterChart/ScatterChart.js +64 -13
- package/ScatterChart/ScatterPlot.d.ts +24 -1
- package/ScatterChart/ScatterPlot.js +28 -4
- package/SparkLineChart/SparkLineChart.d.ts +73 -0
- package/SparkLineChart/SparkLineChart.js +218 -0
- package/SparkLineChart/index.d.ts +1 -0
- package/SparkLineChart/index.js +12 -0
- package/SparkLineChart/package.json +6 -0
- package/colorPalettes/colorPalettes.js +2 -2
- package/context/CartesianContextProvider.d.ts +3 -1
- package/context/CartesianContextProvider.js +50 -14
- package/context/SeriesContextProvider.d.ts +3 -2
- package/context/SeriesContextProvider.js +5 -3
- package/esm/BarChart/BarChart.js +77 -17
- package/esm/BarChart/BarElement.js +21 -11
- package/esm/BarChart/BarPlot.js +23 -4
- package/esm/BarChart/formatter.js +23 -12
- package/esm/ChartContainer/index.js +3 -0
- package/esm/ChartsAxis/ChartsAxis.js +51 -6
- package/esm/ChartsLegend/ChartsLegend.js +47 -14
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/esm/ChartsXAxis/ChartsXAxis.js +45 -9
- package/esm/ChartsYAxis/ChartsYAxis.js +45 -9
- package/esm/LineChart/AreaElement.js +31 -11
- package/esm/LineChart/AreaPlot.js +33 -5
- package/esm/LineChart/LineChart.js +79 -16
- package/esm/LineChart/LineElement.js +31 -11
- package/esm/LineChart/LinePlot.js +45 -9
- package/esm/LineChart/MarkElement.js +1 -1
- package/esm/LineChart/MarkPlot.js +31 -6
- package/esm/LineChart/formatter.js +23 -13
- package/esm/PieChart/PieArcLabel.js +0 -1
- package/esm/PieChart/PieChart.js +60 -13
- package/esm/PieChart/PiePlot.js +31 -6
- package/esm/ScatterChart/ScatterChart.js +64 -13
- package/esm/ScatterChart/ScatterPlot.js +29 -4
- package/esm/SparkLineChart/SparkLineChart.js +210 -0
- package/esm/SparkLineChart/index.js +1 -0
- package/esm/colorPalettes/colorPalettes.js +2 -2
- package/esm/context/CartesianContextProvider.js +50 -14
- package/esm/context/SeriesContextProvider.js +5 -3
- package/esm/hooks/useTicks.js +9 -6
- package/esm/index.js +1 -0
- package/esm/internals/components/AxisSharedComponents.js +10 -10
- package/esm/models/index.js +3 -1
- package/hooks/useTicks.d.ts +20 -5
- package/hooks/useTicks.js +9 -6
- package/index.d.ts +1 -0
- package/index.js +12 -1
- package/internals/components/AxisSharedComponents.d.ts +4 -4
- package/internals/components/AxisSharedComponents.js +15 -15
- package/internals/defaultizeColor.d.ts +4 -2
- package/legacy/BarChart/BarChart.js +75 -17
- package/legacy/BarChart/BarElement.js +20 -10
- package/legacy/BarChart/BarPlot.js +23 -4
- package/legacy/BarChart/formatter.js +23 -10
- package/legacy/ChartContainer/index.js +3 -0
- package/legacy/ChartsAxis/ChartsAxis.js +51 -6
- package/legacy/ChartsLegend/ChartsLegend.js +46 -15
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/legacy/ChartsXAxis/ChartsXAxis.js +45 -9
- package/legacy/ChartsYAxis/ChartsYAxis.js +45 -9
- package/legacy/LineChart/AreaElement.js +30 -10
- package/legacy/LineChart/AreaPlot.js +31 -5
- package/legacy/LineChart/LineChart.js +77 -16
- package/legacy/LineChart/LineElement.js +30 -10
- package/legacy/LineChart/LinePlot.js +38 -6
- package/legacy/LineChart/MarkElement.js +1 -1
- package/legacy/LineChart/MarkPlot.js +29 -6
- package/legacy/LineChart/formatter.js +23 -11
- package/legacy/PieChart/PieArcLabel.js +0 -1
- package/legacy/PieChart/PieChart.js +60 -13
- package/legacy/PieChart/PiePlot.js +29 -6
- package/legacy/ScatterChart/ScatterChart.js +64 -13
- package/legacy/ScatterChart/ScatterPlot.js +27 -4
- package/legacy/SparkLineChart/SparkLineChart.js +214 -0
- package/legacy/SparkLineChart/index.js +1 -0
- package/legacy/colorPalettes/colorPalettes.js +2 -2
- package/legacy/context/CartesianContextProvider.js +59 -15
- package/legacy/context/SeriesContextProvider.js +6 -4
- package/legacy/hooks/useTicks.js +9 -9
- package/legacy/index.js +2 -1
- package/legacy/internals/components/AxisSharedComponents.js +10 -10
- package/legacy/models/index.js +3 -1
- package/models/axis.d.ts +34 -3
- 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 +74 -17
- package/modern/BarChart/BarElement.js +20 -11
- package/modern/BarChart/BarPlot.js +23 -4
- package/modern/BarChart/formatter.js +23 -12
- package/modern/ChartContainer/index.js +3 -0
- package/modern/ChartsAxis/ChartsAxis.js +51 -6
- package/modern/ChartsLegend/ChartsLegend.js +46 -14
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/modern/ChartsXAxis/ChartsXAxis.js +44 -9
- package/modern/ChartsYAxis/ChartsYAxis.js +44 -9
- package/modern/LineChart/AreaElement.js +30 -11
- package/modern/LineChart/AreaPlot.js +33 -5
- package/modern/LineChart/LineChart.js +76 -16
- package/modern/LineChart/LineElement.js +30 -11
- package/modern/LineChart/LinePlot.js +39 -6
- package/modern/LineChart/MarkElement.js +1 -1
- package/modern/LineChart/MarkPlot.js +30 -6
- package/modern/LineChart/formatter.js +23 -13
- package/modern/PieChart/PieArcLabel.js +0 -1
- package/modern/PieChart/PieChart.js +60 -13
- package/modern/PieChart/PiePlot.js +30 -6
- package/modern/ScatterChart/ScatterChart.js +64 -13
- package/modern/ScatterChart/ScatterPlot.js +28 -4
- package/modern/SparkLineChart/SparkLineChart.js +210 -0
- package/modern/SparkLineChart/index.js +1 -0
- package/modern/colorPalettes/colorPalettes.js +2 -2
- package/modern/context/CartesianContextProvider.js +50 -14
- package/modern/context/SeriesContextProvider.js +5 -3
- package/modern/hooks/useTicks.js +9 -6
- package/modern/index.js +2 -1
- package/modern/internals/components/AxisSharedComponents.js +10 -10
- package/modern/models/index.js +3 -1
- package/package.json +4 -2
- package/themeAugmentation/components.d.ts +0 -10
- package/themeAugmentation/overrides.d.ts +0 -2
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
5
|
+
import { BarPlot } from '../BarChart';
|
|
6
|
+
import { LinePlot, MarkPlot, AreaPlot, markElementClasses } from '../LineChart';
|
|
7
|
+
import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
|
|
8
|
+
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
9
|
+
import { ChartsTooltip } from '../ChartsTooltip';
|
|
10
|
+
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
const SparkLineMarkPlot = styled(MarkPlot)({
|
|
14
|
+
[`& .${markElementClasses.root}`]: {
|
|
15
|
+
display: 'none',
|
|
16
|
+
[`&.${markElementClasses.highlighted}`]: {
|
|
17
|
+
display: 'inherit'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const SPARKLINE_DEFAULT_MARGIN = {
|
|
22
|
+
top: 5,
|
|
23
|
+
bottom: 5,
|
|
24
|
+
left: 5,
|
|
25
|
+
right: 5
|
|
26
|
+
};
|
|
27
|
+
const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props, ref) {
|
|
28
|
+
const {
|
|
29
|
+
xAxis,
|
|
30
|
+
width,
|
|
31
|
+
height,
|
|
32
|
+
margin = SPARKLINE_DEFAULT_MARGIN,
|
|
33
|
+
colors,
|
|
34
|
+
sx,
|
|
35
|
+
showTooltip,
|
|
36
|
+
tooltip,
|
|
37
|
+
showHighlight,
|
|
38
|
+
axisHighlight: inAxisHighlight,
|
|
39
|
+
children,
|
|
40
|
+
slots,
|
|
41
|
+
slotProps,
|
|
42
|
+
data,
|
|
43
|
+
plotType = 'line',
|
|
44
|
+
valueFormatter = v => v.toString(),
|
|
45
|
+
area,
|
|
46
|
+
curve = 'linear'
|
|
47
|
+
} = props;
|
|
48
|
+
const defaultXHighlight = showHighlight && plotType === 'bar' ? {
|
|
49
|
+
x: 'band'
|
|
50
|
+
} : {
|
|
51
|
+
x: 'none'
|
|
52
|
+
};
|
|
53
|
+
const axisHighlight = _extends({}, defaultXHighlight, inAxisHighlight);
|
|
54
|
+
return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
|
|
55
|
+
ref: ref,
|
|
56
|
+
series: [_extends({
|
|
57
|
+
type: plotType,
|
|
58
|
+
data,
|
|
59
|
+
valueFormatter
|
|
60
|
+
}, plotType === 'bar' ? {} : {
|
|
61
|
+
area,
|
|
62
|
+
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
|
+
}, (_, index) => index),
|
|
73
|
+
hideTooltip: xAxis === undefined
|
|
74
|
+
}, xAxis)],
|
|
75
|
+
colors: colors,
|
|
76
|
+
sx: sx,
|
|
77
|
+
disableAxisListener: (!showTooltip || (tooltip == null ? void 0 : tooltip.trigger) !== 'axis') && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
|
|
78
|
+
children: [plotType === 'bar' && /*#__PURE__*/_jsx(BarPlot, {
|
|
79
|
+
slots: slots,
|
|
80
|
+
slotProps: slotProps
|
|
81
|
+
}), plotType === 'line' && /*#__PURE__*/_jsxs(React.Fragment, {
|
|
82
|
+
children: [/*#__PURE__*/_jsx(AreaPlot, {
|
|
83
|
+
slots: slots,
|
|
84
|
+
slotProps: slotProps
|
|
85
|
+
}), /*#__PURE__*/_jsx(LinePlot, {
|
|
86
|
+
slots: slots,
|
|
87
|
+
slotProps: slotProps
|
|
88
|
+
}), showHighlight && /*#__PURE__*/_jsx(SparkLineMarkPlot, {})]
|
|
89
|
+
}), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), showTooltip && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), children]
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
93
|
+
// ----------------------------- Warning --------------------------------
|
|
94
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
95
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
96
|
+
// ----------------------------------------------------------------------
|
|
97
|
+
/**
|
|
98
|
+
* Set to `true` to fill spark line area.
|
|
99
|
+
* Has no effect if plotType='bar'.
|
|
100
|
+
* @default false
|
|
101
|
+
*/
|
|
102
|
+
area: PropTypes.bool,
|
|
103
|
+
axisHighlight: PropTypes.shape({
|
|
104
|
+
x: PropTypes.oneOf(['band', 'line', 'none']),
|
|
105
|
+
y: PropTypes.oneOf(['line', 'none'])
|
|
106
|
+
}),
|
|
107
|
+
children: PropTypes.node,
|
|
108
|
+
className: PropTypes.string,
|
|
109
|
+
/**
|
|
110
|
+
* Color palette used to colorize multiple series.
|
|
111
|
+
*/
|
|
112
|
+
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
113
|
+
/**
|
|
114
|
+
* @default 'linear'
|
|
115
|
+
*/
|
|
116
|
+
curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
|
|
117
|
+
/**
|
|
118
|
+
* Data to plot.
|
|
119
|
+
*/
|
|
120
|
+
data: PropTypes.arrayOf(PropTypes.number).isRequired,
|
|
121
|
+
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
122
|
+
desc: PropTypes.string,
|
|
123
|
+
disableAxisListener: PropTypes.bool,
|
|
124
|
+
height: PropTypes.number,
|
|
125
|
+
margin: PropTypes.shape({
|
|
126
|
+
bottom: PropTypes.number,
|
|
127
|
+
left: PropTypes.number,
|
|
128
|
+
right: PropTypes.number,
|
|
129
|
+
top: PropTypes.number
|
|
130
|
+
}),
|
|
131
|
+
/**
|
|
132
|
+
* Type of plot used.
|
|
133
|
+
* @default 'line'
|
|
134
|
+
*/
|
|
135
|
+
plotType: PropTypes.oneOf(['bar', 'line']),
|
|
136
|
+
/**
|
|
137
|
+
* Set to `true` to highlight the value.
|
|
138
|
+
* With line, it shows a point.
|
|
139
|
+
* With bar, it shows a highlight band.
|
|
140
|
+
* @default false
|
|
141
|
+
*/
|
|
142
|
+
showHighlight: PropTypes.bool,
|
|
143
|
+
/**
|
|
144
|
+
* Set to `true` to enable the tooltip in the sparkline.
|
|
145
|
+
* @default false
|
|
146
|
+
*/
|
|
147
|
+
showTooltip: PropTypes.bool,
|
|
148
|
+
/**
|
|
149
|
+
* The props used for each component slot.
|
|
150
|
+
* @default {}
|
|
151
|
+
*/
|
|
152
|
+
slotProps: PropTypes.object,
|
|
153
|
+
/**
|
|
154
|
+
* Overridable component slots.
|
|
155
|
+
* @default {}
|
|
156
|
+
*/
|
|
157
|
+
slots: PropTypes.object,
|
|
158
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
159
|
+
title: PropTypes.string,
|
|
160
|
+
tooltip: PropTypes.shape({
|
|
161
|
+
axisContent: PropTypes.elementType,
|
|
162
|
+
classes: PropTypes.object,
|
|
163
|
+
itemContent: PropTypes.elementType,
|
|
164
|
+
trigger: PropTypes.oneOf(['axis', 'item', 'none'])
|
|
165
|
+
}),
|
|
166
|
+
/**
|
|
167
|
+
* Formatter used by the tooltip.
|
|
168
|
+
* @param {number} value The value to format.
|
|
169
|
+
* @returns {string} the formatted value.
|
|
170
|
+
*/
|
|
171
|
+
valueFormatter: PropTypes.func,
|
|
172
|
+
viewBox: PropTypes.shape({
|
|
173
|
+
height: PropTypes.number,
|
|
174
|
+
width: PropTypes.number,
|
|
175
|
+
x: PropTypes.number,
|
|
176
|
+
y: PropTypes.number
|
|
177
|
+
}),
|
|
178
|
+
width: PropTypes.number,
|
|
179
|
+
/**
|
|
180
|
+
* The xAxis configuration.
|
|
181
|
+
* Notice it is a single configuration object, not an array of configuration.
|
|
182
|
+
*/
|
|
183
|
+
xAxis: PropTypes.shape({
|
|
184
|
+
axisId: PropTypes.string,
|
|
185
|
+
classes: PropTypes.object,
|
|
186
|
+
data: PropTypes.array,
|
|
187
|
+
dataKey: PropTypes.string,
|
|
188
|
+
disableLine: PropTypes.bool,
|
|
189
|
+
disableTicks: PropTypes.bool,
|
|
190
|
+
fill: PropTypes.string,
|
|
191
|
+
hideTooltip: PropTypes.bool,
|
|
192
|
+
id: PropTypes.string,
|
|
193
|
+
label: PropTypes.string,
|
|
194
|
+
labelFontSize: PropTypes.number,
|
|
195
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
196
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
197
|
+
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
198
|
+
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
199
|
+
slotProps: PropTypes.object,
|
|
200
|
+
slots: PropTypes.object,
|
|
201
|
+
stroke: PropTypes.string,
|
|
202
|
+
tickFontSize: PropTypes.number,
|
|
203
|
+
tickMaxStep: PropTypes.number,
|
|
204
|
+
tickMinStep: PropTypes.number,
|
|
205
|
+
tickNumber: PropTypes.number,
|
|
206
|
+
tickSize: PropTypes.number,
|
|
207
|
+
valueFormatter: PropTypes.func
|
|
208
|
+
})
|
|
209
|
+
} : void 0;
|
|
210
|
+
export { SparkLineChart };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SparkLineChart } from './SparkLineChart';
|
|
@@ -4,6 +4,6 @@ export const blueberryTwilightPalette = mode => mode === 'dark' ? blueberryTwili
|
|
|
4
4
|
export const mangoFusionPaletteLight = ['#173A5E', '#00A3A0', '#C91B63', '#EF5350', '#FFA726', '#B800D8', '#60009B', '#2E96FF', '#2731C8', '#03008D'];
|
|
5
5
|
export const mangoFusionPaletteDark = ['#41698F', '#19D0CD', '#DE196B', '#FC5F5C', '#FFD771', '#DA00FF', '#9001CB', '#72CCFF', '#2E96FF', '#3B48E0'];
|
|
6
6
|
export const mangoFusionPalette = mode => mode === 'dark' ? mangoFusionPaletteDark : mangoFusionPaletteLight;
|
|
7
|
-
export const cheerfulFiestaPaletteDark = ['#
|
|
8
|
-
export const cheerfulFiestaPaletteLight = ['#
|
|
7
|
+
export const cheerfulFiestaPaletteDark = ['#0059B2', '#2E96FF', '#FFC24C', '#FF9F0E', '#F38200', '#2ABFDE', '#1F94AD', '#BD2C38', '#FF3143', '#FF8282'];
|
|
8
|
+
export const cheerfulFiestaPaletteLight = ['#003A75', '#007FFF', '#FFC24C', '#FF9D09', '#CA6C00', '#127D94', '#1F94AD', '#C82634', '#FF3143', '#FF7E7E'];
|
|
9
9
|
export const cheerfulFiestaPalette = mode => mode === 'dark' ? cheerfulFiestaPaletteDark : cheerfulFiestaPaletteLight;
|
|
@@ -32,12 +32,37 @@ export const CartesianContext = /*#__PURE__*/React.createContext({
|
|
|
32
32
|
yAxisIds: []
|
|
33
33
|
});
|
|
34
34
|
function CartesianContextProvider({
|
|
35
|
-
xAxis,
|
|
36
|
-
yAxis,
|
|
35
|
+
xAxis: inXAxis,
|
|
36
|
+
yAxis: inYAxis,
|
|
37
|
+
dataset,
|
|
37
38
|
children
|
|
38
39
|
}) {
|
|
39
40
|
const formattedSeries = React.useContext(SeriesContext);
|
|
40
41
|
const drawingArea = React.useContext(DrawingContext);
|
|
42
|
+
const xAxis = React.useMemo(() => inXAxis == null ? void 0 : inXAxis.map(axisConfig => {
|
|
43
|
+
const dataKey = axisConfig.dataKey;
|
|
44
|
+
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
45
|
+
return axisConfig;
|
|
46
|
+
}
|
|
47
|
+
if (dataset === undefined) {
|
|
48
|
+
throw Error('MUI: x-axis uses `dataKey` but no `dataset` is provided.');
|
|
49
|
+
}
|
|
50
|
+
return _extends({}, axisConfig, {
|
|
51
|
+
data: dataset.map(d => d[dataKey])
|
|
52
|
+
});
|
|
53
|
+
}), [inXAxis, dataset]);
|
|
54
|
+
const yAxis = React.useMemo(() => inYAxis == null ? void 0 : inYAxis.map(axisConfig => {
|
|
55
|
+
const dataKey = axisConfig.dataKey;
|
|
56
|
+
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
57
|
+
return axisConfig;
|
|
58
|
+
}
|
|
59
|
+
if (dataset === undefined) {
|
|
60
|
+
throw Error('MUI: y-axis uses `dataKey` but no `dataset` is provided.');
|
|
61
|
+
}
|
|
62
|
+
return _extends({}, axisConfig, {
|
|
63
|
+
data: dataset.map(d => d[dataKey])
|
|
64
|
+
});
|
|
65
|
+
}), [inYAxis, dataset]);
|
|
41
66
|
const value = React.useMemo(() => {
|
|
42
67
|
var _xAxis$map, _yAxis$map;
|
|
43
68
|
const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis) => {
|
|
@@ -102,7 +127,8 @@ function CartesianContextProvider({
|
|
|
102
127
|
const scaleType = (_axis$scaleType = axis.scaleType) != null ? _axis$scaleType : 'linear';
|
|
103
128
|
const extremums = [(_axis$min = axis.min) != null ? _axis$min : minData, (_axis$max = axis.max) != null ? _axis$max : maxData];
|
|
104
129
|
const ticksNumber = getTicksNumber(_extends({}, axis, {
|
|
105
|
-
range
|
|
130
|
+
range,
|
|
131
|
+
domain: extremums
|
|
106
132
|
}));
|
|
107
133
|
const niceScale = getScale(scaleType, extremums, range).nice(ticksNumber);
|
|
108
134
|
const niceDomain = niceScale.domain();
|
|
@@ -151,7 +177,8 @@ function CartesianContextProvider({
|
|
|
151
177
|
const scaleType = (_axis$scaleType2 = axis.scaleType) != null ? _axis$scaleType2 : 'linear';
|
|
152
178
|
const extremums = [(_axis$min3 = axis.min) != null ? _axis$min3 : minData, (_axis$max3 = axis.max) != null ? _axis$max3 : maxData];
|
|
153
179
|
const ticksNumber = getTicksNumber(_extends({}, axis, {
|
|
154
|
-
range
|
|
180
|
+
range,
|
|
181
|
+
domain: extremums
|
|
155
182
|
}));
|
|
156
183
|
const niceScale = getScale(scaleType, extremums, range).nice(ticksNumber);
|
|
157
184
|
const niceDomain = niceScale.domain();
|
|
@@ -186,48 +213,57 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
186
213
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
187
214
|
// ----------------------------------------------------------------------
|
|
188
215
|
children: PropTypes.node,
|
|
216
|
+
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
189
217
|
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
190
218
|
axisId: PropTypes.string,
|
|
191
219
|
classes: PropTypes.object,
|
|
192
220
|
data: PropTypes.array,
|
|
221
|
+
dataKey: PropTypes.string,
|
|
193
222
|
disableLine: PropTypes.bool,
|
|
194
223
|
disableTicks: PropTypes.bool,
|
|
195
224
|
fill: PropTypes.string,
|
|
225
|
+
hideTooltip: PropTypes.bool,
|
|
196
226
|
id: PropTypes.string,
|
|
197
227
|
label: PropTypes.string,
|
|
198
228
|
labelFontSize: PropTypes.number,
|
|
199
|
-
max: PropTypes.number,
|
|
200
|
-
|
|
201
|
-
min: PropTypes.number,
|
|
202
|
-
minTicks: PropTypes.number,
|
|
229
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
230
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
203
231
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
204
232
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
233
|
+
slotProps: PropTypes.object,
|
|
234
|
+
slots: PropTypes.object,
|
|
205
235
|
stroke: PropTypes.string,
|
|
206
236
|
tickFontSize: PropTypes.number,
|
|
237
|
+
tickMaxStep: PropTypes.number,
|
|
238
|
+
tickMinStep: PropTypes.number,
|
|
239
|
+
tickNumber: PropTypes.number,
|
|
207
240
|
tickSize: PropTypes.number,
|
|
208
|
-
tickSpacing: PropTypes.number,
|
|
209
241
|
valueFormatter: PropTypes.func
|
|
210
242
|
})),
|
|
211
243
|
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
212
244
|
axisId: PropTypes.string,
|
|
213
245
|
classes: PropTypes.object,
|
|
214
246
|
data: PropTypes.array,
|
|
247
|
+
dataKey: PropTypes.string,
|
|
215
248
|
disableLine: PropTypes.bool,
|
|
216
249
|
disableTicks: PropTypes.bool,
|
|
217
250
|
fill: PropTypes.string,
|
|
251
|
+
hideTooltip: PropTypes.bool,
|
|
218
252
|
id: PropTypes.string,
|
|
219
253
|
label: PropTypes.string,
|
|
220
254
|
labelFontSize: PropTypes.number,
|
|
221
|
-
max: PropTypes.number,
|
|
222
|
-
|
|
223
|
-
min: PropTypes.number,
|
|
224
|
-
minTicks: PropTypes.number,
|
|
255
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
256
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
225
257
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
226
258
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
259
|
+
slotProps: PropTypes.object,
|
|
260
|
+
slots: PropTypes.object,
|
|
227
261
|
stroke: PropTypes.string,
|
|
228
262
|
tickFontSize: PropTypes.number,
|
|
263
|
+
tickMaxStep: PropTypes.number,
|
|
264
|
+
tickMinStep: PropTypes.number,
|
|
265
|
+
tickNumber: PropTypes.number,
|
|
229
266
|
tickSize: PropTypes.number,
|
|
230
|
-
tickSpacing: PropTypes.number,
|
|
231
267
|
valueFormatter: PropTypes.func
|
|
232
268
|
}))
|
|
233
269
|
} : void 0;
|
|
@@ -15,6 +15,7 @@ const 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 @@ const 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
|
-
const formatSeries = (series, colors) => {
|
|
27
|
+
const formatSeries = (series, colors, dataset) => {
|
|
27
28
|
// Group series by type
|
|
28
29
|
const seriesGroups = {};
|
|
29
30
|
series.forEach((seriesData, seriesIndex) => {
|
|
@@ -51,18 +52,19 @@ const formatSeries = (series, colors) => {
|
|
|
51
52
|
Object.keys(seriesTypeFormatter).forEach(type => {
|
|
52
53
|
if (seriesGroups[type] !== undefined) {
|
|
53
54
|
var _seriesTypeFormatter$, _seriesTypeFormatter$2;
|
|
54
|
-
formattedSeries[type] = (_seriesTypeFormatter$ = (_seriesTypeFormatter$2 = seriesTypeFormatter[type]) == null ? void 0 : _seriesTypeFormatter$2.call(seriesTypeFormatter, seriesGroups[type])) != null ? _seriesTypeFormatter$ : seriesGroups[type];
|
|
55
|
+
formattedSeries[type] = (_seriesTypeFormatter$ = (_seriesTypeFormatter$2 = seriesTypeFormatter[type]) == null ? void 0 : _seriesTypeFormatter$2.call(seriesTypeFormatter, seriesGroups[type], dataset)) != null ? _seriesTypeFormatter$ : seriesGroups[type];
|
|
55
56
|
}
|
|
56
57
|
});
|
|
57
58
|
return formattedSeries;
|
|
58
59
|
};
|
|
59
60
|
export function SeriesContextProvider({
|
|
60
61
|
series,
|
|
62
|
+
dataset,
|
|
61
63
|
colors = blueberryTwilightPalette,
|
|
62
64
|
children
|
|
63
65
|
}) {
|
|
64
66
|
const theme = useTheme();
|
|
65
|
-
const formattedSeries = React.useMemo(() => formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors), [series, colors, theme.palette.mode]);
|
|
67
|
+
const formattedSeries = React.useMemo(() => formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors, dataset), [series, colors, theme.palette.mode, dataset]);
|
|
66
68
|
return /*#__PURE__*/_jsx(SeriesContext.Provider, {
|
|
67
69
|
value: formattedSeries,
|
|
68
70
|
children: children
|
package/esm/hooks/useTicks.js
CHANGED
|
@@ -2,13 +2,16 @@ import * as React from 'react';
|
|
|
2
2
|
import { isBandScale } from '../internals/isBandScale';
|
|
3
3
|
export function getTicksNumber(params) {
|
|
4
4
|
const {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
range
|
|
5
|
+
tickMaxStep,
|
|
6
|
+
tickMinStep,
|
|
7
|
+
tickNumber,
|
|
8
|
+
range,
|
|
9
|
+
domain
|
|
9
10
|
} = params;
|
|
10
|
-
const
|
|
11
|
-
|
|
11
|
+
const maxTicks = tickMinStep === undefined ? 999 : Math.floor(Math.abs(domain[1] - domain[0]) / tickMinStep);
|
|
12
|
+
const minTicks = tickMaxStep === undefined ? 2 : Math.ceil(Math.abs(domain[1] - domain[0]) / tickMaxStep);
|
|
13
|
+
const defaultizedTickNumber = tickNumber != null ? tickNumber : Math.floor(Math.abs(range[1] - range[0]) / 50);
|
|
14
|
+
return Math.min(maxTicks, Math.max(minTicks, defaultizedTickNumber));
|
|
12
15
|
}
|
|
13
16
|
function useTicks(options) {
|
|
14
17
|
const {
|
package/esm/index.js
CHANGED
|
@@ -8,39 +8,39 @@ export const AxisRoot = styled('g', {
|
|
|
8
8
|
})({
|
|
9
9
|
[`&.${axisClasses.directionY}`]: {
|
|
10
10
|
[`.${axisClasses.tickLabel}`]: {
|
|
11
|
-
|
|
11
|
+
dominantBaseline: 'middle'
|
|
12
12
|
},
|
|
13
13
|
[`.${axisClasses.label}`]: {
|
|
14
|
-
|
|
14
|
+
dominantBaseline: 'auto',
|
|
15
15
|
textAnchor: 'middle'
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
[`&.${axisClasses.left}`]: {
|
|
19
19
|
[`.${axisClasses.tickLabel}`]: {
|
|
20
|
-
|
|
20
|
+
dominantBaseline: 'central',
|
|
21
21
|
textAnchor: 'end'
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
[`&.${axisClasses.right}`]: {
|
|
25
25
|
[`.${axisClasses.tickLabel}`]: {
|
|
26
|
-
|
|
26
|
+
dominantBaseline: 'central',
|
|
27
27
|
textAnchor: 'start'
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
[`&.${axisClasses.bottom}`]: {
|
|
31
31
|
[`.${axisClasses.tickLabel}, .${axisClasses.label}`]: {
|
|
32
|
-
|
|
32
|
+
dominantBaseline: 'hanging',
|
|
33
33
|
textAnchor: 'middle'
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
[`&.${axisClasses.top}`]: {
|
|
37
37
|
[`.${axisClasses.tickLabel}, .${axisClasses.label}`]: {
|
|
38
|
-
|
|
38
|
+
dominantBaseline: 'baseline',
|
|
39
39
|
textAnchor: 'middle'
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
|
-
export const
|
|
43
|
+
export const ChartsLine = styled('line', {
|
|
44
44
|
name: 'MuiChartsAxis',
|
|
45
45
|
slot: 'Line',
|
|
46
46
|
overridesResolver: (props, styles) => styles.line
|
|
@@ -51,7 +51,7 @@ export const Line = styled('line', {
|
|
|
51
51
|
shapeRendering: 'crispEdges',
|
|
52
52
|
strokeWidth: 1
|
|
53
53
|
}));
|
|
54
|
-
export const
|
|
54
|
+
export const ChartsTick = styled('line', {
|
|
55
55
|
name: 'MuiChartsAxis',
|
|
56
56
|
slot: 'Tick',
|
|
57
57
|
overridesResolver: (props, styles) => styles.tick
|
|
@@ -61,7 +61,7 @@ export const Tick = styled('line', {
|
|
|
61
61
|
stroke: theme.palette.text.primary,
|
|
62
62
|
shapeRendering: 'crispEdges'
|
|
63
63
|
}));
|
|
64
|
-
export const
|
|
64
|
+
export const ChartsTickLabel = styled('text', {
|
|
65
65
|
name: 'MuiChartsAxis',
|
|
66
66
|
slot: 'TickLabel',
|
|
67
67
|
overridesResolver: (props, styles) => styles.tickLabel
|
|
@@ -70,7 +70,7 @@ export const TickLabel = styled('text', {
|
|
|
70
70
|
}) => _extends({}, theme.typography.caption, {
|
|
71
71
|
fill: theme.palette.text.primary
|
|
72
72
|
}));
|
|
73
|
-
export const
|
|
73
|
+
export const ChartsLabel = styled('text', {
|
|
74
74
|
name: 'MuiChartsAxis',
|
|
75
75
|
slot: 'Label',
|
|
76
76
|
overridesResolver: (props, styles) => styles.label
|
package/esm/models/index.js
CHANGED
package/hooks/useTicks.d.ts
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import { D3Scale } from '../models/axis';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
export interface TickParams {
|
|
3
|
+
/**
|
|
4
|
+
* Maximal step between two ticks.
|
|
5
|
+
* When using time data, the value is assumed to be in ms.
|
|
6
|
+
* Not supported by categorical axis (band, points).
|
|
7
|
+
*/
|
|
8
|
+
tickMaxStep?: number;
|
|
9
|
+
/**
|
|
10
|
+
* Maximal step between two ticks.
|
|
11
|
+
* When using time data, the value is assumed to be in ms.
|
|
12
|
+
* Not supported by categorical axis (band, points).
|
|
13
|
+
*/
|
|
14
|
+
tickMinStep?: number;
|
|
15
|
+
/**
|
|
16
|
+
* The number of ticks. This number is not guaranted.
|
|
17
|
+
* Not supported by categorical axis (band, points).
|
|
18
|
+
*/
|
|
19
|
+
tickNumber?: number;
|
|
20
|
+
}
|
|
7
21
|
export declare function getTicksNumber(params: TickParams & {
|
|
8
22
|
range: any[];
|
|
23
|
+
domain: any[];
|
|
9
24
|
}): number;
|
|
10
25
|
declare function useTicks(options: {
|
|
11
26
|
scale: D3Scale;
|
package/hooks/useTicks.js
CHANGED
|
@@ -11,13 +11,16 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
11
11
|
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; }
|
|
12
12
|
function getTicksNumber(params) {
|
|
13
13
|
const {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
range
|
|
14
|
+
tickMaxStep,
|
|
15
|
+
tickMinStep,
|
|
16
|
+
tickNumber,
|
|
17
|
+
range,
|
|
18
|
+
domain
|
|
18
19
|
} = params;
|
|
19
|
-
const
|
|
20
|
-
|
|
20
|
+
const maxTicks = tickMinStep === undefined ? 999 : Math.floor(Math.abs(domain[1] - domain[0]) / tickMinStep);
|
|
21
|
+
const minTicks = tickMaxStep === undefined ? 2 : Math.ceil(Math.abs(domain[1] - domain[0]) / tickMaxStep);
|
|
22
|
+
const defaultizedTickNumber = tickNumber ?? Math.floor(Math.abs(range[1] - range[0]) / 50);
|
|
23
|
+
return Math.min(maxTicks, Math.max(minTicks, defaultizedTickNumber));
|
|
21
24
|
}
|
|
22
25
|
function useTicks(options) {
|
|
23
26
|
const {
|
package/index.d.ts
CHANGED
package/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.7
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -175,6 +175,17 @@ Object.keys(_ScatterChart).forEach(function (key) {
|
|
|
175
175
|
}
|
|
176
176
|
});
|
|
177
177
|
});
|
|
178
|
+
var _SparkLineChart = require("./SparkLineChart");
|
|
179
|
+
Object.keys(_SparkLineChart).forEach(function (key) {
|
|
180
|
+
if (key === "default" || key === "__esModule") return;
|
|
181
|
+
if (key in exports && exports[key] === _SparkLineChart[key]) return;
|
|
182
|
+
Object.defineProperty(exports, key, {
|
|
183
|
+
enumerable: true,
|
|
184
|
+
get: function () {
|
|
185
|
+
return _SparkLineChart[key];
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
});
|
|
178
189
|
var _ChartContainer = require("./ChartContainer");
|
|
179
190
|
Object.keys(_ChartContainer).forEach(function (key) {
|
|
180
191
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export declare const AxisRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGProps<SVGGElement>, keyof import("react").SVGProps<SVGGElement>>, {}>;
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
3
|
+
export declare const ChartsLine: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGLineElementAttributes<SVGLineElement>, keyof import("react").SVGLineElementAttributes<SVGLineElement>>, {}>;
|
|
4
|
+
export declare const ChartsTick: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGLineElementAttributes<SVGLineElement>, keyof import("react").SVGLineElementAttributes<SVGLineElement>>, {}>;
|
|
5
|
+
export declare const ChartsTickLabel: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGTextElementAttributes<SVGTextElement>, keyof import("react").SVGTextElementAttributes<SVGTextElement>>, {}>;
|
|
6
|
+
export declare const ChartsLabel: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGTextElementAttributes<SVGTextElement>, keyof import("react").SVGTextElementAttributes<SVGTextElement>>, {}>;
|