From d6eaaf3add7741e13da58b940496db5e6080dd11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 23 Feb 2017 15:56:37 +0100 Subject: [PATCH] refactor: minor refactoring --- public/app/plugins/panel/graph/module.ts | 25 +++++++++---- .../panel/graph/specs/graph_ctrl_specs.ts | 12 +++---- public/app/plugins/panel/graph/template.ts | 13 ++----- public/test/core/time_series_specs.js | 36 ++++++++++--------- 4 files changed, 46 insertions(+), 40 deletions(-) diff --git a/public/app/plugins/panel/graph/module.ts b/public/app/plugins/panel/graph/module.ts index 1a8fb3c0481..01f7a485aa6 100644 --- a/public/app/plugins/panel/graph/module.ts +++ b/public/app/plugins/panel/graph/module.ts @@ -26,8 +26,7 @@ class GraphCtrl extends MetricsPanelCtrl { alertState: any; annotationsPromise: any; - datapointsCount: number; - datapointsOutside: boolean; + dataWarning: any; colors: any = []; subTabIndex: number; processor: DataProcessor; @@ -178,14 +177,26 @@ class GraphCtrl extends MetricsPanelCtrl { this.dataList = dataList; this.seriesList = this.processor.getSeriesList({dataList: dataList, range: this.range}); - this.datapointsCount = this.seriesList.reduce((prev, series) => { + this.dataWarning = null; + const datapointsCount = this.seriesList.reduce((prev, series) => { return prev + series.datapoints.length; }, 0); - this.datapointsOutside = false; - for (let series of this.seriesList) { - if (series.isOutsideRange) { - this.datapointsOutside = true; + if (datapointsCount === 0) { + this.dataWarning = { + title: 'No data points', + tip: 'No datapoints returned from data query' + }; + } else { + + for (let series of this.seriesList) { + if (series.isOutsideRange) { + this.dataWarning = { + title: 'Data points outside time range', + tip: 'Can be caused by timezone mismatch or missing time filter in query', + }; + break; + } } } diff --git a/public/app/plugins/panel/graph/specs/graph_ctrl_specs.ts b/public/app/plugins/panel/graph/specs/graph_ctrl_specs.ts index d06c66e253a..ab91b87ece9 100644 --- a/public/app/plugins/panel/graph/specs/graph_ctrl_specs.ts +++ b/public/app/plugins/panel/graph/specs/graph_ctrl_specs.ts @@ -35,7 +35,7 @@ describe('GraphCtrl', function() { }); it('should set datapointsOutside', function() { - expect(ctx.ctrl.datapointsOutside).to.be(true); + expect(ctx.ctrl.dataWarning.title).to.be('Data points outside time range'); }); }); @@ -55,21 +55,21 @@ describe('GraphCtrl', function() { }); it('should set datapointsOutside', function() { - expect(ctx.ctrl.datapointsOutside).to.be(false); + expect(ctx.ctrl.dataWarning).to.be(null); }); }); describe('datapointsCount given 2 series', function() { beforeEach(function() { var data = [ - {target: 'test.cpu1', datapoints: [[45, 1234567890], [60, 1234567899]]}, - {target: 'test.cpu2', datapoints: [[45, 1234567890]]}, + {target: 'test.cpu1', datapoints: []}, + {target: 'test.cpu2', datapoints: []}, ]; ctx.ctrl.onDataReceived(data); }); - it('should set datapointsCount to sum of datapoints', function() { - expect(ctx.ctrl.datapointsCount).to.be(3); + it('should set datapointsCount warning', function() { + expect(ctx.ctrl.dataWarning.title).to.be('No data points'); }); }); diff --git a/public/app/plugins/panel/graph/template.ts b/public/app/plugins/panel/graph/template.ts index ec6cd8d0907..6ded97ce33a 100644 --- a/public/app/plugins/panel/graph/template.ts +++ b/public/app/plugins/panel/graph/template.ts @@ -2,17 +2,8 @@ var template = `
-
- - No datapoints No datapoints returned from metric query - -
- -
- - Datapoints outside time range - Can be caused by timezone mismatch between browser and graphite server - +
+ {{ctrl.dataWarning.title}}
diff --git a/public/test/core/time_series_specs.js b/public/test/core/time_series_specs.js index 829f74d3515..04efa8a2249 100644 --- a/public/test/core/time_series_specs.js +++ b/public/test/core/time_series_specs.js @@ -6,12 +6,16 @@ define([ describe("TimeSeries", function() { var points, series; var yAxisFormats = ['short', 'ms']; - var testData = { - alias: 'test', - datapoints: [ - [1,2],[null,3],[10,4],[8,5] - ] - }; + var testData; + + beforeEach(function() { + testData = { + alias: 'test', + datapoints: [ + [1,2],[null,3],[10,4],[8,5] + ] + }; + }); describe('when getting flot pairs', function() { it('with connected style, should ignore nulls', function() { @@ -51,40 +55,40 @@ define([ it('the delta value should account for nulls', function() { series = new TimeSeries({ - datapoints: [[1,2],[3,3],[null,4],[10,5],[15,6]] - }); + datapoints: [[1,2],[3,3],[null,4],[10,5],[15,6]] + }); series.getFlotPairs('null', yAxisFormats); expect(series.stats.delta).to.be(14); }); it('the delta value should account for nulls on first', function() { series = new TimeSeries({ - datapoints: [[null,2],[1,3],[10,4],[15,5]] - }); + datapoints: [[null,2],[1,3],[10,4],[15,5]] + }); series.getFlotPairs('null', yAxisFormats); expect(series.stats.delta).to.be(14); }); it('the delta value should account for nulls on last', function() { series = new TimeSeries({ - datapoints: [[1,2],[5,3],[10,4],[null,5]] - }); + datapoints: [[1,2],[5,3],[10,4],[null,5]] + }); series.getFlotPairs('null', yAxisFormats); expect(series.stats.delta).to.be(9); }); it('the delta value should account for resets', function() { series = new TimeSeries({ - datapoints: [[1,2],[5,3],[10,4],[0,5],[10,6]] - }); + datapoints: [[1,2],[5,3],[10,4],[0,5],[10,6]] + }); series.getFlotPairs('null', yAxisFormats); expect(series.stats.delta).to.be(19); }); it('the delta value should account for resets on last', function() { series = new TimeSeries({ - datapoints: [[1,2],[2,3],[10,4],[8,5]] - }); + datapoints: [[1,2],[2,3],[10,4],[8,5]] + }); series.getFlotPairs('null', yAxisFormats); expect(series.stats.delta).to.be(17); });