mui-x icon indicating copy to clipboard operation
mui-x copied to clipboard

[charts] Make scatter chart use data attributes

Open alexfauquette opened this issue 7 months ago • 6 comments

I found nothing to say about the label because they are not yet supported on Heatmap. I created #18046 on this topic.

For the scatter chart the initial idea was to provide explaination about how to target elements with CSS like in https://mui.com/x/react-charts/lines/#css

Instead of adding CSS classes, I propose to start the implementation of data attribute for series' id and states. Created #18047 to continue the effort on this topic.

Will probably need a cleaner way of doing it, and document available data attributes

alexfauquette avatar May 28 '25 14:05 alexfauquette

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

Updated pages:

Bundle size report

Total Size Change: 🔺+975B(+0.01%) - Total Gzip Change: 🔺+479B(+0.01%) Files: 122 total (0 added, 0 removed, 30 changed)

Show details for 100 more bundles (22 more not shown)

@mui/x-chartsparsed: 🔺+251B(+0.09%) gzip: 🔺+72B(+0.09%) @mui/x-charts-proparsed: 🔺+251B(+0.07%) gzip: 🔺+98B(+0.09%) @mui/x-charts/ScatterChartparsed: 🔺+251B(+0.16%) gzip: 🔺+80B(+0.15%) @mui/x-charts-pro/ScatterChartProparsed: 🔺+222B(+0.11%) gzip: 🔺+105B(+0.16%) @mui/x-charts-pro/BarChartProparsed: 0B(0.00%) gzip: 🔺+4B(+0.01%) @mui/x-charts-pro/ChartContainerProparsed: 0B(0.00%) gzip: 🔺+5B(+0.01%) @mui/x-charts-pro/ChartDataProviderProparsed: 0B(0.00%) gzip: 🔺+3B(+0.01%) @mui/x-charts-pro/ChartsToolbarProparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts-pro/ChartZoomSliderparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts-pro/FunnelChartparsed: 0B(0.00%) gzip: 🔺+4B(+0.01%) @mui/x-charts-pro/Heatmapparsed: 0B(0.00%) gzip: 🔺+4B(+0.01%) @mui/x-charts-pro/LineChartProparsed: 0B(0.00%) gzip: 🔺+4B(+0.01%) @mui/x-charts-pro/PieChartProparsed: 0B(0.00%) gzip: 🔺+4B(+0.01%) @mui/x-charts-pro/RadarChartProparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/BarChartparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/ChartContainerparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/ChartDataProviderparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/ChartsAxisparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/ChartsAxisHighlightparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/ChartsClipPathparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/ChartsGridparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/ChartsLabelparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/ChartsLegendparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/ChartsLocalizationProviderparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/ChartsOverlayparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/ChartsReferenceLineparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/ChartsSurfaceparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/ChartsTextparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/ChartsTooltipparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/ChartsXAxisparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/ChartsYAxisparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/Gaugeparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/LineChartparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/PieChartparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/RadarChartparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/SparkLineChartparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-charts/Toolbarparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-data-gridparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-data-grid-premiumparsed: 0B(0.00%) gzip: 🔺+4B(0.00%) @mui/x-data-grid-premium/DataGridPremiumparsed: 0B(0.00%) gzip: 🔺+4B(0.00%) @mui/x-data-grid-proparsed: 0B(0.00%) gzip: 🔺+4B(0.00%) @mui/x-data-grid-pro/DataGridProparsed: 0B(0.00%) gzip: 🔺+3B(0.00%) @mui/x-data-grid/DataGridparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickersparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-proparsed: 0B(0.00%) gzip: 🔺+8B(+0.01%) @mui/x-date-pickers-pro/AdapterDateFnsparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-pro/AdapterDateFnsJalaliparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-pro/AdapterDayjsparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-pro/AdapterLuxonparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-pro/AdapterMomentparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-pro/AdapterMomentHijriparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-pro/AdapterMomentJalaaliparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-pro/DateRangeCalendarparsed: 0B(0.00%) gzip: 🔺+3B(+0.01%) @mui/x-date-pickers-pro/DateRangePickerparsed: 0B(0.00%) gzip: 🔺+9B(+0.02%) @mui/x-date-pickers-pro/DateRangePickerDayparsed: 0B(0.00%) gzip: 🔺+4B(+0.05%) @mui/x-date-pickers-pro/DateRangePickerDay2parsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-pro/DateTimeRangePickerparsed: 0B(0.00%) gzip: 🔺+7B(+0.01%) @mui/x-date-pickers-pro/DesktopDateRangePickerparsed: 0B(0.00%) gzip: 🔺+7B(+0.01%) @mui/x-date-pickers-pro/DesktopDateTimeRangePickerparsed: 0B(0.00%) gzip: 🔺+8B(+0.01%) @mui/x-date-pickers-pro/DesktopTimeRangePickerparsed: 0B(0.00%) gzip: 🔺+5B(+0.01%) @mui/x-date-pickers-pro/LocalizationProviderparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-pro/MobileDateRangePickerparsed: 0B(0.00%) gzip: 🔺+8B(+0.02%) @mui/x-date-pickers-pro/MobileDateTimeRangePickerparsed: 0B(0.00%) gzip: 🔺+7B(+0.01%) @mui/x-date-pickers-pro/MobileTimeRangePickerparsed: 0B(0.00%) gzip: 🔺+3B(+0.01%) @mui/x-date-pickers-pro/MultiInputDateRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-pro/MultiInputDateTimeRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-pro/MultiInputTimeRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-pro/PickersRangeCalendarHeaderparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-pro/SingleInputDateRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-pro/SingleInputDateTimeRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-pro/SingleInputTimeRangeFieldparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers-pro/StaticDateRangePickerparsed: 0B(0.00%) gzip: 🔺+4B(+0.01%) @mui/x-date-pickers-pro/TimeRangePickerparsed: 0B(0.00%) gzip: 🔺+3B(+0.01%) @mui/x-date-pickers/AdapterDateFnsparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/AdapterDateFnsBaseparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/AdapterDateFnsJalaliparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/AdapterDayjsparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/AdapterLuxonparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/AdapterMomentparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/AdapterMomentHijriparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/AdapterMomentJalaaliparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/DateCalendarparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/DateFieldparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/DatePickerparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/DateTimeFieldparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/DateTimePickerparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/DayCalendarSkeletonparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/DesktopDatePickerparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/DesktopDateTimePickerparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/DesktopTimePickerparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/DigitalClockparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/LocalizationProviderparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/MobileDatePickerparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/MobileDateTimePickerparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/MobileTimePickerparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/MonthCalendarparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/MultiSectionDigitalClockparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/PickerDay2parsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/PickersActionBarparsed: 0B(0.00%) gzip: 0B(0.00%) @mui/x-date-pickers/PickersCalendarHeaderparsed: 0B(0.00%) gzip: 0B(0.00%)

Details of bundle changes

Generated by :no_entry_sign: dangerJS against 561e4a082da9a16562d9cd6c0ce47d70f45e8ab5

mui-bot avatar May 28 '25 14:05 mui-bot

CodSpeed Performance Report

Merging #18048 will not alter performance

Comparing alexfauquette:heatmap-label (561e4a0) with master (7f6e8d9)

Summary

✅ 9 untouched benchmarks

codspeed-hq[bot] avatar May 28 '25 14:05 codspeed-hq[bot]

It's a shame that this impacts performance significantly. I wonder what we could do to make it faster again.

Maybe styling the highlight natively using CSS and removing the isHighlighted and isFaded helps?

It is a bit odd really, if we remove other props instead of adding props, does it improve speed? 🤔

JCQuintas avatar May 29 '25 07:05 JCQuintas

It's a shame that this impacts performance significantly. I wonder what we could do to make it faster again. Maybe styling the highlight natively using CSS and removing the isHighlighted and isFaded helps?

It is a bit odd really, if we remove other props instead of adding props, does it improve speed? 🤔

It might. Also, styling using CSS is probably faster as well.

bernardobelchior avatar May 29 '25 08:05 bernardobelchior

Should we go for data-index or data-data-index? 😆 There is also data-series or data-series-id 😢

I'd go for the shorter names: data-index and data-series.

bernardobelchior avatar May 30 '25 07:05 bernardobelchior

Should we go for data-index or data-data-index? 😆 There is also data-series or data-series-id 😢

I'd go for the shorter names: data-index and data-series.

Would be my preference as well

JCQuintas avatar May 30 '25 07:05 JCQuintas

About the performances decrease, I can confirm it's not CodSpeed error. The Added the attributes slow down each mark render by a very small amount of time, but multiplied by the number of them, it increases the total render time.

I did some test with react profiler, and Addins those attributes moves the ScatterChart initial render from 140-160ms to 160-200ms

So around 0.05ms per mark since we render 800 of them

alexfauquette avatar Jun 09 '25 11:06 alexfauquette

About the performances decrease, I can confirm it's not CodSpeed error. The Added the attributes slow down each mark render by a very small amount of time, but multiplied by the number of them, it increases the total render time.

I did some test with react profiler, and Addins those attributes moves the ScatterChart initial render from 140-160ms to 160-200ms

So around 0.05ms per mark since we render 800 of them

That is unfortunate. I wonder if we should just add a demo where we replace the marker slot with a custom one that applies the data attributes. That way users keep control of what they want to set as data attributes and we don't regress performance at the cost of DX. We already have some performance problems with a lot of data, so merging this would only exacerbate it. Some users might not care about the CSS styling but will be hit with a performance regression.

What do you think?

bernardobelchior avatar Jun 10 '25 09:06 bernardobelchior