Skip to content

Commit

Permalink
Assume time series data has been normalized (#6775)
Browse files Browse the repository at this point in the history
* Assume time series data has been normalized

* Add sentance to docs
  • Loading branch information
benmccann authored and etimberg committed Nov 23, 2019
1 parent 62bbaeb commit fb3cad0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/axes/cartesian/time.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,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

0 comments on commit fb3cad0

Please sign in to comment.