@mui/x-charts 7.0.0-beta.0 → 7.0.0-beta.2

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 (258) hide show
  1. package/BarChart/BarChart.d.ts +2 -1
  2. package/BarChart/BarChart.js +33 -12
  3. package/BarChart/BarElement.d.ts +20 -13
  4. package/BarChart/BarElement.js +7 -3
  5. package/BarChart/BarPlot.d.ts +11 -6
  6. package/BarChart/BarPlot.js +28 -15
  7. package/BarChart/formatter.js +1 -1
  8. package/CHANGELOG.md +406 -1
  9. package/ChartContainer/ChartContainer.js +6 -4
  10. package/ChartsAxis/ChartsAxis.js +4 -4
  11. package/ChartsLegend/ChartsLegend.d.ts +5 -54
  12. package/ChartsLegend/ChartsLegend.js +2 -307
  13. package/ChartsLegend/DefaultChartsLegend.d.ts +60 -0
  14. package/ChartsLegend/DefaultChartsLegend.js +294 -0
  15. package/ChartsLegend/index.d.ts +1 -0
  16. package/ChartsLegend/index.js +11 -0
  17. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.d.ts +20 -0
  18. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +83 -0
  19. package/ChartsOnAxisClickHandler/index.d.ts +1 -0
  20. package/ChartsOnAxisClickHandler/index.js +16 -0
  21. package/ChartsOnAxisClickHandler/package.json +6 -0
  22. package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  23. package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  24. package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  25. package/ChartsReferenceLine/common.d.ts +2 -1
  26. package/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  27. package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  28. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -5
  29. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  30. package/ChartsTooltip/utils.d.ts +4 -1
  31. package/ChartsTooltip/utils.js +15 -0
  32. package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +7 -0
  33. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  34. package/ChartsXAxis/ChartsXAxis.js +13 -9
  35. package/ChartsYAxis/ChartsYAxis.js +1 -1
  36. package/LineChart/AnimatedArea.d.ts +1361 -0
  37. package/LineChart/AnimatedArea.js +111 -0
  38. package/LineChart/AnimatedLine.d.ts +1361 -0
  39. package/LineChart/AnimatedLine.js +113 -0
  40. package/LineChart/AreaElement.d.ts +19 -18
  41. package/LineChart/AreaElement.js +17 -34
  42. package/LineChart/AreaPlot.d.ts +12 -7
  43. package/LineChart/AreaPlot.js +91 -58
  44. package/LineChart/LineChart.d.ts +13 -4
  45. package/LineChart/LineChart.js +45 -14
  46. package/LineChart/LineElement.d.ts +19 -18
  47. package/LineChart/LineElement.js +16 -36
  48. package/LineChart/LineHighlightElement.d.ts +3 -2
  49. package/LineChart/LineHighlightElement.js +5 -3
  50. package/LineChart/LinePlot.d.ts +12 -7
  51. package/LineChart/LinePlot.js +89 -56
  52. package/LineChart/MarkElement.d.ts +8 -4
  53. package/LineChart/MarkElement.js +27 -13
  54. package/LineChart/MarkPlot.d.ts +8 -1
  55. package/LineChart/MarkPlot.js +80 -51
  56. package/LineChart/formatter.js +1 -1
  57. package/LineChart/index.d.ts +2 -0
  58. package/LineChart/index.js +22 -0
  59. package/PieChart/PieArc.d.ts +3 -2
  60. package/PieChart/PieArc.js +1 -0
  61. package/PieChart/PieArcLabel.d.ts +3 -2
  62. package/PieChart/PieArcLabel.js +1 -0
  63. package/PieChart/PieArcLabelPlot.d.ts +1 -1
  64. package/PieChart/PieArcLabelPlot.js +2 -2
  65. package/PieChart/PieArcPlot.d.ts +2 -2
  66. package/PieChart/PieArcPlot.js +7 -7
  67. package/PieChart/PieChart.d.ts +1 -1
  68. package/PieChart/PieChart.js +14 -12
  69. package/PieChart/PiePlot.d.ts +1 -1
  70. package/PieChart/PiePlot.js +4 -4
  71. package/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
  72. package/ScatterChart/Scatter.d.ts +7 -1
  73. package/ScatterChart/Scatter.js +17 -3
  74. package/ScatterChart/ScatterChart.d.ts +8 -2
  75. package/ScatterChart/ScatterChart.js +21 -10
  76. package/ScatterChart/ScatterPlot.d.ts +1 -1
  77. package/ScatterChart/ScatterPlot.js +10 -2
  78. package/SparkLineChart/SparkLineChart.d.ts +1 -1
  79. package/SparkLineChart/SparkLineChart.js +7 -4
  80. package/context/CartesianContextProvider.js +8 -6
  81. package/context/DrawingProvider.d.ts +6 -1
  82. package/context/DrawingProvider.js +9 -2
  83. package/context/InteractionProvider.d.ts +3 -3
  84. package/esm/BarChart/BarChart.js +33 -12
  85. package/esm/BarChart/BarElement.js +7 -3
  86. package/esm/BarChart/BarPlot.js +27 -15
  87. package/esm/BarChart/formatter.js +1 -1
  88. package/esm/ChartContainer/ChartContainer.js +6 -4
  89. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  90. package/esm/ChartsLegend/ChartsLegend.js +2 -307
  91. package/esm/ChartsLegend/DefaultChartsLegend.js +286 -0
  92. package/esm/ChartsLegend/index.js +1 -0
  93. package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +77 -0
  94. package/esm/ChartsOnAxisClickHandler/index.js +1 -0
  95. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  96. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  97. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  98. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  99. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  100. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -5
  101. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  102. package/esm/ChartsTooltip/utils.js +12 -0
  103. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  104. package/esm/ChartsXAxis/ChartsXAxis.js +13 -9
  105. package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
  106. package/esm/LineChart/AnimatedArea.js +103 -0
  107. package/esm/LineChart/AnimatedLine.js +105 -0
  108. package/esm/LineChart/AreaElement.js +16 -33
  109. package/esm/LineChart/AreaPlot.js +92 -59
  110. package/esm/LineChart/LineChart.js +45 -14
  111. package/esm/LineChart/LineElement.js +16 -35
  112. package/esm/LineChart/LineHighlightElement.js +5 -3
  113. package/esm/LineChart/LinePlot.js +90 -57
  114. package/esm/LineChart/MarkElement.js +27 -13
  115. package/esm/LineChart/MarkPlot.js +80 -51
  116. package/esm/LineChart/formatter.js +1 -1
  117. package/esm/LineChart/index.js +2 -0
  118. package/esm/PieChart/PieArc.js +1 -0
  119. package/esm/PieChart/PieArcLabel.js +1 -0
  120. package/esm/PieChart/PieArcLabelPlot.js +2 -2
  121. package/esm/PieChart/PieArcPlot.js +7 -7
  122. package/esm/PieChart/PieChart.js +14 -12
  123. package/esm/PieChart/PiePlot.js +4 -4
  124. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
  125. package/esm/ScatterChart/Scatter.js +17 -3
  126. package/esm/ScatterChart/ScatterChart.js +21 -10
  127. package/esm/ScatterChart/ScatterPlot.js +10 -2
  128. package/esm/SparkLineChart/SparkLineChart.js +7 -4
  129. package/esm/context/CartesianContextProvider.js +8 -6
  130. package/esm/context/DrawingProvider.js +9 -2
  131. package/esm/hooks/useDrawingArea.js +7 -3
  132. package/esm/index.js +1 -0
  133. package/esm/internals/geometry.js +1 -1
  134. package/esm/internals/useAnimatedPath.js +29 -0
  135. package/esm/internals/utils.js +7 -0
  136. package/hooks/useDrawingArea.d.ts +2 -0
  137. package/hooks/useDrawingArea.js +7 -3
  138. package/index.d.ts +1 -0
  139. package/index.js +12 -1
  140. package/internals/defaultizeColor.d.ts +16 -16
  141. package/internals/defaultizeValueFormatter.d.ts +4 -7
  142. package/internals/geometry.js +1 -1
  143. package/internals/stackSeries.d.ts +4 -7
  144. package/internals/useAnimatedPath.d.ts +1 -0
  145. package/internals/useAnimatedPath.js +38 -0
  146. package/internals/utils.d.ts +4 -0
  147. package/internals/utils.js +8 -0
  148. package/legacy/BarChart/BarChart.js +33 -12
  149. package/legacy/BarChart/BarElement.js +6 -2
  150. package/legacy/BarChart/BarPlot.js +28 -14
  151. package/legacy/BarChart/formatter.js +1 -1
  152. package/legacy/ChartContainer/ChartContainer.js +6 -4
  153. package/legacy/ChartsAxis/ChartsAxis.js +4 -4
  154. package/legacy/ChartsLegend/ChartsLegend.js +2 -323
  155. package/legacy/ChartsLegend/DefaultChartsLegend.js +302 -0
  156. package/legacy/ChartsLegend/index.js +1 -0
  157. package/legacy/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
  158. package/legacy/ChartsOnAxisClickHandler/index.js +1 -0
  159. package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  160. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  161. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  162. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +6 -7
  163. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  164. package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -5
  165. package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  166. package/legacy/ChartsTooltip/utils.js +12 -0
  167. package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +88 -44
  168. package/legacy/ChartsXAxis/ChartsXAxis.js +12 -8
  169. package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
  170. package/legacy/LineChart/AnimatedArea.js +102 -0
  171. package/legacy/LineChart/AnimatedLine.js +104 -0
  172. package/legacy/LineChart/AreaElement.js +15 -35
  173. package/legacy/LineChart/AreaPlot.js +102 -66
  174. package/legacy/LineChart/LineChart.js +45 -14
  175. package/legacy/LineChart/LineElement.js +15 -37
  176. package/legacy/LineChart/LineHighlightElement.js +5 -3
  177. package/legacy/LineChart/LinePlot.js +97 -63
  178. package/legacy/LineChart/MarkElement.js +30 -12
  179. package/legacy/LineChart/MarkPlot.js +83 -53
  180. package/legacy/LineChart/formatter.js +1 -1
  181. package/legacy/LineChart/index.js +2 -0
  182. package/legacy/PieChart/PieArc.js +1 -0
  183. package/legacy/PieChart/PieArcLabel.js +1 -0
  184. package/legacy/PieChart/PieArcLabelPlot.js +2 -2
  185. package/legacy/PieChart/PieArcPlot.js +7 -7
  186. package/legacy/PieChart/PieChart.js +14 -12
  187. package/legacy/PieChart/PiePlot.js +4 -4
  188. package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
  189. package/legacy/ScatterChart/Scatter.js +19 -3
  190. package/legacy/ScatterChart/ScatterChart.js +21 -10
  191. package/legacy/ScatterChart/ScatterPlot.js +10 -2
  192. package/legacy/SparkLineChart/SparkLineChart.js +8 -5
  193. package/legacy/context/CartesianContextProvider.js +8 -6
  194. package/legacy/context/DrawingProvider.js +11 -2
  195. package/legacy/hooks/useDrawingArea.js +7 -3
  196. package/legacy/index.js +2 -1
  197. package/legacy/internals/geometry.js +1 -1
  198. package/legacy/internals/useAnimatedPath.js +32 -0
  199. package/legacy/internals/utils.js +7 -0
  200. package/models/axis.d.ts +7 -2
  201. package/models/seriesType/common.d.ts +2 -1
  202. package/models/seriesType/config.d.ts +7 -12
  203. package/models/seriesType/line.d.ts +2 -2
  204. package/models/seriesType/pie.d.ts +7 -3
  205. package/models/seriesType/scatter.d.ts +5 -2
  206. package/modern/BarChart/BarChart.js +33 -12
  207. package/modern/BarChart/BarElement.js +7 -3
  208. package/modern/BarChart/BarPlot.js +27 -15
  209. package/modern/BarChart/formatter.js +1 -1
  210. package/modern/ChartContainer/ChartContainer.js +6 -4
  211. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  212. package/modern/ChartsLegend/ChartsLegend.js +2 -307
  213. package/modern/ChartsLegend/DefaultChartsLegend.js +286 -0
  214. package/modern/ChartsLegend/index.js +1 -0
  215. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
  216. package/modern/ChartsOnAxisClickHandler/index.js +1 -0
  217. package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  218. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  219. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  220. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  221. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  222. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -5
  223. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  224. package/modern/ChartsTooltip/utils.js +12 -0
  225. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  226. package/modern/ChartsXAxis/ChartsXAxis.js +13 -9
  227. package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
  228. package/modern/LineChart/AnimatedArea.js +103 -0
  229. package/modern/LineChart/AnimatedLine.js +105 -0
  230. package/modern/LineChart/AreaElement.js +16 -33
  231. package/modern/LineChart/AreaPlot.js +91 -58
  232. package/modern/LineChart/LineChart.js +45 -14
  233. package/modern/LineChart/LineElement.js +16 -35
  234. package/modern/LineChart/LineHighlightElement.js +5 -3
  235. package/modern/LineChart/LinePlot.js +89 -56
  236. package/modern/LineChart/MarkElement.js +27 -13
  237. package/modern/LineChart/MarkPlot.js +80 -51
  238. package/modern/LineChart/formatter.js +1 -1
  239. package/modern/LineChart/index.js +2 -0
  240. package/modern/PieChart/PieArc.js +1 -0
  241. package/modern/PieChart/PieArcLabel.js +1 -0
  242. package/modern/PieChart/PieArcLabelPlot.js +2 -2
  243. package/modern/PieChart/PieArcPlot.js +7 -7
  244. package/modern/PieChart/PieChart.js +14 -12
  245. package/modern/PieChart/PiePlot.js +4 -4
  246. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
  247. package/modern/ScatterChart/Scatter.js +17 -3
  248. package/modern/ScatterChart/ScatterChart.js +21 -10
  249. package/modern/ScatterChart/ScatterPlot.js +10 -2
  250. package/modern/SparkLineChart/SparkLineChart.js +7 -4
  251. package/modern/context/CartesianContextProvider.js +8 -6
  252. package/modern/context/DrawingProvider.js +9 -2
  253. package/modern/hooks/useDrawingArea.js +7 -3
  254. package/modern/index.js +2 -1
  255. package/modern/internals/geometry.js +1 -1
  256. package/modern/internals/useAnimatedPath.js +29 -0
  257. package/modern/internals/utils.js +7 -0
  258. package/package.json +6 -5
@@ -1,22 +1,15 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
1
  import _extends from "@babel/runtime/helpers/esm/extends";
4
- var _excluded = ["rotate", "dominantBaseline"],
5
- _excluded2 = ["label"];
6
2
  import * as React from 'react';
7
3
  import PropTypes from 'prop-types';
8
4
  import { useSlotProps } from '@mui/base/utils';
9
- import { NoSsr } from '@mui/base/NoSsr';
10
5
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
11
- import { useThemeProps, useTheme, styled } from '@mui/material/styles';
6
+ import { useThemeProps, useTheme } from '@mui/material/styles';
12
7
  import { DrawingContext } from '../context/DrawingProvider';
13
8
  import { getSeriesToDisplay } from './utils';
14
9
  import { SeriesContext } from '../context/SeriesContextProvider';
15
10
  import { getLegendUtilityClass } from './chartsLegendClasses';
16
- import { ChartsText } from '../ChartsText';
17
- import { getWordsByLines } from '../internals/getWordsByLines';
11
+ import { DefaultChartsLegend } from './DefaultChartsLegend';
18
12
  import { jsx as _jsx } from "react/jsx-runtime";
19
- import { jsxs as _jsxs } from "react/jsx-runtime";
20
13
  var useUtilityClasses = function useUtilityClasses(ownerState) {
21
14
  var classes = ownerState.classes,
22
15
  direction = ownerState.direction;
@@ -28,13 +21,6 @@ var useUtilityClasses = function useUtilityClasses(ownerState) {
28
21
  };
29
22
  return composeClasses(slots, getLegendUtilityClass, classes);
30
23
  };
31
- export var ChartsLegendRoot = styled('g', {
32
- name: 'MuiChartsLegend',
33
- slot: 'Root',
34
- overridesResolver: function overridesResolver(props, styles) {
35
- return styles.root;
36
- }
37
- })({});
38
24
  var defaultProps = {
39
25
  position: {
40
26
  horizontal: 'middle',
@@ -42,313 +28,6 @@ var defaultProps = {
42
28
  },
43
29
  direction: 'row'
44
30
  };
45
- /**
46
- * Transforms number or partial padding object to a defaultized padding object.
47
- */
48
- var getStandardizedPadding = function getStandardizedPadding(padding) {
49
- if (typeof padding === 'number') {
50
- return {
51
- left: padding,
52
- right: padding,
53
- top: padding,
54
- bottom: padding
55
- };
56
- }
57
- return _extends({
58
- left: 0,
59
- right: 0,
60
- top: 0,
61
- bottom: 0
62
- }, padding);
63
- };
64
- function DefaultChartsLegend(props) {
65
- var hidden = props.hidden,
66
- position = props.position,
67
- direction = props.direction,
68
- seriesToDisplay = props.seriesToDisplay,
69
- drawingArea = props.drawingArea,
70
- classes = props.classes,
71
- _props$itemMarkWidth = props.itemMarkWidth,
72
- itemMarkWidth = _props$itemMarkWidth === void 0 ? 20 : _props$itemMarkWidth,
73
- _props$itemMarkHeight = props.itemMarkHeight,
74
- itemMarkHeight = _props$itemMarkHeight === void 0 ? 20 : _props$itemMarkHeight,
75
- _props$markGap = props.markGap,
76
- markGap = _props$markGap === void 0 ? 5 : _props$markGap,
77
- _props$itemGap = props.itemGap,
78
- itemGap = _props$itemGap === void 0 ? 10 : _props$itemGap,
79
- _props$padding = props.padding,
80
- paddingProps = _props$padding === void 0 ? 10 : _props$padding,
81
- inLabelStyle = props.labelStyle;
82
- var theme = useTheme();
83
- var labelStyle = React.useMemo(function () {
84
- return _extends({}, theme.typography.subtitle1, {
85
- color: 'inherit',
86
- dominantBaseline: 'central',
87
- textAnchor: 'start',
88
- fill: (theme.vars || theme).palette.text.primary,
89
- lineHeight: 1
90
- }, inLabelStyle);
91
- },
92
- // To say to TS that the dominantBaseline and textAnchor are correct
93
- [inLabelStyle, theme]);
94
- var padding = React.useMemo(function () {
95
- return getStandardizedPadding(paddingProps);
96
- }, [paddingProps]);
97
- var getItemSpace = React.useCallback(function (label) {
98
- var inStyle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
99
- var rotate = inStyle.rotate,
100
- dominantBaseline = inStyle.dominantBaseline,
101
- style = _objectWithoutProperties(inStyle, _excluded);
102
- var linesSize = getWordsByLines({
103
- style: style,
104
- needsComputation: true,
105
- text: label
106
- });
107
- var innerSize = {
108
- innerWidth: itemMarkWidth + markGap + Math.max.apply(Math, _toConsumableArray(linesSize.map(function (size) {
109
- return size.width;
110
- }))),
111
- innerHeight: Math.max(itemMarkHeight, linesSize.length * linesSize[0].height)
112
- };
113
- return _extends({}, innerSize, {
114
- outerWidth: innerSize.innerWidth + itemGap,
115
- outerHeight: innerSize.innerHeight + itemGap
116
- });
117
- }, [itemGap, itemMarkHeight, itemMarkWidth, markGap]);
118
- var totalWidth = drawingArea.left + drawingArea.width + drawingArea.right;
119
- var totalHeight = drawingArea.top + drawingArea.height + drawingArea.bottom;
120
- var availableWidth = totalWidth - padding.left - padding.right;
121
- var availableHeight = totalHeight - padding.top - padding.bottom;
122
- var seriesWithPosition = React.useMemo(function () {
123
- // Start at 0, 0. Will be modified later by padding and position.
124
- var x = 0;
125
- var y = 0;
126
-
127
- // total values used to align legend later.
128
- var totalWidthUsed = 0;
129
- var totalHeightUsed = 0;
130
- var rowIndex = 0;
131
- var rowMaxHeight = [0];
132
- var seriesWithRawPosition = seriesToDisplay.map(function (_ref) {
133
- var label = _ref.label,
134
- other = _objectWithoutProperties(_ref, _excluded2);
135
- var itemSpace = getItemSpace(label, labelStyle);
136
- var rep = _extends({}, other, {
137
- label: label,
138
- positionX: x,
139
- positionY: y,
140
- innerHeight: itemSpace.innerHeight,
141
- innerWidth: itemSpace.innerWidth,
142
- outerHeight: itemSpace.outerHeight,
143
- outerWidth: itemSpace.outerWidth,
144
- rowIndex: rowIndex
145
- });
146
- if (direction === 'row') {
147
- if (x + itemSpace.innerWidth > availableWidth) {
148
- // This legend item would create overflow along the x-axis, so we start a new row.
149
- x = 0;
150
- y += rowMaxHeight[rowIndex];
151
- rowIndex += 1;
152
- if (rowMaxHeight.length <= rowIndex) {
153
- rowMaxHeight.push(0);
154
- }
155
- rep.positionX = x;
156
- rep.positionY = y;
157
- rep.rowIndex = rowIndex;
158
- }
159
- totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
160
- totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
161
- rowMaxHeight[rowIndex] = Math.max(rowMaxHeight[rowIndex], itemSpace.outerHeight);
162
- x += itemSpace.outerWidth;
163
- }
164
- if (direction === 'column') {
165
- if (y + itemSpace.innerHeight > availableHeight) {
166
- // This legend item would create overflow along the y-axis, so we start a new column.
167
- x = totalWidthUsed + itemGap;
168
- y = 0;
169
- rowIndex = 0;
170
- rep.positionX = x;
171
- rep.positionY = y;
172
- rep.rowIndex = rowIndex;
173
- }
174
- if (rowMaxHeight.length <= rowIndex) {
175
- rowMaxHeight.push(0);
176
- }
177
- totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
178
- totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
179
- rowIndex += 1;
180
- y += itemSpace.outerHeight;
181
- }
182
- return rep;
183
- });
184
-
185
- // Move the legend according to padding and position
186
- var gapX = 0;
187
- var gapY = 0;
188
- switch (position.horizontal) {
189
- case 'left':
190
- gapX = padding.left;
191
- break;
192
- case 'right':
193
- gapX = totalWidth - padding.right - totalWidthUsed;
194
- break;
195
- default:
196
- gapX = (totalWidth - totalWidthUsed) / 2;
197
- break;
198
- }
199
- switch (position.vertical) {
200
- case 'top':
201
- gapY = padding.top;
202
- break;
203
- case 'bottom':
204
- gapY = totalHeight - padding.bottom - totalHeightUsed;
205
- break;
206
- default:
207
- gapY = (totalHeight - totalHeightUsed) / 2;
208
- break;
209
- }
210
- return seriesWithRawPosition.map(function (item) {
211
- return _extends({}, item, {
212
- // Add the gap due to the position
213
- positionX: item.positionX + gapX,
214
- // Add the gap due to the position
215
- positionY: item.positionY + gapY + (direction === 'row' ? rowMaxHeight[item.rowIndex] / 2 // Get the center of the entire row
216
- : item.outerHeight / 2) // Get the center of the item
217
- });
218
- });
219
- }, [seriesToDisplay, position.horizontal, position.vertical, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap, padding.left, padding.right, padding.top, padding.bottom, totalWidth, totalHeight]);
220
- if (hidden) {
221
- return null;
222
- }
223
- return /*#__PURE__*/_jsx(NoSsr, {
224
- children: /*#__PURE__*/_jsx(ChartsLegendRoot, {
225
- className: classes.root,
226
- children: seriesWithPosition.map(function (_ref2) {
227
- var id = _ref2.id,
228
- label = _ref2.label,
229
- color = _ref2.color,
230
- positionX = _ref2.positionX,
231
- positionY = _ref2.positionY;
232
- return /*#__PURE__*/_jsxs("g", {
233
- className: classes.series,
234
- transform: "translate(".concat(positionX, " ").concat(positionY, ")"),
235
- children: [/*#__PURE__*/_jsx("rect", {
236
- className: classes.mark,
237
- y: -itemMarkHeight / 2,
238
- width: itemMarkWidth,
239
- height: itemMarkHeight,
240
- fill: color
241
- }), /*#__PURE__*/_jsx(ChartsText, {
242
- style: labelStyle,
243
- text: label,
244
- x: itemMarkWidth + markGap,
245
- y: 0
246
- })]
247
- }, id);
248
- })
249
- })
250
- });
251
- }
252
- process.env.NODE_ENV !== "production" ? DefaultChartsLegend.propTypes = {
253
- // ----------------------------- Warning --------------------------------
254
- // | These PropTypes are generated from the TypeScript type definitions |
255
- // | To update them edit the TypeScript types and run "yarn proptypes" |
256
- // ----------------------------------------------------------------------
257
- /**
258
- * Override or extend the styles applied to the component.
259
- */
260
- classes: PropTypes.object.isRequired,
261
- /**
262
- * The direction of the legend layout.
263
- * The default depends on the chart.
264
- */
265
- direction: PropTypes.oneOf(['column', 'row']).isRequired,
266
- drawingArea: PropTypes.shape({
267
- bottom: PropTypes.number.isRequired,
268
- height: PropTypes.number.isRequired,
269
- left: PropTypes.number.isRequired,
270
- right: PropTypes.number.isRequired,
271
- top: PropTypes.number.isRequired,
272
- width: PropTypes.number.isRequired
273
- }).isRequired,
274
- /**
275
- * Set to true to hide the legend.
276
- */
277
- hidden: PropTypes.bool,
278
- /**
279
- * Space between two legend items (in px).
280
- * @default 10
281
- */
282
- itemGap: PropTypes.number,
283
- /**
284
- * Height of the item mark (in px).
285
- * @default 20
286
- */
287
- itemMarkHeight: PropTypes.number,
288
- /**
289
- * Width of the item mark (in px).
290
- * @default 20
291
- */
292
- itemMarkWidth: PropTypes.number,
293
- /**
294
- * Style applied to legend labels.
295
- * @default theme.typography.subtitle1
296
- */
297
- labelStyle: PropTypes.object,
298
- /**
299
- * Space between the mark and the label (in px).
300
- * @default 5
301
- */
302
- markGap: PropTypes.number,
303
- /**
304
- * Legend padding (in px).
305
- * Can either be a single number, or an object with top, left, bottom, right properties.
306
- * @default 0
307
- */
308
- padding: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
309
- bottom: PropTypes.number,
310
- left: PropTypes.number,
311
- right: PropTypes.number,
312
- top: PropTypes.number
313
- })]),
314
- position: PropTypes.shape({
315
- horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
316
- vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
317
- }).isRequired,
318
- series: PropTypes.shape({
319
- bar: PropTypes.shape({
320
- series: PropTypes.object.isRequired,
321
- seriesOrder: PropTypes.arrayOf(PropTypes.string).isRequired,
322
- stackingGroups: PropTypes.arrayOf(PropTypes.shape({
323
- ids: PropTypes.arrayOf(PropTypes.string).isRequired,
324
- stackingOffset: PropTypes.func.isRequired,
325
- stackingOrder: PropTypes.func.isRequired
326
- })).isRequired
327
- }),
328
- line: PropTypes.shape({
329
- series: PropTypes.object.isRequired,
330
- seriesOrder: PropTypes.arrayOf(PropTypes.string).isRequired,
331
- stackingGroups: PropTypes.arrayOf(PropTypes.shape({
332
- ids: PropTypes.arrayOf(PropTypes.string).isRequired,
333
- stackingOffset: PropTypes.func.isRequired,
334
- stackingOrder: PropTypes.func.isRequired
335
- })).isRequired
336
- }),
337
- pie: PropTypes.shape({
338
- series: PropTypes.object.isRequired,
339
- seriesOrder: PropTypes.arrayOf(PropTypes.string).isRequired
340
- }),
341
- scatter: PropTypes.shape({
342
- series: PropTypes.object.isRequired,
343
- seriesOrder: PropTypes.arrayOf(PropTypes.string).isRequired
344
- })
345
- }).isRequired,
346
- seriesToDisplay: PropTypes.arrayOf(PropTypes.shape({
347
- color: PropTypes.string.isRequired,
348
- id: PropTypes.string.isRequired,
349
- label: PropTypes.string.isRequired
350
- })).isRequired
351
- } : void 0;
352
31
  function ChartsLegend(inProps) {
353
32
  var _slots$legend;
354
33
  var props = useThemeProps({
@@ -0,0 +1,302 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ var _excluded = ["rotate", "dominantBaseline"],
5
+ _excluded2 = ["label"];
6
+ import * as React from 'react';
7
+ import PropTypes from 'prop-types';
8
+ import { NoSsr } from '@mui/base/NoSsr';
9
+ import { useTheme, styled } from '@mui/material/styles';
10
+ import { ChartsText } from '../ChartsText';
11
+ import { getWordsByLines } from '../internals/getWordsByLines';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ export var ChartsLegendRoot = styled('g', {
15
+ name: 'MuiChartsLegend',
16
+ slot: 'Root',
17
+ overridesResolver: function overridesResolver(props, styles) {
18
+ return styles.root;
19
+ }
20
+ })({});
21
+ /**
22
+ * Transforms number or partial padding object to a defaultized padding object.
23
+ */
24
+ var getStandardizedPadding = function getStandardizedPadding(padding) {
25
+ if (typeof padding === 'number') {
26
+ return {
27
+ left: padding,
28
+ right: padding,
29
+ top: padding,
30
+ bottom: padding
31
+ };
32
+ }
33
+ return _extends({
34
+ left: 0,
35
+ right: 0,
36
+ top: 0,
37
+ bottom: 0
38
+ }, padding);
39
+ };
40
+ function DefaultChartsLegend(props) {
41
+ var hidden = props.hidden,
42
+ position = props.position,
43
+ direction = props.direction,
44
+ seriesToDisplay = props.seriesToDisplay,
45
+ drawingArea = props.drawingArea,
46
+ classes = props.classes,
47
+ _props$itemMarkWidth = props.itemMarkWidth,
48
+ itemMarkWidth = _props$itemMarkWidth === void 0 ? 20 : _props$itemMarkWidth,
49
+ _props$itemMarkHeight = props.itemMarkHeight,
50
+ itemMarkHeight = _props$itemMarkHeight === void 0 ? 20 : _props$itemMarkHeight,
51
+ _props$markGap = props.markGap,
52
+ markGap = _props$markGap === void 0 ? 5 : _props$markGap,
53
+ _props$itemGap = props.itemGap,
54
+ itemGap = _props$itemGap === void 0 ? 10 : _props$itemGap,
55
+ _props$padding = props.padding,
56
+ paddingProps = _props$padding === void 0 ? 10 : _props$padding,
57
+ inLabelStyle = props.labelStyle;
58
+ var theme = useTheme();
59
+ var labelStyle = React.useMemo(function () {
60
+ return _extends({}, theme.typography.subtitle1, {
61
+ color: 'inherit',
62
+ dominantBaseline: 'central',
63
+ textAnchor: 'start',
64
+ fill: (theme.vars || theme).palette.text.primary,
65
+ lineHeight: 1
66
+ }, inLabelStyle);
67
+ },
68
+ // To say to TS that the dominantBaseline and textAnchor are correct
69
+ [inLabelStyle, theme]);
70
+ var padding = React.useMemo(function () {
71
+ return getStandardizedPadding(paddingProps);
72
+ }, [paddingProps]);
73
+ var getItemSpace = React.useCallback(function (label) {
74
+ var inStyle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
75
+ var rotate = inStyle.rotate,
76
+ dominantBaseline = inStyle.dominantBaseline,
77
+ style = _objectWithoutProperties(inStyle, _excluded);
78
+ var linesSize = getWordsByLines({
79
+ style: style,
80
+ needsComputation: true,
81
+ text: label
82
+ });
83
+ var innerSize = {
84
+ innerWidth: itemMarkWidth + markGap + Math.max.apply(Math, _toConsumableArray(linesSize.map(function (size) {
85
+ return size.width;
86
+ }))),
87
+ innerHeight: Math.max(itemMarkHeight, linesSize.length * linesSize[0].height)
88
+ };
89
+ return _extends({}, innerSize, {
90
+ outerWidth: innerSize.innerWidth + itemGap,
91
+ outerHeight: innerSize.innerHeight + itemGap
92
+ });
93
+ }, [itemGap, itemMarkHeight, itemMarkWidth, markGap]);
94
+ var totalWidth = drawingArea.left + drawingArea.width + drawingArea.right;
95
+ var totalHeight = drawingArea.top + drawingArea.height + drawingArea.bottom;
96
+ var availableWidth = totalWidth - padding.left - padding.right;
97
+ var availableHeight = totalHeight - padding.top - padding.bottom;
98
+ var seriesWithPosition = React.useMemo(function () {
99
+ // Start at 0, 0. Will be modified later by padding and position.
100
+ var x = 0;
101
+ var y = 0;
102
+
103
+ // total values used to align legend later.
104
+ var totalWidthUsed = 0;
105
+ var totalHeightUsed = 0;
106
+ var rowIndex = 0;
107
+ var rowMaxHeight = [0];
108
+ var seriesWithRawPosition = seriesToDisplay.map(function (_ref) {
109
+ var label = _ref.label,
110
+ other = _objectWithoutProperties(_ref, _excluded2);
111
+ var itemSpace = getItemSpace(label, labelStyle);
112
+ var rep = _extends({}, other, {
113
+ label: label,
114
+ positionX: x,
115
+ positionY: y,
116
+ innerHeight: itemSpace.innerHeight,
117
+ innerWidth: itemSpace.innerWidth,
118
+ outerHeight: itemSpace.outerHeight,
119
+ outerWidth: itemSpace.outerWidth,
120
+ rowIndex: rowIndex
121
+ });
122
+ if (direction === 'row') {
123
+ if (x + itemSpace.innerWidth > availableWidth) {
124
+ // This legend item would create overflow along the x-axis, so we start a new row.
125
+ x = 0;
126
+ y += rowMaxHeight[rowIndex];
127
+ rowIndex += 1;
128
+ if (rowMaxHeight.length <= rowIndex) {
129
+ rowMaxHeight.push(0);
130
+ }
131
+ rep.positionX = x;
132
+ rep.positionY = y;
133
+ rep.rowIndex = rowIndex;
134
+ }
135
+ totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
136
+ totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
137
+ rowMaxHeight[rowIndex] = Math.max(rowMaxHeight[rowIndex], itemSpace.outerHeight);
138
+ x += itemSpace.outerWidth;
139
+ }
140
+ if (direction === 'column') {
141
+ if (y + itemSpace.innerHeight > availableHeight) {
142
+ // This legend item would create overflow along the y-axis, so we start a new column.
143
+ x = totalWidthUsed + itemGap;
144
+ y = 0;
145
+ rowIndex = 0;
146
+ rep.positionX = x;
147
+ rep.positionY = y;
148
+ rep.rowIndex = rowIndex;
149
+ }
150
+ if (rowMaxHeight.length <= rowIndex) {
151
+ rowMaxHeight.push(0);
152
+ }
153
+ totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
154
+ totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
155
+ rowIndex += 1;
156
+ y += itemSpace.outerHeight;
157
+ }
158
+ return rep;
159
+ });
160
+
161
+ // Move the legend according to padding and position
162
+ var gapX = 0;
163
+ var gapY = 0;
164
+ switch (position.horizontal) {
165
+ case 'left':
166
+ gapX = padding.left;
167
+ break;
168
+ case 'right':
169
+ gapX = totalWidth - padding.right - totalWidthUsed;
170
+ break;
171
+ default:
172
+ gapX = (totalWidth - totalWidthUsed) / 2;
173
+ break;
174
+ }
175
+ switch (position.vertical) {
176
+ case 'top':
177
+ gapY = padding.top;
178
+ break;
179
+ case 'bottom':
180
+ gapY = totalHeight - padding.bottom - totalHeightUsed;
181
+ break;
182
+ default:
183
+ gapY = (totalHeight - totalHeightUsed) / 2;
184
+ break;
185
+ }
186
+ return seriesWithRawPosition.map(function (item) {
187
+ return _extends({}, item, {
188
+ // Add the gap due to the position
189
+ positionX: item.positionX + gapX,
190
+ // Add the gap due to the position
191
+ positionY: item.positionY + gapY + (direction === 'row' ? rowMaxHeight[item.rowIndex] / 2 // Get the center of the entire row
192
+ : item.outerHeight / 2) // Get the center of the item
193
+ });
194
+ });
195
+ }, [seriesToDisplay, position.horizontal, position.vertical, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap, padding.left, padding.right, padding.top, padding.bottom, totalWidth, totalHeight]);
196
+ if (hidden) {
197
+ return null;
198
+ }
199
+ return /*#__PURE__*/_jsx(NoSsr, {
200
+ children: /*#__PURE__*/_jsx(ChartsLegendRoot, {
201
+ className: classes.root,
202
+ children: seriesWithPosition.map(function (_ref2) {
203
+ var id = _ref2.id,
204
+ label = _ref2.label,
205
+ color = _ref2.color,
206
+ positionX = _ref2.positionX,
207
+ positionY = _ref2.positionY;
208
+ return /*#__PURE__*/_jsxs("g", {
209
+ className: classes.series,
210
+ transform: "translate(".concat(positionX, " ").concat(positionY, ")"),
211
+ children: [/*#__PURE__*/_jsx("rect", {
212
+ className: classes.mark,
213
+ y: -itemMarkHeight / 2,
214
+ width: itemMarkWidth,
215
+ height: itemMarkHeight,
216
+ fill: color
217
+ }), /*#__PURE__*/_jsx(ChartsText, {
218
+ style: labelStyle,
219
+ text: label,
220
+ x: itemMarkWidth + markGap,
221
+ y: 0
222
+ })]
223
+ }, id);
224
+ })
225
+ })
226
+ });
227
+ }
228
+ process.env.NODE_ENV !== "production" ? DefaultChartsLegend.propTypes = {
229
+ // ----------------------------- Warning --------------------------------
230
+ // | These PropTypes are generated from the TypeScript type definitions |
231
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
232
+ // ----------------------------------------------------------------------
233
+ /**
234
+ * Override or extend the styles applied to the component.
235
+ */
236
+ classes: PropTypes.object.isRequired,
237
+ /**
238
+ * The direction of the legend layout.
239
+ * The default depends on the chart.
240
+ */
241
+ direction: PropTypes.oneOf(['column', 'row']).isRequired,
242
+ drawingArea: PropTypes.shape({
243
+ bottom: PropTypes.number.isRequired,
244
+ height: PropTypes.number.isRequired,
245
+ left: PropTypes.number.isRequired,
246
+ right: PropTypes.number.isRequired,
247
+ top: PropTypes.number.isRequired,
248
+ width: PropTypes.number.isRequired
249
+ }).isRequired,
250
+ /**
251
+ * Set to true to hide the legend.
252
+ * @default false
253
+ */
254
+ hidden: PropTypes.bool,
255
+ /**
256
+ * Space between two legend items (in px).
257
+ * @default 10
258
+ */
259
+ itemGap: PropTypes.number,
260
+ /**
261
+ * Height of the item mark (in px).
262
+ * @default 20
263
+ */
264
+ itemMarkHeight: PropTypes.number,
265
+ /**
266
+ * Width of the item mark (in px).
267
+ * @default 20
268
+ */
269
+ itemMarkWidth: PropTypes.number,
270
+ /**
271
+ * Style applied to legend labels.
272
+ * @default theme.typography.subtitle1
273
+ */
274
+ labelStyle: PropTypes.object,
275
+ /**
276
+ * Space between the mark and the label (in px).
277
+ * @default 5
278
+ */
279
+ markGap: PropTypes.number,
280
+ /**
281
+ * Legend padding (in px).
282
+ * Can either be a single number, or an object with top, left, bottom, right properties.
283
+ * @default 10
284
+ */
285
+ padding: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
286
+ bottom: PropTypes.number,
287
+ left: PropTypes.number,
288
+ right: PropTypes.number,
289
+ top: PropTypes.number
290
+ })]),
291
+ position: PropTypes.shape({
292
+ horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
293
+ vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
294
+ }).isRequired,
295
+ series: PropTypes.object.isRequired,
296
+ seriesToDisplay: PropTypes.arrayOf(PropTypes.shape({
297
+ color: PropTypes.string.isRequired,
298
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
299
+ label: PropTypes.string.isRequired
300
+ })).isRequired
301
+ } : void 0;
302
+ export { DefaultChartsLegend };
@@ -1,3 +1,4 @@
1
1
  export * from './ChartsLegend';
2
+ export * from './DefaultChartsLegend';
2
3
  export * from './chartsLegendClasses';
3
4
  export * from './utils';