singlestat: with table data, support string values
If the selected table column is string then show that in the singlestat
This commit is contained in:
@@ -174,10 +174,16 @@ class SingleStatCtrl extends MetricsPanelCtrl {
|
||||
const datapoint = tableData[0][0];
|
||||
data.value = datapoint[this.panel.tableColumn];
|
||||
|
||||
var decimalInfo = this.getDecimalsForValue(data.value);
|
||||
var formatFunc = kbn.valueFormats[this.panel.format];
|
||||
data.valueFormatted = formatFunc(datapoint[this.panel.tableColumn], decimalInfo.decimals, decimalInfo.scaledDecimals);
|
||||
data.valueRounded = kbn.roundValue(data.value, this.panel.decimals || 0);
|
||||
if (_.isString(data.value)) {
|
||||
data.valueFormatted = _.escape(data.value);
|
||||
data.value = 0;
|
||||
data.valueRounded = 0;
|
||||
} else {
|
||||
const decimalInfo = this.getDecimalsForValue(data.value);
|
||||
const formatFunc = kbn.valueFormats[this.panel.format];
|
||||
data.valueFormatted = formatFunc(datapoint[this.panel.tableColumn], decimalInfo.decimals, decimalInfo.scaledDecimals);
|
||||
data.valueRounded = kbn.roundValue(data.value, this.panel.decimals || 0);
|
||||
}
|
||||
|
||||
this.setValueMapping(data);
|
||||
}
|
||||
|
||||
@@ -242,6 +242,18 @@ describe('SingleStatCtrl', function() {
|
||||
expect(ctx.data.valueFormatted).to.be('NOT OK');
|
||||
});
|
||||
});
|
||||
|
||||
singleStatScenario('When value is string', function(ctx) {
|
||||
ctx.setup(function() {
|
||||
ctx.data = tableData;
|
||||
ctx.data[0].rows[0] = [1492759673649,'ignore1', 65, 'ignore2'];
|
||||
ctx.ctrl.panel.tableColumn = 'test1';
|
||||
});
|
||||
|
||||
it('Should replace value with text NOT OK', function() {
|
||||
expect(ctx.data.valueFormatted).to.be('ignore1');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user