@mui/x-charts 6.0.0-alpha.1 → 6.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/BarChart/BarChart.d.ts +1 -4
  2. package/BarChart/BarChart.js +6 -3
  3. package/BarChart/BarPlot.js +42 -8
  4. package/BarChart/legend.d.ts +3 -0
  5. package/BarChart/legend.js +20 -0
  6. package/CHANGELOG.md +287 -107
  7. package/ChartContainer/index.d.ts +3 -1
  8. package/ChartContainer/index.js +10 -6
  9. package/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
  10. package/ChartsLegend/ChartsLegend.d.ts +5 -1
  11. package/ChartsLegend/ChartsLegend.js +5 -1
  12. package/ChartsLegend/utils.d.ts +1 -1
  13. package/ChartsLegend/utils.js +12 -1
  14. package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  15. package/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
  16. package/LineChart/LineChart.d.ts +1 -4
  17. package/LineChart/LineChart.js +6 -3
  18. package/LineChart/legend.d.ts +3 -0
  19. package/LineChart/legend.js +20 -0
  20. package/PieChart/PieArc.d.ts +36 -0
  21. package/PieChart/PieArc.js +128 -0
  22. package/PieChart/PieArcLabel.d.ts +36 -0
  23. package/PieChart/PieArcLabel.js +113 -0
  24. package/PieChart/PieChart.d.ts +20 -0
  25. package/PieChart/PieChart.js +292 -0
  26. package/PieChart/PiePlot.d.ts +2 -0
  27. package/PieChart/PiePlot.js +98 -0
  28. package/PieChart/formatter.d.ts +3 -0
  29. package/PieChart/formatter.js +49 -0
  30. package/PieChart/index.d.ts +4 -0
  31. package/PieChart/index.js +47 -0
  32. package/PieChart/legend.d.ts +3 -0
  33. package/PieChart/legend.js +19 -0
  34. package/PieChart/package.json +6 -0
  35. package/README.md +2 -2
  36. package/ResponsiveChartContainer/index.d.ts +1 -1
  37. package/ResponsiveChartContainer/index.js +22 -9
  38. package/ScatterChart/Scatter.d.ts +1 -1
  39. package/ScatterChart/Scatter.js +1 -1
  40. package/ScatterChart/ScatterChart.d.ts +1 -4
  41. package/ScatterChart/ScatterChart.js +6 -3
  42. package/ScatterChart/legend.d.ts +3 -0
  43. package/ScatterChart/legend.js +20 -0
  44. package/context/CartesianContextProvider.js +31 -20
  45. package/context/SeriesContextProvider.js +11 -1
  46. package/esm/BarChart/BarChart.js +4 -2
  47. package/esm/BarChart/BarPlot.js +44 -8
  48. package/esm/BarChart/legend.js +13 -0
  49. package/esm/ChartContainer/index.js +7 -5
  50. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
  51. package/esm/ChartsLegend/ChartsLegend.js +5 -1
  52. package/esm/ChartsLegend/utils.js +11 -1
  53. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  54. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +11 -3
  55. package/esm/LineChart/LineChart.js +4 -2
  56. package/esm/LineChart/legend.js +13 -0
  57. package/esm/PieChart/PieArc.js +117 -0
  58. package/esm/PieChart/PieArcLabel.js +101 -0
  59. package/esm/PieChart/PieChart.js +285 -0
  60. package/esm/PieChart/PiePlot.js +92 -0
  61. package/esm/PieChart/formatter.js +48 -0
  62. package/esm/PieChart/index.js +4 -0
  63. package/esm/PieChart/legend.js +12 -0
  64. package/esm/ResponsiveChartContainer/index.js +20 -8
  65. package/esm/ScatterChart/Scatter.js +1 -1
  66. package/esm/ScatterChart/ScatterChart.js +4 -2
  67. package/esm/ScatterChart/legend.js +13 -0
  68. package/esm/context/CartesianContextProvider.js +31 -18
  69. package/esm/context/SeriesContextProvider.js +11 -1
  70. package/esm/hooks/index.js +2 -0
  71. package/esm/hooks/useAxisEvents.js +12 -7
  72. package/esm/hooks/useDrawingArea.js +16 -0
  73. package/esm/hooks/useScale.js +19 -21
  74. package/esm/hooks/useTicks.js +26 -13
  75. package/esm/index.js +2 -0
  76. package/esm/internals/defaultizeColor.js +7 -0
  77. package/esm/internals/getScale.js +17 -0
  78. package/esm/internals/isBandScale.js +3 -0
  79. package/esm/models/axis.js +6 -1
  80. package/esm/models/seriesType/index.js +1 -8
  81. package/hooks/index.d.ts +2 -0
  82. package/hooks/index.js +27 -0
  83. package/hooks/package.json +6 -0
  84. package/hooks/useAxisEvents.js +14 -9
  85. package/hooks/useDrawingArea.d.ts +6 -0
  86. package/hooks/useDrawingArea.js +24 -0
  87. package/hooks/useScale.d.ts +3 -6
  88. package/hooks/useScale.js +24 -24
  89. package/hooks/useTicks.d.ts +1 -1
  90. package/hooks/useTicks.js +19 -9
  91. package/index.d.ts +2 -0
  92. package/index.js +23 -1
  93. package/internals/defaultizeColor.d.ts +35 -0
  94. package/internals/defaultizeColor.js +7 -0
  95. package/internals/getScale.d.ts +2 -0
  96. package/internals/getScale.js +23 -0
  97. package/internals/isBandScale.d.ts +3 -0
  98. package/internals/isBandScale.js +9 -0
  99. package/legacy/BarChart/BarChart.js +4 -2
  100. package/legacy/BarChart/BarPlot.js +44 -10
  101. package/legacy/BarChart/legend.js +15 -0
  102. package/legacy/ChartContainer/index.js +7 -5
  103. package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
  104. package/legacy/ChartsLegend/ChartsLegend.js +5 -1
  105. package/legacy/ChartsLegend/utils.js +12 -6
  106. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +3 -1
  107. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +10 -3
  108. package/legacy/LineChart/LineChart.js +4 -2
  109. package/legacy/LineChart/legend.js +15 -0
  110. package/legacy/PieChart/PieArc.js +118 -0
  111. package/legacy/PieChart/PieArcLabel.js +101 -0
  112. package/legacy/PieChart/PieChart.js +297 -0
  113. package/legacy/PieChart/PiePlot.js +89 -0
  114. package/legacy/PieChart/formatter.js +55 -0
  115. package/legacy/PieChart/index.js +4 -0
  116. package/legacy/PieChart/legend.js +16 -0
  117. package/legacy/ResponsiveChartContainer/index.js +18 -8
  118. package/legacy/ScatterChart/Scatter.js +1 -1
  119. package/legacy/ScatterChart/ScatterChart.js +4 -2
  120. package/legacy/ScatterChart/legend.js +15 -0
  121. package/legacy/context/CartesianContextProvider.js +31 -18
  122. package/legacy/context/SeriesContextProvider.js +11 -1
  123. package/legacy/hooks/index.js +2 -0
  124. package/legacy/hooks/useAxisEvents.js +12 -7
  125. package/legacy/hooks/useDrawingArea.js +17 -0
  126. package/legacy/hooks/useScale.js +17 -21
  127. package/legacy/hooks/useTicks.js +26 -13
  128. package/legacy/index.js +3 -1
  129. package/legacy/internals/defaultizeColor.js +9 -0
  130. package/legacy/internals/getScale.js +17 -0
  131. package/legacy/internals/isBandScale.js +3 -0
  132. package/legacy/models/axis.js +6 -1
  133. package/legacy/models/seriesType/index.js +1 -8
  134. package/models/axis.d.ts +25 -12
  135. package/models/axis.js +9 -1
  136. package/models/seriesType/bar.d.ts +1 -1
  137. package/models/seriesType/common.d.ts +1 -1
  138. package/models/seriesType/config.d.ts +29 -2
  139. package/models/seriesType/index.d.ts +7 -3
  140. package/models/seriesType/index.js +11 -0
  141. package/models/seriesType/line.d.ts +1 -1
  142. package/models/seriesType/pie.d.ts +103 -3
  143. package/models/seriesType/scatter.d.ts +1 -1
  144. package/modern/BarChart/BarChart.js +4 -2
  145. package/modern/BarChart/BarPlot.js +44 -8
  146. package/modern/BarChart/legend.js +13 -0
  147. package/modern/ChartContainer/index.js +7 -5
  148. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
  149. package/modern/ChartsLegend/ChartsLegend.js +5 -1
  150. package/modern/ChartsLegend/utils.js +11 -1
  151. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  152. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
  153. package/modern/LineChart/LineChart.js +4 -2
  154. package/modern/LineChart/legend.js +13 -0
  155. package/modern/PieChart/PieArc.js +116 -0
  156. package/modern/PieChart/PieArcLabel.js +101 -0
  157. package/modern/PieChart/PieChart.js +285 -0
  158. package/modern/PieChart/PiePlot.js +91 -0
  159. package/modern/PieChart/formatter.js +41 -0
  160. package/modern/PieChart/index.js +4 -0
  161. package/modern/PieChart/legend.js +12 -0
  162. package/modern/ResponsiveChartContainer/index.js +20 -8
  163. package/modern/ScatterChart/Scatter.js +1 -1
  164. package/modern/ScatterChart/ScatterChart.js +4 -2
  165. package/modern/ScatterChart/legend.js +13 -0
  166. package/modern/context/CartesianContextProvider.js +29 -18
  167. package/modern/context/SeriesContextProvider.js +11 -1
  168. package/modern/hooks/index.js +2 -0
  169. package/modern/hooks/useAxisEvents.js +12 -7
  170. package/modern/hooks/useDrawingArea.js +16 -0
  171. package/modern/hooks/useScale.js +19 -21
  172. package/modern/hooks/useTicks.js +18 -8
  173. package/modern/index.js +3 -1
  174. package/modern/internals/defaultizeColor.js +7 -0
  175. package/modern/internals/getScale.js +17 -0
  176. package/modern/internals/isBandScale.js +3 -0
  177. package/modern/models/axis.js +6 -1
  178. package/modern/models/seriesType/index.js +1 -8
  179. package/package.json +1 -1
@@ -1,5 +1,105 @@
1
- import { CartesianSeriesType, CommonSeriesType } from './common';
2
- export interface PieSeriesType extends CommonSeriesType<number>, CartesianSeriesType {
1
+ import { PieArcDatum as D3PieArcDatum } from 'd3-shape';
2
+ import { DefaultizedProps } from '../helpers';
3
+ import { CommonDefaultizedProps, CommonSeriesType } from './common';
4
+ export type PieValueType = {
5
+ id: string | number;
6
+ value: number;
7
+ label?: string;
8
+ color?: string;
9
+ };
10
+ export type DefaultizedPieValueType = PieValueType & D3PieArcDatum<any> & {
11
+ color: string;
12
+ formattedValue: string;
13
+ };
14
+ export type ChartsPieSorting = 'none' | 'asc' | 'desc' | ((a: number, b: number) => number);
15
+ export interface PieSeriesType<Tdata = PieValueType> extends CommonSeriesType<Tdata> {
3
16
  type: 'pie';
4
- data: number[];
17
+ data: Tdata[];
18
+ /**
19
+ * The radius between circle center and the begining of the arc.
20
+ * @default 0
21
+ */
22
+ innerRadius?: number;
23
+ /**
24
+ * The radius between circle center and the end of the arc.
25
+ * @default R_max The maximal radius that fit into the drawing area.
26
+ */
27
+ outerRadius?: number;
28
+ /**
29
+ * The radius applied to arc corners (similar to border radius).
30
+ * @default 0
31
+ */
32
+ cornerRadius?: number;
33
+ /**
34
+ * The start angle (deg) of the first item.
35
+ * @default 0
36
+ */
37
+ startAngle?: number;
38
+ /**
39
+ * The end angle (deg) of the last item.
40
+ * @default 360
41
+ */
42
+ endAngle?: number;
43
+ /**
44
+ * The padding angle (deg) between two arcs.
45
+ * @default 0
46
+ */
47
+ paddingAngle?: number;
48
+ sortingValues?: ChartsPieSorting;
49
+ /**
50
+ * The label displayed into the arc.
51
+ */
52
+ arcLabel?: 'formattedValue' | 'label' | 'value' | ((item: DefaultizedPieValueType) => string);
53
+ /**
54
+ * The minimal angle required to display the arc label.
55
+ */
56
+ arcLabelMinAngle?: number;
57
+ /**
58
+ * The x coordinate of the pie center.
59
+ * @default width/2 the center of the drawing area.
60
+ */
61
+ cx?: number;
62
+ /**
63
+ * The y coordinate of the pie center.
64
+ * @default height/2 the center of the drawing area.
65
+ */
66
+ cy?: number;
67
+ /**
68
+ * Override the arc attibutes when it is highlighted.
69
+ */
70
+ highlighted?: {
71
+ /**
72
+ * Value added to the default `outerRadius`.
73
+ * Can be negative. It is ignored if you provide a `highlighted.outerRadius` value.
74
+ */
75
+ additionalRadius?: number;
76
+ innerRadius?: number;
77
+ outerRadius?: number;
78
+ cornerRadius?: number;
79
+ };
80
+ /**
81
+ * Override the arc attibutes when it is faded.
82
+ */
83
+ faded?: {
84
+ /**
85
+ * Value added to the default `outerRadius`.
86
+ * Can be negative. It is ignored if you provide a `faded.outerRadius` value.
87
+ */
88
+ additionalRadius?: number;
89
+ innerRadius?: number;
90
+ outerRadius?: number;
91
+ cornerRadius?: number;
92
+ };
93
+ }
94
+ /**
95
+ * An object that allows to identify a single pie slice.
96
+ * Used for item interaction
97
+ */
98
+ export type PieItemIdentifier = {
99
+ type: 'pie';
100
+ seriesId: DefaultizedPieSeriesType['id'];
101
+ dataIndex: number;
102
+ };
103
+ export interface DefaultizedPieSeriesType extends DefaultizedProps<PieSeriesType, CommonDefaultizedProps> {
104
+ data: DefaultizedPieValueType[];
5
105
  }
@@ -12,7 +12,7 @@ export interface ScatterSeriesType extends CommonSeriesType<ScatterValueType>, C
12
12
  label?: string;
13
13
  }
14
14
  /**
15
- * An object that allows to identify a single line.
15
+ * An object that allows to identify a single scatter item.
16
16
  * Used for item interaction
17
17
  */
18
18
  export type ScatterItemIdentifier = {
@@ -12,7 +12,7 @@ import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
12
12
  import { ChartsClipPath } from '../ChartsClipPath';
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { jsxs as _jsxs } from "react/jsx-runtime";
15
- function BarChart(props) {
15
+ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
16
16
  const {
17
17
  xAxis,
18
18
  yAxis,
@@ -34,6 +34,7 @@ function BarChart(props) {
34
34
  const id = useId();
35
35
  const clipPathId = `${id}-clip-path`;
36
36
  return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
37
+ ref: ref,
37
38
  series: series.map(s => _extends({
38
39
  type: 'bar'
39
40
  }, s)),
@@ -65,7 +66,7 @@ function BarChart(props) {
65
66
  id: clipPathId
66
67
  }), children]
67
68
  });
68
- }
69
+ });
69
70
  process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
70
71
  // ----------------------------- Warning --------------------------------
71
72
  // | These PropTypes are generated from the TypeScript type definitions |
@@ -123,6 +124,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
123
124
  legend: PropTypes.shape({
124
125
  classes: PropTypes.object,
125
126
  direction: PropTypes.oneOf(['column', 'row']),
127
+ hidden: PropTypes.bool,
126
128
  itemWidth: PropTypes.number,
127
129
  markSize: PropTypes.number,
128
130
  offset: PropTypes.shape({
@@ -1,9 +1,37 @@
1
1
  import * as React from 'react';
2
2
  import { SeriesContext } from '../context/SeriesContextProvider';
3
3
  import { CartesianContext } from '../context/CartesianContextProvider';
4
- import { isBandScale } from '../hooks/useScale';
5
4
  import { BarElement } from './BarElement';
5
+ import { isBandScaleConfig } from '../models/axis';
6
+
7
+ /**
8
+ * Solution of the equations
9
+ * W = barWidth * N + offset * (N-1)
10
+ * offset / (offset + barWidth) = r
11
+ * @param bandWidth The width available to place bars.
12
+ * @param numberOfGroups The number of bars to place in that space.
13
+ * @param gapRatio The ratio of the gap between bars over the bar width.
14
+ * @returns The bar width and the offset between bars.
15
+ */
6
16
  import { jsx as _jsx } from "react/jsx-runtime";
17
+ function getBandSize({
18
+ bandWidth: W,
19
+ numberOfGroups: N,
20
+ gapRatio: r
21
+ }) {
22
+ if (r === 0) {
23
+ return {
24
+ barWidth: W / N,
25
+ offset: 0
26
+ };
27
+ }
28
+ const barWidth = W / (N + (N - 1) * r);
29
+ const offset = r * barWidth;
30
+ return {
31
+ barWidth,
32
+ offset
33
+ };
34
+ }
7
35
  export function BarPlot() {
8
36
  const seriesData = React.useContext(SeriesContext).bar;
9
37
  const axisData = React.useContext(CartesianContext);
@@ -29,19 +57,27 @@ export function BarPlot() {
29
57
  return groupIds.flatMap(seriesId => {
30
58
  const xAxisKey = series[seriesId].xAxisKey ?? defaultXAxisId;
31
59
  const yAxisKey = series[seriesId].yAxisKey ?? defaultYAxisId;
32
- const xScale = xAxis[xAxisKey].scale;
33
- const yScale = yAxis[yAxisKey].scale;
34
- if (!isBandScale(xScale)) {
35
- throw new Error(`Axis with id "${xAxisKey}" shoud be of type "band" to display the bar series ${stackingGroups}`);
60
+ const xAxisConfig = xAxis[xAxisKey];
61
+ const yAxisConfig = yAxis[yAxisKey];
62
+ if (!isBandScaleConfig(xAxisConfig)) {
63
+ throw new Error(`Axis with id "${xAxisKey}" shoud be of type "band" to display the bar series of id "${seriesId}"`);
36
64
  }
37
65
  if (xAxis[xAxisKey].data === undefined) {
38
66
  throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
39
67
  }
68
+ const xScale = xAxisConfig.scale;
69
+ const yScale = yAxisConfig.scale;
40
70
 
41
71
  // Currently assuming all bars are vertical
42
72
  const bandWidth = xScale.bandwidth();
43
- const barWidth = 0.9 * bandWidth / stackingGroups.length;
44
- const offset = 0.05 * bandWidth;
73
+ const {
74
+ barWidth,
75
+ offset
76
+ } = getBandSize({
77
+ bandWidth,
78
+ numberOfGroups: stackingGroups.length,
79
+ gapRatio: xAxisConfig.barGapRatio
80
+ });
45
81
 
46
82
  // @ts-ignore TODO: fix when adding a correct API for customisation
47
83
  const {
@@ -54,7 +90,7 @@ export function BarPlot() {
54
90
  return /*#__PURE__*/_jsx(BarElement, {
55
91
  id: seriesId,
56
92
  dataIndex: dataIndex,
57
- x: xScale(xAxis[xAxisKey].data?.[dataIndex]) + groupIndex * barWidth + offset,
93
+ x: xScale(xAxis[xAxisKey].data?.[dataIndex]) + groupIndex * (barWidth + offset),
58
94
  y: yScale(value),
59
95
  height: yScale(baseline) - yScale(value),
60
96
  width: barWidth,
@@ -0,0 +1,13 @@
1
+ const legendGetter = params => {
2
+ const {
3
+ seriesOrder,
4
+ series
5
+ } = params;
6
+ const data = seriesOrder.map(seriesId => ({
7
+ color: series[seriesId].color,
8
+ label: series[seriesId].label,
9
+ id: seriesId
10
+ }));
11
+ return data.filter(item => item.label !== undefined);
12
+ };
13
+ export default legendGetter;
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import useForkRef from '@mui/utils/useForkRef';
2
3
  import { DrawingProvider } from '../context/DrawingProvider';
3
4
  import { SeriesContextProvider } from '../context/SeriesContextProvider';
4
5
  import { InteractionProvider } from '../context/InteractionProvider';
@@ -6,7 +7,7 @@ import { ChartsSurface } from '../ChartsSurface';
6
7
  import { CartesianContextProvider } from '../context/CartesianContextProvider';
7
8
  import { HighlightProvider } from '../context/HighlightProvider';
8
9
  import { jsx as _jsx } from "react/jsx-runtime";
9
- export function ChartContainer(props) {
10
+ export const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(props, ref) {
10
11
  const {
11
12
  width,
12
13
  height,
@@ -21,12 +22,13 @@ export function ChartContainer(props) {
21
22
  disableAxisListener,
22
23
  children
23
24
  } = props;
24
- const ref = React.useRef(null);
25
+ const svgRef = React.useRef(null);
26
+ const handleRef = useForkRef(ref, svgRef);
25
27
  return /*#__PURE__*/_jsx(DrawingProvider, {
26
28
  width: width,
27
29
  height: height,
28
30
  margin: margin,
29
- svgRef: ref,
31
+ svgRef: svgRef,
30
32
  children: /*#__PURE__*/_jsx(SeriesContextProvider, {
31
33
  series: series,
32
34
  colors: colors,
@@ -38,7 +40,7 @@ export function ChartContainer(props) {
38
40
  children: /*#__PURE__*/_jsx(ChartsSurface, {
39
41
  width: width,
40
42
  height: height,
41
- ref: ref,
43
+ ref: handleRef,
42
44
  sx: sx,
43
45
  title: title,
44
46
  desc: desc,
@@ -50,4 +52,4 @@ export function ChartContainer(props) {
50
52
  })
51
53
  })
52
54
  });
53
- }
55
+ });
@@ -2,7 +2,8 @@ import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { InteractionContext } from '../context/InteractionProvider';
4
4
  import { CartesianContext } from '../context/CartesianContextProvider';
5
- import { getValueToPositionMapper, isBandScale } from '../hooks/useScale';
5
+ import { getValueToPositionMapper } from '../hooks/useScale';
6
+ import { isBandScale } from '../internals/isBandScale';
6
7
  import { jsx as _jsx } from "react/jsx-runtime";
7
8
  import { jsxs as _jsxs } from "react/jsx-runtime";
8
9
  function ChartsAxisHighlight(props) {
@@ -26,7 +27,7 @@ function ChartsAxisHighlight(props) {
26
27
  const getXPosition = getValueToPositionMapper(xScale);
27
28
  return /*#__PURE__*/_jsxs(React.Fragment, {
28
29
  children: [xAxisHighlight === 'band' && axis.x !== null && isBandScale(xScale) && /*#__PURE__*/_jsx("path", {
29
- d: `M ${xScale(axis.x.value)} ${yScale.range()[0]} L ${xScale(axis.x.value) + xScale.bandwidth()} ${yScale.range()[0]} L ${xScale(axis.x.value) + xScale.bandwidth()} ${yScale.range()[1]} L ${xScale(axis.x.value)} ${yScale.range()[1]} Z`,
30
+ d: `M ${xScale(axis.x.value) - (xScale.step() - xScale.bandwidth()) / 2} ${yScale.range()[0]} l ${xScale.step()} 0 l 0 ${yScale.range()[1] - yScale.range()[0]} l ${-xScale.step()} 0 Z`,
30
31
  fill: "gray",
31
32
  fillOpacity: 0.1,
32
33
  style: {
@@ -146,7 +146,8 @@ export function ChartsLegend(inProps) {
146
146
  const {
147
147
  position,
148
148
  direction,
149
- offset
149
+ offset,
150
+ hidden
150
151
  } = props;
151
152
  const theme = useTheme();
152
153
  const classes = useUtilityClasses(_extends({}, props, {
@@ -154,6 +155,9 @@ export function ChartsLegend(inProps) {
154
155
  }));
155
156
  const drawingArea = React.useContext(DrawingContext);
156
157
  const series = React.useContext(SeriesContext);
158
+ if (hidden) {
159
+ return null;
160
+ }
157
161
  const seriesToDisplay = getSeriesToDisplay(series);
158
162
  return /*#__PURE__*/_jsx(ChartsLegendRoot, {
159
163
  ownerState: {
@@ -1,3 +1,13 @@
1
+ import getBarLegend from '../BarChart/legend';
2
+ import getScatterLegend from '../ScatterChart/legend';
3
+ import getLineLegend from '../LineChart/legend';
4
+ import getPieLegend from '../PieChart/legend';
5
+ const legendGetter = {
6
+ bar: getBarLegend,
7
+ scatter: getScatterLegend,
8
+ line: getLineLegend,
9
+ pie: getPieLegend
10
+ };
1
11
  export function getSeriesToDisplay(series) {
2
- return Object.values(series).flatMap(s => s.seriesOrder.map(seriesId => s.series[seriesId])).filter(s => s.label !== undefined);
12
+ return Object.keys(series).flatMap(seriesType => legendGetter[seriesType](series[seriesType]));
3
13
  }
@@ -81,7 +81,7 @@ export function ChartsAxisTooltipContent(props) {
81
81
  const USED_X_AXIS_ID = xAxisIds[0];
82
82
  const relevantSeries = React.useMemo(() => {
83
83
  const rep = [];
84
- Object.keys(series).forEach(seriesType => {
84
+ Object.keys(series).filter(seriesType => ['bar', 'line', 'scatter'].includes(seriesType)).forEach(seriesType => {
85
85
  series[seriesType].seriesOrder.forEach(seriesId => {
86
86
  const axisKey = series[seriesType].series[seriesId].xAxisKey;
87
87
  if (axisKey === undefined || axisKey === USED_X_AXIS_ID) {
@@ -13,8 +13,17 @@ export function DefaultChartsItemContent(props) {
13
13
  if (itemData.dataIndex === undefined) {
14
14
  return null;
15
15
  }
16
- const displayedLabel = series.label ?? null;
17
- const color = series.color;
16
+ const {
17
+ displayedLabel,
18
+ color
19
+ } = series.type === 'pie' ? {
20
+ color: series.data[itemData.dataIndex].color,
21
+ displayedLabel: series.data[itemData.dataIndex].label
22
+ } : {
23
+ color: series.color,
24
+ displayedLabel: series.label
25
+ };
26
+
18
27
  // TODO: Manage to let TS understand series.data and series.valueFormatter are coherent
19
28
  // @ts-ignore
20
29
  const formattedValue = series.valueFormatter(series.data[itemData.dataIndex]);
@@ -14,7 +14,7 @@ import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
14
14
  import { ChartsClipPath } from '../ChartsClipPath';
15
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
17
- function LineChart(props) {
17
+ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
18
18
  const {
19
19
  xAxis,
20
20
  yAxis,
@@ -38,6 +38,7 @@ function LineChart(props) {
38
38
  const id = useId();
39
39
  const clipPathId = `${id}-clip-path`;
40
40
  return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
41
+ ref: ref,
41
42
  series: series.map(s => _extends({
42
43
  type: 'line'
43
44
  }, s)),
@@ -67,7 +68,7 @@ function LineChart(props) {
67
68
  id: clipPathId
68
69
  }), children]
69
70
  });
70
- }
71
+ });
71
72
  process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
72
73
  // ----------------------------- Warning --------------------------------
73
74
  // | These PropTypes are generated from the TypeScript type definitions |
@@ -125,6 +126,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
125
126
  legend: PropTypes.shape({
126
127
  classes: PropTypes.object,
127
128
  direction: PropTypes.oneOf(['column', 'row']),
129
+ hidden: PropTypes.bool,
128
130
  itemWidth: PropTypes.number,
129
131
  markSize: PropTypes.number,
130
132
  offset: PropTypes.shape({
@@ -0,0 +1,13 @@
1
+ const legendGetter = params => {
2
+ const {
3
+ seriesOrder,
4
+ series
5
+ } = params;
6
+ const data = seriesOrder.map(seriesId => ({
7
+ color: series[seriesId].color,
8
+ label: series[seriesId].label,
9
+ id: seriesId
10
+ }));
11
+ return data.filter(item => item.label !== undefined);
12
+ };
13
+ export default legendGetter;
@@ -0,0 +1,116 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "innerRadius", "outerRadius", "cornerRadius", "highlighted", "faded"];
4
+ import * as React from 'react';
5
+ import { arc as d3Arc } from 'd3-shape';
6
+ import PropTypes from 'prop-types';
7
+ import composeClasses from '@mui/utils/composeClasses';
8
+ import generateUtilityClass from '@mui/utils/generateUtilityClass';
9
+ import { styled } from '@mui/material/styles';
10
+ import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
11
+ import { InteractionContext } from '../context/InteractionProvider';
12
+ import { getIsFaded, getIsHighlighted, useInteractionItemProps } from '../hooks/useInteractionItemProps';
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ export function getPieArcUtilityClass(slot) {
15
+ return generateUtilityClass('MuiPieArc', slot);
16
+ }
17
+ export const pieArcClasses = generateUtilityClasses('MuiPieArc', ['root', 'highlighted', 'faded']);
18
+ const useUtilityClasses = ownerState => {
19
+ const {
20
+ classes,
21
+ id,
22
+ isFaded,
23
+ isHighlighted
24
+ } = ownerState;
25
+ const slots = {
26
+ root: ['root', `series-${id}`, isHighlighted && 'highlighted', isFaded && 'faded']
27
+ };
28
+ return composeClasses(slots, getPieArcUtilityClass, classes);
29
+ };
30
+ const PieArcRoot = styled('path', {
31
+ name: 'MuiPieArc',
32
+ slot: 'Root',
33
+ overridesResolver: (_, styles) => styles.arc
34
+ })(({
35
+ ownerState,
36
+ theme
37
+ }) => ({
38
+ stroke: theme.palette.background.paper,
39
+ strokeWidth: 1,
40
+ strokeLinejoin: 'round',
41
+ fill: ownerState.color,
42
+ opacity: ownerState.isFaded ? 0.3 : 1
43
+ }));
44
+ export default function PieArc(props) {
45
+ const {
46
+ id,
47
+ dataIndex,
48
+ classes: innerClasses,
49
+ color,
50
+ highlightScope,
51
+ innerRadius: baseInnerRadius = 0,
52
+ outerRadius: baseOuterRadius,
53
+ cornerRadius: baseCornerRadius = 0,
54
+ highlighted,
55
+ faded = {
56
+ additionalRadius: -5
57
+ }
58
+ } = props,
59
+ other = _objectWithoutPropertiesLoose(props, _excluded);
60
+ const getInteractionItemProps = useInteractionItemProps(highlightScope);
61
+ const {
62
+ item
63
+ } = React.useContext(InteractionContext);
64
+ const isHighlighted = getIsHighlighted(item, {
65
+ type: 'pie',
66
+ seriesId: id,
67
+ dataIndex
68
+ }, highlightScope);
69
+ const isFaded = !isHighlighted && getIsFaded(item, {
70
+ type: 'pie',
71
+ seriesId: id,
72
+ dataIndex
73
+ }, highlightScope);
74
+ const ownerState = {
75
+ id,
76
+ dataIndex,
77
+ classes: innerClasses,
78
+ color,
79
+ isFaded,
80
+ isHighlighted
81
+ };
82
+ const classes = useUtilityClasses(ownerState);
83
+ const attibuesOverride = _extends({
84
+ additionalRadius: 0
85
+ }, isFaded && faded || isHighlighted && highlighted || {});
86
+ const innerRadius = Math.max(0, attibuesOverride.innerRadius ?? baseInnerRadius);
87
+ const outerRadius = Math.max(0, attibuesOverride.outerRadius ?? baseOuterRadius + attibuesOverride.additionalRadius);
88
+ const cornerRadius = attibuesOverride.cornerRadius ?? baseCornerRadius;
89
+ return /*#__PURE__*/_jsx(PieArcRoot, _extends({
90
+ d: d3Arc().cornerRadius(cornerRadius)(_extends({}, other, {
91
+ innerRadius,
92
+ outerRadius
93
+ })),
94
+ ownerState: ownerState,
95
+ className: classes.root
96
+ }, getInteractionItemProps({
97
+ type: 'pie',
98
+ seriesId: id,
99
+ dataIndex
100
+ })));
101
+ }
102
+ process.env.NODE_ENV !== "production" ? PieArc.propTypes = {
103
+ // ----------------------------- Warning --------------------------------
104
+ // | These PropTypes are generated from the TypeScript type definitions |
105
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
106
+ // ----------------------------------------------------------------------
107
+ classes: PropTypes.object,
108
+ cornerRadius: PropTypes.number,
109
+ dataIndex: PropTypes.number.isRequired,
110
+ highlightScope: PropTypes.shape({
111
+ faded: PropTypes.oneOf(['global', 'none', 'series']),
112
+ highlighted: PropTypes.oneOf(['item', 'none', 'series'])
113
+ }),
114
+ innerRadius: PropTypes.number,
115
+ outerRadius: PropTypes.number.isRequired
116
+ } : void 0;
@@ -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 = ["id", "dataIndex", "classes", "color", "highlightScope", "innerRadius", "outerRadius", "cornerRadius", "formattedArcLabel"];
4
+ import * as React from 'react';
5
+ import { arc as d3Arc } from 'd3-shape';
6
+ import PropTypes from 'prop-types';
7
+ import composeClasses from '@mui/utils/composeClasses';
8
+ import generateUtilityClass from '@mui/utils/generateUtilityClass';
9
+ import { styled } from '@mui/material/styles';
10
+ import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
11
+ import { InteractionContext } from '../context/InteractionProvider';
12
+ import { getIsFaded, getIsHighlighted } from '../hooks/useInteractionItemProps';
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ export function getPieArcLabelUtilityClass(slot) {
15
+ return generateUtilityClass('MuiPieArcLabel', slot);
16
+ }
17
+ export const pieArcLabelClasses = generateUtilityClasses('MuiPieArcLabel', ['root', 'highlighted', 'faded']);
18
+ const useUtilityClasses = ownerState => {
19
+ const {
20
+ classes,
21
+ id,
22
+ isFaded,
23
+ isHighlighted
24
+ } = ownerState;
25
+ const slots = {
26
+ root: ['root', `series-${id}`, isHighlighted && 'highlighted', isFaded && 'faded']
27
+ };
28
+ return composeClasses(slots, getPieArcLabelUtilityClass, classes);
29
+ };
30
+ const PieArcLabelRoot = styled('text', {
31
+ name: 'MuiPieArcLabel',
32
+ slot: 'Root',
33
+ overridesResolver: (_, styles) => styles.root
34
+ })(({
35
+ theme
36
+ }) => ({
37
+ fill: theme.palette.text.primary,
38
+ alignmentBaseline: 'baseline',
39
+ textAnchor: 'middle'
40
+ }));
41
+ export default function PieArcLabel(props) {
42
+ const {
43
+ id,
44
+ dataIndex,
45
+ classes: innerClasses,
46
+ color,
47
+ highlightScope,
48
+ innerRadius = 0,
49
+ outerRadius,
50
+ cornerRadius = 0,
51
+ formattedArcLabel
52
+ } = props,
53
+ other = _objectWithoutPropertiesLoose(props, _excluded);
54
+ const {
55
+ item
56
+ } = React.useContext(InteractionContext);
57
+ const isHighlighted = getIsHighlighted(item, {
58
+ type: 'pie',
59
+ seriesId: id,
60
+ dataIndex
61
+ }, highlightScope);
62
+ const isFaded = !isHighlighted && getIsFaded(item, {
63
+ type: 'pie',
64
+ seriesId: id,
65
+ dataIndex
66
+ }, highlightScope);
67
+ const ownerState = {
68
+ id,
69
+ dataIndex,
70
+ classes: innerClasses,
71
+ color,
72
+ isFaded,
73
+ isHighlighted
74
+ };
75
+ const classes = useUtilityClasses(ownerState);
76
+ const arcLabelPosition = formattedArcLabel ? d3Arc().cornerRadius(cornerRadius).centroid(_extends({}, other, {
77
+ innerRadius,
78
+ outerRadius
79
+ })) : [0, 0];
80
+ return /*#__PURE__*/_jsx(PieArcLabelRoot, {
81
+ className: classes.root,
82
+ x: arcLabelPosition[0],
83
+ y: arcLabelPosition[1],
84
+ children: formattedArcLabel
85
+ });
86
+ }
87
+ process.env.NODE_ENV !== "production" ? PieArcLabel.propTypes = {
88
+ // ----------------------------- Warning --------------------------------
89
+ // | These PropTypes are generated from the TypeScript type definitions |
90
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
91
+ // ----------------------------------------------------------------------
92
+ classes: PropTypes.object,
93
+ cornerRadius: PropTypes.number,
94
+ dataIndex: PropTypes.number.isRequired,
95
+ highlightScope: PropTypes.shape({
96
+ faded: PropTypes.oneOf(['global', 'none', 'series']),
97
+ highlighted: PropTypes.oneOf(['item', 'none', 'series'])
98
+ }),
99
+ innerRadius: PropTypes.number,
100
+ outerRadius: PropTypes.number.isRequired
101
+ } : void 0;