From 7c4d1b7b01b40d5e64f70069557a14ab22420556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 16 Oct 2014 13:44:52 -0400 Subject: [PATCH] StatsPanel: made big values template based --- src/app/panels/stats/module.js | 51 +++++++++++++++------------ src/app/panels/stats/statsEditor.html | 13 ++++--- src/css/less/stats-panel.less | 4 +-- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/app/panels/stats/module.js b/src/app/panels/stats/module.js index 572ef040572..470faa5f0c4 100644 --- a/src/app/panels/stats/module.js +++ b/src/app/panels/stats/module.js @@ -39,12 +39,18 @@ function (angular, app, _, TimeSeries, kbn) { targets: [{}], cacheTimeout: null, format: 'none', - avg: true, - stats: true, - table: true, + stats: { + show: true, + avg: true, + template: '{{value}} {{func}}' + }, + table: { + show: true, + } }; _.defaults($scope.panel, _d); + _.defaults($scope.panel.stats, _d.stats); $scope.init = function() { panelSrv.init($scope); @@ -121,19 +127,6 @@ function (angular, app, _, TimeSeries, kbn) { series.updateLegendValues(kbn.valueFormats[$scope.panel.format], 2, -7); } - var main = data.series[0]; - - if ($scope.panel.avg) { - data.stats.push({ value: $scope.formatValue(main.stats.avg), func: 'avg' }); - } - if ($scope.panel.total) { - data.stats.push({ value: $scope.formatValue(main.stats.total), func: 'total' }); - } - if ($scope.panel.current) { - data.stats.push({ value: $scope.formatValue(main.stats.current), func: 'current' }); - } - - $scope.data = data; $scope.$emit('render'); }; @@ -146,8 +139,9 @@ function (angular, app, _, TimeSeries, kbn) { return { link: function(scope, elem) { var data; + var valueRegex = /\{\{([a-zA-Z]+)\}\}/g; + var smallValueTextRegex = /!(\S+)/g; - console.log('asd'); scope.$on('render', function() { data = scope.data; @@ -159,20 +153,31 @@ function (angular, app, _, TimeSeries, kbn) { render(); }); + function valueTemplateReplaceFunc(match, statType) { + var stats = data.series[0].stats; + var value = scope.formatValue(stats[statType]); + return value; + } + + function smallValueTextReplaceFunc(match, text) { + return '' + text + ''; + } + function render() { + var panel = scope.panel; var body = ''; var i, series; - if (scope.panel.stats) { + if (panel.stats.show) { body += '
'; - for (i = 0; i < scope.data.stats.length; i++) { - body += '' + data.stats[i].value + ''; - body += ' (' + data.stats[i].func + ')'; - } + body += ''; + var valueHtml = panel.stats.template.replace(valueRegex, valueTemplateReplaceFunc); + body += valueHtml.replace(smallValueTextRegex, smallValueTextReplaceFunc); + body += '
'; body += ''; } - if (scope.panel.table) { + if (panel.table.show) { body += ''; body += ''; body += ''; diff --git a/src/app/panels/stats/statsEditor.html b/src/app/panels/stats/statsEditor.html index 297738ef218..98df3dda258 100644 --- a/src/app/panels/stats/statsEditor.html +++ b/src/app/panels/stats/statsEditor.html @@ -1,16 +1,15 @@
Main options
- - + +
Big values
- - - - - +
+ + +
Formats
diff --git a/src/css/less/stats-panel.less b/src/css/less/stats-panel.less index ad1ad017628..34bbefd806d 100644 --- a/src/css/less/stats-panel.less +++ b/src/css/less/stats-panel.less @@ -12,8 +12,8 @@ padding-left: 20px; } -.stats-panel-func { - font-size: 1.5em; +.stats-panel-value-small { + font-size: 50%; } .stats-panel-table {
avgminmaxcurrenttotal