Skip to content

Conversation

alexfauquette
Copy link
Member

Part of #17980

I memoised a few stuff in the sparkline bcause it was slow. Might be better to follow the same patern as other charts with a dedicated hook to transform props into props per sub-components

@alexfauquette alexfauquette added docs Improvements or additions to the documentation. scope: charts Changes related to the charts. labels Aug 7, 2025
@mui-bot
Copy link

mui-bot commented Aug 7, 2025

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

Updated pages:

Bundle size report

Bundle Parsed Size Gzip Size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 🔺+491B(+0.16%) 🔺+136B(+0.14%)
@mui/x-charts-pro 🔺+491B(+0.12%) 🔺+130B(+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 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 🔺+1B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against a38c281

Copy link

codspeed-hq bot commented Aug 7, 2025

CodSpeed Performance Report

Merging #19089 will improve performances by 9.24%

Comparing alexfauquette:npm-sparkline (a38c281) with master (cdea241)1

Summary

⚡ 1 improvements
✅ 9 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
ScatterChartPro with big data amount 438.6 ms 401.5 ms +9.24%

Footnotes

  1. No successful run was found on master (49d5efd) during the generation of this report, so cdea241 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copy link
Member

@bernardobelchior bernardobelchior left a comment

Choose a reason for hiding this comment

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

I memoised a few stuff in the sparkline bcause it was slow.

Do you know what part was slow? What caused the slowness?

Comment on lines 241 to 243
data: Array.from({ length: data.length }, (_, index) => index),
hideTooltip: xAxisProps === undefined,
...xAxisProps,
Copy link
Member

Choose a reason for hiding this comment

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

No need to create an array just to not use it after

Suggested change
data: Array.from({ length: data.length }, (_, index) => index),
hideTooltip: xAxisProps === undefined,
...xAxisProps,
hideTooltip: xAxisProps === undefined,
...xAxisProps,
data: xAxisProps.data ?? Array.from({ length: data.length }, (_, index) => index),

## Demo

As an example the sparkline from npm.
Notice that the accessibility is not down in the chart itself but in a parent context.
Copy link
Member

Choose a reason for hiding this comment

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

What do you mean by this? I couldn't get it

## Demo

As an example the sparkline from npm.
Notice that the accessibility is not down in the chart itself but in a parent context.
Copy link
Member

Choose a reason for hiding this comment

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

What do you mean by this? I couldn't get it

@@ -90,3 +90,10 @@ You can disable clipping by setting `disableClipping` to `true`.
The example below shows how the line's stroke width, `disableClipping` and `clipAreaOffset` affect the sparkline rendering.

{{"demo": "SparklineLineWidth.js"}}

## Demo
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 have a more specific name? E.g., "Weekly downloads example"

Copy link
Member Author

@alexfauquette alexfauquette Aug 7, 2025

Choose a reason for hiding this comment

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

I was not sure about where to place it. It does not fit well in a docs page, And I don't want to creat e a demo page for a single sparkline.

Maybe moving it to the to p og the page with an introduction.

Something like

+ A sparkline is a small chart drawn without axes or coordinates, that presents the general shape of a variation in a simplified way.
+ For example npm downloads display a sparkline of the weekly downloads during the last year.
+ {{"demo": "NpmDownloadsDemo.js}}

## Basics

- A sparkline is a small chart drawn without axes or coordinates, that presents the general shape of a variation in a simplified way.
The <SparkLineChart /> requires only the data props which is an array of numbers. You can also switch from line to a bar plot with plotType="bar".
{{"demo": "BasicSparkLine.js}}

Something a bit like that
image

The idea being to add nie looking example on top to say "hey you can do great stuff with that component"

Copy link
Member

Choose a reason for hiding this comment

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

That sounds good to me 👍

@alexfauquette
Copy link
Member Author

Do you know what part was slow? What caused the slowness?

Not 100% sure, but the series, xAxis, and yAxis were not memoized. So:

  • each state update due to our pointer move leads to
  • a rerender, of that sparkline
  • which create new series/axes objects
  • trigger update of the stroe and the entire data pipeline

@bernardobelchior
Copy link
Member

Compared to the real thing:

image

Here's how it looks now:

image

A couple of things I think we can improve:

  • Reduce font weight in the "Weekly downloads" title
  • Increase space between the title/download count and the chart
  • It seems the bottom horizontal line stretches to the right of the end of the chart. It seems npm's as well, but I think it doesn't look as good in our specific example

@alexfauquette
Copy link
Member Author

The remaining differences are due to different font-size but it looks fairly similar to my non-designer eyes :)

image

Signed-off-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com>
@bernardobelchior
Copy link
Member

Should we center the icon vertically with the text?

Screen.Recording.2025-08-08.at.10.28.27.mov

Before:

image

After:

image

@alexfauquette
Copy link
Member Author

Should we center the icon vertically with the text?

I prefer the current solution which align the horizontal bar with the text baseline

image

@@ -0,0 +1,64 @@
// Run `node generate-sparkline.js > weekly-downloads.json` To update the npm chart demo.
Copy link
Member

Choose a reason for hiding this comment

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

Why not make this dynamic? Eg on page load? I fear this will be forgotten here 😆

Copy link
Member Author

Choose a reason for hiding this comment

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

Why not make this dynamic? Eg on page load? I fear this will be forgotten here 😆

Because data does not need to be up to date. I just made this script to get a realistic look and feel (nothing is more realistic than real data O:) )

I'm not fan of a browser API call. first to avoid bothering npm server, and mostly to avoid having a broken page if they modify their API/their server are for download stats are down

bottom: clipAreaOffset?.bottom ?? 1,
left: clipAreaOffset?.left ?? 1,
};
const clipPathOffset = React.useMemo(
Copy link
Member

Choose a reason for hiding this comment

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

While I don't have an issue with having them here, shouldn't these memoization be moved to the plugins or series config? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Those default are chart specific, so I don't see how to put them in pluggins, and putting them in series config seems a bit over engineering the issue

Copy link
Member

Choose a reason for hiding this comment

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

Those default are chart specific

Ah true, because the sparkline uses the line/bar series config 😢
I've been a bit too focused on the sankey lately which is the chart/series 😆

@alexfauquette alexfauquette merged commit 17f3f75 into mui:master Aug 8, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation. scope: charts Changes related to the charts.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants