-
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
Shared data between charts #2346
Conversation
addElementAndReset: function(index) { | ||
this.getDataset().metaData = this.getDataset().metaData || []; |
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.
Is the meta.data array defined somewhere else?
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.
Accessing meta info requires to use the getDatasetMeta() (or getMeta() on a dataset controller), which will build the meta object (so the meta.data array).
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.
Actually, we should never access the _meta object directly, but always rely on the get(Dataset)Meta() accessors. This to ensure that meta are initialized, but also in the case we decide to change where we store these meta info.
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.
Ok, perfect. I haven't gotten that far down yet so that jumped out at me.
The |
4935990
to
517d9a9
Compare
Yes, I plan to fix this sample while working on the tests |
@etimberg, can you please review my fix in the last commit? |
Changes Unknown when pulling c2c09b6 on simonbrunel:shared-data into * on chartjs:master*. |
@simonbrunel looks good |
This is great! |
Changes Unknown when pulling ac7e267 on simonbrunel:shared-data into * on chartjs:master*. |
@etimberg @tannerlinsley @zachpanz88: commit ac7e267 is a rewrite of some tests using the new meta data structure. It would be nice to review it because I had to change a lot of code and might have change the tests logic. |
@simonbrunel I'll have a detailed look tonight. |
At first glance the test changes look good 👍 |
ac7e267
to
d74e97c
Compare
Changes Unknown when pulling d74e97c on simonbrunel:shared-data into * on chartjs:master*. |
d74e97c
to
6b12796
Compare
49e935b
to
dee0485
Compare
Meta info are now scoped by chart and moved under the dataset._meta map { chart.id -> meta }. Meta for a specific chart (and dataset) can be accessed using chart.getDatasetMeta(datasetIndex) or from the dataset controller using getMeta(). Note that helpers.uid() now generates an int (instead of a string) to make lookups in the _meta map faster.
Dataset effective type is now stored under meta.type, allowing many charts to share the same dataset but with different types. Also move dataset.bar flag to meta.bar.
Introduced a new meta.hidden 3 states flag (null|true|false) to be able to override dataset.hidden when interacting with the chart (i.e., true or false to ignore the dataset.hidden value). This is required in order to be able to correctly share dataset.hidden between multiple charts. For example: 2 charts are sharing the same data and dataset.hidden is initially false: the dataset will be displayed on both charts because meta.hidden is null. If the user clicks the legend of the first chart, meta.hidden is changed to true and the dataset is only hidden on the first chart. If dataset.hidden changes, only the second chart will have the dataset visibility updated and that until the user click again on the first chart legend, switching the meta.hidden to null.
New Chart.Element.hidden bool flag storing the visibility state of its associated data. Since elements belong to a specific chart, this change allows to manage data visibility per chart (e.g. when clicking the legend of some charts). This commit also changes (fixes?) the polar chart animation when data visibility changes. Previous implementation was affected by an edge effect due to the use of NaN as hidden implementation.
Fix access of uninitialized meta data while calculating circumference in the polar area chart by caching the number of visible elements in the update() method. Also make the calculateTotal() of the doughnut chart tolerant of uninitialized meta data.
Since we changed the way how meta data are stores, now unit tests need to work on real Chart instances. This commit brings some helpers to inject/cleanup HTML canvas and it's wrapper into/from the DOM.
Because of differences between testing platforms, introduce a new matcher for (floating) pixel values comparison (currently 2 pixels tolerance).
Also replace the 2 spaces indentation in controller.bar.tests.js by tabs to match the overall code style.
dee0485
to
e0353da
Compare
83b98dd
to
eb14481
Compare
As agreed with @etimberg, I disabled failing tests to be able to merge that PR. The list includes the following suites (can be updated in
Note: |
Important: This PR breaks all tests because now it requires to work on a real chart instance (not a fake chart/context). Modifying all tests will require an important effort, so I prefer to be sure we want to merge these changes before rewriting all tests.
Note: Since this PR is pretty big and touches almost all files, it would be great to consider merging it as soon as possible to avoid too many conflicts with upcoming contributions.
This PR allows sharing config.data between multiple chart instances (charts can be of different types). For details, please review commit messages which should be enough to understand changes. But basically, I moved all meta info under dataset._meta, which is a map from chart id to meta info (chart id is now an integer to speed up lookups).
left: master | right: PR
Also changed (fixed) the polar show/hide animations as talk on Slack: