From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sat, 23 Nov 2019 22:37:32 +0000 (-0800) Subject: Assume time series data has been normalized (#6775) X-Git-Tag: v3.0.0-alpha~216 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb3cad0b9491664f5913298ff32511e59a707503;p=thirdparty%2FChart.js.git Assume time series data has been normalized (#6775) * Assume time series data has been normalized * Add sentance to docs --- diff --git a/docs/axes/cartesian/time.md b/docs/axes/cartesian/time.md index 157d6c612..ff3946476 100644 --- a/docs/axes/cartesian/time.md +++ b/docs/axes/cartesian/time.md @@ -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). diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index ae751ac94..3beb2afa8 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -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;