|
@@ -35,6 +35,14 @@ class SingleStatCtrl extends MetricsPanelCtrl {
|
|
|
valueMaps: [
|
|
valueMaps: [
|
|
|
{ value: 'null', op: '=', text: 'N/A' }
|
|
{ value: 'null', op: '=', text: 'N/A' }
|
|
|
],
|
|
],
|
|
|
|
|
+ mappingTypes: [
|
|
|
|
|
+ {name: 'value to text', value: 1},
|
|
|
|
|
+ {name: 'range to text', value: 2},
|
|
|
|
|
+ ],
|
|
|
|
|
+ rangeMaps: [
|
|
|
|
|
+ { from: 'null', to: 'null', text: 'N/A' }
|
|
|
|
|
+ ],
|
|
|
|
|
+ mappingType: 1,
|
|
|
nullPointMode: 'connected',
|
|
nullPointMode: 'connected',
|
|
|
valueName: 'avg',
|
|
valueName: 'avg',
|
|
|
prefixFontSize: '50%',
|
|
prefixFontSize: '50%',
|
|
@@ -73,6 +81,7 @@ class SingleStatCtrl extends MetricsPanelCtrl {
|
|
|
onInitEditMode() {
|
|
onInitEditMode() {
|
|
|
this.fontSizes = ['20%', '30%','50%','70%','80%','100%', '110%', '120%', '150%', '170%', '200%'];
|
|
this.fontSizes = ['20%', '30%','50%','70%','80%','100%', '110%', '120%', '150%', '170%', '200%'];
|
|
|
this.addEditorTab('Options', 'public/app/plugins/panel/singlestat/editor.html', 2);
|
|
this.addEditorTab('Options', 'public/app/plugins/panel/singlestat/editor.html', 2);
|
|
|
|
|
+ this.addEditorTab('Value Mappings', 'public/app/plugins/panel/singlestat/mappings.html', 3);
|
|
|
this.unitFormats = kbn.getUnitFormats();
|
|
this.unitFormats = kbn.getUnitFormats();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -192,23 +201,45 @@ class SingleStatCtrl extends MetricsPanelCtrl {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // check value to text mappings
|
|
|
|
|
- for (var i = 0; i < this.panel.valueMaps.length; i++) {
|
|
|
|
|
- var map = this.panel.valueMaps[i];
|
|
|
|
|
- // special null case
|
|
|
|
|
- if (map.value === 'null') {
|
|
|
|
|
- if (data.value === null || data.value === void 0) {
|
|
|
|
|
|
|
+ // check value to text mappings if its enabled
|
|
|
|
|
+ if (this.panel.mappingType === 1) {
|
|
|
|
|
+ for (var i = 0; i < this.panel.valueMaps.length; i++) {
|
|
|
|
|
+ var map = this.panel.valueMaps[i];
|
|
|
|
|
+ // special null case
|
|
|
|
|
+ if (map.value === 'null') {
|
|
|
|
|
+ if (data.value === null || data.value === void 0) {
|
|
|
|
|
+ data.valueFormated = map.text;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // value/number to text mapping
|
|
|
|
|
+ var value = parseFloat(map.value);
|
|
|
|
|
+ if (value === data.valueRounded) {
|
|
|
data.valueFormated = map.text;
|
|
data.valueFormated = map.text;
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- continue;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ } else if (this.panel.mappingType === 2) {
|
|
|
|
|
+ for (var i = 0; i < this.panel.rangeMaps.length; i++) {
|
|
|
|
|
+ var map = this.panel.rangeMaps[i];
|
|
|
|
|
+ // special null case
|
|
|
|
|
+ if (map.from === 'null' && map.to === 'null') {
|
|
|
|
|
+ if (data.value === null || data.value === void 0) {
|
|
|
|
|
+ data.valueFormated = map.text;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // value/number to text mapping
|
|
|
|
|
- var value = parseFloat(map.value);
|
|
|
|
|
- if (value === data.valueRounded) {
|
|
|
|
|
- data.valueFormated = map.text;
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ // value/number to range mapping
|
|
|
|
|
+ var from = parseFloat(map.from);
|
|
|
|
|
+ var to = parseFloat(map.to);
|
|
|
|
|
+ if (to >= data.valueRounded && from <= data.valueRounded) {
|
|
|
|
|
+ data.valueFormated = map.text;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -227,6 +258,16 @@ class SingleStatCtrl extends MetricsPanelCtrl {
|
|
|
this.panel.valueMaps.push({value: '', op: '=', text: '' });
|
|
this.panel.valueMaps.push({value: '', op: '=', text: '' });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ removeRangeMap(rangeMap) {
|
|
|
|
|
+ var index = _.indexOf(this.panel.rangeMaps, rangeMap);
|
|
|
|
|
+ this.panel.rangeMaps.splice(index, 1);
|
|
|
|
|
+ this.render();
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ addRangeMap() {
|
|
|
|
|
+ this.panel.rangeMaps.push({from: '', to: '', text: ''});
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
link(scope, elem, attrs, ctrl) {
|
|
link(scope, elem, attrs, ctrl) {
|
|
|
var $location = this.$location;
|
|
var $location = this.$location;
|
|
|
var linkSrv = this.linkSrv;
|
|
var linkSrv = this.linkSrv;
|