Skip to content

Conversation

@bernardobelchior
Copy link
Member

@bernardobelchior bernardobelchior commented Oct 24, 2025

Add series colorGetter prop with a (data: { value: TValue, dataIndex: number}) => string signature.

Demo:

image Screenshot 2025-11-05 at 18 30 30

@bernardobelchior bernardobelchior added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. scope: charts Changes related to the charts. labels Oct 24, 2025
@mui-bot
Copy link

mui-bot commented Oct 24, 2025

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

Updated pages:

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid 🔺+117B(+0.03%) 🔺+29B(+0.02%)
@mui/x-data-grid-pro 🔺+117B(+0.02%) 🔺+31B(+0.02%)
@mui/x-data-grid-premium 🔺+117B(+0.02%) 🔺+28B(+0.01%)
@mui/x-charts 🔺+750B(+0.22%) 🔺+156B(+0.15%)
@mui/x-charts-pro 🔺+748B(+0.17%) 🔺+101B(+0.08%)
@mui/x-charts-premium 🔺+750B(+0.17%) 🔺+151B(+0.11%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 🔺+39B(+0.06%) ▼-3B(-0.01%)
@mui/x-tree-view-pro 🔺+39B(+0.04%) 🔺+2B(+0.01%)

Details of bundle changes

Generated by 🚫 dangerJS against 22423c6

xScale: D3Scale;
yScale: D3Scale;
/**
* @deprecated Use `colorGetter` instead.
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 color can be obtained by calling colorGetter(), so this color is redundant. That was my logic for deprecating this. Let me know what you think.

Copy link
Member

Choose a reason for hiding this comment

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

It feels a bit weird because all the series now have color that support a callback, and scatter get its color deprecated in favor of the colorGetter

@bernardobelchior bernardobelchior changed the title Add series color callback [charts] Add series color callback Oct 24, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 24, 2025

CodSpeed Performance Report

Merging #20084 will not alter performance

Comparing bernardobelchior:add-series-color-callback (22423c6) with master (7e864cf)

Summary

✅ 13 untouched

@bernardobelchior bernardobelchior force-pushed the add-series-color-callback branch from e5711c8 to 61ed9e5 Compare October 29, 2025 09:59
{seriesOrder.map((seriesId) => {
const { id, xAxisId, yAxisId, zAxisId, color } = series[seriesId];

// FIXME: V9: remove this cast as it will no longer be necessary
Copy link
Member Author

Choose a reason for hiding this comment

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

Added an action item in tasks for v9 to remove these fixmes

@bernardobelchior bernardobelchior force-pushed the add-series-color-callback branch from a06ce47 to e3de132 Compare October 29, 2025 11:00
@bernardobelchior bernardobelchior marked this pull request as ready for review October 29, 2025 12:50
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 29, 2025
@github-actions
Copy link

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

@bernardobelchior bernardobelchior force-pushed the add-series-color-callback branch from f177611 to 43f4e87 Compare October 29, 2025 14:43
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 29, 2025
xScale: D3Scale;
yScale: D3Scale;
/**
* @deprecated Use `colorGetter` instead.
Copy link
Member

Choose a reason for hiding this comment

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

It feels a bit weird because all the series now have color that support a callback, and scatter get its color deprecated in favor of the colorGetter

Comment on lines 47 to 51
color={
typeof series.color === 'function'
? series.color({ value: min.value, dataIndex: min.index })
: series.color
}
Copy link
Member

Choose a reason for hiding this comment

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

From a user perspective this feel paintfull. 99% of the time color is just a string. Having to do edge case for the function option is not optimal.

What about getting the colorGetter and at the same place we defaultise the color according to the colorPalette, we add a logic saying "if colorGetter is deined, I do color = colorGetter(null)"

That way people that don't care about callback can ignore this option. and those who care can simply do color={series.collorGetter?.(value) ?? series.color}

Copy link
Member Author

Choose a reason for hiding this comment

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

From a user perspective this feel paintfull

Yeah, I kind of agree. We can expose colorGetter and color is the result of colorGetter(null), i.e., a default color for the series.

Copy link
Member Author

Choose a reason for hiding this comment

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

So what you're saying is that a series will accept a colorGetter prop that has priority over color, right?

Copy link
Member

Choose a reason for hiding this comment

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

So what you're saying is that a series will accept a colorGetter prop that has priority over color, right?

Yes, at least that what I though while reading the PR. Maybe there is a better tradeof

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated, let me know what you think 😄

@bernardobelchior bernardobelchior force-pushed the add-series-color-callback branch from ea1d740 to 5dc7e1b Compare October 30, 2025 14:32
series: [
{
data: netSpendInPounds,
colorGetter: (data) => clubColors[data.dataIndex],
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we call it getColor instead of colorGetter? Or getDataPointColor?

Copy link
Member

Choose a reason for hiding this comment

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

colorGetter has the advantage that when you search for color you find it just after in the API page or the autocomplet. But I agree getColor feels more natural

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that was my conclusion as well.

@JCQuintas any input? If not, I'd rather stick with colorGetter as I value the discoverability more

Comment on lines 25 to 26
const { seriesId, points, color, hideMark, fillArea } = series;
const getColor = getSeriesColorFn(series);
Copy link
Member

Choose a reason for hiding this comment

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

Should we put that in the useRadarSeriesData() to avoid having some computation in the hook and others on the component

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure

series: [
{
data: netSpendInPounds,
colorGetter: (data) => clubColors[data.dataIndex],
Copy link
Member

Choose a reason for hiding this comment

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

colorGetter has the advantage that when you search for color you find it just after in the API page or the autocomplet. But I agree getColor feels more natural

@bernardobelchior bernardobelchior force-pushed the add-series-color-callback branch from 509d888 to 808f940 Compare October 30, 2025 15:38
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 30, 2025
@github-actions
Copy link

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

@bernardobelchior bernardobelchior force-pushed the add-series-color-callback branch from 808f940 to 7173e06 Compare October 30, 2025 16:41
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 30, 2025
@bernardobelchior bernardobelchior force-pushed the add-series-color-callback branch from 7173e06 to 1ba3a9f Compare October 31, 2025 17:20
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.

Shouldn't this also extend to pro packages?

Co-authored-by: Jose C Quintas Jr <[email protected]>
Signed-off-by: Bernardo Belchior <[email protected]>
@bernardobelchior
Copy link
Member Author

Shouldn't this also extend to pro packages?

Do you mean that I forgot to update the pro series types? Yeah, I did 😅 on it

@bernardobelchior
Copy link
Member Author

Actually, all pro charts omit the color prop, so we don't need to implement colorGetter.

renovate bot and others added 17 commits November 3, 2025 15:40
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…ui#19851)

Signed-off-by: Michel Engelen <[email protected]>
Signed-off-by: Gene Arch <[email protected]>
Co-authored-by: Michel Engelen <[email protected]>
Co-authored-by: Olivier Tassinari <[email protected]>
Co-authored-by: Gene Arch <[email protected]>
Co-authored-by: Rom Grk <[email protected]>
…ctionsCellItem) (mui#19513)

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: michelengelen <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@JCQuintas
Copy link
Member

JCQuintas commented Nov 3, 2025

Actually, all pro charts omit the color prop, so we don't need to implement colorGetter.

But shouldn't it be implemented for them? Like, the funnel chart has a similar color setting as the pie chart. The sankey is completely custom, but it could, technically, benefit from a colorGetter

We can do it in a followup though if you agree

@bernardobelchior
Copy link
Member Author

Yeah, I'll do that as a follow-up 👍

@bernardobelchior bernardobelchior merged commit 30592e8 into mui:master Nov 3, 2025
22 checks passed
@bernardobelchior bernardobelchior deleted the add-series-color-callback branch November 3, 2025 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: charts Changes related to the charts. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants