Skip to content

Commit e982256

Browse files
JCQuintasalexfauquette
authored andcommitted
[charts] Simplify plugin types (mui#13396)
Signed-off-by: Jose C Quintas Jr <[email protected]> Signed-off-by: Alexandre Fauquette <[email protected]> Co-authored-by: Alexandre Fauquette <[email protected]>
1 parent c3a664b commit e982256

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

packages/x-charts/src/ChartContainer/ChartContainer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import {
1515
} from '../context/CartesianContextProvider';
1616
import { ChartsAxesGradients } from '../internals/components/ChartsAxesGradients';
1717
import { HighlightedProvider, HighlightedProviderProps } from '../context';
18-
import { ChartsPluginTypes } from '../models/plugin';
18+
import { ChartsPluginType } from '../models/plugin';
1919
import { ChartSeriesType } from '../models/seriesType/config';
2020
import { usePluginsMerge } from './usePluginsMerge';
2121

22-
export type ChartContainerProps<T extends ChartSeriesType = ChartSeriesType> = Omit<
22+
export type ChartContainerProps = Omit<
2323
ChartsSurfaceProps &
2424
Omit<SeriesContextProviderProps, 'seriesFormatters'> &
2525
Omit<DrawingProviderProps, 'svgRef'> &
@@ -32,7 +32,7 @@ export type ChartContainerProps<T extends ChartSeriesType = ChartSeriesType> = O
3232
* An array of plugins defining how to preprocess data.
3333
* If not provided, the container supports line, bar, scatter and pie charts.
3434
*/
35-
plugins?: ChartsPluginTypes<T>[];
35+
plugins?: ChartsPluginType<ChartSeriesType>[];
3636
};
3737

3838
const ChartContainer = React.forwardRef(function ChartContainer(props: ChartContainerProps, ref) {

packages/x-charts/src/ChartContainer/defaultPlugins.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@ import { plugin as barPlugin } from '../BarChart/plugin';
22
import { plugin as scatterPlugin } from '../ScatterChart/plugin';
33
import { plugin as linePlugin } from '../LineChart/plugin';
44
import { plugin as piePlugin } from '../PieChart/plugin';
5+
import { ChartsPluginType } from '../models';
56

6-
export const defaultPlugins = [barPlugin, scatterPlugin, linePlugin, piePlugin];
7+
export const defaultPlugins: ChartsPluginType<'bar' | 'scatter' | 'line' | 'pie'>[] = [
8+
barPlugin,
9+
scatterPlugin,
10+
linePlugin,
11+
piePlugin,
12+
];

packages/x-charts/src/ChartContainer/usePluginsMerge.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as React from 'react';
2-
import { ChartsPluginTypes, ColorProcessorsConfig } from '../models';
2+
import { ChartsPluginType, ColorProcessorsConfig } from '../models';
33
import { ChartSeriesType } from '../models/seriesType/config';
44
import { ExtremumGettersConfig } from '../context/CartesianContextProvider';
55
import { SeriesFormatterConfig } from '../context/SeriesContextProvider';
66
import { defaultPlugins } from './defaultPlugins';
77

8-
export function usePluginsMerge<T extends ChartSeriesType>(plugins?: ChartsPluginTypes<T>[]) {
8+
export function usePluginsMerge<T extends ChartSeriesType>(plugins?: ChartsPluginType<T>[]) {
99
const defaultizedPlugins = plugins ?? defaultPlugins;
1010

1111
return React.useMemo(() => {

packages/x-charts/src/models/plugin.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ export type ColorProcessorsConfig<T extends ChartSeriesType> = {
1414
[Key in T]?: ColorProcessor<Key>;
1515
};
1616

17-
export type ChartsPluginType<T extends ChartSeriesType> = {
18-
seriesType: T;
19-
seriesFormatter: Formatter<T>;
20-
colorProcessor: ColorProcessor<T>;
21-
xExtremumGetter?: ExtremumGetter<T>;
22-
yExtremumGetter?: ExtremumGetter<T>;
23-
};
24-
25-
export type ChartsPluginTypes<T extends ChartSeriesType> = {
26-
[Key in T]: ChartsPluginType<Key>;
27-
}[T];
17+
export type ChartsPluginType<T> = T extends ChartSeriesType
18+
? {
19+
seriesType: T;
20+
seriesFormatter: Formatter<T>;
21+
colorProcessor: ColorProcessor<T>;
22+
xExtremumGetter?: ExtremumGetter<T>;
23+
yExtremumGetter?: ExtremumGetter<T>;
24+
}
25+
: never;

scripts/x-charts.exports.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
{ "name": "ChartsOnAxisClickHandlerProps", "kind": "Interface" },
9494
{ "name": "ChartsPieSorting", "kind": "TypeAlias" },
9595
{ "name": "ChartsPluginType", "kind": "TypeAlias" },
96-
{ "name": "ChartsPluginTypes", "kind": "TypeAlias" },
9796
{ "name": "ChartsReferenceLine", "kind": "Function" },
9897
{ "name": "ChartsReferenceLineClasses", "kind": "Interface" },
9998
{ "name": "ChartsReferenceLineClassKey", "kind": "TypeAlias" },

0 commit comments

Comments
 (0)