Commit d6eaaf3a by Torkel Ödegaard

refactor: minor refactoring

parent 68bb417d
......@@ -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;
}
}
}
......
......@@ -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');
});
});
......
......@@ -2,17 +2,8 @@ var template = `
<div class="graph-wrapper" ng-class="{'graph-legend-rightside': ctrl.panel.legend.rightSide}">
<div class="graph-canvas-wrapper">
<div class="datapoints-warning" ng-show="ctrl.datapointsCount===0">
<span class="small" >
No datapoints <tip>No datapoints returned from metric query</tip>
</span>
</div>
<div class="datapoints-warning" ng-show="ctrl.datapointsOutside">
<span class="small">
Datapoints outside time range
<tip>Can be caused by timezone mismatch between browser and graphite server</tip>
</span>
<div class="datapoints-warning" ng-if="ctrl.dataWarning">
<span class="small" bs-tooltip="ctrl.dataWarning.tip">{{ctrl.dataWarning.title}}</span>
</div>
<div grafana-graph class="histogram-chart" ng-dblclick="ctrl.zoomOut()">
......
......@@ -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);
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment