Skip to content

Commit

Permalink
Fix custom sectors colors
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Jun 19, 2019
1 parent 66c48c5 commit 10dc1f9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions justgage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 10dc1f9

Please sign in to comment.