@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 == null ? void 0 : 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 == null ? void 0 : 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/esm/index.js CHANGED
@@ -8,9 +8,11 @@ export * from './ChartsReferenceLine';
8
8
  export * from './ChartsAxis';
9
9
  export * from './ChartsXAxis';
10
10
  export * from './ChartsYAxis';
11
+ export * from './ChartsText';
11
12
  export * from './ChartsTooltip';
12
13
  export * from './ChartsLegend';
13
14
  export * from './ChartsAxisHighlight';
15
+ export * from './ChartsVoronoiHandler';
14
16
  export * from './BarChart';
15
17
  export * from './LineChart';
16
18
  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
  }
@@ -9,8 +9,12 @@ var _InteractionProvider = require("../context/InteractionProvider");
9
9
  var _CartesianContextProvider = require("../context/CartesianContextProvider");
10
10
  var _DrawingProvider = require("../context/DrawingProvider");
11
11
  var _isBandScale = require("../internals/isBandScale");
12
+ var _utils = require("../internals/utils");
12
13
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
14
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
+ function getAsANumber(value) {
16
+ return value instanceof Date ? value.getTime() : value;
17
+ }
14
18
  const useAxisEvents = disableAxisListener => {
15
19
  const svgRef = React.useContext(_DrawingProvider.SVGContext);
16
20
  const {
@@ -56,17 +60,18 @@ const useAxisEvents = disableAxisListener => {
56
60
  value
57
61
  };
58
62
  }
59
- const closestIndex = axisData?.findIndex((v, index) => {
60
- if (v > value) {
61
- // @ts-ignore
62
- if (index === 0 || Math.abs(value - v) <= Math.abs(value - axisData[index - 1])) {
63
+ const valueAsNumber = getAsANumber(value);
64
+ const closestIndex = axisData?.findIndex((pointValue, index) => {
65
+ const v = getAsANumber(pointValue);
66
+ if (v > valueAsNumber) {
67
+ if (index === 0 || Math.abs(valueAsNumber - v) <= Math.abs(valueAsNumber - getAsANumber(axisData[index - 1]))) {
63
68
  return true;
64
69
  }
65
70
  }
66
- if (v <= value) {
71
+ if (v <= valueAsNumber) {
67
72
  if (index === axisData.length - 1 ||
68
73
  // @ts-ignore
69
- Math.abs(value - v) < Math.abs(value - axisData[index + 1])) {
74
+ Math.abs(value - v) < Math.abs(value - getAsANumber(axisData[index + 1]))) {
70
75
  return true;
71
76
  }
72
77
  }
@@ -92,37 +97,25 @@ const useAxisEvents = disableAxisListener => {
92
97
  y: -1
93
98
  };
94
99
  dispatch({
95
- type: 'updateAxis',
96
- data: {
97
- x: null,
98
- y: null
99
- }
100
+ type: 'exitChart'
100
101
  });
101
102
  };
102
103
  const handleMouseMove = event => {
103
- // Get mouse coordinate in global SVG space
104
- const pt = svgRef.current.createSVGPoint();
105
- pt.x = event.clientX;
106
- pt.y = event.clientY;
107
- const svgPt = pt.matrixTransform(svgRef.current.getScreenCTM().inverse());
104
+ const svgPoint = (0, _utils.getSVGPoint)(svgRef.current, event);
108
105
  mousePosition.current = {
109
- x: svgPt.x,
110
- y: svgPt.y
106
+ x: svgPoint.x,
107
+ y: svgPoint.y
111
108
  };
112
- const outsideX = svgPt.x < left || svgPt.x > left + width;
113
- const outsideY = svgPt.y < top || svgPt.y > top + height;
109
+ const outsideX = svgPoint.x < left || svgPoint.x > left + width;
110
+ const outsideY = svgPoint.y < top || svgPoint.y > top + height;
114
111
  if (outsideX || outsideY) {
115
112
  dispatch({
116
- type: 'updateAxis',
117
- data: {
118
- x: null,
119
- y: null
120
- }
113
+ type: 'exitChart'
121
114
  });
122
115
  return;
123
116
  }
124
- const newStateX = getUpdate(xAxis[usedXAxis], svgPt.x);
125
- const newStateY = getUpdate(yAxis[usedYAxis], svgPt.y);
117
+ const newStateX = getUpdate(xAxis[usedXAxis], svgPoint.x);
118
+ const newStateY = getUpdate(yAxis[usedYAxis], svgPoint.y);
126
119
  dispatch({
127
120
  type: 'updateAxis',
128
121
  data: {
@@ -1,8 +1,8 @@
1
1
  import { HighlightScope } from '../context/HighlightProvider';
2
2
  import { SeriesItemIdentifier } from '../models';
3
- export declare const useInteractionItemProps: (scope?: Partial<HighlightScope>) => (data: SeriesItemIdentifier) => {
3
+ export declare const useInteractionItemProps: (scope?: Partial<HighlightScope>, skip?: boolean) => (() => {}) | ((data: SeriesItemIdentifier) => {
4
4
  onMouseEnter: () => void;
5
5
  onMouseLeave: () => void;
6
- };
6
+ });
7
7
  export declare const getIsHighlighted: (selectedItem: SeriesItemIdentifier | null, currentItem: SeriesItemIdentifier, highlightScope?: Partial<HighlightScope>) => boolean;
8
8
  export declare const getIsFaded: (selectedItem: SeriesItemIdentifier | null, currentItem: SeriesItemIdentifier, highlightScope?: Partial<HighlightScope>) => boolean;
@@ -9,13 +9,16 @@ var _InteractionProvider = require("../context/InteractionProvider");
9
9
  var _HighlightProvider = require("../context/HighlightProvider");
10
10
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
11
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
- const useInteractionItemProps = scope => {
12
+ const useInteractionItemProps = (scope, skip) => {
13
13
  const {
14
14
  dispatch: dispatchInteraction
15
15
  } = React.useContext(_InteractionProvider.InteractionContext);
16
16
  const {
17
17
  dispatch: dispatchHighlight
18
18
  } = React.useContext(_HighlightProvider.HighlighContext);
19
+ if (skip) {
20
+ return () => ({});
21
+ }
19
22
  const getInteractionItemProps = data => {
20
23
  const onMouseEnter = () => {
21
24
  dispatchInteraction({
package/index.d.ts CHANGED
@@ -8,9 +8,11 @@ export * from './ChartsReferenceLine';
8
8
  export * from './ChartsAxis';
9
9
  export * from './ChartsXAxis';
10
10
  export * from './ChartsYAxis';
11
+ export * from './ChartsText';
11
12
  export * from './ChartsTooltip';
12
13
  export * from './ChartsLegend';
13
14
  export * from './ChartsAxisHighlight';
15
+ export * from './ChartsVoronoiHandler';
14
16
  export * from './BarChart';
15
17
  export * from './LineChart';
16
18
  export * from './PieChart';
package/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
@@ -120,6 +120,17 @@ Object.keys(_ChartsYAxis).forEach(function (key) {
120
120
  }
121
121
  });
122
122
  });
123
+ var _ChartsText = require("./ChartsText");
124
+ Object.keys(_ChartsText).forEach(function (key) {
125
+ if (key === "default" || key === "__esModule") return;
126
+ if (key in exports && exports[key] === _ChartsText[key]) return;
127
+ Object.defineProperty(exports, key, {
128
+ enumerable: true,
129
+ get: function () {
130
+ return _ChartsText[key];
131
+ }
132
+ });
133
+ });
123
134
  var _ChartsTooltip = require("./ChartsTooltip");
124
135
  Object.keys(_ChartsTooltip).forEach(function (key) {
125
136
  if (key === "default" || key === "__esModule") return;
@@ -153,6 +164,17 @@ Object.keys(_ChartsAxisHighlight).forEach(function (key) {
153
164
  }
154
165
  });
155
166
  });
167
+ var _ChartsVoronoiHandler = require("./ChartsVoronoiHandler");
168
+ Object.keys(_ChartsVoronoiHandler).forEach(function (key) {
169
+ if (key === "default" || key === "__esModule") return;
170
+ if (key in exports && exports[key] === _ChartsVoronoiHandler[key]) return;
171
+ Object.defineProperty(exports, key, {
172
+ enumerable: true,
173
+ get: function () {
174
+ return _ChartsVoronoiHandler[key];
175
+ }
176
+ });
177
+ });
156
178
  var _BarChart = require("./BarChart");
157
179
  Object.keys(_BarChart).forEach(function (key) {
158
180
  if (key === "default" || key === "__esModule") return;
@@ -7,8 +7,8 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
7
7
  id?: string | number | undefined;
8
8
  }[];
9
9
  type: "pie";
10
- innerRadius?: number | undefined;
11
- outerRadius?: number | undefined;
10
+ innerRadius?: string | number | undefined;
11
+ outerRadius?: string | number | undefined;
12
12
  cornerRadius?: number | undefined;
13
13
  startAngle?: number | undefined;
14
14
  endAngle?: number | undefined;
@@ -16,8 +16,8 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
16
16
  sortingValues?: import("../models/seriesType").ChartsPieSorting | undefined;
17
17
  arcLabel?: "label" | "value" | "formattedValue" | ((item: import("../models/seriesType").DefaultizedPieValueType) => string) | undefined;
18
18
  arcLabelMinAngle?: number | undefined;
19
- cx?: number | undefined;
20
- cy?: number | undefined;
19
+ cx?: string | number | undefined;
20
+ cy?: string | number | undefined;
21
21
  highlighted?: {
22
22
  additionalRadius?: number | undefined;
23
23
  innerRadius?: number | undefined;
@@ -77,6 +77,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
77
77
  data: import("../models/seriesType").ScatterValueType[];
78
78
  markerSize?: number | undefined;
79
79
  label?: string | undefined;
80
+ disableHover?: boolean | undefined;
80
81
  id?: string | undefined;
81
82
  color: string;
82
83
  valueFormatter?: ((value: import("../models/seriesType").ScatterValueType) => string) | undefined;
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ /// <reference types="react" />
2
2
  export type ChartsTextBaseline = 'hanging' | 'central' | 'auto';
3
3
  export interface ChartsTextStyle extends React.CSSProperties {
4
4
  angle?: number;
@@ -8,7 +8,7 @@ export interface ChartsTextStyle extends React.CSSProperties {
8
8
  */
9
9
  dominantBaseline?: ChartsTextBaseline;
10
10
  }
11
- interface GetWordsByLinesParams {
11
+ export interface GetWordsByLinesParams {
12
12
  /**
13
13
  * Text displayed.
14
14
  */
@@ -23,13 +23,4 @@ interface GetWordsByLinesParams {
23
23
  */
24
24
  needsComputation?: boolean;
25
25
  }
26
- export interface ChartsTextProps extends Omit<React.SVGTextElementAttributes<SVGTextElement>, 'width' | 'ref' | 'style' | 'dominantBaseline'>, GetWordsByLinesParams {
27
- /**
28
- * Height of a text line (in `em`).
29
- */
30
- lineHeight?: number;
31
- ownerState?: any;
32
- }
33
26
  export declare function getWordsByLines({ style, needsComputation, text }: GetWordsByLinesParams): any[];
34
- export declare function ChartsText(props: ChartsTextProps): React.JSX.Element;
35
- export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getWordsByLines = getWordsByLines;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _domUtils = require("./domUtils");
10
+ function getWordsByLines({
11
+ style,
12
+ needsComputation,
13
+ text
14
+ }) {
15
+ return text.split('\n').map(subText => (0, _extends2.default)({
16
+ text: subText
17
+ }, needsComputation ? (0, _domUtils.getStringSize)(subText, style) : {
18
+ width: 0,
19
+ height: 0
20
+ }));
21
+ }
@@ -4,4 +4,17 @@ type Without<T, U> = {
4
4
  [P in Exclude<keyof T, keyof U>]?: never;
5
5
  };
6
6
  export type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
7
+ /**
8
+ * Transform mouse event position to corrdinates inside the SVG.
9
+ * @param svg The SVG element
10
+ * @param event The mouseEvent to transform
11
+ */
12
+ export declare function getSVGPoint(svg: SVGSVGElement, event: MouseEvent): DOMPoint;
13
+ /**
14
+ * Helper that converts values and percentages into values.
15
+ * @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
16
+ * @param refValue The numerical value associated to 100%.
17
+ * @returns The numerical value associated to the provided value.
18
+ */
19
+ export declare function getPercentageValue(value: number | string, refValue: number): number;
7
20
  export {};
@@ -3,9 +3,51 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.getPercentageValue = getPercentageValue;
7
+ exports.getSVGPoint = getSVGPoint;
6
8
  exports.getSymbol = getSymbol;
7
9
  // Returns the index of a defined shape
8
10
  function getSymbol(shape) {
9
11
  const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
10
12
  return symbolNames.indexOf(shape) || 0;
13
+ }
14
+ /**
15
+ * Transform mouse event position to corrdinates inside the SVG.
16
+ * @param svg The SVG element
17
+ * @param event The mouseEvent to transform
18
+ */
19
+ function getSVGPoint(svg, event) {
20
+ const pt = svg.createSVGPoint();
21
+ pt.x = event.clientX;
22
+ pt.y = event.clientY;
23
+ return pt.matrixTransform(svg.getScreenCTM().inverse());
24
+ }
25
+
26
+ /**
27
+ * Helper that converts values and percentages into values.
28
+ * @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
29
+ * @param refValue The numerical value associated to 100%.
30
+ * @returns The numerical value associated to the provided value.
31
+ */
32
+ function getPercentageValue(value, refValue) {
33
+ if (typeof value === 'number') {
34
+ return value;
35
+ }
36
+ if (value === '100%') {
37
+ // Avoid potential rounding issues
38
+ return refValue;
39
+ }
40
+ if (value.endsWith('%')) {
41
+ const percentage = Number.parseFloat(value.slice(0, value.length - 1));
42
+ if (!Number.isNaN(percentage)) {
43
+ return percentage * refValue / 100;
44
+ }
45
+ }
46
+ if (value.endsWith('px')) {
47
+ const val = Number.parseFloat(value.slice(0, value.length - 2));
48
+ if (!Number.isNaN(val)) {
49
+ return val;
50
+ }
51
+ }
52
+ throw Error(`MUI-Charts: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
11
53
  }
@@ -9,7 +9,8 @@ import { SeriesContext } from '../context/SeriesContextProvider';
9
9
  import { CartesianContext } from '../context/CartesianContextProvider';
10
10
  import { BarElement } from './BarElement';
11
11
  import { isBandScaleConfig } from '../models/axis';
12
- import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
13
+
13
14
  /**
14
15
  * Solution of the equations
15
16
  * W = barWidth * N + offset * (N-1)
@@ -19,6 +20,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
19
20
  * @param gapRatio The ratio of the gap between bars over the bar width.
20
21
  * @returns The bar width and the offset between bars.
21
22
  */
23
+ import { jsx as _jsx } from "react/jsx-runtime";
22
24
  function getBandSize(_ref) {
23
25
  var W = _ref.bandWidth,
24
26
  N = _ref.numberOfGroups,
@@ -64,18 +66,18 @@ var useCompletedData = function useCompletedData() {
64
66
  var baseScaleConfig;
65
67
  if (verticalLayout) {
66
68
  if (!isBandScaleConfig(xAxisConfig)) {
67
- throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
69
+ throw new Error("MUI-X-Charts: ".concat(xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : "The x-axis with id \"".concat(xAxisKey, "\""), " shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
68
70
  }
69
71
  if (xAxis[xAxisKey].data === undefined) {
70
- throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud have data property"));
72
+ throw new Error("MUI-X-Charts: ".concat(xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : "The x-axis with id \"".concat(xAxisKey, "\""), " shoud have data property"));
71
73
  }
72
74
  baseScaleConfig = xAxisConfig;
73
75
  } else {
74
76
  if (!isBandScaleConfig(yAxisConfig)) {
75
- throw new Error("Axis with id \"".concat(yAxisKey, "\" shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
77
+ throw new Error("MUI-X-Charts: ".concat(yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : "The y-axis with id \"".concat(yAxisKey, "\""), " shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
76
78
  }
77
79
  if (yAxis[yAxisKey].data === undefined) {
78
- throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud have data property"));
80
+ throw new Error("MUI-X-Charts: ".concat(yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : "The y-axis with id \"".concat(yAxisKey, "\""), " shoud have data property"));
79
81
  }
80
82
  baseScaleConfig = yAxisConfig;
81
83
  }
@@ -4,13 +4,15 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
4
  import { stack as d3Stack } from 'd3-shape';
5
5
  import { getStackingGroups } from '../internals/stackSeries';
6
6
  import defaultizeValueFormatter from '../internals/defaultizeValueFormatter';
7
+ var warnOnce = false;
7
8
  var formatter = function formatter(params, dataset) {
9
+ var _ref;
8
10
  var seriesOrder = params.seriesOrder,
9
11
  series = params.series;
10
12
  var stackingGroups = getStackingGroups(params);
11
13
 
12
14
  // Create a data set with format adapted to d3
13
- var d3Dataset = dataset != null ? dataset : [];
15
+ var d3Dataset = (_ref = dataset) != null ? _ref : [];
14
16
  seriesOrder.forEach(function (id) {
15
17
  var data = series[id].data;
16
18
  if (data !== undefined) {
@@ -22,7 +24,7 @@ var formatter = function formatter(params, dataset) {
22
24
  }
23
25
  });
24
26
  } else if (dataset === undefined) {
25
- throw new Error(["MUI: bar series with id='".concat(id, "' has no data."), 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
27
+ throw new Error(["MUI-X-Charts: bar series with id='".concat(id, "' has no data."), 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
26
28
  }
27
29
  });
28
30
  var completedSeries = {};
@@ -35,19 +37,31 @@ var formatter = function formatter(params, dataset) {
35
37
  // Use dataKey if needed and available
36
38
  var dataKey = series[id].dataKey;
37
39
  return series[id].data === undefined && dataKey !== undefined ? dataKey : id;
38
- })).order(stackingOrder).offset(stackingOffset)(d3Dataset);
40
+ })).value(function (d, key) {
41
+ var _d$key;
42
+ return (_d$key = d[key]) != null ? _d$key : 0;
43
+ }) // defaultize null value to 0
44
+ .order(stackingOrder).offset(stackingOffset)(d3Dataset);
39
45
  ids.forEach(function (id, index) {
40
46
  var dataKey = series[id].dataKey;
41
47
  completedSeries[id] = _extends({
42
48
  layout: 'vertical'
43
49
  }, series[id], {
44
- data: dataKey ? dataset.map(function (d) {
45
- return d[dataKey];
50
+ data: dataKey ? dataset.map(function (data) {
51
+ var value = data[dataKey];
52
+ if (typeof value !== 'number') {
53
+ if (process.env.NODE_ENV !== 'production' && !warnOnce && value !== null) {
54
+ warnOnce = true;
55
+ console.error(["MUI-X charts: your dataset key \"".concat(dataKey, "\" is used for plotting bars, but contains nonnumerical elements."), 'Bar plots only support numbers and null values.']);
56
+ }
57
+ return 0;
58
+ }
59
+ return value;
46
60
  }) : series[id].data,
47
- stackedData: stackedSeries[index].map(function (_ref) {
48
- var _ref2 = _slicedToArray(_ref, 2),
49
- a = _ref2[0],
50
- b = _ref2[1];
61
+ stackedData: stackedSeries[index].map(function (_ref2) {
62
+ var _ref3 = _slicedToArray(_ref2, 2),
63
+ a = _ref3[0],
64
+ b = _ref3[1];
51
65
  return [a, b];
52
66
  })
53
67
  });
@@ -57,16 +57,16 @@ function ChartsAxis(props) {
57
57
  var topId = getAxisId(topAxis);
58
58
  var rightId = getAxisId(rightAxis);
59
59
  if (topId !== null && !xAxis[topId]) {
60
- throw Error("MUI: id used for top axis \"".concat(topId, "\" is not defined"));
60
+ throw Error(["MUI-X-Charts: id used for top axis \"".concat(topId, "\" is not defined."), "Available ids are: ".concat(xAxisIds.join(', '), ".")].join('\n'));
61
61
  }
62
62
  if (leftId !== null && !yAxis[leftId]) {
63
- throw Error("MUI: id used for left axis \"".concat(leftId, "\" is not defined"));
63
+ throw Error(["MUI-X-Charts: id used for left axis \"".concat(leftId, "\" is not defined."), "Available ids are: ".concat(yAxisIds.join(', '), ".")].join('\n'));
64
64
  }
65
65
  if (rightId !== null && !yAxis[rightId]) {
66
- throw Error("MUI: id used for right axis \"".concat(rightId, "\" is not defined"));
66
+ throw Error(["MUI-X-Charts: id used for right axis \"".concat(rightId, "\" is not defined."), "Available ids are: ".concat(yAxisIds.join(', '), ".")].join('\n'));
67
67
  }
68
68
  if (bottomId !== null && !xAxis[bottomId]) {
69
- throw Error("MUI: id used for bottom axis \"".concat(bottomId, "\" is not defined"));
69
+ throw Error(["MUI-X-Charts: id used for bottom axis \"".concat(bottomId, "\" is not defined."), "Available ids are: ".concat(xAxisIds.join(', '), ".")].join('\n'));
70
70
  }
71
71
  var topAxisProps = mergeProps(topAxis, slots, slotProps);
72
72
  var bottomAxisProps = mergeProps(bottomAxis, slots, slotProps);
@@ -13,7 +13,8 @@ import { DrawingContext } from '../context/DrawingProvider';
13
13
  import { getSeriesToDisplay } from './utils';
14
14
  import { SeriesContext } from '../context/SeriesContextProvider';
15
15
  import { getLegendUtilityClass } from './chartsLegendClasses';
16
- import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
16
+ import { ChartsText } from '../ChartsText';
17
+ import { getWordsByLines } from '../internals/getWordsByLines';
17
18
  import { jsx as _jsx } from "react/jsx-runtime";
18
19
  import { jsxs as _jsxs } from "react/jsx-runtime";
19
20
  var useUtilityClasses = function useUtilityClasses(ownerState) {