Fix bar chart with {x, y} data points#4673
Conversation
- Use a value scale to check the value when drawing bars - Add null check in arrayUnique() - Fix document issue
src/scales/scale.time.js
Outdated
| for (i = 0, ilen = items.length; i < ilen; ++i) { | ||
| item = items[i]; | ||
| if (!hash[item]) { | ||
| if (item !== null && !hash[item]) { |
There was a problem hiding this comment.
Then that's not anymore arrayUnique if it filters null values. Can we make that check elsewhere without iterating the whole array?
There was a problem hiding this comment.
We can filter null out when the timestamps array is built, but not for the labels array because it is copied to datasets later.
Maybe we can do this way.
labels = arrayUnique(labels).sort(sorter);
if (labels[0] === null) {
labels.shift();
}
timestamps = arrayUnique(timestamps).sort(sorter);
if (timestamps[0] === null) {
timestamps.shift();
}
There was a problem hiding this comment.
Ah, it doesn't work because a timestamp can be a negative value. We need to prepare both labels that doesn't contain null and rawLabels that can contain null.
There was a problem hiding this comment.
negative timestamp would be before 1-1-1970
There was a problem hiding this comment.
Moved the null check to the outside of arrayUnique.
src/scales/scale.time.js
Outdated
| for (i = 0, ilen = chart.data.labels.length; i < ilen; ++i) { | ||
| labels.push(parse(chart.data.labels[i], me)); | ||
| timestamp = parse(chart.data.labels[i], me); | ||
| if (timestamp !== null) { |
There was a problem hiding this comment.
@etimberg do we support null in the data.labels array (what use case)? If not, I would consider that as an error and would avoid duplicating the labels timestamps array with rawLabels.
There was a problem hiding this comment.
I don't think null should be in data.labels
|
@nagix are you sure we are actually checking the correct cases? I think we just want to skip labels: ['2017', null, '2018'] // INVALID (what does that mean?)
data: [{x: null, y: 42}] // INVALID (what does that mean?)
data: [42, null, 16] // VALID (skip the second value mapped to the second label) |
|
@simonbrunel Actually it is intended to check if timestamps are correctly parsed by |
|
Agreed. I removed null timestamp checks. |
|
Can we merge this then? |
Uh oh!
There was an error while loading. Please reload this page.