Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/x-charts/src/ChartContainer/ChartContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import {
} from '../context/CartesianContextProvider';
import { ChartsAxesGradients } from '../internals/components/ChartsAxesGradients';
import { HighlightedProvider, HighlightedProviderProps } from '../context';
import { ChartsPluginTypes } from '../models/plugin';
import { ChartsPluginType } from '../models/plugin';
import { ChartSeriesType } from '../models/seriesType/config';
import { usePluginsMerge } from './usePluginsMerge';

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

const ChartContainer = React.forwardRef(function ChartContainer(props: ChartContainerProps, ref) {
Expand Down
8 changes: 7 additions & 1 deletion packages/x-charts/src/ChartContainer/defaultPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@ import { plugin as barPlugin } from '../BarChart/plugin';
import { plugin as scatterPlugin } from '../ScatterChart/plugin';
import { plugin as linePlugin } from '../LineChart/plugin';
import { plugin as piePlugin } from '../PieChart/plugin';
import { ChartsPluginType } from '../models';

export const defaultPlugins = [barPlugin, scatterPlugin, linePlugin, piePlugin];
export const defaultPlugins: ChartsPluginType<'bar' | 'scatter' | 'line' | 'pie'>[] = [
barPlugin,
scatterPlugin,
linePlugin,
piePlugin,
];
4 changes: 2 additions & 2 deletions packages/x-charts/src/ChartContainer/usePluginsMerge.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from 'react';
import { ChartsPluginTypes, ColorProcessorsConfig } from '../models';
import { ChartsPluginType, ColorProcessorsConfig } from '../models';
import { ChartSeriesType } from '../models/seriesType/config';
import { ExtremumGettersConfig } from '../context/CartesianContextProvider';
import { SeriesFormatterConfig } from '../context/SeriesContextProvider';
import { defaultPlugins } from './defaultPlugins';

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

return React.useMemo(() => {
Expand Down
20 changes: 9 additions & 11 deletions packages/x-charts/src/models/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ export type ColorProcessorsConfig<T extends ChartSeriesType> = {
[Key in T]?: ColorProcessor<Key>;
};

export type ChartsPluginType<T extends ChartSeriesType> = {
seriesType: T;
seriesFormatter: Formatter<T>;
colorProcessor: ColorProcessor<T>;
xExtremumGetter?: ExtremumGetter<T>;
yExtremumGetter?: ExtremumGetter<T>;
};

export type ChartsPluginTypes<T extends ChartSeriesType> = {
[Key in T]: ChartsPluginType<Key>;
}[T];
export type ChartsPluginType<T> = T extends ChartSeriesType
? {
seriesType: T;
seriesFormatter: Formatter<T>;
colorProcessor: ColorProcessor<T>;
xExtremumGetter?: ExtremumGetter<T>;
yExtremumGetter?: ExtremumGetter<T>;
}
: never;
1 change: 0 additions & 1 deletion scripts/x-charts.exports.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
{ "name": "ChartsOnAxisClickHandlerProps", "kind": "Interface" },
{ "name": "ChartsPieSorting", "kind": "TypeAlias" },
{ "name": "ChartsPluginType", "kind": "TypeAlias" },
{ "name": "ChartsPluginTypes", "kind": "TypeAlias" },
{ "name": "ChartsReferenceLine", "kind": "Function" },
{ "name": "ChartsReferenceLineClasses", "kind": "Interface" },
{ "name": "ChartsReferenceLineClassKey", "kind": "TypeAlias" },
Expand Down