From 4eb4974909d4af4cf55f49553585a2722101654d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 12 Nov 2014 13:47:06 +0100 Subject: [PATCH] Graph: change to current legend value handling, if last value is null, current will pick next to last value, Closes #190 --- src/app/components/timeSeries.js | 3 +++ src/test/specs/timeSeries-specs.js | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/app/components/timeSeries.js b/src/app/components/timeSeries.js index 6d54239a0bc..f9329141640 100644 --- a/src/app/components/timeSeries.js +++ b/src/app/components/timeSeries.js @@ -112,6 +112,9 @@ function (_, kbn) { if (result.length) { this.stats.avg = (this.stats.total / result.length); this.stats.current = result[result.length-1][1]; + if (this.stats.current === null && result.length > 1) { + this.stats.current = result[result.length-2][1]; + } } return result; diff --git a/src/test/specs/timeSeries-specs.js b/src/test/specs/timeSeries-specs.js index a2c52dadf57..e68ce16d54e 100644 --- a/src/test/specs/timeSeries-specs.js +++ b/src/test/specs/timeSeries-specs.js @@ -26,6 +26,15 @@ define([ expect(points.length).to.be(4); expect(points[1][1]).to.be(0); }); + + it('if last is null current should pick next to last', function() { + series = new TimeSeries({ + datapoints: [[10,1], [null, 2]] + }); + series.getFlotPairs('null', yAxisFormats); + expect(series.stats.current).to.be(10); + }); + }); describe('series overrides', function() {