Skip to content
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

Assume time series data has been normalized #6775

Merged
merged 2 commits into from
Nov 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/axes/cartesian/time.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ var chart = new Chart(ctx, {
});
```

When the scale is in `series` mode, the data indices are expected to be unique, sorted, and consistent across datasets.

### Scale Bounds

The `bounds` property controls the scale boundary strategy (bypassed by `min`/`max` time options).
Expand Down
21 changes: 14 additions & 7 deletions src/scales/scale.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,20 @@ function ticksFromTimestamps(scale, values, majorUnit) {
}

function getDataTimestamps(scale) {
var timestamps = scale._cache.data || [];
var i, ilen, metas;
const isSeries = scale.options.distribution === 'series';
let timestamps = scale._cache.data || [];
let i, ilen, metas;

if (timestamps.length) {
return timestamps;
}

metas = scale._getMatchingVisibleMetas();

if (isSeries && metas.length) {
return metas[0].controller._getAllParsedValues(scale);
}

for (i = 0, ilen = metas.length; i < ilen; ++i) {
timestamps = timestamps.concat(metas[i].controller._getAllParsedValues(scale));
}
Expand All @@ -377,8 +383,9 @@ function getDataTimestamps(scale) {
}

function getLabelTimestamps(scale) {
var timestamps = scale._cache.labels || [];
var i, ilen, labels;
const isSeries = scale.options.distribution === 'series';
const timestamps = scale._cache.labels || [];
let i, ilen, labels;

if (timestamps.length) {
return timestamps;
Expand All @@ -390,12 +397,12 @@ function getLabelTimestamps(scale) {
}

// We could assume labels are in order and unique - but let's not
return (scale._cache.labels = arrayUnique(timestamps.sort(sorter)));
return (scale._cache.labels = isSeries ? timestamps : arrayUnique(timestamps.sort(sorter)));
}

function getAllTimestamps(scale) {
var timestamps = scale._cache.all || [];
var label, data;
let timestamps = scale._cache.all || [];
let label, data;

if (timestamps.length) {
return timestamps;
Expand Down