@mui/x-charts 7.0.0-alpha.3 → 7.0.0-alpha.5
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/BarPlot.js +7 -6
- package/BarChart/formatter.js +15 -3
- package/CHANGELOG.md +465 -0
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsLegend/ChartsLegend.d.ts +1 -1
- package/ChartsLegend/ChartsLegend.js +3 -2
- package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/ChartsReferenceLine/common.d.ts +1 -1
- package/ChartsText/ChartsText.d.ts +17 -0
- package/{internals/components → ChartsText}/ChartsText.js +32 -17
- package/ChartsText/index.d.ts +3 -0
- package/ChartsText/index.js +12 -0
- package/ChartsText/package.json +6 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +14 -0
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +174 -0
- package/ChartsVoronoiHandler/index.d.ts +1 -0
- package/ChartsVoronoiHandler/index.js +16 -0
- package/ChartsVoronoiHandler/package.json +6 -0
- package/ChartsXAxis/ChartsXAxis.js +3 -2
- package/ChartsYAxis/ChartsYAxis.js +1 -1
- package/LineChart/AreaPlot.js +3 -2
- package/LineChart/LineHighlightPlot.js +2 -1
- package/LineChart/LinePlot.js +3 -2
- package/LineChart/MarkPlot.js +2 -1
- package/LineChart/formatter.js +14 -2
- package/PieChart/PieArcLabelPlot.d.ts +2 -3
- package/PieChart/PieArcLabelPlot.js +0 -1
- package/PieChart/PieArcPlot.d.ts +2 -3
- package/PieChart/PieArcPlot.js +0 -1
- package/PieChart/PieChart.js +4 -4
- package/PieChart/PiePlot.js +20 -15
- package/PieChart/dataTransform/useTransformData.d.ts +2 -3
- package/ResponsiveChartContainer/index.js +2 -2
- package/ScatterChart/Scatter.js +14 -5
- package/ScatterChart/ScatterChart.d.ts +7 -1
- package/ScatterChart/ScatterChart.js +18 -1
- package/SparkLineChart/SparkLineChart.js +1 -0
- package/context/CartesianContextProvider.js +2 -2
- package/context/InteractionProvider.d.ts +10 -0
- package/context/InteractionProvider.js +21 -1
- package/context/SeriesContextProvider.js +1 -1
- package/esm/BarChart/BarPlot.js +7 -5
- package/esm/BarChart/formatter.js +20 -4
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsLegend/ChartsLegend.js +2 -1
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/esm/{internals/components → ChartsText}/ChartsText.js +33 -16
- package/esm/ChartsText/index.js +1 -0
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +168 -0
- package/esm/ChartsVoronoiHandler/index.js +1 -0
- package/esm/ChartsXAxis/ChartsXAxis.js +2 -1
- package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
- package/esm/LineChart/AreaPlot.js +3 -2
- package/esm/LineChart/LineHighlightPlot.js +2 -1
- package/esm/LineChart/LinePlot.js +3 -2
- package/esm/LineChart/MarkPlot.js +2 -1
- package/esm/LineChart/formatter.js +16 -3
- package/esm/PieChart/PieArcLabelPlot.js +0 -1
- package/esm/PieChart/PieArcPlot.js +0 -1
- package/esm/PieChart/PieChart.js +4 -4
- package/esm/PieChart/PiePlot.js +20 -15
- package/esm/ResponsiveChartContainer/index.js +2 -2
- package/esm/ScatterChart/Scatter.js +14 -5
- package/esm/ScatterChart/ScatterChart.js +18 -1
- package/esm/SparkLineChart/SparkLineChart.js +1 -0
- package/esm/context/CartesianContextProvider.js +2 -2
- package/esm/context/InteractionProvider.js +21 -1
- package/esm/context/SeriesContextProvider.js +1 -1
- package/esm/hooks/useAxisEvents.js +20 -27
- package/esm/hooks/useInteractionItemProps.js +4 -1
- package/esm/index.js +2 -0
- package/esm/internals/getWordsByLines.js +14 -0
- package/esm/internals/utils.js +40 -0
- package/hooks/useAxisEvents.js +20 -27
- package/hooks/useInteractionItemProps.d.ts +2 -2
- package/hooks/useInteractionItemProps.js +4 -1
- package/index.d.ts +2 -0
- package/index.js +23 -1
- package/internals/defaultizeColor.d.ts +5 -4
- package/internals/{components/ChartsText.d.ts → getWordsByLines.d.ts} +2 -11
- package/internals/getWordsByLines.js +21 -0
- package/internals/utils.d.ts +13 -0
- package/internals/utils.js +42 -0
- package/legacy/BarChart/BarPlot.js +7 -5
- package/legacy/BarChart/formatter.js +23 -9
- package/legacy/ChartsAxis/ChartsAxis.js +4 -4
- package/legacy/ChartsLegend/ChartsLegend.js +2 -1
- package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/legacy/{internals/components → ChartsText}/ChartsText.js +38 -22
- package/legacy/ChartsText/index.js +1 -0
- package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +162 -0
- package/legacy/ChartsVoronoiHandler/index.js +1 -0
- package/legacy/ChartsXAxis/ChartsXAxis.js +2 -1
- package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
- package/legacy/LineChart/AreaPlot.js +3 -2
- package/legacy/LineChart/LineHighlightPlot.js +2 -1
- package/legacy/LineChart/LinePlot.js +3 -2
- package/legacy/LineChart/MarkPlot.js +2 -1
- package/legacy/LineChart/formatter.js +19 -8
- package/legacy/PieChart/PieArcLabelPlot.js +0 -1
- package/legacy/PieChart/PieArcPlot.js +0 -1
- package/legacy/PieChart/PieChart.js +4 -4
- package/legacy/PieChart/PiePlot.js +20 -15
- package/legacy/ResponsiveChartContainer/index.js +2 -2
- package/legacy/ScatterChart/Scatter.js +17 -6
- package/legacy/ScatterChart/ScatterChart.js +18 -1
- package/legacy/SparkLineChart/SparkLineChart.js +1 -0
- package/legacy/context/CartesianContextProvider.js +2 -2
- package/legacy/context/InteractionProvider.js +21 -1
- package/legacy/context/SeriesContextProvider.js +1 -1
- package/legacy/hooks/useAxisEvents.js +20 -27
- package/legacy/hooks/useInteractionItemProps.js +6 -1
- package/legacy/index.js +3 -1
- package/legacy/internals/getWordsByLines.js +15 -0
- package/legacy/internals/utils.js +40 -0
- package/models/axis.d.ts +1 -1
- package/models/seriesType/config.d.ts +4 -3
- package/models/seriesType/pie.d.ts +29 -7
- package/models/seriesType/scatter.d.ts +5 -0
- package/modern/BarChart/BarPlot.js +7 -5
- package/modern/BarChart/formatter.js +15 -3
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsLegend/ChartsLegend.js +2 -1
- package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/modern/{internals/components → ChartsText}/ChartsText.js +33 -16
- package/modern/ChartsText/index.js +1 -0
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +166 -0
- package/modern/ChartsVoronoiHandler/index.js +1 -0
- package/modern/ChartsXAxis/ChartsXAxis.js +2 -1
- package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
- package/modern/LineChart/AreaPlot.js +3 -2
- package/modern/LineChart/LineHighlightPlot.js +2 -1
- package/modern/LineChart/LinePlot.js +3 -2
- package/modern/LineChart/MarkPlot.js +2 -1
- package/modern/LineChart/formatter.js +14 -2
- package/modern/PieChart/PieArcLabelPlot.js +0 -1
- package/modern/PieChart/PieArcPlot.js +0 -1
- package/modern/PieChart/PieChart.js +4 -4
- package/modern/PieChart/PiePlot.js +20 -15
- package/modern/ResponsiveChartContainer/index.js +2 -2
- package/modern/ScatterChart/Scatter.js +14 -5
- package/modern/ScatterChart/ScatterChart.js +18 -1
- package/modern/SparkLineChart/SparkLineChart.js +1 -0
- package/modern/context/CartesianContextProvider.js +2 -2
- package/modern/context/InteractionProvider.js +21 -1
- package/modern/context/SeriesContextProvider.js +1 -1
- package/modern/hooks/useAxisEvents.js +20 -27
- package/modern/hooks/useInteractionItemProps.js +4 -1
- package/modern/index.js +3 -1
- package/modern/internals/getWordsByLines.js +14 -0
- package/modern/internals/utils.js +40 -0
- package/package.json +6 -4
|
@@ -3,6 +3,10 @@ import { InteractionContext } from '../context/InteractionProvider';
|
|
|
3
3
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
4
4
|
import { SVGContext, DrawingContext } from '../context/DrawingProvider';
|
|
5
5
|
import { isBandScale } from '../internals/isBandScale';
|
|
6
|
+
import { getSVGPoint } from '../internals/utils';
|
|
7
|
+
function getAsANumber(value) {
|
|
8
|
+
return value instanceof Date ? value.getTime() : value;
|
|
9
|
+
}
|
|
6
10
|
export const useAxisEvents = disableAxisListener => {
|
|
7
11
|
const svgRef = React.useContext(SVGContext);
|
|
8
12
|
const {
|
|
@@ -48,17 +52,18 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
48
52
|
value
|
|
49
53
|
};
|
|
50
54
|
}
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
const valueAsNumber = getAsANumber(value);
|
|
56
|
+
const closestIndex = axisData?.findIndex((pointValue, index) => {
|
|
57
|
+
const v = getAsANumber(pointValue);
|
|
58
|
+
if (v > valueAsNumber) {
|
|
59
|
+
if (index === 0 || Math.abs(valueAsNumber - v) <= Math.abs(valueAsNumber - getAsANumber(axisData[index - 1]))) {
|
|
55
60
|
return true;
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
|
-
if (v <=
|
|
63
|
+
if (v <= valueAsNumber) {
|
|
59
64
|
if (index === axisData.length - 1 ||
|
|
60
65
|
// @ts-ignore
|
|
61
|
-
Math.abs(value - v) < Math.abs(value - axisData[index + 1])) {
|
|
66
|
+
Math.abs(value - v) < Math.abs(value - getAsANumber(axisData[index + 1]))) {
|
|
62
67
|
return true;
|
|
63
68
|
}
|
|
64
69
|
}
|
|
@@ -84,37 +89,25 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
84
89
|
y: -1
|
|
85
90
|
};
|
|
86
91
|
dispatch({
|
|
87
|
-
type: '
|
|
88
|
-
data: {
|
|
89
|
-
x: null,
|
|
90
|
-
y: null
|
|
91
|
-
}
|
|
92
|
+
type: 'exitChart'
|
|
92
93
|
});
|
|
93
94
|
};
|
|
94
95
|
const handleMouseMove = event => {
|
|
95
|
-
|
|
96
|
-
const pt = svgRef.current.createSVGPoint();
|
|
97
|
-
pt.x = event.clientX;
|
|
98
|
-
pt.y = event.clientY;
|
|
99
|
-
const svgPt = pt.matrixTransform(svgRef.current.getScreenCTM().inverse());
|
|
96
|
+
const svgPoint = getSVGPoint(svgRef.current, event);
|
|
100
97
|
mousePosition.current = {
|
|
101
|
-
x:
|
|
102
|
-
y:
|
|
98
|
+
x: svgPoint.x,
|
|
99
|
+
y: svgPoint.y
|
|
103
100
|
};
|
|
104
|
-
const outsideX =
|
|
105
|
-
const outsideY =
|
|
101
|
+
const outsideX = svgPoint.x < left || svgPoint.x > left + width;
|
|
102
|
+
const outsideY = svgPoint.y < top || svgPoint.y > top + height;
|
|
106
103
|
if (outsideX || outsideY) {
|
|
107
104
|
dispatch({
|
|
108
|
-
type: '
|
|
109
|
-
data: {
|
|
110
|
-
x: null,
|
|
111
|
-
y: null
|
|
112
|
-
}
|
|
105
|
+
type: 'exitChart'
|
|
113
106
|
});
|
|
114
107
|
return;
|
|
115
108
|
}
|
|
116
|
-
const newStateX = getUpdate(xAxis[usedXAxis],
|
|
117
|
-
const newStateY = getUpdate(yAxis[usedYAxis],
|
|
109
|
+
const newStateX = getUpdate(xAxis[usedXAxis], svgPoint.x);
|
|
110
|
+
const newStateY = getUpdate(yAxis[usedYAxis], svgPoint.y);
|
|
118
111
|
dispatch({
|
|
119
112
|
type: 'updateAxis',
|
|
120
113
|
data: {
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
3
3
|
import { HighlighContext } from '../context/HighlightProvider';
|
|
4
|
-
export const useInteractionItemProps = scope => {
|
|
4
|
+
export const useInteractionItemProps = (scope, skip) => {
|
|
5
5
|
const {
|
|
6
6
|
dispatch: dispatchInteraction
|
|
7
7
|
} = React.useContext(InteractionContext);
|
|
8
8
|
const {
|
|
9
9
|
dispatch: dispatchHighlight
|
|
10
10
|
} = React.useContext(HighlighContext);
|
|
11
|
+
if (skip) {
|
|
12
|
+
return () => ({});
|
|
13
|
+
}
|
|
11
14
|
const getInteractionItemProps = data => {
|
|
12
15
|
const onMouseEnter = () => {
|
|
13
16
|
dispatchInteraction({
|
package/modern/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/x-charts v7.0.0-alpha.
|
|
2
|
+
* @mui/x-charts v7.0.0-alpha.5
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -15,9 +15,11 @@ export * from './ChartsReferenceLine';
|
|
|
15
15
|
export * from './ChartsAxis';
|
|
16
16
|
export * from './ChartsXAxis';
|
|
17
17
|
export * from './ChartsYAxis';
|
|
18
|
+
export * from './ChartsText';
|
|
18
19
|
export * from './ChartsTooltip';
|
|
19
20
|
export * from './ChartsLegend';
|
|
20
21
|
export * from './ChartsAxisHighlight';
|
|
22
|
+
export * from './ChartsVoronoiHandler';
|
|
21
23
|
export * from './BarChart';
|
|
22
24
|
export * from './LineChart';
|
|
23
25
|
export * from './PieChart';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { getStringSize } from './domUtils';
|
|
3
|
+
export function getWordsByLines({
|
|
4
|
+
style,
|
|
5
|
+
needsComputation,
|
|
6
|
+
text
|
|
7
|
+
}) {
|
|
8
|
+
return text.split('\n').map(subText => _extends({
|
|
9
|
+
text: subText
|
|
10
|
+
}, needsComputation ? getStringSize(subText, style) : {
|
|
11
|
+
width: 0,
|
|
12
|
+
height: 0
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
@@ -2,4 +2,44 @@
|
|
|
2
2
|
export function getSymbol(shape) {
|
|
3
3
|
const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
|
|
4
4
|
return symbolNames.indexOf(shape) || 0;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Transform mouse event position to corrdinates inside the SVG.
|
|
8
|
+
* @param svg The SVG element
|
|
9
|
+
* @param event The mouseEvent to transform
|
|
10
|
+
*/
|
|
11
|
+
export function getSVGPoint(svg, event) {
|
|
12
|
+
const pt = svg.createSVGPoint();
|
|
13
|
+
pt.x = event.clientX;
|
|
14
|
+
pt.y = event.clientY;
|
|
15
|
+
return pt.matrixTransform(svg.getScreenCTM().inverse());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Helper that converts values and percentages into values.
|
|
20
|
+
* @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
|
|
21
|
+
* @param refValue The numerical value associated to 100%.
|
|
22
|
+
* @returns The numerical value associated to the provided value.
|
|
23
|
+
*/
|
|
24
|
+
export function getPercentageValue(value, refValue) {
|
|
25
|
+
if (typeof value === 'number') {
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
if (value === '100%') {
|
|
29
|
+
// Avoid potential rounding issues
|
|
30
|
+
return refValue;
|
|
31
|
+
}
|
|
32
|
+
if (value.endsWith('%')) {
|
|
33
|
+
const percentage = Number.parseFloat(value.slice(0, value.length - 1));
|
|
34
|
+
if (!Number.isNaN(percentage)) {
|
|
35
|
+
return percentage * refValue / 100;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (value.endsWith('px')) {
|
|
39
|
+
const val = Number.parseFloat(value.slice(0, value.length - 2));
|
|
40
|
+
if (!Number.isNaN(val)) {
|
|
41
|
+
return val;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
throw Error(`MUI-Charts: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
|
|
5
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-charts",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.5",
|
|
4
4
|
"description": "The community edition of the charts components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -28,13 +28,15 @@
|
|
|
28
28
|
"directory": "packages/x-charts"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@babel/runtime": "^7.23.
|
|
32
|
-
"@mui/base": "^5.0.0-beta.
|
|
33
|
-
"@mui/system": "^5.
|
|
31
|
+
"@babel/runtime": "^7.23.5",
|
|
32
|
+
"@mui/base": "^5.0.0-beta.27",
|
|
33
|
+
"@mui/system": "^5.15.0",
|
|
34
|
+
"@mui/utils": "^5.15.0",
|
|
34
35
|
"@react-spring/rafz": "^9.7.3",
|
|
35
36
|
"@react-spring/web": "^9.7.3",
|
|
36
37
|
"clsx": "^2.0.0",
|
|
37
38
|
"d3-color": "^3.1.0",
|
|
39
|
+
"d3-delaunay": "^6.0.4",
|
|
38
40
|
"d3-scale": "^4.0.2",
|
|
39
41
|
"d3-shape": "^3.2.0",
|
|
40
42
|
"prop-types": "^15.8.1"
|