@datarailsshared/dr_renderer 1.2.5 → 1.2.6

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.
@@ -376,14 +376,13 @@ let initNovixRenderer = function($, window, document, Handsontable){
376
376
  //data columns
377
377
  if (pvtData.colKeys.length > 0) {
378
378
 
379
- const formattedColKeys = pvtData.getFormattedColKeys(colKeys);
380
379
  var aux = rowData.length;
381
380
  var startCol = aux;
382
- var prior = formattedColKeys[0][nn];
381
+ var prior = colKeys[0][nn];
383
382
  var toMerge = 0;
384
- for (var cc = 0; cc < formattedColKeys.length; cc++) {
383
+ for (var cc = 0; cc < colKeys.length; cc++) {
385
384
 
386
- var textHeader = formattedColKeys[cc][nn];
385
+ var textHeader = colKeys[cc][nn];
387
386
 
388
387
  if (nn < pvtData.colAttrs.length - 1 && prior != textHeader) {
389
388
  rowData.push(textHeader);
@@ -457,9 +456,8 @@ let initNovixRenderer = function($, window, document, Handsontable){
457
456
  // DATA
458
457
 
459
458
  var mergeDic = {};
460
- const formattedRowKeys = pvtData.getFormattedRowKeys(rowKeys);
461
459
 
462
- for (var rr = 0; rr < formattedRowKeys.length; rr++) {
460
+ for (var rr = 0; rr < rowKeys.length; rr++) {
463
461
 
464
462
  var rowData = [];
465
463
 
@@ -468,29 +466,29 @@ let initNovixRenderer = function($, window, document, Handsontable){
468
466
  mergeDic[cc] = {
469
467
  toMerge: 1,
470
468
  row: 0,
471
- priorText: formattedRowKeys[rr][cc]
469
+ priorText: rowKeys[rr][cc]
472
470
  };
473
471
  }
474
472
  }
475
473
 
476
474
  //column for row atts
477
475
  for (var cc = 0; cc < pvtData.rowAttrs.length; cc++) {
478
- rowData.push(formattedRowKeys[rr][cc]);
479
- if (formattedRowKeys[rr][cc] === subtotal) {
476
+ rowData.push(rowKeys[rr][cc]);
477
+ if (rowKeys[rr][cc] === subtotal) {
480
478
  addMergeCell(rr + pvtData.colAttrs.length + 1, cc, 1, dataSource.fixedColumns - cc, true, true);
481
- } else if (cc === formattedRowKeys[rr].length - 1 && hasColumnAttr) {
479
+ } else if (cc === rowKeys[rr].length - 1 && hasColumnAttr) {
482
480
  addMergeCell(rr + pvtData.colAttrs.length + 1, cc, 1, 2, true, true);
483
481
  }
484
482
  // merge cell (last column)
485
483
  if (opts.chartOptions.table_options.show_column_total && rr != 0 && mergeDic[cc]) { // check for merge dic
486
- if (formattedRowKeys[rr][cc] == mergeDic[cc].priorText) {
484
+ if (rowKeys[rr][cc] == mergeDic[cc].priorText) {
487
485
  mergeDic[cc].toMerge++;
488
- } else if (cc < formattedRowKeys[rr].length - 1) {
486
+ } else if (cc < rowKeys[rr].length - 1) {
489
487
  //create merge cell for this column
490
488
  addMergeCell(mergeDic[cc].row + pvtData.colAttrs.length + 1, cc, mergeDic[cc].toMerge, 1);
491
489
  mergeDic[cc].row = rr;
492
490
  mergeDic[cc].toMerge = 1;
493
- mergeDic[cc].priorText = formattedRowKeys[rr][cc];
491
+ mergeDic[cc].priorText = rowKeys[rr][cc];
494
492
  }
495
493
  }
496
494
  }
package/src/pivottable.js CHANGED
@@ -1,5 +1,3 @@
1
- const helpers = require('./dr-renderer-helpers');
2
-
3
1
  // from pivottable@2.23.0
4
2
  let initPivotTable = function($, window, document) {
5
3
  var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
@@ -22,7 +20,10 @@ let initPivotTable = function($, window, document) {
22
20
  }
23
21
  return x1 + x2;
24
22
  };
25
-
23
+ let useTotalsCalculation = false;
24
+ if (document.ReportHippo && document.ReportHippo && document.ReportHippo.user) {
25
+ useTotalsCalculation = _.includes(document.ReportHippo.user.features, 'enable_server_totals_calculation');
26
+ }
26
27
  numberFormat = function(opts) {
27
28
  var defaults;
28
29
  defaults = {
@@ -576,7 +577,6 @@ let initPivotTable = function($, window, document) {
576
577
  l_mapping = {};
577
578
  for (i in order) {
578
579
  x = order[i];
579
- if (order[i] === null) x = '[null]';
580
580
  mapping[x] = i;
581
581
  if (typeof x === "string") {
582
582
  l_mapping[x.toLowerCase()] = i;
@@ -668,7 +668,6 @@ let initPivotTable = function($, window, document) {
668
668
  this.getAggregator = bind(this.getAggregator, this);
669
669
  this.getRowKeys = bind(this.getRowKeys, this);
670
670
  this.getColKeys = bind(this.getColKeys, this);
671
- this.getRowKeysByCols = bind(this.getRowKeysByCols, this);
672
671
  this.sortKeys = bind(this.sortKeys, this);
673
672
  this.arrSort = bind(this.arrSort, this);
674
673
  this.input = input;
@@ -685,34 +684,17 @@ let initPivotTable = function($, window, document) {
685
684
  return true;
686
685
  });
687
686
  this.tree = {};
688
-
689
- this.isKeysSortingDoneOnBackendSide = opts.keysObject && typeof opts.keysObject === 'object' && helpers.backendSortingKeysAreNotEmpty(opts.keysObject);
690
- if (this.isKeysSortingDoneOnBackendSide) {
691
- this.rowKeys = opts.keysObject.row_keys;
692
- this.colKeys = opts.keysObject.col_keys;
693
- this.rowKeysByCols = opts.keysObject.row_keys_by_cols;
694
- } else {
695
- this.rowKeys = [];
696
- this.colKeys = [];
697
- }
698
-
687
+ this.rowKeys = [];
688
+ this.colKeys = [];
699
689
  this.rowTotals = {};
700
690
  this.colTotals = {};
701
691
  this.allTotal = this.aggregator(this, [], []);
702
692
  this.sorted = false;
703
693
  this.dateValuesDictionary = opts.dateValuesDictionary;
704
- this.sortByValueAttrs = opts.sortByValueAttrs || [];
705
- this.colFormats = opts.colFormats || [];
706
- this.rowFormats = opts.rowFormats || [];
707
- this.isFormattingAxisLabels = opts.rendererOptions && opts.rendererOptions.isFormattingAxisLabels;
708
- this.getFormattedColKeys = (keys) => opts.getFormattedColKeys(this, keys);
709
- this.getFormattedRowKeys = (keys) => opts.getFormattedRowKeys(this, keys);
710
- this.isDrillDownDisabled = opts.isDrillDownDisabled;
711
-
712
694
  PivotData.forEachRecord(this.input, this.derivedAttributes, (function(_this) {
713
695
  return function(record) {
714
696
  if (_this.filter(record)) {
715
- return _this.processRecord(record);
697
+ return _this.processRecord(record, useTotalsCalculation);
716
698
  }
717
699
  };
718
700
  })(this));
@@ -868,23 +850,15 @@ let initPivotTable = function($, window, document) {
868
850
  };
869
851
 
870
852
  PivotData.prototype.getColKeys = function() {
871
- if (!this.isKeysSortingDoneOnBackendSide) {
872
- this.sortKeys();
873
- }
853
+ this.sortKeys();
874
854
  return this.colKeys;
875
855
  };
876
856
 
877
857
  PivotData.prototype.getRowKeys = function() {
878
- if (!this.isKeysSortingDoneOnBackendSide) {
879
- this.sortKeys();
880
- }
858
+ this.sortKeys();
881
859
  return this.rowKeys;
882
860
  };
883
861
 
884
- PivotData.prototype.getRowKeysByCols = function() {
885
- return this.rowKeysByCols;
886
- };
887
-
888
862
  PivotData.prototype.processRecord = function(record) {
889
863
  var colKey, flatColKey, flatRowKey, l, len1, len2, n, ref, ref1, ref2, ref3, rowKey, x;
890
864
  colKey = [];
@@ -4,7 +4,6 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
4
4
  this.scope = {};
5
5
  this.options = {};
6
6
  this.isScenarioMode = null;
7
- this.settings = {};
8
7
 
9
8
  publishedItemsRenderer.formulaCellClicked = function (event, scope, options, window) {
10
9
  event.stopPropagation();
@@ -20,6 +19,7 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
20
19
  }
21
20
 
22
21
  publishedItemsRenderer.resizeTable = function (options, iframeWindow) {
22
+ options.alreadySetTimeout = null;
23
23
  const publish_item_image = iframeWindow.document.getElementById('publish_item_image');
24
24
  const table = iframeWindow.document.getElementsByTagName("table")[0];
25
25
  const body = iframeWindow.document.getElementsByTagName("body")[0];
@@ -31,23 +31,40 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
31
31
  publishedItemsRenderer.resizePublishedImage(publish_item_image, iframeWindow, body);
32
32
  }
33
33
 
34
- publishedItemsRenderer.zoomTable = function (iframeWindow, table, body) {
35
- const bodyZoom = parseFloat(body.style.zoom) || 1;
36
- const SCROLL_OFFSET = 16;
34
+ publishedItemsRenderer.zoomTable = function(iframeWindow, table, body) {
35
+ let body_zoom = body.style.zoom;
36
+ body_zoom = parseFloat(body_zoom) || 1;
37
37
 
38
- const tableWidth = table.getBoundingClientRect().width * bodyZoom;
39
- const tableHeight = table.getBoundingClientRect().height * bodyZoom;
40
- const root = iframeWindow.document.documentElement;
38
+ let zoom = table.style.zoom;
39
+ zoom = parseFloat(zoom) || 1;
41
40
 
42
- let requiredZoom = (root.clientWidth - SCROLL_OFFSET) / tableWidth;
43
- if (this.settings.resizeTableUsingBothDimensions) {
44
- requiredZoom = Math.min(requiredZoom, (root.clientHeight - SCROLL_OFFSET) / tableHeight);
45
- }
41
+ const positionInfo = table.getBoundingClientRect();
42
+ let width = Math.ceil((positionInfo.width + iframeWindow.innerWidth - iframeWindow.document.body.offsetWidth) * zoom * body_zoom);
43
+
44
+ if (width < iframeWindow.innerWidth) {
45
+ zoom += 0.05;
46
46
 
47
- table.style.zoom = requiredZoom;
48
- };
47
+ width = Math.ceil((positionInfo.width + iframeWindow.innerWidth - iframeWindow.document.body.offsetWidth) * zoom * body_zoom);
48
+ if (width < iframeWindow.innerWidth) {
49
+ table.style.zoom = zoom;
50
+ setTimeout(function () {
51
+ publishedItemsRenderer.zoomTable(iframeWindow, table, body);
52
+ }, 10);
53
+ }
54
+ } else if (width >= iframeWindow.innerWidth) {
55
+ zoom -= 0.05;
56
+
57
+ width = Math.ceil((positionInfo.width + iframeWindow.innerWidth - iframeWindow.document.body.offsetWidth) * zoom * body_zoom);
58
+ table.style.zoom = zoom;
59
+ if (width >= iframeWindow.innerWidth) {
60
+ setTimeout(function () {
61
+ publishedItemsRenderer.zoomTable(iframeWindow, table, body);
62
+ }, 10);
63
+ }
64
+ }
65
+ }
49
66
 
50
- publishedItemsRenderer.resizePublishedImage = function (publish_item_image, iframeWindow, body) {
67
+ publishedItemsRenderer.resizePublishedImage = function(publish_item_image, iframeWindow, body) {
51
68
  if (!publish_item_image) return;
52
69
 
53
70
  let body_zoom = body.style.zoom;
@@ -90,7 +107,11 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
90
107
  if (!options.responsive) {
91
108
  publishedItemsRenderer.resetTableZoom(document);
92
109
  } else {
93
- publishedItemsRenderer.resizeTable(options, iframeWindow);
110
+ if (!options.alreadySetTimeout) {
111
+ options.alreadySetTimeout = setTimeout(function () {
112
+ publishedItemsRenderer.resizeTable(options, iframeWindow);
113
+ }, 100);
114
+ }
94
115
  }
95
116
  }
96
117
 
@@ -196,7 +217,7 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
196
217
  const format = inputMetaData.format ? inputMetaData.format.toUpperCase() : 'MM/DD/YYYY';
197
218
  const formattedDate = formatValue('d', format, inputMetaData.value).value
198
219
  if (_this.isScenarioMode) {
199
- dateEl.innerHTML = '<label class="value dateInput" style="background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;cursor:pointer;">' + formattedDate + '</label>';
220
+ dateEl.innerHTML = '<label class="value dateInput" style="background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;cursor:pointer;">' + formattedDate + '</label>';
200
221
  } else {
201
222
  dateEl.innerHTML = '<label class="value dateInput" style="cursor: pointer;">' + formattedDate + '</label>';
202
223
  }
@@ -302,19 +323,20 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
302
323
  }
303
324
 
304
325
  publishedItemsRenderer.addEventListeners = function (document, iframeWindow, scope, options) {
305
- let resizeTimeout;
306
- const handleDimensionChange = () => {
307
- if (resizeTimeout) {
308
- cancelAnimationFrame(resizeTimeout);
326
+ document.addEventListener("DOMContentLoaded", function () {
327
+ if (!options.alreadySetTimeout) {
328
+ options.alreadySetTimeout = setTimeout(function () {
329
+ publishedItemsRenderer.resizeTable(options, iframeWindow);
330
+ }, 50);
309
331
  }
310
-
311
- resizeTimeout = requestAnimationFrame(() => {
312
- publishedItemsRenderer.resizeTable(iframeWindow.__options__, iframeWindow);
313
- });
314
- }
315
-
316
- document.addEventListener("DOMContentLoaded", handleDimensionChange);
317
- iframeWindow.addEventListener("resize", handleDimensionChange);
332
+ });
333
+ iframeWindow.addEventListener("resize", function () {
334
+ if (!options.alreadySetTimeout) {
335
+ options.alreadySetTimeout = setTimeout(function () {
336
+ publishedItemsRenderer.resizeTable(iframeWindow.__options__, iframeWindow);
337
+ }, 100);
338
+ }
339
+ });
318
340
 
319
341
  // Add click event to cell with formula
320
342
  let all_a_hrefs = document.querySelectorAll('td a[location_id]');
@@ -350,7 +372,7 @@ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
350
372
  }, 500);
351
373
  }
352
374
 
353
- publishedItemsRenderer.applyInitDocumentStyles = function (document, iframeWindow) {
375
+ publishedItemsRenderer.applyInitDocumentStyles = function(document, iframeWindow) {
354
376
  const table = document.getElementsByTagName('table')[0];
355
377
  if (table) {
356
378
  table.style.overflow = 'hidden';