Commit 956d93e8 by Torkel Ödegaard

StatsPanel: fine tuning colors

parent 7c4d1b7b
...@@ -44,6 +44,12 @@ function (angular, app, _, TimeSeries, kbn) { ...@@ -44,6 +44,12 @@ function (angular, app, _, TimeSeries, kbn) {
avg: true, avg: true,
template: '{{value}} {{func}}' template: '{{value}} {{func}}'
}, },
coloring: {
thresholds: '',
background: false,
value: false,
colors: ["rgba(245, 54, 54, 0.9)", "rgba(237, 129, 40, 0.89)", "rgba(50, 172, 45, 0.97)"]
},
table: { table: {
show: true, show: true,
} }
...@@ -51,6 +57,7 @@ function (angular, app, _, TimeSeries, kbn) { ...@@ -51,6 +57,7 @@ function (angular, app, _, TimeSeries, kbn) {
_.defaults($scope.panel, _d); _.defaults($scope.panel, _d);
_.defaults($scope.panel.stats, _d.stats); _.defaults($scope.panel.stats, _d.stats);
_.defaults($scope.panel.coloring, _d.coloring);
$scope.init = function() { $scope.init = function() {
panelSrv.init($scope); panelSrv.init($scope);
...@@ -115,6 +122,25 @@ function (angular, app, _, TimeSeries, kbn) { ...@@ -115,6 +122,25 @@ function (angular, app, _, TimeSeries, kbn) {
return series; return series;
}; };
$scope.setColoring = function(options) {
if (options.background) {
$scope.panel.coloring.value = false;
$scope.panel.coloring.colors = ['rgba(71, 212, 59, 0.4)', 'rgba(245, 150, 40, 0.73)', 'rgba(225, 40, 40, 0.59)'];
}
else {
$scope.panel.coloring.background = false;
$scope.panel.coloring.colors = ['rgba(50, 172, 45, 0.97)', 'rgba(237, 129, 40, 0.89)', 'rgba(245, 54, 54, 0.9)'];
}
$scope.render();
};
$scope.invertColorOrder = function() {
var tmp = $scope.panel.coloring.colors[0];
$scope.panel.coloring.colors[0] = $scope.panel.coloring.colors[2];
$scope.panel.coloring.colors[2] = tmp;
$scope.render();
};
$scope.render = function() { $scope.render = function() {
var i, series; var i, series;
var data = { var data = {
...@@ -127,6 +153,12 @@ function (angular, app, _, TimeSeries, kbn) { ...@@ -127,6 +153,12 @@ function (angular, app, _, TimeSeries, kbn) {
series.updateLegendValues(kbn.valueFormats[$scope.panel.format], 2, -7); series.updateLegendValues(kbn.valueFormats[$scope.panel.format], 2, -7);
} }
data.thresholds = $scope.panel.coloring.thresholds.split(',').map(function(strVale) {
return Number(strVale.trim());
});
data.colorMap = $scope.panel.coloring.colors;
$scope.data = data; $scope.data = data;
$scope.$emit('render'); $scope.$emit('render');
}; };
...@@ -144,6 +176,7 @@ function (angular, app, _, TimeSeries, kbn) { ...@@ -144,6 +176,7 @@ function (angular, app, _, TimeSeries, kbn) {
scope.$on('render', function() { scope.$on('render', function() {
data = scope.data; data = scope.data;
data.mainValue = null;
if (!data || data.series.length === 0) { if (!data || data.series.length === 0) {
elem.html('no data'); elem.html('no data');
...@@ -153,10 +186,33 @@ function (angular, app, _, TimeSeries, kbn) { ...@@ -153,10 +186,33 @@ function (angular, app, _, TimeSeries, kbn) {
render(); render();
}); });
function applyColoringThresholds(value, valueString) {
if (!scope.panel.coloring.value) {
return valueString;
}
var color = getColorForValue(value);
if (color) {
return '<span style="color:' + color + '">'+ valueString + '</span>';
}
return valueString;
}
function getColorForValue(value) {
for (var i = data.thresholds.length - 1; i >= 0 ; i--) {
if (value > data.thresholds[i]) {
return data.colorMap[i];
}
}
return null;
}
function valueTemplateReplaceFunc(match, statType) { function valueTemplateReplaceFunc(match, statType) {
var stats = data.series[0].stats; var stats = data.series[0].stats;
var value = scope.formatValue(stats[statType]); data.mainValue = stats[statType];
return value; var valueFormated = scope.formatValue(data.mainValue);
return applyColoringThresholds(data.mainValue, valueFormated);
} }
function smallValueTextReplaceFunc(match, text) { function smallValueTextReplaceFunc(match, text) {
...@@ -177,6 +233,21 @@ function (angular, app, _, TimeSeries, kbn) { ...@@ -177,6 +233,21 @@ function (angular, app, _, TimeSeries, kbn) {
body += '</div>'; body += '</div>';
} }
if (panel.coloring.background && data.mainValue) {
var color = getColorForValue(data.mainValue);
if (color) {
elem.parents('.panel-container').css('background-color', color);
if (scope.fullscreen) {
elem.css('background-color', color);
} else {
elem.css('background-color', '');
}
}
} else {
elem.parents('.panel-container').css('background-color', '');
elem.css('background-color', '');
}
if (panel.table.show) { if (panel.table.show) {
body += '<table class="stats-panel-table">'; body += '<table class="stats-panel-table">';
body += '<tr>'; body += '<tr>';
......
...@@ -18,28 +18,44 @@ ...@@ -18,28 +18,44 @@
<select class="input-small" ng-model="panel.format" ng-options="f for f in ['none','short','bytes', 'bits', 'bps', 's', 'ms', 'µs', 'ns', 'percent']" ng-change="render()"></select> <select class="input-small" ng-model="panel.format" ng-options="f for f in ['none','short','bytes', 'bits', 'bps', 's', 'ms', 'µs', 'ns', 'percent']" ng-change="render()"></select>
</div> </div>
</div> </div>
</div>
<div class="editor-row">
<div class="section"> <div class="section">
<h5>Series options</h5> <h5>Coloring</h5>
<div class="grafana-target" ng-repeat="series in data.series"> <editor-opt-bool text="Background" model="panel.coloring.background" change="setColoring({background: true})"></editor-opt-bool>
<div class="grafana-target-inner"> <editor-opt-bool text="Value" model="panel.coloring.value" change="setColoring({value: true})"></editor-opt-bool>
<ul class="grafana-segment-list"> <div class="editor-option">
<li class="grafana-target-segment"> <label class="small">Thresholds</label>
<i class="icon-eye-open" ng-click="hideSeries(series)"></i> <input type="text" class="input-large" ng-model="panel.coloring.thresholds" ng-blur="render()"></input>
</li> </div>
<div class="editor-option">
<li class="grafana-target-segment"> <label class="small">Color</label>
{{series.info.alias}} <spectrum-picker ng-model="panel.coloring.colors[0]" ng-change="render()" ></spectrum-picker>
</li> <spectrum-picker ng-model="panel.coloring.colors[1]" ng-change="render()" ></spectrum-picker>
<spectrum-picker ng-model="panel.coloring.colors[2]" ng-change="render()" ></spectrum-picker>
<li class="grafana-target-segment"> <a class="pointer" ng-click="invertColorOrder()">invert order</a>
</li>
</ul>
<div class="clearfix"></div>
</div>
</div> </div>
</div> </div>
</div> </div>
<!-- <div class="editor&#45;row"> -->
<!-- <div class="section"> -->
<!-- <h5>Series options</h5> -->
<!-- <div class="grafana&#45;target" ng&#45;repeat="series in data.series"> -->
<!-- <div class="grafana&#45;target&#45;inner"> -->
<!-- <ul class="grafana&#45;segment&#45;list"> -->
<!-- <li class="grafana&#45;target&#45;segment"> -->
<!-- <i class="icon&#45;eye&#45;open" ng&#45;click="hideSeries(series)"></i> -->
<!-- </li> -->
<!-- -->
<!-- <li class="grafana&#45;target&#45;segment"> -->
<!-- {{series.info.alias}} -->
<!-- </li> -->
<!-- -->
<!-- <li class="grafana&#45;target&#45;segment"> -->
<!-- </li> -->
<!-- </ul> -->
<!-- <div class="clearfix"></div> -->
<!-- </div> -->
<!-- </div> -->
<!-- </div> -->
<!-- </div> -->
<!-- -->
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