@mui/x-charts 6.0.0-alpha.0 → 6.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/BarChart/BarChart.js +8 -5
  2. package/BarChart/legend.d.ts +3 -0
  3. package/BarChart/legend.js +20 -0
  4. package/CHANGELOG.md +136 -8
  5. package/ChartsAxis/ChartsAxis.d.ts +4 -4
  6. package/ChartsAxis/ChartsAxis.js +4 -4
  7. package/ChartsLegend/ChartsLegend.d.ts +5 -1
  8. package/ChartsLegend/ChartsLegend.js +5 -1
  9. package/ChartsLegend/utils.d.ts +1 -1
  10. package/ChartsLegend/utils.js +12 -1
  11. package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  12. package/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
  13. package/ChartsTooltip/ChartsTooltipTable.js +8 -8
  14. package/LineChart/LineChart.js +8 -5
  15. package/LineChart/legend.d.ts +3 -0
  16. package/LineChart/legend.js +20 -0
  17. package/PieChart/PieArc.d.ts +36 -0
  18. package/PieChart/PieArc.js +128 -0
  19. package/PieChart/PieArcLabel.d.ts +36 -0
  20. package/PieChart/PieArcLabel.js +113 -0
  21. package/PieChart/PieChart.d.ts +20 -0
  22. package/PieChart/PieChart.js +292 -0
  23. package/PieChart/PiePlot.d.ts +2 -0
  24. package/PieChart/PiePlot.js +98 -0
  25. package/PieChart/formatter.d.ts +3 -0
  26. package/PieChart/formatter.js +49 -0
  27. package/PieChart/index.d.ts +4 -0
  28. package/PieChart/index.js +47 -0
  29. package/PieChart/legend.d.ts +3 -0
  30. package/PieChart/legend.js +19 -0
  31. package/PieChart/package.json +6 -0
  32. package/README.md +30 -2
  33. package/ResponsiveChartContainer/index.js +91 -25
  34. package/ScatterChart/Scatter.js +1 -1
  35. package/ScatterChart/ScatterChart.js +5 -4
  36. package/ScatterChart/legend.d.ts +3 -0
  37. package/ScatterChart/legend.js +20 -0
  38. package/context/SeriesContextProvider.js +11 -1
  39. package/esm/BarChart/BarChart.js +8 -5
  40. package/esm/BarChart/legend.js +13 -0
  41. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  42. package/esm/ChartsLegend/ChartsLegend.js +5 -1
  43. package/esm/ChartsLegend/utils.js +11 -1
  44. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  45. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +11 -3
  46. package/esm/ChartsTooltip/ChartsTooltipTable.js +8 -8
  47. package/esm/LineChart/LineChart.js +8 -5
  48. package/esm/LineChart/legend.js +13 -0
  49. package/esm/PieChart/PieArc.js +117 -0
  50. package/esm/PieChart/PieArcLabel.js +101 -0
  51. package/esm/PieChart/PieChart.js +285 -0
  52. package/esm/PieChart/PiePlot.js +92 -0
  53. package/esm/PieChart/formatter.js +48 -0
  54. package/esm/PieChart/index.js +4 -0
  55. package/esm/PieChart/legend.js +12 -0
  56. package/esm/ResponsiveChartContainer/index.js +94 -26
  57. package/esm/ScatterChart/Scatter.js +1 -1
  58. package/esm/ScatterChart/ScatterChart.js +5 -4
  59. package/esm/ScatterChart/legend.js +13 -0
  60. package/esm/context/SeriesContextProvider.js +11 -1
  61. package/esm/index.js +1 -0
  62. package/esm/internals/defaultizeColor.js +7 -0
  63. package/esm/models/seriesType/index.js +1 -8
  64. package/index.d.ts +1 -0
  65. package/index.js +12 -1
  66. package/internals/defaultizeColor.d.ts +35 -0
  67. package/internals/defaultizeColor.js +7 -0
  68. package/legacy/BarChart/BarChart.js +10 -7
  69. package/legacy/BarChart/legend.js +15 -0
  70. package/legacy/ChartsAxis/ChartsAxis.js +4 -4
  71. package/legacy/ChartsLegend/ChartsLegend.js +5 -1
  72. package/legacy/ChartsLegend/utils.js +12 -6
  73. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +3 -1
  74. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +10 -3
  75. package/legacy/ChartsTooltip/ChartsTooltipTable.js +7 -9
  76. package/legacy/LineChart/LineChart.js +10 -7
  77. package/legacy/LineChart/legend.js +15 -0
  78. package/legacy/PieChart/PieArc.js +118 -0
  79. package/legacy/PieChart/PieArcLabel.js +101 -0
  80. package/legacy/PieChart/PieChart.js +297 -0
  81. package/legacy/PieChart/PiePlot.js +89 -0
  82. package/legacy/PieChart/formatter.js +55 -0
  83. package/legacy/PieChart/index.js +4 -0
  84. package/legacy/PieChart/legend.js +16 -0
  85. package/legacy/ResponsiveChartContainer/index.js +89 -26
  86. package/legacy/ScatterChart/Scatter.js +1 -1
  87. package/legacy/ScatterChart/ScatterChart.js +5 -4
  88. package/legacy/ScatterChart/legend.js +15 -0
  89. package/legacy/context/SeriesContextProvider.js +11 -1
  90. package/legacy/index.js +2 -1
  91. package/legacy/internals/defaultizeColor.js +9 -0
  92. package/legacy/models/seriesType/index.js +1 -8
  93. package/models/seriesType/bar.d.ts +1 -1
  94. package/models/seriesType/common.d.ts +1 -1
  95. package/models/seriesType/config.d.ts +29 -2
  96. package/models/seriesType/index.d.ts +7 -3
  97. package/models/seriesType/index.js +11 -0
  98. package/models/seriesType/line.d.ts +1 -1
  99. package/models/seriesType/pie.d.ts +103 -3
  100. package/models/seriesType/scatter.d.ts +1 -1
  101. package/modern/BarChart/BarChart.js +8 -5
  102. package/modern/BarChart/legend.js +13 -0
  103. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  104. package/modern/ChartsLegend/ChartsLegend.js +5 -1
  105. package/modern/ChartsLegend/utils.js +11 -1
  106. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  107. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
  108. package/modern/ChartsTooltip/ChartsTooltipTable.js +8 -8
  109. package/modern/LineChart/LineChart.js +8 -5
  110. package/modern/LineChart/legend.js +13 -0
  111. package/modern/PieChart/PieArc.js +116 -0
  112. package/modern/PieChart/PieArcLabel.js +101 -0
  113. package/modern/PieChart/PieChart.js +285 -0
  114. package/modern/PieChart/PiePlot.js +91 -0
  115. package/modern/PieChart/formatter.js +41 -0
  116. package/modern/PieChart/index.js +4 -0
  117. package/modern/PieChart/legend.js +12 -0
  118. package/modern/ResponsiveChartContainer/index.js +91 -25
  119. package/modern/ScatterChart/Scatter.js +1 -1
  120. package/modern/ScatterChart/ScatterChart.js +5 -4
  121. package/modern/ScatterChart/legend.js +13 -0
  122. package/modern/context/SeriesContextProvider.js +11 -1
  123. package/modern/index.js +2 -1
  124. package/modern/internals/defaultizeColor.js +7 -0
  125. package/modern/models/seriesType/index.js +1 -8
  126. package/package.json +1 -3
@@ -4,6 +4,7 @@ import { useTheme } from '@mui/material/styles';
4
4
  import barSeriesFormatter from '../BarChart/formatter';
5
5
  import scatterSeriesFormatter from '../ScatterChart/formatter';
6
6
  import lineSeriesFormatter from '../LineChart/formatter';
7
+ import pieSeriesFormatter from '../PieChart/formatter';
7
8
  import { defaultizeColor } from '../internals/defaultizeColor';
8
9
  import { blueberryTwilightPalette } from '../colorPalettes';
9
10
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -11,8 +12,17 @@ export var SeriesContext = /*#__PURE__*/React.createContext({});
11
12
  var seriesTypeFormatter = {
12
13
  bar: barSeriesFormatter,
13
14
  scatter: scatterSeriesFormatter,
14
- line: lineSeriesFormatter
15
+ line: lineSeriesFormatter,
16
+ pie: pieSeriesFormatter
15
17
  };
18
+ /**
19
+ * This methods is the interface between what the developper is providing and what compoenents receives
20
+ * To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if soe line data are modified
21
+ * It also add defaultized values such as the ids, colors
22
+ * @param series The array of series provided by devs
23
+ * @param colors The color palette used to defaultize series colors
24
+ * @returns An object structuring all the series by type.
25
+ */
16
26
  var formatSeries = function formatSeries(series, colors) {
17
27
  // Group series by type
18
28
  var seriesGroups = {};
package/legacy/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v6.0.0-alpha.0
2
+ * @mui/x-charts v6.0.0-alpha.2
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -17,6 +17,7 @@ export * from './ChartsTooltip';
17
17
  export * from './ChartsAxisHighlight';
18
18
  export * from './BarChart';
19
19
  export * from './LineChart';
20
+ export * from './PieChart';
20
21
  export * from './ScatterChart';
21
22
  export * from './ChartContainer';
22
23
  export * from './ResponsiveChartContainer';
@@ -2,6 +2,15 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  var DEFAULT_COLORS = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'];
3
3
  export function defaultizeColor(series, seriesIndex) {
4
4
  var colors = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_COLORS;
5
+ if (series.type === 'pie') {
6
+ return _extends({}, series, {
7
+ data: series.data.map(function (d, index) {
8
+ return _extends({
9
+ color: colors[index % colors.length]
10
+ }, d);
11
+ })
12
+ });
13
+ }
5
14
  return _extends({
6
15
  color: colors[seriesIndex % colors.length]
7
16
  }, series);
@@ -1,12 +1,5 @@
1
- // import { PieSeriesType } from './pie';
2
-
3
- // | PieSeriesType;
4
-
5
- // | PieSeriesType;
6
-
7
- // | PieSeriesType
8
-
9
1
  export * from './line';
10
2
  export * from './bar';
11
3
  export * from './scatter';
4
+ export * from './pie';
12
5
  export {};
@@ -14,5 +14,5 @@ export type BarItemIdentifier = {
14
14
  seriesId: DefaultizedBarSeriesType['id'];
15
15
  dataIndex: number;
16
16
  };
17
- export interface DefaultizedBarSeriesType extends DefaultizedProps<BarSeriesType, CommonDefaultizedProps> {
17
+ export interface DefaultizedBarSeriesType extends DefaultizedProps<BarSeriesType, CommonDefaultizedProps | 'color'> {
18
18
  }
@@ -11,7 +11,7 @@ export type CommonSeriesType<TValue> = {
11
11
  valueFormatter?: (value: TValue) => string;
12
12
  highlightScope?: Partial<HighlightScope>;
13
13
  };
14
- export type CommonDefaultizedProps = 'id' | 'color' | 'valueFormatter';
14
+ export type CommonDefaultizedProps = 'id' | 'valueFormatter';
15
15
  export type CartesianSeriesType = {
16
16
  xAxisKey?: string;
17
17
  yAxisKey?: string;
@@ -1,8 +1,9 @@
1
1
  import { ScatterSeriesType, DefaultizedScatterSeriesType, ScatterItemIdentifier } from './scatter';
2
2
  import { LineSeriesType, DefaultizedLineSeriesType, LineItemIdentifier } from './line';
3
3
  import { BarItemIdentifier, BarSeriesType, DefaultizedBarSeriesType } from './bar';
4
+ import { PieSeriesType, DefaultizedPieSeriesType, PieItemIdentifier, PieValueType } from './pie';
4
5
  import { AxisConfig } from '../axis';
5
- import { DefaultizedProps } from '../helpers';
6
+ import { DefaultizedProps, MakeOptional } from '../helpers';
6
7
  import { StackingGroupsType } from '../../internals/stackSeries';
7
8
  interface ChartsSeriesConfig {
8
9
  bar: {
@@ -28,8 +29,18 @@ interface ChartsSeriesConfig {
28
29
  series: DefaultizedScatterSeriesType;
29
30
  itemIdentifier: ScatterItemIdentifier;
30
31
  };
32
+ pie: {
33
+ seriesInput: Omit<DefaultizedProps<PieSeriesType, 'id'>, 'data'> & {
34
+ data: (MakeOptional<PieValueType, 'id'> & {
35
+ color: string;
36
+ })[];
37
+ };
38
+ series: DefaultizedPieSeriesType;
39
+ itemIdentifier: PieItemIdentifier;
40
+ };
31
41
  }
32
- export type ChartSeriesType = 'bar' | 'line' | 'scatter';
42
+ export type CartesianChartSeriesType = 'bar' | 'line' | 'scatter';
43
+ export type ChartSeriesType = 'bar' | 'line' | 'scatter' | 'pie';
33
44
  export type ChartSeries<T extends ChartSeriesType> = ChartsSeriesConfig[T] extends {
34
45
  canBeStacked: true;
35
46
  } ? ChartsSeriesConfig[T]['seriesInput'] & {
@@ -63,4 +74,20 @@ export type FormatterResult<T extends ChartSeriesType> = {
63
74
  stackingGroups: StackingGroupsType;
64
75
  } : {});
65
76
  export type Formatter<T extends ChartSeriesType> = (params: FormatterParams<T>) => FormatterResult<T>;
77
+ export type LegendParams = {
78
+ /**
79
+ * The color used in the legend
80
+ */
81
+ color: string;
82
+ /**
83
+ * The label displayed in the legend
84
+ */
85
+ label: string;
86
+ /**
87
+ * The identifier of the legend element.
88
+ * Used for internal purpose such as `key` props
89
+ */
90
+ id: string;
91
+ };
92
+ export type LegendGetter<T extends ChartSeriesType> = (series: FormatterResult<T>) => LegendParams[];
66
93
  export {};
@@ -1,13 +1,17 @@
1
1
  import { BarItemIdentifier, BarSeriesType, DefaultizedBarSeriesType } from './bar';
2
2
  import { DefaultizedLineSeriesType, LineItemIdentifier, LineSeriesType } from './line';
3
3
  import { DefaultizedScatterSeriesType, ScatterItemIdentifier, ScatterSeriesType } from './scatter';
4
- type AllSeriesType = BarSeriesType | LineSeriesType | ScatterSeriesType;
4
+ import { DefaultizedPieSeriesType, PieSeriesType, PieItemIdentifier, PieValueType } from './pie';
5
+ import { MakeOptional } from '../helpers';
6
+ type AllSeriesType = BarSeriesType | LineSeriesType | ScatterSeriesType | PieSeriesType<MakeOptional<PieValueType, 'id'>>;
5
7
  type CartesianSeriesType = BarSeriesType | LineSeriesType | ScatterSeriesType;
6
8
  type DefaultizedCartesianSeriesType = DefaultizedBarSeriesType | DefaultizedLineSeriesType | DefaultizedScatterSeriesType;
9
+ type DefaultizedSeriesType = DefaultizedCartesianSeriesType | DefaultizedPieSeriesType;
7
10
  type StackableSeriesType = DefaultizedBarSeriesType | DefaultizedLineSeriesType;
8
- export type SeriesItemIdentifier = BarItemIdentifier | LineItemIdentifier | ScatterItemIdentifier;
11
+ export type SeriesItemIdentifier = BarItemIdentifier | LineItemIdentifier | ScatterItemIdentifier | PieItemIdentifier;
9
12
  export * from './line';
10
13
  export * from './bar';
11
14
  export * from './scatter';
15
+ export * from './pie';
12
16
  export type { StackOrderType, StackOffsetType } from './common';
13
- export type { AllSeriesType, CartesianSeriesType, DefaultizedCartesianSeriesType, StackableSeriesType, };
17
+ export type { AllSeriesType, CartesianSeriesType, DefaultizedSeriesType, DefaultizedCartesianSeriesType, StackableSeriesType, };
@@ -35,4 +35,15 @@ Object.keys(_scatter).forEach(function (key) {
35
35
  return _scatter[key];
36
36
  }
37
37
  });
38
+ });
39
+ var _pie = require("./pie");
40
+ Object.keys(_pie).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _pie[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _pie[key];
47
+ }
48
+ });
38
49
  });
@@ -21,5 +21,5 @@ export type LineItemIdentifier = {
21
21
  */
22
22
  dataIndex?: number;
23
23
  };
24
- export interface DefaultizedLineSeriesType extends DefaultizedProps<LineSeriesType, CommonDefaultizedProps> {
24
+ export interface DefaultizedLineSeriesType extends DefaultizedProps<LineSeriesType, CommonDefaultizedProps | 'color'> {
25
25
  }
@@ -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. ANd 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. ANd 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 = {
@@ -43,7 +43,9 @@ function BarChart(props) {
43
43
  xAxis: xAxis ?? [{
44
44
  id: DEFAULT_X_AXIS_KEY,
45
45
  scaleType: 'band',
46
- data: [...new Array(Math.max(...series.map(s => s.data.length)))].map((_, index) => index)
46
+ data: Array.from({
47
+ length: Math.max(...series.map(s => s.data.length))
48
+ }, (_, index) => index)
47
49
  }],
48
50
  yAxis: yAxis,
49
51
  colors: colors,
@@ -74,7 +76,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
74
76
  y: PropTypes.oneOf(['line', 'none'])
75
77
  }),
76
78
  /**
77
- * Indicate which axis to display the the bottom of the charts.
79
+ * Indicate which axis to display the bottom of the charts.
78
80
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
79
81
  * @default xAxisIds[0] The id of the first provided axis
80
82
  */
@@ -101,7 +103,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
101
103
  disableAxisListener: PropTypes.bool,
102
104
  height: PropTypes.number,
103
105
  /**
104
- * Indicate which axis to display the the left of the charts.
106
+ * Indicate which axis to display the left of the charts.
105
107
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
106
108
  * @default yAxisIds[0] The id of the first provided axis
107
109
  */
@@ -121,6 +123,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
121
123
  legend: PropTypes.shape({
122
124
  classes: PropTypes.object,
123
125
  direction: PropTypes.oneOf(['column', 'row']),
126
+ hidden: PropTypes.bool,
124
127
  itemWidth: PropTypes.number,
125
128
  markSize: PropTypes.number,
126
129
  offset: PropTypes.shape({
@@ -140,7 +143,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
140
143
  top: PropTypes.number
141
144
  }),
142
145
  /**
143
- * Indicate which axis to display the the right of the charts.
146
+ * Indicate which axis to display the right of the charts.
144
147
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
145
148
  * @default null
146
149
  */
@@ -183,7 +186,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
183
186
  trigger: PropTypes.oneOf(['axis', 'item', 'none'])
184
187
  }),
185
188
  /**
186
- * Indicate which axis to display the the top of the charts.
189
+ * Indicate which axis to display the top of the charts.
187
190
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
188
191
  * @default null
189
192
  */
@@ -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;
@@ -70,7 +70,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
70
70
  // | To update them edit the TypeScript types and run "yarn proptypes" |
71
71
  // ----------------------------------------------------------------------
72
72
  /**
73
- * Indicate which axis to display the the bottom of the charts.
73
+ * Indicate which axis to display the bottom of the charts.
74
74
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
75
75
  * @default xAxisIds[0] The id of the first provided axis
76
76
  */
@@ -88,7 +88,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
88
88
  tickSize: PropTypes.number
89
89
  }), PropTypes.string]),
90
90
  /**
91
- * Indicate which axis to display the the left of the charts.
91
+ * Indicate which axis to display the left of the charts.
92
92
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
93
93
  * @default yAxisIds[0] The id of the first provided axis
94
94
  */
@@ -106,7 +106,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
106
106
  tickSize: PropTypes.number
107
107
  }), PropTypes.string]),
108
108
  /**
109
- * Indicate which axis to display the the right of the charts.
109
+ * Indicate which axis to display the right of the charts.
110
110
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
111
111
  * @default null
112
112
  */
@@ -124,7 +124,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
124
124
  tickSize: PropTypes.number
125
125
  }), PropTypes.string]),
126
126
  /**
127
- * Indicate which axis to display the the top of the charts.
127
+ * Indicate which axis to display the top of the charts.
128
128
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
129
129
  * @default null
130
130
  */
@@ -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]);
@@ -23,10 +23,10 @@ export const ChartsTooltipRow = styled('tr', {
23
23
  })(({
24
24
  theme
25
25
  }) => ({
26
- '&:first-child td': {
26
+ 'tr:first-of-type& td': {
27
27
  paddingTop: theme.spacing(1)
28
28
  },
29
- '&:last-child td': {
29
+ 'tr:last-of-type& td': {
30
30
  paddingBottom: theme.spacing(1)
31
31
  }
32
32
  }));
@@ -38,18 +38,18 @@ export const ChartsTooltipCell = styled('td', {
38
38
  }) => ({
39
39
  verticalAlign: 'middle',
40
40
  color: theme.palette.text.secondary,
41
- '&:first-child': {
42
- paddingLeft: theme.spacing(2)
43
- },
44
- '&:last-child': {
45
- paddingRight: theme.spacing(2)
46
- },
47
41
  [`&.${tooltipClasses.labelCell}`]: {
48
42
  paddingLeft: theme.spacing(1)
49
43
  },
50
44
  [`&.${tooltipClasses.valueCell}`]: {
51
45
  paddingLeft: theme.spacing(4),
52
46
  color: theme.palette.text.primary
47
+ },
48
+ 'td:first-of-type&': {
49
+ paddingLeft: theme.spacing(2)
50
+ },
51
+ 'td:last-of-type&': {
52
+ paddingRight: theme.spacing(2)
53
53
  }
54
54
  }));
55
55
  export const ChartsTooltipMark = styled(Box, {
@@ -47,7 +47,9 @@ function LineChart(props) {
47
47
  xAxis: xAxis ?? [{
48
48
  id: DEFAULT_X_AXIS_KEY,
49
49
  scaleType: 'point',
50
- data: [...new Array(Math.max(...series.map(s => s.data.length)))].map((_, index) => index)
50
+ data: Array.from({
51
+ length: Math.max(...series.map(s => s.data.length))
52
+ }, (_, index) => index)
51
53
  }],
52
54
  yAxis: yAxis,
53
55
  colors: colors,
@@ -76,7 +78,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
76
78
  y: PropTypes.oneOf(['line', 'none'])
77
79
  }),
78
80
  /**
79
- * Indicate which axis to display the the bottom of the charts.
81
+ * Indicate which axis to display the bottom of the charts.
80
82
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
81
83
  * @default xAxisIds[0] The id of the first provided axis
82
84
  */
@@ -103,7 +105,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
103
105
  disableAxisListener: PropTypes.bool,
104
106
  height: PropTypes.number,
105
107
  /**
106
- * Indicate which axis to display the the left of the charts.
108
+ * Indicate which axis to display the left of the charts.
107
109
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
108
110
  * @default yAxisIds[0] The id of the first provided axis
109
111
  */
@@ -123,6 +125,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
123
125
  legend: PropTypes.shape({
124
126
  classes: PropTypes.object,
125
127
  direction: PropTypes.oneOf(['column', 'row']),
128
+ hidden: PropTypes.bool,
126
129
  itemWidth: PropTypes.number,
127
130
  markSize: PropTypes.number,
128
131
  offset: PropTypes.shape({
@@ -142,7 +145,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
142
145
  top: PropTypes.number
143
146
  }),
144
147
  /**
145
- * Indicate which axis to display the the right of the charts.
148
+ * Indicate which axis to display the right of the charts.
146
149
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
147
150
  * @default null
148
151
  */
@@ -187,7 +190,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
187
190
  trigger: PropTypes.oneOf(['axis', 'item', 'none'])
188
191
  }),
189
192
  /**
190
- * Indicate which axis to display the the top of the charts.
193
+ * Indicate which axis to display the top of the charts.
191
194
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
192
195
  * @default null
193
196
  */
@@ -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;