@@ -455,6 +455,27 @@ PivotView.prototype.recalculateSizes = function (container) {
455455
456456} ;
457457
458+ /**
459+ * DeepSee-defined colors.
460+ *
461+ * @param {string } name - name of color. F.e. "red".
462+ * @returns {{ r: number, g: number, b: number } }
463+ */
464+ PivotView . prototype . colorNameToRGB = function ( name ) {
465+ var c = function ( r , g , b ) { return { r : r , g : g , b : b } } ;
466+ switch ( name ) {
467+ case "red" : return c ( 255 , 0 , 0 ) ;
468+ case "green" : return c ( 0 , 255 , 0 ) ;
469+ case "blue" : return c ( 0 , 0 , 255 ) ;
470+ case "purple" : return c ( 102 , 0 , 153 ) ;
471+ case "salmon" : return c ( 255 , 140 , 105 ) ;
472+ case "white" : return c ( 255 , 255 , 255 ) ;
473+ case "black" : return c ( 0 , 0 , 0 ) ;
474+ case "gray" : return c ( 128 , 128 , 128 ) ;
475+ default : return c ( 255 , 255 , 255 ) ;
476+ }
477+ } ;
478+
458479/**
459480 * Raw data - plain 2-dimensional array of data to render.
460481 *
@@ -477,6 +498,8 @@ PivotView.prototype.renderRawData = function (data) {
477498 rawData = data [ "rawData" ] ,
478499 info = data [ "info" ] ,
479500 columnProps = data [ "columnProps" ] ,
501+ colorScale =
502+ data [ "conditionalFormatting" ] ? data [ "conditionalFormatting" ] [ "colorScale" ] : undefined ,
480503 container = this . elements . tableContainer ,
481504 pivotTopSection = document . createElement ( "div" ) ,
482505 pivotBottomSection = document . createElement ( "div" ) ,
@@ -491,7 +514,7 @@ PivotView.prototype.renderRawData = function (data) {
491514 LHTHead = document . createElement ( "thead" ) ,
492515 mainTable = document . createElement ( "table" ) ,
493516 mainTBody = document . createElement ( "tbody" ) ,
494- x , y , tr = null , th , td , primaryColumns = [ ] , primaryRows = [ ] ;
517+ x , y , tr = null , th , td , primaryColumns = [ ] , primaryRows = [ ] , ratio ;
495518
496519 // clean previous content
497520 this . removeMessage ( ) ;
@@ -610,7 +633,19 @@ PivotView.prototype.renderRawData = function (data) {
610633 td . textContent = rawData [ y ] [ x ] . value || "" ;
611634 }
612635 }
613- if ( rawData [ y ] [ x ] . style ) td . setAttribute ( "style" , rawData [ y ] [ x ] . style ) ;
636+ if (
637+ colorScale
638+ && ! ( info . SUMMARY_SHOWN && rawData . length - 1 === y ) // exclude totals formatting
639+ ) {
640+ ratio = ( parseFloat ( rawData [ y ] [ x ] . value ) - colorScale . min ) / colorScale . diff ;
641+ td . setAttribute ( "style" , "background:rgb(" +
642+ + Math . round ( ( colorScale . to . r - colorScale . from . r ) * ratio + colorScale . from . r )
643+ + "," + Math . round ( ( colorScale . to . g - colorScale . from . g ) * ratio + colorScale . from . g )
644+ + "," + Math . round ( ( colorScale . to . b - colorScale . from . b ) * ratio + colorScale . from . b )
645+ + ");" + ( colorScale . invert ? "color: white;" : "" ) ) ;
646+ }
647+ if ( rawData [ y ] [ x ] . style )
648+ td . setAttribute ( "style" , ( td . getAttribute ( "style" ) || "" ) + rawData [ y ] [ x ] . style ) ;
614649 if (
615650 this . controller . CONFIG . conditionalFormattingOn // totals formatting present
616651 && ! ( info . SUMMARY_SHOWN && rawData . length - 1 === y ) // exclude totals formatting
0 commit comments