@mui/x-charts 6.0.0-alpha.8 → 6.0.0-alpha.9
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/CHANGELOG.md +59 -1
- package/LineChart/AreaElement.d.ts +1 -1
- package/LineChart/LineChart.d.ts +7 -2
- package/LineChart/LineChart.js +14 -2
- package/LineChart/LineElement.d.ts +1 -1
- package/LineChart/LineHighlightElement.d.ts +21 -0
- package/LineChart/LineHighlightElement.js +79 -0
- package/LineChart/LineHighlightPlot.d.ts +25 -0
- package/LineChart/LineHighlightPlot.js +99 -0
- package/LineChart/MarkElement.d.ts +1 -1
- package/LineChart/MarkElement.js +1 -4
- package/LineChart/MarkPlot.js +27 -11
- package/LineChart/index.d.ts +2 -0
- package/LineChart/index.js +20 -0
- package/PieChart/PieArc.d.ts +1 -1
- package/PieChart/PieArcLabel.d.ts +1 -1
- package/SparkLineChart/SparkLineChart.d.ts +3 -2
- package/SparkLineChart/SparkLineChart.js +6 -11
- package/esm/LineChart/LineChart.js +14 -2
- package/esm/LineChart/LineHighlightElement.js +68 -0
- package/esm/LineChart/LineHighlightPlot.js +92 -0
- package/esm/LineChart/MarkElement.js +1 -4
- package/esm/LineChart/MarkPlot.js +27 -11
- package/esm/LineChart/index.js +3 -1
- package/esm/SparkLineChart/SparkLineChart.js +7 -12
- package/index.js +1 -1
- package/internals/defaultizeColor.d.ts +2 -0
- package/legacy/LineChart/LineChart.js +14 -2
- package/legacy/LineChart/LineHighlightElement.js +67 -0
- package/legacy/LineChart/LineHighlightPlot.js +85 -0
- package/legacy/LineChart/MarkElement.js +1 -4
- package/legacy/LineChart/MarkPlot.js +19 -4
- package/legacy/LineChart/index.js +3 -1
- package/legacy/SparkLineChart/SparkLineChart.js +7 -10
- package/legacy/index.js +1 -1
- package/models/seriesType/line.d.ts +33 -0
- package/modern/LineChart/LineChart.js +14 -2
- package/modern/LineChart/LineHighlightElement.js +68 -0
- package/modern/LineChart/LineHighlightPlot.js +91 -0
- package/modern/LineChart/MarkElement.js +1 -4
- package/modern/LineChart/MarkPlot.js +27 -11
- package/modern/LineChart/index.js +3 -1
- package/modern/SparkLineChart/SparkLineChart.js +7 -12
- package/modern/index.js +1 -1
- package/package.json +1 -1
|
@@ -12,6 +12,7 @@ import { ChartsTooltip } from '../ChartsTooltip';
|
|
|
12
12
|
import { ChartsLegend } from '../ChartsLegend';
|
|
13
13
|
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
14
14
|
import { ChartsClipPath } from '../ChartsClipPath';
|
|
15
|
+
import { LineHighlightPlot } from './LineHighlightPlot';
|
|
15
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
17
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
18
|
const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
@@ -29,6 +30,7 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
29
30
|
axisHighlight = {
|
|
30
31
|
x: 'line'
|
|
31
32
|
},
|
|
33
|
+
disableLineItemHighlight,
|
|
32
34
|
legend,
|
|
33
35
|
topAxis,
|
|
34
36
|
leftAxis,
|
|
@@ -43,6 +45,7 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
43
45
|
return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
|
|
44
46
|
ref: ref,
|
|
45
47
|
series: series.map(s => _extends({
|
|
48
|
+
disableHighlight: !!disableLineItemHighlight,
|
|
46
49
|
type: 'line'
|
|
47
50
|
}, s)),
|
|
48
51
|
width: width,
|
|
@@ -79,13 +82,16 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
79
82
|
bottomAxis: bottomAxis,
|
|
80
83
|
slots: slots,
|
|
81
84
|
slotProps: slotProps
|
|
82
|
-
}), /*#__PURE__*/_jsx(MarkPlot, {
|
|
85
|
+
}), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), /*#__PURE__*/_jsx(MarkPlot, {
|
|
86
|
+
slots: slots,
|
|
87
|
+
slotProps: slotProps
|
|
88
|
+
}), /*#__PURE__*/_jsx(LineHighlightPlot, {
|
|
83
89
|
slots: slots,
|
|
84
90
|
slotProps: slotProps
|
|
85
91
|
}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
|
|
86
92
|
slots: slots,
|
|
87
93
|
slotProps: slotProps
|
|
88
|
-
})), /*#__PURE__*/_jsx(
|
|
94
|
+
})), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), /*#__PURE__*/_jsx(ChartsClipPath, {
|
|
89
95
|
id: clipPathId
|
|
90
96
|
}), children]
|
|
91
97
|
});
|
|
@@ -131,6 +137,10 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
131
137
|
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
132
138
|
desc: PropTypes.string,
|
|
133
139
|
disableAxisListener: PropTypes.bool,
|
|
140
|
+
/**
|
|
141
|
+
* If `true`, render the line highlight item.
|
|
142
|
+
*/
|
|
143
|
+
disableLineItemHighlight: PropTypes.bool,
|
|
134
144
|
height: PropTypes.number,
|
|
135
145
|
/**
|
|
136
146
|
* Indicate which axis to display the left of the charts.
|
|
@@ -208,12 +218,14 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
208
218
|
curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
|
|
209
219
|
data: PropTypes.arrayOf(PropTypes.number),
|
|
210
220
|
dataKey: PropTypes.string,
|
|
221
|
+
disableHighlight: PropTypes.bool,
|
|
211
222
|
highlightScope: PropTypes.shape({
|
|
212
223
|
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
213
224
|
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
214
225
|
}),
|
|
215
226
|
id: PropTypes.string,
|
|
216
227
|
label: PropTypes.string,
|
|
228
|
+
showMark: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
|
|
217
229
|
stack: PropTypes.string,
|
|
218
230
|
stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
|
|
219
231
|
stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["x", "y", "id", "classes", "color"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import composeClasses from '@mui/utils/composeClasses';
|
|
7
|
+
import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
8
|
+
import { styled } from '@mui/material/styles';
|
|
9
|
+
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
export function getHighlightElementUtilityClass(slot) {
|
|
12
|
+
return generateUtilityClass('MuiHighlightElement', slot);
|
|
13
|
+
}
|
|
14
|
+
export const lineHighlightElementClasses = generateUtilityClasses('MuiHighlightElement', ['root']);
|
|
15
|
+
const useUtilityClasses = ownerState => {
|
|
16
|
+
const {
|
|
17
|
+
classes,
|
|
18
|
+
id
|
|
19
|
+
} = ownerState;
|
|
20
|
+
const slots = {
|
|
21
|
+
root: ['root', `series-${id}`]
|
|
22
|
+
};
|
|
23
|
+
return composeClasses(slots, getHighlightElementUtilityClass, classes);
|
|
24
|
+
};
|
|
25
|
+
const HighlightElement = styled('circle', {
|
|
26
|
+
name: 'MuiHighlightElement',
|
|
27
|
+
slot: 'Root',
|
|
28
|
+
overridesResolver: (_, styles) => styles.root
|
|
29
|
+
})(({
|
|
30
|
+
ownerState
|
|
31
|
+
}) => ({
|
|
32
|
+
transform: `translate(${ownerState.x}px, ${ownerState.y}px)`,
|
|
33
|
+
transformOrigin: `${ownerState.x}px ${ownerState.y}px`,
|
|
34
|
+
fill: ownerState.color
|
|
35
|
+
}));
|
|
36
|
+
function LineHighlightElement(props) {
|
|
37
|
+
const {
|
|
38
|
+
x,
|
|
39
|
+
y,
|
|
40
|
+
id,
|
|
41
|
+
classes: innerClasses,
|
|
42
|
+
color
|
|
43
|
+
} = props,
|
|
44
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
45
|
+
const ownerState = {
|
|
46
|
+
id,
|
|
47
|
+
classes: innerClasses,
|
|
48
|
+
color,
|
|
49
|
+
x,
|
|
50
|
+
y
|
|
51
|
+
};
|
|
52
|
+
const classes = useUtilityClasses(ownerState);
|
|
53
|
+
return /*#__PURE__*/_jsx(HighlightElement, _extends({}, other, {
|
|
54
|
+
ownerState: ownerState,
|
|
55
|
+
className: classes.root,
|
|
56
|
+
cx: 0,
|
|
57
|
+
cy: 0,
|
|
58
|
+
r: other.r === undefined ? 5 : other.r
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
process.env.NODE_ENV !== "production" ? LineHighlightElement.propTypes = {
|
|
62
|
+
// ----------------------------- Warning --------------------------------
|
|
63
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
64
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
65
|
+
// ----------------------------------------------------------------------
|
|
66
|
+
classes: PropTypes.object
|
|
67
|
+
} : void 0;
|
|
68
|
+
export { LineHighlightElement };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["slots", "slotProps"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
7
|
+
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
8
|
+
import { LineHighlightElement } from './LineHighlightElement';
|
|
9
|
+
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
10
|
+
import { InteractionContext } from '../context/InteractionProvider';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
function LineHighlightPlot(props) {
|
|
13
|
+
var _axis$x, _slots$lineHighlight;
|
|
14
|
+
const {
|
|
15
|
+
slots,
|
|
16
|
+
slotProps
|
|
17
|
+
} = props,
|
|
18
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
19
|
+
const seriesData = React.useContext(SeriesContext).line;
|
|
20
|
+
const axisData = React.useContext(CartesianContext);
|
|
21
|
+
const {
|
|
22
|
+
axis
|
|
23
|
+
} = React.useContext(InteractionContext);
|
|
24
|
+
const highlightedIndex = (_axis$x = axis.x) == null ? void 0 : _axis$x.index;
|
|
25
|
+
if (highlightedIndex === undefined) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
if (seriesData === undefined) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const {
|
|
32
|
+
series,
|
|
33
|
+
stackingGroups
|
|
34
|
+
} = seriesData;
|
|
35
|
+
const {
|
|
36
|
+
xAxis,
|
|
37
|
+
yAxis,
|
|
38
|
+
xAxisIds,
|
|
39
|
+
yAxisIds
|
|
40
|
+
} = axisData;
|
|
41
|
+
const defaultXAxisId = xAxisIds[0];
|
|
42
|
+
const defaultYAxisId = yAxisIds[0];
|
|
43
|
+
const Element = (_slots$lineHighlight = slots == null ? void 0 : slots.lineHighlight) != null ? _slots$lineHighlight : LineHighlightElement;
|
|
44
|
+
return /*#__PURE__*/_jsx("g", _extends({}, other, {
|
|
45
|
+
children: stackingGroups.flatMap(({
|
|
46
|
+
ids: groupIds
|
|
47
|
+
}) => {
|
|
48
|
+
return groupIds.flatMap(seriesId => {
|
|
49
|
+
const {
|
|
50
|
+
xAxisKey = defaultXAxisId,
|
|
51
|
+
yAxisKey = defaultYAxisId,
|
|
52
|
+
stackedData,
|
|
53
|
+
disableHighlight
|
|
54
|
+
} = series[seriesId];
|
|
55
|
+
if (disableHighlight) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
|
|
59
|
+
const yScale = yAxis[yAxisKey].scale;
|
|
60
|
+
const xData = xAxis[xAxisKey].data;
|
|
61
|
+
if (xData === undefined) {
|
|
62
|
+
throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot.`);
|
|
63
|
+
}
|
|
64
|
+
const x = xScale(xData[highlightedIndex]);
|
|
65
|
+
const y = yScale(stackedData[highlightedIndex][1]);
|
|
66
|
+
return /*#__PURE__*/_jsx(Element, _extends({
|
|
67
|
+
id: seriesId,
|
|
68
|
+
color: series[seriesId].color,
|
|
69
|
+
x: x,
|
|
70
|
+
y: y
|
|
71
|
+
}, slotProps == null ? void 0 : slotProps.lineHighlight), `${seriesId}`);
|
|
72
|
+
});
|
|
73
|
+
})
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
process.env.NODE_ENV !== "production" ? LineHighlightPlot.propTypes = {
|
|
77
|
+
// ----------------------------- Warning --------------------------------
|
|
78
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
79
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
80
|
+
// ----------------------------------------------------------------------
|
|
81
|
+
/**
|
|
82
|
+
* The props used for each component slot.
|
|
83
|
+
* @default {}
|
|
84
|
+
*/
|
|
85
|
+
slotProps: PropTypes.object,
|
|
86
|
+
/**
|
|
87
|
+
* Overridable component slots.
|
|
88
|
+
* @default {}
|
|
89
|
+
*/
|
|
90
|
+
slots: PropTypes.object
|
|
91
|
+
} : void 0;
|
|
92
|
+
export { LineHighlightPlot };
|
|
@@ -40,10 +40,7 @@ const MarkElementPath = styled('path', {
|
|
|
40
40
|
transformOrigin: `${ownerState.x}px ${ownerState.y}px`,
|
|
41
41
|
fill: theme.palette.background.paper,
|
|
42
42
|
stroke: ownerState.color,
|
|
43
|
-
strokeWidth: 2
|
|
44
|
-
'&.MuiMarkElement-highlighted': {
|
|
45
|
-
fill: ownerState.color
|
|
46
|
-
}
|
|
43
|
+
strokeWidth: 2
|
|
47
44
|
}));
|
|
48
45
|
MarkElementPath.propTypes = {
|
|
49
46
|
// ----------------------------- Warning --------------------------------
|
|
@@ -41,8 +41,12 @@ function MarkPlot(props) {
|
|
|
41
41
|
const {
|
|
42
42
|
xAxisKey = defaultXAxisId,
|
|
43
43
|
yAxisKey = defaultYAxisId,
|
|
44
|
-
stackedData
|
|
44
|
+
stackedData,
|
|
45
|
+
showMark = true
|
|
45
46
|
} = series[seriesId];
|
|
47
|
+
if (showMark === false) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
46
50
|
const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
|
|
47
51
|
const yScale = yAxis[yAxisKey].scale;
|
|
48
52
|
const xData = xAxis[xAxisKey].data;
|
|
@@ -68,21 +72,33 @@ function MarkPlot(props) {
|
|
|
68
72
|
return {
|
|
69
73
|
x: xScale(x),
|
|
70
74
|
y: yScale(y),
|
|
75
|
+
position: x,
|
|
76
|
+
value: y,
|
|
71
77
|
index
|
|
72
78
|
};
|
|
73
79
|
}).filter(isInRange).map(({
|
|
74
80
|
x,
|
|
75
81
|
y,
|
|
76
|
-
index
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
index,
|
|
83
|
+
position,
|
|
84
|
+
value
|
|
85
|
+
}) => {
|
|
86
|
+
return showMark === true || showMark({
|
|
87
|
+
x,
|
|
88
|
+
y,
|
|
89
|
+
index,
|
|
90
|
+
position,
|
|
91
|
+
value
|
|
92
|
+
}) ? /*#__PURE__*/_jsx(Mark, _extends({
|
|
93
|
+
id: seriesId,
|
|
94
|
+
dataIndex: index,
|
|
95
|
+
shape: "circle",
|
|
96
|
+
color: series[seriesId].color,
|
|
97
|
+
x: x,
|
|
98
|
+
y: y,
|
|
99
|
+
highlightScope: series[seriesId].highlightScope
|
|
100
|
+
}, slotProps == null ? void 0 : slotProps.mark), `${seriesId}-${index}`) : null;
|
|
101
|
+
});
|
|
86
102
|
});
|
|
87
103
|
})
|
|
88
104
|
}));
|
package/esm/LineChart/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export { LinePlot } from './LinePlot';
|
|
2
2
|
export { AreaPlot } from './AreaPlot';
|
|
3
3
|
export { MarkPlot } from './MarkPlot';
|
|
4
|
+
export { LineHighlightPlot } from './LineHighlightPlot';
|
|
4
5
|
export { LineChart } from './LineChart';
|
|
5
6
|
export * from './AreaElement';
|
|
6
7
|
export * from './LineElement';
|
|
7
|
-
export * from './MarkElement';
|
|
8
|
+
export * from './MarkElement';
|
|
9
|
+
export * from './LineHighlightElement';
|
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
-
import { styled } from '@mui/material/styles';
|
|
5
4
|
import { BarPlot } from '../BarChart';
|
|
6
|
-
import { LinePlot,
|
|
5
|
+
import { LinePlot, AreaPlot, LineHighlightPlot } from '../LineChart';
|
|
7
6
|
import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
|
|
8
7
|
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
9
8
|
import { ChartsTooltip } from '../ChartsTooltip';
|
|
10
9
|
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
11
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
11
|
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
12
|
const SPARKLINE_DEFAULT_MARGIN = {
|
|
22
13
|
top: 5,
|
|
23
14
|
bottom: 5,
|
|
@@ -59,7 +50,8 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
|
|
|
59
50
|
valueFormatter
|
|
60
51
|
}, plotType === 'bar' ? {} : {
|
|
61
52
|
area,
|
|
62
|
-
curve
|
|
53
|
+
curve,
|
|
54
|
+
disableHighlight: !showHighlight
|
|
63
55
|
})],
|
|
64
56
|
width: width,
|
|
65
57
|
height: height,
|
|
@@ -85,7 +77,10 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
|
|
|
85
77
|
}), /*#__PURE__*/_jsx(LinePlot, {
|
|
86
78
|
slots: slots,
|
|
87
79
|
slotProps: slotProps
|
|
88
|
-
}),
|
|
80
|
+
}), /*#__PURE__*/_jsx(LineHighlightPlot, {
|
|
81
|
+
slots: slots,
|
|
82
|
+
slotProps: slotProps
|
|
83
|
+
})]
|
|
89
84
|
}), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), showTooltip && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), children]
|
|
90
85
|
});
|
|
91
86
|
});
|
package/index.js
CHANGED
|
@@ -57,6 +57,8 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
57
57
|
area?: boolean | undefined;
|
|
58
58
|
label?: string | undefined;
|
|
59
59
|
curve?: import("../models/seriesType").CurveType | undefined;
|
|
60
|
+
showMark?: boolean | ((params: import("../models/seriesType").ShowMarkParams) => boolean) | undefined;
|
|
61
|
+
disableHighlight?: boolean | undefined;
|
|
60
62
|
id?: string | undefined;
|
|
61
63
|
color: string;
|
|
62
64
|
valueFormatter?: ((value: number) => string) | undefined;
|
|
@@ -13,6 +13,7 @@ import { ChartsTooltip } from '../ChartsTooltip';
|
|
|
13
13
|
import { ChartsLegend } from '../ChartsLegend';
|
|
14
14
|
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
15
15
|
import { ChartsClipPath } from '../ChartsClipPath';
|
|
16
|
+
import { LineHighlightPlot } from './LineHighlightPlot';
|
|
16
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
18
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
19
|
var LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
@@ -30,6 +31,7 @@ var LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
30
31
|
axisHighlight = _props$axisHighlight === void 0 ? {
|
|
31
32
|
x: 'line'
|
|
32
33
|
} : _props$axisHighlight,
|
|
34
|
+
disableLineItemHighlight = props.disableLineItemHighlight,
|
|
33
35
|
legend = props.legend,
|
|
34
36
|
topAxis = props.topAxis,
|
|
35
37
|
leftAxis = props.leftAxis,
|
|
@@ -44,6 +46,7 @@ var LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
44
46
|
ref: ref,
|
|
45
47
|
series: series.map(function (s) {
|
|
46
48
|
return _extends({
|
|
49
|
+
disableHighlight: !!disableLineItemHighlight,
|
|
47
50
|
type: 'line'
|
|
48
51
|
}, s);
|
|
49
52
|
}),
|
|
@@ -83,13 +86,16 @@ var LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
83
86
|
bottomAxis: bottomAxis,
|
|
84
87
|
slots: slots,
|
|
85
88
|
slotProps: slotProps
|
|
86
|
-
}), /*#__PURE__*/_jsx(MarkPlot, {
|
|
89
|
+
}), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), /*#__PURE__*/_jsx(MarkPlot, {
|
|
90
|
+
slots: slots,
|
|
91
|
+
slotProps: slotProps
|
|
92
|
+
}), /*#__PURE__*/_jsx(LineHighlightPlot, {
|
|
87
93
|
slots: slots,
|
|
88
94
|
slotProps: slotProps
|
|
89
95
|
}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
|
|
90
96
|
slots: slots,
|
|
91
97
|
slotProps: slotProps
|
|
92
|
-
})), /*#__PURE__*/_jsx(
|
|
98
|
+
})), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), /*#__PURE__*/_jsx(ChartsClipPath, {
|
|
93
99
|
id: clipPathId
|
|
94
100
|
}), children]
|
|
95
101
|
});
|
|
@@ -135,6 +141,10 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
135
141
|
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
136
142
|
desc: PropTypes.string,
|
|
137
143
|
disableAxisListener: PropTypes.bool,
|
|
144
|
+
/**
|
|
145
|
+
* If `true`, render the line highlight item.
|
|
146
|
+
*/
|
|
147
|
+
disableLineItemHighlight: PropTypes.bool,
|
|
138
148
|
height: PropTypes.number,
|
|
139
149
|
/**
|
|
140
150
|
* Indicate which axis to display the left of the charts.
|
|
@@ -212,12 +222,14 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
212
222
|
curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
|
|
213
223
|
data: PropTypes.arrayOf(PropTypes.number),
|
|
214
224
|
dataKey: PropTypes.string,
|
|
225
|
+
disableHighlight: PropTypes.bool,
|
|
215
226
|
highlightScope: PropTypes.shape({
|
|
216
227
|
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
217
228
|
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
218
229
|
}),
|
|
219
230
|
id: PropTypes.string,
|
|
220
231
|
label: PropTypes.string,
|
|
232
|
+
showMark: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
|
|
221
233
|
stack: PropTypes.string,
|
|
222
234
|
stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
|
|
223
235
|
stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["x", "y", "id", "classes", "color"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import composeClasses from '@mui/utils/composeClasses';
|
|
7
|
+
import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
8
|
+
import { styled } from '@mui/material/styles';
|
|
9
|
+
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
export function getHighlightElementUtilityClass(slot) {
|
|
12
|
+
return generateUtilityClass('MuiHighlightElement', slot);
|
|
13
|
+
}
|
|
14
|
+
export var lineHighlightElementClasses = generateUtilityClasses('MuiHighlightElement', ['root']);
|
|
15
|
+
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
16
|
+
var classes = ownerState.classes,
|
|
17
|
+
id = ownerState.id;
|
|
18
|
+
var slots = {
|
|
19
|
+
root: ['root', "series-".concat(id)]
|
|
20
|
+
};
|
|
21
|
+
return composeClasses(slots, getHighlightElementUtilityClass, classes);
|
|
22
|
+
};
|
|
23
|
+
var HighlightElement = styled('circle', {
|
|
24
|
+
name: 'MuiHighlightElement',
|
|
25
|
+
slot: 'Root',
|
|
26
|
+
overridesResolver: function overridesResolver(_, styles) {
|
|
27
|
+
return styles.root;
|
|
28
|
+
}
|
|
29
|
+
})(function (_ref) {
|
|
30
|
+
var ownerState = _ref.ownerState;
|
|
31
|
+
return {
|
|
32
|
+
transform: "translate(".concat(ownerState.x, "px, ").concat(ownerState.y, "px)"),
|
|
33
|
+
transformOrigin: "".concat(ownerState.x, "px ").concat(ownerState.y, "px"),
|
|
34
|
+
fill: ownerState.color
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
function LineHighlightElement(props) {
|
|
38
|
+
var x = props.x,
|
|
39
|
+
y = props.y,
|
|
40
|
+
id = props.id,
|
|
41
|
+
innerClasses = props.classes,
|
|
42
|
+
color = props.color,
|
|
43
|
+
other = _objectWithoutProperties(props, _excluded);
|
|
44
|
+
var ownerState = {
|
|
45
|
+
id: id,
|
|
46
|
+
classes: innerClasses,
|
|
47
|
+
color: color,
|
|
48
|
+
x: x,
|
|
49
|
+
y: y
|
|
50
|
+
};
|
|
51
|
+
var classes = useUtilityClasses(ownerState);
|
|
52
|
+
return /*#__PURE__*/_jsx(HighlightElement, _extends({}, other, {
|
|
53
|
+
ownerState: ownerState,
|
|
54
|
+
className: classes.root,
|
|
55
|
+
cx: 0,
|
|
56
|
+
cy: 0,
|
|
57
|
+
r: other.r === undefined ? 5 : other.r
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
process.env.NODE_ENV !== "production" ? LineHighlightElement.propTypes = {
|
|
61
|
+
// ----------------------------- Warning --------------------------------
|
|
62
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
63
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
64
|
+
// ----------------------------------------------------------------------
|
|
65
|
+
classes: PropTypes.object
|
|
66
|
+
} : void 0;
|
|
67
|
+
export { LineHighlightElement };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["slots", "slotProps"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
7
|
+
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
8
|
+
import { LineHighlightElement } from './LineHighlightElement';
|
|
9
|
+
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
10
|
+
import { InteractionContext } from '../context/InteractionProvider';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
function LineHighlightPlot(props) {
|
|
13
|
+
var _axis$x, _slots$lineHighlight;
|
|
14
|
+
var slots = props.slots,
|
|
15
|
+
slotProps = props.slotProps,
|
|
16
|
+
other = _objectWithoutProperties(props, _excluded);
|
|
17
|
+
var seriesData = React.useContext(SeriesContext).line;
|
|
18
|
+
var axisData = React.useContext(CartesianContext);
|
|
19
|
+
var _React$useContext = React.useContext(InteractionContext),
|
|
20
|
+
axis = _React$useContext.axis;
|
|
21
|
+
var highlightedIndex = (_axis$x = axis.x) == null ? void 0 : _axis$x.index;
|
|
22
|
+
if (highlightedIndex === undefined) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (seriesData === undefined) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
var series = seriesData.series,
|
|
29
|
+
stackingGroups = seriesData.stackingGroups;
|
|
30
|
+
var xAxis = axisData.xAxis,
|
|
31
|
+
yAxis = axisData.yAxis,
|
|
32
|
+
xAxisIds = axisData.xAxisIds,
|
|
33
|
+
yAxisIds = axisData.yAxisIds;
|
|
34
|
+
var defaultXAxisId = xAxisIds[0];
|
|
35
|
+
var defaultYAxisId = yAxisIds[0];
|
|
36
|
+
var Element = (_slots$lineHighlight = slots == null ? void 0 : slots.lineHighlight) != null ? _slots$lineHighlight : LineHighlightElement;
|
|
37
|
+
return /*#__PURE__*/_jsx("g", _extends({}, other, {
|
|
38
|
+
children: stackingGroups.flatMap(function (_ref) {
|
|
39
|
+
var groupIds = _ref.ids;
|
|
40
|
+
return groupIds.flatMap(function (seriesId) {
|
|
41
|
+
var _series$seriesId = series[seriesId],
|
|
42
|
+
_series$seriesId$xAxi = _series$seriesId.xAxisKey,
|
|
43
|
+
xAxisKey = _series$seriesId$xAxi === void 0 ? defaultXAxisId : _series$seriesId$xAxi,
|
|
44
|
+
_series$seriesId$yAxi = _series$seriesId.yAxisKey,
|
|
45
|
+
yAxisKey = _series$seriesId$yAxi === void 0 ? defaultYAxisId : _series$seriesId$yAxi,
|
|
46
|
+
stackedData = _series$seriesId.stackedData,
|
|
47
|
+
disableHighlight = _series$seriesId.disableHighlight;
|
|
48
|
+
if (disableHighlight) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
var xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
|
|
52
|
+
var yScale = yAxis[yAxisKey].scale;
|
|
53
|
+
var xData = xAxis[xAxisKey].data;
|
|
54
|
+
if (xData === undefined) {
|
|
55
|
+
throw new Error("Axis of id \"".concat(xAxisKey, "\" should have data property to be able to display a line plot."));
|
|
56
|
+
}
|
|
57
|
+
var x = xScale(xData[highlightedIndex]);
|
|
58
|
+
var y = yScale(stackedData[highlightedIndex][1]);
|
|
59
|
+
return /*#__PURE__*/_jsx(Element, _extends({
|
|
60
|
+
id: seriesId,
|
|
61
|
+
color: series[seriesId].color,
|
|
62
|
+
x: x,
|
|
63
|
+
y: y
|
|
64
|
+
}, slotProps == null ? void 0 : slotProps.lineHighlight), "".concat(seriesId));
|
|
65
|
+
});
|
|
66
|
+
})
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
process.env.NODE_ENV !== "production" ? LineHighlightPlot.propTypes = {
|
|
70
|
+
// ----------------------------- Warning --------------------------------
|
|
71
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
72
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
73
|
+
// ----------------------------------------------------------------------
|
|
74
|
+
/**
|
|
75
|
+
* The props used for each component slot.
|
|
76
|
+
* @default {}
|
|
77
|
+
*/
|
|
78
|
+
slotProps: PropTypes.object,
|
|
79
|
+
/**
|
|
80
|
+
* Overridable component slots.
|
|
81
|
+
* @default {}
|
|
82
|
+
*/
|
|
83
|
+
slots: PropTypes.object
|
|
84
|
+
} : void 0;
|
|
85
|
+
export { LineHighlightPlot };
|
|
@@ -40,10 +40,7 @@ var MarkElementPath = styled('path', {
|
|
|
40
40
|
transformOrigin: "".concat(ownerState.x, "px ").concat(ownerState.y, "px"),
|
|
41
41
|
fill: theme.palette.background.paper,
|
|
42
42
|
stroke: ownerState.color,
|
|
43
|
-
strokeWidth: 2
|
|
44
|
-
'&.MuiMarkElement-highlighted': {
|
|
45
|
-
fill: ownerState.color
|
|
46
|
-
}
|
|
43
|
+
strokeWidth: 2
|
|
47
44
|
};
|
|
48
45
|
});
|
|
49
46
|
MarkElementPath.propTypes = {
|
|
@@ -37,7 +37,12 @@ function MarkPlot(props) {
|
|
|
37
37
|
xAxisKey = _series$seriesId$xAxi === void 0 ? defaultXAxisId : _series$seriesId$xAxi,
|
|
38
38
|
_series$seriesId$yAxi = _series$seriesId.yAxisKey,
|
|
39
39
|
yAxisKey = _series$seriesId$yAxi === void 0 ? defaultYAxisId : _series$seriesId$yAxi,
|
|
40
|
-
stackedData = _series$seriesId.stackedData
|
|
40
|
+
stackedData = _series$seriesId.stackedData,
|
|
41
|
+
_series$seriesId$show = _series$seriesId.showMark,
|
|
42
|
+
showMark = _series$seriesId$show === void 0 ? true : _series$seriesId$show;
|
|
43
|
+
if (showMark === false) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
41
46
|
var xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
|
|
42
47
|
var yScale = yAxis[yAxisKey].scale;
|
|
43
48
|
var xData = xAxis[xAxisKey].data;
|
|
@@ -62,13 +67,23 @@ function MarkPlot(props) {
|
|
|
62
67
|
return {
|
|
63
68
|
x: xScale(x),
|
|
64
69
|
y: yScale(y),
|
|
70
|
+
position: x,
|
|
71
|
+
value: y,
|
|
65
72
|
index: index
|
|
66
73
|
};
|
|
67
74
|
}).filter(isInRange).map(function (_ref3) {
|
|
68
75
|
var x = _ref3.x,
|
|
69
76
|
y = _ref3.y,
|
|
70
|
-
index = _ref3.index
|
|
71
|
-
|
|
77
|
+
index = _ref3.index,
|
|
78
|
+
position = _ref3.position,
|
|
79
|
+
value = _ref3.value;
|
|
80
|
+
return showMark === true || showMark({
|
|
81
|
+
x: x,
|
|
82
|
+
y: y,
|
|
83
|
+
index: index,
|
|
84
|
+
position: position,
|
|
85
|
+
value: value
|
|
86
|
+
}) ? /*#__PURE__*/_jsx(Mark, _extends({
|
|
72
87
|
id: seriesId,
|
|
73
88
|
dataIndex: index,
|
|
74
89
|
shape: "circle",
|
|
@@ -76,7 +91,7 @@ function MarkPlot(props) {
|
|
|
76
91
|
x: x,
|
|
77
92
|
y: y,
|
|
78
93
|
highlightScope: series[seriesId].highlightScope
|
|
79
|
-
}, slotProps == null ? void 0 : slotProps.mark), "".concat(seriesId, "-").concat(index));
|
|
94
|
+
}, slotProps == null ? void 0 : slotProps.mark), "".concat(seriesId, "-").concat(index)) : null;
|
|
80
95
|
});
|
|
81
96
|
});
|
|
82
97
|
})
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export { LinePlot } from './LinePlot';
|
|
2
2
|
export { AreaPlot } from './AreaPlot';
|
|
3
3
|
export { MarkPlot } from './MarkPlot';
|
|
4
|
+
export { LineHighlightPlot } from './LineHighlightPlot';
|
|
4
5
|
export { LineChart } from './LineChart';
|
|
5
6
|
export * from './AreaElement';
|
|
6
7
|
export * from './LineElement';
|
|
7
|
-
export * from './MarkElement';
|
|
8
|
+
export * from './MarkElement';
|
|
9
|
+
export * from './LineHighlightElement';
|