@datarailsshared/dr_renderer 1.2.80 → 1.2.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datarailsshared/dr_renderer",
3
- "version": "1.2.80",
3
+ "version": "1.2.81",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -6,8 +6,6 @@ let initDRPivotTable = function($, window, document) {
6
6
  var DRPivotData, sortDateStrings, getSort, processKey, SubtotalRenderer, getFormattedNumber, largeToSmallSort, largeToSmallSortByAbsolute, NovixRenderer;
7
7
 
8
8
  var delim = " , ";
9
- const newTableColors = ['rgb(127, 196, 255)', 'rgb(200, 243,243)', 'rgb(247, 161, 173)', 'rgb(255, 237, 178)', 'rgb(221, 239, 255)',
10
- 'rgb(171, 216, 255)', 'rgb(174, 231, 220)', 'rgb(227, 255, 236)', 'rgb(162, 215, 227)', 'rgb(223, 239, 236)'];
11
9
  const useNewUx = document.ReportHippo && document.ReportHippo && document.ReportHippo.user &&
12
10
  document.ReportHippo.user.organization.settings && document.ReportHippo.user.organization.settings.use_new_ux;
13
11
  // const numberOfRows = 500; // change to activate the handsontable when num of rows bigger then this.
@@ -643,18 +641,56 @@ let initDRPivotTable = function($, window, document) {
643
641
  }
644
642
 
645
643
  getColorsWithOffsetForTable = function (value) {
644
+ var colors = [];
645
+
646
+ if (opts.paletteOptions.widgetPalette) {
647
+ const mc_palette = _.find(_.get(opts.paletteOptions, 'monochromePalettes', []), { selected: true });
648
+ colors = mc_palette ? mc_palette.colors : opts.paletteOptions.widgetPalette;
649
+ } else if (opts.paletteOptions.dashboardPalette.colors) {
650
+ colors = opts.paletteOptions.dashboardPalette.colors;
651
+ }
652
+
646
653
  var isNewDesign = useNewUx && opts.chartOptions.table_options.use_new_table_design;
647
654
  if (value) {
648
655
  var offset = parseInt(value);
649
656
  if (offset) {
650
657
  if (isNewDesign) {
651
- return offsetColors(offset, newTableColors);
658
+ return offsetColors(offset, colors);
652
659
  } else {
653
660
  return offsetColors(offset, opts.defaults_colors);
654
661
  }
655
662
  }
656
663
  }
657
- return isNewDesign ? newTableColors : opts.defaults_colors;
664
+ return isNewDesign ? colors : opts.defaults_colors;
665
+ }
666
+
667
+ function invertColors(color) {
668
+ const hexLuminance = 186;
669
+ const rgbLuminance = 0.5;
670
+ let isHex = color[0] === '#';
671
+ let r;
672
+ let g;
673
+ let b;
674
+ if (!isHex) {
675
+ let rgbaColorParts = color.replace(/[^0-9.,]/g, '').split(',');
676
+ r = rgbaColorParts[0]/255;
677
+ g = rgbaColorParts[1]/255;
678
+ b = rgbaColorParts[2]/255;
679
+ } else {
680
+ color = color.slice(1);
681
+
682
+ if (color.length === 3) {
683
+ color = color[0].repeat(2) + color[1].repeat(2) + color[2].repeat(2);
684
+ } else if (color.length !== 6) {
685
+ return "#FFFFFF";
686
+ }
687
+ r = parseInt(color.slice(0, 2), 16);
688
+ g = parseInt(color.slice(2, 4), 16);
689
+ b = parseInt(color.slice(4, 6), 16);
690
+ }
691
+ return (r * 0.299 + g * 0.587 + b * 0.114) > (isHex ? hexLuminance : rgbLuminance)
692
+ ? '#000000'
693
+ : '#FFFFFF';
658
694
  }
659
695
 
660
696
  colorizeRowLabelHeaders = function(element, cols_count){
@@ -665,7 +701,9 @@ let initDRPivotTable = function($, window, document) {
665
701
  if(color_to_set){
666
702
  element.style.setProperty("background-color", color_to_set, "important");
667
703
  element.style.setProperty("border-color", color_to_set, "important");
668
- element.style.color = useNewUx && opts.chartOptions.table_options.use_new_table_design? '#3a3b39' : '#FFFFFF';
704
+ element.style.color = useNewUx && opts.chartOptions.table_options.use_new_table_design
705
+ ? invertColors(color_to_set)
706
+ : '#3a3b39';
669
707
  element.style.fontWeight = "bold";
670
708
  if (opts.chartOptions.table_options.freeze_panes && element.firstChild) {
671
709
  for (const child of element.children) {
@@ -695,7 +733,9 @@ let initDRPivotTable = function($, window, document) {
695
733
  element.style.setProperty("background-color", color_to_set, "important");
696
734
  element.style.setProperty("border-color", color_to_set, "important");
697
735
  element.style.setProperty("vertical-align", "baseline");
698
- element.style.color = useNewUx && opts.chartOptions.table_options.use_new_table_design? '#3a3b39' : '#FFFFFF';
736
+ element.style.color = useNewUx && opts.chartOptions.table_options.use_new_table_design
737
+ ? invertColors(color_to_set)
738
+ : '#3a3b39';
699
739
  element.style.fontWeight = "bold";
700
740
  if (opts.chartOptions.table_options.freeze_panes && element.firstChild) {
701
741
  for (const child of element.children) {