Skip to content

Commit 6495ba1

Browse files
Ben RUBSONtorkelo
authored andcommitted
Correct timeStep in case of missing values (grafana#6526)
* Correct timeStep in case of missing values * Comment
1 parent 2443326 commit 6495ba1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

public/app/core/time_series2.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ export default class TimeSeries {
115115
currentValue = this.datapoints[i][0];
116116
currentTime = this.datapoints[i][1];
117117

118+
// Due to missing values we could have different timeStep all along the series
119+
// so we have to find the minimum one (could occur with aggregators such as ZimSum)
120+
if (i>0) {
121+
var previousTime = this.datapoints[i-1][1];
122+
if (!this.stats.timeStep || currentTime - previousTime < this.stats.timeStep) {
123+
this.stats.timeStep = currentTime - previousTime;
124+
}
125+
}
126+
118127
if (currentValue === null) {
119128
if (ignoreNulls) { continue; }
120129
if (nullAsZero) {
@@ -145,10 +154,6 @@ export default class TimeSeries {
145154
result.push([currentTime, currentValue]);
146155
}
147156

148-
if (this.datapoints.length >= 2) {
149-
this.stats.timeStep = this.datapoints[1][1] - this.datapoints[0][1];
150-
}
151-
152157
if (this.stats.max === -Number.MAX_VALUE) { this.stats.max = null; }
153158
if (this.stats.min === Number.MAX_VALUE) { this.stats.min = null; }
154159

0 commit comments

Comments
 (0)