@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.
Files changed (160) hide show
  1. package/BarChart/BarPlot.js +7 -6
  2. package/BarChart/formatter.js +15 -3
  3. package/CHANGELOG.md +465 -0
  4. package/ChartsAxis/ChartsAxis.js +4 -4
  5. package/ChartsLegend/ChartsLegend.d.ts +1 -1
  6. package/ChartsLegend/ChartsLegend.js +3 -2
  7. package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  8. package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  9. package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  10. package/ChartsReferenceLine/common.d.ts +1 -1
  11. package/ChartsText/ChartsText.d.ts +17 -0
  12. package/{internals/components → ChartsText}/ChartsText.js +32 -17
  13. package/ChartsText/index.d.ts +3 -0
  14. package/ChartsText/index.js +12 -0
  15. package/ChartsText/package.json +6 -0
  16. package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +14 -0
  17. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +174 -0
  18. package/ChartsVoronoiHandler/index.d.ts +1 -0
  19. package/ChartsVoronoiHandler/index.js +16 -0
  20. package/ChartsVoronoiHandler/package.json +6 -0
  21. package/ChartsXAxis/ChartsXAxis.js +3 -2
  22. package/ChartsYAxis/ChartsYAxis.js +1 -1
  23. package/LineChart/AreaPlot.js +3 -2
  24. package/LineChart/LineHighlightPlot.js +2 -1
  25. package/LineChart/LinePlot.js +3 -2
  26. package/LineChart/MarkPlot.js +2 -1
  27. package/LineChart/formatter.js +14 -2
  28. package/PieChart/PieArcLabelPlot.d.ts +2 -3
  29. package/PieChart/PieArcLabelPlot.js +0 -1
  30. package/PieChart/PieArcPlot.d.ts +2 -3
  31. package/PieChart/PieArcPlot.js +0 -1
  32. package/PieChart/PieChart.js +4 -4
  33. package/PieChart/PiePlot.js +20 -15
  34. package/PieChart/dataTransform/useTransformData.d.ts +2 -3
  35. package/ResponsiveChartContainer/index.js +2 -2
  36. package/ScatterChart/Scatter.js +14 -5
  37. package/ScatterChart/ScatterChart.d.ts +7 -1
  38. package/ScatterChart/ScatterChart.js +18 -1
  39. package/SparkLineChart/SparkLineChart.js +1 -0
  40. package/context/CartesianContextProvider.js +2 -2
  41. package/context/InteractionProvider.d.ts +10 -0
  42. package/context/InteractionProvider.js +21 -1
  43. package/context/SeriesContextProvider.js +1 -1
  44. package/esm/BarChart/BarPlot.js +7 -5
  45. package/esm/BarChart/formatter.js +20 -4
  46. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  47. package/esm/ChartsLegend/ChartsLegend.js +2 -1
  48. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  49. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  50. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  51. package/esm/{internals/components → ChartsText}/ChartsText.js +33 -16
  52. package/esm/ChartsText/index.js +1 -0
  53. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +168 -0
  54. package/esm/ChartsVoronoiHandler/index.js +1 -0
  55. package/esm/ChartsXAxis/ChartsXAxis.js +2 -1
  56. package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
  57. package/esm/LineChart/AreaPlot.js +3 -2
  58. package/esm/LineChart/LineHighlightPlot.js +2 -1
  59. package/esm/LineChart/LinePlot.js +3 -2
  60. package/esm/LineChart/MarkPlot.js +2 -1
  61. package/esm/LineChart/formatter.js +16 -3
  62. package/esm/PieChart/PieArcLabelPlot.js +0 -1
  63. package/esm/PieChart/PieArcPlot.js +0 -1
  64. package/esm/PieChart/PieChart.js +4 -4
  65. package/esm/PieChart/PiePlot.js +20 -15
  66. package/esm/ResponsiveChartContainer/index.js +2 -2
  67. package/esm/ScatterChart/Scatter.js +14 -5
  68. package/esm/ScatterChart/ScatterChart.js +18 -1
  69. package/esm/SparkLineChart/SparkLineChart.js +1 -0
  70. package/esm/context/CartesianContextProvider.js +2 -2
  71. package/esm/context/InteractionProvider.js +21 -1
  72. package/esm/context/SeriesContextProvider.js +1 -1
  73. package/esm/hooks/useAxisEvents.js +20 -27
  74. package/esm/hooks/useInteractionItemProps.js +4 -1
  75. package/esm/index.js +2 -0
  76. package/esm/internals/getWordsByLines.js +14 -0
  77. package/esm/internals/utils.js +40 -0
  78. package/hooks/useAxisEvents.js +20 -27
  79. package/hooks/useInteractionItemProps.d.ts +2 -2
  80. package/hooks/useInteractionItemProps.js +4 -1
  81. package/index.d.ts +2 -0
  82. package/index.js +23 -1
  83. package/internals/defaultizeColor.d.ts +5 -4
  84. package/internals/{components/ChartsText.d.ts → getWordsByLines.d.ts} +2 -11
  85. package/internals/getWordsByLines.js +21 -0
  86. package/internals/utils.d.ts +13 -0
  87. package/internals/utils.js +42 -0
  88. package/legacy/BarChart/BarPlot.js +7 -5
  89. package/legacy/BarChart/formatter.js +23 -9
  90. package/legacy/ChartsAxis/ChartsAxis.js +4 -4
  91. package/legacy/ChartsLegend/ChartsLegend.js +2 -1
  92. package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  93. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  94. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  95. package/legacy/{internals/components → ChartsText}/ChartsText.js +38 -22
  96. package/legacy/ChartsText/index.js +1 -0
  97. package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +162 -0
  98. package/legacy/ChartsVoronoiHandler/index.js +1 -0
  99. package/legacy/ChartsXAxis/ChartsXAxis.js +2 -1
  100. package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
  101. package/legacy/LineChart/AreaPlot.js +3 -2
  102. package/legacy/LineChart/LineHighlightPlot.js +2 -1
  103. package/legacy/LineChart/LinePlot.js +3 -2
  104. package/legacy/LineChart/MarkPlot.js +2 -1
  105. package/legacy/LineChart/formatter.js +19 -8
  106. package/legacy/PieChart/PieArcLabelPlot.js +0 -1
  107. package/legacy/PieChart/PieArcPlot.js +0 -1
  108. package/legacy/PieChart/PieChart.js +4 -4
  109. package/legacy/PieChart/PiePlot.js +20 -15
  110. package/legacy/ResponsiveChartContainer/index.js +2 -2
  111. package/legacy/ScatterChart/Scatter.js +17 -6
  112. package/legacy/ScatterChart/ScatterChart.js +18 -1
  113. package/legacy/SparkLineChart/SparkLineChart.js +1 -0
  114. package/legacy/context/CartesianContextProvider.js +2 -2
  115. package/legacy/context/InteractionProvider.js +21 -1
  116. package/legacy/context/SeriesContextProvider.js +1 -1
  117. package/legacy/hooks/useAxisEvents.js +20 -27
  118. package/legacy/hooks/useInteractionItemProps.js +6 -1
  119. package/legacy/index.js +3 -1
  120. package/legacy/internals/getWordsByLines.js +15 -0
  121. package/legacy/internals/utils.js +40 -0
  122. package/models/axis.d.ts +1 -1
  123. package/models/seriesType/config.d.ts +4 -3
  124. package/models/seriesType/pie.d.ts +29 -7
  125. package/models/seriesType/scatter.d.ts +5 -0
  126. package/modern/BarChart/BarPlot.js +7 -5
  127. package/modern/BarChart/formatter.js +15 -3
  128. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  129. package/modern/ChartsLegend/ChartsLegend.js +2 -1
  130. package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  131. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  132. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  133. package/modern/{internals/components → ChartsText}/ChartsText.js +33 -16
  134. package/modern/ChartsText/index.js +1 -0
  135. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +166 -0
  136. package/modern/ChartsVoronoiHandler/index.js +1 -0
  137. package/modern/ChartsXAxis/ChartsXAxis.js +2 -1
  138. package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
  139. package/modern/LineChart/AreaPlot.js +3 -2
  140. package/modern/LineChart/LineHighlightPlot.js +2 -1
  141. package/modern/LineChart/LinePlot.js +3 -2
  142. package/modern/LineChart/MarkPlot.js +2 -1
  143. package/modern/LineChart/formatter.js +14 -2
  144. package/modern/PieChart/PieArcLabelPlot.js +0 -1
  145. package/modern/PieChart/PieArcPlot.js +0 -1
  146. package/modern/PieChart/PieChart.js +4 -4
  147. package/modern/PieChart/PiePlot.js +20 -15
  148. package/modern/ResponsiveChartContainer/index.js +2 -2
  149. package/modern/ScatterChart/Scatter.js +14 -5
  150. package/modern/ScatterChart/ScatterChart.js +18 -1
  151. package/modern/SparkLineChart/SparkLineChart.js +1 -0
  152. package/modern/context/CartesianContextProvider.js +2 -2
  153. package/modern/context/InteractionProvider.js +21 -1
  154. package/modern/context/SeriesContextProvider.js +1 -1
  155. package/modern/hooks/useAxisEvents.js +20 -27
  156. package/modern/hooks/useInteractionItemProps.js +4 -1
  157. package/modern/index.js +3 -1
  158. package/modern/internals/getWordsByLines.js +14 -0
  159. package/modern/internals/utils.js +40 -0
  160. 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 closestIndex = axisData?.findIndex((v, index) => {
52
- if (v > value) {
53
- // @ts-ignore
54
- if (index === 0 || Math.abs(value - v) <= Math.abs(value - axisData[index - 1])) {
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 <= value) {
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: 'updateAxis',
88
- data: {
89
- x: null,
90
- y: null
91
- }
92
+ type: 'exitChart'
92
93
  });
93
94
  };
94
95
  const handleMouseMove = event => {
95
- // Get mouse coordinate in global SVG space
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: svgPt.x,
102
- y: svgPt.y
98
+ x: svgPoint.x,
99
+ y: svgPoint.y
103
100
  };
104
- const outsideX = svgPt.x < left || svgPt.x > left + width;
105
- const outsideY = svgPt.y < top || svgPt.y > top + height;
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: 'updateAxis',
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], svgPt.x);
117
- const newStateY = getUpdate(yAxis[usedYAxis], svgPt.y);
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.3
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",
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.4",
32
- "@mui/base": "^5.0.0-beta.24",
33
- "@mui/system": "^5.14.18",
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"