-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Cache sorting order of dataset metas #6757
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 wonder if we should check if the dataset is visible here so that we don't have to do it each time
_getSortedDatasetMetas
is calledThere 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.
Done
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 don't think we necessarily need a new property
visible
cause that's basically just!hidden
, right?I was wondering if we could do the filtering of only visible datasets here to cache that as well, but on second look it seems like that's not possible because the legend shows the labels for visible and non-visible datasets
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.
Chart.js/src/core/core.controller.js
Lines 897 to 899 in eb0751c
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'm not sure about the use case where datasets are shared between charts, @etimberg any insights?
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'm not quite sure where we modify the data object, but stopping that sounds like another potentially good thing to change
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.
Perhaps 'modify' is the wrong word, but we attach extra info to the data object and so systems that treat that as immutable are unhappy
Chart.js/src/core/core.controller.js
Line 863 in e5b03a0
I used chart.js in a React project recently and tried writing my own wrapper. I had a look at the source code of react-chartjs-2 and they have to do a lot of work to handle the fact that the data object gets mutated. Dropping that would significantly simplify things
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 wonder if we need to treat
options
as immutable as well. Here's a PR for fixingdataset._meta
: #6778There 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.
So the
meta.hidden
anddataset.hidden
are both needed.dataset.hidden
is provided in dataset configuration (loaded from storage maybe) andmeta.hidden
is used to override that, when clicking legend (avoiding touching the provided configuration).Now this could be changed to read the dataset.hidden to meta.hidden at initializion and only use meta.hidden runtime. Provide hide() and show() for developer access. But not in the scope of this PR.
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
visible
be made private (i.e._visible
) since we may change it in the future? (maybe even worth adding a TODO to make the change you suggested)