From 73dcd9e11ae47eebf1fc439b7ca507482ea88554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Sun, 2 Mar 2014 13:26:08 +0100 Subject: [PATCH] improvement to bar width --- src/app/directives/grafanaGraph.js | 9 +++++---- src/app/panels/graphite/module.js | 6 ++++++ src/app/panels/graphite/timeSeries.js | 5 +++++ src/app/partials/metrics.html | 4 ++-- src/app/services/datasourceSrv.js | 3 +++ 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/app/directives/grafanaGraph.js b/src/app/directives/grafanaGraph.js index 44e645ea6d2..edbdeeb931a 100644 --- a/src/app/directives/grafanaGraph.js +++ b/src/app/directives/grafanaGraph.js @@ -75,9 +75,6 @@ function (angular, $, kbn, moment, _) { } }); - // Set barwidth based on specified interval - var barwidth = kbn.interval_to_ms(scope.interval); - var stack = panel.stack ? true : null; // Populate element @@ -96,7 +93,7 @@ function (angular, $, kbn, moment, _) { bars: { show: panel.bars, fill: 1, - barWidth: barwidth/1.5, + barWidth: 1, zero: false, lineWidth: 0 }, @@ -128,6 +125,10 @@ function (angular, $, kbn, moment, _) { data[i].data = _d; } + if (panel.bars && data.length && data[0].info.timeStep) { + options.series.bars.barWidth = data[0].info.timeStep / 1.5; + } + addTimeAxis(options); addGridThresholds(options, panel); addAnnotations(options); diff --git a/src/app/panels/graphite/module.js b/src/app/panels/graphite/module.js index 8fd982bddf6..c8f2642fc8b 100644 --- a/src/app/panels/graphite/module.js +++ b/src/app/panels/graphite/module.js @@ -213,6 +213,12 @@ function (angular, app, $, _, kbn, moment, timeSeries) { $scope.setDatasource = function(datasource) { $scope.panel.datasource = datasource; $scope.datasource = datasourceSrv.get(datasource); + + if (!$scope.datasource) { + $scope.panel.error = "Cannot find datasource " + datasource; + return; + } + $scope.get_data(); }; diff --git a/src/app/panels/graphite/timeSeries.js b/src/app/panels/graphite/timeSeries.js index ec15f17aaf9..9d4fad7f6e4 100644 --- a/src/app/panels/graphite/timeSeries.js +++ b/src/app/panels/graphite/timeSeries.js @@ -50,7 +50,12 @@ function (_, kbn) { result.push([currentTime * 1000, currentValue]); }, this); + if (result.length > 2) { + this.info.timeStep = result[1][0] - result[0][0]; + } + if (result.length) { + this.info.avg = (this.info.total / result.length); this.info.current = result[result.length-1][1]; diff --git a/src/app/partials/metrics.html b/src/app/partials/metrics.html index cc5446e12d0..02654ebdc90 100644 --- a/src/app/partials/metrics.html +++ b/src/app/partials/metrics.html @@ -5,13 +5,13 @@
- + -
+ diff --git a/src/app/services/datasourceSrv.js b/src/app/services/datasourceSrv.js index 1bc4c4407a6..9a943fb5044 100644 --- a/src/app/services/datasourceSrv.js +++ b/src/app/services/datasourceSrv.js @@ -20,6 +20,9 @@ function (angular, _, config) { if (!name) { return this.default; } var ds = config.datasources[name]; + if (!ds) { + return null; + } switch(ds.type) { case 'graphite':