widgets/justgage/lib/js/justgage.js
function getColor(val, pct, col, noGradient, custSec, fullBri) {

    var no, inc, colors, percentage, rval, gval, bval, lower, upper, range, rangePct, pctLower, pctUpper, color, pow;
    var noGradient = noGradient || custSec.length > 0;

    if (custSec.length > 0) {
        for (var i = 0; i < custSec.length; i++) {
            if (val >= custSec[i].lo && val <= custSec[i].hi) {
                return custSec[i].color;
            }
        }
    }

    no = col.length;
    if (no === 1) return col[0];
    inc = (noGradient) ? (1 / no) : (1 / (no - 1));
    colors = [];
    for (i = 0; i < col.length; i++) {
        if (typeof col[i] === 'object'){
            percentage = col[i].pct ? col[i].pct : ((noGradient) ? (inc * (i + 1)) : (inc * i));
            pow = col[i].pow || 1;
            rval = parseInt((cutHex(col[i].color)).substring(0, 2), 16);
            gval = parseInt((cutHex(col[i].color)).substring(2, 4), 16);
            bval = parseInt((cutHex(col[i].color)).substring(4, 6), 16);
        }else{
            percentage = (noGradient) ? (inc * (i + 1)) : (inc * i);
            pow = 1;
            rval = parseInt((cutHex(col[i])).substring(0, 2), 16);
            gval = parseInt((cutHex(col[i])).substring(2, 4), 16);
            bval = parseInt((cutHex(col[i])).substring(4, 6), 16);
        }
        colors[i] = {
            pct: percentage,
            pow: pow,
            color: {
                r: rval,
                g: gval,
                b: bval
            }
        };
    }
    if (pct === 0) {
        return 'rgb(' + [colors[0].color.r, colors[0].color.g, colors[0].color.b].join(',') + ')';
    }

    for (var j = 0; j < colors.length; j++) {
        if (pct <= colors[j].pct) {
            var colorMax = Math.max(colors[j].color.r, colors[j].color.g, colors[j].color.b);
            if (noGradient) {
                return 'rgb(' + [colors[j].color.r, colors[j].color.g, colors[j].color.b].join(',') + ')';
            } else {
                lower = colors[j - 1];
                upper = colors[j];
                range = upper.pct - lower.pct;
                rangePct = Math.pow((pct - lower.pct) / range,colors[j].pow/colors[j-1].pow);
                pctLower = 1 - rangePct;
                pctUpper = rangePct;
                color = {
                    r: Math.floor(lower.color.r * pctLower + upper.color.r * pctUpper),
                    g: Math.floor(lower.color.g * pctLower + upper.color.g * pctUpper),
                    b: Math.floor(lower.color.b * pctLower + upper.color.b * pctUpper)
                };
                if (fullBri) {
                    colorMax2 = Math.max(color.r, color.g, color.b);
                    return 'rgb(' + [Math.floor(color.r / colorMax2 * colorMax), Math.floor(color.g / colorMax2 * colorMax), Math.floor(color.b / colorMax2 * colorMax)].join(',') + ')';
                } else {
                    return 'rgb(' + [color.r, color.g, color.b].join(',') + ')';
                }
            }
        }
    }
}
function getColor(val, pct, col, noGradient, custSec, fullBri) {

    var no, inc, colors, percentage, rval, gval, bval, lower, upper, range, rangePct, pctLower, pctUpper, color, pow;
    var noGradient = noGradient || custSec.length > 0;

    if (custSec.length > 0) {
        for (var i = 0; i < custSec.length; i++) {
            if (val >= custSec[i].lo && val <= custSec[i].hi) {
                return custSec[i].color;
            }
        }
    }

    no = col.length;
    if (no === 1) return col[0];
    inc = (noGradient) ? (1 / no) : (1 / (no - 1));
    colors = [];
    for (i = 0; i < col.length; i++) {
        if (typeof col[i] === 'object'){
            percentage = col[i].pct ? col[i].pct : ((noGradient) ? (inc * (i + 1)) : (inc * i));
            pow = col[i].pow || 1;
            rval = parseInt((cutHex(col[i].color)).substring(0, 2), 16);
            gval = parseInt((cutHex(col[i].color)).substring(2, 4), 16);
            bval = parseInt((cutHex(col[i].color)).substring(4, 6), 16);
        }else{
            percentage = (noGradient) ? (inc * (i + 1)) : (inc * i);
            pow = 1;
            rval = parseInt((cutHex(col[i])).substring(0, 2), 16);
            gval = parseInt((cutHex(col[i])).substring(2, 4), 16);
            bval = parseInt((cutHex(col[i])).substring(4, 6), 16);
        }
        colors[i] = {
            pct: percentage,
            pow: pow,
            color: {
                r: rval,
                g: gval,
                b: bval
            }
        };
    }
    if (pct === 0) {
        return 'rgb(' + [colors[0].color.r, colors[0].color.g, colors[0].color.b].join(',') + ')';
    }

    for (var j = 0; j < colors.length; j++) {
        if (pct <= colors[j].pct) {
            var colorMax = Math.max(colors[j].color.r, colors[j].color.g, colors[j].color.b);
            if (noGradient) {
                return 'rgb(' + [colors[j].color.r, colors[j].color.g, colors[j].color.b].join(',') + ')';
            } else {
                lower = colors[j - 1];
                upper = colors[j];
                range = upper.pct - lower.pct;
                rangePct = Math.pow((pct - lower.pct) / range,colors[j].pow/colors[j-1].pow);
                pctLower = 1 - rangePct;
                pctUpper = rangePct;
                color = {
                    r: Math.floor(lower.color.r * pctLower + upper.color.r * pctUpper),
                    g: Math.floor(lower.color.g * pctLower + upper.color.g * pctUpper),
                    b: Math.floor(lower.color.b * pctLower + upper.color.b * pctUpper)
                };
                if (fullBri) {
                    colorMax2 = Math.max(color.r, color.g, color.b);
                    return 'rgb(' + [Math.floor(color.r / colorMax2 * colorMax), Math.floor(color.g / colorMax2 * colorMax), Math.floor(color.b / colorMax2 * colorMax)].join(',') + ')';
                } else {
                    return 'rgb(' + [color.r, color.g, color.b].join(',') + ')';
                }
            }
        }
    }
}
function getColor ( val , pct , col , noGradient , custSec , fullBri ) { var no , inc , colors , percentage , rval , gval , bval , lower , upper , range , rangePct , pctLower , pctUpper , color , pow ; var noGradient = noGradient || custSec . length > 0 ; if ( custSec . length > 0 ) { for ( var i = 0 ; i < custSec . length ; i ++ ) { if ( val >= custSec [ i ] . lo && val <= custSec [ i ] . hi ) { return custSec [ i ] . color ; } } } no = col . length ; if ( no === 1 ) return col [ 0 ] ; inc = ( noGradient ) ? ( 1 / no ) : ( 1 / ( no - 1 ) ) ; colors = [ ] ; for ( i = 0 ; i < col . length ; i ++ ) { if ( typeof col [ i ] === 'object' ) { percentage = col [ i ] . pct ? col [ i ] . pct : ( ( noGradient ) ? ( inc * ( i + 1 ) ) : ( inc * i ) ) ; pow = col [ i ] . pow || 1 ; rval = parseInt ( ( cutHex ( col [ i ] . color ) ) . substring ( 0 , 2 ) , 16 ) ; gval = parseInt ( ( cutHex ( col [ i ] . color ) ) . substring ( 2 , 4 ) , 16 ) ; bval = parseInt ( ( cutHex ( col [ i ] . color ) ) . substring ( 4 , 6 ) , 16 ) ; } else { percentage = ( noGradient ) ? ( inc * ( i + 1 ) ) : ( inc * i ) ; pow = 1 ; rval = parseInt ( ( cutHex ( col [ i ] ) ) . substring ( 0 , 2 ) , 16 ) ; gval = parseInt ( ( cutHex ( col [ i ] ) ) . substring ( 2 , 4 ) , 16 ) ; bval = parseInt ( ( cutHex ( col [ i ] ) ) . substring ( 4 , 6 ) , 16 ) ; } colors [ i ] = { pct : percentage , pow : pow , color : { r : rval , g : gval , b : bval } } ; } if ( pct === 0 ) { return 'rgb(' + [ colors [ 0 ] . color . r , colors [ 0 ] . color . g , colors [ 0 ] . color . b ] . join ( ',' ) + ')' ; } for ( var j = 0 ; j < colors . length ; j ++ ) { if ( pct <= colors [ j ] . pct ) { var colorMax = Math . max ( colors [ j ] . color . r , colors [ j ] . color . g , colors [ j ] . color . b ) ; if ( noGradient ) { return 'rgb(' + [ colors [ j ] . color . r , colors [ j ] . color . g , colors [ j ] . color . b ] . join ( ',' ) + ')' ; } else { lower = colors [ j - 1 ] ; upper = colors [ j ] ; range = upper . pct - lower . pct ; rangePct = Math . pow ( ( pct - lower . pct ) / range , colors [ j ] . pow / colors [ j - 1 ] . pow ) ; pctLower = 1 - rangePct ; pctUpper = rangePct ; color = { r : Math . floor ( lower . color . r * pctLower + upper . color . r * pctUpper ) , g : Math . floor ( lower . color . g * pctLower + upper . color . g * pctUpper ) , b : Math . floor ( lower . color . b * pctLower + upper . color . b * pctUpper ) } ; if ( fullBri ) { colorMax2 = Math . max ( color . r , color . g , color . b ) ; return 'rgb(' + [ Math . floor ( color . r / colorMax2 * colorMax ) , Math . floor ( color . g / colorMax2 * colorMax ) , Math . floor ( color . b / colorMax2 * colorMax ) ] . join ( ',' ) + ')' ; } else { return 'rgb(' + [ color . r , color . g , color . b ] . join ( ',' ) + ')' ; } } } } }
Get color for value
Get color for value