From 1210fca8e5eae430d7abcd893453f1d5e0bd0cc1 Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 28 Jan 2016 01:11:26 +0100 Subject: [PATCH] fix(singlestat): fix bug in threshold calculations --- public/app/plugins/panel/singlestat/module.ts | 2 +- .../panel/singlestat/specs/singlestat_panel_spec.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/public/app/plugins/panel/singlestat/module.ts b/public/app/plugins/panel/singlestat/module.ts index 0a171207bcfe..faf88e691e4a 100644 --- a/public/app/plugins/panel/singlestat/module.ts +++ b/public/app/plugins/panel/singlestat/module.ts @@ -221,7 +221,7 @@ function singleStatPanel($location, linkSrv, $timeout, templateSrv) { function getColorForValue(data, value) { for (var i = data.thresholds.length; i > 0; i--) { - if (value >= data.thresholds[i]) { + if (value >= data.thresholds[i-1]) { return data.colorMap[i]; } } diff --git a/public/app/plugins/panel/singlestat/specs/singlestat_panel_spec.ts b/public/app/plugins/panel/singlestat/specs/singlestat_panel_spec.ts index 17b34f6bcefc..5e93923e6d3f 100644 --- a/public/app/plugins/panel/singlestat/specs/singlestat_panel_spec.ts +++ b/public/app/plugins/panel/singlestat/specs/singlestat_panel_spec.ts @@ -2,12 +2,12 @@ import {describe, beforeEach, it, sinon, expect} from 'test/lib/common'; import {getColorForValue} from '../module'; -describe('grafanaSingleStat', function() { +describe.only('grafanaSingleStat', function() { describe('legacy thresholds', () => { describe('positive thresholds', () => { var data: any = { colorMap: ['green', 'yellow', 'red'], - thresholds: [0, 20, 50] + thresholds: [20, 50] }; it('5 should return green', () => { @@ -29,7 +29,7 @@ describe('grafanaSingleStat', function() { describe('negative thresholds', () => { var data: any = { colorMap: ['green', 'yellow', 'red'], - thresholds: [ -20, 0, 20] + thresholds: [ 0, 20] }; it('-30 should return green', () => { @@ -48,7 +48,7 @@ describe('grafanaSingleStat', function() { describe('negative thresholds', () => { var data: any = { colorMap: ['green', 'yellow', 'red'], - thresholds: [ -40, -27, 20] + thresholds: [-27, 20] }; it('-30 should return green', () => {