@mui/x-charts 8.0.0-alpha.6 → 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 +127 -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,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  export declare const useChartContainerDimensions: (inWidth?: number, inHeight?: number) => {
3
- svgRef: React.RefObject<SVGSVGElement>;
3
+ svgRef: React.RefObject<SVGSVGElement | null>;
4
4
  width: number;
5
5
  height: number;
6
6
  hasIntrinsicSize: boolean;
package/hooks/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export * from './useAxis';
5
5
  export * from './useColorScale';
6
6
  export * from './useSvgRef';
7
7
  export { useSeries as unstable_useSeries, usePieSeries as unstable_usePieSeries, useLineSeries as unstable_useLineSeries, useBarSeries as unstable_useBarSeries, useScatterSeries as unstable_useScatterSeries, } from './useSeries';
8
+ export * from './useLegend';
package/hooks/index.js CHANGED
@@ -4,4 +4,5 @@ export * from "./useScale.js";
4
4
  export * from "./useAxis.js";
5
5
  export * from "./useColorScale.js";
6
6
  export * from "./useSvgRef.js";
7
- export { useSeries as unstable_useSeries, usePieSeries as unstable_usePieSeries, useLineSeries as unstable_useLineSeries, useBarSeries as unstable_useBarSeries, useScatterSeries as unstable_useScatterSeries } from "./useSeries.js";
7
+ export { useSeries as unstable_useSeries, usePieSeries as unstable_usePieSeries, useLineSeries as unstable_useLineSeries, useBarSeries as unstable_useBarSeries, useScatterSeries as unstable_useScatterSeries } from "./useSeries.js";
8
+ export * from "./useLegend.js";
@@ -0,0 +1,13 @@
1
+ import type { LegendItemParams } from '../ChartsLegend';
2
+ /**
3
+ * Get the legend items to display.
4
+ *
5
+ * This hook is used by the `ChartsLegend` component. And will return the legend items formatted for display.
6
+ *
7
+ * An alternative is to use the `useSeries` hook and format the legend items yourself.
8
+ *
9
+ * @returns legend data
10
+ */
11
+ export declare function useLegend(): {
12
+ items: LegendItemParams[];
13
+ };
@@ -1,16 +1,35 @@
1
+ 'use client';
2
+
1
3
  import getBarLegend from "../BarChart/legend.js";
2
4
  import getScatterLegend from "../ScatterChart/legend.js";
3
5
  import getLineLegend from "../LineChart/legend.js";
4
6
  import getPieLegend from "../PieChart/legend.js";
7
+ import { useSeries } from "./useSeries.js";
5
8
  const legendGetter = {
6
9
  bar: getBarLegend,
7
10
  scatter: getScatterLegend,
8
11
  line: getLineLegend,
9
12
  pie: getPieLegend
10
13
  };
11
- export function getSeriesToDisplay(series) {
14
+ function getSeriesToDisplay(series) {
12
15
  return Object.keys(series).flatMap(seriesType => {
13
16
  const getter = legendGetter[seriesType];
14
17
  return getter === undefined ? [] : getter(series[seriesType]);
15
18
  });
19
+ }
20
+
21
+ /**
22
+ * Get the legend items to display.
23
+ *
24
+ * This hook is used by the `ChartsLegend` component. And will return the legend items formatted for display.
25
+ *
26
+ * An alternative is to use the `useSeries` hook and format the legend items yourself.
27
+ *
28
+ * @returns legend data
29
+ */
30
+ export function useLegend() {
31
+ const series = useSeries();
32
+ return {
33
+ items: getSeriesToDisplay(series)
34
+ };
16
35
  }
@@ -1,2 +1,2 @@
1
1
  import * as React from 'react';
2
- export declare function useSvgRef(): React.RefObject<SVGSVGElement>;
2
+ export declare function useSvgRef(): React.RefObject<SVGSVGElement | null>;
package/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export * from './ChartsYAxis';
11
11
  export * from './ChartsGrid';
12
12
  export * from './ChartsText';
13
13
  export * from './ChartsTooltip';
14
+ export * from './ChartsLabel';
14
15
  export * from './ChartsLegend';
15
16
  export * from './ChartsAxisHighlight';
16
17
  export * from './ChartsVoronoiHandler';
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v8.0.0-alpha.6
2
+ * @mui/x-charts v8.0.0-alpha.7
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -18,6 +18,7 @@ export * from "./ChartsYAxis/index.js";
18
18
  export * from "./ChartsGrid/index.js";
19
19
  export * from "./ChartsText/index.js";
20
20
  export * from "./ChartsTooltip/index.js";
21
+ export * from "./ChartsLabel/index.js";
21
22
  export * from "./ChartsLegend/index.js";
22
23
  export * from "./ChartsAxisHighlight/index.js";
23
24
  export * from "./ChartsVoronoiHandler/index.js";
@@ -0,0 +1,7 @@
1
+ import type { ChartsLegendSlotExtension } from '../ChartsLegend';
2
+ import type { LayoutConfig } from '../models';
3
+ import type { CartesianChartSeriesType, ChartsSeriesConfig } from '../models/seriesType/config';
4
+ export declare const calculateMargins: <T extends ChartsLegendSlotExtension & Pick<LayoutConfig, "margin"> & {
5
+ hideLegend?: boolean;
6
+ series?: Partial<ChartsSeriesConfig[CartesianChartSeriesType]["seriesProp"]>[];
7
+ }>(props: T) => Required<LayoutConfig["margin"]>;
@@ -0,0 +1,25 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { DEFAULT_MARGINS, DEFAULT_LEGEND_FACING_MARGIN } from "../constants/index.js";
3
+ export const calculateMargins = props => {
4
+ if (props.hideLegend || !props.series?.some(s => s.label)) {
5
+ return _extends({}, DEFAULT_MARGINS, props.margin);
6
+ }
7
+ if (props.slotProps?.legend?.direction === 'vertical') {
8
+ if (props.slotProps?.legend?.position?.horizontal === 'left') {
9
+ return _extends({}, DEFAULT_MARGINS, {
10
+ left: DEFAULT_LEGEND_FACING_MARGIN
11
+ }, props.margin);
12
+ }
13
+ return _extends({}, DEFAULT_MARGINS, {
14
+ right: DEFAULT_LEGEND_FACING_MARGIN
15
+ }, props.margin);
16
+ }
17
+ if (props.slotProps?.legend?.position?.vertical === 'bottom') {
18
+ return _extends({}, DEFAULT_MARGINS, {
19
+ bottom: DEFAULT_LEGEND_FACING_MARGIN
20
+ }, props.margin);
21
+ }
22
+ return _extends({}, DEFAULT_MARGINS, {
23
+ top: DEFAULT_LEGEND_FACING_MARGIN
24
+ }, props.margin);
25
+ };
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
2
  import { AxisId } from '../../../models/axis';
3
- export declare function useChartGradient(): (axisId: AxisId, direction: "x" | "y") => string;
3
+ export declare function useChartGradient(): (axisId: AxisId, direction: "x" | "y" | "z") => string;
4
+ export declare function useChartGradientObjectBound(): (axisId: AxisId, direction: "x" | "y" | "z") => string;
4
5
  export declare function ChartsAxesGradients(): React.JSX.Element | null;
@@ -3,11 +3,19 @@ import { useCartesianContext } from "../../../context/CartesianProvider/index.js
3
3
  import { useChartId, useDrawingArea } from "../../../hooks/index.js";
4
4
  import ChartsPiecewiseGradient from "./ChartsPiecewiseGradient.js";
5
5
  import ChartsContinuousGradient from "./ChartsContinuousGradient.js";
6
+ import ChartsContinuousGradientObjectBound from "./ChartsContinuousGradientObjectBound.js";
7
+ import { useZAxis } from "../../../hooks/useZAxis.js";
6
8
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
7
9
  export function useChartGradient() {
8
10
  const chartId = useChartId();
9
11
  return React.useCallback((axisId, direction) => `${chartId}-gradient-${direction}-${axisId}`, [chartId]);
10
12
  }
13
+
14
+ // TODO: make public?
15
+ export function useChartGradientObjectBound() {
16
+ const chartId = useChartId();
17
+ return React.useCallback((axisId, direction) => `${chartId}-gradient-${direction}-${axisId}-object-bound`, [chartId]);
18
+ }
11
19
  export function ChartsAxesGradients() {
12
20
  const {
13
21
  top,
@@ -20,20 +28,27 @@ export function ChartsAxesGradients() {
20
28
  const svgHeight = top + height + bottom;
21
29
  const svgWidth = left + width + right;
22
30
  const getGradientId = useChartGradient();
31
+ const getObjectBoundGradientId = useChartGradientObjectBound();
23
32
  const {
24
33
  xAxisIds,
25
34
  xAxis,
26
35
  yAxisIds,
27
36
  yAxis
28
37
  } = useCartesianContext();
38
+ const {
39
+ zAxisIds,
40
+ zAxis
41
+ } = useZAxis();
29
42
  const filteredYAxisIds = yAxisIds.filter(axisId => yAxis[axisId].colorMap !== undefined);
30
43
  const filteredXAxisIds = xAxisIds.filter(axisId => xAxis[axisId].colorMap !== undefined);
31
- if (filteredYAxisIds.length === 0 && filteredXAxisIds.length === 0) {
44
+ const filteredZAxisIds = zAxisIds.filter(axisId => zAxis[axisId].colorMap !== undefined);
45
+ if (filteredYAxisIds.length === 0 && filteredXAxisIds.length === 0 && filteredZAxisIds.length === 0) {
32
46
  return null;
33
47
  }
34
48
  return /*#__PURE__*/_jsxs("defs", {
35
49
  children: [filteredYAxisIds.map(axisId => {
36
50
  const gradientId = getGradientId(axisId, 'y');
51
+ const objectBoundGradientId = getObjectBoundGradientId(axisId, 'y');
37
52
  const {
38
53
  colorMap,
39
54
  scale,
@@ -51,19 +66,27 @@ export function ChartsAxesGradients() {
51
66
  }, gradientId);
52
67
  }
53
68
  if (colorMap?.type === 'continuous') {
54
- return /*#__PURE__*/_jsx(ChartsContinuousGradient, {
55
- isReversed: !reverse,
56
- scale: scale,
57
- colorScale: colorScale,
58
- colorMap: colorMap,
59
- size: svgHeight,
60
- gradientId: gradientId,
61
- direction: "y"
69
+ return /*#__PURE__*/_jsxs(React.Fragment, {
70
+ children: [/*#__PURE__*/_jsx(ChartsContinuousGradient, {
71
+ isReversed: !reverse,
72
+ scale: scale,
73
+ colorScale: colorScale,
74
+ colorMap: colorMap,
75
+ size: svgHeight,
76
+ gradientId: gradientId,
77
+ direction: "y"
78
+ }), /*#__PURE__*/_jsx(ChartsContinuousGradientObjectBound, {
79
+ isReversed: reverse,
80
+ colorScale: colorScale,
81
+ colorMap: colorMap,
82
+ gradientId: objectBoundGradientId
83
+ })]
62
84
  }, gradientId);
63
85
  }
64
86
  return null;
65
87
  }), filteredXAxisIds.map(axisId => {
66
88
  const gradientId = getGradientId(axisId, 'x');
89
+ const objectBoundGradientId = getObjectBoundGradientId(axisId, 'x');
67
90
  const {
68
91
  colorMap,
69
92
  scale,
@@ -81,15 +104,36 @@ export function ChartsAxesGradients() {
81
104
  }, gradientId);
82
105
  }
83
106
  if (colorMap?.type === 'continuous') {
84
- return /*#__PURE__*/_jsx(ChartsContinuousGradient, {
85
- isReversed: reverse,
86
- scale: scale,
107
+ return /*#__PURE__*/_jsxs(React.Fragment, {
108
+ children: [/*#__PURE__*/_jsx(ChartsContinuousGradient, {
109
+ isReversed: reverse,
110
+ scale: scale,
111
+ colorScale: colorScale,
112
+ colorMap: colorMap,
113
+ size: svgWidth,
114
+ gradientId: gradientId,
115
+ direction: "x"
116
+ }), /*#__PURE__*/_jsx(ChartsContinuousGradientObjectBound, {
117
+ isReversed: reverse,
118
+ colorScale: colorScale,
119
+ colorMap: colorMap,
120
+ gradientId: objectBoundGradientId
121
+ })]
122
+ }, gradientId);
123
+ }
124
+ return null;
125
+ }), filteredZAxisIds.map(axisId => {
126
+ const objectBoundGradientId = getObjectBoundGradientId(axisId, 'z');
127
+ const {
128
+ colorMap,
129
+ colorScale
130
+ } = zAxis[axisId];
131
+ if (colorMap?.type === 'continuous') {
132
+ return /*#__PURE__*/_jsx(ChartsContinuousGradientObjectBound, {
87
133
  colorScale: colorScale,
88
134
  colorMap: colorMap,
89
- size: svgWidth,
90
- gradientId: gradientId,
91
- direction: "x"
92
- }, gradientId);
135
+ gradientId: objectBoundGradientId
136
+ }, objectBoundGradientId);
93
137
  }
94
138
  return null;
95
139
  })]
@@ -13,14 +13,14 @@ export default function ChartsContinuousGradient(props) {
13
13
  colorScale,
14
14
  colorMap
15
15
  } = props;
16
- const extremValues = [colorMap.min ?? 0, colorMap.max ?? 100];
17
- const extremPositions = extremValues.map(scale).filter(p => p !== undefined);
18
- if (extremPositions.length !== 2) {
16
+ const extremumValues = [colorMap.min ?? 0, colorMap.max ?? 100];
17
+ const extremumPositions = extremumValues.map(scale).filter(p => p !== undefined);
18
+ if (extremumPositions.length !== 2) {
19
19
  return null;
20
20
  }
21
- const interpolator = typeof extremValues[0] === 'number' ? interpolateNumber(extremValues[0], extremValues[1]) : interpolateDate(extremValues[0], extremValues[1]);
22
- const numberOfPoints = Math.round((Math.max(...extremPositions) - Math.min(...extremPositions)) / PX_PRECISION);
23
- const keyPrefix = `${extremValues[0]}-${extremValues[1]}-`;
21
+ const interpolator = typeof extremumValues[0] === 'number' ? interpolateNumber(extremumValues[0], extremumValues[1]) : interpolateDate(extremumValues[0], extremumValues[1]);
22
+ const numberOfPoints = Math.round((Math.max(...extremumPositions) - Math.min(...extremumPositions)) / PX_PRECISION);
23
+ const keyPrefix = `${extremumValues[0]}-${extremumValues[1]}-`;
24
24
  return /*#__PURE__*/_jsx("linearGradient", {
25
25
  id: gradientId,
26
26
  x1: "0",
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ import { ContinuousColorConfig } from '../../../models/colorMapping';
3
+ type ChartsContinuousGradientObjectBoundProps = {
4
+ isReversed?: boolean;
5
+ gradientId: string;
6
+ colorMap: ContinuousColorConfig;
7
+ colorScale: (value: any) => string | null;
8
+ };
9
+ /**
10
+ * Generates gradients to be used in tooltips and legends.
11
+ */
12
+ export default function ChartsContinuousGradientObjectBound(props: ChartsContinuousGradientObjectBoundProps): React.JSX.Element;
13
+ export {};
@@ -0,0 +1,61 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import { interpolateDate, interpolateNumber } from '@mui/x-charts-vendor/d3-interpolate';
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ const PX_PRECISION = 10;
6
+ const getDirection = isReversed => {
7
+ if (isReversed) {
8
+ return {
9
+ x1: '1',
10
+ x2: '0',
11
+ y1: '0',
12
+ y2: '0'
13
+ };
14
+ }
15
+ return {
16
+ x1: '0',
17
+ x2: '1',
18
+ y1: '0',
19
+ y2: '0'
20
+ };
21
+ };
22
+
23
+ /**
24
+ * Generates gradients to be used in tooltips and legends.
25
+ */
26
+ export default function ChartsContinuousGradientObjectBound(props) {
27
+ const {
28
+ isReversed,
29
+ gradientId,
30
+ colorScale,
31
+ colorMap
32
+ } = props;
33
+ const extremumValues = [colorMap.min ?? 0, colorMap.max ?? 100];
34
+ const interpolator = typeof extremumValues[0] === 'number' ? interpolateNumber(extremumValues[0], extremumValues[1]) : interpolateDate(extremumValues[0], extremumValues[1]);
35
+ const numberOfPoints = PX_PRECISION;
36
+ const keyPrefix = `${extremumValues[0]}-${extremumValues[1]}-`;
37
+ return /*#__PURE__*/_jsx("linearGradient", _extends({
38
+ id: gradientId
39
+ }, getDirection(isReversed), {
40
+ gradientUnits: 'objectBoundingBox' // Use the SVG coordinate instead of the component ones.
41
+ ,
42
+ children: Array.from({
43
+ length: numberOfPoints + 1
44
+ }, (_, index) => {
45
+ const offset = index / numberOfPoints;
46
+ const value = interpolator(offset);
47
+ if (value === undefined) {
48
+ return null;
49
+ }
50
+ const color = colorScale(value);
51
+ if (color === null) {
52
+ return null;
53
+ }
54
+ return /*#__PURE__*/_jsx("stop", {
55
+ offset: offset,
56
+ stopColor: color,
57
+ stopOpacity: 1
58
+ }, keyPrefix + index);
59
+ })
60
+ }));
61
+ }
@@ -24,6 +24,9 @@ export default function ChartsPiecewiseGradient(props) {
24
24
  return null;
25
25
  }
26
26
  const offset = isReversed ? 1 - x / size : x / size;
27
+ if (Number.isNaN(offset)) {
28
+ return null;
29
+ }
27
30
  return /*#__PURE__*/_jsxs(React.Fragment, {
28
31
  children: [/*#__PURE__*/_jsx("stop", {
29
32
  offset: offset,
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ import { SxProps, Theme } from '@mui/material/styles';
3
+ import { Direction, LegendPosition } from '../../../ChartsLegend';
4
+ export interface ChartsWrapperProps {
5
+ legendPosition?: LegendPosition;
6
+ legendDirection?: Direction;
7
+ children: React.ReactNode;
8
+ sx?: SxProps<Theme>;
9
+ }
10
+ /**
11
+ * @ignore - internal component.
12
+ *
13
+ * Wrapper for the charts components.
14
+ * Its main purpose is to position the HTML legend in the correct place.
15
+ */
16
+ declare function ChartsWrapper(props: ChartsWrapperProps): React.JSX.Element;
17
+ export { ChartsWrapper };
@@ -0,0 +1,66 @@
1
+ import * as React from 'react';
2
+ import { styled } from '@mui/material/styles';
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ const getDirection = (direction, position) => {
5
+ if (direction === 'vertical') {
6
+ if (position?.horizontal === 'left') {
7
+ return 'row';
8
+ }
9
+ return 'row-reverse';
10
+ }
11
+ if (position?.vertical === 'bottom') {
12
+ return 'column-reverse';
13
+ }
14
+ return 'column';
15
+ };
16
+ const getAlign = (direction, position) => {
17
+ if (direction === 'vertical') {
18
+ if (position?.vertical === 'top') {
19
+ return 'flex-start';
20
+ }
21
+ if (position?.vertical === 'bottom') {
22
+ return 'flex-end';
23
+ }
24
+ }
25
+ if (direction === 'horizontal') {
26
+ if (position?.horizontal === 'left') {
27
+ return 'flex-start';
28
+ }
29
+ if (position?.horizontal === 'right') {
30
+ return 'flex-end';
31
+ }
32
+ }
33
+ return 'center';
34
+ };
35
+ const Root = styled('div', {
36
+ name: 'MuiChartsWrapper',
37
+ slot: 'Root',
38
+ overridesResolver: (props, styles) => styles.root
39
+ })(({
40
+ ownerState
41
+ }) => ({
42
+ display: 'flex',
43
+ flexDirection: getDirection(ownerState.legendDirection, ownerState.legendPosition),
44
+ flex: 1,
45
+ justifyContent: 'center',
46
+ alignItems: getAlign(ownerState.legendDirection, ownerState.legendPosition)
47
+ }));
48
+
49
+ /**
50
+ * @ignore - internal component.
51
+ *
52
+ * Wrapper for the charts components.
53
+ * Its main purpose is to position the HTML legend in the correct place.
54
+ */
55
+ function ChartsWrapper(props) {
56
+ const {
57
+ children,
58
+ sx
59
+ } = props;
60
+ return /*#__PURE__*/_jsx(Root, {
61
+ ownerState: props,
62
+ sx: sx,
63
+ children: children
64
+ });
65
+ }
66
+ export { ChartsWrapper };
@@ -0,0 +1 @@
1
+ export * from './ChartsWrapper';
@@ -0,0 +1 @@
1
+ export * from "./ChartsWrapper.js";
@@ -0,0 +1,48 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * A higher order component that consumes a slot from the props and renders the component provided in the slot.
4
+ *
5
+ * This HOC will wrap a single component, and will render the component provided in the slot, if it exists.
6
+ *
7
+ * If you need to render multiple components, you can manually consume the slots from the props and render them in your component instead of using this HOC.
8
+ *
9
+ * In the example below, `MyComponent` will render the component provided in `mySlot` slot, if it exists. Otherwise, it will render the `DefaultComponent`.
10
+ *
11
+ * @example
12
+ *
13
+ * ```tsx
14
+ * type MyComponentProps = {
15
+ * direction: 'row' | 'column';
16
+ * slots?: {
17
+ * mySlot?: React.JSXElementConstructor<{ direction: 'row' | 'column' }>;
18
+ * }
19
+ * };
20
+ *
21
+ * const MyComponent = consumeSlots(
22
+ * 'MuiMyComponent',
23
+ * 'mySlot',
24
+ * function DefaultComponent(props: MyComponentProps) {
25
+ * return (
26
+ * <div className={props.classes.root}>
27
+ * {props.direction}
28
+ * </div>
29
+ * );
30
+ * }
31
+ * );
32
+ * ```
33
+ *
34
+ * @param {string} name The mui component name.
35
+ * @param {string} slotPropName The name of the prop to retrieve the slot from.
36
+ * @param {object} options Options for the HOC.
37
+ * @param {boolean} options.propagateSlots Whether to propagate the slots to the component, this is always false if the slot is provided.
38
+ * @param {Record<string, any>} options.defaultProps A set of defaults for the component, will be deep merged with the props.
39
+ * @param {Array<keyof Props>} options.omitProps An array of props to omit from the component.
40
+ * @param {Function} options.classesResolver A function that returns the classes for the component. It receives the props, after theme props and defaults have been applied. And the theme object as the second argument.
41
+ * @param InComponent The component to render if the slot is not provided.
42
+ */
43
+ export declare const consumeSlots: <Props extends {}, Ref extends {}, RenderFunction = (props: Props, ref: React.Ref<Ref>) => React.ElementType>(name: string, slotPropName: string, options: {
44
+ propagateSlots?: boolean;
45
+ defaultProps?: Omit<Partial<Props>, "slots" | "slotProps"> | ((props: Props) => Omit<Partial<Props>, "slots" | "slotProps">);
46
+ omitProps?: Array<keyof Props>;
47
+ classesResolver?: (props: Props, theme: any) => Record<string, string>;
48
+ }, InComponent: RenderFunction) => React.ForwardRefExoticComponent<React.PropsWithoutRef<Props> & React.RefAttributes<Ref>>;
@@ -0,0 +1,101 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["slots", "slotProps"],
4
+ _excluded2 = ["ownerState"];
5
+ import { useTheme, useThemeProps } from '@mui/material/styles';
6
+ import resolveProps from '@mui/utils/resolveProps';
7
+ import useSlotProps from '@mui/utils/useSlotProps';
8
+ import * as React from 'react';
9
+
10
+ /**
11
+ * A higher order component that consumes a slot from the props and renders the component provided in the slot.
12
+ *
13
+ * This HOC will wrap a single component, and will render the component provided in the slot, if it exists.
14
+ *
15
+ * If you need to render multiple components, you can manually consume the slots from the props and render them in your component instead of using this HOC.
16
+ *
17
+ * In the example below, `MyComponent` will render the component provided in `mySlot` slot, if it exists. Otherwise, it will render the `DefaultComponent`.
18
+ *
19
+ * @example
20
+ *
21
+ * ```tsx
22
+ * type MyComponentProps = {
23
+ * direction: 'row' | 'column';
24
+ * slots?: {
25
+ * mySlot?: React.JSXElementConstructor<{ direction: 'row' | 'column' }>;
26
+ * }
27
+ * };
28
+ *
29
+ * const MyComponent = consumeSlots(
30
+ * 'MuiMyComponent',
31
+ * 'mySlot',
32
+ * function DefaultComponent(props: MyComponentProps) {
33
+ * return (
34
+ * <div className={props.classes.root}>
35
+ * {props.direction}
36
+ * </div>
37
+ * );
38
+ * }
39
+ * );
40
+ * ```
41
+ *
42
+ * @param {string} name The mui component name.
43
+ * @param {string} slotPropName The name of the prop to retrieve the slot from.
44
+ * @param {object} options Options for the HOC.
45
+ * @param {boolean} options.propagateSlots Whether to propagate the slots to the component, this is always false if the slot is provided.
46
+ * @param {Record<string, any>} options.defaultProps A set of defaults for the component, will be deep merged with the props.
47
+ * @param {Array<keyof Props>} options.omitProps An array of props to omit from the component.
48
+ * @param {Function} options.classesResolver A function that returns the classes for the component. It receives the props, after theme props and defaults have been applied. And the theme object as the second argument.
49
+ * @param InComponent The component to render if the slot is not provided.
50
+ */
51
+ import { jsx as _jsx } from "react/jsx-runtime";
52
+ export const consumeSlots = (name, slotPropName, options, InComponent) => {
53
+ function ConsumeSlotsInternal(props, ref) {
54
+ const themedProps = useThemeProps({
55
+ props,
56
+ // eslint-disable-next-line material-ui/mui-name-matches-component-name
57
+ name
58
+ });
59
+ const defaultProps = typeof options.defaultProps === 'function' ? options.defaultProps(themedProps) : options.defaultProps ?? {};
60
+ const defaultizedProps = resolveProps(defaultProps, themedProps);
61
+ const _ref = defaultizedProps,
62
+ {
63
+ slots,
64
+ slotProps
65
+ } = _ref,
66
+ other = _objectWithoutPropertiesLoose(_ref, _excluded);
67
+ const theme = useTheme();
68
+ const classes = options.classesResolver?.(defaultizedProps, theme);
69
+
70
+ // Can be a function component or a forward ref component.
71
+ const Component = slots?.[slotPropName] ?? InComponent;
72
+ const propagateSlots = options.propagateSlots && !slots?.[slotPropName];
73
+ const _useSlotProps = useSlotProps({
74
+ elementType: Component,
75
+ externalSlotProps: slotProps?.[slotPropName],
76
+ additionalProps: _extends({}, other, {
77
+ classes
78
+ }, propagateSlots && {
79
+ slots,
80
+ slotProps
81
+ }),
82
+ ownerState: {}
83
+ }),
84
+ originalOutProps = _objectWithoutPropertiesLoose(_useSlotProps, _excluded2);
85
+ const outProps = _extends({}, originalOutProps);
86
+ for (const prop of options.omitProps ?? []) {
87
+ delete outProps[prop];
88
+ }
89
+
90
+ // Component can be wrapped in React.forwardRef or just a function that accepts (props, ref).
91
+ // If it is a plain function which accepts two arguments, we need to wrap it in React.forwardRef.
92
+ const OutComponent = Component.length >= 2 ? /*#__PURE__*/React.forwardRef(Component) : Component;
93
+ if (process.env.NODE_ENV !== 'production') {
94
+ OutComponent.displayName = `${name}.slots.${slotPropName}`;
95
+ }
96
+ return /*#__PURE__*/_jsx(OutComponent, _extends({}, outProps, {
97
+ ref: ref
98
+ }));
99
+ }
100
+ return /*#__PURE__*/React.forwardRef(ConsumeSlotsInternal);
101
+ };
@@ -44,11 +44,7 @@ import * as React from 'react';
44
44
  * @param {Function} options.classesResolver A function that returns the classes for the component. It receives the props, after theme props and defaults have been applied. And the theme object as the second argument.
45
45
  * @param InComponent The component to render if the slot is not provided.
46
46
  */
47
- export declare const consumeThemeProps: <Props extends {
48
- slots?: Record<string, any>;
49
- slotProps?: Record<string, any>;
50
- classes?: Record<string, any>;
51
- }>(name: string, options: {
52
- defaultProps?: Omit<Partial<Props>, "slots" | "slotProps"> | ((props: Props) => Omit<Partial<Props>, "slots" | "slotProps">);
47
+ export declare const consumeThemeProps: <Props extends {}, Ref extends {}, RenderFunction = (props: Props, ref: React.Ref<Ref>) => React.ElementType>(name: string, options: {
48
+ defaultProps?: Omit<Partial<Props>, "slots" | "slotProps"> | (<T extends Props>(props: T) => Omit<Partial<T>, "slots" | "slotProps">);
53
49
  classesResolver?: (props: Props, theme: any) => Record<string, string>;
54
- }, InComponent: React.JSXElementConstructor<Props>) => React.ForwardRefExoticComponent<React.PropsWithoutRef<Props> & React.RefAttributes<any>>;
50
+ }, InComponent: RenderFunction) => React.ForwardRefExoticComponent<React.PropsWithoutRef<Props> & React.RefAttributes<Ref>>;