Commit 7ff8931d by Torkel Ödegaard

SingleStatPanel: added font size options for value, prefix and postfix, #951

parent 2a962bf8
...@@ -32,7 +32,11 @@ function (angular) { ...@@ -32,7 +32,11 @@ function (angular) {
}; };
input.spectrum(options); input.spectrum(options);
scope.$on('$destroy', function() {
input.spectrum('destroy');
});
} }
}; };
}); });
}); });
\ No newline at end of file
...@@ -347,7 +347,6 @@ function (angular, app, $, _, kbn, moment, TimeSeries) { ...@@ -347,7 +347,6 @@ function (angular, app, $, _, kbn, moment, TimeSeries) {
$scope.render(); $scope.render();
}; };
panelSrv.init($scope); panelSrv.init($scope);
}); });
......
...@@ -43,6 +43,9 @@ function (angular, app, _, TimeSeries, kbn) { ...@@ -43,6 +43,9 @@ function (angular, app, _, TimeSeries, kbn) {
prefix: '', prefix: '',
postfix: '', postfix: '',
valueName: 'avg', valueName: 'avg',
prefixFontSize: '50%',
valueFontSize: '100%',
postfixFontSize: '50%',
thresholds: '', thresholds: '',
colorBackground: false, colorBackground: false,
colorValue: false, colorValue: false,
......
...@@ -17,11 +17,12 @@ function (angular, app, _, kbn, $) { ...@@ -17,11 +17,12 @@ function (angular, app, _, kbn, $) {
return { return {
link: function(scope, elem) { link: function(scope, elem) {
var data; var data, panel;
var $panelContainer = elem.parents('.panel-container'); var $panelContainer = elem.parents('.panel-container');
scope.$on('render', function() { scope.$on('render', function() {
data = scope.data; data = scope.data;
panel = scope.panel;
if (!data || data.flotpairs.length === 0) { if (!data || data.flotpairs.length === 0) {
elem.html('no data'); elem.html('no data');
...@@ -33,12 +34,12 @@ function (angular, app, _, kbn, $) { ...@@ -33,12 +34,12 @@ function (angular, app, _, kbn, $) {
function setElementHeight() { function setElementHeight() {
try { try {
var height = scope.height || scope.panel.height || scope.row.height; var height = scope.height || panel.height || scope.row.height;
if (_.isString(height)) { if (_.isString(height)) {
height = parseInt(height.replace('px', ''), 10); height = parseInt(height.replace('px', ''), 10);
} }
height -= scope.panel.title ? 24 : 9; // subtract panel title bar height -= panel.title ? 24 : 9; // subtract panel title bar
elem.css('height', height + 'px'); elem.css('height', height + 'px');
...@@ -49,7 +50,7 @@ function (angular, app, _, kbn, $) { ...@@ -49,7 +50,7 @@ function (angular, app, _, kbn, $) {
} }
function applyColoringThresholds(value, valueString) { function applyColoringThresholds(value, valueString) {
if (!scope.panel.colorValue) { if (!panel.colorValue) {
return valueString; return valueString;
} }
...@@ -70,8 +71,24 @@ function (angular, app, _, kbn, $) { ...@@ -70,8 +71,24 @@ function (angular, app, _, kbn, $) {
return null; return null;
} }
function getSpan(className, fontSize, value) {
return '<span class="' + className + '" style="font-size:' + fontSize + '">' +
value + '</span>';
}
function getBigValueHtml() { function getBigValueHtml() {
return applyColoringThresholds(data.mainValue, data.mainValueFormated); var body = '<div class="stats-panel-value-container">';
if (panel.prefix) { body += getSpan('stats-panel-prefix', panel.prefixFontSize, scope.panel.prefix); }
var value = applyColoringThresholds(data.mainValue, data.mainValueFormated);
body += getSpan('stats-panel-value', panel.valueFontSize, value);
if (panel.postfix) { body += getSpan('stats-panel-postfix', panel.postfixFontSize, panel.postfix); }
body += '</div>';
return body;
} }
function addSparkline() { function addSparkline() {
...@@ -134,13 +151,7 @@ function (angular, app, _, kbn, $) { ...@@ -134,13 +151,7 @@ function (angular, app, _, kbn, $) {
setElementHeight(); setElementHeight();
var panel = scope.panel; var panel = scope.panel;
var body = ''; var body = getBigValueHtml();
body += '<div class="stats-panel-value-container">';
body += '<span class="stats-panel-value">';
body += getBigValueHtml();
body += '</div>';
body += '</div>';
if (panel.colorBackground && data.mainValue) { if (panel.colorBackground && data.mainValue) {
var color = getColorForValue(data.mainValue); var color = getColorForValue(data.mainValue);
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<h5>Big value</h5> <h5>Big value</h5>
<div class="editor-option"> <div class="editor-option">
<label class="small">Prefix</label> <label class="small">Prefix</label>
<input type="text" class="input-medium" ng-model="panel.prefix" ng-blur="render()"></input> <input type="text" class="input-small" ng-model="panel.prefix" ng-blur="render()"></input>
</div> </div>
<div class="editor-option"> <div class="editor-option">
<label class="small">Value</label> <label class="small">Value</label>
...@@ -11,9 +11,26 @@ ...@@ -11,9 +11,26 @@
</div> </div>
<div class="editor-option"> <div class="editor-option">
<label class="small">Postfix</label> <label class="small">Postfix</label>
<input type="text" class="input-medium" ng-model="panel.prefix" ng-blur="render()"></input> <input type="text" class="input-small" ng-model="panel.postfix" ng-blur="render()" ng-trim="false"></input>
</div> </div>
</div> </div>
<div class="section">
<h5>Big value font size</h5>
<div class="editor-option">
<label class="small">Prefix</label>
<select class="input-mini" style="width: 75px;" ng-model="panel.prefixFontSize" ng-options="f for f in ['30%','50%','70%','80%','100%']" ng-change="render()"></select>
</div>
<div class="editor-option">
<label class="small">Value</label>
<select class="input-mini" style="width: 75px;" ng-model="panel.valueFontSize" ng-options="f for f in ['30%','50%','70%','80%','100%', '110%', '120%']" ng-change="render()"></select>
</div>
<div class="editor-option">
<label class="small">Postfix</label>
<select class="input-mini" style="width: 75px;" ng-model="panel.postfixFontSize" ng-options="f for f in ['30%','50%','70%','80%','100%']" ng-change="render()"></select>
</div>
</div>
<div class="section"> <div class="section">
<h5>Formats</h5> <h5>Formats</h5>
<div class="editor-option"> <div class="editor-option">
......
...@@ -11,19 +11,12 @@ ...@@ -11,19 +11,12 @@
text-align: center; text-align: center;
position: relative; position: relative;
z-index: 1; z-index: 1;
}
.stats-panel-value {
font-size: 3em; font-size: 3em;
font-weight: bold; font-weight: bold;
} }
.stats-panel-value:not(:first-child) { .stats-panel-prefix {
padding-left: 20px; padding-right: 20px;
}
.stats-panel-value-small {
font-size: 50%;
} }
.stats-panel-table { .stats-panel-table {
......
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