@mui/x-charts 6.0.0-alpha.7 → 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/BarChart/BarChart.d.ts +1 -0
- package/BarChart/BarChart.js +26 -13
- package/BarChart/BarPlot.js +25 -15
- package/BarChart/extremums.js +19 -3
- package/BarChart/formatter.js +3 -1
- package/CHANGELOG.md +212 -31
- package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +3 -2
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
- package/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
- package/LineChart/AreaElement.d.ts +1 -1
- package/LineChart/LineChart.d.ts +7 -2
- package/LineChart/LineChart.js +15 -3
- 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 +34 -15
- 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/PieChart/PieChart.js +1 -1
- package/ScatterChart/ScatterChart.js +1 -1
- package/SparkLineChart/SparkLineChart.d.ts +3 -2
- package/SparkLineChart/SparkLineChart.js +7 -12
- package/context/CartesianContextProvider.js +4 -4
- package/esm/BarChart/BarChart.js +30 -17
- package/esm/BarChart/BarPlot.js +26 -16
- package/esm/BarChart/extremums.js +18 -2
- package/esm/BarChart/formatter.js +3 -1
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
- package/esm/LineChart/LineChart.js +15 -3
- 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 +34 -15
- package/esm/LineChart/index.js +3 -1
- package/esm/PieChart/PieChart.js +1 -1
- package/esm/ScatterChart/ScatterChart.js +1 -1
- package/esm/SparkLineChart/SparkLineChart.js +8 -13
- package/esm/context/CartesianContextProvider.js +4 -4
- package/esm/hooks/useAxisEvents.js +21 -38
- package/esm/hooks/useTicks.js +2 -2
- package/hooks/useAxisEvents.js +21 -38
- package/hooks/useTicks.js +2 -2
- package/index.js +1 -1
- package/internals/defaultizeColor.d.ts +3 -0
- package/legacy/BarChart/BarChart.js +35 -20
- package/legacy/BarChart/BarPlot.js +26 -16
- package/legacy/BarChart/extremums.js +22 -2
- package/legacy/BarChart/formatter.js +3 -1
- package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
- package/legacy/LineChart/LineChart.js +15 -3
- 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 +24 -6
- package/legacy/LineChart/index.js +3 -1
- package/legacy/PieChart/PieChart.js +1 -1
- package/legacy/ScatterChart/ScatterChart.js +1 -1
- package/legacy/SparkLineChart/SparkLineChart.js +8 -11
- package/legacy/context/CartesianContextProvider.js +4 -4
- package/legacy/hooks/useAxisEvents.js +21 -37
- package/legacy/hooks/useTicks.js +2 -2
- package/legacy/index.js +1 -1
- package/models/seriesType/bar.d.ts +6 -1
- package/models/seriesType/line.d.ts +33 -0
- package/modern/BarChart/BarChart.js +27 -14
- package/modern/BarChart/BarPlot.js +25 -15
- package/modern/BarChart/extremums.js +18 -2
- package/modern/BarChart/formatter.js +3 -1
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
- package/modern/LineChart/LineChart.js +15 -3
- 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 +34 -15
- package/modern/LineChart/index.js +3 -1
- package/modern/PieChart/PieChart.js +1 -1
- package/modern/ScatterChart/ScatterChart.js +1 -1
- package/modern/SparkLineChart/SparkLineChart.js +8 -13
- package/modern/context/CartesianContextProvider.js +4 -4
- package/modern/hooks/useAxisEvents.js +21 -38
- package/modern/hooks/useTicks.js +2 -2
- package/modern/index.js +1 -1
- package/package.json +4 -4
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
-
|
|
3
|
+
var getBaseExtremum = function getBaseExtremum(params) {
|
|
4
4
|
var _axis$data, _axis$data2;
|
|
5
5
|
var axis = params.axis;
|
|
6
6
|
var minX = Math.min.apply(Math, _toConsumableArray((_axis$data = axis.data) != null ? _axis$data : []));
|
|
7
7
|
var maxX = Math.max.apply(Math, _toConsumableArray((_axis$data2 = axis.data) != null ? _axis$data2 : []));
|
|
8
8
|
return [minX, maxX];
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
var getValueExtremum = function getValueExtremum(params) {
|
|
11
11
|
var series = params.series,
|
|
12
12
|
axis = params.axis,
|
|
13
13
|
isDefaultAxis = params.isDefaultAxis;
|
|
@@ -22,4 +22,24 @@ export var getExtremumY = function getExtremumY(params) {
|
|
|
22
22
|
seriesMax = _series$seriesId$stac2[1];
|
|
23
23
|
return [acc[0] === null ? seriesMin : Math.min(seriesMin, acc[0]), acc[1] === null ? seriesMax : Math.max(seriesMax, acc[1])];
|
|
24
24
|
}, [null, null]);
|
|
25
|
+
};
|
|
26
|
+
export var getExtremumX = function getExtremumX(params) {
|
|
27
|
+
// Notice that bar should be all horizontal or all vertical.
|
|
28
|
+
// Don't think it's a problem for now
|
|
29
|
+
var isHorizontal = Object.keys(params.series).some(function (seriesId) {
|
|
30
|
+
return params.series[seriesId].layout === 'horizontal';
|
|
31
|
+
});
|
|
32
|
+
if (isHorizontal) {
|
|
33
|
+
return getValueExtremum(params);
|
|
34
|
+
}
|
|
35
|
+
return getBaseExtremum(params);
|
|
36
|
+
};
|
|
37
|
+
export var getExtremumY = function getExtremumY(params) {
|
|
38
|
+
var isHorizontal = Object.keys(params.series).some(function (seriesId) {
|
|
39
|
+
return params.series[seriesId].layout === 'horizontal';
|
|
40
|
+
});
|
|
41
|
+
if (isHorizontal) {
|
|
42
|
+
return getBaseExtremum(params);
|
|
43
|
+
}
|
|
44
|
+
return getValueExtremum(params);
|
|
25
45
|
};
|
|
@@ -38,7 +38,9 @@ var formatter = function formatter(params, dataset) {
|
|
|
38
38
|
})).order(stackingOrder).offset(stackingOffset)(d3Dataset);
|
|
39
39
|
ids.forEach(function (id, index) {
|
|
40
40
|
var dataKey = series[id].dataKey;
|
|
41
|
-
completedSeries[id] = _extends({
|
|
41
|
+
completedSeries[id] = _extends({
|
|
42
|
+
layout: 'vertical'
|
|
43
|
+
}, series[id], {
|
|
42
44
|
data: dataKey ? dataset.map(function (d) {
|
|
43
45
|
return d[dataKey];
|
|
44
46
|
}) : series[id].data,
|
|
@@ -21,6 +21,7 @@ function ChartsAxisHighlight(props) {
|
|
|
21
21
|
var _React$useContext2 = React.useContext(InteractionContext),
|
|
22
22
|
axis = _React$useContext2.axis;
|
|
23
23
|
var getXPosition = getValueToPositionMapper(xScale);
|
|
24
|
+
var getYPosition = getValueToPositionMapper(yScale);
|
|
24
25
|
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
25
26
|
children: [xAxisHighlight === 'band' && axis.x !== null && isBandScale(xScale) && /*#__PURE__*/_jsx("path", {
|
|
26
27
|
d: "M ".concat(xScale(axis.x.value) - (xScale.step() - xScale.bandwidth()) / 2, " ").concat(yScale.range()[0], " l ").concat(xScale.step(), " 0 l 0 ").concat(yScale.range()[1] - yScale.range()[0], " l ").concat(-xScale.step(), " 0 Z"),
|
|
@@ -29,15 +30,22 @@ function ChartsAxisHighlight(props) {
|
|
|
29
30
|
style: {
|
|
30
31
|
pointerEvents: 'none'
|
|
31
32
|
}
|
|
33
|
+
}), yAxisHighlight === 'band' && axis.y !== null && isBandScale(yScale) && /*#__PURE__*/_jsx("path", {
|
|
34
|
+
d: "M ".concat(xScale.range()[0], " ").concat(yScale(axis.y.value) - (yScale.step() - yScale.bandwidth()) / 2, " l 0 ").concat(yScale.step(), " l ").concat(xScale.range()[1] - xScale.range()[0], " 0 l 0 ").concat(-yScale.step(), " Z"),
|
|
35
|
+
fill: "gray",
|
|
36
|
+
fillOpacity: 0.1,
|
|
37
|
+
style: {
|
|
38
|
+
pointerEvents: 'none'
|
|
39
|
+
}
|
|
32
40
|
}), xAxisHighlight === 'line' && axis.x !== null && /*#__PURE__*/_jsx("path", {
|
|
33
|
-
d: "M ".concat(getXPosition(axis.x.value), " ").concat(yScale
|
|
41
|
+
d: "M ".concat(getXPosition(axis.x.value), " ").concat(yScale.range()[0], " L ").concat(getXPosition(axis.x.value), " ").concat(yScale.range()[1]),
|
|
34
42
|
stroke: "black",
|
|
35
43
|
strokeDasharray: "5 2",
|
|
36
44
|
style: {
|
|
37
45
|
pointerEvents: 'none'
|
|
38
46
|
}
|
|
39
47
|
}), yAxisHighlight === 'line' && axis.y !== null && /*#__PURE__*/_jsx("path", {
|
|
40
|
-
d: "M ".concat(xScale.range()[0], " ").concat(
|
|
48
|
+
d: "M ".concat(xScale.range()[0], " ").concat(getYPosition(axis.y.value), " L ").concat(xScale.range()[1], " ").concat(getYPosition(axis.y.value)),
|
|
41
49
|
stroke: "black",
|
|
42
50
|
strokeDasharray: "5 2",
|
|
43
51
|
style: {
|
|
@@ -52,6 +60,6 @@ process.env.NODE_ENV !== "production" ? ChartsAxisHighlight.propTypes = {
|
|
|
52
60
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
53
61
|
// ----------------------------------------------------------------------
|
|
54
62
|
x: PropTypes.oneOf(['band', 'line', 'none']),
|
|
55
|
-
y: PropTypes.oneOf(['line', 'none'])
|
|
63
|
+
y: PropTypes.oneOf(['band', 'line', 'none'])
|
|
56
64
|
} : void 0;
|
|
57
65
|
export { ChartsAxisHighlight };
|
|
@@ -71,30 +71,34 @@ export function ChartsAxisTooltipContent(props) {
|
|
|
71
71
|
axisData = props.axisData,
|
|
72
72
|
sx = props.sx,
|
|
73
73
|
classes = props.classes;
|
|
74
|
-
var
|
|
75
|
-
var
|
|
74
|
+
var isXaxis = (axisData.x && axisData.x.index) !== undefined;
|
|
75
|
+
var dataIndex = isXaxis ? axisData.x && axisData.x.index : axisData.y && axisData.y.index;
|
|
76
|
+
var axisValue = isXaxis ? axisData.x && axisData.x.value : axisData.y && axisData.y.value;
|
|
76
77
|
var _React$useContext = React.useContext(CartesianContext),
|
|
77
78
|
xAxisIds = _React$useContext.xAxisIds,
|
|
78
|
-
xAxis = _React$useContext.xAxis
|
|
79
|
+
xAxis = _React$useContext.xAxis,
|
|
80
|
+
yAxisIds = _React$useContext.yAxisIds,
|
|
81
|
+
yAxis = _React$useContext.yAxis;
|
|
79
82
|
var series = React.useContext(SeriesContext);
|
|
80
|
-
var
|
|
83
|
+
var USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
|
|
81
84
|
var relevantSeries = React.useMemo(function () {
|
|
82
85
|
var rep = [];
|
|
83
86
|
Object.keys(series).filter(function (seriesType) {
|
|
84
87
|
return ['bar', 'line', 'scatter'].includes(seriesType);
|
|
85
88
|
}).forEach(function (seriesType) {
|
|
86
89
|
series[seriesType].seriesOrder.forEach(function (seriesId) {
|
|
87
|
-
var
|
|
88
|
-
|
|
90
|
+
var item = series[seriesType].series[seriesId];
|
|
91
|
+
var axisKey = isXaxis ? item.xAxisKey : item.yAxisKey;
|
|
92
|
+
if (axisKey === undefined || axisKey === USED_AXIS_ID) {
|
|
89
93
|
rep.push(series[seriesType].series[seriesId]);
|
|
90
94
|
}
|
|
91
95
|
});
|
|
92
96
|
});
|
|
93
97
|
return rep;
|
|
94
|
-
}, [
|
|
98
|
+
}, [USED_AXIS_ID, isXaxis, series]);
|
|
95
99
|
var relevantAxis = React.useMemo(function () {
|
|
96
|
-
return xAxis[
|
|
97
|
-
}, [
|
|
100
|
+
return isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID];
|
|
101
|
+
}, [USED_AXIS_ID, isXaxis, xAxis, yAxis]);
|
|
98
102
|
var Content = content != null ? content : DefaultChartsAxisContent;
|
|
99
103
|
return /*#__PURE__*/_jsx(Content, {
|
|
100
104
|
axisData: axisData,
|
|
@@ -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
|
});
|
|
@@ -101,7 +107,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
101
107
|
// ----------------------------------------------------------------------
|
|
102
108
|
axisHighlight: PropTypes.shape({
|
|
103
109
|
x: PropTypes.oneOf(['band', 'line', 'none']),
|
|
104
|
-
y: PropTypes.oneOf(['line', 'none'])
|
|
110
|
+
y: PropTypes.oneOf(['band', 'line', 'none'])
|
|
105
111
|
}),
|
|
106
112
|
/**
|
|
107
113
|
* Indicate which axis to display the bottom of the charts.
|
|
@@ -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 = {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["slots", "slotProps"];
|
|
3
5
|
import * as React from 'react';
|
|
4
6
|
import PropTypes from 'prop-types';
|
|
5
7
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
@@ -10,7 +12,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
10
12
|
function MarkPlot(props) {
|
|
11
13
|
var _slots$mark;
|
|
12
14
|
var slots = props.slots,
|
|
13
|
-
slotProps = props.slotProps
|
|
15
|
+
slotProps = props.slotProps,
|
|
16
|
+
other = _objectWithoutProperties(props, _excluded);
|
|
14
17
|
var seriesData = React.useContext(SeriesContext).line;
|
|
15
18
|
var axisData = React.useContext(CartesianContext);
|
|
16
19
|
var Mark = (_slots$mark = slots == null ? void 0 : slots.mark) != null ? _slots$mark : MarkElement;
|
|
@@ -25,7 +28,7 @@ function MarkPlot(props) {
|
|
|
25
28
|
yAxisIds = axisData.yAxisIds;
|
|
26
29
|
var defaultXAxisId = xAxisIds[0];
|
|
27
30
|
var defaultYAxisId = yAxisIds[0];
|
|
28
|
-
return /*#__PURE__*/_jsx("g", _extends({},
|
|
31
|
+
return /*#__PURE__*/_jsx("g", _extends({}, other, {
|
|
29
32
|
children: stackingGroups.flatMap(function (_ref) {
|
|
30
33
|
var groupIds = _ref.ids;
|
|
31
34
|
return groupIds.flatMap(function (seriesId) {
|
|
@@ -34,7 +37,12 @@ function MarkPlot(props) {
|
|
|
34
37
|
xAxisKey = _series$seriesId$xAxi === void 0 ? defaultXAxisId : _series$seriesId$xAxi,
|
|
35
38
|
_series$seriesId$yAxi = _series$seriesId.yAxisKey,
|
|
36
39
|
yAxisKey = _series$seriesId$yAxi === void 0 ? defaultYAxisId : _series$seriesId$yAxi,
|
|
37
|
-
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
|
+
}
|
|
38
46
|
var xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
|
|
39
47
|
var yScale = yAxis[yAxisKey].scale;
|
|
40
48
|
var xData = xAxis[xAxisKey].data;
|
|
@@ -59,13 +67,23 @@ function MarkPlot(props) {
|
|
|
59
67
|
return {
|
|
60
68
|
x: xScale(x),
|
|
61
69
|
y: yScale(y),
|
|
70
|
+
position: x,
|
|
71
|
+
value: y,
|
|
62
72
|
index: index
|
|
63
73
|
};
|
|
64
74
|
}).filter(isInRange).map(function (_ref3) {
|
|
65
75
|
var x = _ref3.x,
|
|
66
76
|
y = _ref3.y,
|
|
67
|
-
index = _ref3.index
|
|
68
|
-
|
|
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({
|
|
69
87
|
id: seriesId,
|
|
70
88
|
dataIndex: index,
|
|
71
89
|
shape: "circle",
|
|
@@ -73,7 +91,7 @@ function MarkPlot(props) {
|
|
|
73
91
|
x: x,
|
|
74
92
|
y: y,
|
|
75
93
|
highlightScope: series[seriesId].highlightScope
|
|
76
|
-
}, slotProps == null ? void 0 : slotProps.mark), "".concat(seriesId, "-").concat(index));
|
|
94
|
+
}, slotProps == null ? void 0 : slotProps.mark), "".concat(seriesId, "-").concat(index)) : null;
|
|
77
95
|
});
|
|
78
96
|
});
|
|
79
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';
|
|
@@ -100,7 +100,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
100
100
|
// ----------------------------------------------------------------------
|
|
101
101
|
axisHighlight: PropTypes.shape({
|
|
102
102
|
x: PropTypes.oneOf(['band', 'line', 'none']),
|
|
103
|
-
y: PropTypes.oneOf(['line', 'none'])
|
|
103
|
+
y: PropTypes.oneOf(['band', 'line', 'none'])
|
|
104
104
|
}),
|
|
105
105
|
/**
|
|
106
106
|
* Indicate which axis to display the bottom of the charts.
|
|
@@ -70,7 +70,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
70
70
|
// ----------------------------------------------------------------------
|
|
71
71
|
axisHighlight: PropTypes.shape({
|
|
72
72
|
x: PropTypes.oneOf(['band', 'line', 'none']),
|
|
73
|
-
y: PropTypes.oneOf(['line', 'none'])
|
|
73
|
+
y: PropTypes.oneOf(['band', 'line', 'none'])
|
|
74
74
|
}),
|
|
75
75
|
/**
|
|
76
76
|
* Indicate which axis to display the bottom of the charts.
|
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
2
|
import * as React from 'react';
|
|
4
3
|
import PropTypes from 'prop-types';
|
|
5
|
-
import { styled } from '@mui/material/styles';
|
|
6
4
|
import { BarPlot } from '../BarChart';
|
|
7
|
-
import { LinePlot,
|
|
5
|
+
import { LinePlot, AreaPlot, LineHighlightPlot } from '../LineChart';
|
|
8
6
|
import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
|
|
9
7
|
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
10
8
|
import { ChartsTooltip } from '../ChartsTooltip';
|
|
11
9
|
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
12
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
11
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
var SparkLineMarkPlot = styled(MarkPlot)(_defineProperty({}, "& .".concat(markElementClasses.root), _defineProperty({
|
|
15
|
-
display: 'none'
|
|
16
|
-
}, "&.".concat(markElementClasses.highlighted), {
|
|
17
|
-
display: 'inherit'
|
|
18
|
-
})));
|
|
19
12
|
var SPARKLINE_DEFAULT_MARGIN = {
|
|
20
13
|
top: 5,
|
|
21
14
|
bottom: 5,
|
|
@@ -61,7 +54,8 @@ var SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props
|
|
|
61
54
|
valueFormatter: valueFormatter
|
|
62
55
|
}, plotType === 'bar' ? {} : {
|
|
63
56
|
area: area,
|
|
64
|
-
curve: curve
|
|
57
|
+
curve: curve,
|
|
58
|
+
disableHighlight: !showHighlight
|
|
65
59
|
})],
|
|
66
60
|
width: width,
|
|
67
61
|
height: height,
|
|
@@ -89,7 +83,10 @@ var SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props
|
|
|
89
83
|
}), /*#__PURE__*/_jsx(LinePlot, {
|
|
90
84
|
slots: slots,
|
|
91
85
|
slotProps: slotProps
|
|
92
|
-
}),
|
|
86
|
+
}), /*#__PURE__*/_jsx(LineHighlightPlot, {
|
|
87
|
+
slots: slots,
|
|
88
|
+
slotProps: slotProps
|
|
89
|
+
})]
|
|
93
90
|
}), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), showTooltip && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), children]
|
|
94
91
|
});
|
|
95
92
|
});
|
|
@@ -106,7 +103,7 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
106
103
|
area: PropTypes.bool,
|
|
107
104
|
axisHighlight: PropTypes.shape({
|
|
108
105
|
x: PropTypes.oneOf(['band', 'line', 'none']),
|
|
109
|
-
y: PropTypes.oneOf(['line', 'none'])
|
|
106
|
+
y: PropTypes.oneOf(['band', 'line', 'none'])
|
|
110
107
|
}),
|
|
111
108
|
children: PropTypes.node,
|
|
112
109
|
className: PropTypes.string,
|
|
@@ -182,17 +182,17 @@ function CartesianContextProvider(_ref) {
|
|
|
182
182
|
if (isBandScaleConfig(axis)) {
|
|
183
183
|
var _axis$categoryGapRati2;
|
|
184
184
|
var categoryGapRatio = (_axis$categoryGapRati2 = axis.categoryGapRatio) != null ? _axis$categoryGapRati2 : DEFAULT_CATEGORY_GAP_RATIO;
|
|
185
|
-
|
|
185
|
+
completedYAxis[axis.id] = _extends({
|
|
186
186
|
categoryGapRatio: categoryGapRatio,
|
|
187
187
|
barGapRatio: 0
|
|
188
188
|
}, axis, {
|
|
189
|
-
scale: scaleBand(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
189
|
+
scale: scaleBand(axis.data, [range[1], range[0]]).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
190
190
|
ticksNumber: axis.data.length
|
|
191
191
|
});
|
|
192
192
|
}
|
|
193
193
|
if (isPointScaleConfig(axis)) {
|
|
194
|
-
|
|
195
|
-
scale: scalePoint(axis.data, range),
|
|
194
|
+
completedYAxis[axis.id] = _extends({}, axis, {
|
|
195
|
+
scale: scalePoint(axis.data, [range[1], range[0]]),
|
|
196
196
|
ticksNumber: axis.data.length
|
|
197
197
|
});
|
|
198
198
|
}
|