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] Create color legend #13700

Merged
merged 13 commits into from
Jul 16, 2024
Merged

Conversation

alexfauquette
Copy link
Member

@alexfauquette alexfauquette commented Jul 2, 2024

Fix #12379

In this PR I propose to add 2 components to display the legend associated with colorMap:

  • ContinuousColorLegend
  • PiecewiseColorLegend

The PiecewiseColorLegend is quite similar to the series legend. So I abstracted the rendering into LegendPerItem which takes a array of objects { color, label } and do the display part. Then DefaultChartsLegend, and PiecewiseColorLegend only have to define the colors and labels they want to display

Known point of discussion

  • the LegendPerItem being a copy past of the DefaultChartsLegend some naming can be weird/not well suited for the PiecewiseColorLegend
  • text are not always perfectly placed. But that's due to text bounding box computation errors. Should be fixed latter
  • Components names does not start with the prefix Charts I thought it would make the naming too long. Buit at the same time not putting it kind of break the convention we follow for charts subcomponents

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

mui-bot commented Jul 2, 2024

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

Updated pages:

Generated by 🚫 dangerJS against ae18c60

@alexfauquette alexfauquette marked this pull request as ready for review July 11, 2024 12:36
@alexfauquette alexfauquette requested a review from JCQuintas July 11, 2024 13:32
Copy link

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

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 11, 2024
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.

Nice PR, I think most of my comments are minor details.

A big question though is if we shouldn't only have the ChartsLabel component and derive all other components from it. So the legend props would have all the configuration necessary

I feel the DX would be simpler since users wouldn't need to use composition if they don't want to? WDYT?

docs/data/charts/legend/legend.md Show resolved Hide resolved
docs/data/charts/legend/legend.md Outdated Show resolved Hide resolved
docs/data/charts/legend/legend.md Outdated Show resolved Hide resolved
packages/x-charts/src/internals/utils.ts Outdated Show resolved Hide resolved
docs/data/charts/legend/tempAnomaly.ts Show resolved Hide resolved
docs/data/charts/legend/BasicColorLegend.tsx Outdated Show resolved Hide resolved
@alexfauquette
Copy link
Member Author

I feel the DX would be simpler since users wouldn't need to use composition if they don't want to? WDYT?

I started with a middle ground: a <ColorLegend /> component that does automatically which between gradient or pieces depending on the colorMap.type

The issue is that customization props are not the same (length, thikness, minLabel, spagin, itemWidth, ...) so it would be a pain for the API documentation due to props used in some cases, but not others.

Since those legends are for already advanced use cases, I preferred to add them in a composition manner.

But the heatmap could have it as a slot

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 16, 2024
@alexfauquette alexfauquette merged commit f195ac2 into mui:master Jul 16, 2024
17 checks passed
@alexfauquette alexfauquette deleted the create-color-legend branch July 16, 2024 12:09
@JCQuintas
Copy link
Member

This PR might break the ci because this other pr was merged too #13822

DungTiger pushed a commit to DungTiger/mui-x that referenced this pull request Jul 23, 2024
thomasmoon pushed a commit to thomasmoon/mui-x that referenced this pull request Sep 9, 2024
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.

[charts] Support color scale legend
3 participants