@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
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
const {
|
|
14
|
+
slots,
|
|
15
|
+
slotProps
|
|
16
|
+
} = props,
|
|
17
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
18
|
+
const seriesData = React.useContext(SeriesContext).line;
|
|
19
|
+
const axisData = React.useContext(CartesianContext);
|
|
20
|
+
const {
|
|
21
|
+
axis
|
|
22
|
+
} = React.useContext(InteractionContext);
|
|
23
|
+
const highlightedIndex = axis.x?.index;
|
|
24
|
+
if (highlightedIndex === undefined) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
if (seriesData === undefined) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const {
|
|
31
|
+
series,
|
|
32
|
+
stackingGroups
|
|
33
|
+
} = seriesData;
|
|
34
|
+
const {
|
|
35
|
+
xAxis,
|
|
36
|
+
yAxis,
|
|
37
|
+
xAxisIds,
|
|
38
|
+
yAxisIds
|
|
39
|
+
} = axisData;
|
|
40
|
+
const defaultXAxisId = xAxisIds[0];
|
|
41
|
+
const defaultYAxisId = yAxisIds[0];
|
|
42
|
+
const Element = slots?.lineHighlight ?? LineHighlightElement;
|
|
43
|
+
return /*#__PURE__*/_jsx("g", _extends({}, other, {
|
|
44
|
+
children: stackingGroups.flatMap(({
|
|
45
|
+
ids: groupIds
|
|
46
|
+
}) => {
|
|
47
|
+
return groupIds.flatMap(seriesId => {
|
|
48
|
+
const {
|
|
49
|
+
xAxisKey = defaultXAxisId,
|
|
50
|
+
yAxisKey = defaultYAxisId,
|
|
51
|
+
stackedData,
|
|
52
|
+
disableHighlight
|
|
53
|
+
} = series[seriesId];
|
|
54
|
+
if (disableHighlight) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
|
|
58
|
+
const yScale = yAxis[yAxisKey].scale;
|
|
59
|
+
const xData = xAxis[xAxisKey].data;
|
|
60
|
+
if (xData === undefined) {
|
|
61
|
+
throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot.`);
|
|
62
|
+
}
|
|
63
|
+
const x = xScale(xData[highlightedIndex]);
|
|
64
|
+
const y = yScale(stackedData[highlightedIndex][1]);
|
|
65
|
+
return /*#__PURE__*/_jsx(Element, _extends({
|
|
66
|
+
id: seriesId,
|
|
67
|
+
color: series[seriesId].color,
|
|
68
|
+
x: x,
|
|
69
|
+
y: y
|
|
70
|
+
}, slotProps?.lineHighlight), `${seriesId}`);
|
|
71
|
+
});
|
|
72
|
+
})
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
process.env.NODE_ENV !== "production" ? LineHighlightPlot.propTypes = {
|
|
76
|
+
// ----------------------------- Warning --------------------------------
|
|
77
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
78
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
79
|
+
// ----------------------------------------------------------------------
|
|
80
|
+
/**
|
|
81
|
+
* The props used for each component slot.
|
|
82
|
+
* @default {}
|
|
83
|
+
*/
|
|
84
|
+
slotProps: PropTypes.object,
|
|
85
|
+
/**
|
|
86
|
+
* Overridable component slots.
|
|
87
|
+
* @default {}
|
|
88
|
+
*/
|
|
89
|
+
slots: PropTypes.object
|
|
90
|
+
} : void 0;
|
|
91
|
+
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 --------------------------------
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["slots", "slotProps"];
|
|
2
4
|
import * as React from 'react';
|
|
3
5
|
import PropTypes from 'prop-types';
|
|
4
6
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
@@ -8,9 +10,10 @@ import { getValueToPositionMapper } from '../hooks/useScale';
|
|
|
8
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
11
|
function MarkPlot(props) {
|
|
10
12
|
const {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
slots,
|
|
14
|
+
slotProps
|
|
15
|
+
} = props,
|
|
16
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
14
17
|
const seriesData = React.useContext(SeriesContext).line;
|
|
15
18
|
const axisData = React.useContext(CartesianContext);
|
|
16
19
|
const Mark = slots?.mark ?? MarkElement;
|
|
@@ -29,7 +32,7 @@ function MarkPlot(props) {
|
|
|
29
32
|
} = axisData;
|
|
30
33
|
const defaultXAxisId = xAxisIds[0];
|
|
31
34
|
const defaultYAxisId = yAxisIds[0];
|
|
32
|
-
return /*#__PURE__*/_jsx("g", _extends({},
|
|
35
|
+
return /*#__PURE__*/_jsx("g", _extends({}, other, {
|
|
33
36
|
children: stackingGroups.flatMap(({
|
|
34
37
|
ids: groupIds
|
|
35
38
|
}) => {
|
|
@@ -37,8 +40,12 @@ function MarkPlot(props) {
|
|
|
37
40
|
const {
|
|
38
41
|
xAxisKey = defaultXAxisId,
|
|
39
42
|
yAxisKey = defaultYAxisId,
|
|
40
|
-
stackedData
|
|
43
|
+
stackedData,
|
|
44
|
+
showMark = true
|
|
41
45
|
} = series[seriesId];
|
|
46
|
+
if (showMark === false) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
42
49
|
const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
|
|
43
50
|
const yScale = yAxis[yAxisKey].scale;
|
|
44
51
|
const xData = xAxis[xAxisKey].data;
|
|
@@ -64,21 +71,33 @@ function MarkPlot(props) {
|
|
|
64
71
|
return {
|
|
65
72
|
x: xScale(x),
|
|
66
73
|
y: yScale(y),
|
|
74
|
+
position: x,
|
|
75
|
+
value: y,
|
|
67
76
|
index
|
|
68
77
|
};
|
|
69
78
|
}).filter(isInRange).map(({
|
|
70
79
|
x,
|
|
71
80
|
y,
|
|
72
|
-
index
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
index,
|
|
82
|
+
position,
|
|
83
|
+
value
|
|
84
|
+
}) => {
|
|
85
|
+
return showMark === true || showMark({
|
|
86
|
+
x,
|
|
87
|
+
y,
|
|
88
|
+
index,
|
|
89
|
+
position,
|
|
90
|
+
value
|
|
91
|
+
}) ? /*#__PURE__*/_jsx(Mark, _extends({
|
|
92
|
+
id: seriesId,
|
|
93
|
+
dataIndex: index,
|
|
94
|
+
shape: "circle",
|
|
95
|
+
color: series[seriesId].color,
|
|
96
|
+
x: x,
|
|
97
|
+
y: y,
|
|
98
|
+
highlightScope: series[seriesId].highlightScope
|
|
99
|
+
}, slotProps?.mark), `${seriesId}-${index}`) : null;
|
|
100
|
+
});
|
|
82
101
|
});
|
|
83
102
|
})
|
|
84
103
|
}));
|
|
@@ -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';
|
|
@@ -88,7 +88,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
88
88
|
// ----------------------------------------------------------------------
|
|
89
89
|
axisHighlight: PropTypes.shape({
|
|
90
90
|
x: PropTypes.oneOf(['band', 'line', 'none']),
|
|
91
|
-
y: PropTypes.oneOf(['line', 'none'])
|
|
91
|
+
y: PropTypes.oneOf(['band', 'line', 'none'])
|
|
92
92
|
}),
|
|
93
93
|
/**
|
|
94
94
|
* 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,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
|
});
|
|
@@ -102,7 +97,7 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
102
97
|
area: PropTypes.bool,
|
|
103
98
|
axisHighlight: PropTypes.shape({
|
|
104
99
|
x: PropTypes.oneOf(['band', 'line', 'none']),
|
|
105
|
-
y: PropTypes.oneOf(['line', 'none'])
|
|
100
|
+
y: PropTypes.oneOf(['band', 'line', 'none'])
|
|
106
101
|
}),
|
|
107
102
|
children: PropTypes.node,
|
|
108
103
|
className: PropTypes.string,
|
|
@@ -150,17 +150,17 @@ function CartesianContextProvider({
|
|
|
150
150
|
const range = [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
151
151
|
if (isBandScaleConfig(axis)) {
|
|
152
152
|
const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
|
|
153
|
-
|
|
153
|
+
completedYAxis[axis.id] = _extends({
|
|
154
154
|
categoryGapRatio,
|
|
155
155
|
barGapRatio: 0
|
|
156
156
|
}, axis, {
|
|
157
|
-
scale: scaleBand(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
157
|
+
scale: scaleBand(axis.data, [range[1], range[0]]).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
158
158
|
ticksNumber: axis.data.length
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
161
|
if (isPointScaleConfig(axis)) {
|
|
162
|
-
|
|
163
|
-
scale: scalePoint(axis.data, range),
|
|
162
|
+
completedYAxis[axis.id] = _extends({}, axis, {
|
|
163
|
+
scale: scalePoint(axis.data, [range[1], range[0]]),
|
|
164
164
|
ticksNumber: axis.data.length
|
|
165
165
|
});
|
|
166
166
|
}
|
|
@@ -33,66 +33,49 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
33
33
|
if (element === null || disableAxisListener) {
|
|
34
34
|
return () => {};
|
|
35
35
|
}
|
|
36
|
-
const
|
|
37
|
-
if (usedYAxis === null) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
const {
|
|
41
|
-
scale: yScale,
|
|
42
|
-
data: yAxisData
|
|
43
|
-
} = yAxis[usedYAxis];
|
|
44
|
-
if (!isBandScale(yScale)) {
|
|
45
|
-
return {
|
|
46
|
-
value: yScale.invert(y)
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
const dataIndex = Math.floor((y - yScale.range()[0]) / yScale.step());
|
|
50
|
-
if (dataIndex < 0 || dataIndex >= yAxisData.length) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
index: dataIndex,
|
|
55
|
-
value: yAxisData[dataIndex]
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
const getUpdateX = x => {
|
|
36
|
+
const getUpdate = (axisConfig, mouseValue) => {
|
|
59
37
|
if (usedXAxis === null) {
|
|
60
38
|
return null;
|
|
61
39
|
}
|
|
62
40
|
const {
|
|
63
|
-
scale
|
|
64
|
-
data:
|
|
65
|
-
} =
|
|
66
|
-
if (!isBandScale(
|
|
67
|
-
const value =
|
|
68
|
-
|
|
41
|
+
scale,
|
|
42
|
+
data: axisData
|
|
43
|
+
} = axisConfig;
|
|
44
|
+
if (!isBandScale(scale)) {
|
|
45
|
+
const value = scale.invert(mouseValue);
|
|
46
|
+
if (axisData === undefined) {
|
|
47
|
+
return {
|
|
48
|
+
value
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const closestIndex = axisData?.findIndex((v, index) => {
|
|
69
52
|
if (v > value) {
|
|
70
53
|
// @ts-ignore
|
|
71
|
-
if (index === 0 || Math.abs(value - v) <= Math.abs(value -
|
|
54
|
+
if (index === 0 || Math.abs(value - v) <= Math.abs(value - axisData[index - 1])) {
|
|
72
55
|
return true;
|
|
73
56
|
}
|
|
74
57
|
}
|
|
75
58
|
if (v <= value) {
|
|
76
|
-
if (index ===
|
|
59
|
+
if (index === axisData.length - 1 ||
|
|
77
60
|
// @ts-ignore
|
|
78
|
-
Math.abs(value - v) < Math.abs(value -
|
|
61
|
+
Math.abs(value - v) < Math.abs(value - axisData[index + 1])) {
|
|
79
62
|
return true;
|
|
80
63
|
}
|
|
81
64
|
}
|
|
82
65
|
return false;
|
|
83
66
|
});
|
|
84
67
|
return {
|
|
85
|
-
value: closestIndex !== undefined && closestIndex >= 0 ?
|
|
68
|
+
value: closestIndex !== undefined && closestIndex >= 0 ? axisData[closestIndex] : value,
|
|
86
69
|
index: closestIndex
|
|
87
70
|
};
|
|
88
71
|
}
|
|
89
|
-
const dataIndex =
|
|
90
|
-
if (dataIndex < 0 || dataIndex >=
|
|
72
|
+
const dataIndex = scale.bandwidth() === 0 ? Math.floor((mouseValue - Math.min(...scale.range()) + scale.step() / 2) / scale.step()) : Math.floor((mouseValue - Math.min(...scale.range())) / scale.step());
|
|
73
|
+
if (dataIndex < 0 || dataIndex >= axisData.length) {
|
|
91
74
|
return null;
|
|
92
75
|
}
|
|
93
76
|
return {
|
|
94
77
|
index: dataIndex,
|
|
95
|
-
value:
|
|
78
|
+
value: axisData[dataIndex]
|
|
96
79
|
};
|
|
97
80
|
};
|
|
98
81
|
const handleMouseOut = () => {
|
|
@@ -130,8 +113,8 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
130
113
|
});
|
|
131
114
|
return;
|
|
132
115
|
}
|
|
133
|
-
const newStateX =
|
|
134
|
-
const newStateY =
|
|
116
|
+
const newStateX = getUpdate(xAxis[usedXAxis], svgPt.x);
|
|
117
|
+
const newStateY = getUpdate(yAxis[usedYAxis], svgPt.y);
|
|
135
118
|
dispatch({
|
|
136
119
|
type: 'updateAxis',
|
|
137
120
|
data: {
|
package/modern/hooks/useTicks.js
CHANGED
|
@@ -25,9 +25,9 @@ function useTicks(options) {
|
|
|
25
25
|
const domain = scale.domain();
|
|
26
26
|
if (scale.bandwidth() > 0) {
|
|
27
27
|
// scale type = 'band'
|
|
28
|
-
return [...domain.map(
|
|
28
|
+
return [...domain.map(value => ({
|
|
29
29
|
formattedValue: valueFormatter?.(value) ?? value,
|
|
30
|
-
offset:
|
|
30
|
+
offset: scale(value) - (scale.step() - scale.bandwidth()) / 2,
|
|
31
31
|
labelOffset: scale.step() / 2
|
|
32
32
|
})), {
|
|
33
33
|
formattedValue: undefined,
|
package/modern/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-charts",
|
|
3
|
-
"version": "6.0.0-alpha.
|
|
3
|
+
"version": "6.0.0-alpha.9",
|
|
4
4
|
"description": "The community edition of the charts components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"directory": "packages/x-charts"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@babel/runtime": "^7.22.
|
|
30
|
+
"@babel/runtime": "^7.22.11",
|
|
31
31
|
"clsx": "^2.0.0",
|
|
32
32
|
"d3-color": "^3.1.0",
|
|
33
33
|
"d3-scale": "^4.0.2",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
},
|
|
59
59
|
"./*": {
|
|
60
60
|
"types": "./*/index.d.ts",
|
|
61
|
-
"require": "
|
|
62
|
-
"import": "./esm
|
|
61
|
+
"require": "./*/index.js",
|
|
62
|
+
"import": "./esm/*/index.js"
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
"setupFiles": [
|