-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[charts] Add a series processor using the drawing area #20437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,37 @@ | ||
| import type { ChartSeriesTypeConfig } from '@mui/x-charts/internals'; | ||
| import type { | ||
| ChartSeriesTypeConfig, | ||
| SeriesProcessor, | ||
| SeriesProcessorResult, | ||
| } from '@mui/x-charts/internals'; | ||
| import { getSeriesWithDefaultValues } from './getSeriesWithDefaultValues'; | ||
| import { tooltipGetter } from './tooltipGetter'; | ||
| import { calculateSankeyLayout } from '../calculateSankeyLayout'; | ||
|
|
||
| // Simple passthrough functions for sankey chart | ||
| const seriesProcessor = (series: any) => series; | ||
| const colorProcessor = (series: any) => series; | ||
| const legendGetter = () => []; | ||
|
|
||
| const seriesProcessorWithDrawingArea: SeriesProcessor<'sankey'> = (series, drawingArea) => { | ||
| if (series.seriesOrder.length === 0) { | ||
| return series as SeriesProcessorResult<'sankey'>; | ||
| } | ||
| return { | ||
| series: { | ||
| [series.seriesOrder[0]]: { | ||
| ...series.series[series.seriesOrder[0]], | ||
| sankeyLayout: calculateSankeyLayout(series.series[series.seriesOrder[0]], drawingArea), | ||
| }, | ||
| }, | ||
| seriesOrder: series.seriesOrder, | ||
| } satisfies SeriesProcessorResult<'sankey'>; | ||
| }; | ||
|
|
||
| export const sankeySeriesConfig: ChartSeriesTypeConfig<'sankey'> = { | ||
| seriesProcessor, | ||
| colorProcessor, | ||
| legendGetter, | ||
| tooltipGetter, | ||
| getSeriesWithDefaultValues, | ||
| seriesProcessorWithDrawingArea, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| import { createSelectorMemoized, createSelector } from '@mui/x-internals/store'; | ||
| import { ChartRootSelector } from '../../utils/selectors'; | ||
| import { UseChartSeriesSignature } from './useChartSeries.types'; | ||
| import { applySeriesProcessors } from './processSeries'; | ||
| import { applySeriesProcessors, applySeriesProcessorsWithoutDimensions } from './processSeries'; | ||
| import { selectorChartDrawingArea } from '../useChartDimensions'; | ||
|
|
||
| export const selectorChartSeriesState: ChartRootSelector<UseChartSeriesSignature> = (state) => | ||
| state.series; | ||
|
|
@@ -28,13 +29,28 @@ export const selectorChartDataset = createSelector( | |
| /** | ||
| * Get the processed series after applying series processors. | ||
| * This selector computes the processed series on-demand from the defaultized series. | ||
| * It's a first step before applying the drawing-area-dependent processors. | ||
| * @returns {ProcessedSeries} The processed series. | ||
| */ | ||
| export const selectorChartSeriesProcessed = createSelectorMemoized( | ||
| export const selectorChartSeriesProcessedWithoutDimensions = createSelectorMemoized( | ||
| selectorChartDefaultizedSeries, | ||
| selectorChartSeriesConfig, | ||
| selectorChartDataset, | ||
| function selectorChartSeriesProcessed(defaultizedSeries, seriesConfig, dataset) { | ||
| return applySeriesProcessors(defaultizedSeries, seriesConfig, dataset); | ||
| function selectorChartSeriesProcessedWithoutDimensions(defaultizedSeries, seriesConfig, dataset) { | ||
| return applySeriesProcessorsWithoutDimensions(defaultizedSeries, seriesConfig, dataset); | ||
| }, | ||
| ); | ||
|
|
||
| /** | ||
| * Get the processed series after applying series processors. | ||
| * This selector computes the processed series on-demand from the defaultized series. | ||
| * @returns {ProcessedSeries} The processed series. | ||
| */ | ||
| export const selectorChartSeriesProcessed = createSelectorMemoized( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are using the same selector, why not make the regular series processor use the drawing area?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this approach if the drawing area is modified, but no series uses it the selectors is an identity function. Not sure it's usefull. But if some selector uses the processed series and not the drawing area they should be able to avoid a recomputation. Maybe bernarod's work on the scatter zoom performance can benefit from it. Not sure |
||
| selectorChartSeriesProcessedWithoutDimensions, | ||
| selectorChartSeriesConfig, | ||
| selectorChartDrawingArea, | ||
| function selectorChartSeriesProcessed(processedSeries, seriesConfig, drawingArea) { | ||
| return applySeriesProcessors(processedSeries, seriesConfig, drawingArea); | ||
| }, | ||
| ); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
processingDetectedjust to avoid breaking selectors' cache when processing results in the same value?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that way either not providing
seriesProcessor()or havingseriesProcessor=(x)=>xwill be transparent