forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[charts] Introduce plugins system (mui#13367)
- Loading branch information
1 parent
9ca107f
commit 0e951bd
Showing
33 changed files
with
226 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ChartsPluginType } from '../models/plugin'; | ||
import { getExtremumX, getExtremumY } from './extremums'; | ||
import formatter from './formatter'; | ||
import getColor from './getColor'; | ||
|
||
export const plugin: ChartsPluginType<'bar'> = { | ||
seriesType: 'bar', | ||
seriesFormatter: formatter, | ||
colorProcessor: getColor, | ||
xExtremumGetter: getExtremumX, | ||
yExtremumGetter: getExtremumY, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
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'; | ||
|
||
export const defaultPlugins = [barPlugin, scatterPlugin, linePlugin, piePlugin]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as React from 'react'; | ||
import { ChartsPluginTypes, 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>[]) { | ||
const defaultizedPlugins = plugins ?? defaultPlugins; | ||
|
||
return React.useMemo(() => { | ||
const seriesFormatters: SeriesFormatterConfig<ChartSeriesType> = {}; | ||
const colorProcessors: ColorProcessorsConfig<ChartSeriesType> = {}; | ||
const xExtremumGetters: ExtremumGettersConfig<ChartSeriesType> = {}; | ||
const yExtremumGetters: ExtremumGettersConfig<ChartSeriesType> = {}; | ||
|
||
for (let i = 0; i < defaultizedPlugins.length; i += 1) { | ||
const plugin = defaultizedPlugins[i]; | ||
|
||
// To remove those any we will need to solve this union discrimination issue: | ||
// https://www.typescriptlang.org/play/?#code/FDAuE8AcFMAIDkCuBbARtATgYQPYDsAzASwHNYBeWAb2FlgGsi8ATALlgHI8V0MOBuWrBwwMAQ1A4M7ABQAPdtzSYAlBQB8sJb0EBfEBBiwAyqAxMSuQqQrUhjFuw4BnMxYFCRmCVNkLYruZ4JGrkmoEWeiAAxviuWqhWxCTsSMrY+Mm2VAxMbLAARNqYBQA0wqI+0rByGrAATLAAVDWw+rF48YFJpOymQZaZNpQ5DvkFEcFlFd6S1bVhsAAG9S0AJFRyukttMXGgsB3JzrYA2niJQyTl3VcAugZQcADylXPOALJikJAW2ULFDAAflSPEwPRIpw4XnEcw4d1KQkmJBBJjcwQhUJhVXhiN0gmAHXi2LmXx+FnYr1mUk+31+wWy+JABCksBkABtoAcjjYcARDldnGoaCA6AB6MWwADqUnoJxw9FgRH5AHc4L9ooroGJogALQ5iZxwPJEABuRGYiDE7PASJVRFAerZPJIADoxsKhHRooa4FwwXxWF66DNYVIyfTIS73Xk7rZoySpIIQyHUBhtfRkyGfUbOMiOEGU3RExgIxZTtGxnHKAm3kng8xoAQxIh2aBC0W0xms-pvftqLkWOUS2141chBLYABJDimuB4HBKxtiWBiVA4RAHXU4FWwSSwTkHAAqxlgiBYmFcYhYAusbrGq5vtepGFX6YPTHo0GYnjrpbp5ZVrYJZ6EAA | ||
seriesFormatters[plugin.seriesType] = plugin.seriesFormatter as any; | ||
|
||
colorProcessors[plugin.seriesType] = plugin.colorProcessor as any; | ||
|
||
if (plugin.xExtremumGetter) { | ||
xExtremumGetters[plugin.seriesType] = plugin.xExtremumGetter as any; | ||
} | ||
|
||
if (plugin.yExtremumGetter) { | ||
yExtremumGetters[plugin.seriesType] = plugin.yExtremumGetter as any; | ||
} | ||
} | ||
return { | ||
seriesFormatters, | ||
colorProcessors, | ||
xExtremumGetters, | ||
yExtremumGetters, | ||
}; | ||
}, [defaultizedPlugins]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ChartsPluginType } from '../models/plugin'; | ||
import { getExtremumX, getExtremumY } from './extremums'; | ||
import formatter from './formatter'; | ||
import getColor from './getColor'; | ||
|
||
export const plugin: ChartsPluginType<'line'> = { | ||
seriesType: 'line', | ||
colorProcessor: getColor, | ||
seriesFormatter: formatter, | ||
xExtremumGetter: getExtremumX, | ||
yExtremumGetter: getExtremumY, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ChartsPluginType } from '../models/plugin'; | ||
import formatter from './formatter'; | ||
import getColor from './getColor'; | ||
|
||
export const plugin: ChartsPluginType<'pie'> = { | ||
seriesType: 'pie', | ||
colorProcessor: getColor, | ||
seriesFormatter: formatter, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ChartsPluginType } from '../models/plugin'; | ||
import { getExtremumX, getExtremumY } from './extremums'; | ||
import formatter from './formatter'; | ||
import getColor from './getColor'; | ||
|
||
export const plugin: ChartsPluginType<'scatter'> = { | ||
seriesType: 'scatter', | ||
seriesFormatter: formatter, | ||
colorProcessor: getColor, | ||
xExtremumGetter: getExtremumX, | ||
yExtremumGetter: getExtremumY, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.