Skip to content

Commit 26eeb65

Browse files
committed
feat(gauge): polish to gauge, better handling of automatic font size, added option to hide threshold markers
1 parent 8bb0712 commit 26eeb65

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

public/app/plugins/panel/singlestat/editor.html

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158

159159
<div class="editor-row">
160160
<div class="section" style="margin-bottom: 20px">
161-
<div class="tight-form last">
161+
<div class="tight-form">
162162
<ul class="tight-form-list">
163163
<li class="tight-form-item" style="width: 80px">
164164
<strong>Gauge</strong>
@@ -169,12 +169,6 @@
169169
ng-model="ctrl.panel.gauge.show" ng-checked="ctrl.panel.gauge.show" ng-change="ctrl.render()">
170170
<label for="panel.gauge.show" class="cr1"></label>
171171
</li>
172-
<li class="tight-form-item">
173-
Threshold labels&nbsp;
174-
<input class="cr1" id="panel.gauge.thresholdLabels" type="checkbox"
175-
ng-model="ctrl.panel.gauge.thresholdLabels" ng-checked="ctrl.panel.gauge.thresholdLabels" ng-change="ctrl.render()">
176-
<label for="panel.gauge.thresholdLabels" class="cr1"></label>
177-
</li>
178172
<li class="tight-form-item">
179173
Min
180174
</li>
@@ -195,6 +189,19 @@
195189
</ul>
196190
<div class="clearfix"></div>
197191
</div>
192+
<div class="tight-form last">
193+
<li class="tight-form-item">
194+
Threshold labels&nbsp;
195+
<input class="cr1" id="panel.gauge.thresholdLabels" type="checkbox" ng-model="ctrl.panel.gauge.thresholdLabels" ng-checked="ctrl.panel.gauge.thresholdLabels" ng-change="ctrl.render()">
196+
<label for="panel.gauge.thresholdLabels" class="cr1"></label>
197+
</li>
198+
<li class="tight-form-item">
199+
Threshold markers&nbsp;
200+
<input class="cr1" id="panel.gauge.thresholdMarkers" type="checkbox" ng-model="ctrl.panel.gauge.thresholdMarkers" ng-checked="ctrl.panel.gauge.thresholdMarkers" ng-change="ctrl.render()">
201+
<label for="panel.gauge.thresholdMarkers" class="cr1"></label>
202+
</li>
203+
<div class="clearfix"></div>
204+
</div>
198205
</div>
199206
</div>
200207

public/app/plugins/panel/singlestat/module.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ class SingleStatCtrl extends MetricsPanelCtrl {
5454
show: false,
5555
minValue: 0,
5656
maxValue: 100,
57-
thresholdLabels: true
57+
thresholdMarkers: true,
58+
thresholdLabels: false
5859
}
5960
};
6061

@@ -295,12 +296,14 @@ class SingleStatCtrl extends MetricsPanelCtrl {
295296
}
296297

297298
var plotCanvas = $('<div></div>');
299+
var width = elem.width();
300+
var height = elem.height();
298301
var plotCss = {
299302
top: '10px',
300303
margin: 'auto',
301304
position: 'relative',
302-
height: (elem.height() * 0.9) + 'px',
303-
width: elem.width() + 'px'
305+
height: (height * 0.9) + 'px',
306+
width: width + 'px'
304307
};
305308

306309
plotCanvas.css(plotCss);
@@ -321,6 +324,12 @@ class SingleStatCtrl extends MetricsPanelCtrl {
321324
? 'rgb(230,230,230)'
322325
: 'rgb(38,38,38)';
323326

327+
328+
var dimension = Math.min(width, height);
329+
var fontSize = Math.min(dimension/4, 100);
330+
var gaugeWidth = Math.min(dimension/6, 60);
331+
var thresholdMarkersWidth = gaugeWidth/5;
332+
324333
var options = {
325334
series: {
326335
gauges: {
@@ -330,11 +339,11 @@ class SingleStatCtrl extends MetricsPanelCtrl {
330339
background: { color: bgColor },
331340
border: { color: null },
332341
shadow: { show: false },
333-
width: 38
342+
width: gaugeWidth,
334343
},
335344
frame: { show: false },
336345
label: { show: false },
337-
layout: { margin: 0 },
346+
layout: { margin: 0, thresholdWidth: 0 },
338347
cell: { border: { width: 0 } },
339348
threshold: {
340349
values: thresholds,
@@ -343,12 +352,13 @@ class SingleStatCtrl extends MetricsPanelCtrl {
343352
margin: 8,
344353
font: { size: 18 }
345354
},
346-
width: 8
355+
show: panel.gauge.thresholdMarkers,
356+
width: thresholdMarkersWidth,
347357
},
348358
value: {
349359
color: panel.colorValue ? getColorForValue(data, data.valueRounded) : null,
350360
formatter: function() { return getValueText(); },
351-
font: { size: getGaugeFontSize(), family: 'Helvetica Neue", Helvetica, Arial, sans-serif' }
361+
font: { size: fontSize, family: 'Helvetica Neue", Helvetica, Arial, sans-serif' }
352362
},
353363
show: true
354364
}

0 commit comments

Comments
 (0)