From 10dc1f93883e0024f8f6d495b53886f3fb4f517b Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Wed, 19 Jun 2019 13:43:49 +0200 Subject: [PATCH] Fix custom sectors colors --- justgage.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/justgage.js b/justgage.js index 7c5ae9e..a9e2bda 100644 --- a/justgage.js +++ b/justgage.js @@ -214,9 +214,11 @@ JustGage = function(config) { // number of digits after floating point decimals: kvLookup('decimals', config, dataset, 0), - // customSectors : [] of objects - // number of digits after floating point - customSectors: kvLookup('customSectors', config, dataset, []), + // customSectors : object + // custom sectors colors. Expects an object with props + // percents : bool hi/lo are percents values + // ranges : array of objects : {hi, lo, color} + customSectors: kvLookup('customSectors', config, dataset, {}), // formatNumber: boolean // formats numbers with commas where appropriate @@ -1009,9 +1011,10 @@ function kvLookup(key, tablea, tableb, defval, datatype, delimiter) { function getColor(val, pct, col, noGradient, custSec) { var no, inc, colors, percentage, rval, gval, bval, lower, upper, range, rangePct, pctLower, pctUpper, color; - var noGradient = noGradient || custSec.length > 0; + var cust = custSec && custSec.ranges && custSec.ranges.length > 0; + var noGradient = noGradient || cust; - if (custSec.length > 0) { + if (cust) { if (custSec.percents === true) val = pct * 100; for (var i = 0; i < custSec.ranges.length; i++) { if (val >= custSec.ranges[i].lo && val <= custSec.ranges[i].hi) {