]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Assume time series data has been normalized (#6775)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Sat, 23 Nov 2019 22:37:32 +0000 (14:37 -0800)
committerEvert Timberg <evert.timberg+github@gmail.com>
Sat, 23 Nov 2019 22:37:32 +0000 (17:37 -0500)
* Assume time series data has been normalized

* Add sentance to docs

docs/axes/cartesian/time.md
src/scales/scale.time.js

index 157d6c612f4f988fbb347407fe51750a93e2f8f2..ff39464764c27db418ce7d372fe7072c5b2eb493 100644 (file)
@@ -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).
index ae751ac94bf92725069f4849cb68a4d5191037ae..3beb2afa8badaf33854abe2bb989b13c8cb2d26c 100644 (file)
@@ -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));
        }
@@ -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;
@@ -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;