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