@mui/x-charts 7.1.1 → 7.3.0

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 (192) hide show
  1. package/BarChart/BarChart.js +32 -2
  2. package/BarChart/BarPlot.js +12 -5
  3. package/BarChart/extremums.js +1 -1
  4. package/BarChart/getColor.d.ts +3 -0
  5. package/BarChart/getColor.js +33 -0
  6. package/CHANGELOG.md +211 -0
  7. package/ChartContainer/ChartContainer.js +35 -4
  8. package/ChartsAxis/ChartsAxis.js +4 -4
  9. package/ChartsClipPath/ChartsClipPath.js +2 -2
  10. package/ChartsLegend/ChartsLegend.js +2 -2
  11. package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +4 -1
  12. package/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
  13. package/ChartsTooltip/ChartsItemTooltipContent.d.ts +6 -0
  14. package/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
  15. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
  16. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
  17. package/ChartsTooltip/utils.d.ts +5 -1
  18. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
  19. package/ChartsXAxis/ChartsXAxis.js +7 -7
  20. package/ChartsYAxis/ChartsYAxis.js +9 -6
  21. package/Gauge/GaugeProvider.js +5 -5
  22. package/LineChart/AnimatedArea.js +6 -5
  23. package/LineChart/AnimatedLine.js +7 -5
  24. package/LineChart/AreaElement.d.ts +1 -0
  25. package/LineChart/AreaElement.js +4 -1
  26. package/LineChart/AreaPlot.js +7 -1
  27. package/LineChart/LineChart.js +32 -2
  28. package/LineChart/LineElement.d.ts +1 -0
  29. package/LineChart/LineElement.js +4 -1
  30. package/LineChart/LineHighlightPlot.js +4 -1
  31. package/LineChart/LinePlot.js +7 -1
  32. package/LineChart/MarkPlot.js +5 -5
  33. package/LineChart/getColor.d.ts +3 -0
  34. package/LineChart/getColor.js +31 -0
  35. package/PieChart/PieChart.js +32 -2
  36. package/PieChart/PiePlot.js +26 -6
  37. package/PieChart/formatter.js +4 -2
  38. package/PieChart/getColor.d.ts +2 -0
  39. package/PieChart/getColor.js +11 -0
  40. package/PieChart/getPieCoordinates.d.ts +7 -0
  41. package/PieChart/getPieCoordinates.js +25 -0
  42. package/PieChart/index.d.ts +1 -0
  43. package/PieChart/index.js +11 -0
  44. package/ResponsiveChartContainer/ResponsiveChartContainer.js +32 -2
  45. package/ScatterChart/Scatter.d.ts +1 -0
  46. package/ScatterChart/Scatter.js +6 -3
  47. package/ScatterChart/ScatterChart.js +32 -2
  48. package/ScatterChart/ScatterPlot.js +3 -0
  49. package/ScatterChart/getColor.d.ts +3 -0
  50. package/ScatterChart/getColor.js +31 -0
  51. package/SparkLineChart/SparkLineChart.js +15 -0
  52. package/context/CartesianContextProvider.d.ts +2 -2
  53. package/context/CartesianContextProvider.js +23 -8
  54. package/esm/BarChart/BarChart.js +32 -2
  55. package/esm/BarChart/BarPlot.js +13 -5
  56. package/esm/BarChart/extremums.js +1 -1
  57. package/esm/BarChart/getColor.js +27 -0
  58. package/esm/ChartContainer/ChartContainer.js +36 -4
  59. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  60. package/esm/ChartsClipPath/ChartsClipPath.js +2 -2
  61. package/esm/ChartsLegend/ChartsLegend.js +2 -2
  62. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
  63. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
  64. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
  65. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
  66. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
  67. package/esm/ChartsXAxis/ChartsXAxis.js +7 -7
  68. package/esm/ChartsYAxis/ChartsYAxis.js +9 -6
  69. package/esm/Gauge/GaugeProvider.js +5 -5
  70. package/esm/LineChart/AnimatedArea.js +6 -5
  71. package/esm/LineChart/AnimatedLine.js +7 -5
  72. package/esm/LineChart/AreaElement.js +4 -1
  73. package/esm/LineChart/AreaPlot.js +7 -1
  74. package/esm/LineChart/LineChart.js +32 -2
  75. package/esm/LineChart/LineElement.js +4 -1
  76. package/esm/LineChart/LineHighlightPlot.js +4 -1
  77. package/esm/LineChart/LinePlot.js +7 -1
  78. package/esm/LineChart/MarkPlot.js +5 -5
  79. package/esm/LineChart/getColor.js +25 -0
  80. package/esm/PieChart/PieChart.js +32 -2
  81. package/esm/PieChart/PiePlot.js +26 -6
  82. package/esm/PieChart/formatter.js +4 -2
  83. package/esm/PieChart/getColor.js +5 -0
  84. package/esm/PieChart/getPieCoordinates.js +19 -0
  85. package/esm/PieChart/index.js +2 -1
  86. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +32 -2
  87. package/esm/ScatterChart/Scatter.js +6 -3
  88. package/esm/ScatterChart/ScatterChart.js +32 -2
  89. package/esm/ScatterChart/ScatterPlot.js +3 -0
  90. package/esm/ScatterChart/getColor.js +25 -0
  91. package/esm/SparkLineChart/SparkLineChart.js +15 -0
  92. package/esm/context/CartesianContextProvider.js +23 -8
  93. package/esm/hooks/index.js +4 -1
  94. package/esm/hooks/useAxisEvents.js +7 -6
  95. package/esm/hooks/useChartId.js +8 -0
  96. package/esm/hooks/useSeries.js +64 -0
  97. package/esm/hooks/useSvgRef.js +9 -0
  98. package/esm/internals/colorGetter.js +22 -0
  99. package/esm/internals/colorScale.js +16 -0
  100. package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +96 -0
  101. package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +55 -0
  102. package/esm/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +41 -0
  103. package/esm/internals/components/ChartsAxesGradients/index.js +1 -0
  104. package/esm/models/colorMapping.js +1 -0
  105. package/esm/models/seriesType/index.js +6 -1
  106. package/hooks/index.d.ts +3 -0
  107. package/hooks/index.js +65 -1
  108. package/hooks/useAxisEvents.js +7 -6
  109. package/hooks/useChartId.d.ts +1 -0
  110. package/hooks/useChartId.js +16 -0
  111. package/hooks/useSeries.d.ts +45 -0
  112. package/hooks/useSeries.js +75 -0
  113. package/hooks/useSvgRef.d.ts +2 -0
  114. package/hooks/useSvgRef.js +17 -0
  115. package/hooks/useTicks.d.ts +1 -1
  116. package/index.js +1 -1
  117. package/internals/colorGetter.d.ts +5 -0
  118. package/internals/colorGetter.js +29 -0
  119. package/internals/colorScale.d.ts +5 -0
  120. package/internals/colorScale.js +24 -0
  121. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +3 -0
  122. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +105 -0
  123. package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.d.ts +13 -0
  124. package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +63 -0
  125. package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.d.ts +12 -0
  126. package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +48 -0
  127. package/internals/components/ChartsAxesGradients/index.d.ts +1 -0
  128. package/internals/components/ChartsAxesGradients/index.js +16 -0
  129. package/internals/defaultizeColor.d.ts +4 -4
  130. package/internals/defaultizeValueFormatter.d.ts +5 -5
  131. package/internals/getScale.d.ts +2 -2
  132. package/models/axis.d.ts +44 -4
  133. package/models/colorMapping.d.ts +45 -0
  134. package/models/colorMapping.js +5 -0
  135. package/models/index.d.ts +1 -1
  136. package/models/seriesType/common.d.ts +10 -2
  137. package/models/seriesType/index.d.ts +2 -0
  138. package/models/seriesType/index.js +17 -1
  139. package/modern/BarChart/BarChart.js +32 -2
  140. package/modern/BarChart/BarPlot.js +13 -5
  141. package/modern/BarChart/extremums.js +1 -1
  142. package/modern/BarChart/getColor.js +27 -0
  143. package/modern/ChartContainer/ChartContainer.js +36 -4
  144. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  145. package/modern/ChartsClipPath/ChartsClipPath.js +2 -2
  146. package/modern/ChartsLegend/ChartsLegend.js +2 -2
  147. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
  148. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
  149. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
  150. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
  151. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
  152. package/modern/ChartsXAxis/ChartsXAxis.js +7 -7
  153. package/modern/ChartsYAxis/ChartsYAxis.js +9 -6
  154. package/modern/Gauge/GaugeProvider.js +5 -5
  155. package/modern/LineChart/AnimatedArea.js +6 -5
  156. package/modern/LineChart/AnimatedLine.js +7 -5
  157. package/modern/LineChart/AreaElement.js +4 -1
  158. package/modern/LineChart/AreaPlot.js +7 -1
  159. package/modern/LineChart/LineChart.js +32 -2
  160. package/modern/LineChart/LineElement.js +4 -1
  161. package/modern/LineChart/LineHighlightPlot.js +4 -1
  162. package/modern/LineChart/LinePlot.js +7 -1
  163. package/modern/LineChart/MarkPlot.js +5 -5
  164. package/modern/LineChart/getColor.js +25 -0
  165. package/modern/PieChart/PieChart.js +32 -2
  166. package/modern/PieChart/PiePlot.js +26 -6
  167. package/modern/PieChart/formatter.js +4 -2
  168. package/modern/PieChart/getColor.js +5 -0
  169. package/modern/PieChart/getPieCoordinates.js +19 -0
  170. package/modern/PieChart/index.js +2 -1
  171. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +32 -2
  172. package/modern/ScatterChart/Scatter.js +6 -3
  173. package/modern/ScatterChart/ScatterChart.js +32 -2
  174. package/modern/ScatterChart/ScatterPlot.js +3 -0
  175. package/modern/ScatterChart/getColor.js +25 -0
  176. package/modern/SparkLineChart/SparkLineChart.js +15 -0
  177. package/modern/context/CartesianContextProvider.js +23 -8
  178. package/modern/hooks/index.js +4 -1
  179. package/modern/hooks/useAxisEvents.js +7 -6
  180. package/modern/hooks/useChartId.js +8 -0
  181. package/modern/hooks/useSeries.js +64 -0
  182. package/modern/hooks/useSvgRef.js +9 -0
  183. package/modern/index.js +1 -1
  184. package/modern/internals/colorGetter.js +22 -0
  185. package/modern/internals/colorScale.js +16 -0
  186. package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +96 -0
  187. package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +55 -0
  188. package/modern/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +41 -0
  189. package/modern/internals/components/ChartsAxesGradients/index.js +1 -0
  190. package/modern/models/colorMapping.js +1 -0
  191. package/modern/models/seriesType/index.js +6 -1
  192. package/package.json +1 -1
@@ -39,7 +39,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
39
39
  } | undefined;
40
40
  id?: import("../models/seriesType/common").SeriesId | undefined;
41
41
  color?: string | undefined;
42
- valueFormatter?: (<V extends import("../models/helpers").MakeOptional<import("../models/seriesType").PieValueType, "id">>(value: V) => string) | undefined;
42
+ valueFormatter?: import("../models/seriesType/common").SeriesValueFormatter<import("../models/helpers").MakeOptional<import("../models/seriesType").PieValueType, "id">> | undefined;
43
43
  highlightScope?: Partial<import("..").HighlightScope> | undefined;
44
44
  } | {
45
45
  type: "bar";
@@ -50,7 +50,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
50
50
  stackOffset?: import("..").StackOffsetType | undefined;
51
51
  id?: import("../models/seriesType/common").SeriesId | undefined;
52
52
  color: string;
53
- valueFormatter?: (<V_1 extends number | null>(value: V_1) => string) | undefined;
53
+ valueFormatter?: import("../models/seriesType/common").SeriesValueFormatter<number | null> | undefined;
54
54
  highlightScope?: Partial<import("..").HighlightScope> | undefined;
55
55
  xAxisKey?: string | undefined;
56
56
  yAxisKey?: string | undefined;
@@ -64,7 +64,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
64
64
  disableHover?: boolean | undefined;
65
65
  id?: import("../models/seriesType/common").SeriesId | undefined;
66
66
  color: string;
67
- valueFormatter?: (<V_2 extends import("../models/seriesType").ScatterValueType>(value: V_2) => string) | undefined;
67
+ valueFormatter?: import("../models/seriesType/common").SeriesValueFormatter<import("../models/seriesType").ScatterValueType> | undefined;
68
68
  highlightScope?: Partial<import("..").HighlightScope> | undefined;
69
69
  xAxisKey?: string | undefined;
70
70
  yAxisKey?: string | undefined;
@@ -82,7 +82,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
82
82
  stackOffset?: import("..").StackOffsetType | undefined;
83
83
  id?: import("../models/seriesType/common").SeriesId | undefined;
84
84
  color: string;
85
- valueFormatter?: (<V_1 extends number | null>(value: V_1) => string) | undefined;
85
+ valueFormatter?: import("../models/seriesType/common").SeriesValueFormatter<number | null> | undefined;
86
86
  highlightScope?: Partial<import("..").HighlightScope> | undefined;
87
87
  xAxisKey?: string | undefined;
88
88
  yAxisKey?: string | undefined;
@@ -1,7 +1,7 @@
1
- import { SeriesId } from '../models/seriesType/common';
2
- declare function defaultizeValueFormatter<ISeries extends {
3
- valueFormatter?: IFormatter;
4
- }, IFormatter extends (v: any) => string>(series: Record<SeriesId, ISeries>, defaultValueFormatter: IFormatter): Record<SeriesId, ISeries & {
5
- valueFormatter: IFormatter;
1
+ import { SeriesId, SeriesValueFormatter } from '../models/seriesType/common';
2
+ declare function defaultizeValueFormatter<TValue, ISeries extends {
3
+ valueFormatter?: SeriesValueFormatter<TValue>;
4
+ }>(series: Record<SeriesId, ISeries>, defaultValueFormatter: SeriesValueFormatter<TValue>): Record<SeriesId, ISeries & {
5
+ valueFormatter: SeriesValueFormatter<TValue>;
6
6
  }>;
7
7
  export default defaultizeValueFormatter;
@@ -1,2 +1,2 @@
1
- import { ContinuouseScaleName, D3ContinuouseScale } from '../models/axis';
2
- export declare function getScale(scaleType: ContinuouseScaleName, domain: any[], range: any[]): D3ContinuouseScale;
1
+ import { ContinuousScaleName, D3ContinuousScale } from '../models/axis';
2
+ export declare function getScale(scaleType: ContinuousScaleName, domain: any[], range: any[]): D3ContinuousScale;
package/models/axis.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  /// <reference types="react" />
2
- import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, ScalePoint } from 'd3-scale';
2
+ import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, ScalePoint, ScaleOrdinal, ScaleSequential, ScaleThreshold } from 'd3-scale';
3
3
  import { ChartsAxisClasses } from '../ChartsAxis/axisClasses';
4
4
  import type { TickParams } from '../hooks/useTicks';
5
5
  import { ChartsTextProps } from '../ChartsText';
6
+ import { ContinuousColorConfig, OrdinalColorConfig, PiecewiseColorConfig } from './colorMapping';
6
7
  export type AxisId = string | number;
7
8
  export type D3Scale<Domain extends {
8
9
  toString(): string;
9
10
  } = number | Date | string, Range = number, Output = number> = ScaleBand<Domain> | ScaleLogarithmic<Range, Output> | ScalePoint<Domain> | ScalePower<Range, Output> | ScaleTime<Range, Output> | ScaleLinear<Range, Output>;
10
- export type D3ContinuouseScale<Range = number, Output = number> = ScaleLogarithmic<Range, Output> | ScalePower<Range, Output> | ScaleTime<Range, Output> | ScaleLinear<Range, Output>;
11
+ export type D3ContinuousScale<Range = number, Output = number> = ScaleLogarithmic<Range, Output> | ScalePower<Range, Output> | ScaleTime<Range, Output> | ScaleLinear<Range, Output>;
11
12
  export interface ChartsAxisSlots {
12
13
  /**
13
14
  * Custom component for the axis main line.
@@ -126,7 +127,7 @@ export interface ChartsXAxisProps extends ChartsAxisProps {
126
127
  position?: 'top' | 'bottom';
127
128
  }
128
129
  export type ScaleName = 'linear' | 'band' | 'point' | 'log' | 'pow' | 'sqrt' | 'time' | 'utc';
129
- export type ContinuouseScaleName = 'linear' | 'log' | 'pow' | 'sqrt' | 'time' | 'utc';
130
+ export type ContinuousScaleName = 'linear' | 'log' | 'pow' | 'sqrt' | 'time' | 'utc';
130
131
  interface AxisScaleConfig {
131
132
  band: {
132
133
  scaleType: 'band';
@@ -143,37 +144,76 @@ interface AxisScaleConfig {
143
144
  * @default 0.1
144
145
  */
145
146
  barGapRatio: number;
147
+ colorMap?: OrdinalColorConfig | ContinuousColorConfig | PiecewiseColorConfig;
146
148
  } & Pick<TickParams, 'tickPlacement' | 'tickLabelPlacement'>;
147
149
  point: {
148
150
  scaleType: 'point';
149
151
  scale: ScalePoint<number | Date | string>;
152
+ colorMap?: OrdinalColorConfig | ContinuousColorConfig | PiecewiseColorConfig;
150
153
  };
151
154
  log: {
152
155
  scaleType: 'log';
153
156
  scale: ScaleLogarithmic<number, number>;
157
+ colorMap?: ContinuousColorConfig | PiecewiseColorConfig;
154
158
  };
155
159
  pow: {
156
160
  scaleType: 'pow';
157
161
  scale: ScalePower<number, number>;
162
+ colorMap?: ContinuousColorConfig | PiecewiseColorConfig;
158
163
  };
159
164
  sqrt: {
160
165
  scaleType: 'sqrt';
161
166
  scale: ScalePower<number, number>;
167
+ colorMap?: ContinuousColorConfig | PiecewiseColorConfig;
162
168
  };
163
169
  time: {
164
170
  scaleType: 'time';
165
171
  scale: ScaleTime<number, number>;
172
+ colorMap?: ContinuousColorConfig | PiecewiseColorConfig;
166
173
  };
167
174
  utc: {
168
175
  scaleType: 'utc';
169
176
  scale: ScaleTime<number, number>;
177
+ colorMap?: ContinuousColorConfig | PiecewiseColorConfig;
170
178
  };
171
179
  linear: {
172
180
  scaleType: 'linear';
173
181
  scale: ScaleLinear<number, number>;
182
+ colorMap?: ContinuousColorConfig | PiecewiseColorConfig;
183
+ };
184
+ }
185
+ interface AxisScaleComputedConfig {
186
+ band: {
187
+ colorScale?: ScaleOrdinal<string | number | Date, string, string | null> | ScaleOrdinal<number, string, string | null> | ScaleSequential<string, string | null> | ScaleThreshold<number | Date, string | null>;
188
+ };
189
+ point: {
190
+ colorScale?: ScaleOrdinal<string | number | Date, string, string | null> | ScaleOrdinal<number, string, string | null> | ScaleSequential<string, string | null> | ScaleThreshold<number | Date, string | null>;
191
+ };
192
+ log: {
193
+ colorScale?: ScaleSequential<string, string | null> | ScaleThreshold<number, string | null>;
194
+ };
195
+ pow: {
196
+ colorScale?: ScaleSequential<string, string | null> | ScaleThreshold<number, string | null>;
197
+ };
198
+ sqrt: {
199
+ colorScale?: ScaleSequential<string, string | null> | ScaleThreshold<number, string | null>;
200
+ };
201
+ time: {
202
+ colorScale?: ScaleSequential<string, string | null> | ScaleThreshold<number | Date, string | null>;
203
+ };
204
+ utc: {
205
+ colorScale?: ScaleSequential<string, string | null> | ScaleThreshold<number | Date, string | null>;
206
+ };
207
+ linear: {
208
+ colorScale?: ScaleSequential<string, string | null> | ScaleThreshold<number, string | null>;
174
209
  };
175
210
  }
176
211
  export type AxisValueFormatterContext = {
212
+ /**
213
+ * Location indicates where the value will be displayed.
214
+ * - `'tick'` The value is displayed on the axis ticks.
215
+ * - `'tooltip'` The value is displayed in the tooltip when hovering the chart.
216
+ */
177
217
  location: 'tick' | 'tooltip';
178
218
  };
179
219
  export type AxisConfig<S extends ScaleName = ScaleName, V = any> = {
@@ -215,7 +255,7 @@ export type AxisConfig<S extends ScaleName = ScaleName, V = any> = {
215
255
  */
216
256
  reverse?: boolean;
217
257
  } & Partial<ChartsXAxisProps | ChartsYAxisProps> & Partial<Omit<AxisScaleConfig[S], 'scale'>> & TickParams;
218
- export type AxisDefaultized<S extends ScaleName = ScaleName, V = any> = Omit<AxisConfig<S, V>, 'scaleType'> & AxisScaleConfig[S] & {
258
+ export type AxisDefaultized<S extends ScaleName = ScaleName, V = any> = Omit<AxisConfig<S, V>, 'scaleType'> & AxisScaleConfig[S] & AxisScaleComputedConfig[S] & {
219
259
  /**
220
260
  * An indication of the expected number of ticks.
221
261
  */
@@ -0,0 +1,45 @@
1
+ export interface ContinuousColorConfig<Value = number | Date> {
2
+ type: 'continuous';
3
+ /**
4
+ * The minimal value of the color scale.
5
+ * @default 0
6
+ */
7
+ min?: Value;
8
+ /**
9
+ * The maximal value of the color scale.
10
+ * @default 100
11
+ */
12
+ max?: Value;
13
+ /**
14
+ * The colors to render. Can either be and array with the extrem colors, or an interpolation function.
15
+ */
16
+ color: [string, string] | ((t: number) => string);
17
+ }
18
+ export interface PiecewiseColorConfig<Value = number | Date> {
19
+ type: 'piecewise';
20
+ /**
21
+ * The thresholds where color should change from one category to another.
22
+ */
23
+ thresholds: Value[];
24
+ /**
25
+ * The colors used for each band defined by `thresholds`.
26
+ * Should contain N+1 colors with N the number of thresholds.
27
+ */
28
+ colors: string[];
29
+ }
30
+ export interface OrdinalColorConfig<Value = number | Date | string> {
31
+ type: 'ordinal';
32
+ /**
33
+ * The value to map.
34
+ * If undefined, it will be integers from 0 to the number of colors.
35
+ */
36
+ values?: Value[];
37
+ /**
38
+ * The color palette.
39
+ */
40
+ colors: string[];
41
+ /**
42
+ * The color to use when an element is not part of the values.
43
+ */
44
+ unknownColor?: string;
45
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
package/models/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './seriesType';
2
2
  export * from './layout';
3
3
  export * from './stacking';
4
- export type { AxisConfig, ChartsYAxisProps, ChartsXAxisProps, ScaleName, ContinuouseScaleName, } from './axis';
4
+ export type { AxisConfig, ChartsYAxisProps, ChartsXAxisProps, ScaleName, ContinuousScaleName, } from './axis';
@@ -1,15 +1,23 @@
1
1
  import type { HighlightScope } from '../../context/HighlightProvider';
2
2
  import type { StackOffsetType, StackOrderType } from '../stacking';
3
3
  export type SeriesId = number | string;
4
+ export type SeriesValueFormatterContext = {
5
+ /**
6
+ * The index of the value in the data array.
7
+ */
8
+ dataIndex: number;
9
+ };
10
+ export type SeriesValueFormatter<TValue> = (value: TValue, context: SeriesValueFormatterContext) => string;
4
11
  export type CommonSeriesType<TValue> = {
5
12
  id?: SeriesId;
6
13
  color?: string;
7
14
  /**
8
15
  * Formatter used to render values in tooltip or other data display.
9
16
  * @param {TValue} value The series' value to render.
10
- * @returns {string} The string to dispaly.
17
+ * @param {SeriesValueFormatterContext} context The rendering context of the value.
18
+ * @returns {string} The string to display.
11
19
  */
12
- valueFormatter?: <V extends TValue>(value: V) => string;
20
+ valueFormatter?: SeriesValueFormatter<TValue>;
13
21
  highlightScope?: Partial<HighlightScope>;
14
22
  };
15
23
  export type CommonDefaultizedProps = 'id' | 'valueFormatter' | 'data';
@@ -14,3 +14,5 @@ export * from './bar';
14
14
  export * from './scatter';
15
15
  export * from './pie';
16
16
  export type { AllSeriesType, CartesianSeriesType, DefaultizedSeriesType, DefaultizedCartesianSeriesType, StackableSeriesType, };
17
+ export declare function isDefaultizedBarSeries(series: DefaultizedSeriesType): series is DefaultizedBarSeriesType;
18
+ export declare function isBarSeries(series: AllSeriesType): series is BarSeriesType;
@@ -3,9 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ isDefaultizedBarSeries: true,
8
+ isBarSeries: true
9
+ };
10
+ exports.isBarSeries = isBarSeries;
11
+ exports.isDefaultizedBarSeries = isDefaultizedBarSeries;
6
12
  var _line = require("./line");
7
13
  Object.keys(_line).forEach(function (key) {
8
14
  if (key === "default" || key === "__esModule") return;
15
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
9
16
  if (key in exports && exports[key] === _line[key]) return;
10
17
  Object.defineProperty(exports, key, {
11
18
  enumerable: true,
@@ -17,6 +24,7 @@ Object.keys(_line).forEach(function (key) {
17
24
  var _bar = require("./bar");
18
25
  Object.keys(_bar).forEach(function (key) {
19
26
  if (key === "default" || key === "__esModule") return;
27
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
20
28
  if (key in exports && exports[key] === _bar[key]) return;
21
29
  Object.defineProperty(exports, key, {
22
30
  enumerable: true,
@@ -28,6 +36,7 @@ Object.keys(_bar).forEach(function (key) {
28
36
  var _scatter = require("./scatter");
29
37
  Object.keys(_scatter).forEach(function (key) {
30
38
  if (key === "default" || key === "__esModule") return;
39
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
31
40
  if (key in exports && exports[key] === _scatter[key]) return;
32
41
  Object.defineProperty(exports, key, {
33
42
  enumerable: true,
@@ -39,6 +48,7 @@ Object.keys(_scatter).forEach(function (key) {
39
48
  var _pie = require("./pie");
40
49
  Object.keys(_pie).forEach(function (key) {
41
50
  if (key === "default" || key === "__esModule") return;
51
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
42
52
  if (key in exports && exports[key] === _pie[key]) return;
43
53
  Object.defineProperty(exports, key, {
44
54
  enumerable: true,
@@ -46,4 +56,10 @@ Object.keys(_pie).forEach(function (key) {
46
56
  return _pie[key];
47
57
  }
48
58
  });
49
- });
59
+ });
60
+ function isDefaultizedBarSeries(series) {
61
+ return series.type === 'bar';
62
+ }
63
+ function isBarSeries(series) {
64
+ return series.type === 'bar';
65
+ }
@@ -366,11 +366,26 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
366
366
  width: PropTypes.number,
367
367
  /**
368
368
  * The configuration of the x-axes.
369
- * If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
369
+ * If not provided, a default axis config is used.
370
370
  */
371
371
  xAxis: PropTypes.arrayOf(PropTypes.shape({
372
372
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
373
373
  classes: PropTypes.object,
374
+ colorMap: PropTypes.oneOfType([PropTypes.shape({
375
+ color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
376
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
377
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
378
+ type: PropTypes.oneOf(['continuous']).isRequired
379
+ }), PropTypes.shape({
380
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
381
+ thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
382
+ type: PropTypes.oneOf(['piecewise']).isRequired
383
+ }), PropTypes.shape({
384
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
385
+ type: PropTypes.oneOf(['ordinal']).isRequired,
386
+ unknownColor: PropTypes.string,
387
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
388
+ })]),
374
389
  data: PropTypes.array,
375
390
  dataKey: PropTypes.string,
376
391
  disableLine: PropTypes.bool,
@@ -403,11 +418,26 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
403
418
  })),
404
419
  /**
405
420
  * The configuration of the y-axes.
406
- * If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
421
+ * If not provided, a default axis config is used.
407
422
  */
408
423
  yAxis: PropTypes.arrayOf(PropTypes.shape({
409
424
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
410
425
  classes: PropTypes.object,
426
+ colorMap: PropTypes.oneOfType([PropTypes.shape({
427
+ color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
428
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
429
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
430
+ type: PropTypes.oneOf(['continuous']).isRequired
431
+ }), PropTypes.shape({
432
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
433
+ thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
434
+ type: PropTypes.oneOf(['piecewise']).isRequired
435
+ }), PropTypes.shape({
436
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
437
+ type: PropTypes.oneOf(['ordinal']).isRequired,
438
+ unknownColor: PropTypes.string,
439
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
440
+ })]),
411
441
  data: PropTypes.array,
412
442
  dataKey: PropTypes.string,
413
443
  disableLine: PropTypes.bool,
@@ -7,9 +7,10 @@ import { useTransition } from '@react-spring/web';
7
7
  import { SeriesContext } from '../context/SeriesContextProvider';
8
8
  import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { BarElement } from './BarElement';
10
- import { isBandScaleConfig } from '../models/axis';
10
+ import { isBandScaleConfig, isPointScaleConfig } from '../models/axis';
11
11
  import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
12
- import { jsx as _jsx } from "react/jsx-runtime";
12
+ import getColor from './getColor';
13
+
13
14
  /**
14
15
  * Solution of the equations
15
16
  * W = barWidth * N + offset * (N-1)
@@ -19,6 +20,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
19
20
  * @param gapRatio The ratio of the gap between bars over the bar width.
20
21
  * @returns The bar width and the offset between bars.
21
22
  */
23
+ import { jsx as _jsx } from "react/jsx-runtime";
22
24
  function getBandSize({
23
25
  bandWidth: W,
24
26
  numberOfGroups: N,
@@ -74,6 +76,9 @@ const useAggregatedData = () => {
74
76
  throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud have data property.`);
75
77
  }
76
78
  baseScaleConfig = xAxisConfig;
79
+ if (isBandScaleConfig(yAxisConfig) || isPointScaleConfig(yAxisConfig)) {
80
+ throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud be a continuous type to display the bar series of id "${seriesId}".`);
81
+ }
77
82
  } else {
78
83
  if (!isBandScaleConfig(yAxisConfig)) {
79
84
  throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud be of type "band" to display the bar series of id "${seriesId}".`);
@@ -82,9 +87,13 @@ const useAggregatedData = () => {
82
87
  throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud have data property.`);
83
88
  }
84
89
  baseScaleConfig = yAxisConfig;
90
+ if (isBandScaleConfig(xAxisConfig) || isPointScaleConfig(xAxisConfig)) {
91
+ throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud be a continuous type to display the bar series of id "${seriesId}".`);
92
+ }
85
93
  }
86
94
  const xScale = xAxisConfig.scale;
87
95
  const yScale = yAxisConfig.scale;
96
+ const colorGetter = getColor(series[seriesId], xAxis[xAxisKey], yAxis[yAxisKey]);
88
97
  const bandWidth = baseScaleConfig.scale.bandwidth();
89
98
  const {
90
99
  barWidth,
@@ -96,8 +105,7 @@ const useAggregatedData = () => {
96
105
  });
97
106
  const barOffset = groupIndex * (barWidth + offset);
98
107
  const {
99
- stackedData,
100
- color
108
+ stackedData
101
109
  } = series[seriesId];
102
110
  return stackedData.map((values, dataIndex) => {
103
111
  const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
@@ -113,7 +121,7 @@ const useAggregatedData = () => {
113
121
  yOrigin: yScale(0),
114
122
  height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
115
123
  width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
116
- color,
124
+ color: colorGetter(dataIndex),
117
125
  highlightScope: series[seriesId].highlightScope
118
126
  };
119
127
  });
@@ -13,7 +13,7 @@ const getValueExtremum = params => {
13
13
  isDefaultAxis
14
14
  } = params;
15
15
  return Object.keys(series).filter(seriesId => series[seriesId].yAxisKey === axis.id || isDefaultAxis && series[seriesId].yAxisKey === undefined).reduce((acc, seriesId) => {
16
- const [seriesMin, seriesMax] = series[seriesId].stackedData.reduce((seriesAcc, values) => [Math.min(...values, ...(seriesAcc[0] === null ? [] : [seriesAcc[0]])), Math.max(...values, ...(seriesAcc[1] === null ? [] : [seriesAcc[1]]))], series[seriesId].stackedData[0]);
16
+ const [seriesMin, seriesMax] = series[seriesId].stackedData?.reduce((seriesAcc, values) => [Math.min(...values, ...(seriesAcc[0] === null ? [] : [seriesAcc[0]])), Math.max(...values, ...(seriesAcc[1] === null ? [] : [seriesAcc[1]]))], series[seriesId].stackedData[0]) ?? [null, null];
17
17
  return [acc[0] === null ? seriesMin : Math.min(seriesMin, acc[0]), acc[1] === null ? seriesMax : Math.max(seriesMax, acc[1])];
18
18
  }, [null, null]);
19
19
  };
@@ -0,0 +1,27 @@
1
+ export default function getColor(series, xAxis, yAxis) {
2
+ const verticalLayout = series.layout === 'vertical';
3
+ const bandColorScale = verticalLayout ? xAxis.colorScale : yAxis.colorScale;
4
+ const valueColorScale = verticalLayout ? yAxis.colorScale : xAxis.colorScale;
5
+ const bandValues = verticalLayout ? xAxis.data : yAxis.data;
6
+ if (valueColorScale) {
7
+ return dataIndex => {
8
+ const value = series.data[dataIndex];
9
+ const color = value === null ? series.color : valueColorScale(value);
10
+ if (color === null) {
11
+ return series.color;
12
+ }
13
+ return color;
14
+ };
15
+ }
16
+ if (bandColorScale) {
17
+ return dataIndex => {
18
+ const value = bandValues[dataIndex];
19
+ const color = value === null ? series.color : bandColorScale(value);
20
+ if (color === null) {
21
+ return series.color;
22
+ }
23
+ return color;
24
+ };
25
+ }
26
+ return () => series.color;
27
+ }
@@ -8,7 +8,9 @@ import { useReducedMotion } from '../hooks/useReducedMotion';
8
8
  import { ChartsSurface } from '../ChartsSurface';
9
9
  import { CartesianContextProvider } from '../context/CartesianContextProvider';
10
10
  import { HighlightProvider } from '../context/HighlightProvider';
11
+ import { ChartsAxesGradients } from '../internals/components/ChartsAxesGradients';
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
12
14
  const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(props, ref) {
13
15
  const {
14
16
  width,
@@ -44,7 +46,7 @@ const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(pro
44
46
  dataset: dataset,
45
47
  children: /*#__PURE__*/_jsx(InteractionProvider, {
46
48
  children: /*#__PURE__*/_jsx(HighlightProvider, {
47
- children: /*#__PURE__*/_jsx(ChartsSurface, {
49
+ children: /*#__PURE__*/_jsxs(ChartsSurface, {
48
50
  width: width,
49
51
  height: height,
50
52
  ref: handleRef,
@@ -52,7 +54,7 @@ const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(pro
52
54
  title: title,
53
55
  desc: desc,
54
56
  disableAxisListener: disableAxisListener,
55
- children: children
57
+ children: [/*#__PURE__*/_jsx(ChartsAxesGradients, {}), children]
56
58
  })
57
59
  })
58
60
  })
@@ -119,11 +121,26 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
119
121
  width: PropTypes.number.isRequired,
120
122
  /**
121
123
  * The configuration of the x-axes.
122
- * If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
124
+ * If not provided, a default axis config is used.
123
125
  */
124
126
  xAxis: PropTypes.arrayOf(PropTypes.shape({
125
127
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
126
128
  classes: PropTypes.object,
129
+ colorMap: PropTypes.oneOfType([PropTypes.shape({
130
+ color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
131
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
132
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
133
+ type: PropTypes.oneOf(['continuous']).isRequired
134
+ }), PropTypes.shape({
135
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
136
+ thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
137
+ type: PropTypes.oneOf(['piecewise']).isRequired
138
+ }), PropTypes.shape({
139
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
140
+ type: PropTypes.oneOf(['ordinal']).isRequired,
141
+ unknownColor: PropTypes.string,
142
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
143
+ })]),
127
144
  data: PropTypes.array,
128
145
  dataKey: PropTypes.string,
129
146
  disableLine: PropTypes.bool,
@@ -156,11 +173,26 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
156
173
  })),
157
174
  /**
158
175
  * The configuration of the y-axes.
159
- * If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
176
+ * If not provided, a default axis config is used.
160
177
  */
161
178
  yAxis: PropTypes.arrayOf(PropTypes.shape({
162
179
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
163
180
  classes: PropTypes.object,
181
+ colorMap: PropTypes.oneOfType([PropTypes.shape({
182
+ color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
183
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
184
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
185
+ type: PropTypes.oneOf(['continuous']).isRequired
186
+ }), PropTypes.shape({
187
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
188
+ thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
189
+ type: PropTypes.oneOf(['piecewise']).isRequired
190
+ }), PropTypes.shape({
191
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
192
+ type: PropTypes.oneOf(['ordinal']).isRequired,
193
+ unknownColor: PropTypes.string,
194
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
195
+ })]),
164
196
  data: PropTypes.array,
165
197
  dataKey: PropTypes.string,
166
198
  disableLine: PropTypes.bool,
@@ -6,12 +6,12 @@ import { ChartsXAxis } from '../ChartsXAxis';
6
6
  import { ChartsYAxis } from '../ChartsYAxis';
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
8
  import { jsxs as _jsxs } from "react/jsx-runtime";
9
- const getAxisId = propsValue => {
9
+ const getAxisId = (propsValue, defaultAxisId) => {
10
10
  if (propsValue == null) {
11
11
  return null;
12
12
  }
13
13
  if (typeof propsValue === 'object') {
14
- return propsValue.axisId ?? null;
14
+ return propsValue.axisId ?? defaultAxisId ?? null;
15
15
  }
16
16
  return propsValue;
17
17
  };
@@ -55,8 +55,8 @@ function ChartsAxis(props) {
55
55
 
56
56
  const leftId = getAxisId(leftAxis === undefined ? yAxisIds[0] : leftAxis);
57
57
  const bottomId = getAxisId(bottomAxis === undefined ? xAxisIds[0] : bottomAxis);
58
- const topId = getAxisId(topAxis);
59
- const rightId = getAxisId(rightAxis);
58
+ const topId = getAxisId(topAxis, xAxisIds[0]);
59
+ const rightId = getAxisId(rightAxis, yAxisIds[0]);
60
60
  if (topId !== null && !xAxis[topId]) {
61
61
  throw Error([`MUI X Charts: id used for top axis "${topId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
62
62
  }
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import PropTypes from 'prop-types';
4
- import { DrawingContext } from '../context/DrawingProvider';
4
+ import { useDrawingArea } from '../hooks/useDrawingArea';
5
5
  import { jsx as _jsx } from "react/jsx-runtime";
6
6
  /**
7
7
  * API:
@@ -18,7 +18,7 @@ function ChartsClipPath(props) {
18
18
  top,
19
19
  width,
20
20
  height
21
- } = React.useContext(DrawingContext);
21
+ } = useDrawingArea();
22
22
  const offset = _extends({
23
23
  top: 0,
24
24
  right: 0,
@@ -4,11 +4,11 @@ import PropTypes from 'prop-types';
4
4
  import { useSlotProps } from '@mui/base/utils';
5
5
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
6
6
  import { useThemeProps, useTheme } from '@mui/material/styles';
7
- import { DrawingContext } from '../context/DrawingProvider';
8
7
  import { getSeriesToDisplay } from './utils';
9
8
  import { SeriesContext } from '../context/SeriesContextProvider';
10
9
  import { getLegendUtilityClass } from './chartsLegendClasses';
11
10
  import { DefaultChartsLegend } from './DefaultChartsLegend';
11
+ import { useDrawingArea } from '../hooks';
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  const useUtilityClasses = ownerState => {
14
14
  const {
@@ -46,7 +46,7 @@ function ChartsLegend(inProps) {
46
46
  const classes = useUtilityClasses(_extends({}, props, {
47
47
  theme
48
48
  }));
49
- const drawingArea = React.useContext(DrawingContext);
49
+ const drawingArea = useDrawingArea();
50
50
  const series = React.useContext(SeriesContext);
51
51
  const seriesToDisplay = getSeriesToDisplay(series);
52
52
  const ChartLegendRender = slots?.legend ?? DefaultChartsLegend;
@@ -6,6 +6,7 @@ import { SeriesContext } from '../context/SeriesContextProvider';
6
6
  import { CartesianContext } from '../context/CartesianContextProvider';
7
7
  import { DefaultChartsAxisTooltipContent } from './DefaultChartsAxisTooltipContent';
8
8
  import { isCartesianSeriesType } from './utils';
9
+ import colorGetter from '../internals/colorGetter';
9
10
  import { jsx as _jsx } from "react/jsx-runtime";
10
11
  function ChartsAxisTooltipContent(props) {
11
12
  const {
@@ -33,12 +34,16 @@ function ChartsAxisTooltipContent(props) {
33
34
  const item = series[seriesType].series[seriesId];
34
35
  const axisKey = isXaxis ? item.xAxisKey : item.yAxisKey;
35
36
  if (axisKey === undefined || axisKey === USED_AXIS_ID) {
36
- rep.push(series[seriesType].series[seriesId]);
37
+ const seriesToAdd = series[seriesType].series[seriesId];
38
+ const color = colorGetter(seriesToAdd, xAxis[seriesToAdd.xAxisKey ?? xAxisIds[0]], yAxis[seriesToAdd.yAxisKey ?? yAxisIds[0]]);
39
+ rep.push(_extends({}, seriesToAdd, {
40
+ getColor: color
41
+ }));
37
42
  }
38
43
  });
39
44
  });
40
45
  return rep;
41
- }, [USED_AXIS_ID, isXaxis, series]);
46
+ }, [USED_AXIS_ID, isXaxis, series, xAxis, xAxisIds, yAxis, yAxisIds]);
42
47
  const relevantAxis = React.useMemo(() => {
43
48
  return isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID];
44
49
  }, [USED_AXIS_ID, isXaxis, xAxis, yAxis]);