From 213ba0377b2bbf61093da70ad38e66deae413396 Mon Sep 17 00:00:00 2001 From: Adrien Raffin-Caboisse Date: Thu, 5 Oct 2017 20:26:28 +0200 Subject: [PATCH] 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. --- public/app/plugins/panel/singlestat/module.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/panel/singlestat/module.ts b/public/app/plugins/panel/singlestat/module.ts index b4ee2bf7fb7..f9cf5ed2955 100644 --- a/public/app/plugins/panel/singlestat/module.ts +++ b/public/app/plugins/panel/singlestat/module.ts @@ -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) {