Fix coloring in singlestat if null value (#9438)

This modification aim to allow users to set value via textMapping and
these values to be used in background coloring as it text coloring.

This pull request closes #8404, but doesn't agree with #9012.
The issue #9012 consider that no coloring output should be put when
there is no data. I partially agree with this as I explicitely setted a
value in the textMapping I obviously want to treat `N/A` as a number.

`data.valueFormatted` contain the stringified version of `data.value`

If `Number()` cannot convert a string into a number a `NaN` value is
returned. So the code is still valid if the inputted value in
`data.valueFormatted` is not a number.
This commit is contained in:
Adrien Raffin-Caboisse 2017-10-05 20:26:28 +02:00 committed by Torkel Ödegaard
parent e42c118b3d
commit 213ba0377b

View File

@ -589,8 +589,8 @@ class SingleStatCtrl extends MetricsPanelCtrl {
var body = panel.gauge.show ? '' : getBigValueHtml();
if (panel.colorBackground && !isNaN(data.value)) {
var color = getColorForValue(data, data.value);
if (panel.colorBackground && !isNaN(Number(data.valueFormatted))) {
var color = getColorForValue(data, Number(data.valueFormatted));
if (color) {
$panelContainer.css('background-color', color);
if (scope.fullscreen) {