1- 'use strict' ;
2-
31/*
42 This utility contains CSS helpers.
53*/
64
7- const CSSUtil = function ( ) { } ;
8-
9- CSSUtil . prototype . colorTables = {
5+ export const colorTables = {
106 redWhiteGreen : [
117 { percentage : - 1 , color : { r : 0xff , g : 0x00 , b : 0x00 , a : 1.0 } } ,
128 { percentage : 0 , color : { r : 0xff , g : 0xff , b : 0xff , a : 1.0 } } ,
@@ -20,19 +16,19 @@ CSSUtil.prototype.colorTables = {
2016} ;
2117
2218// Stack Overflow: https://stackoverflow.com/a/7128796/4107016
23- CSSUtil . prototype . getColorForPercentage = function ( percentage , colorTable = null ) {
24- colorTable = colorTable || cssUtil . colorTables . redWhiteGreen ;
19+ export function getColorForPercentage ( percentage , colorTableOverride = null ) {
20+ colorTableOverride = colorTableOverride || colorTables . redWhiteGreen ;
2521
2622 percentage = Math . min ( 1 , Math . max ( - 1 , percentage ) ) ;
2723
2824 let index ;
29- for ( index = 1 ; index < colorTable . length - 1 ; index ++ ) {
30- if ( percentage < colorTable [ index ] . percentage ) {
25+ for ( index = 1 ; index < colorTableOverride . length - 1 ; index ++ ) {
26+ if ( percentage < colorTableOverride [ index ] . percentage ) {
3127 break ;
3228 }
3329 }
34- const lower = colorTable [ index - 1 ] ;
35- const upper = colorTable [ index ] ;
30+ const lower = colorTableOverride [ index - 1 ] ;
31+ const upper = colorTableOverride [ index ] ;
3632 const range = upper . percentage - lower . percentage ;
3733 const rangePercentage = ( percentage - lower . percentage ) / range ;
3834 const percentageLower = 1 - rangePercentage ;
@@ -45,7 +41,3 @@ CSSUtil.prototype.getColorForPercentage = function(percentage, colorTable = null
4541 } ;
4642 return `rgba(${ [ color . r , color . g , color . b , color . a ] . join ( "," ) } )` ;
4743} ;
48-
49- const cssUtil = new CSSUtil ( ) ;
50- window . cssUtil = cssUtil ;
51- export default cssUtil ;
0 commit comments