@mui/x-charts 6.0.0-alpha.14 → 6.0.0-alpha.16

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 (199) hide show
  1. package/BarChart/BarChart.d.ts +16 -2
  2. package/BarChart/BarChart.js +49 -11
  3. package/BarChart/BarElement.d.ts +1318 -3
  4. package/BarChart/BarElement.js +10 -8
  5. package/BarChart/BarPlot.d.ts +17 -1
  6. package/BarChart/BarPlot.js +152 -66
  7. package/CHANGELOG.md +169 -0
  8. package/ChartContainer/index.js +5 -2
  9. package/ChartsAxis/ChartsAxis.js +18 -2
  10. package/ChartsAxis/axisClasses.d.ts +1 -1
  11. package/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
  12. package/ChartsClipPath/ChartsClipPath.js +2 -2
  13. package/ChartsLegend/ChartsLegend.d.ts +44 -24
  14. package/ChartsLegend/ChartsLegend.js +191 -145
  15. package/ChartsLegend/utils.d.ts +1 -6
  16. package/ChartsSurface.js +5 -13
  17. package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
  18. package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  19. package/ChartsTooltip/ChartsTooltip.js +2 -2
  20. package/ChartsTooltip/utils.js +2 -2
  21. package/ChartsXAxis/ChartsXAxis.js +151 -40
  22. package/ChartsYAxis/ChartsYAxis.js +76 -33
  23. package/LineChart/AreaElement.d.ts +10 -0
  24. package/LineChart/AreaElement.js +12 -2
  25. package/LineChart/AreaPlot.d.ts +11 -0
  26. package/LineChart/AreaPlot.js +13 -2
  27. package/LineChart/LineChart.d.ts +13 -0
  28. package/LineChart/LineChart.js +40 -10
  29. package/LineChart/LineElement.d.ts +10 -0
  30. package/LineChart/LineElement.js +12 -2
  31. package/LineChart/LineHighlightElement.d.ts +10 -0
  32. package/LineChart/LineHighlightElement.js +12 -2
  33. package/LineChart/LineHighlightPlot.d.ts +10 -0
  34. package/LineChart/LineHighlightPlot.js +12 -2
  35. package/LineChart/LinePlot.d.ts +10 -0
  36. package/LineChart/LinePlot.js +12 -2
  37. package/LineChart/MarkElement.d.ts +10 -0
  38. package/LineChart/MarkElement.js +12 -2
  39. package/LineChart/MarkPlot.d.ts +10 -0
  40. package/LineChart/MarkPlot.js +12 -2
  41. package/PieChart/PieArc.js +2 -2
  42. package/PieChart/PieArcLabel.js +2 -2
  43. package/PieChart/PieChart.d.ts +13 -0
  44. package/PieChart/PieChart.js +41 -10
  45. package/PieChart/PiePlot.d.ts +10 -0
  46. package/PieChart/PiePlot.js +12 -2
  47. package/ResponsiveChartContainer/index.js +4 -4
  48. package/ScatterChart/Scatter.d.ts +10 -0
  49. package/ScatterChart/Scatter.js +12 -2
  50. package/ScatterChart/ScatterChart.d.ts +13 -0
  51. package/ScatterChart/ScatterChart.js +40 -10
  52. package/ScatterChart/ScatterPlot.d.ts +10 -0
  53. package/ScatterChart/ScatterPlot.js +12 -2
  54. package/SparkLineChart/SparkLineChart.d.ts +9 -0
  55. package/SparkLineChart/SparkLineChart.js +16 -2
  56. package/constants.js +1 -1
  57. package/context/CartesianContextProvider.js +20 -12
  58. package/context/DrawingProvider.d.ts +2 -0
  59. package/context/DrawingProvider.js +4 -2
  60. package/context/HighlightProvider.js +2 -2
  61. package/context/InteractionProvider.js +2 -2
  62. package/context/SeriesContextProvider.js +2 -2
  63. package/esm/BarChart/BarChart.js +47 -9
  64. package/esm/BarChart/BarElement.js +7 -4
  65. package/esm/BarChart/BarPlot.js +152 -67
  66. package/esm/ChartContainer/index.js +3 -0
  67. package/esm/ChartsAxis/ChartsAxis.js +16 -0
  68. package/esm/ChartsLegend/ChartsLegend.js +188 -142
  69. package/esm/ChartsSurface.js +3 -11
  70. package/esm/ChartsXAxis/ChartsXAxis.js +148 -37
  71. package/esm/ChartsYAxis/ChartsYAxis.js +73 -30
  72. package/esm/LineChart/AreaElement.js +10 -0
  73. package/esm/LineChart/AreaPlot.js +11 -0
  74. package/esm/LineChart/LineChart.js +38 -8
  75. package/esm/LineChart/LineElement.js +10 -0
  76. package/esm/LineChart/LineHighlightElement.js +10 -0
  77. package/esm/LineChart/LineHighlightPlot.js +10 -0
  78. package/esm/LineChart/LinePlot.js +10 -0
  79. package/esm/LineChart/MarkElement.js +10 -0
  80. package/esm/LineChart/MarkPlot.js +10 -0
  81. package/esm/PieChart/PieChart.js +39 -8
  82. package/esm/PieChart/PiePlot.js +10 -0
  83. package/esm/ResponsiveChartContainer/index.js +2 -2
  84. package/esm/ScatterChart/Scatter.js +10 -0
  85. package/esm/ScatterChart/ScatterChart.js +38 -8
  86. package/esm/ScatterChart/ScatterPlot.js +10 -0
  87. package/esm/SparkLineChart/SparkLineChart.js +14 -0
  88. package/esm/constants.js +1 -1
  89. package/esm/context/CartesianContextProvider.js +19 -11
  90. package/esm/context/DrawingProvider.js +2 -0
  91. package/esm/hooks/useChartDimensions.js +2 -0
  92. package/esm/hooks/useMounted.js +16 -0
  93. package/esm/hooks/useReducedMotion.js +27 -0
  94. package/esm/hooks/useTicks.js +15 -9
  95. package/esm/internals/components/AxisSharedComponents.js +15 -70
  96. package/esm/internals/components/ChartsText.js +75 -0
  97. package/esm/internals/domUtils.js +113 -0
  98. package/esm/internals/geometry.js +36 -0
  99. package/hooks/useAxisEvents.js +2 -2
  100. package/hooks/useChartDimensions.d.ts +2 -0
  101. package/hooks/useChartDimensions.js +4 -2
  102. package/hooks/useDrawingArea.js +2 -2
  103. package/hooks/useInteractionItemProps.js +2 -2
  104. package/hooks/useMounted.d.ts +1 -0
  105. package/hooks/useMounted.js +25 -0
  106. package/hooks/useReducedMotion.d.ts +8 -0
  107. package/hooks/useReducedMotion.js +33 -0
  108. package/hooks/useScale.d.ts +2 -2
  109. package/hooks/useScale.js +2 -2
  110. package/hooks/useTicks.d.ts +19 -11
  111. package/hooks/useTicks.js +18 -12
  112. package/index.js +1 -1
  113. package/internals/components/AxisSharedComponents.d.ts +0 -4
  114. package/internals/components/AxisSharedComponents.js +16 -71
  115. package/internals/components/ChartsText.d.ts +35 -0
  116. package/internals/components/ChartsText.js +85 -0
  117. package/internals/defaultizeColor.d.ts +1 -1
  118. package/internals/domUtils.d.ts +13 -0
  119. package/internals/domUtils.js +122 -0
  120. package/internals/geometry.d.ts +9 -0
  121. package/internals/geometry.js +42 -0
  122. package/legacy/BarChart/BarChart.js +47 -9
  123. package/legacy/BarChart/BarElement.js +6 -3
  124. package/legacy/BarChart/BarPlot.js +151 -63
  125. package/legacy/ChartContainer/index.js +3 -0
  126. package/legacy/ChartsAxis/ChartsAxis.js +16 -0
  127. package/legacy/ChartsLegend/ChartsLegend.js +203 -140
  128. package/legacy/ChartsSurface.js +2 -11
  129. package/legacy/ChartsXAxis/ChartsXAxis.js +152 -39
  130. package/legacy/ChartsYAxis/ChartsYAxis.js +73 -30
  131. package/legacy/LineChart/AreaElement.js +10 -0
  132. package/legacy/LineChart/AreaPlot.js +11 -0
  133. package/legacy/LineChart/LineChart.js +38 -8
  134. package/legacy/LineChart/LineElement.js +10 -0
  135. package/legacy/LineChart/LineHighlightElement.js +10 -0
  136. package/legacy/LineChart/LineHighlightPlot.js +10 -0
  137. package/legacy/LineChart/LinePlot.js +10 -0
  138. package/legacy/LineChart/MarkElement.js +10 -0
  139. package/legacy/LineChart/MarkPlot.js +10 -0
  140. package/legacy/PieChart/PieChart.js +39 -8
  141. package/legacy/PieChart/PiePlot.js +10 -0
  142. package/legacy/ResponsiveChartContainer/index.js +2 -2
  143. package/legacy/ScatterChart/Scatter.js +10 -0
  144. package/legacy/ScatterChart/ScatterChart.js +38 -8
  145. package/legacy/ScatterChart/ScatterPlot.js +10 -0
  146. package/legacy/SparkLineChart/SparkLineChart.js +14 -0
  147. package/legacy/constants.js +1 -1
  148. package/legacy/context/CartesianContextProvider.js +19 -11
  149. package/legacy/context/DrawingProvider.js +2 -0
  150. package/legacy/hooks/useChartDimensions.js +2 -0
  151. package/legacy/hooks/useMounted.js +21 -0
  152. package/legacy/hooks/useReducedMotion.js +27 -0
  153. package/legacy/hooks/useTicks.js +16 -9
  154. package/legacy/index.js +1 -1
  155. package/legacy/internals/components/AxisSharedComponents.js +9 -63
  156. package/legacy/internals/components/ChartsText.js +77 -0
  157. package/legacy/internals/domUtils.js +121 -0
  158. package/legacy/internals/geometry.js +37 -0
  159. package/models/axis.d.ts +25 -7
  160. package/models/layout.d.ts +7 -6
  161. package/models/seriesType/line.d.ts +2 -2
  162. package/modern/BarChart/BarChart.js +47 -9
  163. package/modern/BarChart/BarElement.js +7 -4
  164. package/modern/BarChart/BarPlot.js +149 -65
  165. package/modern/ChartContainer/index.js +3 -0
  166. package/modern/ChartsAxis/ChartsAxis.js +16 -0
  167. package/modern/ChartsLegend/ChartsLegend.js +188 -142
  168. package/modern/ChartsSurface.js +3 -11
  169. package/modern/ChartsXAxis/ChartsXAxis.js +148 -37
  170. package/modern/ChartsYAxis/ChartsYAxis.js +73 -30
  171. package/modern/LineChart/AreaElement.js +10 -0
  172. package/modern/LineChart/AreaPlot.js +11 -0
  173. package/modern/LineChart/LineChart.js +38 -8
  174. package/modern/LineChart/LineElement.js +10 -0
  175. package/modern/LineChart/LineHighlightElement.js +10 -0
  176. package/modern/LineChart/LineHighlightPlot.js +10 -0
  177. package/modern/LineChart/LinePlot.js +10 -0
  178. package/modern/LineChart/MarkElement.js +10 -0
  179. package/modern/LineChart/MarkPlot.js +10 -0
  180. package/modern/PieChart/PieChart.js +39 -8
  181. package/modern/PieChart/PiePlot.js +10 -0
  182. package/modern/ResponsiveChartContainer/index.js +2 -2
  183. package/modern/ScatterChart/Scatter.js +10 -0
  184. package/modern/ScatterChart/ScatterChart.js +38 -8
  185. package/modern/ScatterChart/ScatterPlot.js +10 -0
  186. package/modern/SparkLineChart/SparkLineChart.js +14 -0
  187. package/modern/constants.js +1 -1
  188. package/modern/context/CartesianContextProvider.js +19 -11
  189. package/modern/context/DrawingProvider.js +2 -0
  190. package/modern/hooks/useChartDimensions.js +2 -0
  191. package/modern/hooks/useMounted.js +16 -0
  192. package/modern/hooks/useReducedMotion.js +27 -0
  193. package/modern/hooks/useTicks.js +15 -9
  194. package/modern/index.js +1 -1
  195. package/modern/internals/components/AxisSharedComponents.js +15 -70
  196. package/modern/internals/components/ChartsText.js +75 -0
  197. package/modern/internals/domUtils.js +113 -0
  198. package/modern/internals/geometry.js +36 -0
  199. package/package.json +5 -3
@@ -1,7 +1,8 @@
1
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
1
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
3
  import * as React from 'react';
3
4
  import { isBandScale } from '../internals/isBandScale';
4
- export function getTicksNumber(params) {
5
+ export function getTickNumber(params) {
5
6
  var tickMaxStep = params.tickMaxStep,
6
7
  tickMinStep = params.tickMinStep,
7
8
  tickNumber = params.tickNumber,
@@ -14,8 +15,9 @@ export function getTicksNumber(params) {
14
15
  }
15
16
  function useTicks(options) {
16
17
  var scale = options.scale,
17
- ticksNumber = options.ticksNumber,
18
- valueFormatter = options.valueFormatter;
18
+ tickNumber = options.tickNumber,
19
+ valueFormatter = options.valueFormatter,
20
+ tickInterval = options.tickInterval;
19
21
  return React.useMemo(function () {
20
22
  // band scale
21
23
  if (isBandScale(scale)) {
@@ -25,7 +27,8 @@ function useTicks(options) {
25
27
  return [].concat(_toConsumableArray(domain.map(function (value) {
26
28
  var _valueFormatter;
27
29
  return {
28
- formattedValue: (_valueFormatter = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter : value,
30
+ value: value,
31
+ formattedValue: (_valueFormatter = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter : "".concat(value),
29
32
  offset: scale(value) - (scale.step() - scale.bandwidth()) / 2,
30
33
  labelOffset: scale.step() / 2
31
34
  };
@@ -37,23 +40,27 @@ function useTicks(options) {
37
40
  }
38
41
 
39
42
  // scale type = 'point'
40
- return domain.map(function (value) {
43
+ var filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || _typeof(tickInterval) === 'object' && tickInterval || domain;
44
+ return filteredDomain.map(function (value) {
41
45
  var _valueFormatter2;
42
46
  return {
43
- formattedValue: (_valueFormatter2 = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter2 : value,
47
+ value: value,
48
+ formattedValue: (_valueFormatter2 = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter2 : "".concat(value),
44
49
  offset: scale(value),
45
50
  labelOffset: 0
46
51
  };
47
52
  });
48
53
  }
49
- return scale.ticks(ticksNumber).map(function (value) {
54
+ var ticks = _typeof(tickInterval) === 'object' ? tickInterval : scale.ticks(tickNumber);
55
+ return ticks.map(function (value) {
50
56
  var _valueFormatter3;
51
57
  return {
52
- formattedValue: (_valueFormatter3 = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter3 : scale.tickFormat(ticksNumber)(value),
58
+ value: value,
59
+ formattedValue: (_valueFormatter3 = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter3 : scale.tickFormat(tickNumber)(value),
53
60
  offset: scale(value),
54
61
  labelOffset: 0
55
62
  };
56
63
  });
57
- }, [ticksNumber, scale, valueFormatter]);
64
+ }, [tickNumber, scale, valueFormatter, tickInterval]);
58
65
  }
59
66
  export default useTicks;
package/legacy/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v6.0.0-alpha.14
2
+ * @mui/x-charts v6.0.0-alpha.16
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -1,6 +1,5 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
- var _$concat, _styled;
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
3
  import { styled } from '@mui/material/styles';
5
4
  import { axisClasses } from '../../ChartsAxis/axisClasses';
6
5
  export var AxisRoot = styled('g', {
@@ -9,72 +8,19 @@ export var AxisRoot = styled('g', {
9
8
  overridesResolver: function overridesResolver(props, styles) {
10
9
  return styles.root;
11
10
  }
12
- })((_styled = {}, _defineProperty(_styled, "&.".concat(axisClasses.directionY), (_$concat = {}, _defineProperty(_$concat, ".".concat(axisClasses.tickLabel), {
13
- dominantBaseline: 'middle'
14
- }), _defineProperty(_$concat, ".".concat(axisClasses.label), {
15
- dominantBaseline: 'auto',
16
- textAnchor: 'middle'
17
- }), _$concat)), _defineProperty(_styled, "&.".concat(axisClasses.left), _defineProperty({}, ".".concat(axisClasses.tickLabel), {
18
- dominantBaseline: 'central',
19
- textAnchor: 'end'
20
- })), _defineProperty(_styled, "&.".concat(axisClasses.right), _defineProperty({}, ".".concat(axisClasses.tickLabel), {
21
- dominantBaseline: 'central',
22
- textAnchor: 'start'
23
- })), _defineProperty(_styled, "&.".concat(axisClasses.bottom), _defineProperty({}, ".".concat(axisClasses.tickLabel, ", .").concat(axisClasses.label), {
24
- dominantBaseline: 'hanging',
25
- textAnchor: 'middle'
26
- })), _defineProperty(_styled, "&.".concat(axisClasses.top), _defineProperty({}, ".".concat(axisClasses.tickLabel, ", .").concat(axisClasses.label), {
27
- dominantBaseline: 'baseline',
28
- textAnchor: 'middle'
29
- })), _styled));
30
- export var ChartsLine = styled('line', {
31
- name: 'MuiChartsAxis',
32
- slot: 'Line',
33
- overridesResolver: function overridesResolver(props, styles) {
34
- return styles.line;
35
- }
36
11
  })(function (_ref) {
12
+ var _ref2;
37
13
  var theme = _ref.theme;
38
- return {
14
+ return _ref2 = {}, _defineProperty(_ref2, "& .".concat(axisClasses.tickLabel), _extends({}, theme.typography.caption, {
15
+ fill: (theme.vars || theme).palette.text.primary
16
+ })), _defineProperty(_ref2, "& .".concat(axisClasses.label), _extends({}, theme.typography.body1, {
17
+ fill: (theme.vars || theme).palette.text.primary
18
+ })), _defineProperty(_ref2, "& .".concat(axisClasses.line), {
39
19
  stroke: (theme.vars || theme).palette.text.primary,
40
20
  shapeRendering: 'crispEdges',
41
21
  strokeWidth: 1
42
- };
43
- });
44
- export var ChartsTick = styled('line', {
45
- name: 'MuiChartsAxis',
46
- slot: 'Tick',
47
- overridesResolver: function overridesResolver(props, styles) {
48
- return styles.tick;
49
- }
50
- })(function (_ref2) {
51
- var theme = _ref2.theme;
52
- return {
22
+ }), _defineProperty(_ref2, "& .".concat(axisClasses.tick), {
53
23
  stroke: (theme.vars || theme).palette.text.primary,
54
24
  shapeRendering: 'crispEdges'
55
- };
56
- });
57
- export var ChartsTickLabel = styled('text', {
58
- name: 'MuiChartsAxis',
59
- slot: 'TickLabel',
60
- overridesResolver: function overridesResolver(props, styles) {
61
- return styles.tickLabel;
62
- }
63
- })(function (_ref3) {
64
- var theme = _ref3.theme;
65
- return _extends({}, theme.typography.caption, {
66
- fill: (theme.vars || theme).palette.text.primary
67
- });
68
- });
69
- export var ChartsLabel = styled('text', {
70
- name: 'MuiChartsAxis',
71
- slot: 'Label',
72
- overridesResolver: function overridesResolver(props, styles) {
73
- return styles.label;
74
- }
75
- })(function (_ref4) {
76
- var theme = _ref4.theme;
77
- return _extends({}, theme.typography.body1, {
78
- fill: (theme.vars || theme).palette.text.primary
79
- });
25
+ }), _ref2;
80
26
  });
@@ -0,0 +1,77 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ var _excluded = ["x", "y", "style", "text", "ownerState"],
4
+ _excluded2 = ["angle", "textAnchor", "dominantBaseline"];
5
+ import * as React from 'react';
6
+ import { getStringSize } from '../domUtils';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ export function getWordsByLines(_ref) {
9
+ var style = _ref.style,
10
+ needsComputation = _ref.needsComputation,
11
+ text = _ref.text;
12
+ return text.split('\n').map(function (subText) {
13
+ return _extends({
14
+ text: subText
15
+ }, needsComputation ? getStringSize(subText, style) : {
16
+ width: 0,
17
+ height: 0
18
+ });
19
+ });
20
+ }
21
+ export function ChartsText(props) {
22
+ var x = props.x,
23
+ y = props.y,
24
+ styleProps = props.style,
25
+ text = props.text,
26
+ ownerState = props.ownerState,
27
+ textProps = _objectWithoutProperties(props, _excluded);
28
+ var _ref2 = styleProps != null ? styleProps : {},
29
+ angle = _ref2.angle,
30
+ textAnchor = _ref2.textAnchor,
31
+ dominantBaseline = _ref2.dominantBaseline,
32
+ style = _objectWithoutProperties(_ref2, _excluded2);
33
+ var wordsByLines = React.useMemo(function () {
34
+ return getWordsByLines({
35
+ style: style,
36
+ needsComputation: text.includes('\n'),
37
+ text: text
38
+ });
39
+ }, [style, text]);
40
+ var startDy;
41
+ switch (dominantBaseline) {
42
+ case 'hanging':
43
+ startDy = 0;
44
+ break;
45
+ case 'central':
46
+ startDy = (wordsByLines.length - 1) / 2 * -wordsByLines[0].height;
47
+ break;
48
+ default:
49
+ startDy = (wordsByLines.length - 1) * -wordsByLines[0].height;
50
+ break;
51
+ }
52
+ var transforms = [];
53
+ // if (scaleToFit) {
54
+ // const lineWidth = wordsByLines[0].width;
55
+ // transforms.push(`scale(${(isNumber(width as number) ? (width as number) / lineWidth : 1) / lineWidth})`);
56
+ // }
57
+ if (angle) {
58
+ transforms.push("rotate(".concat(angle, ", ").concat(x, ", ").concat(y, ")"));
59
+ }
60
+ if (transforms.length) {
61
+ textProps.transform = transforms.join(' ');
62
+ }
63
+ return /*#__PURE__*/_jsx("text", _extends({}, textProps, {
64
+ x: x,
65
+ y: y,
66
+ textAnchor: textAnchor,
67
+ dominantBaseline: dominantBaseline,
68
+ style: style,
69
+ children: wordsByLines.map(function (line, index) {
70
+ return /*#__PURE__*/_jsx("tspan", {
71
+ x: x,
72
+ dy: "".concat(index === 0 ? startDy : wordsByLines[0].height, "px"),
73
+ children: line.text
74
+ }, index);
75
+ })
76
+ }));
77
+ }
@@ -0,0 +1,121 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
+ // DOM utils taken from
4
+ // https://github.com/recharts/recharts/blob/master/src/util/DOMUtils.ts
5
+
6
+ var isSsr = function isSsr() {
7
+ return !(typeof window !== 'undefined' && window.document && window.setTimeout);
8
+ };
9
+ var stringCache = {
10
+ widthCache: {},
11
+ cacheCount: 0
12
+ };
13
+ var MAX_CACHE_NUM = 2000;
14
+ var SPAN_STYLE = {
15
+ position: 'absolute',
16
+ top: '-20000px',
17
+ left: 0,
18
+ padding: 0,
19
+ margin: 0,
20
+ border: 'none',
21
+ whiteSpace: 'pre'
22
+ };
23
+ var STYLE_LIST = ['minWidth', 'maxWidth', 'width', 'minHeight', 'maxHeight', 'height', 'top', 'left', 'fontSize', 'padding', 'margin', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom'];
24
+ var MEASUREMENT_SPAN_ID = 'mui_measurement_span';
25
+
26
+ /**
27
+ *
28
+ * @param name CSS property name
29
+ * @param value
30
+ * @returns add 'px' for distance properties
31
+ */
32
+ function autoCompleteStyle(name, value) {
33
+ if (STYLE_LIST.indexOf(name) >= 0 && value === +value) {
34
+ return "".concat(value, "px");
35
+ }
36
+ return value;
37
+ }
38
+
39
+ /**
40
+ *
41
+ * @param text camelcase css property
42
+ * @returns css property
43
+ */
44
+ function camelToMiddleLine(text) {
45
+ var strs = text.split('');
46
+ var formatStrs = strs.reduce(function (result, entry) {
47
+ if (entry === entry.toUpperCase()) {
48
+ return [].concat(_toConsumableArray(result), ['-', entry.toLowerCase()]);
49
+ }
50
+ return [].concat(_toConsumableArray(result), [entry]);
51
+ }, []);
52
+ return formatStrs.join('');
53
+ }
54
+
55
+ /**
56
+ *
57
+ * @param style React style object
58
+ * @returns CSS styling string
59
+ */
60
+ export var getStyleString = function getStyleString(style) {
61
+ return Object.keys(style).sort().reduce(function (result, s) {
62
+ return "".concat(result).concat(camelToMiddleLine(s), ":").concat(autoCompleteStyle(s, style[s]), ";");
63
+ }, '');
64
+ };
65
+
66
+ /**
67
+ *
68
+ * @param text The string to estimate
69
+ * @param style The style applied
70
+ * @returns width and height of the text
71
+ */
72
+ export var getStringSize = function getStringSize(text) {
73
+ var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
74
+ if (text === undefined || text === null || isSsr()) {
75
+ return {
76
+ width: 0,
77
+ height: 0
78
+ };
79
+ }
80
+ var str = "".concat(text);
81
+ var styleString = getStyleString(style);
82
+ var cacheKey = "".concat(str, "-").concat(styleString);
83
+ if (stringCache.widthCache[cacheKey]) {
84
+ return stringCache.widthCache[cacheKey];
85
+ }
86
+ try {
87
+ var measurementSpan = document.getElementById(MEASUREMENT_SPAN_ID);
88
+ if (measurementSpan === null) {
89
+ measurementSpan = document.createElement('span');
90
+ measurementSpan.setAttribute('id', MEASUREMENT_SPAN_ID);
91
+ measurementSpan.setAttribute('aria-hidden', 'true');
92
+ document.body.appendChild(measurementSpan);
93
+ }
94
+ // Need to use CSS Object Model (CSSOM) to be able to comply with Content Security Policy (CSP)
95
+ // https://en.wikipedia.org/wiki/Content_Security_Policy
96
+ var measurementSpanStyle = _extends({}, SPAN_STYLE, style);
97
+ Object.keys(measurementSpanStyle).map(function (styleKey) {
98
+ measurementSpan.style[camelToMiddleLine(styleKey)] = autoCompleteStyle(styleKey, measurementSpanStyle[styleKey]);
99
+ return styleKey;
100
+ });
101
+ measurementSpan.textContent = str;
102
+ var rect = measurementSpan.getBoundingClientRect();
103
+ var result = {
104
+ width: rect.width,
105
+ height: rect.height
106
+ };
107
+ stringCache.widthCache[cacheKey] = result;
108
+ if (stringCache.cacheCount + 1 > MAX_CACHE_NUM) {
109
+ stringCache.cacheCount = 0;
110
+ stringCache.widthCache = {};
111
+ } else {
112
+ stringCache.cacheCount += 1;
113
+ }
114
+ return result;
115
+ } catch (e) {
116
+ return {
117
+ width: 0,
118
+ height: 0
119
+ };
120
+ }
121
+ };
@@ -0,0 +1,37 @@
1
+ var ANGLE_APPROX = 5; // Angle (in deg) for which we approximate the rectangle as perfectly horizontal/vertical
2
+
3
+ var warnedOnce = false;
4
+
5
+ /**
6
+ * Return the minimal translation along the x-axis to avoid overflow of a rectangle of a given width, height, and rotation.
7
+ * This assumes that all rectangles have the same height and angle between -90 and 90.
8
+ * Otherwise it would be problematic because you need the height/width of the next rectangle to do the correct computation.
9
+ * @param width the side along the x axis.
10
+ * @param height the side along the y axis.
11
+ * @param angle the rotation in degrees.
12
+ */
13
+ export function getMinXTranslation(width, height) {
14
+ var angle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
15
+ if (process.env.NODE_ENV !== 'production') {
16
+ if (!warnedOnce && angle > 90 && angle < -90) {
17
+ warnedOnce = true;
18
+ console.warn(["MUI X: It seems you applied an angle larger than 90\xB0 or smaller than -90\xB0 to an axis text.", "This could cause some text overlapping.", "If you encounter a use case where it's needed, please open an issue."].join('\n'));
19
+ }
20
+ }
21
+ var standardAngle = Math.min(Math.abs(angle) % 180, Math.abs(Math.abs(angle) % 180 - 180) % 180); // Map from R to [0, 90]
22
+
23
+ if (standardAngle < ANGLE_APPROX) {
24
+ // It's nearly horizontal
25
+ return width;
26
+ }
27
+ if (standardAngle > 90 - ANGLE_APPROX) {
28
+ // It's nearly vertical
29
+ return height;
30
+ }
31
+ var radAngle = standardAngle * Math.PI / 180;
32
+ var angleSwich = Math.atan2(height, width);
33
+ if (radAngle < angleSwich) {
34
+ return width / Math.cos(radAngle);
35
+ }
36
+ return height / Math.sin(radAngle);
37
+ }
package/models/axis.d.ts CHANGED
@@ -2,19 +2,20 @@
2
2
  import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, ScalePoint } from 'd3-scale';
3
3
  import { ChartsAxisClasses } from '../ChartsAxis/axisClasses';
4
4
  import type { TickParams } from '../hooks/useTicks';
5
- export type D3Scale = ScaleBand<any> | ScaleLogarithmic<any, any> | ScalePoint<any> | ScalePower<any, any> | ScaleTime<any, any> | ScaleLinear<any, any>;
6
- export type D3ContinuouseScale = ScaleLogarithmic<any, any> | ScalePower<any, any> | ScaleTime<any, any> | ScaleLinear<any, any>;
5
+ import { ChartsTextProps } from '../internals/components/ChartsText';
6
+ export type D3Scale = ScaleBand<any> | ScaleLogarithmic<any, number> | ScalePoint<any> | ScalePower<any, number> | ScaleTime<any, number> | ScaleLinear<any, number>;
7
+ export type D3ContinuouseScale = ScaleLogarithmic<any, number> | ScalePower<any, number> | ScaleTime<any, number> | ScaleLinear<any, number>;
7
8
  export interface ChartsAxisSlotsComponent {
8
9
  axisLine?: React.JSXElementConstructor<React.SVGAttributes<SVGPathElement>>;
9
10
  axisTick?: React.JSXElementConstructor<React.SVGAttributes<SVGPathElement>>;
10
- axisTickLabel?: React.JSXElementConstructor<React.SVGAttributes<SVGTextElement>>;
11
- axisLabel?: React.JSXElementConstructor<React.SVGAttributes<SVGTextElement>>;
11
+ axisTickLabel?: React.JSXElementConstructor<ChartsTextProps>;
12
+ axisLabel?: React.JSXElementConstructor<ChartsTextProps>;
12
13
  }
13
14
  export interface ChartsAxisSlotComponentProps {
14
15
  axisLine?: Partial<React.SVGAttributes<SVGPathElement>>;
15
16
  axisTick?: Partial<React.SVGAttributes<SVGPathElement>>;
16
- axisTickLabel?: Partial<React.SVGAttributes<SVGTextElement>>;
17
- axisLabel?: Partial<React.SVGAttributes<SVGTextElement>>;
17
+ axisTickLabel?: Partial<ChartsTextProps>;
18
+ axisLabel?: Partial<ChartsTextProps>;
18
19
  }
19
20
  export interface ChartsAxisProps extends TickParams {
20
21
  /**
@@ -39,8 +40,24 @@ export interface ChartsAxisProps extends TickParams {
39
40
  /**
40
41
  * The font size of the axis ticks text.
41
42
  * @default 12
43
+ * @deprecated Consider using `tickLabelStyle.fontSize` instead.
42
44
  */
43
45
  tickFontSize?: number;
46
+ /**
47
+ * The style applied to ticks text.
48
+ */
49
+ tickLabelStyle?: ChartsTextProps['style'];
50
+ /**
51
+ * The style applied to the axis label.
52
+ */
53
+ labelStyle?: ChartsTextProps['style'];
54
+ /**
55
+ * Defines which ticks get its label displayed. Its value can be:
56
+ * - 'auto' In such case, labels are displayed if they do not overlap with the previous one.
57
+ * - a filtering function of the form (value, index) => boolean. Warning: the index is tick index, not data ones.
58
+ * @default 'auto'
59
+ */
60
+ tickLabelInterval?: 'auto' | ((value: any, index: number) => boolean);
44
61
  /**
45
62
  * The label of the axis.
46
63
  */
@@ -48,6 +65,7 @@ export interface ChartsAxisProps extends TickParams {
48
65
  /**
49
66
  * The font size of the axis label.
50
67
  * @default 14
68
+ * @deprecated Consider using `labelStyle.fontSize` instead.
51
69
  */
52
70
  labelFontSize?: number;
53
71
  /**
@@ -151,7 +169,7 @@ export type AxisConfig<S extends ScaleName = ScaleName, V = any> = {
151
169
  hideTooltip?: boolean;
152
170
  } & Partial<ChartsXAxisProps | ChartsYAxisProps> & Partial<Omit<AxisScaleConfig[S], 'scale'>> & TickParams;
153
171
  export type AxisDefaultized<S extends ScaleName = ScaleName, V = any> = Omit<AxisConfig<S, V>, 'scaleType'> & AxisScaleConfig[S] & {
154
- ticksNumber: number;
172
+ tickNumber: number;
155
173
  };
156
174
  export declare function isBandScaleConfig(scaleConfig: AxisConfig<ScaleName>): scaleConfig is AxisConfig<'band'> & {
157
175
  scaleType: 'band';
@@ -1,10 +1,11 @@
1
+ export interface CardinalDirections<T> {
2
+ top?: T;
3
+ bottom?: T;
4
+ left?: T;
5
+ right?: T;
6
+ }
1
7
  export type LayoutConfig = {
2
8
  width: number;
3
9
  height: number;
4
- margin?: {
5
- top?: number;
6
- bottom?: number;
7
- left?: number;
8
- right?: number;
9
- };
10
+ margin?: Partial<CardinalDirections<number>>;
10
11
  };
@@ -1,7 +1,7 @@
1
1
  import { DefaultizedProps } from '../helpers';
2
2
  import { CartesianSeriesType, CommonDefaultizedProps, CommonSeriesType, StackableSeriesType } from './common';
3
3
  export type CurveType = 'catmullRom' | 'linear' | 'monotoneX' | 'monotoneY' | 'natural' | 'step' | 'stepBefore' | 'stepAfter';
4
- export interface ShowMarkParams {
4
+ export interface ShowMarkParams<AxisValue = number | Date> {
5
5
  /**
6
6
  * The item index.
7
7
  */
@@ -17,7 +17,7 @@ export interface ShowMarkParams {
17
17
  /**
18
18
  * The item position value. It likely comes from the axis `data` property.
19
19
  */
20
- position: number | Date;
20
+ position: AxisValue;
21
21
  /**
22
22
  * The item value. It comes from the series `data` property.
23
23
  */
@@ -12,6 +12,17 @@ import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
12
12
  import { ChartsClipPath } from '../ChartsClipPath';
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { jsxs as _jsxs } from "react/jsx-runtime";
15
+ /**
16
+ * Demos:
17
+ *
18
+ * - [Bars](https://mui.com/x/react-charts/bars/)
19
+ * - [Bar demonstration](https://mui.com/x/react-charts/bar-demo/)
20
+ * - [Stacking](https://mui.com/x/react-charts/stacking/)
21
+ *
22
+ * API:
23
+ *
24
+ * - [BarChart API](https://mui.com/x/api/charts/bar-chart/)
25
+ */
15
26
  const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
16
27
  const {
17
28
  xAxis,
@@ -31,6 +42,7 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
31
42
  leftAxis,
32
43
  rightAxis,
33
44
  bottomAxis,
45
+ skipAnimation,
34
46
  children,
35
47
  slots,
36
48
  slotProps
@@ -73,7 +85,8 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
73
85
  clipPath: `url(#${clipPathId})`,
74
86
  children: /*#__PURE__*/_jsx(BarPlot, {
75
87
  slots: slots,
76
- slotProps: slotProps
88
+ slotProps: slotProps,
89
+ skipAnimation: skipAnimation
77
90
  })
78
91
  }), /*#__PURE__*/_jsx(ChartsAxis, {
79
92
  topAxis: topAxis,
@@ -115,11 +128,15 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
115
128
  fill: PropTypes.string,
116
129
  label: PropTypes.string,
117
130
  labelFontSize: PropTypes.number,
131
+ labelStyle: PropTypes.object,
118
132
  position: PropTypes.oneOf(['bottom', 'top']),
119
133
  slotProps: PropTypes.object,
120
134
  slots: PropTypes.object,
121
135
  stroke: PropTypes.string,
122
136
  tickFontSize: PropTypes.number,
137
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
138
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
139
+ tickLabelStyle: PropTypes.object,
123
140
  tickMaxStep: PropTypes.number,
124
141
  tickMinStep: PropTypes.number,
125
142
  tickNumber: PropTypes.number,
@@ -149,33 +166,33 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
149
166
  fill: PropTypes.string,
150
167
  label: PropTypes.string,
151
168
  labelFontSize: PropTypes.number,
169
+ labelStyle: PropTypes.object,
152
170
  position: PropTypes.oneOf(['left', 'right']),
153
171
  slotProps: PropTypes.object,
154
172
  slots: PropTypes.object,
155
173
  stroke: PropTypes.string,
156
174
  tickFontSize: PropTypes.number,
175
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
176
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
177
+ tickLabelStyle: PropTypes.object,
157
178
  tickMaxStep: PropTypes.number,
158
179
  tickMinStep: PropTypes.number,
159
180
  tickNumber: PropTypes.number,
160
181
  tickSize: PropTypes.number
161
182
  }), PropTypes.string]),
183
+ /**
184
+ * @deprecated Consider using `slotProps.legend` instead.
185
+ */
162
186
  legend: PropTypes.shape({
163
187
  classes: PropTypes.object,
164
188
  direction: PropTypes.oneOf(['column', 'row']),
165
189
  hidden: PropTypes.bool,
166
- itemWidth: PropTypes.number,
167
- markSize: PropTypes.number,
168
- offset: PropTypes.shape({
169
- x: PropTypes.number,
170
- y: PropTypes.number
171
- }),
172
190
  position: PropTypes.shape({
173
191
  horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
174
192
  vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
175
193
  }),
176
194
  slotProps: PropTypes.object,
177
- slots: PropTypes.object,
178
- spacing: PropTypes.number
195
+ slots: PropTypes.object
179
196
  }),
180
197
  margin: PropTypes.shape({
181
198
  bottom: PropTypes.number,
@@ -196,11 +213,15 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
196
213
  fill: PropTypes.string,
197
214
  label: PropTypes.string,
198
215
  labelFontSize: PropTypes.number,
216
+ labelStyle: PropTypes.object,
199
217
  position: PropTypes.oneOf(['left', 'right']),
200
218
  slotProps: PropTypes.object,
201
219
  slots: PropTypes.object,
202
220
  stroke: PropTypes.string,
203
221
  tickFontSize: PropTypes.number,
222
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
223
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
224
+ tickLabelStyle: PropTypes.object,
204
225
  tickMaxStep: PropTypes.number,
205
226
  tickMinStep: PropTypes.number,
206
227
  tickNumber: PropTypes.number,
@@ -225,6 +246,11 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
225
246
  xAxisKey: PropTypes.string,
226
247
  yAxisKey: PropTypes.string
227
248
  })).isRequired,
249
+ /**
250
+ * If `true`, animations are skiped.
251
+ * @default false
252
+ */
253
+ skipAnimation: PropTypes.bool,
228
254
  /**
229
255
  * The props used for each component slot.
230
256
  * @default {}
@@ -258,11 +284,15 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
258
284
  fill: PropTypes.string,
259
285
  label: PropTypes.string,
260
286
  labelFontSize: PropTypes.number,
287
+ labelStyle: PropTypes.object,
261
288
  position: PropTypes.oneOf(['bottom', 'top']),
262
289
  slotProps: PropTypes.object,
263
290
  slots: PropTypes.object,
264
291
  stroke: PropTypes.string,
265
292
  tickFontSize: PropTypes.number,
293
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
294
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
295
+ tickLabelStyle: PropTypes.object,
266
296
  tickMaxStep: PropTypes.number,
267
297
  tickMinStep: PropTypes.number,
268
298
  tickNumber: PropTypes.number,
@@ -287,6 +317,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
287
317
  id: PropTypes.string,
288
318
  label: PropTypes.string,
289
319
  labelFontSize: PropTypes.number,
320
+ labelStyle: PropTypes.object,
290
321
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
291
322
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
292
323
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
@@ -295,6 +326,9 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
295
326
  slots: PropTypes.object,
296
327
  stroke: PropTypes.string,
297
328
  tickFontSize: PropTypes.number,
329
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
330
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
331
+ tickLabelStyle: PropTypes.object,
298
332
  tickMaxStep: PropTypes.number,
299
333
  tickMinStep: PropTypes.number,
300
334
  tickNumber: PropTypes.number,
@@ -313,6 +347,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
313
347
  id: PropTypes.string,
314
348
  label: PropTypes.string,
315
349
  labelFontSize: PropTypes.number,
350
+ labelStyle: PropTypes.object,
316
351
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
317
352
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
318
353
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
@@ -321,6 +356,9 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
321
356
  slots: PropTypes.object,
322
357
  stroke: PropTypes.string,
323
358
  tickFontSize: PropTypes.number,
359
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
360
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
361
+ tickLabelStyle: PropTypes.object,
324
362
  tickMaxStep: PropTypes.number,
325
363
  tickMinStep: PropTypes.number,
326
364
  tickNumber: PropTypes.number,