@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.
- package/BarChart/BarChart.js +32 -2
- package/BarChart/BarPlot.js +12 -5
- package/BarChart/extremums.js +1 -1
- package/BarChart/getColor.d.ts +3 -0
- package/BarChart/getColor.js +33 -0
- package/CHANGELOG.md +211 -0
- package/ChartContainer/ChartContainer.js +35 -4
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsClipPath/ChartsClipPath.js +2 -2
- package/ChartsLegend/ChartsLegend.js +2 -2
- package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +4 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
- package/ChartsTooltip/ChartsItemTooltipContent.d.ts +6 -0
- package/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
- package/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
- package/ChartsTooltip/utils.d.ts +5 -1
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
- package/ChartsXAxis/ChartsXAxis.js +7 -7
- package/ChartsYAxis/ChartsYAxis.js +9 -6
- package/Gauge/GaugeProvider.js +5 -5
- package/LineChart/AnimatedArea.js +6 -5
- package/LineChart/AnimatedLine.js +7 -5
- package/LineChart/AreaElement.d.ts +1 -0
- package/LineChart/AreaElement.js +4 -1
- package/LineChart/AreaPlot.js +7 -1
- package/LineChart/LineChart.js +32 -2
- package/LineChart/LineElement.d.ts +1 -0
- package/LineChart/LineElement.js +4 -1
- package/LineChart/LineHighlightPlot.js +4 -1
- package/LineChart/LinePlot.js +7 -1
- package/LineChart/MarkPlot.js +5 -5
- package/LineChart/getColor.d.ts +3 -0
- package/LineChart/getColor.js +31 -0
- package/PieChart/PieChart.js +32 -2
- package/PieChart/PiePlot.js +26 -6
- package/PieChart/formatter.js +4 -2
- package/PieChart/getColor.d.ts +2 -0
- package/PieChart/getColor.js +11 -0
- package/PieChart/getPieCoordinates.d.ts +7 -0
- package/PieChart/getPieCoordinates.js +25 -0
- package/PieChart/index.d.ts +1 -0
- package/PieChart/index.js +11 -0
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +32 -2
- package/ScatterChart/Scatter.d.ts +1 -0
- package/ScatterChart/Scatter.js +6 -3
- package/ScatterChart/ScatterChart.js +32 -2
- package/ScatterChart/ScatterPlot.js +3 -0
- package/ScatterChart/getColor.d.ts +3 -0
- package/ScatterChart/getColor.js +31 -0
- package/SparkLineChart/SparkLineChart.js +15 -0
- package/context/CartesianContextProvider.d.ts +2 -2
- package/context/CartesianContextProvider.js +23 -8
- package/esm/BarChart/BarChart.js +32 -2
- package/esm/BarChart/BarPlot.js +13 -5
- package/esm/BarChart/extremums.js +1 -1
- package/esm/BarChart/getColor.js +27 -0
- package/esm/ChartContainer/ChartContainer.js +36 -4
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsClipPath/ChartsClipPath.js +2 -2
- package/esm/ChartsLegend/ChartsLegend.js +2 -2
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
- package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
- package/esm/ChartsXAxis/ChartsXAxis.js +7 -7
- package/esm/ChartsYAxis/ChartsYAxis.js +9 -6
- package/esm/Gauge/GaugeProvider.js +5 -5
- package/esm/LineChart/AnimatedArea.js +6 -5
- package/esm/LineChart/AnimatedLine.js +7 -5
- package/esm/LineChart/AreaElement.js +4 -1
- package/esm/LineChart/AreaPlot.js +7 -1
- package/esm/LineChart/LineChart.js +32 -2
- package/esm/LineChart/LineElement.js +4 -1
- package/esm/LineChart/LineHighlightPlot.js +4 -1
- package/esm/LineChart/LinePlot.js +7 -1
- package/esm/LineChart/MarkPlot.js +5 -5
- package/esm/LineChart/getColor.js +25 -0
- package/esm/PieChart/PieChart.js +32 -2
- package/esm/PieChart/PiePlot.js +26 -6
- package/esm/PieChart/formatter.js +4 -2
- package/esm/PieChart/getColor.js +5 -0
- package/esm/PieChart/getPieCoordinates.js +19 -0
- package/esm/PieChart/index.js +2 -1
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +32 -2
- package/esm/ScatterChart/Scatter.js +6 -3
- package/esm/ScatterChart/ScatterChart.js +32 -2
- package/esm/ScatterChart/ScatterPlot.js +3 -0
- package/esm/ScatterChart/getColor.js +25 -0
- package/esm/SparkLineChart/SparkLineChart.js +15 -0
- package/esm/context/CartesianContextProvider.js +23 -8
- package/esm/hooks/index.js +4 -1
- package/esm/hooks/useAxisEvents.js +7 -6
- package/esm/hooks/useChartId.js +8 -0
- package/esm/hooks/useSeries.js +64 -0
- package/esm/hooks/useSvgRef.js +9 -0
- package/esm/internals/colorGetter.js +22 -0
- package/esm/internals/colorScale.js +16 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +96 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +55 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +41 -0
- package/esm/internals/components/ChartsAxesGradients/index.js +1 -0
- package/esm/models/colorMapping.js +1 -0
- package/esm/models/seriesType/index.js +6 -1
- package/hooks/index.d.ts +3 -0
- package/hooks/index.js +65 -1
- package/hooks/useAxisEvents.js +7 -6
- package/hooks/useChartId.d.ts +1 -0
- package/hooks/useChartId.js +16 -0
- package/hooks/useSeries.d.ts +45 -0
- package/hooks/useSeries.js +75 -0
- package/hooks/useSvgRef.d.ts +2 -0
- package/hooks/useSvgRef.js +17 -0
- package/hooks/useTicks.d.ts +1 -1
- package/index.js +1 -1
- package/internals/colorGetter.d.ts +5 -0
- package/internals/colorGetter.js +29 -0
- package/internals/colorScale.d.ts +5 -0
- package/internals/colorScale.js +24 -0
- package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +3 -0
- package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +105 -0
- package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.d.ts +13 -0
- package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +63 -0
- package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.d.ts +12 -0
- package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +48 -0
- package/internals/components/ChartsAxesGradients/index.d.ts +1 -0
- package/internals/components/ChartsAxesGradients/index.js +16 -0
- package/internals/defaultizeColor.d.ts +4 -4
- package/internals/defaultizeValueFormatter.d.ts +5 -5
- package/internals/getScale.d.ts +2 -2
- package/models/axis.d.ts +44 -4
- package/models/colorMapping.d.ts +45 -0
- package/models/colorMapping.js +5 -0
- package/models/index.d.ts +1 -1
- package/models/seriesType/common.d.ts +10 -2
- package/models/seriesType/index.d.ts +2 -0
- package/models/seriesType/index.js +17 -1
- package/modern/BarChart/BarChart.js +32 -2
- package/modern/BarChart/BarPlot.js +13 -5
- package/modern/BarChart/extremums.js +1 -1
- package/modern/BarChart/getColor.js +27 -0
- package/modern/ChartContainer/ChartContainer.js +36 -4
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsClipPath/ChartsClipPath.js +2 -2
- package/modern/ChartsLegend/ChartsLegend.js +2 -2
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
- package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
- package/modern/ChartsXAxis/ChartsXAxis.js +7 -7
- package/modern/ChartsYAxis/ChartsYAxis.js +9 -6
- package/modern/Gauge/GaugeProvider.js +5 -5
- package/modern/LineChart/AnimatedArea.js +6 -5
- package/modern/LineChart/AnimatedLine.js +7 -5
- package/modern/LineChart/AreaElement.js +4 -1
- package/modern/LineChart/AreaPlot.js +7 -1
- package/modern/LineChart/LineChart.js +32 -2
- package/modern/LineChart/LineElement.js +4 -1
- package/modern/LineChart/LineHighlightPlot.js +4 -1
- package/modern/LineChart/LinePlot.js +7 -1
- package/modern/LineChart/MarkPlot.js +5 -5
- package/modern/LineChart/getColor.js +25 -0
- package/modern/PieChart/PieChart.js +32 -2
- package/modern/PieChart/PiePlot.js +26 -6
- package/modern/PieChart/formatter.js +4 -2
- package/modern/PieChart/getColor.js +5 -0
- package/modern/PieChart/getPieCoordinates.js +19 -0
- package/modern/PieChart/index.js +2 -1
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +32 -2
- package/modern/ScatterChart/Scatter.js +6 -3
- package/modern/ScatterChart/ScatterChart.js +32 -2
- package/modern/ScatterChart/ScatterPlot.js +3 -0
- package/modern/ScatterChart/getColor.js +25 -0
- package/modern/SparkLineChart/SparkLineChart.js +15 -0
- package/modern/context/CartesianContextProvider.js +23 -8
- package/modern/hooks/index.js +4 -1
- package/modern/hooks/useAxisEvents.js +7 -6
- package/modern/hooks/useChartId.js +8 -0
- package/modern/hooks/useSeries.js +64 -0
- package/modern/hooks/useSvgRef.js +9 -0
- package/modern/index.js +1 -1
- package/modern/internals/colorGetter.js +22 -0
- package/modern/internals/colorScale.js +16 -0
- package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +96 -0
- package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +55 -0
- package/modern/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +41 -0
- package/modern/internals/components/ChartsAxesGradients/index.js +1 -0
- package/modern/models/colorMapping.js +1 -0
- package/modern/models/seriesType/index.js +6 -1
- 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?: (<
|
|
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?: (<
|
|
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?: (<
|
|
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?: (<
|
|
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?:
|
|
4
|
-
}
|
|
5
|
-
valueFormatter:
|
|
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;
|
package/internals/getScale.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function getScale(scaleType:
|
|
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
|
|
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
|
|
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
|
+
}
|
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,
|
|
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
|
-
* @
|
|
17
|
+
* @param {SeriesValueFormatterContext} context The rendering context of the value.
|
|
18
|
+
* @returns {string} The string to display.
|
|
11
19
|
*/
|
|
12
|
-
valueFormatter?: <
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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__*/
|
|
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
|
|
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
|
|
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 {
|
|
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
|
-
} =
|
|
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 =
|
|
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
|
-
|
|
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]);
|