@mui/x-charts 7.2.0 → 7.3.1
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.d.ts +1 -0
- package/BarChart/BarChart.js +40 -99
- package/BarChart/BarElement.d.ts +63 -62
- package/BarChart/BarElement.js +1 -2
- package/BarChart/BarPlot.js +14 -7
- package/BarChart/getColor.d.ts +3 -0
- package/BarChart/getColor.js +33 -0
- package/CHANGELOG.md +204 -2
- package/ChartContainer/ChartContainer.js +38 -5
- package/ChartsAxis/ChartsAxis.js +11 -103
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
- package/ChartsClipPath/ChartsClipPath.js +3 -3
- package/ChartsGrid/ChartsGrid.js +1 -1
- package/ChartsLegend/ChartsLegend.js +3 -3
- package/ChartsLegend/DefaultChartsLegend.js +1 -1
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +1 -1
- package/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
- package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/ChartsSurface.js +1 -1
- package/ChartsText/ChartsText.js +1 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +4 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +21 -3
- package/ChartsTooltip/ChartsItemTooltipContent.d.ts +6 -0
- package/ChartsTooltip/ChartsItemTooltipContent.js +32 -2
- package/ChartsTooltip/ChartsTooltip.js +1 -1
- package/ChartsTooltip/ChartsTooltipTable.d.ts +3 -7
- package/ChartsTooltip/ChartsTooltipTable.js +8 -9
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -7
- package/ChartsTooltip/DefaultChartsItemTooltipContent.js +15 -8
- package/ChartsTooltip/utils.d.ts +5 -1
- package/ChartsTooltip/utils.js +1 -1
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +7 -7
- package/ChartsXAxis/ChartsXAxis.js +3 -3
- package/ChartsYAxis/ChartsYAxis.js +3 -3
- package/Gauge/Gauge.js +1 -1
- package/Gauge/GaugeContainer.js +1 -1
- package/Gauge/GaugeProvider.js +6 -6
- package/Gauge/GaugeReferenceArc.js +1 -1
- package/Gauge/GaugeValueArc.js +1 -1
- package/Gauge/GaugeValueText.js +1 -1
- package/LineChart/AnimatedArea.d.ts +63 -62
- package/LineChart/AnimatedArea.js +7 -6
- package/LineChart/AnimatedLine.d.ts +63 -62
- package/LineChart/AnimatedLine.js +8 -6
- package/LineChart/AreaElement.d.ts +1 -0
- package/LineChart/AreaElement.js +5 -2
- package/LineChart/AreaPlot.js +8 -2
- package/LineChart/LineChart.d.ts +1 -0
- package/LineChart/LineChart.js +40 -99
- package/LineChart/LineElement.d.ts +1 -0
- package/LineChart/LineElement.js +5 -2
- package/LineChart/LineHighlightElement.js +1 -1
- package/LineChart/LineHighlightPlot.js +5 -2
- package/LineChart/LinePlot.js +8 -2
- package/LineChart/MarkElement.js +1 -1
- package/LineChart/MarkPlot.js +6 -6
- package/LineChart/getColor.d.ts +3 -0
- package/LineChart/getColor.js +31 -0
- package/PieChart/PieArc.d.ts +1 -0
- package/PieChart/PieArc.js +1 -1
- package/PieChart/PieArcLabel.d.ts +1 -0
- package/PieChart/PieArcLabel.js +1 -1
- package/PieChart/PieArcLabelPlot.js +1 -1
- package/PieChart/PieArcPlot.js +1 -1
- package/PieChart/PieChart.d.ts +1 -0
- package/PieChart/PieChart.js +40 -99
- package/PieChart/PiePlot.js +27 -7
- package/PieChart/dataTransform/transition.d.ts +1 -0
- package/PieChart/dataTransform/useTransformData.js +1 -1
- 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 +35 -3
- package/ResponsiveChartContainer/useChartContainerDimensions.js +1 -1
- package/ScatterChart/Scatter.d.ts +1 -0
- package/ScatterChart/Scatter.js +7 -4
- package/ScatterChart/ScatterChart.d.ts +3 -1
- package/ScatterChart/ScatterChart.js +95 -126
- package/ScatterChart/ScatterPlot.js +11 -1
- package/ScatterChart/getColor.d.ts +4 -0
- package/ScatterChart/getColor.js +48 -0
- package/SparkLineChart/SparkLineChart.js +16 -1
- package/context/CartesianContextProvider.d.ts +4 -3
- package/context/CartesianContextProvider.js +24 -9
- package/context/DrawingProvider.js +1 -1
- package/context/HighlightProvider.js +1 -1
- package/context/InteractionProvider.js +1 -1
- package/context/SeriesContextProvider.js +1 -1
- package/context/ZAxisContextProvider.d.ts +33 -0
- package/context/ZAxisContextProvider.js +98 -0
- package/context/index.d.ts +2 -0
- package/context/index.js +8 -1
- package/esm/BarChart/BarChart.js +40 -100
- package/esm/BarChart/BarElement.js +0 -1
- package/esm/BarChart/BarPlot.js +15 -7
- package/esm/BarChart/getColor.js +27 -0
- package/esm/ChartContainer/ChartContainer.js +38 -5
- package/esm/ChartsAxis/ChartsAxis.js +11 -104
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -2
- package/esm/ChartsClipPath/ChartsClipPath.js +2 -2
- package/esm/ChartsGrid/ChartsGrid.js +1 -2
- package/esm/ChartsLegend/ChartsLegend.js +2 -2
- package/esm/ChartsLegend/DefaultChartsLegend.js +1 -2
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -2
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -2
- package/esm/ChartsSurface.js +1 -2
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +20 -2
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +31 -1
- package/esm/ChartsTooltip/ChartsTooltipTable.js +8 -8
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -8
- package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +15 -9
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
- package/esm/ChartsXAxis/ChartsXAxis.js +3 -4
- package/esm/ChartsYAxis/ChartsYAxis.js +3 -4
- package/esm/Gauge/Gauge.js +1 -2
- package/esm/Gauge/GaugeProvider.js +5 -5
- package/esm/LineChart/AnimatedArea.js +7 -7
- package/esm/LineChart/AnimatedLine.js +8 -7
- package/esm/LineChart/AreaElement.js +4 -1
- package/esm/LineChart/AreaPlot.js +7 -1
- package/esm/LineChart/LineChart.js +40 -100
- 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 +40 -100
- package/esm/PieChart/PiePlot.js +27 -8
- 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 +34 -2
- package/esm/ScatterChart/Scatter.js +6 -3
- package/esm/ScatterChart/ScatterChart.js +95 -127
- package/esm/ScatterChart/ScatterPlot.js +10 -0
- package/esm/ScatterChart/getColor.js +42 -0
- package/esm/SparkLineChart/SparkLineChart.js +16 -2
- package/esm/context/CartesianContextProvider.js +23 -8
- package/esm/context/ZAxisContextProvider.js +89 -0
- package/esm/context/index.js +1 -1
- 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 +95 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +55 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +40 -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/esm/models/z-axis.js +1 -0
- package/hooks/index.d.ts +3 -0
- package/hooks/index.js +65 -1
- package/hooks/useAxisEvents.js +8 -7
- package/hooks/useChartDimensions.js +1 -1
- package/hooks/useChartId.d.ts +1 -0
- package/hooks/useChartId.js +16 -0
- package/hooks/useDrawingArea.js +1 -1
- package/hooks/useInteractionItemProps.js +1 -1
- package/hooks/useMounted.js +1 -1
- package/hooks/useScale.js +1 -1
- 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.js +1 -1
- package/index.js +1 -1
- package/internals/colorGetter.d.ts +7 -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 +5 -4
- package/internals/defaultizeValueFormatter.d.ts +5 -5
- package/internals/getScale.d.ts +2 -2
- package/internals/useAnimatedPath.d.ts +1 -0
- package/internals/useAnimatedPath.js +1 -1
- package/models/axis.d.ts +44 -4
- package/models/colorMapping.d.ts +46 -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/models/seriesType/pie.d.ts +5 -0
- package/models/seriesType/scatter.d.ts +5 -0
- package/models/z-axis.d.ts +14 -0
- package/models/z-axis.js +5 -0
- package/modern/BarChart/BarChart.js +40 -100
- package/modern/BarChart/BarElement.js +0 -1
- package/modern/BarChart/BarPlot.js +15 -7
- package/modern/BarChart/getColor.js +27 -0
- package/modern/ChartContainer/ChartContainer.js +38 -5
- package/modern/ChartsAxis/ChartsAxis.js +11 -104
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -2
- package/modern/ChartsClipPath/ChartsClipPath.js +2 -2
- package/modern/ChartsGrid/ChartsGrid.js +1 -2
- package/modern/ChartsLegend/ChartsLegend.js +2 -2
- package/modern/ChartsLegend/DefaultChartsLegend.js +1 -2
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -2
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -2
- package/modern/ChartsSurface.js +1 -2
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +20 -2
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +31 -1
- package/modern/ChartsTooltip/ChartsTooltipTable.js +8 -8
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -8
- package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +15 -9
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
- package/modern/ChartsXAxis/ChartsXAxis.js +3 -4
- package/modern/ChartsYAxis/ChartsYAxis.js +3 -4
- package/modern/Gauge/Gauge.js +1 -2
- package/modern/Gauge/GaugeProvider.js +5 -5
- package/modern/LineChart/AnimatedArea.js +7 -7
- package/modern/LineChart/AnimatedLine.js +8 -7
- package/modern/LineChart/AreaElement.js +4 -1
- package/modern/LineChart/AreaPlot.js +7 -1
- package/modern/LineChart/LineChart.js +40 -100
- 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 +40 -100
- package/modern/PieChart/PiePlot.js +27 -8
- 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 +34 -2
- package/modern/ScatterChart/Scatter.js +6 -3
- package/modern/ScatterChart/ScatterChart.js +95 -127
- package/modern/ScatterChart/ScatterPlot.js +10 -0
- package/modern/ScatterChart/getColor.js +42 -0
- package/modern/SparkLineChart/SparkLineChart.js +16 -2
- package/modern/context/CartesianContextProvider.js +23 -8
- package/modern/context/ZAxisContextProvider.js +89 -0
- package/modern/context/index.js +1 -1
- 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 +95 -0
- package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +55 -0
- package/modern/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +40 -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/modern/models/z-axis.js +1 -0
- package/package.json +3 -5
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,46 @@
|
|
|
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. It can be an array with the extremum 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, where N is 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
|
+
* Items equal to `values[k]` will get the color of `colors[k]`.
|
|
40
|
+
*/
|
|
41
|
+
colors: string[];
|
|
42
|
+
/**
|
|
43
|
+
* The color to use when an element is not part of the values.
|
|
44
|
+
*/
|
|
45
|
+
unknownColor?: string;
|
|
46
|
+
}
|
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
|
+
}
|
|
@@ -60,6 +60,11 @@ export interface PieSeriesType<Tdata = PieValueType> extends CommonSeriesType<Td
|
|
|
60
60
|
* @default 0
|
|
61
61
|
*/
|
|
62
62
|
paddingAngle?: number;
|
|
63
|
+
/**
|
|
64
|
+
* The sorting strategy used to order pie slices.
|
|
65
|
+
* Can be 'none', 'asc', 'desc', or a sorting function.
|
|
66
|
+
* @default 'none'
|
|
67
|
+
*/
|
|
63
68
|
sortingValues?: ChartsPieSorting;
|
|
64
69
|
/**
|
|
65
70
|
* The label displayed into the arc.
|
|
@@ -3,6 +3,7 @@ import { CartesianSeriesType, CommonDefaultizedProps, CommonSeriesType, SeriesId
|
|
|
3
3
|
export type ScatterValueType = {
|
|
4
4
|
x: number;
|
|
5
5
|
y: number;
|
|
6
|
+
z?: any;
|
|
6
7
|
/**
|
|
7
8
|
* A unique identifier for the scatter point
|
|
8
9
|
*/
|
|
@@ -18,6 +19,10 @@ export interface ScatterSeriesType extends CommonSeriesType<ScatterValueType>, C
|
|
|
18
19
|
* @default false
|
|
19
20
|
*/
|
|
20
21
|
disableHover?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The id of the z-axis used to render the series.
|
|
24
|
+
*/
|
|
25
|
+
zAxisKey?: string;
|
|
21
26
|
}
|
|
22
27
|
/**
|
|
23
28
|
* An object that allows to identify a single scatter item.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ScaleOrdinal, ScaleSequential, ScaleThreshold } from 'd3-scale';
|
|
2
|
+
import { ContinuousColorConfig, OrdinalColorConfig, PiecewiseColorConfig } from './colorMapping';
|
|
3
|
+
export interface ZAxisConfig<V = any> {
|
|
4
|
+
id: string;
|
|
5
|
+
data?: V[];
|
|
6
|
+
/**
|
|
7
|
+
* The key used to retrieve `data` from the `dataset` prop.
|
|
8
|
+
*/
|
|
9
|
+
dataKey?: string;
|
|
10
|
+
colorMap?: OrdinalColorConfig | ContinuousColorConfig | PiecewiseColorConfig;
|
|
11
|
+
}
|
|
12
|
+
export interface ZAxisDefaultized extends ZAxisConfig {
|
|
13
|
+
colorScale?: ScaleOrdinal<string | number | Date, string, string | null> | ScaleOrdinal<number, string, string | null> | ScaleSequential<string, string | null> | ScaleThreshold<number | Date, string | null>;
|
|
14
|
+
}
|
package/models/z-axis.js
ADDED
|
@@ -12,8 +12,7 @@ import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
|
12
12
|
import { ChartsClipPath } from '../ChartsClipPath';
|
|
13
13
|
import { ChartsGrid } from '../ChartsGrid';
|
|
14
14
|
import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
|
|
15
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
16
|
/**
|
|
18
17
|
* Demos:
|
|
19
18
|
*
|
|
@@ -137,30 +136,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
137
136
|
* Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
|
|
138
137
|
* @default xAxisIds[0] The id of the first provided axis
|
|
139
138
|
*/
|
|
140
|
-
bottomAxis: PropTypes.oneOfType([PropTypes.
|
|
141
|
-
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
142
|
-
classes: PropTypes.object,
|
|
143
|
-
disableLine: PropTypes.bool,
|
|
144
|
-
disableTicks: PropTypes.bool,
|
|
145
|
-
fill: PropTypes.string,
|
|
146
|
-
label: PropTypes.string,
|
|
147
|
-
labelFontSize: PropTypes.number,
|
|
148
|
-
labelStyle: PropTypes.object,
|
|
149
|
-
position: PropTypes.oneOf(['bottom', 'top']),
|
|
150
|
-
slotProps: PropTypes.object,
|
|
151
|
-
slots: PropTypes.object,
|
|
152
|
-
stroke: PropTypes.string,
|
|
153
|
-
tickFontSize: PropTypes.number,
|
|
154
|
-
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
155
|
-
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
156
|
-
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
|
|
157
|
-
tickLabelStyle: PropTypes.object,
|
|
158
|
-
tickMaxStep: PropTypes.number,
|
|
159
|
-
tickMinStep: PropTypes.number,
|
|
160
|
-
tickNumber: PropTypes.number,
|
|
161
|
-
tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
|
|
162
|
-
tickSize: PropTypes.number
|
|
163
|
-
}), PropTypes.string]),
|
|
139
|
+
bottomAxis: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
164
140
|
children: PropTypes.node,
|
|
165
141
|
className: PropTypes.string,
|
|
166
142
|
/**
|
|
@@ -200,30 +176,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
200
176
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
201
177
|
* @default yAxisIds[0] The id of the first provided axis
|
|
202
178
|
*/
|
|
203
|
-
leftAxis: PropTypes.oneOfType([PropTypes.
|
|
204
|
-
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
205
|
-
classes: PropTypes.object,
|
|
206
|
-
disableLine: PropTypes.bool,
|
|
207
|
-
disableTicks: PropTypes.bool,
|
|
208
|
-
fill: PropTypes.string,
|
|
209
|
-
label: PropTypes.string,
|
|
210
|
-
labelFontSize: PropTypes.number,
|
|
211
|
-
labelStyle: PropTypes.object,
|
|
212
|
-
position: PropTypes.oneOf(['left', 'right']),
|
|
213
|
-
slotProps: PropTypes.object,
|
|
214
|
-
slots: PropTypes.object,
|
|
215
|
-
stroke: PropTypes.string,
|
|
216
|
-
tickFontSize: PropTypes.number,
|
|
217
|
-
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
218
|
-
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
219
|
-
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
|
|
220
|
-
tickLabelStyle: PropTypes.object,
|
|
221
|
-
tickMaxStep: PropTypes.number,
|
|
222
|
-
tickMinStep: PropTypes.number,
|
|
223
|
-
tickNumber: PropTypes.number,
|
|
224
|
-
tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
|
|
225
|
-
tickSize: PropTypes.number
|
|
226
|
-
}), PropTypes.string]),
|
|
179
|
+
leftAxis: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
227
180
|
/**
|
|
228
181
|
* @deprecated Consider using `slotProps.legend` instead.
|
|
229
182
|
*/
|
|
@@ -268,32 +221,10 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
268
221
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
269
222
|
* @default null
|
|
270
223
|
*/
|
|
271
|
-
rightAxis: PropTypes.oneOfType([PropTypes.
|
|
272
|
-
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
273
|
-
classes: PropTypes.object,
|
|
274
|
-
disableLine: PropTypes.bool,
|
|
275
|
-
disableTicks: PropTypes.bool,
|
|
276
|
-
fill: PropTypes.string,
|
|
277
|
-
label: PropTypes.string,
|
|
278
|
-
labelFontSize: PropTypes.number,
|
|
279
|
-
labelStyle: PropTypes.object,
|
|
280
|
-
position: PropTypes.oneOf(['left', 'right']),
|
|
281
|
-
slotProps: PropTypes.object,
|
|
282
|
-
slots: PropTypes.object,
|
|
283
|
-
stroke: PropTypes.string,
|
|
284
|
-
tickFontSize: PropTypes.number,
|
|
285
|
-
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
286
|
-
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
287
|
-
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
|
|
288
|
-
tickLabelStyle: PropTypes.object,
|
|
289
|
-
tickMaxStep: PropTypes.number,
|
|
290
|
-
tickMinStep: PropTypes.number,
|
|
291
|
-
tickNumber: PropTypes.number,
|
|
292
|
-
tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
|
|
293
|
-
tickSize: PropTypes.number
|
|
294
|
-
}), PropTypes.string]),
|
|
224
|
+
rightAxis: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
295
225
|
/**
|
|
296
226
|
* The series to display in the bar chart.
|
|
227
|
+
* An array of [[BarSeriesType]] objects.
|
|
297
228
|
*/
|
|
298
229
|
series: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
299
230
|
/**
|
|
@@ -330,30 +261,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
330
261
|
* Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
|
|
331
262
|
* @default null
|
|
332
263
|
*/
|
|
333
|
-
topAxis: PropTypes.oneOfType([PropTypes.
|
|
334
|
-
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
335
|
-
classes: PropTypes.object,
|
|
336
|
-
disableLine: PropTypes.bool,
|
|
337
|
-
disableTicks: PropTypes.bool,
|
|
338
|
-
fill: PropTypes.string,
|
|
339
|
-
label: PropTypes.string,
|
|
340
|
-
labelFontSize: PropTypes.number,
|
|
341
|
-
labelStyle: PropTypes.object,
|
|
342
|
-
position: PropTypes.oneOf(['bottom', 'top']),
|
|
343
|
-
slotProps: PropTypes.object,
|
|
344
|
-
slots: PropTypes.object,
|
|
345
|
-
stroke: PropTypes.string,
|
|
346
|
-
tickFontSize: PropTypes.number,
|
|
347
|
-
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
348
|
-
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
349
|
-
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
|
|
350
|
-
tickLabelStyle: PropTypes.object,
|
|
351
|
-
tickMaxStep: PropTypes.number,
|
|
352
|
-
tickMinStep: PropTypes.number,
|
|
353
|
-
tickNumber: PropTypes.number,
|
|
354
|
-
tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
|
|
355
|
-
tickSize: PropTypes.number
|
|
356
|
-
}), PropTypes.string]),
|
|
264
|
+
topAxis: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
357
265
|
viewBox: PropTypes.shape({
|
|
358
266
|
height: PropTypes.number,
|
|
359
267
|
width: PropTypes.number,
|
|
@@ -366,11 +274,27 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
366
274
|
width: PropTypes.number,
|
|
367
275
|
/**
|
|
368
276
|
* The configuration of the x-axes.
|
|
369
|
-
* If not provided, a default axis config is used
|
|
277
|
+
* If not provided, a default axis config is used.
|
|
278
|
+
* An array of [[AxisConfig]] objects.
|
|
370
279
|
*/
|
|
371
280
|
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
372
281
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
373
282
|
classes: PropTypes.object,
|
|
283
|
+
colorMap: PropTypes.oneOfType([PropTypes.shape({
|
|
284
|
+
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
|
|
285
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
286
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
287
|
+
type: PropTypes.oneOf(['continuous']).isRequired
|
|
288
|
+
}), PropTypes.shape({
|
|
289
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
290
|
+
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
|
|
291
|
+
type: PropTypes.oneOf(['piecewise']).isRequired
|
|
292
|
+
}), PropTypes.shape({
|
|
293
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
294
|
+
type: PropTypes.oneOf(['ordinal']).isRequired,
|
|
295
|
+
unknownColor: PropTypes.string,
|
|
296
|
+
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
|
|
297
|
+
})]),
|
|
374
298
|
data: PropTypes.array,
|
|
375
299
|
dataKey: PropTypes.string,
|
|
376
300
|
disableLine: PropTypes.bool,
|
|
@@ -403,11 +327,27 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
403
327
|
})),
|
|
404
328
|
/**
|
|
405
329
|
* The configuration of the y-axes.
|
|
406
|
-
* If not provided, a default axis config is used
|
|
330
|
+
* If not provided, a default axis config is used.
|
|
331
|
+
* An array of [[AxisConfig]] objects.
|
|
407
332
|
*/
|
|
408
333
|
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
409
334
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
410
335
|
classes: PropTypes.object,
|
|
336
|
+
colorMap: PropTypes.oneOfType([PropTypes.shape({
|
|
337
|
+
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
|
|
338
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
339
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
340
|
+
type: PropTypes.oneOf(['continuous']).isRequired
|
|
341
|
+
}), PropTypes.shape({
|
|
342
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
343
|
+
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
|
|
344
|
+
type: PropTypes.oneOf(['piecewise']).isRequired
|
|
345
|
+
}), PropTypes.shape({
|
|
346
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
347
|
+
type: PropTypes.oneOf(['ordinal']).isRequired,
|
|
348
|
+
unknownColor: PropTypes.string,
|
|
349
|
+
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
|
|
350
|
+
})]),
|
|
411
351
|
data: PropTypes.array,
|
|
412
352
|
dataKey: PropTypes.string,
|
|
413
353
|
disableLine: PropTypes.bool,
|
|
@@ -35,7 +35,6 @@ export const BarElementPath = styled(animated.rect, {
|
|
|
35
35
|
ownerState
|
|
36
36
|
}) => ({
|
|
37
37
|
stroke: 'none',
|
|
38
|
-
shapeRendering: 'crispEdges',
|
|
39
38
|
fill: ownerState.isHighlighted ? d3Color(ownerState.color).brighter(0.5).formatHex() : ownerState.color,
|
|
40
39
|
transition: 'opacity 0.2s ease-in, fill 0.2s ease-in',
|
|
41
40
|
opacity: ownerState.isFaded && 0.3 || 1
|
|
@@ -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,13 +105,12 @@ 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));
|
|
104
|
-
const minValueCoord = Math.min(...valueCoordinates);
|
|
105
|
-
const maxValueCoord = Math.max(...valueCoordinates);
|
|
112
|
+
const minValueCoord = Math.round(Math.min(...valueCoordinates));
|
|
113
|
+
const maxValueCoord = Math.round(Math.max(...valueCoordinates));
|
|
106
114
|
return {
|
|
107
115
|
seriesId,
|
|
108
116
|
dataIndex,
|
|
@@ -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
|
});
|
|
@@ -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
|
+
}
|