@mui/x-charts 6.18.0 → 6.18.1
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 +7 -0
- package/BarChart/BarChart.js +41 -4
- package/CHANGELOG.md +63 -5
- package/ChartsAxis/ChartsAxis.js +5 -5
- package/ChartsAxis/axisClasses.d.ts +2 -2
- package/ChartsLegend/ChartsLegend.d.ts +1 -0
- package/ChartsLegend/ChartsLegend.js +1 -1
- package/ChartsLegend/chartsLegendClasses.d.ts +1 -1
- package/ChartsLegend/chartsLegendClasses.js +2 -2
- package/ChartsReferenceLine/ChartsReferenceLine.d.ts +10 -0
- package/ChartsReferenceLine/ChartsReferenceLine.js +78 -0
- package/ChartsReferenceLine/ChartsXReferenceLine.d.ts +13 -0
- package/ChartsReferenceLine/ChartsXReferenceLine.js +112 -0
- package/ChartsReferenceLine/ChartsYReferenceLine.d.ts +13 -0
- package/ChartsReferenceLine/ChartsYReferenceLine.js +112 -0
- package/ChartsReferenceLine/chartsReferenceLineClasses.d.ts +15 -0
- package/ChartsReferenceLine/chartsReferenceLineClasses.js +14 -0
- package/ChartsReferenceLine/common.d.ts +41 -0
- package/ChartsReferenceLine/common.js +27 -0
- package/ChartsReferenceLine/index.d.ts +2 -0
- package/ChartsReferenceLine/index.js +27 -0
- package/ChartsReferenceLine/package.json +6 -0
- package/ChartsSurface.d.ts +11 -0
- package/ChartsXAxis/ChartsXAxis.js +9 -5
- package/ChartsYAxis/ChartsYAxis.js +9 -5
- package/LineChart/LineChart.d.ts +7 -0
- package/LineChart/LineChart.js +41 -4
- package/LineChart/LineHighlightPlot.js +1 -1
- package/LineChart/MarkPlot.js +2 -1
- package/PieChart/PieChart.js +34 -4
- package/ResponsiveChartContainer/index.d.ts +13 -3
- package/ScatterChart/ScatterChart.js +34 -4
- package/SparkLineChart/SparkLineChart.js +22 -0
- package/context/CartesianContextProvider.d.ts +21 -1
- package/context/CartesianContextProvider.js +11 -0
- package/context/DrawingProvider.d.ts +18 -0
- package/context/DrawingProvider.js +6 -0
- package/context/HighlightProvider.d.ts +17 -0
- package/context/InteractionProvider.d.ts +6 -0
- package/context/SeriesContextProvider.d.ts +5 -0
- package/esm/BarChart/BarChart.js +41 -4
- package/esm/ChartsAxis/ChartsAxis.js +6 -5
- package/esm/ChartsLegend/ChartsLegend.js +2 -2
- package/esm/ChartsLegend/chartsLegendClasses.js +1 -1
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +70 -0
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +105 -0
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +105 -0
- package/esm/ChartsReferenceLine/chartsReferenceLineClasses.js +6 -0
- package/esm/ChartsReferenceLine/common.js +20 -0
- package/esm/ChartsReferenceLine/index.js +2 -0
- package/esm/ChartsXAxis/ChartsXAxis.js +10 -6
- package/esm/ChartsYAxis/ChartsYAxis.js +10 -6
- package/esm/LineChart/LineChart.js +41 -4
- package/esm/LineChart/LineHighlightPlot.js +1 -1
- package/esm/LineChart/MarkPlot.js +2 -1
- package/esm/PieChart/PieChart.js +34 -4
- package/esm/ScatterChart/ScatterChart.js +34 -4
- package/esm/SparkLineChart/SparkLineChart.js +22 -0
- package/esm/context/CartesianContextProvider.js +11 -0
- package/esm/context/DrawingProvider.js +6 -0
- package/esm/index.js +1 -0
- package/esm/internals/geometry.js +2 -2
- package/hooks/useScale.d.ts +2 -2
- package/index.d.ts +1 -0
- package/index.js +12 -1
- package/internals/components/ChartsText.d.ts +1 -1
- package/internals/geometry.d.ts +2 -2
- package/internals/geometry.js +2 -2
- package/internals/isBandScale.d.ts +3 -1
- package/internals/utils.d.ts +5 -0
- package/legacy/BarChart/BarChart.js +41 -4
- package/legacy/ChartsAxis/ChartsAxis.js +6 -5
- package/legacy/ChartsLegend/ChartsLegend.js +2 -2
- package/legacy/ChartsLegend/chartsLegendClasses.js +1 -1
- package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +70 -0
- package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +105 -0
- package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +105 -0
- package/legacy/ChartsReferenceLine/chartsReferenceLineClasses.js +6 -0
- package/legacy/ChartsReferenceLine/common.js +20 -0
- package/legacy/ChartsReferenceLine/index.js +2 -0
- package/legacy/ChartsXAxis/ChartsXAxis.js +15 -12
- package/legacy/ChartsYAxis/ChartsYAxis.js +15 -12
- package/legacy/LineChart/LineChart.js +41 -4
- package/legacy/LineChart/LineHighlightPlot.js +1 -1
- package/legacy/LineChart/MarkPlot.js +2 -1
- package/legacy/PieChart/PieChart.js +34 -4
- package/legacy/ScatterChart/ScatterChart.js +34 -4
- package/legacy/SparkLineChart/SparkLineChart.js +22 -0
- package/legacy/context/CartesianContextProvider.js +11 -0
- package/legacy/context/DrawingProvider.js +6 -0
- package/legacy/index.js +2 -1
- package/legacy/internals/geometry.js +2 -2
- package/models/axis.d.ts +33 -13
- package/models/layout.d.ts +6 -0
- package/models/seriesType/common.d.ts +16 -0
- package/modern/BarChart/BarChart.js +41 -4
- package/modern/ChartsAxis/ChartsAxis.js +5 -5
- package/modern/ChartsLegend/ChartsLegend.js +2 -2
- package/modern/ChartsLegend/chartsLegendClasses.js +1 -1
- package/modern/ChartsReferenceLine/ChartsReferenceLine.js +70 -0
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +104 -0
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +104 -0
- package/modern/ChartsReferenceLine/chartsReferenceLineClasses.js +6 -0
- package/modern/ChartsReferenceLine/common.js +20 -0
- package/modern/ChartsReferenceLine/index.js +2 -0
- package/modern/ChartsXAxis/ChartsXAxis.js +9 -5
- package/modern/ChartsYAxis/ChartsYAxis.js +9 -5
- package/modern/LineChart/LineChart.js +41 -4
- package/modern/LineChart/LineHighlightPlot.js +1 -1
- package/modern/LineChart/MarkPlot.js +2 -1
- package/modern/PieChart/PieChart.js +34 -4
- package/modern/ScatterChart/ScatterChart.js +34 -4
- package/modern/SparkLineChart/SparkLineChart.js +22 -0
- package/modern/context/CartesianContextProvider.js +11 -0
- package/modern/context/DrawingProvider.js +6 -0
- package/modern/index.js +2 -1
- package/modern/internals/geometry.js +2 -2
- package/package.json +1 -1
|
@@ -111,6 +111,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
111
111
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
112
112
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
113
113
|
// ----------------------------------------------------------------------
|
|
114
|
+
/**
|
|
115
|
+
* Object `{ x, y }` that defines how the charts highlight the mouse position along the x- and y-axes.
|
|
116
|
+
* The two properties accept the following values:
|
|
117
|
+
* - 'none': display nothing.
|
|
118
|
+
* - 'line': display a line at the current mouse position.
|
|
119
|
+
* - 'band': display a band at the current mouse position. Only available with band scale.
|
|
120
|
+
*/
|
|
114
121
|
axisHighlight: PropTypes.shape({
|
|
115
122
|
x: PropTypes.oneOf(['band', 'line', 'none']),
|
|
116
123
|
y: PropTypes.oneOf(['band', 'line', 'none'])
|
|
@@ -121,7 +128,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
121
128
|
* @default xAxisIds[0] The id of the first provided axis
|
|
122
129
|
*/
|
|
123
130
|
bottomAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
124
|
-
axisId: PropTypes.string
|
|
131
|
+
axisId: PropTypes.string,
|
|
125
132
|
classes: PropTypes.object,
|
|
126
133
|
disableLine: PropTypes.bool,
|
|
127
134
|
disableTicks: PropTypes.bool,
|
|
@@ -148,9 +155,21 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
148
155
|
* Color palette used to colorize multiple series.
|
|
149
156
|
*/
|
|
150
157
|
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
158
|
+
/**
|
|
159
|
+
* An array of objects that can be used to populate series and axes data using their `dataKey` property.
|
|
160
|
+
*/
|
|
151
161
|
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
152
162
|
desc: PropTypes.string,
|
|
163
|
+
/**
|
|
164
|
+
* If `true`, the charts will not listen to the mouse move event.
|
|
165
|
+
* It might break interactive features, but will improve performance.
|
|
166
|
+
* @default false
|
|
167
|
+
*/
|
|
153
168
|
disableAxisListener: PropTypes.bool,
|
|
169
|
+
/**
|
|
170
|
+
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
171
|
+
* @default undefined
|
|
172
|
+
*/
|
|
154
173
|
height: PropTypes.number,
|
|
155
174
|
layout: PropTypes.oneOf(['horizontal', 'vertical']),
|
|
156
175
|
/**
|
|
@@ -159,7 +178,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
159
178
|
* @default yAxisIds[0] The id of the first provided axis
|
|
160
179
|
*/
|
|
161
180
|
leftAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
162
|
-
axisId: PropTypes.string
|
|
181
|
+
axisId: PropTypes.string,
|
|
163
182
|
classes: PropTypes.object,
|
|
164
183
|
disableLine: PropTypes.bool,
|
|
165
184
|
disableTicks: PropTypes.bool,
|
|
@@ -194,6 +213,12 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
194
213
|
slotProps: PropTypes.object,
|
|
195
214
|
slots: PropTypes.object
|
|
196
215
|
}),
|
|
216
|
+
/**
|
|
217
|
+
* The margin between the SVG and the drawing area.
|
|
218
|
+
* It's used for leaving some space for extra information such as the x- and y-axis or legend.
|
|
219
|
+
* Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
|
|
220
|
+
* @default object Depends on the charts type.
|
|
221
|
+
*/
|
|
197
222
|
margin: PropTypes.shape({
|
|
198
223
|
bottom: PropTypes.number,
|
|
199
224
|
left: PropTypes.number,
|
|
@@ -206,7 +231,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
206
231
|
* @default null
|
|
207
232
|
*/
|
|
208
233
|
rightAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
209
|
-
axisId: PropTypes.string
|
|
234
|
+
axisId: PropTypes.string,
|
|
210
235
|
classes: PropTypes.object,
|
|
211
236
|
disableLine: PropTypes.bool,
|
|
212
237
|
disableTicks: PropTypes.bool,
|
|
@@ -277,7 +302,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
277
302
|
* @default null
|
|
278
303
|
*/
|
|
279
304
|
topAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
280
|
-
axisId: PropTypes.string
|
|
305
|
+
axisId: PropTypes.string,
|
|
281
306
|
classes: PropTypes.object,
|
|
282
307
|
disableLine: PropTypes.bool,
|
|
283
308
|
disableTicks: PropTypes.bool,
|
|
@@ -304,7 +329,15 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
304
329
|
x: PropTypes.number,
|
|
305
330
|
y: PropTypes.number
|
|
306
331
|
}),
|
|
332
|
+
/**
|
|
333
|
+
* The width of the chart in px. If not defined, it takes the width of the parent element.
|
|
334
|
+
* @default undefined
|
|
335
|
+
*/
|
|
307
336
|
width: PropTypes.number,
|
|
337
|
+
/**
|
|
338
|
+
* The configuration of the x-axes.
|
|
339
|
+
* If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
|
|
340
|
+
*/
|
|
308
341
|
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
309
342
|
axisId: PropTypes.string,
|
|
310
343
|
classes: PropTypes.object,
|
|
@@ -335,6 +368,10 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
335
368
|
tickSize: PropTypes.number,
|
|
336
369
|
valueFormatter: PropTypes.func
|
|
337
370
|
})),
|
|
371
|
+
/**
|
|
372
|
+
* The configuration of the y-axes.
|
|
373
|
+
* If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
|
|
374
|
+
*/
|
|
338
375
|
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
339
376
|
axisId: PropTypes.string,
|
|
340
377
|
classes: PropTypes.object,
|
|
@@ -11,7 +11,7 @@ const getAxisId = propsValue => {
|
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
13
|
if (typeof propsValue === 'object') {
|
|
14
|
-
return propsValue.axisId;
|
|
14
|
+
return propsValue.axisId ?? null;
|
|
15
15
|
}
|
|
16
16
|
return propsValue;
|
|
17
17
|
};
|
|
@@ -100,7 +100,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
|
|
|
100
100
|
* @default xAxisIds[0] The id of the first provided axis
|
|
101
101
|
*/
|
|
102
102
|
bottomAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
103
|
-
axisId: PropTypes.string
|
|
103
|
+
axisId: PropTypes.string,
|
|
104
104
|
classes: PropTypes.object,
|
|
105
105
|
disableLine: PropTypes.bool,
|
|
106
106
|
disableTicks: PropTypes.bool,
|
|
@@ -127,7 +127,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
|
|
|
127
127
|
* @default yAxisIds[0] The id of the first provided axis
|
|
128
128
|
*/
|
|
129
129
|
leftAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
130
|
-
axisId: PropTypes.string
|
|
130
|
+
axisId: PropTypes.string,
|
|
131
131
|
classes: PropTypes.object,
|
|
132
132
|
disableLine: PropTypes.bool,
|
|
133
133
|
disableTicks: PropTypes.bool,
|
|
@@ -154,7 +154,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
|
|
|
154
154
|
* @default null
|
|
155
155
|
*/
|
|
156
156
|
rightAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
157
|
-
axisId: PropTypes.string
|
|
157
|
+
axisId: PropTypes.string,
|
|
158
158
|
classes: PropTypes.object,
|
|
159
159
|
disableLine: PropTypes.bool,
|
|
160
160
|
disableTicks: PropTypes.bool,
|
|
@@ -191,7 +191,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
|
|
|
191
191
|
* @default null
|
|
192
192
|
*/
|
|
193
193
|
topAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
194
|
-
axisId: PropTypes.string
|
|
194
|
+
axisId: PropTypes.string,
|
|
195
195
|
classes: PropTypes.object,
|
|
196
196
|
disableLine: PropTypes.bool,
|
|
197
197
|
disableTicks: PropTypes.bool,
|
|
@@ -10,7 +10,7 @@ import { useThemeProps, useTheme, styled } from '@mui/material/styles';
|
|
|
10
10
|
import { DrawingContext } from '../context/DrawingProvider';
|
|
11
11
|
import { getSeriesToDisplay } from './utils';
|
|
12
12
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
13
|
-
import {
|
|
13
|
+
import { getLegendUtilityClass } from './chartsLegendClasses';
|
|
14
14
|
import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
|
|
15
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -25,7 +25,7 @@ const useUtilityClasses = ownerState => {
|
|
|
25
25
|
label: ['label'],
|
|
26
26
|
series: ['series']
|
|
27
27
|
};
|
|
28
|
-
return composeClasses(slots,
|
|
28
|
+
return composeClasses(slots, getLegendUtilityClass, classes);
|
|
29
29
|
};
|
|
30
30
|
export const ChartsLegendRoot = styled('g', {
|
|
31
31
|
name: 'MuiChartsLegend',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { unstable_generateUtilityClass as generateUtilityClass, unstable_generateUtilityClasses as generateUtilityClasses } from '@mui/utils';
|
|
2
|
-
export function
|
|
2
|
+
export function getLegendUtilityClass(slot) {
|
|
3
3
|
return generateUtilityClass('MuiChartsLegend', slot);
|
|
4
4
|
}
|
|
5
5
|
export const legendClasses = generateUtilityClasses('MuiChartsLegend', ['root', 'series', 'mark', 'label', 'column', 'row']);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { ChartsXReferenceLine } from './ChartsXReferenceLine';
|
|
5
|
+
import { ChartsYReferenceLine } from './ChartsYReferenceLine';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
function ChartsReferenceLine(props) {
|
|
8
|
+
if (props.x !== undefined && props.y !== undefined) {
|
|
9
|
+
throw new Error('MUI-X: The ChartsReferenceLine can not have both `x` and `y` props set.');
|
|
10
|
+
}
|
|
11
|
+
if (props.x === undefined && props.y === undefined) {
|
|
12
|
+
throw new Error('MUI-X: The ChartsReferenceLine should have a value in `x` or `y` prop.');
|
|
13
|
+
}
|
|
14
|
+
if (props.x !== undefined) {
|
|
15
|
+
return /*#__PURE__*/_jsx(ChartsXReferenceLine, _extends({}, props));
|
|
16
|
+
}
|
|
17
|
+
return /*#__PURE__*/_jsx(ChartsYReferenceLine, _extends({}, props));
|
|
18
|
+
}
|
|
19
|
+
process.env.NODE_ENV !== "production" ? ChartsReferenceLine.propTypes = {
|
|
20
|
+
// ----------------------------- Warning --------------------------------
|
|
21
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
22
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
23
|
+
// ----------------------------------------------------------------------
|
|
24
|
+
/**
|
|
25
|
+
* The id of the axis used for the reference value.
|
|
26
|
+
* @default The `id` of the first defined axis.
|
|
27
|
+
*/
|
|
28
|
+
axisId: PropTypes.string,
|
|
29
|
+
/**
|
|
30
|
+
* Override or extend the styles applied to the component.
|
|
31
|
+
*/
|
|
32
|
+
classes: PropTypes.object,
|
|
33
|
+
/**
|
|
34
|
+
* The label to display along the reference line.
|
|
35
|
+
*/
|
|
36
|
+
label: PropTypes.string,
|
|
37
|
+
/**
|
|
38
|
+
* The alignment if the label is in the chart drawing area.
|
|
39
|
+
* @default 'middle'
|
|
40
|
+
*/
|
|
41
|
+
labelAlign: PropTypes.oneOf(['end', 'middle', 'start']),
|
|
42
|
+
/**
|
|
43
|
+
* The style applied to the label.
|
|
44
|
+
*/
|
|
45
|
+
labelStyle: PropTypes.object,
|
|
46
|
+
/**
|
|
47
|
+
* The style applied to the line.
|
|
48
|
+
*/
|
|
49
|
+
lineStyle: PropTypes.object,
|
|
50
|
+
/**
|
|
51
|
+
* Additional space arround the label in px.
|
|
52
|
+
* Can be a number or an object `{ x, y }` to distinguish space with the reference line and space with axes.
|
|
53
|
+
* @default 5
|
|
54
|
+
*/
|
|
55
|
+
spacing: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
|
|
56
|
+
x: PropTypes.number,
|
|
57
|
+
y: PropTypes.number
|
|
58
|
+
})]),
|
|
59
|
+
/**
|
|
60
|
+
* The x value associated with the reference line.
|
|
61
|
+
* If defined the reference line will be vertical.
|
|
62
|
+
*/
|
|
63
|
+
x: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]),
|
|
64
|
+
/**
|
|
65
|
+
* The y value associated with the reference line.
|
|
66
|
+
* If defined the reference line will be horizontal.
|
|
67
|
+
*/
|
|
68
|
+
y: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string])
|
|
69
|
+
} : void 0;
|
|
70
|
+
export { ChartsReferenceLine };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import composeClasses from '@mui/utils/composeClasses';
|
|
4
|
+
import { useDrawingArea, useXScale } from '../hooks';
|
|
5
|
+
import { ReferenceLineRoot } from './common';
|
|
6
|
+
import { ChartsText } from '../internals/components/ChartsText';
|
|
7
|
+
import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
const getTextParams = ({
|
|
11
|
+
top,
|
|
12
|
+
height,
|
|
13
|
+
spacingY,
|
|
14
|
+
labelAlign = 'middle'
|
|
15
|
+
}) => {
|
|
16
|
+
switch (labelAlign) {
|
|
17
|
+
case 'start':
|
|
18
|
+
return {
|
|
19
|
+
y: top + spacingY,
|
|
20
|
+
style: {
|
|
21
|
+
dominantBaseline: 'hanging',
|
|
22
|
+
textAnchor: 'start'
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
case 'end':
|
|
26
|
+
return {
|
|
27
|
+
y: top + height - spacingY,
|
|
28
|
+
style: {
|
|
29
|
+
dominantBaseline: 'auto',
|
|
30
|
+
textAnchor: 'start'
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
default:
|
|
34
|
+
return {
|
|
35
|
+
y: top + height / 2,
|
|
36
|
+
style: {
|
|
37
|
+
dominantBaseline: 'central',
|
|
38
|
+
textAnchor: 'start'
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export function getXReferenceLineClasses(classes) {
|
|
44
|
+
return composeClasses({
|
|
45
|
+
root: ['root', 'vertical'],
|
|
46
|
+
line: ['line'],
|
|
47
|
+
label: ['label']
|
|
48
|
+
}, getReferenceLineUtilityClass, classes);
|
|
49
|
+
}
|
|
50
|
+
let warnedOnce = false;
|
|
51
|
+
function ChartsXReferenceLine(props) {
|
|
52
|
+
const {
|
|
53
|
+
x,
|
|
54
|
+
label = '',
|
|
55
|
+
spacing = 5,
|
|
56
|
+
classes: inClasses,
|
|
57
|
+
labelAlign,
|
|
58
|
+
lineStyle,
|
|
59
|
+
labelStyle,
|
|
60
|
+
axisId
|
|
61
|
+
} = props;
|
|
62
|
+
const {
|
|
63
|
+
top,
|
|
64
|
+
height
|
|
65
|
+
} = useDrawingArea();
|
|
66
|
+
const xAxisScale = useXScale(axisId);
|
|
67
|
+
const xPosition = xAxisScale(x);
|
|
68
|
+
if (xPosition === undefined) {
|
|
69
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
70
|
+
if (!warnedOnce) {
|
|
71
|
+
warnedOnce = true;
|
|
72
|
+
console.error(`MUI X: the value ${x} does not exist in the data of x axis with id ${axisId}.`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const d = `M ${xPosition} ${top} l 0 ${height}`;
|
|
78
|
+
const classes = getXReferenceLineClasses(inClasses);
|
|
79
|
+
const spacingX = typeof spacing === 'object' ? spacing.x ?? 0 : spacing;
|
|
80
|
+
const spacingY = typeof spacing === 'object' ? spacing.y ?? 0 : spacing;
|
|
81
|
+
const textParams = _extends({
|
|
82
|
+
x: xPosition + spacingX,
|
|
83
|
+
text: label,
|
|
84
|
+
fontSize: 12
|
|
85
|
+
}, getTextParams({
|
|
86
|
+
top,
|
|
87
|
+
height,
|
|
88
|
+
spacingY,
|
|
89
|
+
labelAlign
|
|
90
|
+
}), {
|
|
91
|
+
className: classes.label
|
|
92
|
+
});
|
|
93
|
+
return /*#__PURE__*/_jsxs(ReferenceLineRoot, {
|
|
94
|
+
className: classes.root,
|
|
95
|
+
children: [/*#__PURE__*/_jsx("path", {
|
|
96
|
+
d: d,
|
|
97
|
+
className: classes.line,
|
|
98
|
+
style: lineStyle
|
|
99
|
+
}), /*#__PURE__*/_jsx(ChartsText, _extends({}, textParams, {
|
|
100
|
+
style: _extends({}, textParams.style, labelStyle)
|
|
101
|
+
}))]
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
export { ChartsXReferenceLine };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import composeClasses from '@mui/utils/composeClasses';
|
|
4
|
+
import { useDrawingArea, useYScale } from '../hooks';
|
|
5
|
+
import { ReferenceLineRoot } from './common';
|
|
6
|
+
import { ChartsText } from '../internals/components/ChartsText';
|
|
7
|
+
import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
const getTextParams = ({
|
|
11
|
+
left,
|
|
12
|
+
width,
|
|
13
|
+
spacingX,
|
|
14
|
+
labelAlign = 'middle'
|
|
15
|
+
}) => {
|
|
16
|
+
switch (labelAlign) {
|
|
17
|
+
case 'start':
|
|
18
|
+
return {
|
|
19
|
+
x: left + spacingX,
|
|
20
|
+
style: {
|
|
21
|
+
dominantBaseline: 'auto',
|
|
22
|
+
textAnchor: 'start'
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
case 'end':
|
|
26
|
+
return {
|
|
27
|
+
x: left + width - spacingX,
|
|
28
|
+
style: {
|
|
29
|
+
dominantBaseline: 'auto',
|
|
30
|
+
textAnchor: 'end'
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
default:
|
|
34
|
+
return {
|
|
35
|
+
x: left + width / 2,
|
|
36
|
+
style: {
|
|
37
|
+
dominantBaseline: 'auto',
|
|
38
|
+
textAnchor: 'middle'
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
let warnedOnce = false;
|
|
44
|
+
export function getYReferenceLineClasses(classes) {
|
|
45
|
+
return composeClasses({
|
|
46
|
+
root: ['root', 'horizontal'],
|
|
47
|
+
line: ['line'],
|
|
48
|
+
label: ['label']
|
|
49
|
+
}, getReferenceLineUtilityClass, classes);
|
|
50
|
+
}
|
|
51
|
+
function ChartsYReferenceLine(props) {
|
|
52
|
+
const {
|
|
53
|
+
y,
|
|
54
|
+
label = '',
|
|
55
|
+
spacing = 5,
|
|
56
|
+
classes: inClasses,
|
|
57
|
+
labelAlign,
|
|
58
|
+
lineStyle,
|
|
59
|
+
labelStyle,
|
|
60
|
+
axisId
|
|
61
|
+
} = props;
|
|
62
|
+
const {
|
|
63
|
+
left,
|
|
64
|
+
width
|
|
65
|
+
} = useDrawingArea();
|
|
66
|
+
const yAxisScale = useYScale(axisId);
|
|
67
|
+
const yPosition = yAxisScale(y);
|
|
68
|
+
if (yPosition === undefined) {
|
|
69
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
70
|
+
if (!warnedOnce) {
|
|
71
|
+
warnedOnce = true;
|
|
72
|
+
console.error(`MUI X: the value ${y} does not exist in the data of y axis with id ${axisId}.`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const d = `M ${left} ${yPosition} l ${width} 0`;
|
|
78
|
+
const classes = getYReferenceLineClasses(inClasses);
|
|
79
|
+
const spacingX = typeof spacing === 'object' ? spacing.x ?? 0 : spacing;
|
|
80
|
+
const spacingY = typeof spacing === 'object' ? spacing.y ?? 0 : spacing;
|
|
81
|
+
const textParams = _extends({
|
|
82
|
+
y: yPosition - spacingY,
|
|
83
|
+
text: label,
|
|
84
|
+
fontSize: 12
|
|
85
|
+
}, getTextParams({
|
|
86
|
+
left,
|
|
87
|
+
width,
|
|
88
|
+
spacingX,
|
|
89
|
+
labelAlign
|
|
90
|
+
}), {
|
|
91
|
+
className: classes.label
|
|
92
|
+
});
|
|
93
|
+
return /*#__PURE__*/_jsxs(ReferenceLineRoot, {
|
|
94
|
+
className: classes.root,
|
|
95
|
+
children: [/*#__PURE__*/_jsx("path", {
|
|
96
|
+
d: d,
|
|
97
|
+
className: classes.line,
|
|
98
|
+
style: lineStyle
|
|
99
|
+
}), /*#__PURE__*/_jsx(ChartsText, _extends({}, textParams, {
|
|
100
|
+
style: _extends({}, textParams.style, labelStyle)
|
|
101
|
+
}))]
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
export { ChartsYReferenceLine };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
2
|
+
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
|
|
3
|
+
export function getReferenceLineUtilityClass(slot) {
|
|
4
|
+
return generateUtilityClass('MuiChartsReferenceLine', slot);
|
|
5
|
+
}
|
|
6
|
+
export const referenceLineClasses = generateUtilityClasses('MuiChartsReferenceLine', ['root', 'vertical', 'horizontal', 'line', 'label']);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { styled } from '@mui/material/styles';
|
|
3
|
+
import { referenceLineClasses } from './chartsReferenceLineClasses';
|
|
4
|
+
export const ReferenceLineRoot = styled('g')(({
|
|
5
|
+
theme
|
|
6
|
+
}) => ({
|
|
7
|
+
[`& .${referenceLineClasses.line}`]: {
|
|
8
|
+
fill: 'none',
|
|
9
|
+
stroke: (theme.vars || theme).palette.text.primary,
|
|
10
|
+
shapeRendering: 'crispEdges',
|
|
11
|
+
strokeWidth: 1,
|
|
12
|
+
pointerEvents: 'none'
|
|
13
|
+
},
|
|
14
|
+
[`& .${referenceLineClasses.label}`]: _extends({
|
|
15
|
+
fill: (theme.vars || theme).palette.text.primary,
|
|
16
|
+
stroke: 'none',
|
|
17
|
+
pointerEvents: 'none',
|
|
18
|
+
fontSize: 12
|
|
19
|
+
}, theme.typography.body1)
|
|
20
|
+
}));
|
|
@@ -106,17 +106,20 @@ function ChartsXAxis(inProps) {
|
|
|
106
106
|
props: _extends({}, defaultProps, inProps),
|
|
107
107
|
name: 'MuiChartsXAxis'
|
|
108
108
|
});
|
|
109
|
+
const {
|
|
110
|
+
xAxisIds
|
|
111
|
+
} = React.useContext(CartesianContext);
|
|
109
112
|
const _React$useContext = React.useContext(CartesianContext),
|
|
110
|
-
|
|
113
|
+
_ref = props.axisId ?? xAxisIds[0],
|
|
111
114
|
{
|
|
112
115
|
xAxis: {
|
|
113
|
-
[
|
|
116
|
+
[_ref]: {
|
|
114
117
|
scale: xScale,
|
|
115
118
|
tickNumber
|
|
116
119
|
}
|
|
117
120
|
}
|
|
118
121
|
} = _React$useContext,
|
|
119
|
-
settings = _objectWithoutPropertiesLoose(_React$useContext.xAxis[
|
|
122
|
+
settings = _objectWithoutPropertiesLoose(_React$useContext.xAxis[_ref], _excluded);
|
|
120
123
|
const isMounted = useMounted();
|
|
121
124
|
const defaultizedProps = _extends({}, defaultProps, settings, props);
|
|
122
125
|
const {
|
|
@@ -234,9 +237,10 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
|
|
|
234
237
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
235
238
|
// ----------------------------------------------------------------------
|
|
236
239
|
/**
|
|
237
|
-
*
|
|
240
|
+
* The id of the axis to render.
|
|
241
|
+
* If undefined, it will be the first defined axis.
|
|
238
242
|
*/
|
|
239
|
-
axisId: PropTypes.string
|
|
243
|
+
axisId: PropTypes.string,
|
|
240
244
|
/**
|
|
241
245
|
* Override or extend the styles applied to the component.
|
|
242
246
|
*/
|
|
@@ -52,17 +52,20 @@ function ChartsYAxis(inProps) {
|
|
|
52
52
|
props: _extends({}, defaultProps, inProps),
|
|
53
53
|
name: 'MuiChartsYAxis'
|
|
54
54
|
});
|
|
55
|
+
const {
|
|
56
|
+
yAxisIds
|
|
57
|
+
} = React.useContext(CartesianContext);
|
|
55
58
|
const _React$useContext = React.useContext(CartesianContext),
|
|
56
|
-
|
|
59
|
+
_ref = props.axisId ?? yAxisIds[0],
|
|
57
60
|
{
|
|
58
61
|
yAxis: {
|
|
59
|
-
[
|
|
62
|
+
[_ref]: {
|
|
60
63
|
scale: yScale,
|
|
61
64
|
tickNumber
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
} = _React$useContext,
|
|
65
|
-
settings = _objectWithoutPropertiesLoose(_React$useContext.yAxis[
|
|
68
|
+
settings = _objectWithoutPropertiesLoose(_React$useContext.yAxis[_ref], _excluded);
|
|
66
69
|
const defaultizedProps = _extends({}, defaultProps, settings, props);
|
|
67
70
|
const {
|
|
68
71
|
position,
|
|
@@ -167,9 +170,10 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
|
|
|
167
170
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
168
171
|
// ----------------------------------------------------------------------
|
|
169
172
|
/**
|
|
170
|
-
*
|
|
173
|
+
* The id of the axis to render.
|
|
174
|
+
* If undefined, it will be the first defined axis.
|
|
171
175
|
*/
|
|
172
|
-
axisId: PropTypes.string
|
|
176
|
+
axisId: PropTypes.string,
|
|
173
177
|
/**
|
|
174
178
|
* Override or extend the styles applied to the component.
|
|
175
179
|
*/
|
|
@@ -111,6 +111,13 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
111
111
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
112
112
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
113
113
|
// ----------------------------------------------------------------------
|
|
114
|
+
/**
|
|
115
|
+
* Object `{ x, y }` that defines how the charts highlight the mouse position along the x- and y-axes.
|
|
116
|
+
* The two properties accept the following values:
|
|
117
|
+
* - 'none': display nothing.
|
|
118
|
+
* - 'line': display a line at the current mouse position.
|
|
119
|
+
* - 'band': display a band at the current mouse position. Only available with band scale.
|
|
120
|
+
*/
|
|
114
121
|
axisHighlight: PropTypes.shape({
|
|
115
122
|
x: PropTypes.oneOf(['band', 'line', 'none']),
|
|
116
123
|
y: PropTypes.oneOf(['band', 'line', 'none'])
|
|
@@ -121,7 +128,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
121
128
|
* @default xAxisIds[0] The id of the first provided axis
|
|
122
129
|
*/
|
|
123
130
|
bottomAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
124
|
-
axisId: PropTypes.string
|
|
131
|
+
axisId: PropTypes.string,
|
|
125
132
|
classes: PropTypes.object,
|
|
126
133
|
disableLine: PropTypes.bool,
|
|
127
134
|
disableTicks: PropTypes.bool,
|
|
@@ -148,13 +155,25 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
148
155
|
* Color palette used to colorize multiple series.
|
|
149
156
|
*/
|
|
150
157
|
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
158
|
+
/**
|
|
159
|
+
* An array of objects that can be used to populate series and axes data using their `dataKey` property.
|
|
160
|
+
*/
|
|
151
161
|
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
152
162
|
desc: PropTypes.string,
|
|
163
|
+
/**
|
|
164
|
+
* If `true`, the charts will not listen to the mouse move event.
|
|
165
|
+
* It might break interactive features, but will improve performance.
|
|
166
|
+
* @default false
|
|
167
|
+
*/
|
|
153
168
|
disableAxisListener: PropTypes.bool,
|
|
154
169
|
/**
|
|
155
170
|
* If `true`, render the line highlight item.
|
|
156
171
|
*/
|
|
157
172
|
disableLineItemHighlight: PropTypes.bool,
|
|
173
|
+
/**
|
|
174
|
+
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
175
|
+
* @default undefined
|
|
176
|
+
*/
|
|
158
177
|
height: PropTypes.number,
|
|
159
178
|
/**
|
|
160
179
|
* Indicate which axis to display the left of the charts.
|
|
@@ -162,7 +181,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
162
181
|
* @default yAxisIds[0] The id of the first provided axis
|
|
163
182
|
*/
|
|
164
183
|
leftAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
165
|
-
axisId: PropTypes.string
|
|
184
|
+
axisId: PropTypes.string,
|
|
166
185
|
classes: PropTypes.object,
|
|
167
186
|
disableLine: PropTypes.bool,
|
|
168
187
|
disableTicks: PropTypes.bool,
|
|
@@ -197,6 +216,12 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
197
216
|
slotProps: PropTypes.object,
|
|
198
217
|
slots: PropTypes.object
|
|
199
218
|
}),
|
|
219
|
+
/**
|
|
220
|
+
* The margin between the SVG and the drawing area.
|
|
221
|
+
* It's used for leaving some space for extra information such as the x- and y-axis or legend.
|
|
222
|
+
* Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
|
|
223
|
+
* @default object Depends on the charts type.
|
|
224
|
+
*/
|
|
200
225
|
margin: PropTypes.shape({
|
|
201
226
|
bottom: PropTypes.number,
|
|
202
227
|
left: PropTypes.number,
|
|
@@ -209,7 +234,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
209
234
|
* @default null
|
|
210
235
|
*/
|
|
211
236
|
rightAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
212
|
-
axisId: PropTypes.string
|
|
237
|
+
axisId: PropTypes.string,
|
|
213
238
|
classes: PropTypes.object,
|
|
214
239
|
disableLine: PropTypes.bool,
|
|
215
240
|
disableTicks: PropTypes.bool,
|
|
@@ -279,7 +304,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
279
304
|
* @default null
|
|
280
305
|
*/
|
|
281
306
|
topAxis: PropTypes.oneOfType([PropTypes.shape({
|
|
282
|
-
axisId: PropTypes.string
|
|
307
|
+
axisId: PropTypes.string,
|
|
283
308
|
classes: PropTypes.object,
|
|
284
309
|
disableLine: PropTypes.bool,
|
|
285
310
|
disableTicks: PropTypes.bool,
|
|
@@ -306,7 +331,15 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
306
331
|
x: PropTypes.number,
|
|
307
332
|
y: PropTypes.number
|
|
308
333
|
}),
|
|
334
|
+
/**
|
|
335
|
+
* The width of the chart in px. If not defined, it takes the width of the parent element.
|
|
336
|
+
* @default undefined
|
|
337
|
+
*/
|
|
309
338
|
width: PropTypes.number,
|
|
339
|
+
/**
|
|
340
|
+
* The configuration of the x-axes.
|
|
341
|
+
* If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
|
|
342
|
+
*/
|
|
310
343
|
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
311
344
|
axisId: PropTypes.string,
|
|
312
345
|
classes: PropTypes.object,
|
|
@@ -337,6 +370,10 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
337
370
|
tickSize: PropTypes.number,
|
|
338
371
|
valueFormatter: PropTypes.func
|
|
339
372
|
})),
|
|
373
|
+
/**
|
|
374
|
+
* The configuration of the y-axes.
|
|
375
|
+
* If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
|
|
376
|
+
*/
|
|
340
377
|
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
341
378
|
axisId: PropTypes.string,
|
|
342
379
|
classes: PropTypes.object,
|