@mui/x-charts 6.0.0-alpha.1 → 6.0.0-alpha.3

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 (179) hide show
  1. package/BarChart/BarChart.d.ts +1 -4
  2. package/BarChart/BarChart.js +6 -3
  3. package/BarChart/BarPlot.js +42 -8
  4. package/BarChart/legend.d.ts +3 -0
  5. package/BarChart/legend.js +20 -0
  6. package/CHANGELOG.md +287 -107
  7. package/ChartContainer/index.d.ts +3 -1
  8. package/ChartContainer/index.js +10 -6
  9. package/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
  10. package/ChartsLegend/ChartsLegend.d.ts +5 -1
  11. package/ChartsLegend/ChartsLegend.js +5 -1
  12. package/ChartsLegend/utils.d.ts +1 -1
  13. package/ChartsLegend/utils.js +12 -1
  14. package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  15. package/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
  16. package/LineChart/LineChart.d.ts +1 -4
  17. package/LineChart/LineChart.js +6 -3
  18. package/LineChart/legend.d.ts +3 -0
  19. package/LineChart/legend.js +20 -0
  20. package/PieChart/PieArc.d.ts +36 -0
  21. package/PieChart/PieArc.js +128 -0
  22. package/PieChart/PieArcLabel.d.ts +36 -0
  23. package/PieChart/PieArcLabel.js +113 -0
  24. package/PieChart/PieChart.d.ts +20 -0
  25. package/PieChart/PieChart.js +292 -0
  26. package/PieChart/PiePlot.d.ts +2 -0
  27. package/PieChart/PiePlot.js +98 -0
  28. package/PieChart/formatter.d.ts +3 -0
  29. package/PieChart/formatter.js +49 -0
  30. package/PieChart/index.d.ts +4 -0
  31. package/PieChart/index.js +47 -0
  32. package/PieChart/legend.d.ts +3 -0
  33. package/PieChart/legend.js +19 -0
  34. package/PieChart/package.json +6 -0
  35. package/README.md +2 -2
  36. package/ResponsiveChartContainer/index.d.ts +1 -1
  37. package/ResponsiveChartContainer/index.js +22 -9
  38. package/ScatterChart/Scatter.d.ts +1 -1
  39. package/ScatterChart/Scatter.js +1 -1
  40. package/ScatterChart/ScatterChart.d.ts +1 -4
  41. package/ScatterChart/ScatterChart.js +6 -3
  42. package/ScatterChart/legend.d.ts +3 -0
  43. package/ScatterChart/legend.js +20 -0
  44. package/context/CartesianContextProvider.js +31 -20
  45. package/context/SeriesContextProvider.js +11 -1
  46. package/esm/BarChart/BarChart.js +4 -2
  47. package/esm/BarChart/BarPlot.js +44 -8
  48. package/esm/BarChart/legend.js +13 -0
  49. package/esm/ChartContainer/index.js +7 -5
  50. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
  51. package/esm/ChartsLegend/ChartsLegend.js +5 -1
  52. package/esm/ChartsLegend/utils.js +11 -1
  53. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  54. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +11 -3
  55. package/esm/LineChart/LineChart.js +4 -2
  56. package/esm/LineChart/legend.js +13 -0
  57. package/esm/PieChart/PieArc.js +117 -0
  58. package/esm/PieChart/PieArcLabel.js +101 -0
  59. package/esm/PieChart/PieChart.js +285 -0
  60. package/esm/PieChart/PiePlot.js +92 -0
  61. package/esm/PieChart/formatter.js +48 -0
  62. package/esm/PieChart/index.js +4 -0
  63. package/esm/PieChart/legend.js +12 -0
  64. package/esm/ResponsiveChartContainer/index.js +20 -8
  65. package/esm/ScatterChart/Scatter.js +1 -1
  66. package/esm/ScatterChart/ScatterChart.js +4 -2
  67. package/esm/ScatterChart/legend.js +13 -0
  68. package/esm/context/CartesianContextProvider.js +31 -18
  69. package/esm/context/SeriesContextProvider.js +11 -1
  70. package/esm/hooks/index.js +2 -0
  71. package/esm/hooks/useAxisEvents.js +12 -7
  72. package/esm/hooks/useDrawingArea.js +16 -0
  73. package/esm/hooks/useScale.js +19 -21
  74. package/esm/hooks/useTicks.js +26 -13
  75. package/esm/index.js +2 -0
  76. package/esm/internals/defaultizeColor.js +7 -0
  77. package/esm/internals/getScale.js +17 -0
  78. package/esm/internals/isBandScale.js +3 -0
  79. package/esm/models/axis.js +6 -1
  80. package/esm/models/seriesType/index.js +1 -8
  81. package/hooks/index.d.ts +2 -0
  82. package/hooks/index.js +27 -0
  83. package/hooks/package.json +6 -0
  84. package/hooks/useAxisEvents.js +14 -9
  85. package/hooks/useDrawingArea.d.ts +6 -0
  86. package/hooks/useDrawingArea.js +24 -0
  87. package/hooks/useScale.d.ts +3 -6
  88. package/hooks/useScale.js +24 -24
  89. package/hooks/useTicks.d.ts +1 -1
  90. package/hooks/useTicks.js +19 -9
  91. package/index.d.ts +2 -0
  92. package/index.js +23 -1
  93. package/internals/defaultizeColor.d.ts +35 -0
  94. package/internals/defaultizeColor.js +7 -0
  95. package/internals/getScale.d.ts +2 -0
  96. package/internals/getScale.js +23 -0
  97. package/internals/isBandScale.d.ts +3 -0
  98. package/internals/isBandScale.js +9 -0
  99. package/legacy/BarChart/BarChart.js +4 -2
  100. package/legacy/BarChart/BarPlot.js +44 -10
  101. package/legacy/BarChart/legend.js +15 -0
  102. package/legacy/ChartContainer/index.js +7 -5
  103. package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
  104. package/legacy/ChartsLegend/ChartsLegend.js +5 -1
  105. package/legacy/ChartsLegend/utils.js +12 -6
  106. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +3 -1
  107. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +10 -3
  108. package/legacy/LineChart/LineChart.js +4 -2
  109. package/legacy/LineChart/legend.js +15 -0
  110. package/legacy/PieChart/PieArc.js +118 -0
  111. package/legacy/PieChart/PieArcLabel.js +101 -0
  112. package/legacy/PieChart/PieChart.js +297 -0
  113. package/legacy/PieChart/PiePlot.js +89 -0
  114. package/legacy/PieChart/formatter.js +55 -0
  115. package/legacy/PieChart/index.js +4 -0
  116. package/legacy/PieChart/legend.js +16 -0
  117. package/legacy/ResponsiveChartContainer/index.js +18 -8
  118. package/legacy/ScatterChart/Scatter.js +1 -1
  119. package/legacy/ScatterChart/ScatterChart.js +4 -2
  120. package/legacy/ScatterChart/legend.js +15 -0
  121. package/legacy/context/CartesianContextProvider.js +31 -18
  122. package/legacy/context/SeriesContextProvider.js +11 -1
  123. package/legacy/hooks/index.js +2 -0
  124. package/legacy/hooks/useAxisEvents.js +12 -7
  125. package/legacy/hooks/useDrawingArea.js +17 -0
  126. package/legacy/hooks/useScale.js +17 -21
  127. package/legacy/hooks/useTicks.js +26 -13
  128. package/legacy/index.js +3 -1
  129. package/legacy/internals/defaultizeColor.js +9 -0
  130. package/legacy/internals/getScale.js +17 -0
  131. package/legacy/internals/isBandScale.js +3 -0
  132. package/legacy/models/axis.js +6 -1
  133. package/legacy/models/seriesType/index.js +1 -8
  134. package/models/axis.d.ts +25 -12
  135. package/models/axis.js +9 -1
  136. package/models/seriesType/bar.d.ts +1 -1
  137. package/models/seriesType/common.d.ts +1 -1
  138. package/models/seriesType/config.d.ts +29 -2
  139. package/models/seriesType/index.d.ts +7 -3
  140. package/models/seriesType/index.js +11 -0
  141. package/models/seriesType/line.d.ts +1 -1
  142. package/models/seriesType/pie.d.ts +103 -3
  143. package/models/seriesType/scatter.d.ts +1 -1
  144. package/modern/BarChart/BarChart.js +4 -2
  145. package/modern/BarChart/BarPlot.js +44 -8
  146. package/modern/BarChart/legend.js +13 -0
  147. package/modern/ChartContainer/index.js +7 -5
  148. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
  149. package/modern/ChartsLegend/ChartsLegend.js +5 -1
  150. package/modern/ChartsLegend/utils.js +11 -1
  151. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  152. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
  153. package/modern/LineChart/LineChart.js +4 -2
  154. package/modern/LineChart/legend.js +13 -0
  155. package/modern/PieChart/PieArc.js +116 -0
  156. package/modern/PieChart/PieArcLabel.js +101 -0
  157. package/modern/PieChart/PieChart.js +285 -0
  158. package/modern/PieChart/PiePlot.js +91 -0
  159. package/modern/PieChart/formatter.js +41 -0
  160. package/modern/PieChart/index.js +4 -0
  161. package/modern/PieChart/legend.js +12 -0
  162. package/modern/ResponsiveChartContainer/index.js +20 -8
  163. package/modern/ScatterChart/Scatter.js +1 -1
  164. package/modern/ScatterChart/ScatterChart.js +4 -2
  165. package/modern/ScatterChart/legend.js +13 -0
  166. package/modern/context/CartesianContextProvider.js +29 -18
  167. package/modern/context/SeriesContextProvider.js +11 -1
  168. package/modern/hooks/index.js +2 -0
  169. package/modern/hooks/useAxisEvents.js +12 -7
  170. package/modern/hooks/useDrawingArea.js +16 -0
  171. package/modern/hooks/useScale.js +19 -21
  172. package/modern/hooks/useTicks.js +18 -8
  173. package/modern/index.js +3 -1
  174. package/modern/internals/defaultizeColor.js +7 -0
  175. package/modern/internals/getScale.js +17 -0
  176. package/modern/internals/isBandScale.js +3 -0
  177. package/modern/models/axis.js +6 -1
  178. package/modern/models/seriesType/index.js +1 -8
  179. package/package.json +1 -1
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import { InteractionContext } from '../context/InteractionProvider';
3
3
  import { CartesianContext } from '../context/CartesianContextProvider';
4
4
  import { SVGContext, DrawingContext } from '../context/DrawingProvider';
5
- import { isBandScale } from './useScale';
5
+ import { isBandScale } from '../internals/isBandScale';
6
6
  export const useAxisEvents = disableAxisListener => {
7
7
  const svgRef = React.useContext(SVGContext);
8
8
  const {
@@ -109,12 +109,17 @@ export const useAxisEvents = disableAxisListener => {
109
109
  });
110
110
  };
111
111
  const handleMouseMove = event => {
112
+ // Get mouse coordinate in global SVG space
113
+ const pt = svgRef.current.createSVGPoint();
114
+ pt.x = event.clientX;
115
+ pt.y = event.clientY;
116
+ const svgPt = pt.matrixTransform(svgRef.current.getScreenCTM().inverse());
112
117
  mousePosition.current = {
113
- x: event.offsetX,
114
- y: event.offsetY
118
+ x: svgPt.x,
119
+ y: svgPt.y
115
120
  };
116
- const outsideX = event.offsetX < left || event.offsetX > left + width;
117
- const outsideY = event.offsetY < top || event.offsetY > top + height;
121
+ const outsideX = svgPt.x < left || svgPt.x > left + width;
122
+ const outsideY = svgPt.y < top || svgPt.y > top + height;
118
123
  if (outsideX || outsideY) {
119
124
  dispatch({
120
125
  type: 'updateAxis',
@@ -125,8 +130,8 @@ export const useAxisEvents = disableAxisListener => {
125
130
  });
126
131
  return;
127
132
  }
128
- const newStateX = getUpdateX(event.offsetX);
129
- const newStateY = getUpdateY(event.offsetY);
133
+ const newStateX = getUpdateX(svgPt.x);
134
+ const newStateY = getUpdateY(svgPt.y);
130
135
  dispatch({
131
136
  type: 'updateAxis',
132
137
  data: {
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ import { DrawingContext } from '../context/DrawingProvider';
3
+ export function useDrawingArea() {
4
+ const {
5
+ left,
6
+ top,
7
+ width,
8
+ height
9
+ } = React.useContext(DrawingContext);
10
+ return React.useMemo(() => ({
11
+ left,
12
+ top,
13
+ width,
14
+ height
15
+ }), [height, left, top, width]);
16
+ }
@@ -1,24 +1,6 @@
1
- import { scaleLog, scalePow, scaleSqrt, scaleTime, scaleUtc, scaleLinear } from 'd3-scale';
2
- export function getScale(scaleType, domain, range) {
3
- switch (scaleType) {
4
- case 'log':
5
- return scaleLog(domain, range);
6
- case 'pow':
7
- return scalePow(domain, range);
8
- case 'sqrt':
9
- return scaleSqrt(domain, range);
10
- case 'time':
11
- return scaleTime(domain, range);
12
- case 'utc':
13
- return scaleUtc(domain, range);
14
- default:
15
- return scaleLinear(domain, range);
16
- }
17
- }
18
- export function isBandScale(scale) {
19
- return scale.bandwidth !== undefined;
20
- }
21
-
1
+ import * as React from 'react';
2
+ import { CartesianContext } from '../context/CartesianContextProvider';
3
+ import { isBandScale } from '../internals/isBandScale';
22
4
  /**
23
5
  * For a given scale return a function that map value to their position.
24
6
  * Usefull when dealing with specific scale such as band.
@@ -30,4 +12,20 @@ export function getValueToPositionMapper(scale) {
30
12
  return value => scale(value) + scale.bandwidth() / 2;
31
13
  }
32
14
  return value => scale(value);
15
+ }
16
+ export function useXScale(identifier) {
17
+ const {
18
+ xAxis,
19
+ xAxisIds
20
+ } = React.useContext(CartesianContext);
21
+ const id = typeof identifier === 'string' ? identifier : xAxisIds[identifier ?? 0];
22
+ return xAxis[id].scale;
23
+ }
24
+ export function useYScale(identifier) {
25
+ const {
26
+ yAxis,
27
+ yAxisIds
28
+ } = React.useContext(CartesianContext);
29
+ const id = typeof identifier === 'string' ? identifier : yAxisIds[identifier ?? 0];
30
+ return yAxis[id].scale;
33
31
  }
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { isBandScale } from './useScale';
2
+ import { isBandScale } from '../internals/isBandScale';
3
3
  export function getTicksNumber(params) {
4
4
  const {
5
5
  maxTicks = 999,
@@ -20,15 +20,25 @@ function useTicks(options) {
20
20
  // band scale
21
21
  if (isBandScale(scale)) {
22
22
  const domain = scale.domain();
23
- return [...domain.map(value => ({
23
+ if (scale.bandwidth() > 0) {
24
+ // scale type = 'band'
25
+ return [...domain.map((value, index) => ({
26
+ formattedValue: valueFormatter?.(value) ?? value,
27
+ offset: index === 0 ? scale.range()[0] : scale(value) - (scale.step() - scale.bandwidth()) / 2,
28
+ labelOffset: scale.step() / 2
29
+ })), {
30
+ formattedValue: undefined,
31
+ offset: scale.range()[1],
32
+ labelOffset: 0
33
+ }];
34
+ }
35
+
36
+ // scale type = 'point'
37
+ return domain.map(value => ({
24
38
  formattedValue: valueFormatter?.(value) ?? value,
25
- offset: scale(value) ?? 0,
26
- labelOffset: scale.bandwidth() / 2
27
- })), ...(scale.bandwidth() > 0 ? [{
28
- formattedValue: undefined,
29
- offset: scale.range()[1],
39
+ offset: scale(value),
30
40
  labelOffset: 0
31
- }] : [])];
41
+ }));
32
42
  }
33
43
  return scale.ticks(ticksNumber).map(value => ({
34
44
  formattedValue: valueFormatter?.(value) ?? scale.tickFormat(ticksNumber)(value),
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v6.0.0-alpha.1
2
+ * @mui/x-charts v6.0.0-alpha.3
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -7,6 +7,7 @@
7
7
  */
8
8
  export * from './constants';
9
9
  export * from './context';
10
+ export * from './hooks';
10
11
  export * from './colorPalettes';
11
12
  export * from './models';
12
13
  export * from './ChartsClipPath';
@@ -17,6 +18,7 @@ export * from './ChartsTooltip';
17
18
  export * from './ChartsAxisHighlight';
18
19
  export * from './BarChart';
19
20
  export * from './LineChart';
21
+ export * from './PieChart';
20
22
  export * from './ScatterChart';
21
23
  export * from './ChartContainer';
22
24
  export * from './ResponsiveChartContainer';
@@ -1,6 +1,13 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  const DEFAULT_COLORS = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'];
3
3
  export function defaultizeColor(series, seriesIndex, colors = DEFAULT_COLORS) {
4
+ if (series.type === 'pie') {
5
+ return _extends({}, series, {
6
+ data: series.data.map((d, index) => _extends({
7
+ color: colors[index % colors.length]
8
+ }, d))
9
+ });
10
+ }
4
11
  return _extends({
5
12
  color: colors[seriesIndex % colors.length]
6
13
  }, series);
@@ -0,0 +1,17 @@
1
+ import { scaleLog, scalePow, scaleSqrt, scaleTime, scaleUtc, scaleLinear } from 'd3-scale';
2
+ export function getScale(scaleType, domain, range) {
3
+ switch (scaleType) {
4
+ case 'log':
5
+ return scaleLog(domain, range);
6
+ case 'pow':
7
+ return scalePow(domain, range);
8
+ case 'sqrt':
9
+ return scaleSqrt(domain, range);
10
+ case 'time':
11
+ return scaleTime(domain, range);
12
+ case 'utc':
13
+ return scaleUtc(domain, range);
14
+ default:
15
+ return scaleLinear(domain, range);
16
+ }
17
+ }
@@ -0,0 +1,3 @@
1
+ export function isBandScale(scale) {
2
+ return scale.bandwidth !== undefined;
3
+ }
@@ -1 +1,6 @@
1
- export {};
1
+ export function isBandScaleConfig(scaleConfig) {
2
+ return scaleConfig.scaleType === 'band';
3
+ }
4
+ export function isPointScaleConfig(scaleConfig) {
5
+ return scaleConfig.scaleType === 'point';
6
+ }
@@ -1,12 +1,5 @@
1
- // import { PieSeriesType } from './pie';
2
-
3
- // | PieSeriesType;
4
-
5
- // | PieSeriesType;
6
-
7
- // | PieSeriesType
8
-
9
1
  export * from './line';
10
2
  export * from './bar';
11
3
  export * from './scatter';
4
+ export * from './pie';
12
5
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-charts",
3
- "version": "6.0.0-alpha.1",
3
+ "version": "6.0.0-alpha.3",
4
4
  "description": "The community edition of the charts components (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./index.js",