Skip to content
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

[charts] Make typescript more flexible about plugins and their params #16478

Merged
merged 5 commits into from
Feb 7, 2025

Conversation

alexfauquette
Copy link
Member

Extracted from the radar and voronoid PRs.

The introduction of the polar and voronoid plugins reveal to missing usecases:

The typing of useChartContainerProps and useChartContainerProProps assumed all the plugins were set. And the pie chart was managed by avoiding this hook and manually manage props propagation.

The radar chart needs a different set of plugins (replacing the cartesian by the polar one)
Same for the voronoi plugin which makes sens to add only for the Scatter chart and maybe the line chart latter.

This PR extends the propagation of the generics to set correctly the number plugins used by each chart.

It also introduces a file XxxCharts.plugins.ts which defines the array and plugins and its signature. This is done in order to clarify which chart uses which plugin

@alexfauquette alexfauquette added the component: charts This is the name of the generic UI component, not the React module! label Feb 5, 2025
@mui-bot
Copy link

mui-bot commented Feb 5, 2025

Deploy preview: https://deploy-preview-16478--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against 88d465f

Copy link

codspeed-hq bot commented Feb 5, 2025

CodSpeed Performance Report

Merging #16478 will not alter performance

Comparing alexfauquette:types (88d465f) with master (1ffe360)

Summary

✅ 6 untouched benchmarks

@@ -19,7 +22,7 @@ export const useChartContainerProps = <
>(
props: ChartContainerProps<TSeries, TSignatures>,
ref: React.Ref<SVGSVGElement>,
): UseChartContainerPropsReturnValue<TSeries> => {
): UseChartContainerPropsReturnValue<TSeries, TSignatures> => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hack I found is to force the type as AllPlugins but export the DataProvideProps as TSignatures

export const useChartCartesianAxis: ChartPlugin<
UseChartCartesianAxisSignature<ChartSeriesType>
> = ({ params, store, seriesConfig, svgRef, instance }) => {
export const useChartCartesianAxis: ChartPlugin<UseChartCartesianAxisSignature<any>> = ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<any> here seems better than the previous ChartSeriesType, since ChartSeriesType means all of these, which causes conflicts.

I believe the main issue in in the ChartPlugin signature. As a function with extra props (getInitialState,models,etc) is a bit complex to type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for myself tomorrow: Test if CartesianChartsSeriesType make it works.

Otherwise I agree that the any is better than the override

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After verification it does not work

Copy link
Member

@JCQuintas JCQuintas Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it wont work with anything other than "any". To make it work we would have to make it work with useChartCartesianAxis<'bar'>, but currently only the type is generic.

This means that the we can make the type specific, but not the implementation. So a: UseChartCartesianAxis<'bar'> = useChartCartesianAxis gives an error, because useChartCartesianAxis = useChartCartesianAxis<'bar'> | useChartCartesianAxis<'pie'> | ...

Not specifically this example, but you get the gist I suppose. a: Type = b kinda of coerces the types if they are compatible 😆

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 6, 2025
Copy link

github-actions bot commented Feb 6, 2025

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 6, 2025
Comment on lines +3 to +9
"colors": { "type": { "name": "any" }, "default": "rainbowSurgePalette" },
"dataset": { "type": { "name": "any" } },
"height": { "type": { "name": "any" } },
"id": { "type": { "name": "any" } },
"margin": { "type": { "name": "any" } },
"series": { "type": { "name": "any" } },
"skipAnimation": { "type": { "name": "any" } },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really have to move away from our current doc generator 😆

Copy link
Member

@JCQuintas JCQuintas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a slight improvement.

Bear in mind it will require changes in the funnel and radar PRs

@alexfauquette alexfauquette merged commit d8f2691 into mui:master Feb 7, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: charts This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants