From 6495ba155af148c0a76eb5c5f254d406edb62cc7 Mon Sep 17 00:00:00 2001 From: Ben RUBSON Date: Thu, 10 Nov 2016 10:20:27 +0100 Subject: [PATCH] Correct timeStep in case of missing values (#6526) * Correct timeStep in case of missing values * Comment --- public/app/core/time_series2.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/public/app/core/time_series2.ts b/public/app/core/time_series2.ts index d672e0dd0dc..3d99b43704e 100644 --- a/public/app/core/time_series2.ts +++ b/public/app/core/time_series2.ts @@ -115,6 +115,15 @@ export default class TimeSeries { currentValue = this.datapoints[i][0]; currentTime = this.datapoints[i][1]; + // Due to missing values we could have different timeStep all along the series + // so we have to find the minimum one (could occur with aggregators such as ZimSum) + if (i>0) { + var previousTime = this.datapoints[i-1][1]; + if (!this.stats.timeStep || currentTime - previousTime < this.stats.timeStep) { + this.stats.timeStep = currentTime - previousTime; + } + } + if (currentValue === null) { if (ignoreNulls) { continue; } if (nullAsZero) { @@ -145,10 +154,6 @@ export default class TimeSeries { result.push([currentTime, currentValue]); } - if (this.datapoints.length >= 2) { - this.stats.timeStep = this.datapoints[1][1] - this.datapoints[0][1]; - } - if (this.stats.max === -Number.MAX_VALUE) { this.stats.max = null; } if (this.stats.min === Number.MAX_VALUE) { this.stats.min = null; }