@mui/x-charts 7.0.0-beta.1 → 7.0.0-beta.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 (234) hide show
  1. package/BarChart/BarChart.d.ts +21 -5
  2. package/BarChart/BarChart.js +37 -13
  3. package/BarChart/BarElement.d.ts +20 -13
  4. package/BarChart/BarElement.js +1 -0
  5. package/BarChart/BarPlot.d.ts +3 -5
  6. package/BarChart/BarPlot.js +9 -10
  7. package/CHANGELOG.md +223 -1
  8. package/ChartContainer/ChartContainer.js +6 -4
  9. package/ChartsAxis/ChartsAxis.js +4 -4
  10. package/ChartsGrid/ChartsGrid.d.ts +30 -0
  11. package/ChartsGrid/ChartsGrid.js +128 -0
  12. package/ChartsGrid/chartsGridClasses.d.ts +13 -0
  13. package/ChartsGrid/chartsGridClasses.js +14 -0
  14. package/ChartsGrid/index.d.ts +2 -0
  15. package/ChartsGrid/index.js +27 -0
  16. package/ChartsGrid/package.json +6 -0
  17. package/ChartsLegend/ChartsLegend.d.ts +5 -54
  18. package/ChartsLegend/ChartsLegend.js +2 -307
  19. package/ChartsLegend/DefaultChartsLegend.d.ts +60 -0
  20. package/ChartsLegend/DefaultChartsLegend.js +294 -0
  21. package/ChartsLegend/index.d.ts +1 -0
  22. package/ChartsLegend/index.js +11 -0
  23. package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  24. package/ChartsReferenceLine/common.d.ts +2 -1
  25. package/ChartsSurface.js +6 -4
  26. package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  27. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
  28. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  29. package/ChartsTooltip/utils.d.ts +1 -0
  30. package/ChartsTooltip/utils.js +7 -0
  31. package/ChartsXAxis/ChartsXAxis.js +15 -11
  32. package/ChartsYAxis/ChartsYAxis.js +3 -3
  33. package/Gauge/Gauge.d.ts +13 -0
  34. package/Gauge/Gauge.js +156 -0
  35. package/Gauge/GaugeContainer.d.ts +19 -0
  36. package/Gauge/GaugeContainer.js +216 -0
  37. package/Gauge/GaugeProvider.d.ts +117 -0
  38. package/Gauge/GaugeProvider.js +96 -0
  39. package/Gauge/GaugeReferenceArc.d.ts +2 -0
  40. package/Gauge/GaugeReferenceArc.js +44 -0
  41. package/Gauge/GaugeValueArc.d.ts +2 -0
  42. package/Gauge/GaugeValueArc.js +51 -0
  43. package/Gauge/GaugeValueText.d.ts +15 -0
  44. package/Gauge/GaugeValueText.js +77 -0
  45. package/Gauge/gaugeClasses.d.ts +14 -0
  46. package/Gauge/gaugeClasses.js +15 -0
  47. package/Gauge/index.d.ts +7 -0
  48. package/Gauge/index.js +87 -0
  49. package/Gauge/package.json +6 -0
  50. package/Gauge/utils.d.ts +19 -0
  51. package/Gauge/utils.js +75 -0
  52. package/LineChart/AnimatedArea.js +1 -1
  53. package/LineChart/AnimatedLine.js +1 -1
  54. package/LineChart/AreaElement.d.ts +2 -1
  55. package/LineChart/AreaElement.js +1 -1
  56. package/LineChart/LineChart.d.ts +24 -5
  57. package/LineChart/LineChart.js +41 -13
  58. package/LineChart/LineElement.d.ts +2 -1
  59. package/LineChart/LineElement.js +1 -1
  60. package/LineChart/LineHighlightElement.d.ts +3 -2
  61. package/LineChart/LineHighlightElement.js +2 -1
  62. package/LineChart/MarkElement.d.ts +3 -2
  63. package/LineChart/MarkElement.js +1 -0
  64. package/PieChart/PieArc.d.ts +7 -6
  65. package/PieChart/PieArc.js +10 -9
  66. package/PieChart/PieArcLabel.d.ts +3 -2
  67. package/PieChart/PieArcLabel.js +1 -0
  68. package/PieChart/PieArcLabelPlot.js +14 -14
  69. package/PieChart/PieArcPlot.js +1 -1
  70. package/PieChart/PieChart.d.ts +22 -0
  71. package/PieChart/PieChart.js +32 -8
  72. package/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -70
  73. package/ResponsiveChartContainer/useChartContainerDimensions.d.ts +2 -0
  74. package/ResponsiveChartContainer/useChartContainerDimensions.js +76 -0
  75. package/ScatterChart/ScatterChart.d.ts +18 -0
  76. package/ScatterChart/ScatterChart.js +35 -8
  77. package/SparkLineChart/SparkLineChart.d.ts +1 -1
  78. package/SparkLineChart/SparkLineChart.js +5 -4
  79. package/context/CartesianContextProvider.js +8 -6
  80. package/esm/BarChart/BarChart.js +37 -13
  81. package/esm/BarChart/BarElement.js +1 -0
  82. package/esm/BarChart/BarPlot.js +8 -10
  83. package/esm/ChartContainer/ChartContainer.js +6 -4
  84. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  85. package/esm/ChartsGrid/ChartsGrid.js +121 -0
  86. package/esm/ChartsGrid/chartsGridClasses.js +6 -0
  87. package/esm/ChartsGrid/index.js +2 -0
  88. package/esm/ChartsLegend/ChartsLegend.js +2 -307
  89. package/esm/ChartsLegend/DefaultChartsLegend.js +286 -0
  90. package/esm/ChartsLegend/index.js +1 -0
  91. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  92. package/esm/ChartsSurface.js +6 -4
  93. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  94. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +2 -2
  95. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  96. package/esm/ChartsTooltip/utils.js +6 -0
  97. package/esm/ChartsXAxis/ChartsXAxis.js +14 -10
  98. package/esm/ChartsYAxis/ChartsYAxis.js +2 -2
  99. package/esm/Gauge/Gauge.js +149 -0
  100. package/esm/Gauge/GaugeContainer.js +211 -0
  101. package/esm/Gauge/GaugeProvider.js +85 -0
  102. package/esm/Gauge/GaugeReferenceArc.js +35 -0
  103. package/esm/Gauge/GaugeValueArc.js +42 -0
  104. package/esm/Gauge/GaugeValueText.js +69 -0
  105. package/esm/Gauge/gaugeClasses.js +7 -0
  106. package/esm/Gauge/index.js +7 -0
  107. package/esm/Gauge/utils.js +68 -0
  108. package/esm/LineChart/AnimatedArea.js +1 -1
  109. package/esm/LineChart/AnimatedLine.js +1 -1
  110. package/esm/LineChart/AreaElement.js +1 -1
  111. package/esm/LineChart/LineChart.js +41 -13
  112. package/esm/LineChart/LineElement.js +1 -1
  113. package/esm/LineChart/LineHighlightElement.js +2 -1
  114. package/esm/LineChart/MarkElement.js +1 -0
  115. package/esm/PieChart/PieArc.js +10 -9
  116. package/esm/PieChart/PieArcLabel.js +1 -0
  117. package/esm/PieChart/PieArcLabelPlot.js +14 -14
  118. package/esm/PieChart/PieArcPlot.js +1 -1
  119. package/esm/PieChart/PieChart.js +32 -8
  120. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -70
  121. package/esm/ResponsiveChartContainer/useChartContainerDimensions.js +66 -0
  122. package/esm/ScatterChart/ScatterChart.js +35 -8
  123. package/esm/SparkLineChart/SparkLineChart.js +5 -4
  124. package/esm/context/CartesianContextProvider.js +8 -6
  125. package/esm/hooks/useTicks.js +2 -3
  126. package/esm/index.js +2 -0
  127. package/hooks/useTicks.d.ts +1 -2
  128. package/hooks/useTicks.js +2 -3
  129. package/index.d.ts +2 -0
  130. package/index.js +23 -1
  131. package/internals/defaultizeColor.d.ts +16 -16
  132. package/internals/defaultizeValueFormatter.d.ts +4 -7
  133. package/internals/stackSeries.d.ts +4 -7
  134. package/legacy/BarChart/BarChart.js +37 -13
  135. package/legacy/BarChart/BarElement.js +1 -0
  136. package/legacy/BarChart/BarPlot.js +10 -10
  137. package/legacy/ChartContainer/ChartContainer.js +6 -4
  138. package/legacy/ChartsAxis/ChartsAxis.js +4 -4
  139. package/legacy/ChartsGrid/ChartsGrid.js +119 -0
  140. package/legacy/ChartsGrid/chartsGridClasses.js +6 -0
  141. package/legacy/ChartsGrid/index.js +2 -0
  142. package/legacy/ChartsLegend/ChartsLegend.js +2 -323
  143. package/legacy/ChartsLegend/DefaultChartsLegend.js +302 -0
  144. package/legacy/ChartsLegend/index.js +1 -0
  145. package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  146. package/legacy/ChartsSurface.js +5 -3
  147. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  148. package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +2 -2
  149. package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  150. package/legacy/ChartsTooltip/utils.js +6 -0
  151. package/legacy/ChartsXAxis/ChartsXAxis.js +13 -9
  152. package/legacy/ChartsYAxis/ChartsYAxis.js +2 -2
  153. package/legacy/Gauge/Gauge.js +146 -0
  154. package/legacy/Gauge/GaugeContainer.js +215 -0
  155. package/legacy/Gauge/GaugeProvider.js +87 -0
  156. package/legacy/Gauge/GaugeReferenceArc.js +37 -0
  157. package/legacy/Gauge/GaugeValueArc.js +44 -0
  158. package/legacy/Gauge/GaugeValueText.js +66 -0
  159. package/legacy/Gauge/gaugeClasses.js +7 -0
  160. package/legacy/Gauge/index.js +7 -0
  161. package/legacy/Gauge/utils.js +84 -0
  162. package/legacy/LineChart/AnimatedArea.js +1 -1
  163. package/legacy/LineChart/AnimatedLine.js +1 -1
  164. package/legacy/LineChart/AreaElement.js +1 -1
  165. package/legacy/LineChart/LineChart.js +41 -13
  166. package/legacy/LineChart/LineElement.js +1 -1
  167. package/legacy/LineChart/LineHighlightElement.js +2 -1
  168. package/legacy/LineChart/MarkElement.js +1 -0
  169. package/legacy/PieChart/PieArc.js +11 -10
  170. package/legacy/PieChart/PieArcLabel.js +1 -0
  171. package/legacy/PieChart/PieArcLabelPlot.js +15 -15
  172. package/legacy/PieChart/PieArcPlot.js +1 -1
  173. package/legacy/PieChart/PieChart.js +32 -8
  174. package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +13 -81
  175. package/legacy/ResponsiveChartContainer/useChartContainerDimensions.js +73 -0
  176. package/legacy/ScatterChart/ScatterChart.js +35 -8
  177. package/legacy/SparkLineChart/SparkLineChart.js +6 -5
  178. package/legacy/context/CartesianContextProvider.js +8 -6
  179. package/legacy/hooks/useTicks.js +2 -3
  180. package/legacy/index.js +3 -1
  181. package/models/axis.d.ts +7 -2
  182. package/models/seriesType/common.d.ts +2 -1
  183. package/models/seriesType/config.d.ts +7 -12
  184. package/models/seriesType/line.d.ts +2 -2
  185. package/models/seriesType/pie.d.ts +7 -3
  186. package/models/seriesType/scatter.d.ts +5 -2
  187. package/modern/BarChart/BarChart.js +37 -13
  188. package/modern/BarChart/BarElement.js +1 -0
  189. package/modern/BarChart/BarPlot.js +8 -10
  190. package/modern/ChartContainer/ChartContainer.js +6 -4
  191. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  192. package/modern/ChartsGrid/ChartsGrid.js +121 -0
  193. package/modern/ChartsGrid/chartsGridClasses.js +6 -0
  194. package/modern/ChartsGrid/index.js +2 -0
  195. package/modern/ChartsLegend/ChartsLegend.js +2 -307
  196. package/modern/ChartsLegend/DefaultChartsLegend.js +286 -0
  197. package/modern/ChartsLegend/index.js +1 -0
  198. package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  199. package/modern/ChartsSurface.js +6 -4
  200. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  201. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +2 -2
  202. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  203. package/modern/ChartsTooltip/utils.js +6 -0
  204. package/modern/ChartsXAxis/ChartsXAxis.js +14 -10
  205. package/modern/ChartsYAxis/ChartsYAxis.js +2 -2
  206. package/modern/Gauge/Gauge.js +149 -0
  207. package/modern/Gauge/GaugeContainer.js +208 -0
  208. package/modern/Gauge/GaugeProvider.js +85 -0
  209. package/modern/Gauge/GaugeReferenceArc.js +35 -0
  210. package/modern/Gauge/GaugeValueArc.js +42 -0
  211. package/modern/Gauge/GaugeValueText.js +69 -0
  212. package/modern/Gauge/gaugeClasses.js +7 -0
  213. package/modern/Gauge/index.js +7 -0
  214. package/modern/Gauge/utils.js +68 -0
  215. package/modern/LineChart/AnimatedArea.js +1 -1
  216. package/modern/LineChart/AnimatedLine.js +1 -1
  217. package/modern/LineChart/AreaElement.js +1 -1
  218. package/modern/LineChart/LineChart.js +41 -13
  219. package/modern/LineChart/LineElement.js +1 -1
  220. package/modern/LineChart/LineHighlightElement.js +2 -1
  221. package/modern/LineChart/MarkElement.js +1 -0
  222. package/modern/PieChart/PieArc.js +10 -9
  223. package/modern/PieChart/PieArcLabel.js +1 -0
  224. package/modern/PieChart/PieArcLabelPlot.js +14 -14
  225. package/modern/PieChart/PieArcPlot.js +1 -1
  226. package/modern/PieChart/PieChart.js +32 -8
  227. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -70
  228. package/modern/ResponsiveChartContainer/useChartContainerDimensions.js +66 -0
  229. package/modern/ScatterChart/ScatterChart.js +35 -8
  230. package/modern/SparkLineChart/SparkLineChart.js +5 -4
  231. package/modern/context/CartesianContextProvider.js +8 -6
  232. package/modern/hooks/useTicks.js +2 -3
  233. package/modern/index.js +3 -1
  234. package/package.json +4 -4
package/models/axis.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, S
3
3
  import { ChartsAxisClasses } from '../ChartsAxis/axisClasses';
4
4
  import type { TickParams } from '../hooks/useTicks';
5
5
  import { ChartsTextProps } from '../ChartsText';
6
+ export type AxisId = string | number;
6
7
  export type D3Scale<Domain extends {
7
8
  toString(): string;
8
9
  } = number | Date | string, Range = number, Output = number> = ScaleBand<Domain> | ScaleLogarithmic<Range, Output> | ScalePoint<Domain> | ScalePower<Range, Output> | ScaleTime<Range, Output> | ScaleLinear<Range, Output>;
@@ -24,7 +25,7 @@ export interface ChartsAxisProps extends TickParams {
24
25
  * The id of the axis to render.
25
26
  * If undefined, it will be the first defined axis.
26
27
  */
27
- axisId?: string;
28
+ axisId?: AxisId;
28
29
  /**
29
30
  * If true, the axis line is disabled.
30
31
  * @default false
@@ -160,7 +161,7 @@ export type AxisConfig<S extends ScaleName = ScaleName, V = any> = {
160
161
  /**
161
162
  * Id used to identify the axis.
162
163
  */
163
- id: string;
164
+ id: AxisId;
164
165
  /**
165
166
  * The minimal value of the domain.
166
167
  * If not provided, it gets computed to display the entire chart data.
@@ -184,6 +185,10 @@ export type AxisConfig<S extends ScaleName = ScaleName, V = any> = {
184
185
  * If `true`, hide this value in the tooltip
185
186
  */
186
187
  hideTooltip?: boolean;
188
+ /**
189
+ * If `true`, Reverse the axis scaleBand.
190
+ */
191
+ reverse?: boolean;
187
192
  } & Partial<ChartsXAxisProps | ChartsYAxisProps> & Partial<Omit<AxisScaleConfig[S], 'scale'>> & TickParams;
188
193
  export type AxisDefaultized<S extends ScaleName = ScaleName, V = any> = Omit<AxisConfig<S, V>, 'scaleType'> & AxisScaleConfig[S] & {
189
194
  /**
@@ -1,7 +1,8 @@
1
1
  import type { HighlightScope } from '../../context/HighlightProvider';
2
2
  import type { StackOffsetType, StackOrderType } from '../stacking';
3
+ export type SeriesId = number | string;
3
4
  export type CommonSeriesType<TValue> = {
4
- id?: string;
5
+ id?: SeriesId;
5
6
  color?: string;
6
7
  /**
7
8
  * Formatter used to render values in tooltip or other data display.
@@ -5,6 +5,7 @@ import { PieSeriesType, DefaultizedPieSeriesType, PieItemIdentifier, PieValueTyp
5
5
  import { AxisConfig } from '../axis';
6
6
  import { DefaultizedProps, MakeOptional } from '../helpers';
7
7
  import { StackingGroupsType } from '../../internals/stackSeries';
8
+ import { SeriesId } from './common';
8
9
  interface ChartsSeriesConfig {
9
10
  bar: {
10
11
  seriesInput: DefaultizedProps<BarSeriesType, 'id'> & {
@@ -53,25 +54,19 @@ export type ChartSeriesDefaultized<T extends ChartSeriesType> = ChartsSeriesConf
53
54
  } : ChartsSeriesConfig[T]['series'];
54
55
  export type ChartItemIdentifier<T extends ChartSeriesType> = ChartsSeriesConfig[T]['itemIdentifier'];
55
56
  type ExtremumGetterParams<T extends ChartSeriesType> = {
56
- series: {
57
- [id: string]: ChartSeries<T>;
58
- };
57
+ series: Record<SeriesId, ChartSeries<T>>;
59
58
  axis: AxisConfig;
60
59
  isDefaultAxis: boolean;
61
60
  };
62
61
  export type ExtremumGetterResult = [number, number] | [null, null];
63
62
  export type ExtremumGetter<T extends ChartSeriesType> = (params: ExtremumGetterParams<T>) => ExtremumGetterResult;
64
63
  export type FormatterParams<T extends ChartSeriesType> = {
65
- series: {
66
- [id: string]: ChartsSeriesConfig[T]['seriesInput'];
67
- };
68
- seriesOrder: string[];
64
+ series: Record<SeriesId, ChartsSeriesConfig[T]['seriesInput']>;
65
+ seriesOrder: SeriesId[];
69
66
  };
70
67
  export type FormatterResult<T extends ChartSeriesType> = {
71
- series: {
72
- [id: string]: ChartSeriesDefaultized<T>;
73
- };
74
- seriesOrder: string[];
68
+ series: Record<SeriesId, ChartSeriesDefaultized<T>>;
69
+ seriesOrder: SeriesId[];
75
70
  } & (ChartsSeriesConfig[T] extends {
76
71
  canBeStacked: true;
77
72
  } ? {
@@ -95,7 +90,7 @@ export type LegendParams = {
95
90
  * The identifier of the legend element.
96
91
  * Used for internal purpose such as `key` props
97
92
  */
98
- id: string;
93
+ id: SeriesId;
99
94
  };
100
95
  export type LegendGetter<T extends ChartSeriesType> = (series: FormatterResult<T>) => LegendParams[];
101
96
  export {};
@@ -1,6 +1,6 @@
1
1
  import { DefaultizedProps } from '../helpers';
2
2
  import type { StackOffsetType } from '../stacking';
3
- import { CartesianSeriesType, CommonDefaultizedProps, CommonSeriesType, StackableSeriesType } from './common';
3
+ import { CartesianSeriesType, CommonDefaultizedProps, CommonSeriesType, SeriesId, StackableSeriesType } from './common';
4
4
  export type CurveType = 'catmullRom' | 'linear' | 'monotoneX' | 'monotoneY' | 'natural' | 'step' | 'stepBefore' | 'stepAfter';
5
5
  export interface ShowMarkParams<AxisValue = number | Date> {
6
6
  /**
@@ -66,7 +66,7 @@ export interface LineSeriesType extends CommonSeriesType<number | null>, Cartesi
66
66
  */
67
67
  export type LineItemIdentifier = {
68
68
  type: 'line';
69
- seriesId: DefaultizedLineSeriesType['id'];
69
+ seriesId: SeriesId;
70
70
  /**
71
71
  * `dataIndex` can be `undefined` if the mouse is over the area and not a specific item.
72
72
  */
@@ -1,8 +1,12 @@
1
1
  import { PieArcDatum as D3PieArcDatum } from 'd3-shape';
2
2
  import { DefaultizedProps } from '../helpers';
3
- import { CommonDefaultizedProps, CommonSeriesType } from './common';
3
+ import { CommonDefaultizedProps, CommonSeriesType, SeriesId } from './common';
4
+ export type PieItemId = string | number;
4
5
  export type PieValueType = {
5
- id: string | number;
6
+ /**
7
+ * A unique identifier of the pie slice.
8
+ */
9
+ id: PieItemId;
6
10
  value: number;
7
11
  label?: string;
8
12
  color?: string;
@@ -119,7 +123,7 @@ export interface PieSeriesType<Tdata = PieValueType> extends CommonSeriesType<Td
119
123
  */
120
124
  export type PieItemIdentifier = {
121
125
  type: 'pie';
122
- seriesId: DefaultizedPieSeriesType['id'];
126
+ seriesId: SeriesId;
123
127
  dataIndex: number;
124
128
  };
125
129
  export interface DefaultizedPieSeriesType extends DefaultizedProps<PieSeriesType, CommonDefaultizedProps> {
@@ -1,8 +1,11 @@
1
1
  import { DefaultizedProps } from '../helpers';
2
- import { CartesianSeriesType, CommonDefaultizedProps, CommonSeriesType } from './common';
2
+ import { CartesianSeriesType, CommonDefaultizedProps, CommonSeriesType, SeriesId } from './common';
3
3
  export type ScatterValueType = {
4
4
  x: number;
5
5
  y: number;
6
+ /**
7
+ * A unique identifier for the scatter point
8
+ */
6
9
  id: string | number;
7
10
  };
8
11
  export interface ScatterSeriesType extends CommonSeriesType<ScatterValueType>, CartesianSeriesType {
@@ -22,7 +25,7 @@ export interface ScatterSeriesType extends CommonSeriesType<ScatterValueType>, C
22
25
  */
23
26
  export type ScatterItemIdentifier = {
24
27
  type: 'scatter';
25
- seriesId: DefaultizedScatterSeriesType['id'];
28
+ seriesId: SeriesId;
26
29
  dataIndex: number;
27
30
  };
28
31
  export interface DefaultizedScatterSeriesType extends DefaultizedProps<ScatterSeriesType, CommonDefaultizedProps | 'color'> {
@@ -10,6 +10,7 @@ import { ChartsTooltip } from '../ChartsTooltip';
10
10
  import { ChartsLegend } from '../ChartsLegend';
11
11
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
12
12
  import { ChartsClipPath } from '../ChartsClipPath';
13
+ import { ChartsGrid } from '../ChartsGrid';
13
14
  import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
14
15
  import { jsx as _jsx } from "react/jsx-runtime";
15
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -39,6 +40,7 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
39
40
  tooltip,
40
41
  axisHighlight,
41
42
  legend,
43
+ grid,
42
44
  topAxis,
43
45
  leftAxis,
44
46
  rightAxis,
@@ -86,6 +88,9 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
86
88
  disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick,
87
89
  children: [onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, {
88
90
  onAxisClick: onAxisClick
91
+ }), grid && /*#__PURE__*/_jsx(ChartsGrid, {
92
+ vertical: grid.vertical,
93
+ horizontal: grid.horizontal
89
94
  }), /*#__PURE__*/_jsx("g", {
90
95
  clipPath: `url(#${clipPathId})`,
91
96
  children: /*#__PURE__*/_jsx(BarPlot, {
@@ -118,11 +123,10 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
118
123
  // | To update them edit the TypeScript types and run "yarn proptypes" |
119
124
  // ----------------------------------------------------------------------
120
125
  /**
121
- * Object `{ x, y }` that defines how the charts highlight the mouse position along the x- and y-axes.
122
- * The two properties accept the following values:
123
- * - 'none': display nothing.
124
- * - 'line': display a line at the current mouse position.
125
- * - 'band': display a band at the current mouse position. Only available with band scale.
126
+ * The configuration of axes highlight.
127
+ * Default is set to 'band' in the bar direction.
128
+ * Depends on `layout` prop.
129
+ * @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
126
130
  */
127
131
  axisHighlight: PropTypes.shape({
128
132
  x: PropTypes.oneOf(['band', 'line', 'none']),
@@ -134,7 +138,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
134
138
  * @default xAxisIds[0] The id of the first provided axis
135
139
  */
136
140
  bottomAxis: PropTypes.oneOfType([PropTypes.shape({
137
- axisId: PropTypes.string,
141
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
138
142
  classes: PropTypes.object,
139
143
  disableLine: PropTypes.bool,
140
144
  disableTicks: PropTypes.bool,
@@ -173,11 +177,22 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
173
177
  * @default false
174
178
  */
175
179
  disableAxisListener: PropTypes.bool,
180
+ /**
181
+ * Option to display a cartesian grid in the background.
182
+ */
183
+ grid: PropTypes.shape({
184
+ horizontal: PropTypes.bool,
185
+ vertical: PropTypes.bool
186
+ }),
176
187
  /**
177
188
  * The height of the chart in px. If not defined, it takes the height of the parent element.
178
189
  * @default undefined
179
190
  */
180
191
  height: PropTypes.number,
192
+ /**
193
+ * The direction of the bar elements.
194
+ * @default 'vertical'
195
+ */
181
196
  layout: PropTypes.oneOf(['horizontal', 'vertical']),
182
197
  /**
183
198
  * Indicate which axis to display the left of the charts.
@@ -185,7 +200,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
185
200
  * @default yAxisIds[0] The id of the first provided axis
186
201
  */
187
202
  leftAxis: PropTypes.oneOfType([PropTypes.shape({
188
- axisId: PropTypes.string,
203
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
189
204
  classes: PropTypes.object,
190
205
  disableLine: PropTypes.bool,
191
206
  disableTicks: PropTypes.bool,
@@ -251,7 +266,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
251
266
  * @default null
252
267
  */
253
268
  rightAxis: PropTypes.oneOfType([PropTypes.shape({
254
- axisId: PropTypes.string,
269
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
255
270
  classes: PropTypes.object,
256
271
  disableLine: PropTypes.bool,
257
272
  disableTicks: PropTypes.bool,
@@ -272,6 +287,9 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
272
287
  tickNumber: PropTypes.number,
273
288
  tickSize: PropTypes.number
274
289
  }), PropTypes.string]),
290
+ /**
291
+ * The series to display in the bar chart.
292
+ */
275
293
  series: PropTypes.arrayOf(PropTypes.object).isRequired,
276
294
  /**
277
295
  * If `true`, animations are skipped.
@@ -290,6 +308,10 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
290
308
  slots: PropTypes.object,
291
309
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
292
310
  title: PropTypes.string,
311
+ /**
312
+ * The configuration of the tooltip.
313
+ * @see See {@link https://mui.com/x/react-charts/tooltip/ tooltip docs} for more details.
314
+ */
293
315
  tooltip: PropTypes.shape({
294
316
  axisContent: PropTypes.elementType,
295
317
  classes: PropTypes.object,
@@ -304,7 +326,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
304
326
  * @default null
305
327
  */
306
328
  topAxis: PropTypes.oneOfType([PropTypes.shape({
307
- axisId: PropTypes.string,
329
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
308
330
  classes: PropTypes.object,
309
331
  disableLine: PropTypes.bool,
310
332
  disableTicks: PropTypes.bool,
@@ -341,7 +363,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
341
363
  * If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
342
364
  */
343
365
  xAxis: PropTypes.arrayOf(PropTypes.shape({
344
- axisId: PropTypes.string,
366
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
345
367
  classes: PropTypes.object,
346
368
  data: PropTypes.array,
347
369
  dataKey: PropTypes.string,
@@ -349,13 +371,14 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
349
371
  disableTicks: PropTypes.bool,
350
372
  fill: PropTypes.string,
351
373
  hideTooltip: PropTypes.bool,
352
- id: PropTypes.string,
374
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
353
375
  label: PropTypes.string,
354
376
  labelFontSize: PropTypes.number,
355
377
  labelStyle: PropTypes.object,
356
378
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
357
379
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
358
380
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
381
+ reverse: PropTypes.bool,
359
382
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
360
383
  slotProps: PropTypes.object,
361
384
  slots: PropTypes.object,
@@ -375,7 +398,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
375
398
  * If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
376
399
  */
377
400
  yAxis: PropTypes.arrayOf(PropTypes.shape({
378
- axisId: PropTypes.string,
401
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
379
402
  classes: PropTypes.object,
380
403
  data: PropTypes.array,
381
404
  dataKey: PropTypes.string,
@@ -383,13 +406,14 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
383
406
  disableTicks: PropTypes.bool,
384
407
  fill: PropTypes.string,
385
408
  hideTooltip: PropTypes.bool,
386
- id: PropTypes.string,
409
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
387
410
  label: PropTypes.string,
388
411
  labelFontSize: PropTypes.number,
389
412
  labelStyle: PropTypes.object,
390
413
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
391
414
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
392
415
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
416
+ reverse: PropTypes.bool,
393
417
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
394
418
  slotProps: PropTypes.object,
395
419
  slots: PropTypes.object,
@@ -105,6 +105,7 @@ process.env.NODE_ENV !== "production" ? BarElement.propTypes = {
105
105
  faded: PropTypes.oneOf(['global', 'none', 'series']),
106
106
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
107
107
  }),
108
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
108
109
  /**
109
110
  * The props used for each component slot.
110
111
  * @default {}
@@ -9,7 +9,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { BarElement } from './BarElement';
10
10
  import { isBandScaleConfig } from '../models/axis';
11
11
  import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
12
-
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
13
  /**
14
14
  * Solution of the equations
15
15
  * W = barWidth * N + offset * (N-1)
@@ -19,7 +19,6 @@ import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
19
19
  * @param gapRatio The ratio of the gap between bars over the bar width.
20
20
  * @returns The bar width and the offset between bars.
21
21
  */
22
- import { jsx as _jsx } from "react/jsx-runtime";
23
22
  function getBandSize({
24
23
  bandWidth: W,
25
24
  numberOfGroups: N,
@@ -101,20 +100,19 @@ const useAggregatedData = () => {
101
100
  color
102
101
  } = series[seriesId];
103
102
  return stackedData.map((values, dataIndex) => {
104
- const bottom = Math.min(...values);
105
- const top = Math.max(...values);
103
+ const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
104
+ const minValueCoord = Math.min(...valueCoordinates);
105
+ const maxValueCoord = Math.max(...valueCoordinates);
106
106
  return {
107
- bottom,
108
- top,
109
107
  seriesId,
110
108
  dataIndex,
111
109
  layout: series[seriesId].layout,
112
- x: verticalLayout ? xScale(xAxis[xAxisKey].data?.[dataIndex]) + barOffset : xScale(bottom),
113
- y: verticalLayout ? yScale(top) : yScale(yAxis[yAxisKey].data?.[dataIndex]) + barOffset,
110
+ x: verticalLayout ? xScale(xAxis[xAxisKey].data?.[dataIndex]) + barOffset : minValueCoord,
111
+ y: verticalLayout ? minValueCoord : yScale(yAxis[yAxisKey].data?.[dataIndex]) + barOffset,
114
112
  xOrigin: xScale(0),
115
113
  yOrigin: yScale(0),
116
- height: verticalLayout ? Math.abs(yScale(bottom) - yScale(top)) : barWidth,
117
- width: verticalLayout ? barWidth : Math.abs(xScale(bottom) - xScale(top)),
114
+ height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
115
+ width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
118
116
  color,
119
117
  highlightScope: series[seriesId].highlightScope
120
118
  };
@@ -122,7 +122,7 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
122
122
  * If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
123
123
  */
124
124
  xAxis: PropTypes.arrayOf(PropTypes.shape({
125
- axisId: PropTypes.string,
125
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
126
126
  classes: PropTypes.object,
127
127
  data: PropTypes.array,
128
128
  dataKey: PropTypes.string,
@@ -130,13 +130,14 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
130
130
  disableTicks: PropTypes.bool,
131
131
  fill: PropTypes.string,
132
132
  hideTooltip: PropTypes.bool,
133
- id: PropTypes.string,
133
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
134
134
  label: PropTypes.string,
135
135
  labelFontSize: PropTypes.number,
136
136
  labelStyle: PropTypes.object,
137
137
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
138
138
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
139
139
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
140
+ reverse: PropTypes.bool,
140
141
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
141
142
  slotProps: PropTypes.object,
142
143
  slots: PropTypes.object,
@@ -156,7 +157,7 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
156
157
  * If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
157
158
  */
158
159
  yAxis: PropTypes.arrayOf(PropTypes.shape({
159
- axisId: PropTypes.string,
160
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
160
161
  classes: PropTypes.object,
161
162
  data: PropTypes.array,
162
163
  dataKey: PropTypes.string,
@@ -164,13 +165,14 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
164
165
  disableTicks: PropTypes.bool,
165
166
  fill: PropTypes.string,
166
167
  hideTooltip: PropTypes.bool,
167
- id: PropTypes.string,
168
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
168
169
  label: PropTypes.string,
169
170
  labelFontSize: PropTypes.number,
170
171
  labelStyle: PropTypes.object,
171
172
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
172
173
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
173
174
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
175
+ reverse: PropTypes.bool,
174
176
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
175
177
  slotProps: PropTypes.object,
176
178
  slots: PropTypes.object,
@@ -100,7 +100,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
100
100
  * @default xAxisIds[0] The id of the first provided axis
101
101
  */
102
102
  bottomAxis: PropTypes.oneOfType([PropTypes.shape({
103
- axisId: PropTypes.string,
103
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
104
104
  classes: PropTypes.object,
105
105
  disableLine: PropTypes.bool,
106
106
  disableTicks: PropTypes.bool,
@@ -127,7 +127,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
127
127
  * @default yAxisIds[0] The id of the first provided axis
128
128
  */
129
129
  leftAxis: PropTypes.oneOfType([PropTypes.shape({
130
- axisId: PropTypes.string,
130
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
131
131
  classes: PropTypes.object,
132
132
  disableLine: PropTypes.bool,
133
133
  disableTicks: PropTypes.bool,
@@ -154,7 +154,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
154
154
  * @default null
155
155
  */
156
156
  rightAxis: PropTypes.oneOfType([PropTypes.shape({
157
- axisId: PropTypes.string,
157
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
158
158
  classes: PropTypes.object,
159
159
  disableLine: PropTypes.bool,
160
160
  disableTicks: PropTypes.bool,
@@ -191,7 +191,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
191
191
  * @default null
192
192
  */
193
193
  topAxis: PropTypes.oneOfType([PropTypes.shape({
194
- axisId: PropTypes.string,
194
+ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
195
195
  classes: PropTypes.object,
196
196
  disableLine: PropTypes.bool,
197
197
  disableTicks: PropTypes.bool,
@@ -0,0 +1,121 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["vertical", "horizontal"];
4
+ import * as React from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import composeClasses from '@mui/utils/composeClasses';
7
+ import { styled } from '@mui/material/styles';
8
+ import { CartesianContext } from '../context/CartesianContextProvider';
9
+ import { useTicks } from '../hooks/useTicks';
10
+ import { getChartsGridUtilityClass, chartsGridClasses } from './chartsGridClasses';
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { jsxs as _jsxs } from "react/jsx-runtime";
13
+ const GridRoot = styled('g', {
14
+ name: 'MuiChartsGrid',
15
+ slot: 'Root',
16
+ overridesResolver: (props, styles) => styles.root
17
+ })(({
18
+ theme
19
+ }) => ({
20
+ [`& .${chartsGridClasses.line}`]: {
21
+ stroke: (theme.vars || theme).palette.divider,
22
+ shapeRendering: 'crispEdges',
23
+ strokeWidth: 1
24
+ }
25
+ }));
26
+ const useUtilityClasses = ({
27
+ classes
28
+ }) => {
29
+ const slots = {
30
+ root: ['root'],
31
+ verticalLine: ['line', 'verticalLine'],
32
+ horizontalLine: ['line', 'horizontalLine']
33
+ };
34
+ return composeClasses(slots, getChartsGridUtilityClass, classes);
35
+ };
36
+ /**
37
+ * Demos:
38
+ *
39
+ * - [Axis](https://mui.com/x/react-charts/axis/)
40
+ *
41
+ * API:
42
+ *
43
+ * - [ChartsGrid API](https://mui.com/x/api/charts/charts-axis/)
44
+ */
45
+ function ChartsGrid(props) {
46
+ const {
47
+ vertical,
48
+ horizontal
49
+ } = props,
50
+ other = _objectWithoutPropertiesLoose(props, _excluded);
51
+ const {
52
+ xAxis,
53
+ xAxisIds,
54
+ yAxis,
55
+ yAxisIds
56
+ } = React.useContext(CartesianContext);
57
+ const classes = useUtilityClasses(props);
58
+ const horizontalAxisId = yAxisIds[0];
59
+ const verticalAxisId = xAxisIds[0];
60
+ const {
61
+ scale: xScale,
62
+ tickNumber: xTickNumber,
63
+ tickInterval: xTickInterval
64
+ } = xAxis[verticalAxisId];
65
+ const {
66
+ scale: yScale,
67
+ tickNumber: yTickNumber,
68
+ tickInterval: yTickInterval
69
+ } = yAxis[horizontalAxisId];
70
+ const xTicks = useTicks({
71
+ scale: xScale,
72
+ tickNumber: xTickNumber,
73
+ tickInterval: xTickInterval
74
+ });
75
+ const yTicks = useTicks({
76
+ scale: yScale,
77
+ tickNumber: yTickNumber,
78
+ tickInterval: yTickInterval
79
+ });
80
+ return /*#__PURE__*/_jsxs(GridRoot, _extends({}, other, {
81
+ className: classes.root,
82
+ children: [vertical && xTicks.map(({
83
+ formattedValue,
84
+ offset
85
+ }) => /*#__PURE__*/_jsx("line", {
86
+ y1: yScale.range()[0],
87
+ y2: yScale.range()[1],
88
+ x1: offset,
89
+ x2: offset,
90
+ className: classes.verticalLine
91
+ }, formattedValue)), horizontal && yTicks.map(({
92
+ formattedValue,
93
+ offset
94
+ }) => /*#__PURE__*/_jsx("line", {
95
+ y1: offset,
96
+ y2: offset,
97
+ x1: xScale.range()[0],
98
+ x2: xScale.range()[1],
99
+ className: classes.horizontalLine
100
+ }, formattedValue))]
101
+ }));
102
+ }
103
+ process.env.NODE_ENV !== "production" ? ChartsGrid.propTypes = {
104
+ // ----------------------------- Warning --------------------------------
105
+ // | These PropTypes are generated from the TypeScript type definitions |
106
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
107
+ // ----------------------------------------------------------------------
108
+ /**
109
+ * Override or extend the styles applied to the component.
110
+ */
111
+ classes: PropTypes.object,
112
+ /**
113
+ * Displays horizontal grid.
114
+ */
115
+ horizontal: PropTypes.bool,
116
+ /**
117
+ * Displays vertical grid.
118
+ */
119
+ vertical: PropTypes.bool
120
+ } : void 0;
121
+ export { ChartsGrid };
@@ -0,0 +1,6 @@
1
+ import generateUtilityClass from '@mui/utils/generateUtilityClass';
2
+ import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
3
+ export function getChartsGridUtilityClass(slot) {
4
+ return generateUtilityClass('MuiChartsGrid', slot);
5
+ }
6
+ export const chartsGridClasses = generateUtilityClasses('MuiChartsGrid', ['root', 'line', 'horizontalLine', 'verticalLine']);
@@ -0,0 +1,2 @@
1
+ export * from './ChartsGrid';
2
+ export * from './chartsGridClasses';