@mui/x-charts 7.0.0-beta.1 → 7.0.0-beta.3

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