@mui/x-charts 8.0.0-alpha.5 → 8.0.0-alpha.7

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 (251) hide show
  1. package/BarChart/AnimatedBarElement.js +1 -0
  2. package/BarChart/BarChart.js +17 -7
  3. package/BarChart/BarLabel/BarLabel.d.ts +1 -479
  4. package/BarChart/BarLabel/barLabelClasses.d.ts +1 -1
  5. package/BarChart/legend.js +1 -0
  6. package/BarChart/useBarChartProps.d.ts +4 -2
  7. package/BarChart/useBarChartProps.js +16 -3
  8. package/CHANGELOG.md +206 -1
  9. package/ChartsLabel/ChartsLabel.d.ts +2 -3
  10. package/ChartsLabel/ChartsLabel.js +3 -18
  11. package/ChartsLabel/ChartsLabelGradient.d.ts +9 -8
  12. package/ChartsLabel/ChartsLabelGradient.js +21 -18
  13. package/ChartsLabel/ChartsLabelMark.d.ts +2 -3
  14. package/ChartsLabel/ChartsLabelMark.js +5 -2
  15. package/ChartsLabel/index.d.ts +7 -0
  16. package/ChartsLabel/index.js +6 -0
  17. package/ChartsLabel/labelClasses.d.ts +0 -1
  18. package/ChartsLabel/labelGradientClasses.d.ts +5 -4
  19. package/ChartsLabel/labelGradientClasses.js +3 -2
  20. package/ChartsLabel/labelMarkClasses.d.ts +3 -2
  21. package/ChartsLabel/labelMarkClasses.js +3 -2
  22. package/ChartsLabel/package.json +6 -0
  23. package/ChartsLegend/ChartsLegend.d.ts +18 -22
  24. package/ChartsLegend/ChartsLegend.js +100 -109
  25. package/ChartsLegend/ContinuousColorLegend.d.ts +29 -38
  26. package/ChartsLegend/ContinuousColorLegend.js +198 -321
  27. package/ChartsLegend/PiecewiseColorLegend.d.ts +27 -19
  28. package/ChartsLegend/PiecewiseColorLegend.js +201 -111
  29. package/ChartsLegend/chartsLegend.types.d.ts +17 -60
  30. package/ChartsLegend/chartsLegendClasses.d.ts +7 -8
  31. package/ChartsLegend/chartsLegendClasses.js +16 -2
  32. package/ChartsLegend/colorLegend.types.d.ts +13 -0
  33. package/ChartsLegend/colorLegend.types.js +1 -0
  34. package/ChartsLegend/continuousColorLegendClasses.d.ts +26 -0
  35. package/ChartsLegend/continuousColorLegendClasses.js +23 -0
  36. package/ChartsLegend/direction.d.ts +1 -0
  37. package/ChartsLegend/direction.js +1 -0
  38. package/ChartsLegend/index.d.ts +13 -3
  39. package/ChartsLegend/index.js +9 -3
  40. package/ChartsLegend/legend.types.d.ts +10 -54
  41. package/ChartsLegend/legendContext.types.d.ts +55 -0
  42. package/ChartsLegend/legendContext.types.js +1 -0
  43. package/ChartsLegend/onClickContextBuilder.d.ts +2 -0
  44. package/ChartsLegend/onClickContextBuilder.js +7 -0
  45. package/ChartsLegend/piecewiseColorDefaultLabelFormatter.d.ts +2 -0
  46. package/ChartsLegend/piecewiseColorDefaultLabelFormatter.js +9 -0
  47. package/ChartsLegend/piecewiseColorLegend.types.d.ts +26 -0
  48. package/ChartsLegend/piecewiseColorLegend.types.js +1 -0
  49. package/ChartsLegend/piecewiseColorLegendClasses.d.ts +28 -0
  50. package/ChartsLegend/piecewiseColorLegendClasses.js +23 -0
  51. package/ChartsLegend/useAxis.d.ts +1 -1
  52. package/ChartsLegend/useAxis.js +0 -1
  53. package/ChartsReferenceLine/ChartsXReferenceLine.d.ts +1 -1
  54. package/ChartsReferenceLine/ChartsYReferenceLine.d.ts +1 -1
  55. package/ChartsSurface/ChartsSurface.js +0 -1
  56. package/ChartsTooltip/chartsTooltipClasses.d.ts +1 -1
  57. package/LineChart/AnimatedArea.js +1 -0
  58. package/LineChart/AnimatedLine.js +1 -0
  59. package/LineChart/AppearingMask.js +1 -0
  60. package/LineChart/CircleMarkElement.js +1 -0
  61. package/LineChart/LineChart.js +20 -10
  62. package/LineChart/MarkElement.js +3 -1
  63. package/LineChart/legend.js +1 -0
  64. package/LineChart/useLineChartProps.d.ts +4 -2
  65. package/LineChart/useLineChartProps.js +15 -2
  66. package/PieChart/PieArc.js +3 -1
  67. package/PieChart/PieArcLabel.js +13 -9
  68. package/PieChart/PieArcLabelPlot.js +1 -0
  69. package/PieChart/PieArcPlot.js +1 -0
  70. package/PieChart/PieChart.js +42 -41
  71. package/PieChart/legend.js +1 -0
  72. package/ScatterChart/ScatterChart.js +21 -11
  73. package/ScatterChart/legend.js +1 -0
  74. package/ScatterChart/useScatterChartProps.d.ts +4 -2
  75. package/ScatterChart/useScatterChartProps.js +15 -2
  76. package/SparkLineChart/SparkLineChart.js +1 -4
  77. package/constants/index.d.ts +1 -0
  78. package/constants/index.js +2 -1
  79. package/context/CartesianProvider/defaultizeAxis.d.ts +9 -9
  80. package/context/ChartDataProvider/useChartDataProviderProps.d.ts +18 -18
  81. package/context/ChartDataProvider/useDefaultizeAxis.d.ts +9 -9
  82. package/context/ChartProvider/ChartProvider.types.d.ts +1 -1
  83. package/context/InteractionSelectors.d.ts +11 -11
  84. package/context/PluginProvider/SeriesFormatter.types.d.ts +1 -1
  85. package/context/PluginProvider/mergePlugins.d.ts +8 -8
  86. package/context/SizeProvider/Size.types.d.ts +1 -1
  87. package/context/SizeProvider/useChartContainerDimensions.d.ts +1 -1
  88. package/hooks/index.d.ts +1 -0
  89. package/hooks/index.js +2 -1
  90. package/hooks/useLegend.d.ts +13 -0
  91. package/{modern/ChartsLegend/utils.js → hooks/useLegend.js} +20 -1
  92. package/hooks/useSvgRef.d.ts +1 -1
  93. package/index.d.ts +1 -0
  94. package/index.js +2 -1
  95. package/internals/calculateMargins.d.ts +7 -0
  96. package/internals/calculateMargins.js +25 -0
  97. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +2 -1
  98. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +60 -16
  99. package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +6 -6
  100. package/internals/components/ChartsAxesGradients/ChartsContinuousGradientObjectBound.d.ts +13 -0
  101. package/internals/components/ChartsAxesGradients/ChartsContinuousGradientObjectBound.js +61 -0
  102. package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -0
  103. package/internals/components/ChartsWrapper/ChartsWrapper.d.ts +17 -0
  104. package/internals/components/ChartsWrapper/ChartsWrapper.js +66 -0
  105. package/internals/components/ChartsWrapper/index.d.ts +1 -0
  106. package/internals/components/ChartsWrapper/index.js +1 -0
  107. package/internals/consumeSlots.d.ts +48 -0
  108. package/internals/consumeSlots.js +101 -0
  109. package/internals/consumeThemeProps.d.ts +3 -7
  110. package/internals/consumeThemeProps.js +18 -27
  111. package/internals/defaultizeColor.d.ts +6 -1
  112. package/internals/index.d.ts +1 -0
  113. package/internals/index.js +1 -0
  114. package/internals/plugins/corePlugins/useChartId/useChartId.selectors.d.ts +1 -1
  115. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +11 -11
  116. package/internals/plugins/models/plugin.d.ts +1 -1
  117. package/internals/store/useCharts.d.ts +2 -2
  118. package/internals/store/useCharts.types.d.ts +1 -1
  119. package/models/seriesType/common.d.ts +9 -0
  120. package/models/seriesType/pie.d.ts +9 -0
  121. package/modern/BarChart/AnimatedBarElement.js +1 -0
  122. package/modern/BarChart/BarChart.js +17 -7
  123. package/modern/BarChart/legend.js +1 -0
  124. package/modern/BarChart/useBarChartProps.js +16 -3
  125. package/modern/ChartsLabel/ChartsLabel.js +3 -18
  126. package/modern/ChartsLabel/ChartsLabelGradient.js +21 -18
  127. package/modern/ChartsLabel/ChartsLabelMark.js +5 -2
  128. package/modern/ChartsLabel/index.js +6 -0
  129. package/modern/ChartsLabel/labelGradientClasses.js +3 -2
  130. package/modern/ChartsLabel/labelMarkClasses.js +3 -2
  131. package/modern/ChartsLegend/ChartsLegend.js +100 -109
  132. package/modern/ChartsLegend/ContinuousColorLegend.js +198 -321
  133. package/modern/ChartsLegend/PiecewiseColorLegend.js +201 -111
  134. package/modern/ChartsLegend/chartsLegendClasses.js +16 -2
  135. package/modern/ChartsLegend/colorLegend.types.js +1 -0
  136. package/modern/ChartsLegend/continuousColorLegendClasses.js +23 -0
  137. package/modern/ChartsLegend/direction.js +1 -0
  138. package/modern/ChartsLegend/index.js +9 -3
  139. package/modern/ChartsLegend/legendContext.types.js +1 -0
  140. package/modern/ChartsLegend/onClickContextBuilder.js +7 -0
  141. package/modern/ChartsLegend/piecewiseColorDefaultLabelFormatter.js +9 -0
  142. package/modern/ChartsLegend/piecewiseColorLegend.types.js +1 -0
  143. package/modern/ChartsLegend/piecewiseColorLegendClasses.js +23 -0
  144. package/modern/ChartsLegend/useAxis.js +0 -1
  145. package/modern/ChartsSurface/ChartsSurface.js +0 -1
  146. package/modern/LineChart/AnimatedArea.js +1 -0
  147. package/modern/LineChart/AnimatedLine.js +1 -0
  148. package/modern/LineChart/AppearingMask.js +1 -0
  149. package/modern/LineChart/CircleMarkElement.js +1 -0
  150. package/modern/LineChart/LineChart.js +20 -10
  151. package/modern/LineChart/MarkElement.js +3 -1
  152. package/modern/LineChart/legend.js +1 -0
  153. package/modern/LineChart/useLineChartProps.js +15 -2
  154. package/modern/PieChart/PieArc.js +3 -1
  155. package/modern/PieChart/PieArcLabel.js +13 -9
  156. package/modern/PieChart/PieArcLabelPlot.js +1 -0
  157. package/modern/PieChart/PieArcPlot.js +1 -0
  158. package/modern/PieChart/PieChart.js +42 -41
  159. package/modern/PieChart/legend.js +1 -0
  160. package/modern/ScatterChart/ScatterChart.js +21 -11
  161. package/modern/ScatterChart/legend.js +1 -0
  162. package/modern/ScatterChart/useScatterChartProps.js +15 -2
  163. package/modern/SparkLineChart/SparkLineChart.js +1 -4
  164. package/modern/constants/index.js +2 -1
  165. package/modern/hooks/index.js +2 -1
  166. package/{ChartsLegend/utils.js → modern/hooks/useLegend.js} +20 -1
  167. package/modern/index.js +2 -1
  168. package/modern/internals/calculateMargins.js +25 -0
  169. package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +60 -16
  170. package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +6 -6
  171. package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradientObjectBound.js +61 -0
  172. package/modern/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -0
  173. package/modern/internals/components/ChartsWrapper/ChartsWrapper.js +66 -0
  174. package/modern/internals/components/ChartsWrapper/index.js +1 -0
  175. package/modern/internals/consumeSlots.js +101 -0
  176. package/modern/internals/consumeThemeProps.js +18 -27
  177. package/modern/internals/index.js +1 -0
  178. package/node/BarChart/AnimatedBarElement.js +1 -0
  179. package/node/BarChart/BarChart.js +17 -7
  180. package/node/BarChart/legend.js +1 -0
  181. package/node/BarChart/useBarChartProps.js +15 -3
  182. package/node/ChartsLabel/ChartsLabel.js +3 -18
  183. package/node/ChartsLabel/ChartsLabelGradient.js +21 -18
  184. package/node/ChartsLabel/ChartsLabelMark.js +5 -2
  185. package/node/ChartsLabel/index.js +26 -0
  186. package/node/ChartsLabel/labelGradientClasses.js +3 -2
  187. package/node/ChartsLabel/labelMarkClasses.js +3 -2
  188. package/node/ChartsLegend/ChartsLegend.js +99 -108
  189. package/node/ChartsLegend/ContinuousColorLegend.js +199 -322
  190. package/node/ChartsLegend/PiecewiseColorLegend.js +201 -111
  191. package/node/ChartsLegend/chartsLegendClasses.js +17 -3
  192. package/node/ChartsLegend/colorLegend.types.js +5 -0
  193. package/node/ChartsLegend/continuousColorLegendClasses.js +31 -0
  194. package/node/ChartsLegend/direction.js +5 -0
  195. package/node/ChartsLegend/index.js +80 -16
  196. package/node/ChartsLegend/legendContext.types.js +5 -0
  197. package/node/ChartsLegend/onClickContextBuilder.js +14 -0
  198. package/node/ChartsLegend/piecewiseColorDefaultLabelFormatter.js +15 -0
  199. package/node/ChartsLegend/piecewiseColorLegend.types.js +5 -0
  200. package/node/ChartsLegend/piecewiseColorLegendClasses.js +31 -0
  201. package/node/ChartsSurface/ChartsSurface.js +0 -1
  202. package/node/LineChart/AnimatedArea.js +1 -0
  203. package/node/LineChart/AnimatedLine.js +1 -0
  204. package/node/LineChart/AppearingMask.js +1 -0
  205. package/node/LineChart/CircleMarkElement.js +1 -0
  206. package/node/LineChart/LineChart.js +20 -10
  207. package/node/LineChart/MarkElement.js +3 -1
  208. package/node/LineChart/legend.js +1 -0
  209. package/node/LineChart/useLineChartProps.js +14 -2
  210. package/node/PieChart/PieArc.js +3 -1
  211. package/node/PieChart/PieArcLabel.js +13 -9
  212. package/node/PieChart/PieArcLabelPlot.js +1 -0
  213. package/node/PieChart/PieArcPlot.js +1 -0
  214. package/node/PieChart/PieChart.js +42 -41
  215. package/node/PieChart/legend.js +1 -0
  216. package/node/ScatterChart/ScatterChart.js +21 -11
  217. package/node/ScatterChart/legend.js +1 -0
  218. package/node/ScatterChart/useScatterChartProps.js +14 -2
  219. package/node/SparkLineChart/SparkLineChart.js +1 -4
  220. package/node/constants/index.js +3 -2
  221. package/node/hooks/index.js +13 -1
  222. package/node/{ChartsLegend/utils.js → hooks/useLegend.js} +19 -1
  223. package/node/index.js +12 -1
  224. package/node/internals/calculateMargins.js +33 -0
  225. package/node/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +61 -16
  226. package/node/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +6 -6
  227. package/node/internals/components/ChartsAxesGradients/ChartsContinuousGradientObjectBound.js +69 -0
  228. package/node/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -0
  229. package/node/internals/components/ChartsWrapper/ChartsWrapper.js +72 -0
  230. package/node/internals/components/ChartsWrapper/index.js +16 -0
  231. package/node/internals/consumeSlots.js +109 -0
  232. package/node/internals/consumeThemeProps.js +18 -27
  233. package/node/internals/index.js +12 -0
  234. package/package.json +4 -4
  235. package/ChartsLegend/ChartsLegendItem.d.ts +0 -26
  236. package/ChartsLegend/ChartsLegendItem.js +0 -65
  237. package/ChartsLegend/DefaultChartsLegend.d.ts +0 -25
  238. package/ChartsLegend/DefaultChartsLegend.js +0 -112
  239. package/ChartsLegend/LegendPerItem.d.ts +0 -65
  240. package/ChartsLegend/LegendPerItem.js +0 -129
  241. package/ChartsLegend/legendItemsPlacement.d.ts +0 -3
  242. package/ChartsLegend/legendItemsPlacement.js +0 -72
  243. package/ChartsLegend/utils.d.ts +0 -2
  244. package/modern/ChartsLegend/ChartsLegendItem.js +0 -65
  245. package/modern/ChartsLegend/DefaultChartsLegend.js +0 -112
  246. package/modern/ChartsLegend/LegendPerItem.js +0 -129
  247. package/modern/ChartsLegend/legendItemsPlacement.js +0 -72
  248. package/node/ChartsLegend/ChartsLegendItem.js +0 -72
  249. package/node/ChartsLegend/DefaultChartsLegend.js +0 -118
  250. package/node/ChartsLegend/LegendPerItem.js +0 -137
  251. package/node/ChartsLegend/legendItemsPlacement.js +0 -79
@@ -1,40 +1,130 @@
1
1
  'use client';
2
2
 
3
- import _extends from "@babel/runtime/helpers/esm/extends";
4
3
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- const _excluded = ["axisDirection", "axisId", "hideFirst", "hideLast", "labelFormatter", "onItemClick"];
4
+ import _extends from "@babel/runtime/helpers/esm/extends";
5
+ const _excluded = ["direction", "classes", "className", "markType", "labelPosition", "axisDirection", "axisId", "labelFormatter", "onItemClick"];
6
6
  import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
+ import { styled } from '@mui/material/styles';
9
+ import clsx from 'clsx';
10
+ import { ChartsLabel } from "../ChartsLabel/ChartsLabel.js";
11
+ import { ChartsLabelMark } from "../ChartsLabel/ChartsLabelMark.js";
12
+ import { consumeThemeProps } from "../internals/consumeThemeProps.js";
13
+ import { piecewiseColorLegendClasses, useUtilityClasses } from "./piecewiseColorLegendClasses.js";
8
14
  import { useAxis } from "./useAxis.js";
9
- import { LegendPerItem } from "./LegendPerItem.js";
10
- import { notNull } from "../internals/notNull.js";
11
- import { jsx as _jsx } from "react/jsx-runtime";
12
- function defaultLabelFormatter(params) {
13
- if (params.min === null) {
14
- return `<${params.formattedMax}`;
15
- }
16
- if (params.max === null) {
17
- return `>${params.formattedMin}`;
18
- }
19
- return `${params.formattedMin}-${params.formattedMax}`;
20
- }
21
- const piecewiseColorContextBuilder = context => ({
22
- type: 'piecewiseColor',
23
- color: context.color,
24
- label: context.label,
25
- maxValue: context.maxValue,
26
- minValue: context.minValue
15
+ import { piecewiseColorDefaultLabelFormatter } from "./piecewiseColorDefaultLabelFormatter.js";
16
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
17
+ const RootElement = styled('ul', {
18
+ name: 'MuiPiecewiseColorLegend',
19
+ slot: 'Root',
20
+ overridesResolver: (props, styles) => styles.root
21
+ })(({
22
+ theme,
23
+ ownerState
24
+ }) => {
25
+ return _extends({}, theme.typography.caption, {
26
+ color: (theme.vars || theme).palette.text.primary,
27
+ lineHeight: '100%',
28
+ display: 'flex',
29
+ flexDirection: ownerState.direction === 'vertical' ? 'column' : 'row',
30
+ flexShrink: 0,
31
+ gap: theme.spacing(0.5),
32
+ listStyleType: 'none',
33
+ paddingInlineStart: 0,
34
+ marginBlock: theme.spacing(1),
35
+ marginInline: theme.spacing(1),
36
+ width: 'max-content',
37
+ [`button.${piecewiseColorLegendClasses.item}`]: {
38
+ // Reset button styles
39
+ background: 'none',
40
+ border: 'none',
41
+ padding: 0,
42
+ cursor: ownerState.onItemClick ? 'pointer' : 'unset',
43
+ fontFamily: 'inherit',
44
+ fontWeight: 'inherit',
45
+ fontSize: 'inherit',
46
+ letterSpacing: 'inherit',
47
+ color: 'inherit'
48
+ },
49
+ [`.${piecewiseColorLegendClasses.item}`]: {
50
+ display: 'flex',
51
+ gap: theme.spacing(0.5)
52
+ },
53
+ [`li :not(.${piecewiseColorLegendClasses.minLabel}, .${piecewiseColorLegendClasses.maxLabel}) .${piecewiseColorLegendClasses?.mark}`]: {
54
+ alignSelf: 'center'
55
+ },
56
+ [`&.${piecewiseColorLegendClasses.start}`]: {
57
+ alignItems: 'end'
58
+ },
59
+ [`&.${piecewiseColorLegendClasses.end}`]: {
60
+ alignItems: 'start'
61
+ },
62
+ [`&.${piecewiseColorLegendClasses.horizontal}`]: {
63
+ alignItems: 'center',
64
+ [`.${piecewiseColorLegendClasses.item}`]: {
65
+ flexDirection: 'column'
66
+ },
67
+ [`&.${piecewiseColorLegendClasses.start}`]: {
68
+ alignItems: 'end'
69
+ },
70
+ [`&.${piecewiseColorLegendClasses.end}`]: {
71
+ alignItems: 'start'
72
+ },
73
+ [`.${piecewiseColorLegendClasses.minLabel}`]: {
74
+ alignItems: 'end'
75
+ },
76
+ [`&.${piecewiseColorLegendClasses.extremes}`]: {
77
+ [`.${piecewiseColorLegendClasses.minLabel}, .${piecewiseColorLegendClasses.maxLabel}`]: {
78
+ alignItems: 'center',
79
+ display: 'flex',
80
+ flexDirection: 'row'
81
+ }
82
+ }
83
+ },
84
+ [`&.${piecewiseColorLegendClasses.vertical}`]: {
85
+ [`.${piecewiseColorLegendClasses.item}`]: {
86
+ flexDirection: 'row',
87
+ alignItems: 'center'
88
+ },
89
+ [`&.${piecewiseColorLegendClasses.start}`]: {
90
+ alignItems: 'end'
91
+ },
92
+ [`&.${piecewiseColorLegendClasses.end}`]: {
93
+ alignItems: 'start'
94
+ },
95
+ [`&.${piecewiseColorLegendClasses.extremes}`]: {
96
+ alignItems: 'center',
97
+ [`.${piecewiseColorLegendClasses.minLabel}, .${piecewiseColorLegendClasses.maxLabel}`]: {
98
+ alignItems: 'center',
99
+ display: 'flex',
100
+ flexDirection: 'column'
101
+ }
102
+ }
103
+ }
104
+ });
27
105
  });
28
- function PiecewiseColorLegend(props) {
106
+ const PiecewiseColorLegend = consumeThemeProps('MuiPiecewiseColorLegend', {
107
+ defaultProps: {
108
+ direction: 'horizontal',
109
+ labelPosition: 'extremes',
110
+ labelFormatter: piecewiseColorDefaultLabelFormatter
111
+ },
112
+ classesResolver: useUtilityClasses
113
+ }, function PiecewiseColorLegend(props, ref) {
29
114
  const {
115
+ direction,
116
+ classes,
117
+ className,
118
+ markType,
119
+ labelPosition,
30
120
  axisDirection,
31
121
  axisId,
32
- hideFirst,
33
- hideLast,
34
- labelFormatter = defaultLabelFormatter,
122
+ labelFormatter,
35
123
  onItemClick
36
124
  } = props,
37
125
  other = _objectWithoutPropertiesLoose(props, _excluded);
126
+ const isVertical = direction === 'vertical';
127
+ const isReverse = isVertical;
38
128
  const axisItem = useAxis({
39
129
  axisDirection,
40
130
  axisId
@@ -47,42 +137,83 @@ function PiecewiseColorLegend(props) {
47
137
  location: 'legend'
48
138
  }) ?? v.toLocaleString();
49
139
  const formattedLabels = colorMap.thresholds.map(valueFormatter);
50
- const itemsToDisplay = colorMap.colors.map((color, index) => {
51
- const isFirst = index === 0;
52
- const isLast = index === colorMap.colors.length - 1;
53
- if (hideFirst && isFirst || hideLast && isLast) {
54
- return null;
55
- }
56
- const data = _extends({}, isFirst ? {
57
- min: null,
58
- formattedMin: null
59
- } : {
60
- min: colorMap.thresholds[index - 1],
61
- formattedMin: formattedLabels[index - 1]
62
- }, isLast ? {
63
- max: null,
64
- formattedMax: null
65
- } : {
66
- max: colorMap.thresholds[index],
67
- formattedMax: formattedLabels[index]
68
- });
69
- const label = labelFormatter(data);
70
- if (label === null) {
71
- return null;
72
- }
73
- return {
74
- id: label,
140
+ const startClass = isReverse ? classes?.maxLabel : classes?.minLabel;
141
+ const endClass = isReverse ? classes?.minLabel : classes?.maxLabel;
142
+ const colors = colorMap.colors.map((color, colorIndex) => ({
143
+ color,
144
+ colorIndex
145
+ }));
146
+ const orderedColors = isReverse ? colors.reverse() : colors;
147
+ const isStart = labelPosition === 'start';
148
+ const isEnd = labelPosition === 'end';
149
+ const isExtremes = labelPosition === 'extremes';
150
+ return /*#__PURE__*/_jsx(RootElement, _extends({
151
+ className: clsx(classes?.root, className),
152
+ ref: ref
153
+ }, other, {
154
+ ownerState: props,
155
+ children: orderedColors.map(({
75
156
  color,
76
- label,
77
- minValue: data.min,
78
- maxValue: data.max
79
- };
80
- }).filter(notNull);
81
- return /*#__PURE__*/_jsx(LegendPerItem, _extends({}, other, {
82
- itemsToDisplay: itemsToDisplay,
83
- onItemClick: onItemClick ? (event, i) => onItemClick(event, piecewiseColorContextBuilder(itemsToDisplay[i]), i) : undefined
157
+ colorIndex
158
+ }, index) => {
159
+ const isFirst = index === 0;
160
+ const isLast = index === colorMap.colors.length - 1;
161
+ const isFirstColor = colorIndex === 0;
162
+ const isLastColor = colorIndex === colorMap.colors.length - 1;
163
+ const data = _extends({
164
+ index: colorIndex,
165
+ length: formattedLabels.length
166
+ }, isFirstColor ? {
167
+ min: null,
168
+ formattedMin: null
169
+ } : {
170
+ min: colorMap.thresholds[colorIndex - 1],
171
+ formattedMin: formattedLabels[colorIndex - 1]
172
+ }, isLastColor ? {
173
+ max: null,
174
+ formattedMax: null
175
+ } : {
176
+ max: colorMap.thresholds[colorIndex],
177
+ formattedMax: formattedLabels[colorIndex]
178
+ });
179
+ const label = labelFormatter?.(data);
180
+ if (label === null || label === undefined) {
181
+ return null;
182
+ }
183
+ const isTextBefore = isStart || isExtremes && isFirst;
184
+ const isTextAfter = isEnd || isExtremes && isLast;
185
+ const clickObject = {
186
+ type: 'piecewiseColor',
187
+ color,
188
+ label,
189
+ minValue: data.min,
190
+ maxValue: data.max
191
+ };
192
+ const Element = onItemClick ? 'button' : 'div';
193
+ return /*#__PURE__*/_jsx("li", {
194
+ children: /*#__PURE__*/_jsxs(Element, {
195
+ role: onItemClick ? 'button' : undefined,
196
+ type: onItemClick ? 'button' : undefined,
197
+ onClick:
198
+ // @ts-ignore onClick is only attached to a button
199
+ onItemClick ? event => onItemClick(event, clickObject, index) : undefined,
200
+ className: clsx(classes?.item, index === 0 && `${startClass}`, index === orderedColors.length - 1 && `${endClass}`),
201
+ children: [isTextBefore && /*#__PURE__*/_jsx(ChartsLabel, {
202
+ className: classes?.label,
203
+ children: label
204
+ }), /*#__PURE__*/_jsx(ChartsLabelMark, {
205
+ className: classes?.mark,
206
+ type: markType,
207
+ color: color
208
+ }), isTextAfter && /*#__PURE__*/_jsx(ChartsLabel, {
209
+ className: classes?.label,
210
+ children: label
211
+ })]
212
+ })
213
+ }, colorIndex);
214
+ })
84
215
  }));
85
- }
216
+ });
86
217
  process.env.NODE_ENV !== "production" ? PiecewiseColorLegend.propTypes = {
87
218
  // ----------------------------- Warning --------------------------------
88
219
  // | These PropTypes are generated from the TypeScript type definitions |
@@ -102,76 +233,35 @@ process.env.NODE_ENV !== "production" ? PiecewiseColorLegend.propTypes = {
102
233
  * Override or extend the styles applied to the component.
103
234
  */
104
235
  classes: PropTypes.object,
236
+ className: PropTypes.string,
105
237
  /**
106
238
  * The direction of the legend layout.
107
- * The default depends on the chart.
108
- */
109
- direction: PropTypes.oneOf(['column', 'row']).isRequired,
110
- /**
111
- * Hide the first item of the legend, corresponding to the [-infinity, min] piece.
112
- * @default false
239
+ * @default 'horizontal'
113
240
  */
114
- hideFirst: PropTypes.bool,
115
- /**
116
- * Hide the last item of the legend, corresponding to the [max, +infinity] piece.
117
- * @default false
118
- */
119
- hideLast: PropTypes.bool,
120
- /**
121
- * Space between two legend items (in px).
122
- * @default 10
123
- */
124
- itemGap: PropTypes.number,
125
- /**
126
- * Height of the item mark (in px).
127
- * @default 20
128
- */
129
- itemMarkHeight: PropTypes.number,
130
- /**
131
- * Width of the item mark (in px).
132
- * @default 20
133
- */
134
- itemMarkWidth: PropTypes.number,
241
+ direction: PropTypes.oneOf(['horizontal', 'vertical']),
135
242
  /**
136
243
  * Format the legend labels.
137
244
  * @param {PiecewiseLabelFormatterParams} params The bound of the piece to format.
138
- * @returns {string|null} The displayed label, or `null` to skip the item.
245
+ * @returns {string|null} The displayed label, `''` to skip the label but show the color mark, or `null` to skip it entirely.
139
246
  */
140
247
  labelFormatter: PropTypes.func,
141
248
  /**
142
- * Style applied to legend labels.
143
- * @default theme.typography.subtitle1
249
+ * Where to position the labels relative to the gradient.
250
+ * @default 'extremes'
144
251
  */
145
- labelStyle: PropTypes.object,
252
+ labelPosition: PropTypes.oneOf(['start', 'end', 'extremes']),
146
253
  /**
147
- * Space between the mark and the label (in px).
148
- * @default 5
254
+ * The type of the mark.
255
+ * @default 'square'
149
256
  */
150
- markGap: PropTypes.number,
257
+ markType: PropTypes.oneOf(['square', 'circle', 'line']),
151
258
  /**
152
259
  * Callback fired when a legend item is clicked.
153
- * @param {React.MouseEvent<SVGRectElement, MouseEvent>} event The click event.
260
+ * @param {React.MouseEvent<HTMLButtonElement, MouseEvent>} event The click event.
154
261
  * @param {PiecewiseColorLegendItemContext} legendItem The legend item data.
155
262
  * @param {number} index The index of the clicked legend item.
156
263
  */
157
264
  onItemClick: PropTypes.func,
158
- /**
159
- * Legend padding (in px).
160
- * Can either be a single number, or an object with top, left, bottom, right properties.
161
- * @default 10
162
- */
163
- padding: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
164
- bottom: PropTypes.number,
165
- left: PropTypes.number,
166
- right: PropTypes.number,
167
- top: PropTypes.number
168
- })]),
169
- /**
170
- * The position of the legend.
171
- */
172
- position: PropTypes.shape({
173
- horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
174
- vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
175
- }).isRequired
265
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
176
266
  } : void 0;
177
267
  export { PiecewiseColorLegend };
@@ -1,6 +1,20 @@
1
1
  import generateUtilityClass from '@mui/utils/generateUtilityClass';
2
2
  import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
3
- export function getLegendUtilityClass(slot) {
3
+ import composeClasses from '@mui/utils/composeClasses';
4
+ function getLegendUtilityClass(slot) {
4
5
  return generateUtilityClass('MuiChartsLegend', slot);
5
6
  }
6
- export const legendClasses = generateUtilityClasses('MuiChartsLegend', ['root', 'series', 'itemBackground', 'mark', 'label', 'column', 'row']);
7
+ export const useUtilityClasses = props => {
8
+ const {
9
+ classes,
10
+ direction
11
+ } = props;
12
+ const slots = {
13
+ root: ['root', direction],
14
+ mark: ['mark'],
15
+ label: ['label'],
16
+ series: ['series']
17
+ };
18
+ return composeClasses(slots, getLegendUtilityClass, classes);
19
+ };
20
+ export const legendClasses = generateUtilityClasses('MuiChartsLegend', ['root', 'series', 'mark', 'label', 'vertical', 'horizontal']);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import generateUtilityClass from '@mui/utils/generateUtilityClass';
2
+ import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
3
+ import composeClasses from '@mui/utils/composeClasses';
4
+ function getLegendUtilityClass(slot) {
5
+ return generateUtilityClass('MuiContinuousColorLegend', slot);
6
+ }
7
+ export const useUtilityClasses = props => {
8
+ const {
9
+ classes,
10
+ direction,
11
+ labelPosition
12
+ } = props;
13
+ const slots = {
14
+ root: ['root', direction, labelPosition],
15
+ minLabel: ['minLabel'],
16
+ maxLabel: ['maxLabel'],
17
+ gradient: ['gradient'],
18
+ mark: ['mark'],
19
+ label: ['label']
20
+ };
21
+ return composeClasses(slots, getLegendUtilityClass, classes);
22
+ };
23
+ export const continuousColorLegendClasses = generateUtilityClasses('MuiContinuousColorLegend', ['root', 'minLabel', 'maxLabel', 'gradient', 'vertical', 'horizontal', 'start', 'end', 'extremes', 'label']);
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,12 @@
1
1
  export * from "./ChartsLegend.js";
2
- export * from "./DefaultChartsLegend.js";
2
+ export * from "./chartsLegend.types.js";
3
+ export * from "./direction.js";
4
+ export * from "./legendContext.types.js";
5
+ export { legendClasses } from "./chartsLegendClasses.js";
3
6
  export * from "./ContinuousColorLegend.js";
7
+ export * from "./colorLegend.types.js";
8
+ export { continuousColorLegendClasses } from "./continuousColorLegendClasses.js";
4
9
  export * from "./PiecewiseColorLegend.js";
5
- export * from "./chartsLegendClasses.js";
6
- export * from "./utils.js";
10
+ export { piecewiseColorLegendClasses } from "./piecewiseColorLegendClasses.js";
11
+ export { piecewiseColorDefaultLabelFormatter } from "./piecewiseColorDefaultLabelFormatter.js";
12
+ export * from "./legend.types.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export const seriesContextBuilder = context => ({
2
+ type: 'series',
3
+ color: context.color,
4
+ label: context.label,
5
+ seriesId: context.seriesId,
6
+ itemId: context.itemId
7
+ });
@@ -0,0 +1,9 @@
1
+ export function piecewiseColorDefaultLabelFormatter(params) {
2
+ if (params.min === null) {
3
+ return `<${params.formattedMax}`;
4
+ }
5
+ if (params.max === null) {
6
+ return `>${params.formattedMin}`;
7
+ }
8
+ return `${params.formattedMin}-${params.formattedMax}`;
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import generateUtilityClass from '@mui/utils/generateUtilityClass';
2
+ import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
3
+ import composeClasses from '@mui/utils/composeClasses';
4
+ function getLegendUtilityClass(slot) {
5
+ return generateUtilityClass('MuiPiecewiseColorLegendClasses', slot);
6
+ }
7
+ export const useUtilityClasses = props => {
8
+ const {
9
+ classes,
10
+ direction,
11
+ labelPosition
12
+ } = props;
13
+ const slots = {
14
+ root: ['root', direction, labelPosition],
15
+ minLabel: ['minLabel'],
16
+ maxLabel: ['maxLabel'],
17
+ item: ['item'],
18
+ mark: ['mark'],
19
+ label: ['label']
20
+ };
21
+ return composeClasses(slots, getLegendUtilityClass, classes);
22
+ };
23
+ export const piecewiseColorLegendClasses = generateUtilityClasses('MuiPiecewiseColorLegendClasses', ['root', 'minLabel', 'maxLabel', 'item', 'vertical', 'horizontal', 'start', 'end', 'extremes', 'mark', 'label']);
@@ -2,7 +2,6 @@
2
2
 
3
3
  import { useCartesianContext } from "../context/CartesianProvider/useCartesianContext.js";
4
4
  import { useZAxis } from "../hooks/useZAxis.js";
5
-
6
5
  /**
7
6
  * Helper to select an axis definition according to its direction and id.
8
7
  */
@@ -22,7 +22,6 @@ const ChartsSurfaceStyles = styled('svg', {
22
22
  height: ownerState.height ?? '100%',
23
23
  display: 'flex',
24
24
  position: 'relative',
25
- flexGrow: 1,
26
25
  flexDirection: 'column',
27
26
  alignItems: 'center',
28
27
  justifyContent: 'center',
@@ -44,6 +44,7 @@ function AnimatedArea(props) {
44
44
  skipAnimation: skipAnimation,
45
45
  id: `${ownerState.id}-area-clip`,
46
46
  children: transitionChange((style, interpolator) => /*#__PURE__*/_jsx(animated.path, _extends({
47
+ // @ts-expect-error
47
48
  d: style.value.to(interpolator),
48
49
  fill: ownerState.gradientId ? `url(#${ownerState.gradientId})` : ownerState.color,
49
50
  filter:
@@ -44,6 +44,7 @@ function AnimatedLine(props) {
44
44
  skipAnimation: skipAnimation,
45
45
  id: `${ownerState.id}-line-clip`,
46
46
  children: transitionChange((style, interpolator) => /*#__PURE__*/_jsx(animated.path, _extends({
47
+ // @ts-expect-error
47
48
  d: style.value.to(interpolator),
48
49
  stroke: ownerState.gradientId ? `url(#${ownerState.gradientId})` : ownerState.color,
49
50
  strokeWidth: 2,
@@ -29,6 +29,7 @@ export function AppearingMask(props) {
29
29
  children: [/*#__PURE__*/_jsx("clipPath", {
30
30
  id: clipId,
31
31
  children: transitionAppear(style => /*#__PURE__*/_jsx(animated.rect, {
32
+ // @ts-expect-error
32
33
  x: 0,
33
34
  y: 0,
34
35
  width: style.animatedWidth,
@@ -69,6 +69,7 @@ function CircleMarkElement(props) {
69
69
  };
70
70
  const classes = useUtilityClasses(ownerState);
71
71
  return /*#__PURE__*/_jsx(animated.circle, _extends({}, other, {
72
+ // @ts-expect-error
72
73
  cx: position.x,
73
74
  cy: position.y,
74
75
  r: 5,
@@ -6,7 +6,6 @@ import PropTypes from 'prop-types';
6
6
  import { useThemeProps } from '@mui/material/styles';
7
7
  import { AreaPlot } from "./AreaPlot.js";
8
8
  import { LinePlot } from "./LinePlot.js";
9
- import { ChartContainer } from "../ChartContainer/index.js";
10
9
  import { MarkPlot } from "./MarkPlot.js";
11
10
  import { ChartsAxis } from "../ChartsAxis/ChartsAxis.js";
12
11
  import { ChartsTooltip } from "../ChartsTooltip/index.js";
@@ -18,6 +17,10 @@ import { ChartsGrid } from "../ChartsGrid/index.js";
18
17
  import { ChartsOnAxisClickHandler } from "../ChartsOnAxisClickHandler/index.js";
19
18
  import { ChartsOverlay } from "../ChartsOverlay/index.js";
20
19
  import { useLineChartProps } from "./useLineChartProps.js";
20
+ import { useChartContainerProps } from "../ChartContainer/useChartContainerProps.js";
21
+ import { ChartDataProvider } from "../context/index.js";
22
+ import { ChartsSurface } from "../ChartsSurface/index.js";
23
+ import { ChartsWrapper } from "../internals/components/ChartsWrapper/index.js";
21
24
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
22
25
  /**
23
26
  * Demos:
@@ -35,6 +38,7 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(inProps, ref)
35
38
  name: 'MuiLineChart'
36
39
  });
37
40
  const {
41
+ chartsWrapperProps,
38
42
  chartContainerProps,
39
43
  axisClickHandlerProps,
40
44
  gridProps,
@@ -50,16 +54,22 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(inProps, ref)
50
54
  legendProps,
51
55
  children
52
56
  } = useLineChartProps(props);
57
+ const {
58
+ chartDataProviderProps,
59
+ chartsSurfaceProps
60
+ } = useChartContainerProps(chartContainerProps, ref);
53
61
  const Tooltip = props.slots?.tooltip ?? ChartsTooltip;
54
- return /*#__PURE__*/_jsxs(ChartContainer, _extends({
55
- ref: ref
56
- }, chartContainerProps, {
57
- children: [props.onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, _extends({}, axisClickHandlerProps)), /*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsxs("g", _extends({}, clipPathGroupProps, {
58
- children: [/*#__PURE__*/_jsx(AreaPlot, _extends({}, areaPlotProps)), /*#__PURE__*/_jsx(LinePlot, _extends({}, linePlotProps)), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps))]
59
- })), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), /*#__PURE__*/_jsx("g", {
60
- "data-drawing-container": true,
61
- children: /*#__PURE__*/_jsx(MarkPlot, _extends({}, markPlotProps))
62
- }), /*#__PURE__*/_jsx(LineHighlightPlot, _extends({}, lineHighlightPlotProps)), !props.hideLegend && /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), !props.loading && /*#__PURE__*/_jsx(Tooltip, _extends({}, props.slotProps?.tooltip)), /*#__PURE__*/_jsx(ChartsClipPath, _extends({}, clipPathProps)), children]
62
+ return /*#__PURE__*/_jsx(ChartDataProvider, _extends({}, chartDataProviderProps, {
63
+ children: /*#__PURE__*/_jsxs(ChartsWrapper, _extends({}, chartsWrapperProps, {
64
+ children: [!props.hideLegend && /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), /*#__PURE__*/_jsxs(ChartsSurface, _extends({}, chartsSurfaceProps, {
65
+ children: [props.onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, _extends({}, axisClickHandlerProps)), /*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsxs("g", _extends({}, clipPathGroupProps, {
66
+ children: [/*#__PURE__*/_jsx(AreaPlot, _extends({}, areaPlotProps)), /*#__PURE__*/_jsx(LinePlot, _extends({}, linePlotProps)), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps))]
67
+ })), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), /*#__PURE__*/_jsx("g", {
68
+ "data-drawing-container": true,
69
+ children: /*#__PURE__*/_jsx(MarkPlot, _extends({}, markPlotProps))
70
+ }), /*#__PURE__*/_jsx(LineHighlightPlot, _extends({}, lineHighlightPlotProps)), !props.loading && /*#__PURE__*/_jsx(Tooltip, _extends({}, props.slotProps?.tooltip)), /*#__PURE__*/_jsx(ChartsClipPath, _extends({}, clipPathProps)), children]
71
+ }))]
72
+ }))
63
73
  }));
64
74
  });
65
75
  process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
@@ -80,7 +80,9 @@ function MarkElement(props) {
80
80
  transform: to([position.x, position.y], (pX, pY) => `translate(${pX}px, ${pY}px)`),
81
81
  transformOrigin: to([position.x, position.y], (pX, pY) => `${pX}px ${pY}px`)
82
82
  },
83
- ownerState: ownerState,
83
+ ownerState: ownerState
84
+ // @ts-expect-error
85
+ ,
84
86
  className: classes.root,
85
87
  d: d3Symbol(d3SymbolsFill[getSymbol(shape)])(),
86
88
  onClick: onClick,
@@ -10,6 +10,7 @@ const legendGetter = params => {
10
10
  return acc;
11
11
  }
12
12
  acc.push({
13
+ markType: series[seriesId].labelMarkType ?? 'line',
13
14
  id: seriesId,
14
15
  seriesId,
15
16
  color: series[seriesId].color,