@mui/x-charts 6.0.0-alpha.6 → 6.0.0-alpha.8

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 (142) hide show
  1. package/BarChart/BarChart.d.ts +19 -2
  2. package/BarChart/BarChart.js +84 -22
  3. package/BarChart/BarElement.d.ts +22 -0
  4. package/BarChart/BarElement.js +21 -10
  5. package/BarChart/BarPlot.d.ts +14 -1
  6. package/BarChart/BarPlot.js +48 -19
  7. package/BarChart/extremums.js +19 -3
  8. package/BarChart/formatter.js +3 -1
  9. package/CHANGELOG.md +213 -28
  10. package/ChartsAxis/ChartsAxis.d.ts +11 -1
  11. package/ChartsAxis/ChartsAxis.js +51 -6
  12. package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +3 -2
  13. package/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  14. package/ChartsLegend/ChartsLegend.d.ts +25 -2
  15. package/ChartsLegend/ChartsLegend.js +49 -17
  16. package/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  17. package/ChartsTooltip/ChartsTooltipTable.d.ts +2 -9
  18. package/ChartsXAxis/ChartsXAxis.js +44 -9
  19. package/ChartsYAxis/ChartsYAxis.js +44 -9
  20. package/LineChart/AreaElement.d.ts +22 -0
  21. package/LineChart/AreaElement.js +31 -11
  22. package/LineChart/AreaPlot.d.ts +14 -1
  23. package/LineChart/AreaPlot.js +29 -3
  24. package/LineChart/LineChart.d.ts +20 -2
  25. package/LineChart/LineChart.js +63 -11
  26. package/LineChart/LineElement.d.ts +22 -0
  27. package/LineChart/LineElement.js +31 -10
  28. package/LineChart/LinePlot.d.ts +14 -1
  29. package/LineChart/LinePlot.js +35 -4
  30. package/LineChart/MarkPlot.d.ts +24 -1
  31. package/LineChart/MarkPlot.js +29 -4
  32. package/PieChart/PieArcLabel.js +0 -1
  33. package/PieChart/PieChart.d.ts +14 -2
  34. package/PieChart/PieChart.js +52 -10
  35. package/PieChart/PiePlot.d.ts +27 -1
  36. package/PieChart/PiePlot.js +29 -6
  37. package/ScatterChart/ScatterChart.d.ts +18 -2
  38. package/ScatterChart/ScatterChart.js +56 -10
  39. package/ScatterChart/ScatterPlot.d.ts +24 -1
  40. package/ScatterChart/ScatterPlot.js +28 -4
  41. package/SparkLineChart/SparkLineChart.d.ts +18 -0
  42. package/SparkLineChart/SparkLineChart.js +29 -6
  43. package/colorPalettes/colorPalettes.js +2 -2
  44. package/context/CartesianContextProvider.js +18 -12
  45. package/esm/BarChart/BarChart.js +88 -26
  46. package/esm/BarChart/BarElement.js +21 -11
  47. package/esm/BarChart/BarPlot.js +49 -20
  48. package/esm/BarChart/extremums.js +18 -2
  49. package/esm/BarChart/formatter.js +3 -1
  50. package/esm/ChartsAxis/ChartsAxis.js +51 -6
  51. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  52. package/esm/ChartsLegend/ChartsLegend.js +47 -14
  53. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  54. package/esm/ChartsXAxis/ChartsXAxis.js +45 -9
  55. package/esm/ChartsYAxis/ChartsYAxis.js +45 -9
  56. package/esm/LineChart/AreaElement.js +31 -11
  57. package/esm/LineChart/AreaPlot.js +31 -4
  58. package/esm/LineChart/LineChart.js +63 -11
  59. package/esm/LineChart/LineElement.js +31 -11
  60. package/esm/LineChart/LinePlot.js +43 -8
  61. package/esm/LineChart/MarkPlot.js +32 -5
  62. package/esm/PieChart/PieArcLabel.js +0 -1
  63. package/esm/PieChart/PieChart.js +52 -10
  64. package/esm/PieChart/PiePlot.js +31 -6
  65. package/esm/ScatterChart/ScatterChart.js +56 -10
  66. package/esm/ScatterChart/ScatterPlot.js +29 -4
  67. package/esm/SparkLineChart/SparkLineChart.js +29 -6
  68. package/esm/colorPalettes/colorPalettes.js +2 -2
  69. package/esm/context/CartesianContextProvider.js +18 -12
  70. package/esm/hooks/useAxisEvents.js +21 -38
  71. package/esm/hooks/useTicks.js +11 -8
  72. package/esm/internals/components/AxisSharedComponents.js +10 -10
  73. package/hooks/useAxisEvents.js +21 -38
  74. package/hooks/useTicks.d.ts +20 -5
  75. package/hooks/useTicks.js +11 -8
  76. package/index.js +1 -1
  77. package/internals/components/AxisSharedComponents.d.ts +4 -4
  78. package/internals/components/AxisSharedComponents.js +15 -15
  79. package/internals/defaultizeColor.d.ts +1 -0
  80. package/legacy/BarChart/BarChart.js +93 -29
  81. package/legacy/BarChart/BarElement.js +20 -10
  82. package/legacy/BarChart/BarPlot.js +49 -20
  83. package/legacy/BarChart/extremums.js +22 -2
  84. package/legacy/BarChart/formatter.js +3 -1
  85. package/legacy/ChartsAxis/ChartsAxis.js +51 -6
  86. package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  87. package/legacy/ChartsLegend/ChartsLegend.js +46 -15
  88. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  89. package/legacy/ChartsXAxis/ChartsXAxis.js +45 -9
  90. package/legacy/ChartsYAxis/ChartsYAxis.js +45 -9
  91. package/legacy/LineChart/AreaElement.js +30 -10
  92. package/legacy/LineChart/AreaPlot.js +29 -4
  93. package/legacy/LineChart/LineChart.js +63 -11
  94. package/legacy/LineChart/LineElement.js +30 -10
  95. package/legacy/LineChart/LinePlot.js +36 -5
  96. package/legacy/LineChart/MarkPlot.js +30 -5
  97. package/legacy/PieChart/PieArcLabel.js +0 -1
  98. package/legacy/PieChart/PieChart.js +52 -10
  99. package/legacy/PieChart/PiePlot.js +29 -6
  100. package/legacy/ScatterChart/ScatterChart.js +56 -10
  101. package/legacy/ScatterChart/ScatterPlot.js +27 -4
  102. package/legacy/SparkLineChart/SparkLineChart.js +29 -6
  103. package/legacy/colorPalettes/colorPalettes.js +2 -2
  104. package/legacy/context/CartesianContextProvider.js +18 -12
  105. package/legacy/hooks/useAxisEvents.js +21 -37
  106. package/legacy/hooks/useTicks.js +11 -11
  107. package/legacy/index.js +1 -1
  108. package/legacy/internals/components/AxisSharedComponents.js +10 -10
  109. package/models/axis.d.ts +24 -1
  110. package/models/seriesType/bar.d.ts +6 -1
  111. package/modern/BarChart/BarChart.js +85 -23
  112. package/modern/BarChart/BarElement.js +20 -11
  113. package/modern/BarChart/BarPlot.js +48 -19
  114. package/modern/BarChart/extremums.js +18 -2
  115. package/modern/BarChart/formatter.js +3 -1
  116. package/modern/ChartsAxis/ChartsAxis.js +51 -6
  117. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  118. package/modern/ChartsLegend/ChartsLegend.js +46 -14
  119. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  120. package/modern/ChartsXAxis/ChartsXAxis.js +44 -9
  121. package/modern/ChartsYAxis/ChartsYAxis.js +44 -9
  122. package/modern/LineChart/AreaElement.js +30 -11
  123. package/modern/LineChart/AreaPlot.js +31 -4
  124. package/modern/LineChart/LineChart.js +63 -11
  125. package/modern/LineChart/LineElement.js +30 -11
  126. package/modern/LineChart/LinePlot.js +37 -5
  127. package/modern/LineChart/MarkPlot.js +31 -5
  128. package/modern/PieChart/PieArcLabel.js +0 -1
  129. package/modern/PieChart/PieChart.js +52 -10
  130. package/modern/PieChart/PiePlot.js +30 -6
  131. package/modern/ScatterChart/ScatterChart.js +56 -10
  132. package/modern/ScatterChart/ScatterPlot.js +28 -4
  133. package/modern/SparkLineChart/SparkLineChart.js +29 -6
  134. package/modern/colorPalettes/colorPalettes.js +2 -2
  135. package/modern/context/CartesianContextProvider.js +18 -12
  136. package/modern/hooks/useAxisEvents.js +21 -38
  137. package/modern/hooks/useTicks.js +11 -8
  138. package/modern/index.js +1 -1
  139. package/modern/internals/components/AxisSharedComponents.js +10 -10
  140. package/package.json +5 -5
  141. package/themeAugmentation/components.d.ts +0 -10
  142. package/themeAugmentation/overrides.d.ts +0 -2
@@ -33,66 +33,49 @@ export const useAxisEvents = disableAxisListener => {
33
33
  if (element === null || disableAxisListener) {
34
34
  return () => {};
35
35
  }
36
- const getUpdateY = y => {
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: xScale,
64
- data: xAxisData
65
- } = xAxis[usedXAxis];
66
- if (!isBandScale(xScale)) {
67
- const value = xScale.invert(x);
68
- const closestIndex = xAxisData?.findIndex((v, index) => {
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 - xAxisData[index - 1])) {
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 === xAxisData.length - 1 ||
59
+ if (index === axisData.length - 1 ||
77
60
  // @ts-ignore
78
- Math.abs(value - v) < Math.abs(value - xAxisData[index + 1])) {
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 ? xAxisData[closestIndex] : value,
68
+ value: closestIndex !== undefined && closestIndex >= 0 ? axisData[closestIndex] : value,
86
69
  index: closestIndex
87
70
  };
88
71
  }
89
- const dataIndex = xScale.bandwidth() === 0 ? Math.floor((x - xScale.range()[0] + xScale.step() / 2) / xScale.step()) : Math.floor((x - xScale.range()[0]) / xScale.step());
90
- if (dataIndex < 0 || dataIndex >= xAxisData.length) {
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: xAxisData[dataIndex]
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 = getUpdateX(svgPt.x);
134
- const newStateY = getUpdateY(svgPt.y);
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: {
@@ -2,13 +2,16 @@ import * as React from 'react';
2
2
  import { isBandScale } from '../internals/isBandScale';
3
3
  export function getTicksNumber(params) {
4
4
  const {
5
- maxTicks = 999,
6
- minTicks = 2,
7
- tickSpacing = 50,
8
- range
5
+ tickMaxStep,
6
+ tickMinStep,
7
+ tickNumber,
8
+ range,
9
+ domain
9
10
  } = params;
10
- const estimatedTickNumber = Math.floor(Math.abs(range[1] - range[0]) / tickSpacing);
11
- return Math.min(maxTicks, Math.max(minTicks, estimatedTickNumber));
11
+ const maxTicks = tickMinStep === undefined ? 999 : Math.floor(Math.abs(domain[1] - domain[0]) / tickMinStep);
12
+ const minTicks = tickMaxStep === undefined ? 2 : Math.ceil(Math.abs(domain[1] - domain[0]) / tickMaxStep);
13
+ const defaultizedTickNumber = tickNumber ?? Math.floor(Math.abs(range[1] - range[0]) / 50);
14
+ return Math.min(maxTicks, Math.max(minTicks, defaultizedTickNumber));
12
15
  }
13
16
  function useTicks(options) {
14
17
  const {
@@ -22,9 +25,9 @@ function useTicks(options) {
22
25
  const domain = scale.domain();
23
26
  if (scale.bandwidth() > 0) {
24
27
  // scale type = 'band'
25
- return [...domain.map((value, index) => ({
28
+ return [...domain.map(value => ({
26
29
  formattedValue: valueFormatter?.(value) ?? value,
27
- offset: index === 0 ? scale.range()[0] : scale(value) - (scale.step() - scale.bandwidth()) / 2,
30
+ offset: scale(value) - (scale.step() - scale.bandwidth()) / 2,
28
31
  labelOffset: scale.step() / 2
29
32
  })), {
30
33
  formattedValue: undefined,
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v6.0.0-alpha.6
2
+ * @mui/x-charts v6.0.0-alpha.8
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -8,39 +8,39 @@ export const AxisRoot = styled('g', {
8
8
  })({
9
9
  [`&.${axisClasses.directionY}`]: {
10
10
  [`.${axisClasses.tickLabel}`]: {
11
- alignmentBaseline: 'middle'
11
+ dominantBaseline: 'middle'
12
12
  },
13
13
  [`.${axisClasses.label}`]: {
14
- alignmentBaseline: 'baseline',
14
+ dominantBaseline: 'auto',
15
15
  textAnchor: 'middle'
16
16
  }
17
17
  },
18
18
  [`&.${axisClasses.left}`]: {
19
19
  [`.${axisClasses.tickLabel}`]: {
20
- alignmentBaseline: 'central',
20
+ dominantBaseline: 'central',
21
21
  textAnchor: 'end'
22
22
  }
23
23
  },
24
24
  [`&.${axisClasses.right}`]: {
25
25
  [`.${axisClasses.tickLabel}`]: {
26
- alignmentBaseline: 'central',
26
+ dominantBaseline: 'central',
27
27
  textAnchor: 'start'
28
28
  }
29
29
  },
30
30
  [`&.${axisClasses.bottom}`]: {
31
31
  [`.${axisClasses.tickLabel}, .${axisClasses.label}`]: {
32
- alignmentBaseline: 'hanging',
32
+ dominantBaseline: 'hanging',
33
33
  textAnchor: 'middle'
34
34
  }
35
35
  },
36
36
  [`&.${axisClasses.top}`]: {
37
37
  [`.${axisClasses.tickLabel}, .${axisClasses.label}`]: {
38
- alignmentBaseline: 'baseline',
38
+ dominantBaseline: 'baseline',
39
39
  textAnchor: 'middle'
40
40
  }
41
41
  }
42
42
  });
43
- export const Line = styled('line', {
43
+ export const ChartsLine = styled('line', {
44
44
  name: 'MuiChartsAxis',
45
45
  slot: 'Line',
46
46
  overridesResolver: (props, styles) => styles.line
@@ -51,7 +51,7 @@ export const Line = styled('line', {
51
51
  shapeRendering: 'crispEdges',
52
52
  strokeWidth: 1
53
53
  }));
54
- export const Tick = styled('line', {
54
+ export const ChartsTick = styled('line', {
55
55
  name: 'MuiChartsAxis',
56
56
  slot: 'Tick',
57
57
  overridesResolver: (props, styles) => styles.tick
@@ -61,7 +61,7 @@ export const Tick = styled('line', {
61
61
  stroke: theme.palette.text.primary,
62
62
  shapeRendering: 'crispEdges'
63
63
  }));
64
- export const TickLabel = styled('text', {
64
+ export const ChartsTickLabel = styled('text', {
65
65
  name: 'MuiChartsAxis',
66
66
  slot: 'TickLabel',
67
67
  overridesResolver: (props, styles) => styles.tickLabel
@@ -70,7 +70,7 @@ export const TickLabel = styled('text', {
70
70
  }) => _extends({}, theme.typography.caption, {
71
71
  fill: theme.palette.text.primary
72
72
  }));
73
- export const Label = styled('text', {
73
+ export const ChartsLabel = styled('text', {
74
74
  name: 'MuiChartsAxis',
75
75
  slot: 'Label',
76
76
  overridesResolver: (props, styles) => styles.label
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-charts",
3
- "version": "6.0.0-alpha.6",
3
+ "version": "6.0.0-alpha.8",
4
4
  "description": "The community edition of the charts components (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./index.js",
@@ -27,8 +27,8 @@
27
27
  "directory": "packages/x-charts"
28
28
  },
29
29
  "dependencies": {
30
- "@babel/runtime": "^7.22.6",
31
- "clsx": "^1.2.1",
30
+ "@babel/runtime": "^7.22.11",
31
+ "clsx": "^2.0.0",
32
32
  "d3-color": "^3.1.0",
33
33
  "d3-scale": "^4.0.2",
34
34
  "d3-shape": "^3.2.0",
@@ -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": [
@@ -7,19 +7,15 @@ export interface ChartsComponents {
7
7
  };
8
8
  MuiChartsXAxis?: {
9
9
  defaultProps?: ComponentsProps['MuiChartsXAxis'];
10
- styleOverrides?: ComponentsOverrides['MuiChartsXAxis'];
11
10
  };
12
11
  MuiChartsYAxis?: {
13
12
  defaultProps?: ComponentsProps['MuiChartsYAxis'];
14
- styleOverrides?: ComponentsOverrides['MuiChartsYAxis'];
15
13
  };
16
14
  MuiChartsAxisHighlight?: {
17
15
  defaultProps?: ComponentsProps['MuiChartsAxisHighlight'];
18
- styleOverrides?: never; // ComponentsOverrides['MuiChartsAxisHighlight'];
19
16
  };
20
17
  MuiChartsClipPath?: {
21
18
  defaultProps?: ComponentsProps['MuiChartsClipPath'];
22
- styleOverrides?: never; // ComponentsOverrides['MuiChartsClipPath'];
23
19
  };
24
20
  MuiChartsLegend?: {
25
21
  defaultProps?: ComponentsProps['MuiChartsLegend'];
@@ -27,15 +23,12 @@ export interface ChartsComponents {
27
23
  };
28
24
  MuiChartsTooltip?: {
29
25
  defaultProps?: ComponentsProps['MuiChartsTooltip'];
30
- styleOverrides?: never; // ComponentsOverrides['MuiChartsTooltip'];
31
26
  };
32
27
  MuiChartsSurface?: {
33
28
  defaultProps?: ComponentsProps['MuiChartsSurface'];
34
- styleOverrides?: never; // ComponentsOverrides['MuiChartsSurface'];
35
29
  };
36
30
  MuiBarChart?: {
37
31
  defaultProps?: ComponentsProps['MuiBarChart'];
38
- styleOverrides?: never; // ComponentsOverrides['MuiBarChart'];
39
32
  };
40
33
  MuiBarElement?: {
41
34
  defaultProps?: ComponentsProps['MuiBarElement'];
@@ -43,7 +36,6 @@ export interface ChartsComponents {
43
36
  };
44
37
  MuiLineChart?: {
45
38
  defaultProps?: ComponentsProps['MuiLineChart'];
46
- styleOverrides?: never; // ComponentsOverrides['MuiLineChart'];
47
39
  };
48
40
  MuiAreaElement?: {
49
41
  defaultProps?: ComponentsProps['MuiAreaElement'];
@@ -59,11 +51,9 @@ export interface ChartsComponents {
59
51
  };
60
52
  MuiScatterChart?: {
61
53
  defaultProps?: ComponentsProps['MuiScatterChart'];
62
- styleOverrides?: never; // ComponentsOverrides['MuiScatterChart'];
63
54
  };
64
55
  MuiScatter?: {
65
56
  defaultProps?: ComponentsProps['MuiScatter'];
66
- styleOverrides?: never; // ComponentsOverrides['MuiScatter'];
67
57
  };
68
58
  }
69
59
 
@@ -6,8 +6,6 @@ import { AreaElementClassKey, LineElementClassKey, MarkElementClassKey } from '.
6
6
  // prettier-ignore
7
7
  export interface PickersComponentNameToClassKey {
8
8
  MuiChartsAxis: ChartsAxisClassKey;
9
- MuiChartsXAxis: ChartsAxisClassKey;
10
- MuiChartsYAxis: ChartsAxisClassKey;
11
9
  MuiChartsLegend: ChartsLegendClassKey;
12
10
 
13
11
  // BarChart components