@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
package/hooks/useTicks.js CHANGED
@@ -4,12 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- exports.getTicksNumber = getTicksNumber;
7
+ exports.getTickNumber = getTickNumber;
8
8
  var React = _interopRequireWildcard(require("react"));
9
9
  var _isBandScale = require("../internals/isBandScale");
10
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
12
- function getTicksNumber(params) {
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
+ 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
+ function getTickNumber(params) {
13
13
  const {
14
14
  tickMaxStep,
15
15
  tickMinStep,
@@ -25,8 +25,9 @@ function getTicksNumber(params) {
25
25
  function useTicks(options) {
26
26
  const {
27
27
  scale,
28
- ticksNumber,
29
- valueFormatter
28
+ tickNumber,
29
+ valueFormatter,
30
+ tickInterval
30
31
  } = options;
31
32
  return React.useMemo(() => {
32
33
  // band scale
@@ -35,7 +36,8 @@ function useTicks(options) {
35
36
  if (scale.bandwidth() > 0) {
36
37
  // scale type = 'band'
37
38
  return [...domain.map(value => ({
38
- formattedValue: valueFormatter?.(value) ?? value,
39
+ value,
40
+ formattedValue: valueFormatter?.(value) ?? `${value}`,
39
41
  offset: scale(value) - (scale.step() - scale.bandwidth()) / 2,
40
42
  labelOffset: scale.step() / 2
41
43
  })), {
@@ -46,17 +48,21 @@ function useTicks(options) {
46
48
  }
47
49
 
48
50
  // scale type = 'point'
49
- return domain.map(value => ({
50
- formattedValue: valueFormatter?.(value) ?? value,
51
+ const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
52
+ return filteredDomain.map(value => ({
53
+ value,
54
+ formattedValue: valueFormatter?.(value) ?? `${value}`,
51
55
  offset: scale(value),
52
56
  labelOffset: 0
53
57
  }));
54
58
  }
55
- return scale.ticks(ticksNumber).map(value => ({
56
- formattedValue: valueFormatter?.(value) ?? scale.tickFormat(ticksNumber)(value),
59
+ const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
60
+ return ticks.map(value => ({
61
+ value,
62
+ formattedValue: valueFormatter?.(value) ?? scale.tickFormat(tickNumber)(value),
57
63
  offset: scale(value),
58
64
  labelOffset: 0
59
65
  }));
60
- }, [ticksNumber, scale, valueFormatter]);
66
+ }, [tickNumber, scale, valueFormatter, tickInterval]);
61
67
  }
62
68
  var _default = exports.default = useTicks;
package/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,2 @@
1
1
  /// <reference types="react" />
2
2
  export declare const AxisRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGProps<SVGGElement>, keyof import("react").SVGProps<SVGGElement>>, {}>;
3
- export declare const ChartsLine: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGLineElementAttributes<SVGLineElement>, keyof import("react").SVGLineElementAttributes<SVGLineElement>>, {}>;
4
- export declare const ChartsTick: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGLineElementAttributes<SVGLineElement>, keyof import("react").SVGLineElementAttributes<SVGLineElement>>, {}>;
5
- export declare const ChartsTickLabel: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGTextElementAttributes<SVGTextElement>, keyof import("react").SVGTextElementAttributes<SVGTextElement>>, {}>;
6
- export declare const ChartsLabel: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGTextElementAttributes<SVGTextElement>, keyof import("react").SVGTextElementAttributes<SVGTextElement>>, {}>;
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.ChartsTickLabel = exports.ChartsTick = exports.ChartsLine = exports.ChartsLabel = exports.AxisRoot = void 0;
7
+ exports.AxisRoot = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _styles = require("@mui/material/styles");
10
10
  var _axisClasses = require("../../ChartsAxis/axisClasses");
@@ -12,77 +12,22 @@ const AxisRoot = exports.AxisRoot = (0, _styles.styled)('g', {
12
12
  name: 'MuiChartsAxis',
13
13
  slot: 'Root',
14
14
  overridesResolver: (props, styles) => styles.root
15
- })({
16
- [`&.${_axisClasses.axisClasses.directionY}`]: {
17
- [`.${_axisClasses.axisClasses.tickLabel}`]: {
18
- dominantBaseline: 'middle'
19
- },
20
- [`.${_axisClasses.axisClasses.label}`]: {
21
- dominantBaseline: 'auto',
22
- textAnchor: 'middle'
23
- }
24
- },
25
- [`&.${_axisClasses.axisClasses.left}`]: {
26
- [`.${_axisClasses.axisClasses.tickLabel}`]: {
27
- dominantBaseline: 'central',
28
- textAnchor: 'end'
29
- }
30
- },
31
- [`&.${_axisClasses.axisClasses.right}`]: {
32
- [`.${_axisClasses.axisClasses.tickLabel}`]: {
33
- dominantBaseline: 'central',
34
- textAnchor: 'start'
35
- }
36
- },
37
- [`&.${_axisClasses.axisClasses.bottom}`]: {
38
- [`.${_axisClasses.axisClasses.tickLabel}, .${_axisClasses.axisClasses.label}`]: {
39
- dominantBaseline: 'hanging',
40
- textAnchor: 'middle'
41
- }
42
- },
43
- [`&.${_axisClasses.axisClasses.top}`]: {
44
- [`.${_axisClasses.axisClasses.tickLabel}, .${_axisClasses.axisClasses.label}`]: {
45
- dominantBaseline: 'baseline',
46
- textAnchor: 'middle'
47
- }
48
- }
49
- });
50
- const ChartsLine = exports.ChartsLine = (0, _styles.styled)('line', {
51
- name: 'MuiChartsAxis',
52
- slot: 'Line',
53
- overridesResolver: (props, styles) => styles.line
54
15
  })(({
55
16
  theme
56
17
  }) => ({
57
- stroke: (theme.vars || theme).palette.text.primary,
58
- shapeRendering: 'crispEdges',
59
- strokeWidth: 1
60
- }));
61
- const ChartsTick = exports.ChartsTick = (0, _styles.styled)('line', {
62
- name: 'MuiChartsAxis',
63
- slot: 'Tick',
64
- overridesResolver: (props, styles) => styles.tick
65
- })(({
66
- theme
67
- }) => ({
68
- stroke: (theme.vars || theme).palette.text.primary,
69
- shapeRendering: 'crispEdges'
70
- }));
71
- const ChartsTickLabel = exports.ChartsTickLabel = (0, _styles.styled)('text', {
72
- name: 'MuiChartsAxis',
73
- slot: 'TickLabel',
74
- overridesResolver: (props, styles) => styles.tickLabel
75
- })(({
76
- theme
77
- }) => (0, _extends2.default)({}, theme.typography.caption, {
78
- fill: (theme.vars || theme).palette.text.primary
79
- }));
80
- const ChartsLabel = exports.ChartsLabel = (0, _styles.styled)('text', {
81
- name: 'MuiChartsAxis',
82
- slot: 'Label',
83
- overridesResolver: (props, styles) => styles.label
84
- })(({
85
- theme
86
- }) => (0, _extends2.default)({}, theme.typography.body1, {
87
- fill: (theme.vars || theme).palette.text.primary
18
+ [`& .${_axisClasses.axisClasses.tickLabel}`]: (0, _extends2.default)({}, theme.typography.caption, {
19
+ fill: (theme.vars || theme).palette.text.primary
20
+ }),
21
+ [`& .${_axisClasses.axisClasses.label}`]: (0, _extends2.default)({}, theme.typography.body1, {
22
+ fill: (theme.vars || theme).palette.text.primary
23
+ }),
24
+ [`& .${_axisClasses.axisClasses.line}`]: {
25
+ stroke: (theme.vars || theme).palette.text.primary,
26
+ shapeRendering: 'crispEdges',
27
+ strokeWidth: 1
28
+ },
29
+ [`& .${_axisClasses.axisClasses.tick}`]: {
30
+ stroke: (theme.vars || theme).palette.text.primary,
31
+ shapeRendering: 'crispEdges'
32
+ }
88
33
  }));
@@ -0,0 +1,35 @@
1
+ import * as React from 'react';
2
+ export type ChartsTextBaseline = 'hanging' | 'central' | 'auto';
3
+ export interface ChartsTextStyle extends React.CSSProperties {
4
+ angle?: number;
5
+ /**
6
+ * The text baseline
7
+ * @default 'central'
8
+ */
9
+ dominantBaseline?: ChartsTextBaseline;
10
+ }
11
+ interface GetWordsByLinesParams {
12
+ /**
13
+ * Text displayed.
14
+ */
15
+ text: string;
16
+ /**
17
+ * Style applied to text elements.
18
+ */
19
+ style?: ChartsTextStyle;
20
+ /**
21
+ * If true, the line width is computed.
22
+ * @default false
23
+ */
24
+ needsComputation?: boolean;
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
+ export declare function getWordsByLines({ style, needsComputation, text }: GetWordsByLinesParams): any[];
34
+ export declare function ChartsText(props: ChartsTextProps): React.JSX.Element;
35
+ export {};
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ChartsText = ChartsText;
8
+ exports.getWordsByLines = getWordsByLines;
9
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+ var React = _interopRequireWildcard(require("react"));
12
+ var _domUtils = require("../domUtils");
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
+ const _excluded = ["x", "y", "style", "text", "ownerState"],
15
+ _excluded2 = ["angle", "textAnchor", "dominantBaseline"];
16
+ 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); }
17
+ 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; }
18
+ function getWordsByLines({
19
+ style,
20
+ needsComputation,
21
+ text
22
+ }) {
23
+ return text.split('\n').map(subText => (0, _extends2.default)({
24
+ text: subText
25
+ }, needsComputation ? (0, _domUtils.getStringSize)(subText, style) : {
26
+ width: 0,
27
+ height: 0
28
+ }));
29
+ }
30
+ function ChartsText(props) {
31
+ const {
32
+ x,
33
+ y,
34
+ style: styleProps,
35
+ text
36
+ } = props,
37
+ textProps = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
38
+ const _ref = styleProps ?? {},
39
+ {
40
+ angle,
41
+ textAnchor,
42
+ dominantBaseline
43
+ } = _ref,
44
+ style = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded2);
45
+ const wordsByLines = React.useMemo(() => getWordsByLines({
46
+ style,
47
+ needsComputation: text.includes('\n'),
48
+ text
49
+ }), [style, text]);
50
+ let startDy;
51
+ switch (dominantBaseline) {
52
+ case 'hanging':
53
+ startDy = 0;
54
+ break;
55
+ case 'central':
56
+ startDy = (wordsByLines.length - 1) / 2 * -wordsByLines[0].height;
57
+ break;
58
+ default:
59
+ startDy = (wordsByLines.length - 1) * -wordsByLines[0].height;
60
+ break;
61
+ }
62
+ const transforms = [];
63
+ // if (scaleToFit) {
64
+ // const lineWidth = wordsByLines[0].width;
65
+ // transforms.push(`scale(${(isNumber(width as number) ? (width as number) / lineWidth : 1) / lineWidth})`);
66
+ // }
67
+ if (angle) {
68
+ transforms.push(`rotate(${angle}, ${x}, ${y})`);
69
+ }
70
+ if (transforms.length) {
71
+ textProps.transform = transforms.join(' ');
72
+ }
73
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("text", (0, _extends2.default)({}, textProps, {
74
+ x: x,
75
+ y: y,
76
+ textAnchor: textAnchor,
77
+ dominantBaseline: dominantBaseline,
78
+ style: style,
79
+ children: wordsByLines.map((line, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)("tspan", {
80
+ x: x,
81
+ dy: `${index === 0 ? startDy : wordsByLines[0].height}px`,
82
+ children: line.text
83
+ }, index))
84
+ }));
85
+ }
@@ -57,7 +57,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
57
57
  area?: boolean | undefined;
58
58
  label?: string | undefined;
59
59
  curve?: import("../models/seriesType").CurveType | undefined;
60
- showMark?: boolean | ((params: import("../models/seriesType").ShowMarkParams) => boolean) | undefined;
60
+ showMark?: boolean | ((params: import("../models/seriesType").ShowMarkParams<number | Date>) => boolean) | undefined;
61
61
  disableHighlight?: boolean | undefined;
62
62
  id?: string | undefined;
63
63
  color: string;
@@ -0,0 +1,13 @@
1
+ /**
2
+ *
3
+ * @param style React style object
4
+ * @returns CSS styling string
5
+ */
6
+ export declare const getStyleString: (style: React.CSSProperties) => string;
7
+ /**
8
+ *
9
+ * @param text The string to estimate
10
+ * @param style The style applied
11
+ * @returns width and height of the text
12
+ */
13
+ export declare const getStringSize: (text: string | number, style?: React.CSSProperties) => any;
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getStyleString = exports.getStringSize = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ // DOM utils taken from
10
+ // https://github.com/recharts/recharts/blob/master/src/util/DOMUtils.ts
11
+
12
+ const isSsr = () => !(typeof window !== 'undefined' && window.document && window.setTimeout);
13
+ const stringCache = {
14
+ widthCache: {},
15
+ cacheCount: 0
16
+ };
17
+ const MAX_CACHE_NUM = 2000;
18
+ const SPAN_STYLE = {
19
+ position: 'absolute',
20
+ top: '-20000px',
21
+ left: 0,
22
+ padding: 0,
23
+ margin: 0,
24
+ border: 'none',
25
+ whiteSpace: 'pre'
26
+ };
27
+ const STYLE_LIST = ['minWidth', 'maxWidth', 'width', 'minHeight', 'maxHeight', 'height', 'top', 'left', 'fontSize', 'padding', 'margin', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom'];
28
+ const MEASUREMENT_SPAN_ID = 'mui_measurement_span';
29
+
30
+ /**
31
+ *
32
+ * @param name CSS property name
33
+ * @param value
34
+ * @returns add 'px' for distance properties
35
+ */
36
+ function autoCompleteStyle(name, value) {
37
+ if (STYLE_LIST.indexOf(name) >= 0 && value === +value) {
38
+ return `${value}px`;
39
+ }
40
+ return value;
41
+ }
42
+
43
+ /**
44
+ *
45
+ * @param text camelcase css property
46
+ * @returns css property
47
+ */
48
+ function camelToMiddleLine(text) {
49
+ const strs = text.split('');
50
+ const formatStrs = strs.reduce((result, entry) => {
51
+ if (entry === entry.toUpperCase()) {
52
+ return [...result, '-', entry.toLowerCase()];
53
+ }
54
+ return [...result, entry];
55
+ }, []);
56
+ return formatStrs.join('');
57
+ }
58
+
59
+ /**
60
+ *
61
+ * @param style React style object
62
+ * @returns CSS styling string
63
+ */
64
+ const getStyleString = style => Object.keys(style).sort().reduce((result, s) => `${result}${camelToMiddleLine(s)}:${autoCompleteStyle(s, style[s])};`, '');
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
+ exports.getStyleString = getStyleString;
73
+ const getStringSize = (text, style = {}) => {
74
+ if (text === undefined || text === null || isSsr()) {
75
+ return {
76
+ width: 0,
77
+ height: 0
78
+ };
79
+ }
80
+ const str = `${text}`;
81
+ const styleString = getStyleString(style);
82
+ const cacheKey = `${str}-${styleString}`;
83
+ if (stringCache.widthCache[cacheKey]) {
84
+ return stringCache.widthCache[cacheKey];
85
+ }
86
+ try {
87
+ let 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
+ const measurementSpanStyle = (0, _extends2.default)({}, SPAN_STYLE, style);
97
+ Object.keys(measurementSpanStyle).map(styleKey => {
98
+ measurementSpan.style[camelToMiddleLine(styleKey)] = autoCompleteStyle(styleKey, measurementSpanStyle[styleKey]);
99
+ return styleKey;
100
+ });
101
+ measurementSpan.textContent = str;
102
+ const rect = measurementSpan.getBoundingClientRect();
103
+ const 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
+ };
122
+ exports.getStringSize = getStringSize;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Return the minimal translation along the x-axis to avoid overflow of a rectangle of a given width, height, and rotation.
3
+ * This assumes that all rectangles have the same height and angle between -90 and 90.
4
+ * Otherwise it would be problematic because you need the height/width of the next rectangle to do the correct computation.
5
+ * @param width the side along the x axis.
6
+ * @param height the side along the y axis.
7
+ * @param angle the rotation in degrees.
8
+ */
9
+ export declare function getMinXTranslation(width: number, height: number, angle?: number): number;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getMinXTranslation = getMinXTranslation;
7
+ const ANGLE_APPROX = 5; // Angle (in deg) for which we approximate the rectangle as perfectly horizontal/vertical
8
+
9
+ let warnedOnce = false;
10
+
11
+ /**
12
+ * Return the minimal translation along the x-axis to avoid overflow of a rectangle of a given width, height, and rotation.
13
+ * This assumes that all rectangles have the same height and angle between -90 and 90.
14
+ * Otherwise it would be problematic because you need the height/width of the next rectangle to do the correct computation.
15
+ * @param width the side along the x axis.
16
+ * @param height the side along the y axis.
17
+ * @param angle the rotation in degrees.
18
+ */
19
+ function getMinXTranslation(width, height, angle = 0) {
20
+ if (process.env.NODE_ENV !== 'production') {
21
+ if (!warnedOnce && angle > 90 && angle < -90) {
22
+ warnedOnce = true;
23
+ console.warn([`MUI X: It seems you applied an angle larger than 90° or smaller than -90° 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'));
24
+ }
25
+ }
26
+ const standardAngle = Math.min(Math.abs(angle) % 180, Math.abs(Math.abs(angle) % 180 - 180) % 180); // Map from R to [0, 90]
27
+
28
+ if (standardAngle < ANGLE_APPROX) {
29
+ // It's nearly horizontal
30
+ return width;
31
+ }
32
+ if (standardAngle > 90 - ANGLE_APPROX) {
33
+ // It's nearly vertical
34
+ return height;
35
+ }
36
+ const radAngle = standardAngle * Math.PI / 180;
37
+ const angleSwich = Math.atan2(height, width);
38
+ if (radAngle < angleSwich) {
39
+ return width / Math.cos(radAngle);
40
+ }
41
+ return height / Math.sin(radAngle);
42
+ }