Skip to content

Commit 8bb0712

Browse files
committed
fix(gauge): validate min / max range, fixes grafana#4820
1 parent bce5c44 commit 8bb0712

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,18 @@
179179
Min
180180
</li>
181181
<li>
182-
<input type="text" class="input-small tight-form-input" ng-model="ctrl.panel.gauge.minValue" ng-blur="ctrl.render()" placeholder="0"></input>
182+
<input type="number" class="input-small tight-form-input" ng-model="ctrl.panel.gauge.minValue" ng-blur="ctrl.render()" placeholder="0"></input>
183183
</li>
184184
<li class="tight-form-item last">
185185
Max
186186
</li>
187187
<li>
188-
<input type="text" class="input-small tight-form-input last" ng-model="ctrl.panel.gauge.maxValue" ng-blur="ctrl.render()" placeholder="100"></input>
188+
<input type="number" class="input-small tight-form-input last" ng-model="ctrl.panel.gauge.maxValue" ng-blur="ctrl.render()" placeholder="100"></input>
189+
<span class="alert-state-critical" ng-show="ctrl.invalidGaugeRange">
190+
&nbsp;
191+
<i class="fa fa-warning"></i>
192+
Min value is bigger than max.
193+
</span>
189194
</li>
190195
</ul>
191196
<div class="clearfix"></div>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class SingleStatCtrl extends MetricsPanelCtrl {
1818
data: any;
1919
fontSizes: any[];
2020
unitFormats: any[];
21+
invalidGaugeRange: boolean;
2122

2223
// Set and populate defaults
2324
panelDefaults = {
@@ -287,6 +288,12 @@ class SingleStatCtrl extends MetricsPanelCtrl {
287288
}
288289

289290
function addGauge() {
291+
ctrl.invalidGaugeRange = false;
292+
if (panel.gauge.minValue > panel.gauge.maxValue) {
293+
ctrl.invalidGaugeRange = true;
294+
return;
295+
}
296+
290297
var plotCanvas = $('<div></div>');
291298
var plotCss = {
292299
top: '10px',

0 commit comments

Comments
 (0)