-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[docs] Reproduce npm sparkline #19089
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
Conversation
Deploy preview: https://deploy-preview-19089--material-ui-x.netlify.app/ Updated pages: Bundle size report
|
CodSpeed Performance ReportMerging #19089 will improve performances by 9.24%Comparing Summary
Benchmarks breakdown
Footnotes |
There was a problem hiding this 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?
data: Array.from({ length: data.length }, (_, index) => index), | ||
hideTooltip: xAxisProps === undefined, | ||
...xAxisProps, |
There was a problem hiding this comment.
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
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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}}
The idea being to add nie looking example on top to say "hey you can do great stuff with that component"
There was a problem hiding this comment.
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 👍
Not 100% sure, but the series, xAxis, and yAxis were not memoized. So:
|
Signed-off-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com>
@@ -0,0 +1,64 @@ | |||
// Run `node generate-sparkline.js > weekly-downloads.json` To update the npm chart demo. |
There was a problem hiding this comment.
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 😆
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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? 🤔
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 😆
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