From 2a962bf8fde735cf6ce8a1d0d3547272522bb2ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 6 Nov 2014 09:56:50 +0100 Subject: [PATCH] Singlestat: progress on singlestat panel --- src/app/panels/graph/module.js | 7 ------- src/app/panels/stats/module.js | 22 +++++++++++++--------- src/app/panels/stats/statsDirective.js | 26 +++++++++----------------- src/app/panels/stats/statsEditor.html | 17 ++++++++++++++--- src/app/services/panelSrv.js | 8 ++++++++ 5 files changed, 44 insertions(+), 36 deletions(-) diff --git a/src/app/panels/graph/module.js b/src/app/panels/graph/module.js index fa7bed1cf65..ae50e372c7c 100644 --- a/src/app/panels/graph/module.js +++ b/src/app/panels/graph/module.js @@ -347,13 +347,6 @@ function (angular, app, $, _, kbn, moment, TimeSeries) { $scope.render(); }; - $scope.toggleEditorHelp = function(index) { - if ($scope.editorHelpIndex === index) { - $scope.editorHelpIndex = null; - return; - } - $scope.editorHelpIndex = index; - }; panelSrv.init($scope); }); diff --git a/src/app/panels/stats/module.js b/src/app/panels/stats/module.js index d5fdc9e38ac..f85a1df62e5 100644 --- a/src/app/panels/stats/module.js +++ b/src/app/panels/stats/module.js @@ -40,7 +40,9 @@ function (angular, app, _, TimeSeries, kbn) { targets: [{}], cacheTimeout: null, format: 'none', - template: '{{avg}} !(avg)', + prefix: '', + postfix: '', + valueName: 'avg', thresholds: '', colorBackground: false, colorValue: false, @@ -103,7 +105,7 @@ function (angular, app, _, TimeSeries, kbn) { info: { alias: seriesData.target }, }); - series.data = series.getFlotPairs('connected'); + series.flotpairs = series.getFlotPairs('connected'); return series; }; @@ -128,15 +130,17 @@ function (angular, app, _, TimeSeries, kbn) { }; $scope.render = function() { - var i, series; - var data = { - series: $scope.series, - stats: [] - }; + var data = {}; - for (i = 0; i < data.series.length; i++) { - series = data.series[i]; + if (!$scope.series || $scope.series.length === 0) { + data.series = { mainValue: null, datapoints: [] }; + } + else { + var series = $scope.series[0]; series.updateLegendValues(kbn.valueFormats[$scope.panel.format], 2, -7); + data.mainValue = series.stats[$scope.panel.valueName]; + data.mainValueFormated = $scope.formatValue(data.mainValue); + data.flotpairs = series.flotpairs; } data.thresholds = $scope.panel.thresholds.split(',').map(function(strVale) { diff --git a/src/app/panels/stats/statsDirective.js b/src/app/panels/stats/statsDirective.js index 19d7e39b477..cc8b1c43e6a 100644 --- a/src/app/panels/stats/statsDirective.js +++ b/src/app/panels/stats/statsDirective.js @@ -18,15 +18,12 @@ function (angular, app, _, kbn, $) { return { link: function(scope, elem) { var data; - var valueRegex = /\{\{([a-zA-Z]+)\}\}/g; - var smallValueTextRegex = /!(\S+)/g; var $panelContainer = elem.parents('.panel-container'); scope.$on('render', function() { data = scope.data; - data.mainValue = null; - if (!data || data.series.length === 0) { + if (!data || data.flotpairs.length === 0) { elem.html('no data'); return; } @@ -73,15 +70,8 @@ function (angular, app, _, kbn, $) { return null; } - function valueTemplateReplaceFunc(match, statType) { - var stats = data.series[0].stats; - data.mainValue = stats[statType]; - var valueFormated = scope.formatValue(data.mainValue); - return applyColoringThresholds(data.mainValue, valueFormated); - } - - function smallValueTextReplaceFunc(match, text) { - return '' + text + ''; + function getBigValueHtml() { + return applyColoringThresholds(data.mainValue, data.mainValueFormated); } function addSparkline() { @@ -130,10 +120,13 @@ function (angular, app, _, kbn, $) { elem.append(plotCanvas); - data.series[0].color = panel.sparkline.lineColor; + var plotSeries = { + data: data.flotpairs, + color: panel.sparkline.lineColor + }; setTimeout(function() { - $.plot(plotCanvas, [data.series[0]], options); + $.plot(plotCanvas, [plotSeries], options); }, 10); } @@ -145,8 +138,7 @@ function (angular, app, _, kbn, $) { body += '
'; body += ''; - var valueHtml = panel.template.replace(valueRegex, valueTemplateReplaceFunc); - body += valueHtml.replace(smallValueTextRegex, smallValueTextReplaceFunc); + body += getBigValueHtml(); body += '
'; body += ''; diff --git a/src/app/panels/stats/statsEditor.html b/src/app/panels/stats/statsEditor.html index 0406fecd7de..7ca1ab107af 100644 --- a/src/app/panels/stats/statsEditor.html +++ b/src/app/panels/stats/statsEditor.html @@ -1,9 +1,17 @@
-
Big values
+
Big value
- - + + +
+
+ + +
+
+ +
@@ -39,6 +47,9 @@
+
+
+
diff --git a/src/app/services/panelSrv.js b/src/app/services/panelSrv.js index 4563f3ad6c8..faa37b4e057 100644 --- a/src/app/services/panelSrv.js +++ b/src/app/services/panelSrv.js @@ -99,6 +99,14 @@ function (angular, _) { $scope.get_data(); }; + $scope.toggleEditorHelp = function(index) { + if ($scope.editorHelpIndex === index) { + $scope.editorHelpIndex = null; + return; + } + $scope.editorHelpIndex = index; + }; + $scope.toggleFullscreen = function(edit) { $scope.dashboardViewState.update({ fullscreen: true, edit: edit, panelId: $scope.panel.id }); };