Prechádzať zdrojové kódy

Graph: change to current legend value handling, if last value is null, current will pick next to last value, Closes #190

Torkel Ödegaard 11 rokov pred
rodič
commit
4eb4974909

+ 3 - 0
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;

+ 9 - 0
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() {