@datarailsshared/dr_renderer 1.2.38-beta → 1.2.38

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.
@@ -1,2290 +1,2290 @@
1
- let initDRPivotTable = function($, window, document) {
2
- var hasProp = {}.hasOwnProperty;
3
- var slice = [].slice;
4
- var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
5
-
6
- var DRPivotData, sortDateStrings, getSort, processKey, SubtotalRenderer, getFormattedNumber, largeToSmallSort, NovixRenderer;
7
-
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
- const useNewUx = document.ReportHippo && document.ReportHippo && document.ReportHippo.user &&
12
- document.ReportHippo.user.organization.settings && document.ReportHippo.user.organization.settings.use_new_ux;
13
- // const numberOfRows = 500; // change to activate the handsontable when num of rows bigger then this.
14
-
15
- DRPivotData = (function(superClass) {
16
- extend(DRPivotData, superClass);
17
-
18
- function DRPivotData(input, opts) {
19
- DRPivotData.__super__.constructor.call(this, input, opts);
20
- }
21
-
22
- getSort = function(sorters, attr) {
23
- var sort;
24
- sort = sorters(attr);
25
- if ($.isFunction(sort)) {
26
- return sort;
27
- } else {
28
- return $.pivotUtilities.naturalSort;
29
- }
30
- };
31
-
32
- DRPivotData.prototype.forEachRecord = function(input, derivedAttributes, f) {
33
- var addRecord, compactRecord, i, j, k, l, len1, record, ref, results, results1, tblCols;
34
- if ($.isEmptyObject(derivedAttributes)) {
35
- addRecord = f;
36
- } else {
37
- addRecord = function(record) {
38
- var k, ref, v;
39
- for (k in derivedAttributes) {
40
- v = derivedAttributes[k];
41
- record[k] = (ref = v(record)) != null ? ref : record[k];
42
- }
43
- return f(record);
44
- };
45
- }
46
- if ($.isFunction(input)) {
47
- return input(addRecord);
48
- } else if ($.isArray(input)) {
49
- if ($.isArray(input[0])) {
50
- results = [];
51
- for (i in input) {
52
- if (!hasProp.call(input, i)) continue;
53
- compactRecord = input[i];
54
- if (!(i > 0)) {
55
- continue;
56
- }
57
- record = {};
58
- ref = input[0];
59
- for (j in ref) {
60
- if (!hasProp.call(ref, j)) continue;
61
- k = ref[j];
62
- record[k] = compactRecord[j];
63
- }
64
- results.push(addRecord(record));
65
- }
66
- return results;
67
- } else {
68
- results1 = [];
69
- for (l = 0, len1 = input.length; l < len1; l++) {
70
- record = input[l];
71
- results1.push(addRecord(record));
72
- }
73
- return results1;
74
- }
75
- } else if (input instanceof jQuery) {
76
- tblCols = [];
77
- $("thead > tr > th", input).each(function(i) {
78
- return tblCols.push($(this).text());
79
- });
80
- return $("tbody > tr", input).each(function(i) {
81
- record = {};
82
- $("td", this).each(function(j) {
83
- return record[tblCols[j]] = $(this).html();
84
- });
85
- return addRecord(record);
86
- });
87
- } else {
88
- throw new Error("unknown input format");
89
- }
90
- };
91
-
92
- DRPivotData.prototype.arrSort = function(attrs) {
93
- var a, sortersArr;
94
- sortersArr = (function() {
95
- var l, len1, results;
96
- results = [];
97
- for (l = 0, len1 = attrs.length; l < len1; l++) {
98
- a = attrs[l];
99
- results.push(getSort(this.sorters, a));
100
- }
101
- return results;
102
- }).call(this);
103
- return function(a, b) {
104
- var comparison, i, sorter;
105
- for (i in sortersArr) {
106
- sorter = sortersArr[i];
107
- comparison = sorter(a[i], b[i]);
108
- if (comparison !== 0) {
109
- return comparison;
110
- }
111
- }
112
- return 0;
113
- };
114
- };
115
-
116
- processKey = function(record, totals, keys, attrs, getAggregator) {
117
- var addKey, attr, flatKey, k, key, len, ref;
118
- key = [];
119
- addKey = false;
120
- for (k = 0, len = attrs.length; k < len; k++) {
121
- attr = attrs[k];
122
- key.push((ref = record[attr]) != null ? ref : "null");
123
- flatKey = key.join(delim);
124
- if (!totals[flatKey]) {
125
- totals[flatKey] = getAggregator(key.slice());
126
- addKey = true;
127
- }
128
- totals[flatKey].push(record);
129
- }
130
- if (addKey) {
131
- keys.push(key);
132
- }
133
- return key;
134
- };
135
-
136
- DRPivotData.prototype.processRecord = function(record) {
137
- var colKey, fColKey, fRowKey, flatColKey, flatRowKey, i, j, k, m, n, ref, results, rowKey;
138
- rowKey = [];
139
- colKey = [];
140
- this.allTotal.push(record);
141
- rowKey = processKey(record, this.rowTotals, this.rowKeys, this.rowAttrs, (function(_this) {
142
- return function(key) {
143
- return _this.aggregator(_this, key, []);
144
- };
145
- })(this));
146
- colKey = processKey(record, this.colTotals, this.colKeys, this.colAttrs, (function(_this) {
147
- return function(key) {
148
- return _this.aggregator(_this, [], key);
149
- };
150
- })(this));
151
- m = rowKey.length - 1;
152
- n = colKey.length - 1;
153
- if (m < 0 || n < 0) {
154
- return;
155
- }
156
- results = [];
157
- for (i = k = 0, ref = m; 0 <= ref ? k <= ref : k >= ref; i = 0 <= ref ? ++k : --k) {
158
- fRowKey = rowKey.slice(0, i + 1);
159
- flatRowKey = fRowKey.join(delim);
160
- if (!this.tree[flatRowKey]) {
161
- this.tree[flatRowKey] = {};
162
- }
163
- results.push((function() {
164
- var l, ref1, results1;
165
- results1 = [];
166
- for (j = l = 0, ref1 = n; 0 <= ref1 ? l <= ref1 : l >= ref1; j = 0 <= ref1 ? ++l : --l) {
167
- fColKey = colKey.slice(0, j + 1);
168
- flatColKey = fColKey.join(delim);
169
- if (!this.tree[flatRowKey][flatColKey]) {
170
- this.tree[flatRowKey][flatColKey] = this.aggregator(this, fRowKey, fColKey);
171
- }
172
- results1.push(this.tree[flatRowKey][flatColKey].push(record));
173
- }
174
- return results1;
175
- }).call(this));
176
- }
177
- return results;
178
- };
179
-
180
- DRPivotData.prototype.getAggregator = function(rowKey, colKey) {
181
- var agg, flatColKey, flatRowKey;
182
- flatRowKey = rowKey.join(delim);
183
- flatColKey = colKey.join(delim);
184
- if (rowKey.length === 0 && colKey.length === 0) {
185
- agg = this.allTotal;
186
- } else if (rowKey.length === 0) {
187
- agg = this.colTotals[flatColKey];
188
- } else if (colKey.length === 0) {
189
- agg = this.rowTotals[flatRowKey];
190
- } else {
191
- agg = this.tree[flatRowKey][flatColKey];
192
- }
193
- return agg != null ? agg : {
194
- value: (function() {
195
- return null;
196
- }),
197
- format: function() {
198
- return "";
199
- }
200
- };
201
- };
202
-
203
- return DRPivotData;
204
-
205
- })($.pivotUtilities.PivotData);
206
-
207
- sortDateStrings = function(month_order) {
208
- var i, mapping, x;
209
- mapping = {};
210
- var order = [
211
- {"month":"jan", "versions": ['january', 'jan', 'ja'], weight:1},
212
- {"month":"feb", "versions": ['february', 'feb', 'fe'], weight:2},
213
- {"month":"mar", "versions": ['march', 'mar', 'mr'], weight:3},
214
- {"month":"apr", "versions": ['april', 'apr', 'ap','al'], weight:4},
215
- {"month":"may", "versions": ['may', 'ma'], weight:5},
216
- {"month":"jun", "versions": ['june', 'jun','jn'], weight:6},
217
- {"month":"jul", "versions": ['july', 'jul','jl'], weight:7},
218
- {"month":"aug", "versions": ['august', 'aug', 'au'], weight:8},
219
- {"month":"sep", "versions": ['september', 'sept', 'sep','sp','se'], weight:9},
220
- {"month":"oct", "versions": ['october','oct', 'oc'], weight:10},
221
- {"month":"nov", "versions": ['november', 'nov', 'no'], weight:11},
222
- {"month":"dec", "versions": ['december', 'dec', 'de'], weight:12}
223
- ];
224
- var pattern = /(\d{1,4})|(Ja(n)?(uary)?|Fe(b)?(ruary)?|Mar(ch)?|mr|Ap(r)?(il)?|al|Ma(y)?|Jun(e)?|jn|Jul(y)?|jl|Aug(ust)?|au|Se(p)?(t)?(ember)?|sp|Oc(t)?(ober)?|No(v)?(ember)?|De(c)?(ember)?)/ig
225
- if(month_order){
226
- for(i=0; i<month_order.length; i++){
227
- var find_row = _.find(order, {month:month_order[i]});
228
- if(find_row){
229
- find_row.weight = i+1;
230
- }
231
- }
232
- }
233
-
234
- _.forEach(order, function(month_obj){
235
- _.forEach(month_obj.versions, function(val){
236
- mapping[val] = month_obj.weight*31;
237
- });
238
- });
239
-
240
- var getIndexForVal = function(value){
241
- var to_return = 0, matches, i;
242
- if (typeof value === 'string' || value instanceof String){
243
- matches = value.match(pattern);
244
- var numbers = 0;
245
- var i = 0;
246
- _.forEach(matches, function(v)
247
- {
248
- i++;
249
- v = v.trim().toLowerCase();
250
- var res = 0;
251
-
252
- if(mapping[v] != undefined){
253
- res = mapping[v];
254
- }
255
- else{
256
- try {
257
- res = parseInt(v)
258
- if(res > 31 || numbers > 1 || i == matches.length)
259
- res *=1000
260
- numbers++;
261
- }
262
- catch(er){
263
- res = 0
264
- }
265
- }
266
- if(res == NaN){
267
- res = 0
268
- }
269
- to_return += res
270
- });
271
- }
272
- else{
273
- try {
274
- to_return = parseInt(value)
275
- }
276
- catch(er){
277
- to_return = value
278
- }
279
- }
280
-
281
- return to_return;
282
- };
283
-
284
- return function(a, b) {
285
- return $.pivotUtilities.naturalSort(getIndexForVal(a), getIndexForVal(b));
286
- };
287
- };
288
-
289
- largeToSmallSort = function(as, bs) {
290
- var a, a1, b, b1, rd, rx, rz;
291
- rx = /(\d+)|(\D+)/g;
292
- rd = /\d/;
293
- rz = /^0/;
294
- if (typeof as === "number" || typeof bs === "number") {
295
- if (isNaN(as)) {
296
- return -1;
297
- }
298
- if (isNaN(bs)) {
299
- return 1;
300
- }
301
- return bs - as;
302
- }
303
- a = String(as).toLowerCase();
304
- b = String(bs).toLowerCase();
305
- if (a === b) {
306
- return 0;
307
- }
308
- if (!(rd.test(a) && rd.test(b))) {
309
- return (b > a ? 1 : -1);
310
- }
311
- a = a.match(rx);
312
- b = b.match(rx);
313
- while (a.length && b.length) {
314
- a1 = a.shift();
315
- b1 = b.shift();
316
- if (a1 !== b1) {
317
- if (rd.test(a1) && rd.test(b1)) {
318
- return b1.replace(rz, ".0") - a1.replace(rz, ".0");
319
- } else {
320
- return (b1 > a1 ? 1 : -1);
321
- }
322
- }
323
- }
324
- return b.length - a.length;
325
- };
326
-
327
- $.pivotUtilities.DRPivotData = DRPivotData;
328
-
329
- getFormattedNumber = function(val, aggregator, opts, format_argument) {
330
- if (!aggregator) {
331
- aggregator = {};
332
- aggregator.format = function(val) {
333
- return val.toLocaleString();
334
- }
335
- }
336
- if (val < 0 && opts && opts.chartOptions && opts.chartOptions.negative_numbers && opts.chartOptions.negative_numbers.value) {
337
- switch (opts.chartOptions.negative_numbers.value) {
338
- case 'red_minus':
339
- return '<span style="color: red; fill: red;">' + aggregator.format(val, format_argument) + '</span>';
340
- break;
341
- case 'absolute':
342
- return '(' + aggregator.format(Math.abs(val), format_argument) + ')';
343
- break;
344
- case 'red_absolute':
345
- return '<span style="color: red; fill: red;">(' + aggregator.format(Math.abs(val), format_argument) + ')</span>';
346
- break;
347
- default:
348
- return aggregator.format(val, format_argument);
349
- }
350
- }
351
- return aggregator.format(val, format_argument);
352
- };
353
-
354
- NovixRenderer = function(pvtData, opts, charttype) {
355
- var resultsArr = [];
356
- var additionOptions = opts.chartOptions ? opts.chartOptions : null;
357
- if (additionOptions && additionOptions.table_options.use_handsOnTable) {
358
- if (opts && opts.chart_title && !opts.chartOptions.hideChartHeader) {
359
- var title = document.createElement("div");
360
- title.className = "title";
361
- title.innerText = opts.chart_title;
362
- resultsArr.push(title);
363
- }
364
-
365
- if (additionOptions && additionOptions.subtitle && additionOptions.subtitle.subtitle && !opts.chartOptions.hideChartHeader) {
366
- console.log("subtitle", additionOptions.subtitle);
367
- var subTitle = document.createElement("div");
368
- subTitle.className = "sub-title";
369
- subTitle.innerText = additionOptions.subtitle.subtitle;
370
- resultsArr.push(subTitle);
371
- }
372
-
373
- resultsArr.push($.pivotUtilities.novix_renderers["Pivot Table"](pvtData, opts));
374
-
375
- // var wrapper = document.createElement("div");
376
- // wrapper.className = "pivot-wrapper2";
377
- // $(wrapper).append(resultsArr);
378
-
379
- return resultsArr;
380
- } else {
381
- let tooMuch = false;
382
- if (pvtData && (pvtData.rowKeys.length > 1000 || pvtData.colKeys.length > 500) &&
383
- (!opts.show_more_function_cols || !opts.show_more_function_cols)) {
384
- pvtData.rowKeys = [];
385
- pvtData.colKeys = [];
386
- tooMuch = true;
387
- }
388
- return SubtotalRenderer(pvtData, opts, charttype, tooMuch);
389
- }
390
- }
391
-
392
- SubtotalRenderer = function(pivotData, opts, charttype, tooMuch = false) {
393
- var addClass, allTotal, arrowCollapsed, arrowExpanded, buildColHeaderHeader, buildColHeaderHeaders, buildColHeaderHeadersClickEvents, buildColHeaders, buildColTotals, buildColTotalsHeader, buildGrandTotal, buildRowHeaderHeaders, buildRowHeaderHeadersClickEvents, buildRowHeaders, buildRowTotalsHeader, buildValues, classColCollapsed, classColExpanded, classColHide, classColShow, classCollapsed, classExpanded, classRowCollapsed, classRowExpanded, classRowHide, classRowShow, clickStatusCollapsed, clickStatusExpanded, colAttrs, colDisableAfter, colKeys, colTotals, collapseCol, collapseColsAt, collapseHideDescendantRow, collapseRow, collapseRowsAt, collapseShowColSubtotal, collapseShowRowSubtotal, createElement, defaults, expandChildCol, expandChildRow, expandCol, expandColsAt, expandHideColSubtotal, expandHideRowSubtotal, expandRow, expandRowsAt, expandShowColSubtotal, expandShowRowSubtotal, getTableEventHandlers, hasClass, hideDescendantCol, isColDisable, isColDisableExpandCollapse, isColHideOnExpand, isRowDisable, isRowDisableExpandCollapse, isRowHideOnExpand, main, getSubtotalInBrackets, processKeys, encodeHtmlEntities, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, removeClass, replaceClass, rowAttrs, rowDisableAfter, rowKeys, rowTotals, setAttributes, showChildCol, showChildRow, toggleCol, toggleColHeaderHeader, toggleRow, toggleRowHeaderHeader, tree, assumptionSubscribe;
394
- var createTotalValsBolder, createGrandTotalBolder, getHeaderColorProperties, colorizeRowLabelHeaders, colorizeTableIfNeed, valueNoDashes, getColorsWithOffsetForTable, offsetColors, handleFreezePanesScroll, selectFreezableElements, removeRowHeaderNullValue;
395
- var edit_assumptions;
396
-
397
- var horizontalFreezePaneClass = opts.chartOptions.table_options.freeze_panes ? ' horizontal-freeze-pane' : '';
398
- var verticalFreezePaneClass = opts.chartOptions.table_options.freeze_panes ? ' vertical-freeze-pane' : '';
399
- var axisFreezePaneClass = opts.chartOptions.table_options.freeze_panes ? ' axis-freeze-pane' : '';
400
-
401
- var elementToTransform = {
402
- X: horizontalFreezePaneClass,
403
- Y: verticalFreezePaneClass,
404
- XY: axisFreezePaneClass,
405
- }
406
-
407
- defaults = {
408
- table: {
409
- clickCallback: null
410
- },
411
- localeStrings: {
412
- totals: "Grand Totals",
413
- subtotals: "Subtotal"
414
- },
415
- chartOptions:{
416
- table_options:{
417
- show_column_total:true,
418
- show_row_total:true
419
- }
420
- },
421
- totalFilterElements: null,
422
- resetSortingElement: null,
423
- nextSortingElement: null,
424
- prevSortingElement: null,
425
- show_more_function_cols: null,
426
- show_more_function_rows: null,
427
- show_more_max_items: 10,
428
- labelsConvertFunction: function(str){return str;}
429
- };
430
- opts = $.extend(true, {}, defaults, opts);
431
-
432
- if(opts.chartOptions.table_options.start_collapsed_rows) {
433
- opts.collapseRowsAt = 0;
434
- }
435
- if(opts.chartOptions.table_options.start_collapsed_columns) {
436
- opts.collapseColsAt = 0;
437
- }
438
- edit_assumptions = opts.chartOptions.edit_assumptions;
439
- isRowDisable = (ref = opts.rowSubtotalDisplay) != null ? ref.disableSubtotal : void 0;
440
- isRowHideOnExpand = (ref1 = opts.rowSubtotalDisplay) != null ? ref1.hideOnExpand : !opts.chartOptions.table_options.show_subtotals_for_rows;
441
- isRowDisableExpandCollapse = (ref2 = opts.rowSubtotalDisplay) != null ? ref2.disableExpandCollapse : void 0;
442
- rowDisableAfter = (ref3 = opts.rowSubtotalDisplay) != null ? ref3.disableAfter != null ? ref3.disableAfter : ref3.disableAfter = 9999 : void 0;
443
- isColDisable = (ref4 = opts.colSubtotalDisplay) != null ? ref4.disableSubtotal : void 0;
444
- isColHideOnExpand = (ref5 = opts.colSubtotalDisplay) != null ? ref5.hideOnExpand : !opts.chartOptions.table_options.show_subtotals_for_columns;
445
- isColDisableExpandCollapse = (ref6 = opts.colSubtotalDisplay) != null ? ref6.disableExpandCollapse : void 0;
446
- colDisableAfter = (ref7 = opts.colSubtotalDisplay) != null ? ref7.disableAfter != null ? ref7.disableAfter : ref7.disableAfter = 9999 : void 0;
447
- arrowCollapsed = opts.arrowCollapsed != null ? opts.arrowCollapsed : opts.arrowCollapsed = '<i class="fa fa-plus dr-icon-add"></i> ';
448
- arrowExpanded = opts.arrowExpanded != null ? opts.arrowExpanded : opts.arrowExpanded = '<i class="fa fa-minus dr-icon-minus"></i> ';
449
- colAttrs = pivotData.colAttrs;
450
- rowAttrs = pivotData.rowAttrs;
451
- rowKeys = pivotData.getRowKeys();
452
-
453
- if (charttype == 'column-chart' || charttype == 'column-chart-stacked') {
454
- if (_.get(opts, 'chartOptions.table_options.transpose_table', false)) {
455
- rowAttrs = [rowAttrs[0]];
456
- if (rowKeys && rowKeys.length) {
457
- rowKeys = rowKeys.map( function(_, index) {
458
- return [rowKeys[index][0]];
459
- });
460
- }
461
- } else {
462
- colAttrs = [colAttrs[0]];
463
- }
464
- }
465
- colKeys = pivotData.getColKeys();
466
- tree = pivotData.tree;
467
- rowTotals = pivotData.rowTotals;
468
- colTotals = pivotData.colTotals;
469
- allTotal = pivotData.allTotal;
470
- classRowExpanded = "rowexpanded";
471
- classRowCollapsed = "rowcollapsed";
472
- classRowHide = "rowhide";
473
- classRowShow = "rowshow";
474
- classColExpanded = "colexpanded";
475
- classColCollapsed = "colcollapsed";
476
- classColHide = "colhide";
477
- classColShow = "colshow";
478
- clickStatusExpanded = "expanded";
479
- clickStatusCollapsed = "collapsed";
480
- classExpanded = "expanded";
481
- classCollapsed = "collapsed";
482
- hasClass = function(element, className) {
483
- var regExp;
484
- regExp = new RegExp("(?:^|\\s)" + className + "(?!\\S)", "g");
485
- return element.className.match(regExp) !== null;
486
- };
487
- removeClass = function(element, className) {
488
- var k, len, name, ref8, regExp, results;
489
- ref8 = className.split(" ");
490
- results = [];
491
- for (k = 0, len = ref8.length; k < len; k++) {
492
- name = ref8[k];
493
- regExp = new RegExp("(?:^|\\s)" + name + "(?!\\S)", "g");
494
- results.push(element.className = element.className.replace(regExp, ''));
495
- }
496
- return results;
497
- };
498
- addClass = function(element, className) {
499
- var k, len, name, ref8, results;
500
- ref8 = className.split(" ");
501
- results = [];
502
- for (k = 0, len = ref8.length; k < len; k++) {
503
- name = ref8[k];
504
- if (!hasClass(element, name)) {
505
- results.push(element.className += " " + name);
506
- } else {
507
- results.push(void 0);
508
- }
509
- }
510
- return results;
511
- };
512
- replaceClass = function(element, replaceClassName, byClassName) {
513
- removeClass(element, replaceClassName);
514
- return addClass(element, byClassName);
515
- };
516
-
517
- colorizeTableIfNeed = function(element){
518
- if(opts.chartOptions.table_options.colorize_headers == true){
519
- element.className += " colorized";
520
- }
521
- };
522
-
523
- valueNoDashes = function(value){
524
-
525
- if(opts.chartOptions.table_options.remove_underscores == true && typeof(value) == 'string'){
526
- return value.replace(/_/g, " ");
527
- }
528
- return value;
529
- };
530
-
531
- offsetColors = function (offset, colorsArray) {
532
- if (offset > opts.defaults_colors.length) {
533
- offset = offset % opts.defaults_colors;
534
- }
535
- var colors_to_return = JSON.parse(JSON.stringify(colorsArray));
536
- for (var i = 0; i < offset; i++) {
537
- colors_to_return.push(colors_to_return.shift());
538
- }
539
- return colors_to_return;
540
- }
541
-
542
- getColorsWithOffsetForTable = function (value) {
543
- var isNewDesign = useNewUx && opts.chartOptions.table_options.use_new_table_design;
544
- if (value) {
545
- var offset = parseInt(value);
546
- if (offset) {
547
- if (isNewDesign) {
548
- return offsetColors(offset, newTableColors);
549
- } else {
550
- return offsetColors(offset, opts.defaults_colors);
551
- }
552
- }
553
- }
554
- return isNewDesign ? newTableColors : opts.defaults_colors;
555
- }
556
-
557
- colorizeRowLabelHeaders = function(element, cols_count){
558
- if(opts.chartOptions.table_options.colorize_headers == true &&
559
- opts.defaults_colors && opts.defaults_colors.length > 0){
560
- var offsetColor = getColorsWithOffsetForTable(opts.chartOptions.table_options.table_colors_offset);
561
- var color_to_set = offsetColor[cols_count];
562
- if(color_to_set){
563
- element.style.setProperty("background-color", color_to_set, "important");
564
- element.style.setProperty("border-color", color_to_set, "important");
565
- element.style.color = useNewUx && opts.chartOptions.table_options.use_new_table_design? '#3a3b39' : '#FFFFFF';
566
- element.style.fontWeight = "bold";
567
- if (opts.chartOptions.table_options.freeze_panes && element.firstChild) {
568
- for (const child of element.children) {
569
- child.style.setProperty("background-color", color_to_set, "important");
570
- }
571
- }
572
- }
573
- }
574
- };
575
-
576
- createTotalValsBolder = function(element){
577
- if(opts.chartOptions.table_options.colorize_headers == true && (!useNewUx || !opts.chartOptions.table_options.use_new_table_design)){
578
- element.style.setProperty("border-bottom", "3px double #000000", "important");
579
- }
580
- };
581
- createGrandTotalBolder = function(element){
582
- if(opts.chartOptions.table_options.colorize_headers == true && (!useNewUx || !opts.chartOptions.table_options.use_new_table_design)){
583
- element.style.setProperty("border-top", "3px solid #000000", "important");
584
- }
585
- };
586
- getHeaderColorProperties = function(element, col_number = 0){
587
- if(opts.chartOptions.table_options.colorize_headers == true &&
588
- opts.defaults_colors && opts.defaults_colors.length > 0){
589
- const offsetColor = getColorsWithOffsetForTable(opts.chartOptions.table_options.table_colors_offset);
590
- var color_to_set = offsetColor[col_number];
591
- if(color_to_set){
592
- element.style.setProperty("background-color", color_to_set, "important");
593
- element.style.setProperty("border-color", color_to_set, "important");
594
- element.style.setProperty("vertical-align", "baseline");
595
- element.style.color = useNewUx && opts.chartOptions.table_options.use_new_table_design? '#3a3b39' : '#FFFFFF';
596
- element.style.fontWeight = "bold";
597
- if (opts.chartOptions.table_options.freeze_panes && element.firstChild) {
598
- for (const child of element.children) {
599
- child.style.setProperty("background-color", color_to_set, "important");
600
- }
601
- }
602
- }
603
- }
604
- };
605
- getTableEventHandlers = function(value, rowValues, colValues) {
606
- var attr, event, eventHandlers, filters, handler, i, ref8;
607
- if (!opts.table && !opts.table.eventHandlers) {
608
- return;
609
- }
610
- eventHandlers = {};
611
- ref8 = opts.table.eventHandlers;
612
- for (event in ref8) {
613
- if (!hasProp.call(ref8, event)) continue;
614
- handler = ref8[event];
615
- filters = {};
616
- for (i in colAttrs) {
617
- if (!hasProp.call(colAttrs, i)) continue;
618
- attr = colAttrs[i];
619
- if (colValues[i] != null) {
620
- filters[attr] = colValues[i];
621
- }
622
- }
623
- for (i in rowAttrs) {
624
- if (!hasProp.call(rowAttrs, i)) continue;
625
- attr = rowAttrs[i];
626
- if (rowValues[i] != null) {
627
- filters[attr] = rowValues[i];
628
- }
629
- }
630
- eventHandlers[event] = function(e) {
631
- return handler(e, value, filters, pivotData);
632
- };
633
- }
634
- return eventHandlers;
635
- };
636
- createElement = function(elementType, className, textContent, attributes, eventHandlers) {
637
- var attr, e, event, handler, val;
638
- e = document.createElement(elementType);
639
- if (className != null) {
640
- e.className = className;
641
- }
642
- if (textContent != null) {
643
- // We need html for negative items.
644
- e.innerHTML = textContent;
645
- }
646
- if (attributes != null) {
647
- for (attr in attributes) {
648
- if (!hasProp.call(attributes, attr)) continue;
649
- val = attributes[attr];
650
- e.setAttribute(attr, val);
651
- }
652
- }
653
- if (eventHandlers != null) {
654
- for (event in eventHandlers) {
655
- if (!hasProp.call(eventHandlers, event)) continue;
656
- handler = eventHandlers[event];
657
- e.addEventListener(event, handler);
658
- }
659
- }
660
- return e;
661
- };
662
- setAttributes = function(e, attrs) {
663
- var a, results, v;
664
- results = [];
665
- for (a in attrs) {
666
- if (!hasProp.call(attrs, a)) continue;
667
- v = attrs[a];
668
- results.push(e.setAttribute(a, v));
669
- }
670
- return results;
671
- };
672
- getSubtotalInBrackets = function(keysArr, className, lastCol, lastRow, from, to) {
673
- let aggregator, val, to_return;
674
- if(opts.chartOptions.table_options.show_subtotals_in_brackets){
675
- if(className == "pvtColLabel" && keysArr[from] && to < keysArr[from].length){
676
- aggregator = pivotData.getAggregator([], keysArr[from].slice(0, to+1));
677
- val = aggregator.value();
678
- to_return = getFormattedNumber(val, aggregator, opts);
679
- return ' ('+to_return+")";
680
- }
681
- else if(className == "pvtRowLabel" && keysArr[from] && to < keysArr[from].length){
682
- aggregator = pivotData.getAggregator(keysArr[from].slice(0, to+1), []);
683
- val = aggregator.value();
684
- to_return = getFormattedNumber(val, aggregator, opts);
685
- return ' ('+to_return+")";
686
- }
687
- }
688
- return '';
689
- };
690
- encodeHtmlEntities = function(string_val) {
691
- if(!string_val || typeof(string_val) != 'string' ){
692
- return string_val;
693
- }
694
- var entityMap = {"'":"&apos;","<":"&lt;",">":"&gt;"," ":"&nbsp;","¡":"&iexcl;","¢":"&cent;","£":"&pound;","¤":"&curren;","¥":"&yen;","¦":"&brvbar;","§":"&sect;","¨":"&uml;","©":"&copy;","ª":"&ordf;","«":"&laquo;","¬":"&not;","®":"&reg;","¯":"&macr;","°":"&deg;","±":"&plusmn;","²":"&sup2;","³":"&sup3;","´":"&acute;","µ":"&micro;","¶":"&para;","·":"&middot;","¸":"&cedil;","¹":"&sup1;","º":"&ordm;","»":"&raquo;","¼":"&frac14;","½":"&frac12;","¾":"&frac34;","¿":"&iquest;","À":"&Agrave;","Á":"&Aacute;","Â":"&Acirc;","Ã":"&Atilde;","Ä":"&Auml;","Å":"&Aring;","Æ":"&AElig;","Ç":"&Ccedil;","È":"&Egrave;","É":"&Eacute;","Ê":"&Ecirc;","Ë":"&Euml;","Ì":"&Igrave;","Í":"&Iacute;","Î":"&Icirc;","Ï":"&Iuml;","Ð":"&ETH;","Ñ":"&Ntilde;","Ò":"&Ograve;","Ó":"&Oacute;","Ô":"&Ocirc;","Õ":"&Otilde;","Ö":"&Ouml;","×":"&times;","Ø":"&Oslash;","Ù":"&Ugrave;","Ú":"&Uacute;","Û":"&Ucirc;","Ü":"&Uuml;","Ý":"&Yacute;","Þ":"&THORN;","ß":"&szlig;","à":"&agrave;","á":"&aacute;","â":"&acirc;","ã":"&atilde;","ä":"&auml;","å":"&aring;","æ":"&aelig;","ç":"&ccedil;","è":"&egrave;","é":"&eacute;","ê":"&ecirc;","ë":"&euml;","ì":"&igrave;","í":"&iacute;","î":"&icirc;","ï":"&iuml;","ð":"&eth;","ñ":"&ntilde;","ò":"&ograve;","ó":"&oacute;","ô":"&ocirc;","õ":"&otilde;","ö":"&ouml;","÷":"&divide;","ø":"&oslash;","ù":"&ugrave;","ú":"&uacute;","û":"&ucirc;","ü":"&uuml;","ý":"&yacute;","þ":"&thorn;","ÿ":"&yuml;","Œ":"&OElig;","œ":"&oelig;","Š":"&Scaron;","š":"&scaron;","Ÿ":"&Yuml;","ƒ":"&fnof;","ˆ":"&circ;","˜":"&tilde;","Α":"&Alpha;","Β":"&Beta;","Γ":"&Gamma;","Δ":"&Delta;","Ε":"&Epsilon;","Ζ":"&Zeta;","Η":"&Eta;","Θ":"&Theta;","Ι":"&Iota;","Κ":"&Kappa;","Λ":"&Lambda;","Μ":"&Mu;","Ν":"&Nu;","Ξ":"&Xi;","Ο":"&Omicron;","Π":"&Pi;","Ρ":"&Rho;","Σ":"&Sigma;","Τ":"&Tau;","Υ":"&Upsilon;","Φ":"&Phi;","Χ":"&Chi;","Ψ":"&Psi;","Ω":"&Omega;","α":"&alpha;","β":"&beta;","γ":"&gamma;","δ":"&delta;","ε":"&epsilon;","ζ":"&zeta;","η":"&eta;","θ":"&theta;","ι":"&iota;","κ":"&kappa;","λ":"&lambda;","μ":"&mu;","ν":"&nu;","ξ":"&xi;","ο":"&omicron;","π":"&pi;","ρ":"&rho;","ς":"&sigmaf;","σ":"&sigma;","τ":"&tau;","υ":"&upsilon;","φ":"&phi;","χ":"&chi;","ψ":"&psi;","ω":"&omega;","ϑ":"&thetasym;","ϒ":"&Upsih;","ϖ":"&piv;","–":"&ndash;","—":"&mdash;","‘":"&lsquo;","’":"&rsquo;","‚":"&sbquo;","“":"&ldquo;","”":"&rdquo;","„":"&bdquo;","†":"&dagger;","‡":"&Dagger;","•":"&bull;","…":"&hellip;","‰":"&permil;","′":"&prime;","″":"&Prime;","‹":"&lsaquo;","›":"&rsaquo;","‾":"&oline;","⁄":"&frasl;","€":"&euro;","ℑ":"&image;","℘":"&weierp;","ℜ":"&real;","™":"&trade;","ℵ":"&alefsym;","←":"&larr;","↑":"&uarr;","→":"&rarr;","↓":"&darr;","↔":"&harr;","↵":"&crarr;","⇐":"&lArr;","⇑":"&UArr;","⇒":"&rArr;","⇓":"&dArr;","⇔":"&hArr;","∀":"&forall;","∂":"&part;","∃":"&exist;","∅":"&empty;","∇":"&nabla;","∈":"&isin;","∉":"&notin;","∋":"&ni;","∏":"&prod;","∑":"&sum;","−":"&minus;","∗":"&lowast;","√":"&radic;","∝":"&prop;","∞":"&infin;","∠":"&ang;","∧":"&and;","∨":"&or;","∩":"&cap;","∪":"&cup;","∫":"&int;","∴":"&there4;","∼":"&sim;","≅":"&cong;","≈":"&asymp;","≠":"&ne;","≡":"&equiv;","≤":"&le;","≥":"&ge;","⊂":"&sub;","⊃":"&sup;","⊄":"&nsub;","⊆":"&sube;","⊇":"&supe;","⊕":"&oplus;","⊗":"&otimes;","⊥":"&perp;","⋅":"&sdot;","⌈":"&lceil;","⌉":"&rceil;","⌊":"&lfloor;","⌋":"&rfloor;","⟨":"&lang;","⟩":"&rang;","◊":"&loz;","♠":"&spades;","♣":"&clubs;","♥":"&hearts;","♦":"&diams;"};
695
- string_val = string_val.replace(/&/g, '&amp;');
696
- string_val = string_val.replace(/"/g, '&quot;');
697
- for (var key in entityMap) {
698
- var entity = entityMap[key];
699
- var regex = new RegExp(key, 'g');
700
- string_val = string_val.replace(regex, entity);
701
- }
702
- return string_val;
703
- };
704
-
705
- processKeys = function(keysArr, className, dimention, attrs) {
706
- var c, headers, k, key, lastCol, lastRow, node, nodePos, r, rMark, ref8, repeats, th, x;
707
- const showAllData = opts && opts.chartOptions && opts.chartOptions.table_options && opts.chartOptions.table_options.show_all;
708
-
709
- headers = [];
710
- lastRow = keysArr.length - 1;
711
- lastCol = keysArr[0].length - 1;
712
- if(lastCol > 0 && className == "pvtColLabel" && !_.get(opts, 'chartOptions.table_options.transpose_table', false) && (charttype == 'column-chart' || charttype == 'column-chart-stacked')){
713
- lastCol = 0;
714
- }
715
- rMark = [];
716
- th = createElement("th", className, valueNoDashes(encodeHtmlEntities(keysArr[0][0]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, 0, 0)));
717
- key = [];
718
- key.push(keysArr[0][0]);
719
- nodePos = 0;
720
- node = {
721
- node: nodePos,
722
- row: 0,
723
- col: 0,
724
- th: th,
725
- parent: null,
726
- children: [],
727
- descendants: lastCol,
728
- leaves: 1,
729
- key: key,
730
- flatKey: key.join(delim)
731
- };
732
- headers.push(node);
733
- rMark[0] = node;
734
- c = 1;
735
- while (c <= lastCol) {
736
- th = createElement("th", className, valueNoDashes(encodeHtmlEntities(keysArr[0][c]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, 0, c)));
737
- key = key.slice();
738
- key.push(keysArr[0][c]);
739
- ++nodePos;
740
- node = {
741
- node: nodePos,
742
- row: 0,
743
- col: c,
744
- th: th,
745
- parent: rMark[c - 1],
746
- children: [],
747
- descendants: lastCol - c,
748
- leaves: 1,
749
- key: key,
750
- flatKey: key.join(delim)
751
- };
752
- rMark[c] = node;
753
- rMark[c - 1].children.push(node);
754
- ++c;
755
- }
756
- rMark[lastCol].leaves = 0;
757
- r = 1;
758
- while (r <= lastRow) {
759
- repeats = true;
760
- key = [];
761
- c = 0;
762
- while (c <= lastCol) {
763
- key = key.slice();
764
- key.push(keysArr[r][c]);
765
- if ((keysArr[r][c] === keysArr[rMark[c].row][c]) && (c !== lastCol) && repeats) {
766
- repeats = true;
767
- ++c;
768
- continue;
769
- }
770
-
771
- if(c === 0 && ((dimention == 'rows' && opts.show_more_function_rows)
772
- || (dimention == 'cols' && opts.show_more_function_cols)
773
- ) && headers.length > opts.show_more_max_items && !showAllData)
774
- {
775
- key=['...'];
776
-
777
- let th_attr = {data_show_more:'1'};
778
-
779
- th = createElement("th", className, '... Show All', th_attr);
780
- ++nodePos;
781
- node = {
782
- node: nodePos,
783
- row: r,
784
- col: c,
785
- th: th,
786
- parent: null,
787
- children: [],
788
- descendants: 0,
789
- leaves: 0,
790
- key: key,
791
- flatKey: key.join(delim)
792
- };
793
-
794
- headers.push(node);
795
- rMark[c] = node;
796
- repeats = false;
797
- r = lastRow;
798
- break;
799
- }
800
-
801
-
802
- th = createElement("th", className, valueNoDashes(encodeHtmlEntities(keysArr[r][c]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, r, c)));
803
- ++nodePos;
804
- node = {
805
- node: nodePos,
806
- row: r,
807
- col: c,
808
- th: th,
809
- parent: null,
810
- children: [],
811
- descendants: 0,
812
- leaves: 0,
813
- key: key,
814
- flatKey: key.join(delim)
815
- };
816
- if (c === 0) {
817
- headers.push(node);
818
- } else {
819
- node.parent = rMark[c - 1];
820
- rMark[c - 1].children.push(node);
821
- x = 0;
822
- while (x <= c - 1) {
823
- ++rMark[x].descendants;
824
- ++x;
825
- }
826
- }
827
- rMark[c] = node;
828
- repeats = false;
829
- ++c;
830
- }
831
- for (c = k = 0, ref8 = lastCol; 0 <= ref8 ? k <= ref8 : k >= ref8; c = 0 <= ref8 ? ++k : --k) {
832
- ++rMark[c].leaves;
833
- }
834
- rMark[lastCol].leaves = 0;
835
- ++r;
836
- }
837
- return headers;
838
- };
839
- buildColHeaderHeader = function(thead, colHeaderHeaders, rowAttrs, colAttrs, tr, col) {
840
- var className, colAttr, textContent, th, clickStatus;
841
- colAttr = colAttrs[col];
842
- textContent = opts.labelsConvertFunction(colAttr);
843
- className = "pvtAxisLabel" + axisFreezePaneClass;
844
- if (col < colAttrs.length - 1) {
845
- if (!(isColDisableExpandCollapse || isColDisable || col > colDisableAfter)) {
846
- if(opts.collapseColsAt == 0){
847
- clickStatus = clickStatusCollapsed;
848
- className += " "+classCollapsed;
849
- textContent = " " + arrowCollapsed + " " + textContent;
850
- }
851
- else{
852
- clickStatus = clickStatusExpanded;
853
- className += " "+classExpanded;
854
- textContent = " " + arrowExpanded + " " + textContent;
855
- }
856
- }
857
- }
858
- th = createElement("th", className, textContent);
859
- th.setAttribute("data-colAttr", colAttr);
860
- //getHeaderColorProperties(th, col);
861
- tr.appendChild(th);
862
- colHeaderHeaders.push({
863
- tr: tr,
864
- th: th,
865
- clickStatus: clickStatus,
866
- expandedCount: 0,
867
- nHeaders: 0
868
- });
869
- return thead.appendChild(tr);
870
- };
871
- buildColHeaderHeaders = function(thead, colHeaderHeaders, rowAttrs, colAttrs) {
872
- var c, k, ref8, results, tr, rowSpan;
873
- tr = createElement("tr");
874
- if (rowAttrs.length !== 0) {
875
- if(opts.chartOptions.table_options.colorize_headers == true){
876
- rowSpan = 1;
877
- }
878
- else{
879
- rowSpan = colAttrs.length;
880
- }
881
- tr.appendChild(createElement("th", axisFreezePaneClass, null, {
882
- colspan: rowAttrs.length,
883
- rowspan: rowSpan
884
- }));
885
- }
886
-
887
- buildColHeaderHeader(thead, colHeaderHeaders, rowAttrs, colAttrs, tr, 0);
888
- getHeaderColorProperties(tr);
889
- results = [];
890
- for (c = k = 1, ref8 = colAttrs.length; 1 <= ref8 ? k <= ref8 : k >= ref8; c = 1 <= ref8 ? ++k : --k) {
891
- if (!(c < colAttrs.length)) {
892
- continue;
893
- }
894
- tr = createElement("tr");
895
- if (opts.chartOptions.table_options.colorize_headers == true && rowAttrs.length !== 0) {
896
- tr.appendChild(createElement("th", axisFreezePaneClass, null, {
897
- colspan: rowAttrs.length
898
- }));
899
- }
900
- getHeaderColorProperties(tr, c);
901
- results.push(buildColHeaderHeader(thead, colHeaderHeaders, rowAttrs, colAttrs, tr, c));
902
- }
903
- return results;
904
- };
905
- buildColHeaderHeadersClickEvents = function(colHeaderHeaders, colHeaderCols, colAttrs) {
906
- var colAttr, i, k, n, ref8, results, th;
907
- n = colAttrs.length - 1;
908
- results = [];
909
- for (i = k = 0, ref8 = n; 0 <= ref8 ? k <= ref8 : k >= ref8; i = 0 <= ref8 ? ++k : --k) {
910
- if (!(i < n)) {
911
- continue;
912
- }
913
- th = colHeaderHeaders[i].th;
914
- colAttr = colAttrs[i];
915
- results.push(th.onclick = function(event) {
916
- event = event || window.event;
917
- if(!event.currentTarget)
918
- event.currentTarget = event.target;
919
- return toggleColHeaderHeader(colHeaderHeaders, colHeaderCols, colAttrs, event.currentTarget.getAttribute("data-colAttr"));
920
- });
921
- }
922
- return results;
923
- };
924
- buildColHeaders = function(colHeaderHeaders, colHeaderCols, colHeader, rowAttrs, colAttrs) {
925
- var colspan, h, hh, isColSubtotal, k, len, ref8, rowspan, sTh, style, th, tr;
926
- ref8 = colHeader.children;
927
- for (k = 0, len = ref8.length; k < len; k++) {
928
- h = ref8[k];
929
- buildColHeaders(colHeaderHeaders, colHeaderCols, h, rowAttrs, colAttrs);
930
- }
931
- isColSubtotal = colHeader.children.length !== 0;
932
- colHeader.node = colHeaderCols.length;
933
- hh = colHeaderHeaders[colHeader.col];
934
- ++hh.expandedCount;
935
- ++hh.nHeaders;
936
- tr = hh.tr;
937
- th = colHeader.th;
938
- addClass(th, "col" + colHeader.row + " colcol" + colHeader.col + " " + classColShow + verticalFreezePaneClass);
939
- //getHeaderColorProperties(th, colHeader.col);
940
- if (isColHideOnExpand || isColDisable || (isColSubtotal && colHeader.col > colDisableAfter)) {
941
- colspan = colHeader.leaves;
942
- } else if (isColSubtotal && colHeader.col <= colDisableAfter) {
943
- colspan = colHeader.leaves + 1;
944
- } else {
945
- colspan = colHeader.descendants + 1;
946
- }
947
-
948
- if(th.getAttribute('data_show_more') == '1'){
949
- rowspan = colAttrs.length + 1;
950
- addClass(th, 'show_more_header');
951
- th.onclick = opts.show_more_function_cols;
952
- }
953
- else{
954
- rowspan = colHeader.col === colAttrs.length - 1 && rowAttrs.length !== 0 ? 2 : 1;
955
- }
956
- setAttributes(th, {
957
- "rowspan": rowspan,
958
- "colspan": colspan,
959
- "data-colnode": colHeader.node,
960
- "data-colHeader": th.textContent
961
- });
962
- if (isColSubtotal) {
963
- addClass(th, classColExpanded);
964
- if (!(isColDisableExpandCollapse || isColDisable || colHeader.col > colDisableAfter)) {
965
- th.innerHTML = " " + arrowExpanded + " " + th.textContent;
966
- }
967
- th.onclick = function(event) {
968
- event = event || window.event;
969
- return toggleCol(colHeaderHeaders, colHeaderCols, parseInt(event.currentTarget.getAttribute("data-colnode")));
970
- };
971
- rowspan = colAttrs.length - (colHeader.col + 1) + (rowAttrs.length !== 0 ? 1 : 0);
972
- style = "pvtColLabel pvtColSubtotal " + classColExpanded + verticalFreezePaneClass;
973
- style += " col" + colHeader.row + " colcol" + colHeader.col;
974
- if (isColHideOnExpand || isColDisable || colHeader.col > colDisableAfter) {
975
- style += " " + classColHide;
976
- }
977
- sTh = createElement("th", style, opts.localeStrings.subtotals, {
978
- "rowspan": rowspan,
979
- "data-colnode": colHeader.node
980
- });
981
- addClass(sTh, isColHideOnExpand || isColDisable ? " " + classColHide : " " + classColShow);
982
- //getHeaderColorProperties(sTh, colHeader.col);
983
- if (isColHideOnExpand || isColDisable || colHeader.col > colDisableAfter) {
984
- sTh.style.display = "none";
985
- }
986
- colHeader.children[0].tr.appendChild(sTh);
987
- colHeader.sTh = sTh;
988
- }
989
- colHeader.clickStatus = clickStatusExpanded;
990
- tr.appendChild(th);
991
- if (opts.chartOptions.table_options.freeze_panes) {
992
- getHeaderColorProperties(tr);
993
- }
994
- colHeader.tr = tr;
995
- return colHeaderCols.push(colHeader);
996
- };
997
- buildRowHeaderHeaders = function(thead, rowHeaderHeaders, rowAttrs, colAttrs) {
998
- var className, i, rowAttr, textContent, th, tr, clickStatus;
999
- tr = createElement("tr");
1000
- rowHeaderHeaders.hh = [];
1001
- for (i in rowAttrs) {
1002
- if (!hasProp.call(rowAttrs, i)) continue;
1003
- rowAttr = rowAttrs[i];
1004
- textContent = opts.labelsConvertFunction(rowAttr);
1005
- className = "pvtAxisLabel" + axisFreezePaneClass;
1006
- if (i < rowAttrs.length - 1) {
1007
- className += " expanded";
1008
- if (!(isRowDisableExpandCollapse || isRowDisable || i > rowDisableAfter)) {
1009
- if(opts.collapseRowsAt == 0){
1010
- clickStatus = clickStatusCollapsed;
1011
- className += " "+classCollapsed;
1012
- textContent = " " + arrowCollapsed + " " + textContent;
1013
- }
1014
- else{
1015
- clickStatus = clickStatusExpanded;
1016
- className += " "+classExpanded;
1017
- textContent = " " + arrowExpanded + " " + textContent;
1018
- }
1019
- }
1020
- }
1021
- th = createElement("th", className, textContent);
1022
- th.setAttribute("data-rowAttr", rowAttr);
1023
- tr.appendChild(th);
1024
- rowHeaderHeaders.hh.push({
1025
- th: th,
1026
- clickStatus: clickStatus,
1027
- expandedCount: 0,
1028
- nHeaders: 0
1029
- });
1030
- }
1031
- if (colAttrs.length !== 0) {
1032
- th = createElement("th", axisFreezePaneClass);
1033
- tr.appendChild(th);
1034
- }
1035
- colorizeRowLabelHeaders(tr, colAttrs.length);
1036
- thead.appendChild(tr);
1037
- return rowHeaderHeaders.tr = tr;
1038
- };
1039
- buildRowHeaderHeadersClickEvents = function(rowHeaderHeaders, rowHeaderRows, rowAttrs) {
1040
- var i, k, n, ref8, results, rowAttr, th;
1041
- n = rowAttrs.length - 1;
1042
- results = [];
1043
- for (i = k = 0, ref8 = n; 0 <= ref8 ? k <= ref8 : k >= ref8; i = 0 <= ref8 ? ++k : --k) {
1044
- if (!(i < n)) {
1045
- continue;
1046
- }
1047
- th = rowHeaderHeaders.hh[i];
1048
- rowAttr = rowAttrs[i];
1049
- results.push(th.th.onclick = function(event) {
1050
- event = event || window.event;
1051
- if(!event.currentTarget)
1052
- event.currentTarget = event.target;
1053
- return toggleRowHeaderHeader(rowHeaderHeaders, rowHeaderRows, rowAttrs, event.currentTarget.getAttribute("data-rowAttr"));
1054
- });
1055
- }
1056
- return results;
1057
- };
1058
- buildRowTotalsHeader = function(tr, rowAttrs, colAttrs) {
1059
- var rowspan, th;
1060
- rowspan = 1;
1061
- if (colAttrs.length !== 0) {
1062
- rowspan = colAttrs.length + (rowAttrs.length === 0 ? 0 : 1);
1063
- }
1064
-
1065
- if(opts.chartOptions.table_options.colorize_headers == true && colAttrs.length > 1){
1066
- rowspan = 1;
1067
- }
1068
-
1069
- th = createElement("th", "pvtTotalLabel rowTotal" + verticalFreezePaneClass , opts.localeStrings.totals, {
1070
- rowspan: rowspan
1071
- });
1072
-
1073
- if (opts.totalFilterElements && opts.totalFilterElements.row_total) {
1074
- th.innerHTML = '';
1075
- th.appendChild(opts.totalFilterElements.row_total);
1076
- }
1077
-
1078
- //getHeaderColorProperties(th);
1079
- if (opts.chartOptions.table_options.freeze_panes) {
1080
- tr.appendChild(th);
1081
- getHeaderColorProperties(tr);
1082
- } else {
1083
- return tr.appendChild(th);
1084
- }
1085
- };
1086
- buildRowHeaders = function(tbody, rowHeaderHeaders, rowHeaderRows, rowHeader, rowAttrs, colAttrs, highlighted, hasColLabels) {
1087
- var colspan, h, hh, isRowSubtotal, k, len, ref8, results, style, th, tr;
1088
- hh = rowHeaderHeaders.hh[rowHeader.col];
1089
- ++hh.expandedCount;
1090
- ++hh.nHeaders;
1091
- tr = createElement("tr", "pvtRowSubtotal row" + rowHeader.row, "", {
1092
- "data-rownode": rowHeader.node
1093
- });
1094
- th = rowHeader.th;
1095
-
1096
- if(th.getAttribute('data_show_more') == '1'){
1097
- colspan = rowAttrs.length + 1;
1098
- addClass(th, 'show_more_header');
1099
- th.onclick = opts.show_more_function_rows;
1100
- }
1101
- else{
1102
- colspan = rowHeader.col === rowAttrs.length - 1 && colAttrs.length !== 0 ? 2 : 1;
1103
- }
1104
-
1105
- isRowSubtotal = rowHeader.children.length !== 0;
1106
- addClass(th, "row" + rowHeader.row + " rowcol" + rowHeader.col + " " + classRowShow + horizontalFreezePaneClass);
1107
- if (highlighted) {
1108
- addClass(th, "highlighted");
1109
- }
1110
- setAttributes(th, {
1111
- "data-rowHeader": th.textContent,
1112
- "data-rownode": rowHeader.node,
1113
- "rowspan": rowHeader.descendants + 1,
1114
- "colspan": colspan
1115
- });
1116
- if (opts.chartOptions.table_options.hide_nulls_in_headers) {
1117
- th.textContent = th.textContent.replace('[null]', '');
1118
- }
1119
-
1120
- if (th.hasAttribute('data_show_more') && th.colSpan > 0 && !hasColLabels) {
1121
- th.colSpan = th.colSpan - 1;
1122
- }
1123
-
1124
- tr.appendChild(th);
1125
- if (isRowSubtotal) {
1126
- addClass(tr, classRowExpanded);
1127
- addClass(th, classRowExpanded);
1128
- if (!(isRowDisableExpandCollapse || isRowDisable || rowHeader.col > rowDisableAfter)) {
1129
- th.innerHTML = " " + arrowExpanded + " " + th.textContent;
1130
- }
1131
- th.onclick = function(event) {
1132
- event = event || window.event;
1133
- return toggleRow(rowHeaderHeaders, rowHeaderRows, parseInt(event.currentTarget.getAttribute("data-rownode")));
1134
- };
1135
- colspan = rowAttrs.length - (rowHeader.col + 1) + (colAttrs.length !== 0 ? 1 : 0);
1136
- style = "pvtRowLabel pvtRowSubtotal " + classRowExpanded;
1137
- style += " row" + rowHeader.row + " rowcol" + rowHeader.col;
1138
- style += isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter ? " " + classRowHide : " " + classRowShow;
1139
- style += horizontalFreezePaneClass;
1140
- th = createElement("th", style, opts.localeStrings.subtotals, {
1141
- "colspan": colspan,
1142
- "data-rownode": rowHeader.node
1143
- });
1144
- if (isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter) {
1145
- th.style.display = "none";
1146
- }
1147
- tr.appendChild(th);
1148
- }
1149
- rowHeader.clickStatus = clickStatusExpanded;
1150
- rowHeader.tr = tr;
1151
- rowHeaderRows.push(rowHeader);
1152
- tbody.appendChild(tr);
1153
- ref8 = rowHeader.children;
1154
- results = [];
1155
- for (k = 0, len = ref8.length; k < len; k++) {
1156
- h = ref8[k];
1157
- results.push(buildRowHeaders(tbody, rowHeaderHeaders, rowHeaderRows, h, rowAttrs, colAttrs, highlighted, hasColLabels));
1158
- }
1159
- return results;
1160
- };
1161
- buildValues = function(rowHeaderRows, colHeaderCols, rowAttrs, colAttrs) {
1162
- var aggregator, colHeader, eventHandlers, flatColKey, flatRowKey, isColSubtotal, isRowSubtotal, k, l, len, len1, ref8, results, rowHeader, style, td, totalAggregator, tr, val;
1163
- results = [];
1164
- for (k = 0, len = rowHeaderRows.length; k < len; k++) {
1165
- rowHeader = rowHeaderRows[k];
1166
- tr = rowHeader.tr;
1167
- flatRowKey = rowHeader.flatKey;
1168
- isRowSubtotal = rowHeader.children.length !== 0;
1169
- for (l = 0, len1 = colHeaderCols.length; l < len1; l++) {
1170
- colHeader = colHeaderCols[l];
1171
- flatColKey = colHeader.flatKey;
1172
- if(tree && tree[flatRowKey] && tree[flatRowKey][flatColKey]){
1173
- ref8 = tree[flatRowKey][flatColKey]
1174
- }
1175
- else{
1176
- ref8 = null;
1177
- }
1178
-
1179
- aggregator = ref8 != null ? ref8 : {
1180
- value: (function() {
1181
- return null;
1182
- }),
1183
- format: function() {
1184
- return "";
1185
- }
1186
- };
1187
- val = aggregator.value();
1188
- isColSubtotal = colHeader.children.length !== 0;
1189
- style = "pvtVal";
1190
- if (isColSubtotal) {
1191
- style += " pvtColSubtotal " + classColExpanded;
1192
- }
1193
- if (isRowSubtotal) {
1194
- style += " pvtRowSubtotal " + classRowExpanded;
1195
- }
1196
- style += isRowSubtotal && (isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter) ? " " + classRowHide : " " + classRowShow;
1197
- style += isColSubtotal && (isColHideOnExpand || isColDisable || colHeader.col > colDisableAfter) ? " " + classColHide : " " + classColShow;
1198
- style += (" row" + rowHeader.row) + (" col" + colHeader.row) + (" rowcol" + rowHeader.col) + (" colcol" + colHeader.col);
1199
- eventHandlers = getTableEventHandlers(val, rowHeader.key, colHeader.key);
1200
- td = createElement("td", style, getFormattedNumber(val, aggregator, opts), {
1201
- "data-value": val,
1202
- "data-rownode": rowHeader.node,
1203
- "data-colnode": colHeader.node
1204
- }, eventHandlers);
1205
- if ((isRowSubtotal && (isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter)) || (isColSubtotal && (isColHideOnExpand || isColDisable || colHeader.col > colDisableAfter))) {
1206
- td.style.display = "none";
1207
- }
1208
- assumptionSubscribe(td, rowHeader, rowAttrs, colHeader, colAttrs, val);
1209
-
1210
- tr.appendChild(td);
1211
- }
1212
- totalAggregator = rowTotals[flatRowKey];
1213
- if(!totalAggregator){
1214
- totalAggregator = {
1215
- value: (function () {
1216
- return null;
1217
- }),
1218
- format: function () {
1219
- return "";
1220
- }
1221
- };
1222
- }
1223
-
1224
- val = totalAggregator.value();
1225
- style = "pvtTotal rowTotal";
1226
- if (isRowSubtotal) {
1227
- style += " pvtRowSubtotal";
1228
- }
1229
- style += isRowSubtotal && (isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter) ? " " + classRowHide : " " + classRowShow;
1230
- style += " row" + rowHeader.row + " rowcol" + rowHeader.col;
1231
- td = createElement("td", style, getFormattedNumber(val, totalAggregator, opts), {
1232
- "data-value": val,
1233
- "data-row": "row" + rowHeader.row,
1234
- "data-rowcol": "col" + rowHeader.col,
1235
- "data-rownode": rowHeader.node
1236
- }, getTableEventHandlers(val, rowHeader.key, []));
1237
- if (isRowSubtotal && (isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter)) {
1238
- td.style.display = "none";
1239
- }
1240
-
1241
- assumptionSubscribe(td, rowHeader, rowAttrs, {key:[], flatKey:''}, colAttrs, val);
1242
-
1243
- if(opts.chartOptions.table_options.show_row_total)
1244
- tr.appendChild(td);
1245
-
1246
- results.push(tr);
1247
- }
1248
- return results;
1249
- };
1250
-
1251
- assumptionSubscribe = function(td, rowHeader, rowAttrs, colHeader, colAttrs, val){
1252
- if(edit_assumptions){
1253
- var filters = [];
1254
- var i=0;
1255
- var temp;
1256
- for(i=0; i<rowHeader.key.length; i++){
1257
- temp = {
1258
- name: rowAttrs[i],
1259
- values: [rowHeader.key[i]],
1260
- is_excluded:false
1261
- }
1262
- filters.push(temp);
1263
- }
1264
- for(i=0; i<colHeader.key.length; i++){
1265
- temp = {
1266
- name: colAttrs[i],
1267
- values: [colHeader.key[i]],
1268
- is_excluded:false
1269
- }
1270
- filters.push(temp);
1271
- }
1272
- var obj_to_send = {
1273
- "flatColKey": colHeader.flatKey,
1274
- "flatRowKey": rowHeader.flatKey,
1275
- "val": val,
1276
- "filters": filters
1277
- };
1278
-
1279
- // td.addEventListener('dblclick', function(){
1280
- // edit_assumptions.fn(obj_to_send, this);
1281
- // });
1282
-
1283
- td.addEventListener('click', function(){
1284
- edit_assumptions.fn(obj_to_send, this);
1285
- });
1286
- }
1287
-
1288
- if(opts.value_drill_down_fn){
1289
- td.classList.add('clickable');
1290
- td.addEventListener('click', function(rowKey, colKey, rowAttrs, colAttrs){
1291
- return function($event){
1292
- $event.preventDefault();
1293
- opts.value_drill_down_fn($event, rowKey, colKey);
1294
- };
1295
- }(rowHeader.key, colHeader.key, rowAttrs, colAttrs));
1296
- }
1297
- };
1298
-
1299
- buildColTotalsHeader = function(rowAttrs, colAttrs) {
1300
- var colspan, th, tr;
1301
- tr = createElement("tr");
1302
- colspan = rowAttrs.length + (colAttrs.length === 0 ? 0 : 1);
1303
- th = createElement("th", "pvtTotalLabel colTotal" + horizontalFreezePaneClass, opts.localeStrings.totals, {
1304
- colspan: colspan
1305
- });
1306
- if (opts.totalFilterElements && opts.totalFilterElements.col_total) {
1307
- th.innerHTML = '';
1308
- th.appendChild(opts.totalFilterElements.col_total);
1309
- }
1310
- tr.appendChild(th);
1311
- return tr;
1312
- };
1313
- buildColTotals = function(tr, colHeaderCols, rowAttrs, colAttrs) {
1314
- var h, isColSubtotal, k, len, results, style, td, totalAggregator, val;
1315
- results = [];
1316
- for (k = 0, len = colHeaderCols.length; k < len; k++) {
1317
- h = colHeaderCols[k];
1318
- isColSubtotal = h.children.length !== 0;
1319
- totalAggregator = colTotals[h.flatKey];
1320
- if(!totalAggregator){
1321
- totalAggregator = {
1322
- value: (function () {
1323
- return null;
1324
- }),
1325
- format: function () {
1326
- return "";
1327
- }
1328
- };
1329
- }
1330
- val = totalAggregator.value();
1331
- style = "pvtVal pvtTotal colTotal";
1332
- if (isColSubtotal) {
1333
- style += " pvtColSubtotal";
1334
- }
1335
- style += " " + classColExpanded;
1336
- style += " col" + h.row + " colcol" + h.col;
1337
- td = createElement("td", style, getFormattedNumber(val, totalAggregator, opts), {
1338
- "data-value": val,
1339
- "data-for": "col" + h.col,
1340
- "data-colnode": "" + h.node
1341
- }, getTableEventHandlers(val, [], h.key));
1342
- createTotalValsBolder(td)
1343
- if (isColSubtotal && (isColHideOnExpand || isColDisable || h.col > colDisableAfter)) {
1344
- td.style.display = "none";
1345
- }
1346
-
1347
- assumptionSubscribe(td, {key:[], flatKey:''}, rowAttrs, h, colAttrs, val);
1348
-
1349
- results.push(tr.appendChild(td));
1350
- }
1351
- createGrandTotalBolder(tr);
1352
- return results;
1353
- };
1354
- buildGrandTotal = function(result, tr, rowAttrs, colAttrs) {
1355
- var td, totalAggregator, val;
1356
- totalAggregator = allTotal;
1357
- val = totalAggregator.value();
1358
- td = createElement("td", "pvtGrandTotal", getFormattedNumber(val, totalAggregator, opts), {
1359
- "data-value": val
1360
- }, getTableEventHandlers(val, [], []));
1361
- createTotalValsBolder(td);
1362
- assumptionSubscribe(td, {key:[], flatKey:''}, rowAttrs, {key:[], flatKey:''}, colAttrs, val);
1363
-
1364
- tr.appendChild(td);
1365
- return result.appendChild(tr);
1366
- };
1367
- removeRowHeaderNullValue = function(h) {
1368
- if (opts.chartOptions.table_options.hide_nulls_in_headers) {
1369
- h.th.innerHTML = h.th.innerHTML.replace('[null]' , '');
1370
- }
1371
- };
1372
- hideDescendantCol = function(d) {
1373
- return $(d.th).closest('table.pvtTable').find("tbody tr td[data-colnode=\"" + d.node + "\"], th[data-colnode=\"" + d.node + "\"]").removeClass(classColShow).addClass(classColHide).css('display', "none");
1374
- };
1375
- collapseShowColSubtotal = function(h) {
1376
- $(h.th).closest('table.pvtTable').find("tbody tr td[data-colnode=\"" + h.node + "\"], th[data-colnode=\"" + h.node + "\"]").removeClass(classColExpanded + " " + classColHide).addClass(classColCollapsed + " " + classColShow).not(".pvtRowSubtotal." + classRowHide).css('display', "");
1377
- h.th.innerHTML = " " + arrowCollapsed + " " + h.th.getAttribute("data-colheader");
1378
- return h.th.colSpan = 1;
1379
- };
1380
- collapseCol = function(colHeaderHeaders, colHeaderCols, c) {
1381
- var colHeaderHeader, colspan, d, h, i, isColSubtotal, k, l, p, ref10, ref8, ref9, results;
1382
- if (isColDisable) {
1383
- return;
1384
- }
1385
- if (isColDisableExpandCollapse) {
1386
- return;
1387
- }
1388
- if (!colHeaderCols[c]) {
1389
- return;
1390
- }
1391
- h = colHeaderCols[c];
1392
- if (h.col > colDisableAfter) {
1393
- return;
1394
- }
1395
- if (h.clickStatus === clickStatusCollapsed) {
1396
- return;
1397
- }
1398
- isColSubtotal = h.descendants !== 0;
1399
- colspan = h.th.colSpan;
1400
- for (i = k = 1, ref8 = h.descendants; 1 <= ref8 ? k <= ref8 : k >= ref8; i = 1 <= ref8 ? ++k : --k) {
1401
- if (!(h.descendants !== 0)) {
1402
- continue;
1403
- }
1404
- d = colHeaderCols[c - i];
1405
- hideDescendantCol(d);
1406
- }
1407
- if (isColSubtotal) {
1408
- collapseShowColSubtotal(h);
1409
- --colspan;
1410
- }
1411
- p = h.parent;
1412
- while (p !== null) {
1413
- p.th.colSpan -= colspan;
1414
- p = p.parent;
1415
- }
1416
- h.clickStatus = clickStatusCollapsed;
1417
- colHeaderHeader = colHeaderHeaders[h.col];
1418
- colHeaderHeader.expandedCount--;
1419
- if (colHeaderHeader.expandedCount === 0) {
1420
- results = [];
1421
- for (i = l = ref9 = h.col, ref10 = colHeaderHeaders.length - 2; ref9 <= ref10 ? l <= ref10 : l >= ref10; i = ref9 <= ref10 ? ++l : --l) {
1422
- if (!(i <= colDisableAfter)) {
1423
- continue;
1424
- }
1425
- colHeaderHeader = colHeaderHeaders[i];
1426
- replaceClass(colHeaderHeader.th, classExpanded, classCollapsed);
1427
- colHeaderHeader.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(colHeaderHeader.th.getAttribute("data-colAttr"));
1428
- results.push(colHeaderHeader.clickStatus = clickStatusCollapsed);
1429
- }
1430
- return results;
1431
- }
1432
- };
1433
- showChildCol = function(ch) {
1434
- return $(ch.th).closest('table.pvtTable').find("tbody tr td[data-colnode=\"" + ch.node + "\"], th[data-colnode=\"" + ch.node + "\"]").removeClass(classColHide).addClass(classColShow).not(".pvtRowSubtotal." + classRowHide).css('display', "");
1435
- };
1436
- expandHideColSubtotal = function(h) {
1437
- $(h.th).closest('table.pvtTable').find("tbody tr td[data-colnode=\"" + h.node + "\"], th[data-colnode=\"" + h.node + "\"]").removeClass(classColCollapsed + " " + classColShow).addClass(classColExpanded + " " + classColHide).css('display', "none");
1438
- return h.th.style.display = "";
1439
- };
1440
- expandShowColSubtotal = function(h) {
1441
- $(h.th).closest('table.pvtTable').find("tbody tr td[data-colnode=\"" + h.node + "\"], th[data-colnode=\"" + h.node + "\"]").removeClass(classColCollapsed + " " + classColHide).addClass(classColExpanded + " " + classColShow).not(".pvtRowSubtotal." + classRowHide).css('display', "");
1442
- h.th.style.display = "";
1443
- ++h.th.colSpan;
1444
- if (h.sTh != null) {
1445
- return h.sTh.style.display = "";
1446
- }
1447
- };
1448
- expandChildCol = function(ch) {
1449
- var gch, k, len, ref8, results;
1450
- if (ch.descendants !== 0 && hasClass(ch.th, classColExpanded) && (isColHideOnExpand || isColDisable || ch.col > colDisableAfter)) {
1451
- ch.th.style.display = "";
1452
- } else {
1453
- showChildCol(ch);
1454
- }
1455
- if (ch.clickStatus !== clickStatusCollapsed) {
1456
- ref8 = ch.children;
1457
- results = [];
1458
- for (k = 0, len = ref8.length; k < len; k++) {
1459
- gch = ref8[k];
1460
- results.push(expandChildCol(gch));
1461
- }
1462
- return results;
1463
- }
1464
- };
1465
- expandCol = function(colHeaderHeaders, colHeaderCols, c) {
1466
- var ch, colspan, h, hh, isColSubtotal, k, len, p, ref8;
1467
- if (isColDisable) {
1468
- return;
1469
- }
1470
- if (isColDisableExpandCollapse) {
1471
- return;
1472
- }
1473
- if (!colHeaderCols[c]) {
1474
- return;
1475
- }
1476
- h = colHeaderCols[c];
1477
- if (h.col > colDisableAfter) {
1478
- return;
1479
- }
1480
- if (h.clickStatus === clickStatusExpanded) {
1481
- return;
1482
- }
1483
- isColSubtotal = h.descendants !== 0;
1484
- colspan = 0;
1485
- ref8 = h.children;
1486
- for (k = 0, len = ref8.length; k < len; k++) {
1487
- ch = ref8[k];
1488
- expandChildCol(ch);
1489
- colspan += ch.th.colSpan;
1490
- }
1491
- h.th.colSpan = colspan;
1492
- if (isColSubtotal) {
1493
- replaceClass(h.th, classColCollapsed, classColExpanded);
1494
- h.th.innerHTML = " " + arrowExpanded + " " + h.th.getAttribute("data-colHeader");
1495
- if (isColHideOnExpand) {
1496
- expandHideColSubtotal(h);
1497
- --colspan;
1498
- } else {
1499
- expandShowColSubtotal(h);
1500
- }
1501
- }
1502
- p = h.parent;
1503
- while (p) {
1504
- p.th.colSpan += colspan;
1505
- p = p.parent;
1506
- }
1507
- h.clickStatus = clickStatusExpanded;
1508
- hh = colHeaderHeaders[h.col];
1509
- ++hh.expandedCount;
1510
- if (hh.expandedCount === hh.nHeaders) {
1511
- replaceClass(hh.th, classCollapsed, classExpanded);
1512
- hh.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(hh.th.getAttribute("data-colAttr"));
1513
- return hh.clickStatus = clickStatusExpanded;
1514
- }
1515
- };
1516
- collapseHideDescendantRow = function(h) {
1517
- var cell, cells, k, len, ref8, results, tagName;
1518
- h.tr.style.display = "none";
1519
- ref8 = ["td", "th"];
1520
- results = [];
1521
- for (k = 0, len = ref8.length; k < len; k++) {
1522
- tagName = ref8[k];
1523
- cells = h.tr.getElementsByTagName(tagName);
1524
- results.push((function() {
1525
- var l, len1, results1;
1526
- results1 = [];
1527
- for (l = 0, len1 = cells.length; l < len1; l++) {
1528
- cell = cells[l];
1529
- replaceClass(cell, classRowShow, classRowHide);
1530
- results1.push(cell.style.display = "none");
1531
- }
1532
- return results1;
1533
- })());
1534
- }
1535
- return results;
1536
- };
1537
- collapseShowRowSubtotal = function(h) {
1538
- var cell, cells, k, l, len, len1, ref8, tagName;
1539
- ref8 = ["td", "th"];
1540
- for (k = 0, len = ref8.length; k < len; k++) {
1541
- tagName = ref8[k];
1542
- cells = h.tr.getElementsByTagName(tagName);
1543
- for (l = 0, len1 = cells.length; l < len1; l++) {
1544
- cell = cells[l];
1545
- removeClass(cell, classRowExpanded + " " + classRowHide);
1546
- addClass(cell, classRowCollapsed + " " + classRowShow);
1547
- if (!hasClass(cell, classColHide)) {
1548
- cell.style.display = "";
1549
- }
1550
- }
1551
- }
1552
- h.th.rowSpan = 1;
1553
- h.th.innerHTML = " " + arrowCollapsed + " " + h.th.getAttribute("data-rowHeader");
1554
- return replaceClass(h.tr, classRowExpanded, classRowCollapsed);
1555
- };
1556
- collapseRow = function(rowHeaderHeaders, rowHeaderRows, r) {
1557
- var d, h, i, isRowSubtotal, j, k, l, p, ref10, ref8, ref9, results, rowHeaderHeader, rowspan;
1558
- if (isRowDisable) {
1559
- return;
1560
- }
1561
- if (isRowDisableExpandCollapse) {
1562
- return;
1563
- }
1564
- if (!rowHeaderRows[r]) {
1565
- return;
1566
- }
1567
- h = rowHeaderRows[r];
1568
- if (h.col > rowDisableAfter) {
1569
- return;
1570
- }
1571
- if (h.clickStatus === clickStatusCollapsed) {
1572
- return;
1573
- }
1574
- isRowSubtotal = h.descendants !== 0;
1575
- rowspan = h.th.rowSpan;
1576
- for (i = k = 1, ref8 = h.descendants; 1 <= ref8 ? k <= ref8 : k >= ref8; i = 1 <= ref8 ? ++k : --k) {
1577
- if (!(h.descendants !== 0)) {
1578
- continue;
1579
- }
1580
- d = rowHeaderRows[r + i];
1581
- collapseHideDescendantRow(d);
1582
- }
1583
- if (isRowSubtotal) {
1584
- collapseShowRowSubtotal(h);
1585
- --rowspan;
1586
- }
1587
-
1588
- removeRowHeaderNullValue(h);
1589
-
1590
- p = h.parent;
1591
- while (p) {
1592
- p.th.rowSpan -= rowspan;
1593
- p = p.parent;
1594
- }
1595
- h.clickStatus = clickStatusCollapsed;
1596
- rowHeaderHeader = rowHeaderHeaders.hh[h.col];
1597
- rowHeaderHeader.expandedCount--;
1598
- if (rowHeaderHeader.expandedCount !== 0) {
1599
- return;
1600
- }
1601
- results = [];
1602
- for (j = l = ref9 = h.col, ref10 = rowHeaderHeaders.hh.length - 2; ref9 <= ref10 ? l <= ref10 : l >= ref10; j = ref9 <= ref10 ? ++l : --l) {
1603
- if (!(j <= rowDisableAfter)) {
1604
- continue;
1605
- }
1606
- rowHeaderHeader = rowHeaderHeaders.hh[j];
1607
- replaceClass(rowHeaderHeader.th, classExpanded, classCollapsed);
1608
- rowHeaderHeader.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(rowHeaderHeader.th.getAttribute("data-rowAttr"));
1609
- results.push(rowHeaderHeader.clickStatuatus = clickStatusCollapsed);
1610
- }
1611
- return results;
1612
- };
1613
- showChildRow = function(h) {
1614
- var cell, cells, k, l, len, len1, ref8, tagName;
1615
- ref8 = ["td", "th"];
1616
- for (k = 0, len = ref8.length; k < len; k++) {
1617
- tagName = ref8[k];
1618
- cells = h.tr.getElementsByTagName(tagName);
1619
- for (l = 0, len1 = cells.length; l < len1; l++) {
1620
- cell = cells[l];
1621
- replaceClass(cell, classRowHide, classRowShow);
1622
- if (!hasClass(cell, classColHide)) {
1623
- cell.style.display = "";
1624
- }
1625
- }
1626
- }
1627
- return h.tr.style.display = "";
1628
- };
1629
- expandShowRowSubtotal = function(h) {
1630
- var cell, cells, k, l, len, len1, ref8, tagName;
1631
- ref8 = ["td", "th"];
1632
- for (k = 0, len = ref8.length; k < len; k++) {
1633
- tagName = ref8[k];
1634
- cells = h.tr.getElementsByTagName(tagName);
1635
- for (l = 0, len1 = cells.length; l < len1; l++) {
1636
- cell = cells[l];
1637
- removeClass(cell, classRowCollapsed + " " + classRowHide);
1638
- addClass(cell, classRowExpanded + " " + classRowShow);
1639
- if (!hasClass(cell, classColHide)) {
1640
- cell.style.display = "";
1641
- }
1642
- }
1643
- }
1644
- h.th.innerHTML = " " + arrowExpanded + " " + h.th.getAttribute("data-rowHeader");
1645
- return replaceClass(h.tr, classRowCollapsed, classRowExpanded);
1646
- };
1647
- expandHideRowSubtotal = function(h) {
1648
- var cell, cells, k, l, len, len1, ref8, tagName;
1649
- ref8 = ["td", "th"];
1650
- for (k = 0, len = ref8.length; k < len; k++) {
1651
- tagName = ref8[k];
1652
- cells = h.tr.getElementsByTagName(tagName);
1653
- for (l = 0, len1 = cells.length; l < len1; l++) {
1654
- cell = cells[l];
1655
- removeClass(cell, classRowCollapsed + " " + classRowShow);
1656
- addClass(cell, classRowExpanded + " " + classRowHide);
1657
- cell.style.display = "none";
1658
- }
1659
- }
1660
- h.th.style.display = "";
1661
- h.th.innerHTML = " " + arrowExpanded + " " + h.th.getAttribute("data-rowHeader");
1662
- return replaceClass(h.tr, classRowCollapsed, classRowExpanded);
1663
- };
1664
- expandChildRow = function(ch) {
1665
- var gch, k, len, ref8, results;
1666
- if (ch.descendants !== 0 && hasClass(ch.th, classRowExpanded) && (isRowHideOnExpand || isRowDisable || ch.col > rowDisableAfter)) {
1667
- ch.tr.style.display = "";
1668
- ch.th.style.display = "";
1669
- } else {
1670
- showChildRow(ch);
1671
- }
1672
- if (ch.clickStatus !== clickStatusCollapsed) {
1673
- ref8 = ch.children;
1674
- results = [];
1675
- for (k = 0, len = ref8.length; k < len; k++) {
1676
- gch = ref8[k];
1677
- results.push(expandChildRow(gch));
1678
- }
1679
- return results;
1680
- }
1681
- };
1682
- expandRow = function(rowHeaderHeaders, rowHeaderRows, r) {
1683
- var ch, h, hh, isRowSubtotal, k, len, p, ref8, rowspan;
1684
- if (isRowDisable) {
1685
- return;
1686
- }
1687
- if (isRowDisableExpandCollapse) {
1688
- return;
1689
- }
1690
- if (!rowHeaderRows[r]) {
1691
- return;
1692
- }
1693
- h = rowHeaderRows[r];
1694
- if (h.col > rowDisableAfter) {
1695
- return;
1696
- }
1697
- if (h.clickStatus === clickStatusExpanded) {
1698
- return;
1699
- }
1700
- isRowSubtotal = h.descendants !== 0;
1701
- rowspan = 0;
1702
- ref8 = h.children;
1703
- for (k = 0, len = ref8.length; k < len; k++) {
1704
- ch = ref8[k];
1705
- expandChildRow(ch);
1706
- rowspan += ch.th.rowSpan;
1707
- }
1708
- h.th.rowSpan = rowspan + 1;
1709
- if (isRowSubtotal) {
1710
- if (isRowHideOnExpand) {
1711
- expandHideRowSubtotal(h);
1712
- } else {
1713
- expandShowRowSubtotal(h);
1714
- }
1715
- }
1716
-
1717
- removeRowHeaderNullValue(h);
1718
-
1719
- p = h.parent;
1720
- while (p) {
1721
- p.th.rowSpan += rowspan;
1722
- p = p.parent;
1723
- }
1724
- h.clickStatus = clickStatusExpanded;
1725
- hh = rowHeaderHeaders.hh[h.col];
1726
- ++hh.expandedCount;
1727
- if (hh.expandedCount === hh.nHeaders) {
1728
- replaceClass(hh.th, classCollapsed, classExpanded);
1729
- hh.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(hh.th.getAttribute("data-rowAttr"));
1730
- return hh.clickStatus = clickStatusExpanded;
1731
- }
1732
- };
1733
- toggleCol = function(colHeaderHeaders, colHeaderCols, c) {
1734
- var h, allClass, mainClass, is_other, main_th;
1735
- if (colHeaderCols[c] == null) {
1736
- return;
1737
- }
1738
- h = colHeaderCols[c];
1739
- if (h.clickStatus === clickStatusCollapsed) {
1740
- allClass = classColCollapsed;
1741
- mainClass = classCollapsed;
1742
- expandCol(colHeaderHeaders, colHeaderCols, c);
1743
- } else {
1744
- collapseCol(colHeaderHeaders, colHeaderCols, c);
1745
- mainClass = classExpanded;
1746
- allClass = classColExpanded;
1747
- }
1748
-
1749
- is_other = $('.pvtColLabel.'+allClass,h.tr).not('.pvtColSubtotal').length;
1750
- if(is_other == 0){
1751
- $('.pvtAxisLabel.'+mainClass,h.tr).trigger( "click" );
1752
- }
1753
-
1754
- return h.th.scrollIntoView;
1755
- };
1756
- toggleRow = function(rowHeaderHeaders, rowHeaderRows, r) {
1757
- var h, allClass, mainClass, is_other, main_th, hh;
1758
-
1759
- if (rowHeaderRows[r] == null) {
1760
- return;
1761
- }
1762
-
1763
- h = rowHeaderRows[r];
1764
-
1765
- if (rowHeaderRows[r].clickStatus === clickStatusCollapsed) {
1766
- expandRow(rowHeaderHeaders, rowHeaderRows, r);
1767
- allClass = clickStatusCollapsed;
1768
- mainClass = classCollapsed;
1769
- } else {
1770
- collapseRow(rowHeaderHeaders, rowHeaderRows, r);
1771
- allClass = clickStatusExpanded;
1772
- mainClass = classExpanded;
1773
-
1774
- /*is_other = _.find(rowHeaderRows, {col:h.col, clickStatus:allClass});
1775
- if(!is_other){
1776
- hh = rowHeaderHeaders.hh[h.col];
1777
- if(hh && hh.th && $(hh.th).hasClass(mainClass)){
1778
- $(hh.th).trigger('click');
1779
- }
1780
- }*/
1781
- }
1782
-
1783
- return h.th.scrollIntoView;
1784
- };
1785
- collapseColsAt = function(colHeaderHeaders, colHeaderCols, colAttrs, colAttr) {
1786
- var h, hh, i, idx, nAttrs, nCols, results;
1787
- if (isColDisable) {
1788
- return;
1789
- }
1790
- if (typeof colAttr === 'string') {
1791
- idx = colAttrs.indexOf(colAttr);
1792
- } else {
1793
- idx = colAttr;
1794
- }
1795
- if (idx < 0 || idx === colAttrs.length - 1) {
1796
- return;
1797
- }
1798
- i = idx;
1799
- nAttrs = colAttrs.length - 1;
1800
- while (i < nAttrs && i <= colDisableAfter) {
1801
- hh = colHeaderHeaders[i];
1802
- replaceClass(hh.th, classExpanded, classCollapsed);
1803
- hh.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(colAttrs[i]);
1804
- hh.clickStatus = clickStatusCollapsed;
1805
- ++i;
1806
- }
1807
- i = 0;
1808
- nCols = colHeaderCols.length;
1809
- results = [];
1810
- while (i < nCols) {
1811
- h = colHeaderCols[i];
1812
- if (h.col === idx && h.clickStatus !== clickStatusCollapsed && h.th.style.display !== "none") {
1813
- collapseCol(colHeaderHeaders, colHeaderCols, parseInt(h.th.getAttribute("data-colnode")));
1814
- }
1815
- results.push(++i);
1816
- }
1817
- return results;
1818
- };
1819
- expandColsAt = function(colHeaderHeaders, colHeaderCols, colAttrs, colAttr) {
1820
- var colHeaderHeader, h, hh, i, idx, j, k, nCols, ref8, results;
1821
- if (isColDisable) {
1822
- return;
1823
- }
1824
- if (typeof colAttr === 'string') {
1825
- idx = colAttrs.indexOf(colAttr);
1826
- } else {
1827
- idx = colAttr;
1828
- }
1829
- if (idx < 0 || idx === colAttrs.length - 1) {
1830
- return;
1831
- }
1832
- for (i = k = 0, ref8 = idx; 0 <= ref8 ? k <= ref8 : k >= ref8; i = 0 <= ref8 ? ++k : --k) {
1833
- if (i <= colDisableAfter) {
1834
- hh = colHeaderHeaders[i];
1835
- replaceClass(hh.th, classCollapsed, classExpanded);
1836
- hh.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(colAttrs[i]);
1837
- hh.clickStatus = clickStatusExpanded;
1838
- }
1839
- j = 0;
1840
- nCols = colHeaderCols.length;
1841
- while (j < nCols) {
1842
- h = colHeaderCols[j];
1843
- if (h.col === i) {
1844
- expandCol(colHeaderHeaders, colHeaderCols, j);
1845
- }
1846
- ++j;
1847
- }
1848
- }
1849
- ++idx;
1850
- results = [];
1851
- while (idx < colAttrs.length - 1 && idx <= colDisableAfter) {
1852
- colHeaderHeader = colHeaderHeaders[idx];
1853
- if (colHeaderHeader.expandedCount === 0) {
1854
- replaceClass(colHeaderHeader.th, classExpanded, classCollapsed);
1855
- colHeaderHeader.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(colAttrs[idx]);
1856
- colHeaderHeader.clickStatus = clickStatusCollapsed;
1857
- } else if (colHeaderHeader.expandedCount === colHeaderHeader.nHeaders) {
1858
- replaceClass(colHeaderHeader.th, classCollapsed, classExpanded);
1859
- colHeaderHeader.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(colAttrs[idx]);
1860
- colHeaderHeader.clickStatus = clickStatusExpanded;
1861
- }
1862
- results.push(++idx);
1863
- }
1864
- return results;
1865
- };
1866
- collapseRowsAt = function(rowHeaderHeaders, rowHeaderRows, rowAttrs, rowAttr) {
1867
- var h, i, idx, j, nAttrs, nRows, results;
1868
- if (isRowDisable) {
1869
- return;
1870
- }
1871
- if (typeof rowAttr === 'string') {
1872
- idx = rowAttrs.indexOf(rowAttr);
1873
- } else {
1874
- idx = rowAttr;
1875
- }
1876
- if (idx < 0 || idx === rowAttrs.length - 1) {
1877
- return;
1878
- }
1879
- i = idx;
1880
- nAttrs = rowAttrs.length - 1;
1881
- while (i < nAttrs && i <= rowDisableAfter) {
1882
- h = rowHeaderHeaders.hh[i];
1883
- replaceClass(h.th, classExpanded, classCollapsed);
1884
- h.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(rowAttrs[i]);
1885
- h.clickStatus = clickStatusCollapsed;
1886
- ++i;
1887
- }
1888
- j = 0;
1889
- nRows = rowHeaderRows.length;
1890
- results = [];
1891
- while (j < nRows) {
1892
- h = rowHeaderRows[j];
1893
- if (h.col === idx && h.clickStatus !== clickStatusCollapsed && h.tr.style.display !== "none") {
1894
- collapseRow(rowHeaderHeaders, rowHeaderRows, j);
1895
- results.push(j = j + h.descendants + 1);
1896
- } else {
1897
- results.push(++j);
1898
- }
1899
- }
1900
- return results;
1901
- };
1902
- expandRowsAt = function(rowHeaderHeaders, rowHeaderRows, rowAttrs, rowAttr) {
1903
- var h, hh, i, idx, j, k, nRows, ref8, results, rowHeaderHeader;
1904
- if (isRowDisable) {
1905
- return;
1906
- }
1907
- if (typeof rowAttr === 'string') {
1908
- idx = rowAttrs.indexOf(rowAttr);
1909
- } else {
1910
- idx = rowAttr;
1911
- }
1912
- if (idx < 0 || idx === rowAttrs.length - 1) {
1913
- return;
1914
- }
1915
- for (i = k = 0, ref8 = idx; 0 <= ref8 ? k <= ref8 : k >= ref8; i = 0 <= ref8 ? ++k : --k) {
1916
- if (i <= rowDisableAfter) {
1917
- hh = rowHeaderHeaders.hh[i];
1918
- replaceClass(hh.th, classCollapsed, classExpanded);
1919
- hh.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(rowAttrs[i]);
1920
- hh.clickStatus = clickStatusExpanded;
1921
- }
1922
- j = 0;
1923
- nRows = rowHeaderRows.length;
1924
- while (j < nRows) {
1925
- h = rowHeaderRows[j];
1926
- if (h.col === i) {
1927
- expandRow(rowHeaderHeaders, rowHeaderRows, j);
1928
- j += h.descendants + 1;
1929
- } else {
1930
- ++j;
1931
- }
1932
- }
1933
- }
1934
- ++idx;
1935
- results = [];
1936
- while (idx < rowAttrs.length - 1 && idx <= rowDisableAfter) {
1937
- rowHeaderHeader = rowHeaderHeaders.hh[idx];
1938
- if (rowHeaderHeader.expandedCount === 0) {
1939
- replaceClass(rowHeaderHeader.th, classExpanded, classCollapsed);
1940
- rowHeaderHeader.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(rowAttrs[idx]);
1941
- rowHeaderHeader.clickStatus = clickStatusCollapsed;
1942
- } else if (rowHeaderHeader.expandedCount === rowHeaderHeader.nHeaders) {
1943
- replaceClass(rowHeaderHeader.th, classCollapsed, classExpanded);
1944
- rowHeaderHeader.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(rowAttrs[idx]);
1945
- rowHeaderHeader.clickStatus = clickStatusExpanded;
1946
- }
1947
- results.push(++idx);
1948
- }
1949
- return results;
1950
- };
1951
- toggleColHeaderHeader = function(colHeaderHeaders, colHeaderCols, colAttrs, colAttr) {
1952
- var h, idx;
1953
- if (isColDisable) {
1954
- return;
1955
- }
1956
- if (isColDisableExpandCollapse) {
1957
- return;
1958
- }
1959
- idx = colAttrs.indexOf(colAttr);
1960
- h = colHeaderHeaders[idx];
1961
- if (h.col > colDisableAfter) {
1962
- return;
1963
- }
1964
- if (h.clickStatus === clickStatusCollapsed) {
1965
- h.clickStatus = clickStatusExpanded;
1966
- h.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(colAttr);
1967
- replaceClass(h.th, classCollapsed, classExpanded);
1968
- return expandColsAt(colHeaderHeaders, colHeaderCols, colAttrs, colAttr);
1969
- } else {
1970
- h.clickStatus = clickStatusCollapsed;
1971
- h.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(colAttr);
1972
- replaceClass(h.th, classExpanded, classCollapsed);
1973
- return collapseColsAt(colHeaderHeaders, colHeaderCols, colAttrs, colAttr);
1974
- }
1975
- };
1976
- toggleRowHeaderHeader = function(rowHeaderHeaders, rowHeaderRows, rowAttrs, rowAttr) {
1977
- var idx, th;
1978
- if (isRowDisable) {
1979
- return;
1980
- }
1981
- if (isRowDisableExpandCollapse) {
1982
- return;
1983
- }
1984
- idx = rowAttrs.indexOf(rowAttr);
1985
- th = rowHeaderHeaders.hh[idx];
1986
- if (th.col > rowDisableAfter) {
1987
- return;
1988
- }
1989
- if (th.clickStatus === clickStatusCollapsed) {
1990
- th.clickStatus = clickStatusExpanded;
1991
- th.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(rowAttr);
1992
- replaceClass(th.th, classCollapsed, classExpanded);
1993
- return expandRowsAt(rowHeaderHeaders, rowHeaderRows, rowAttrs, rowAttr);
1994
- } else {
1995
- th.clickStatus = clickStatusCollapsed;
1996
- th.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(rowAttr);
1997
- replaceClass(th.th, classExpanded, classCollapsed);
1998
- return collapseRowsAt(rowHeaderHeaders, rowHeaderRows, rowAttrs, rowAttr);
1999
- }
2000
- };
2001
-
2002
- handleFreezePanesScroll = function(freezableElements) {
2003
- return function(event) {
2004
- const wrapper = event.target;
2005
-
2006
- const translateY = `translate(0px, ${wrapper.scrollTop}px)`;
2007
- const translateX = `translate(${wrapper.scrollLeft}px, 0px)`;
2008
- const translateXY = `translate(${wrapper.scrollLeft}px, ${wrapper.scrollTop}px)`;
2009
-
2010
- _.forEach(freezableElements, function (element) {
2011
- let currentTranslate = translateY;
2012
- currentTranslate = element.className.includes(elementToTransform.X) ? translateX : currentTranslate;
2013
- currentTranslate = element.className.includes(elementToTransform.XY) ? translateXY : currentTranslate;
2014
- element.style.transform = currentTranslate;
2015
- });
2016
- }
2017
- };
2018
-
2019
- selectFreezableElements = function(wrapper) {
2020
- const selectString =_.map(Object.values(elementToTransform), function (item) {
2021
- return `.${item.replace(' ', '')}`;
2022
- }).join(',');
2023
- return Array.from(wrapper.querySelectorAll(selectString));
2024
- }
2025
-
2026
- main = function(rowAttrs, rowKeys, colAttrs, colKeys) {
2027
- var c,rowspan, colHeaderCols, colHeaderHeaders, colHeaders, h, k, l, len, len1, result, rowHeaderHeaders, rowHeaderRows, rowHeaders, tbody, thead, tr;
2028
- rowHeaders = [];
2029
- colHeaders = [];
2030
- rowHeaderHeaders = {};
2031
- rowHeaderRows = [];
2032
- colHeaderHeaders = [];
2033
- colHeaderCols = [];
2034
- if (rowAttrs.length > 0 && rowKeys.length > 0) {
2035
- rowHeaders = processKeys(rowKeys, "pvtRowLabel", 'rows', rowAttrs);
2036
- }
2037
- if (colAttrs.length > 0 && colKeys.length > 0) {
2038
- colHeaders = processKeys(colKeys, "pvtColLabel", 'cols', colAttrs);
2039
- }
2040
- var tableClasses = useNewUx && opts.chartOptions.table_options.use_new_table_design ? 'pvtTable newPvtTable' : 'pvtTable';
2041
- result = createElement("table", tableClasses , null, {
2042
- style: "display: none;"
2043
- });
2044
-
2045
- colorizeTableIfNeed(result);
2046
-
2047
- thead = createElement("thead");
2048
- result.appendChild(thead);
2049
- if (colAttrs.length > 0) {
2050
- buildColHeaderHeaders(thead, colHeaderHeaders, rowAttrs, colAttrs);
2051
- for (k = 0, len = colHeaders.length; k < len; k++) {
2052
- h = colHeaders[k];
2053
- buildColHeaders(colHeaderHeaders, colHeaderCols, h, rowAttrs, colAttrs);
2054
- }
2055
- buildColHeaderHeadersClickEvents(colHeaderHeaders, colHeaderCols, colAttrs);
2056
- }
2057
- if (rowAttrs.length > 0) {
2058
- buildRowHeaderHeaders(thead, rowHeaderHeaders, rowAttrs, colAttrs);
2059
- if (colAttrs.length === 0 && opts.chartOptions.table_options.show_row_total) {
2060
- buildRowTotalsHeader(rowHeaderHeaders.tr, rowAttrs, colAttrs);
2061
- }
2062
- }
2063
- if (colAttrs.length > 0 && opts.chartOptions.table_options.show_row_total) {
2064
- buildRowTotalsHeader(colHeaderHeaders[0].tr, rowAttrs, colAttrs);
2065
- if(opts.chartOptions.table_options.colorize_headers == true){
2066
- for (c=1; c<colHeaderHeaders.length; c++){
2067
- rowspan = 1;
2068
- if(c == colHeaderHeaders.length-1){
2069
- rowspan = 2;
2070
- }
2071
- colHeaderHeaders[c].tr.appendChild(createElement("th", verticalFreezePaneClass, "",{rowspan: rowspan}));
2072
- if (opts.chartOptions.table_options.freeze_panes) {
2073
- getHeaderColorProperties(colHeaderHeaders[c].tr, c);
2074
- }
2075
- }
2076
- }
2077
- }
2078
- tbody = createElement("tbody");
2079
- result.appendChild(tbody);
2080
-
2081
- const hasColLabels = !!thead.querySelector('.pvtColLabel');
2082
-
2083
- if (rowAttrs.length > 0) {
2084
- for (l = 0, len1 = rowHeaders.length; l < len1; l++) {
2085
- h = rowHeaders[l];
2086
- buildRowHeaders(tbody, rowHeaderHeaders, rowHeaderRows, h, rowAttrs, colAttrs, l%2 === 0, hasColLabels);
2087
- }
2088
- }
2089
- buildRowHeaderHeadersClickEvents(rowHeaderHeaders, rowHeaderRows, rowAttrs);
2090
- buildValues(rowHeaderRows, colHeaderCols, rowAttrs, colAttrs);
2091
- if(opts.chartOptions.table_options.show_column_total){
2092
- tr = buildColTotalsHeader(rowAttrs, colAttrs);
2093
- if (colAttrs.length > 0) {
2094
- buildColTotals(tr, colHeaderCols, rowAttrs, colAttrs);
2095
- }
2096
- if(opts.chartOptions.table_options.show_row_total)
2097
- buildGrandTotal(tbody, tr, rowAttrs, colAttrs);
2098
- else
2099
- tbody.appendChild(tr);
2100
- }
2101
-
2102
- result.setAttribute("data-numrows", rowKeys.length);
2103
- result.setAttribute("data-numcols", colKeys.length);
2104
- if ((opts.collapseRowsAt == null) && (opts.collapseColsAt == null)) {
2105
- result.style.display = "";
2106
- }
2107
- if (opts.collapseRowsAt != null) {
2108
- collapseRowsAt(rowHeaderHeaders, rowHeaderRows, rowAttrs, opts.collapseRowsAt);
2109
- }
2110
- if (opts.collapseColsAt != null) {
2111
- collapseColsAt(colHeaderHeaders, colHeaderCols, colAttrs, opts.collapseColsAt);
2112
- }
2113
- result.style.display = "";
2114
-
2115
- var resultsArr = [];
2116
- var additionOptions = opts.chartOptions ? opts.chartOptions : null;
2117
-
2118
- if (opts && opts.chart_title && !opts.chartOptions.hideChartHeader) {
2119
- var title = document.createElement("div");
2120
- title.className = "title";
2121
- title.innerText = opts.chart_title;
2122
- resultsArr.push(title);
2123
- }
2124
-
2125
- if (additionOptions && additionOptions.subtitle && !opts.chartOptions.hideChartHeader) {
2126
- var subTitle = document.createElement("div");
2127
- subTitle.className = "sub-title";
2128
- subTitle.innerText = additionOptions.subtitle.subtitle;
2129
- resultsArr.push(subTitle);
2130
- }
2131
-
2132
- if (tooMuch) {
2133
- resultsArr.push($('<div class="noData"><i class="fa fa-info"></i> There are too many rows to display in the table.<br>Please filter or change the table type in options.</div>'));
2134
- } else {
2135
- var tableContainer = document.createElement("div");
2136
- tableContainer.className = "pivot-div";
2137
- tableContainer.appendChild(result);
2138
- if (opts.chartOptions.table_options.freeze_panes) {
2139
- tableContainer.onscroll = handleFreezePanesScroll(selectFreezableElements(tableContainer));
2140
- }
2141
- resultsArr.push(tableContainer);
2142
- }
2143
-
2144
- var wrapper = document.createElement("div");
2145
- wrapper.className = "pivot-wrapper";
2146
-
2147
- $(wrapper).append(resultsArr);
2148
-
2149
- return wrapper;
2150
- };
2151
- return main(rowAttrs, rowKeys, colAttrs, colKeys);
2152
- };
2153
- // $.pivotUtilities.subtotal_renderers = SubtotalRenderer;
2154
- $.pivotUtilities.subtotal_renderers = NovixRenderer;
2155
- $.pivotUtilities.delim = delim;
2156
-
2157
- $.pivotUtilities.getFormattedNumber = getFormattedNumber;
2158
- $.pivotUtilities.sortDateStrings = sortDateStrings;
2159
- $.pivotUtilities.largeToSmallSort = largeToSmallSort;
2160
- $.pivotUtilities.getPivotDataModel = function(input, opts){ return new DRPivotData(input, opts); }
2161
- $.pivotUtilities.getPivotTableFormula = function(rowData, opts, func, colFields, rowFields, aggregationDefaults, utils) {
2162
- let totalStr = 'Grand Totals';
2163
- let pivotData = new DRPivotData(rowData, opts);
2164
- let rowAttrs = pivotData.rowAttrs;
2165
- let rowKeys = pivotData.getRowKeys();
2166
- let colAttrs = pivotData.colAttrs;
2167
- let colKeys = pivotData.getColKeys();
2168
-
2169
- if ((rowKeys.length || 1) * (colKeys.length || 1) > 10000) {
2170
- throw new Error(`Can't create table formula. The table has many rows or columns`);
2171
- }
2172
-
2173
- let rowValuesIndex = colAttrs.length;
2174
- let colValuesIndex = rowAttrs.length;
2175
- let matrix = [];
2176
- let colFormulas = [];
2177
- let rowFormulas = [];
2178
- let aggregation = utils.getAggregationConfigFromFields(func, colFields, rowFields, aggregationDefaults);
2179
-
2180
- // Create headers
2181
- if (rowAttrs && rowAttrs.length && colAttrs && colAttrs.length) {
2182
- colValuesIndex += 1;
2183
- rowValuesIndex += 1;
2184
-
2185
- // Free place in formulas arrays
2186
- colFormulas = new Array(colValuesIndex).fill(null);
2187
- rowFormulas = new Array(rowValuesIndex).fill(null);
2188
-
2189
- for (let i = 0; i < colAttrs.length; i++) {
2190
- // Free place in row start
2191
- let headerRow = new Array(rowAttrs.length).fill(null);
2192
- // Add col field name
2193
- headerRow.push(colAttrs[i]);
2194
- // Add row keys
2195
- _.forEach(colKeys, function (keys) {
2196
- headerRow.push(utils.getHeaderValue(keys[i], colFields[i].type));
2197
- // Calc formulas in first time
2198
- if (i === 0) {
2199
- colFormulas.push(utils.createKeysFormula(colFields, keys, colFormulas.length + 1, true));
2200
- }
2201
- });
2202
-
2203
- // Add row to matrix
2204
- matrix.push(headerRow);
2205
- }
2206
-
2207
- // Add row fields + free space under cols + Grand Totals right
2208
- matrix.push(rowAttrs.concat(new Array(colKeys.length + 1).fill(null)).concat(totalStr));
2209
- // Row Headers
2210
- for (let i = 0; i < rowKeys.length; i++) {
2211
- // Formatting row keys
2212
- let keysFormatted = [];
2213
- for (let k = 0; k < rowKeys[i].length; k++) {
2214
- keysFormatted.push(utils.getHeaderValue(rowKeys[i][k], rowFields[k].type))
2215
- }
2216
- // Add row keys
2217
- matrix.push(keysFormatted.concat(null));
2218
- // Calc formulas
2219
- rowFormulas.push(utils.createKeysFormula(rowFields, rowKeys[i], rowFormulas.length + 1));
2220
- }
2221
- // Add Grand Totals bottom
2222
- matrix.push(new Array(rowAttrs.length).fill(null).concat(totalStr));
2223
-
2224
- // Fill values
2225
- for (let y = rowValuesIndex; y < matrix.length; y++) {
2226
- for (let x = colValuesIndex; x < matrix[rowValuesIndex - 1].length; x++) {
2227
- matrix[y][x] = utils.createCellFormula(func, colFormulas[x], rowFormulas[y], aggregation);
2228
- }
2229
- }
2230
- } else if (colAttrs && colAttrs.length) {
2231
- colFormulas = new Array(null);
2232
-
2233
- for (let i = 0; i < colAttrs.length; i++) {
2234
- // Add col field name
2235
- let headerRow = [colAttrs[i]];
2236
- // Add keys
2237
- _.forEach(colKeys, function (keys) {
2238
- headerRow.push(utils.getHeaderValue(keys[i], colFields[i].type));
2239
- // Calc formulas in first time
2240
- if (i === 0) {
2241
- colFormulas.push(utils.createKeysFormula(colFields, keys, colFormulas.length + 1, true));
2242
- }
2243
- });
2244
-
2245
- // Add row to matrix
2246
- matrix.push(headerRow);
2247
- }
2248
-
2249
- // Add Grand Totals right
2250
- matrix[matrix.length - 1].push(totalStr);
2251
- // Add Grand Totals bottom
2252
- matrix.push([totalStr]);
2253
-
2254
- // Fill totals
2255
- for (let x = 1; x < matrix[matrix.length - 2].length; x++) {
2256
- matrix[matrix.length - 1][x] = utils.createCellFormula(func, colFormulas[x], '', aggregation);
2257
- }
2258
- } else if (rowAttrs && rowAttrs.length) {
2259
- rowFormulas = new Array(null);
2260
-
2261
- // Add row fields + Grand Totals right
2262
- matrix.push(rowAttrs.concat(totalStr));
2263
- // Row Headers
2264
- for (let i = 0; i < rowKeys.length; i++) {
2265
- // Formatting row keys
2266
- let keysFormatted = [];
2267
- for (let k = 0; k < rowKeys[i].length; k++) {
2268
- keysFormatted.push(utils.getHeaderValue(rowKeys[i][k], rowFields[k].type))
2269
- }
2270
- // Add row keys
2271
- matrix.push(keysFormatted);
2272
- // Calc formulas
2273
- rowFormulas.push(utils.createKeysFormula(rowFields, rowKeys[i], rowFormulas.length + 1));
2274
- }
2275
- // Add Grand Totals bottom
2276
- matrix.push(new Array(rowAttrs.length - 1).fill(null).concat(totalStr));
2277
-
2278
- // Fill totals
2279
- for (let y = 1; y < matrix.length; y++) {
2280
- matrix[y][rowAttrs.length] = utils.createCellFormula(func, '', rowFormulas[y], aggregation);
2281
- }
2282
- } else {
2283
- matrix = [[totalStr, utils.createCellFormula(func, '', '', aggregation)]];
2284
- }
2285
-
2286
- return matrix;
2287
- };
2288
- };
2289
-
2290
- module.exports = initDRPivotTable;
1
+ let initDRPivotTable = function($, window, document) {
2
+ var hasProp = {}.hasOwnProperty;
3
+ var slice = [].slice;
4
+ var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
5
+
6
+ var DRPivotData, sortDateStrings, getSort, processKey, SubtotalRenderer, getFormattedNumber, largeToSmallSort, NovixRenderer;
7
+
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
+ const useNewUx = document.ReportHippo && document.ReportHippo && document.ReportHippo.user &&
12
+ document.ReportHippo.user.organization.settings && document.ReportHippo.user.organization.settings.use_new_ux;
13
+ // const numberOfRows = 500; // change to activate the handsontable when num of rows bigger then this.
14
+
15
+ DRPivotData = (function(superClass) {
16
+ extend(DRPivotData, superClass);
17
+
18
+ function DRPivotData(input, opts) {
19
+ DRPivotData.__super__.constructor.call(this, input, opts);
20
+ }
21
+
22
+ getSort = function(sorters, attr) {
23
+ var sort;
24
+ sort = sorters(attr);
25
+ if ($.isFunction(sort)) {
26
+ return sort;
27
+ } else {
28
+ return $.pivotUtilities.naturalSort;
29
+ }
30
+ };
31
+
32
+ DRPivotData.prototype.forEachRecord = function(input, derivedAttributes, f) {
33
+ var addRecord, compactRecord, i, j, k, l, len1, record, ref, results, results1, tblCols;
34
+ if ($.isEmptyObject(derivedAttributes)) {
35
+ addRecord = f;
36
+ } else {
37
+ addRecord = function(record) {
38
+ var k, ref, v;
39
+ for (k in derivedAttributes) {
40
+ v = derivedAttributes[k];
41
+ record[k] = (ref = v(record)) != null ? ref : record[k];
42
+ }
43
+ return f(record);
44
+ };
45
+ }
46
+ if ($.isFunction(input)) {
47
+ return input(addRecord);
48
+ } else if ($.isArray(input)) {
49
+ if ($.isArray(input[0])) {
50
+ results = [];
51
+ for (i in input) {
52
+ if (!hasProp.call(input, i)) continue;
53
+ compactRecord = input[i];
54
+ if (!(i > 0)) {
55
+ continue;
56
+ }
57
+ record = {};
58
+ ref = input[0];
59
+ for (j in ref) {
60
+ if (!hasProp.call(ref, j)) continue;
61
+ k = ref[j];
62
+ record[k] = compactRecord[j];
63
+ }
64
+ results.push(addRecord(record));
65
+ }
66
+ return results;
67
+ } else {
68
+ results1 = [];
69
+ for (l = 0, len1 = input.length; l < len1; l++) {
70
+ record = input[l];
71
+ results1.push(addRecord(record));
72
+ }
73
+ return results1;
74
+ }
75
+ } else if (input instanceof jQuery) {
76
+ tblCols = [];
77
+ $("thead > tr > th", input).each(function(i) {
78
+ return tblCols.push($(this).text());
79
+ });
80
+ return $("tbody > tr", input).each(function(i) {
81
+ record = {};
82
+ $("td", this).each(function(j) {
83
+ return record[tblCols[j]] = $(this).html();
84
+ });
85
+ return addRecord(record);
86
+ });
87
+ } else {
88
+ throw new Error("unknown input format");
89
+ }
90
+ };
91
+
92
+ DRPivotData.prototype.arrSort = function(attrs) {
93
+ var a, sortersArr;
94
+ sortersArr = (function() {
95
+ var l, len1, results;
96
+ results = [];
97
+ for (l = 0, len1 = attrs.length; l < len1; l++) {
98
+ a = attrs[l];
99
+ results.push(getSort(this.sorters, a));
100
+ }
101
+ return results;
102
+ }).call(this);
103
+ return function(a, b) {
104
+ var comparison, i, sorter;
105
+ for (i in sortersArr) {
106
+ sorter = sortersArr[i];
107
+ comparison = sorter(a[i], b[i]);
108
+ if (comparison !== 0) {
109
+ return comparison;
110
+ }
111
+ }
112
+ return 0;
113
+ };
114
+ };
115
+
116
+ processKey = function(record, totals, keys, attrs, getAggregator) {
117
+ var addKey, attr, flatKey, k, key, len, ref;
118
+ key = [];
119
+ addKey = false;
120
+ for (k = 0, len = attrs.length; k < len; k++) {
121
+ attr = attrs[k];
122
+ key.push((ref = record[attr]) != null ? ref : "null");
123
+ flatKey = key.join(delim);
124
+ if (!totals[flatKey]) {
125
+ totals[flatKey] = getAggregator(key.slice());
126
+ addKey = true;
127
+ }
128
+ totals[flatKey].push(record);
129
+ }
130
+ if (addKey) {
131
+ keys.push(key);
132
+ }
133
+ return key;
134
+ };
135
+
136
+ DRPivotData.prototype.processRecord = function(record) {
137
+ var colKey, fColKey, fRowKey, flatColKey, flatRowKey, i, j, k, m, n, ref, results, rowKey;
138
+ rowKey = [];
139
+ colKey = [];
140
+ this.allTotal.push(record);
141
+ rowKey = processKey(record, this.rowTotals, this.rowKeys, this.rowAttrs, (function(_this) {
142
+ return function(key) {
143
+ return _this.aggregator(_this, key, []);
144
+ };
145
+ })(this));
146
+ colKey = processKey(record, this.colTotals, this.colKeys, this.colAttrs, (function(_this) {
147
+ return function(key) {
148
+ return _this.aggregator(_this, [], key);
149
+ };
150
+ })(this));
151
+ m = rowKey.length - 1;
152
+ n = colKey.length - 1;
153
+ if (m < 0 || n < 0) {
154
+ return;
155
+ }
156
+ results = [];
157
+ for (i = k = 0, ref = m; 0 <= ref ? k <= ref : k >= ref; i = 0 <= ref ? ++k : --k) {
158
+ fRowKey = rowKey.slice(0, i + 1);
159
+ flatRowKey = fRowKey.join(delim);
160
+ if (!this.tree[flatRowKey]) {
161
+ this.tree[flatRowKey] = {};
162
+ }
163
+ results.push((function() {
164
+ var l, ref1, results1;
165
+ results1 = [];
166
+ for (j = l = 0, ref1 = n; 0 <= ref1 ? l <= ref1 : l >= ref1; j = 0 <= ref1 ? ++l : --l) {
167
+ fColKey = colKey.slice(0, j + 1);
168
+ flatColKey = fColKey.join(delim);
169
+ if (!this.tree[flatRowKey][flatColKey]) {
170
+ this.tree[flatRowKey][flatColKey] = this.aggregator(this, fRowKey, fColKey);
171
+ }
172
+ results1.push(this.tree[flatRowKey][flatColKey].push(record));
173
+ }
174
+ return results1;
175
+ }).call(this));
176
+ }
177
+ return results;
178
+ };
179
+
180
+ DRPivotData.prototype.getAggregator = function(rowKey, colKey) {
181
+ var agg, flatColKey, flatRowKey;
182
+ flatRowKey = rowKey.join(delim);
183
+ flatColKey = colKey.join(delim);
184
+ if (rowKey.length === 0 && colKey.length === 0) {
185
+ agg = this.allTotal;
186
+ } else if (rowKey.length === 0) {
187
+ agg = this.colTotals[flatColKey];
188
+ } else if (colKey.length === 0) {
189
+ agg = this.rowTotals[flatRowKey];
190
+ } else {
191
+ agg = this.tree[flatRowKey][flatColKey];
192
+ }
193
+ return agg != null ? agg : {
194
+ value: (function() {
195
+ return null;
196
+ }),
197
+ format: function() {
198
+ return "";
199
+ }
200
+ };
201
+ };
202
+
203
+ return DRPivotData;
204
+
205
+ })($.pivotUtilities.PivotData);
206
+
207
+ sortDateStrings = function(month_order) {
208
+ var i, mapping, x;
209
+ mapping = {};
210
+ var order = [
211
+ {"month":"jan", "versions": ['january', 'jan', 'ja'], weight:1},
212
+ {"month":"feb", "versions": ['february', 'feb', 'fe'], weight:2},
213
+ {"month":"mar", "versions": ['march', 'mar', 'mr'], weight:3},
214
+ {"month":"apr", "versions": ['april', 'apr', 'ap','al'], weight:4},
215
+ {"month":"may", "versions": ['may', 'ma'], weight:5},
216
+ {"month":"jun", "versions": ['june', 'jun','jn'], weight:6},
217
+ {"month":"jul", "versions": ['july', 'jul','jl'], weight:7},
218
+ {"month":"aug", "versions": ['august', 'aug', 'au'], weight:8},
219
+ {"month":"sep", "versions": ['september', 'sept', 'sep','sp','se'], weight:9},
220
+ {"month":"oct", "versions": ['october','oct', 'oc'], weight:10},
221
+ {"month":"nov", "versions": ['november', 'nov', 'no'], weight:11},
222
+ {"month":"dec", "versions": ['december', 'dec', 'de'], weight:12}
223
+ ];
224
+ var pattern = /(\d{1,4})|(Ja(n)?(uary)?|Fe(b)?(ruary)?|Mar(ch)?|mr|Ap(r)?(il)?|al|Ma(y)?|Jun(e)?|jn|Jul(y)?|jl|Aug(ust)?|au|Se(p)?(t)?(ember)?|sp|Oc(t)?(ober)?|No(v)?(ember)?|De(c)?(ember)?)/ig
225
+ if(month_order){
226
+ for(i=0; i<month_order.length; i++){
227
+ var find_row = _.find(order, {month:month_order[i]});
228
+ if(find_row){
229
+ find_row.weight = i+1;
230
+ }
231
+ }
232
+ }
233
+
234
+ _.forEach(order, function(month_obj){
235
+ _.forEach(month_obj.versions, function(val){
236
+ mapping[val] = month_obj.weight*31;
237
+ });
238
+ });
239
+
240
+ var getIndexForVal = function(value){
241
+ var to_return = 0, matches, i;
242
+ if (typeof value === 'string' || value instanceof String){
243
+ matches = value.match(pattern);
244
+ var numbers = 0;
245
+ var i = 0;
246
+ _.forEach(matches, function(v)
247
+ {
248
+ i++;
249
+ v = v.trim().toLowerCase();
250
+ var res = 0;
251
+
252
+ if(mapping[v] != undefined){
253
+ res = mapping[v];
254
+ }
255
+ else{
256
+ try {
257
+ res = parseInt(v)
258
+ if(res > 31 || numbers > 1 || i == matches.length)
259
+ res *=1000
260
+ numbers++;
261
+ }
262
+ catch(er){
263
+ res = 0
264
+ }
265
+ }
266
+ if(res == NaN){
267
+ res = 0
268
+ }
269
+ to_return += res
270
+ });
271
+ }
272
+ else{
273
+ try {
274
+ to_return = parseInt(value)
275
+ }
276
+ catch(er){
277
+ to_return = value
278
+ }
279
+ }
280
+
281
+ return to_return;
282
+ };
283
+
284
+ return function(a, b) {
285
+ return $.pivotUtilities.naturalSort(getIndexForVal(a), getIndexForVal(b));
286
+ };
287
+ };
288
+
289
+ largeToSmallSort = function(as, bs) {
290
+ var a, a1, b, b1, rd, rx, rz;
291
+ rx = /(\d+)|(\D+)/g;
292
+ rd = /\d/;
293
+ rz = /^0/;
294
+ if (typeof as === "number" || typeof bs === "number") {
295
+ if (isNaN(as)) {
296
+ return -1;
297
+ }
298
+ if (isNaN(bs)) {
299
+ return 1;
300
+ }
301
+ return bs - as;
302
+ }
303
+ a = String(as).toLowerCase();
304
+ b = String(bs).toLowerCase();
305
+ if (a === b) {
306
+ return 0;
307
+ }
308
+ if (!(rd.test(a) && rd.test(b))) {
309
+ return (b > a ? 1 : -1);
310
+ }
311
+ a = a.match(rx);
312
+ b = b.match(rx);
313
+ while (a.length && b.length) {
314
+ a1 = a.shift();
315
+ b1 = b.shift();
316
+ if (a1 !== b1) {
317
+ if (rd.test(a1) && rd.test(b1)) {
318
+ return b1.replace(rz, ".0") - a1.replace(rz, ".0");
319
+ } else {
320
+ return (b1 > a1 ? 1 : -1);
321
+ }
322
+ }
323
+ }
324
+ return b.length - a.length;
325
+ };
326
+
327
+ $.pivotUtilities.DRPivotData = DRPivotData;
328
+
329
+ getFormattedNumber = function(val, aggregator, opts, format_argument) {
330
+ if (!aggregator) {
331
+ aggregator = {};
332
+ aggregator.format = function(val) {
333
+ return val.toLocaleString();
334
+ }
335
+ }
336
+ if (val < 0 && opts && opts.chartOptions && opts.chartOptions.negative_numbers && opts.chartOptions.negative_numbers.value) {
337
+ switch (opts.chartOptions.negative_numbers.value) {
338
+ case 'red_minus':
339
+ return '<span style="color: red; fill: red;">' + aggregator.format(val, format_argument) + '</span>';
340
+ break;
341
+ case 'absolute':
342
+ return '(' + aggregator.format(Math.abs(val), format_argument) + ')';
343
+ break;
344
+ case 'red_absolute':
345
+ return '<span style="color: red; fill: red;">(' + aggregator.format(Math.abs(val), format_argument) + ')</span>';
346
+ break;
347
+ default:
348
+ return aggregator.format(val, format_argument);
349
+ }
350
+ }
351
+ return aggregator.format(val, format_argument);
352
+ };
353
+
354
+ NovixRenderer = function(pvtData, opts, charttype) {
355
+ var resultsArr = [];
356
+ var additionOptions = opts.chartOptions ? opts.chartOptions : null;
357
+ if (additionOptions && additionOptions.table_options.use_handsOnTable) {
358
+ if (opts && opts.chart_title && !opts.chartOptions.hideChartHeader) {
359
+ var title = document.createElement("div");
360
+ title.className = "title";
361
+ title.innerText = opts.chart_title;
362
+ resultsArr.push(title);
363
+ }
364
+
365
+ if (additionOptions && additionOptions.subtitle && additionOptions.subtitle.subtitle && !opts.chartOptions.hideChartHeader) {
366
+ console.log("subtitle", additionOptions.subtitle);
367
+ var subTitle = document.createElement("div");
368
+ subTitle.className = "sub-title";
369
+ subTitle.innerText = additionOptions.subtitle.subtitle;
370
+ resultsArr.push(subTitle);
371
+ }
372
+
373
+ resultsArr.push($.pivotUtilities.novix_renderers["Pivot Table"](pvtData, opts));
374
+
375
+ // var wrapper = document.createElement("div");
376
+ // wrapper.className = "pivot-wrapper2";
377
+ // $(wrapper).append(resultsArr);
378
+
379
+ return resultsArr;
380
+ } else {
381
+ let tooMuch = false;
382
+ if (pvtData && (pvtData.rowKeys.length > 1000 || pvtData.colKeys.length > 500) &&
383
+ (!opts.show_more_function_cols || !opts.show_more_function_cols)) {
384
+ pvtData.rowKeys = [];
385
+ pvtData.colKeys = [];
386
+ tooMuch = true;
387
+ }
388
+ return SubtotalRenderer(pvtData, opts, charttype, tooMuch);
389
+ }
390
+ }
391
+
392
+ SubtotalRenderer = function(pivotData, opts, charttype, tooMuch = false) {
393
+ var addClass, allTotal, arrowCollapsed, arrowExpanded, buildColHeaderHeader, buildColHeaderHeaders, buildColHeaderHeadersClickEvents, buildColHeaders, buildColTotals, buildColTotalsHeader, buildGrandTotal, buildRowHeaderHeaders, buildRowHeaderHeadersClickEvents, buildRowHeaders, buildRowTotalsHeader, buildValues, classColCollapsed, classColExpanded, classColHide, classColShow, classCollapsed, classExpanded, classRowCollapsed, classRowExpanded, classRowHide, classRowShow, clickStatusCollapsed, clickStatusExpanded, colAttrs, colDisableAfter, colKeys, colTotals, collapseCol, collapseColsAt, collapseHideDescendantRow, collapseRow, collapseRowsAt, collapseShowColSubtotal, collapseShowRowSubtotal, createElement, defaults, expandChildCol, expandChildRow, expandCol, expandColsAt, expandHideColSubtotal, expandHideRowSubtotal, expandRow, expandRowsAt, expandShowColSubtotal, expandShowRowSubtotal, getTableEventHandlers, hasClass, hideDescendantCol, isColDisable, isColDisableExpandCollapse, isColHideOnExpand, isRowDisable, isRowDisableExpandCollapse, isRowHideOnExpand, main, getSubtotalInBrackets, processKeys, encodeHtmlEntities, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, removeClass, replaceClass, rowAttrs, rowDisableAfter, rowKeys, rowTotals, setAttributes, showChildCol, showChildRow, toggleCol, toggleColHeaderHeader, toggleRow, toggleRowHeaderHeader, tree, assumptionSubscribe;
394
+ var createTotalValsBolder, createGrandTotalBolder, getHeaderColorProperties, colorizeRowLabelHeaders, colorizeTableIfNeed, valueNoDashes, getColorsWithOffsetForTable, offsetColors, handleFreezePanesScroll, selectFreezableElements, removeRowHeaderNullValue;
395
+ var edit_assumptions;
396
+
397
+ var horizontalFreezePaneClass = opts.chartOptions.table_options.freeze_panes ? ' horizontal-freeze-pane' : '';
398
+ var verticalFreezePaneClass = opts.chartOptions.table_options.freeze_panes ? ' vertical-freeze-pane' : '';
399
+ var axisFreezePaneClass = opts.chartOptions.table_options.freeze_panes ? ' axis-freeze-pane' : '';
400
+
401
+ var elementToTransform = {
402
+ X: horizontalFreezePaneClass,
403
+ Y: verticalFreezePaneClass,
404
+ XY: axisFreezePaneClass,
405
+ }
406
+
407
+ defaults = {
408
+ table: {
409
+ clickCallback: null
410
+ },
411
+ localeStrings: {
412
+ totals: "Grand Totals",
413
+ subtotals: "Subtotal"
414
+ },
415
+ chartOptions:{
416
+ table_options:{
417
+ show_column_total:true,
418
+ show_row_total:true
419
+ }
420
+ },
421
+ totalFilterElements: null,
422
+ resetSortingElement: null,
423
+ nextSortingElement: null,
424
+ prevSortingElement: null,
425
+ show_more_function_cols: null,
426
+ show_more_function_rows: null,
427
+ show_more_max_items: 10,
428
+ labelsConvertFunction: function(str){return str;}
429
+ };
430
+ opts = $.extend(true, {}, defaults, opts);
431
+
432
+ if(opts.chartOptions.table_options.start_collapsed_rows) {
433
+ opts.collapseRowsAt = 0;
434
+ }
435
+ if(opts.chartOptions.table_options.start_collapsed_columns) {
436
+ opts.collapseColsAt = 0;
437
+ }
438
+ edit_assumptions = opts.chartOptions.edit_assumptions;
439
+ isRowDisable = (ref = opts.rowSubtotalDisplay) != null ? ref.disableSubtotal : void 0;
440
+ isRowHideOnExpand = (ref1 = opts.rowSubtotalDisplay) != null ? ref1.hideOnExpand : !opts.chartOptions.table_options.show_subtotals_for_rows;
441
+ isRowDisableExpandCollapse = (ref2 = opts.rowSubtotalDisplay) != null ? ref2.disableExpandCollapse : void 0;
442
+ rowDisableAfter = (ref3 = opts.rowSubtotalDisplay) != null ? ref3.disableAfter != null ? ref3.disableAfter : ref3.disableAfter = 9999 : void 0;
443
+ isColDisable = (ref4 = opts.colSubtotalDisplay) != null ? ref4.disableSubtotal : void 0;
444
+ isColHideOnExpand = (ref5 = opts.colSubtotalDisplay) != null ? ref5.hideOnExpand : !opts.chartOptions.table_options.show_subtotals_for_columns;
445
+ isColDisableExpandCollapse = (ref6 = opts.colSubtotalDisplay) != null ? ref6.disableExpandCollapse : void 0;
446
+ colDisableAfter = (ref7 = opts.colSubtotalDisplay) != null ? ref7.disableAfter != null ? ref7.disableAfter : ref7.disableAfter = 9999 : void 0;
447
+ arrowCollapsed = opts.arrowCollapsed != null ? opts.arrowCollapsed : opts.arrowCollapsed = '<i class="fa fa-plus dr-icon-add"></i> ';
448
+ arrowExpanded = opts.arrowExpanded != null ? opts.arrowExpanded : opts.arrowExpanded = '<i class="fa fa-minus dr-icon-minus"></i> ';
449
+ colAttrs = pivotData.colAttrs;
450
+ rowAttrs = pivotData.rowAttrs;
451
+ rowKeys = pivotData.getRowKeys();
452
+
453
+ if (charttype == 'column-chart' || charttype == 'column-chart-stacked') {
454
+ if (_.get(opts, 'chartOptions.table_options.transpose_table', false)) {
455
+ rowAttrs = [rowAttrs[0]];
456
+ if (rowKeys && rowKeys.length) {
457
+ rowKeys = rowKeys.map( function(_, index) {
458
+ return [rowKeys[index][0]];
459
+ });
460
+ }
461
+ } else {
462
+ colAttrs = [colAttrs[0]];
463
+ }
464
+ }
465
+ colKeys = pivotData.getColKeys();
466
+ tree = pivotData.tree;
467
+ rowTotals = pivotData.rowTotals;
468
+ colTotals = pivotData.colTotals;
469
+ allTotal = pivotData.allTotal;
470
+ classRowExpanded = "rowexpanded";
471
+ classRowCollapsed = "rowcollapsed";
472
+ classRowHide = "rowhide";
473
+ classRowShow = "rowshow";
474
+ classColExpanded = "colexpanded";
475
+ classColCollapsed = "colcollapsed";
476
+ classColHide = "colhide";
477
+ classColShow = "colshow";
478
+ clickStatusExpanded = "expanded";
479
+ clickStatusCollapsed = "collapsed";
480
+ classExpanded = "expanded";
481
+ classCollapsed = "collapsed";
482
+ hasClass = function(element, className) {
483
+ var regExp;
484
+ regExp = new RegExp("(?:^|\\s)" + className + "(?!\\S)", "g");
485
+ return element.className.match(regExp) !== null;
486
+ };
487
+ removeClass = function(element, className) {
488
+ var k, len, name, ref8, regExp, results;
489
+ ref8 = className.split(" ");
490
+ results = [];
491
+ for (k = 0, len = ref8.length; k < len; k++) {
492
+ name = ref8[k];
493
+ regExp = new RegExp("(?:^|\\s)" + name + "(?!\\S)", "g");
494
+ results.push(element.className = element.className.replace(regExp, ''));
495
+ }
496
+ return results;
497
+ };
498
+ addClass = function(element, className) {
499
+ var k, len, name, ref8, results;
500
+ ref8 = className.split(" ");
501
+ results = [];
502
+ for (k = 0, len = ref8.length; k < len; k++) {
503
+ name = ref8[k];
504
+ if (!hasClass(element, name)) {
505
+ results.push(element.className += " " + name);
506
+ } else {
507
+ results.push(void 0);
508
+ }
509
+ }
510
+ return results;
511
+ };
512
+ replaceClass = function(element, replaceClassName, byClassName) {
513
+ removeClass(element, replaceClassName);
514
+ return addClass(element, byClassName);
515
+ };
516
+
517
+ colorizeTableIfNeed = function(element){
518
+ if(opts.chartOptions.table_options.colorize_headers == true){
519
+ element.className += " colorized";
520
+ }
521
+ };
522
+
523
+ valueNoDashes = function(value){
524
+
525
+ if(opts.chartOptions.table_options.remove_underscores == true && typeof(value) == 'string'){
526
+ return value.replace(/_/g, " ");
527
+ }
528
+ return value;
529
+ };
530
+
531
+ offsetColors = function (offset, colorsArray) {
532
+ if (offset > opts.defaults_colors.length) {
533
+ offset = offset % opts.defaults_colors;
534
+ }
535
+ var colors_to_return = JSON.parse(JSON.stringify(colorsArray));
536
+ for (var i = 0; i < offset; i++) {
537
+ colors_to_return.push(colors_to_return.shift());
538
+ }
539
+ return colors_to_return;
540
+ }
541
+
542
+ getColorsWithOffsetForTable = function (value) {
543
+ var isNewDesign = useNewUx && opts.chartOptions.table_options.use_new_table_design;
544
+ if (value) {
545
+ var offset = parseInt(value);
546
+ if (offset) {
547
+ if (isNewDesign) {
548
+ return offsetColors(offset, newTableColors);
549
+ } else {
550
+ return offsetColors(offset, opts.defaults_colors);
551
+ }
552
+ }
553
+ }
554
+ return isNewDesign ? newTableColors : opts.defaults_colors;
555
+ }
556
+
557
+ colorizeRowLabelHeaders = function(element, cols_count){
558
+ if(opts.chartOptions.table_options.colorize_headers == true &&
559
+ opts.defaults_colors && opts.defaults_colors.length > 0){
560
+ var offsetColor = getColorsWithOffsetForTable(opts.chartOptions.table_options.table_colors_offset);
561
+ var color_to_set = offsetColor[cols_count];
562
+ if(color_to_set){
563
+ element.style.setProperty("background-color", color_to_set, "important");
564
+ element.style.setProperty("border-color", color_to_set, "important");
565
+ element.style.color = useNewUx && opts.chartOptions.table_options.use_new_table_design? '#3a3b39' : '#FFFFFF';
566
+ element.style.fontWeight = "bold";
567
+ if (opts.chartOptions.table_options.freeze_panes && element.firstChild) {
568
+ for (const child of element.children) {
569
+ child.style.setProperty("background-color", color_to_set, "important");
570
+ }
571
+ }
572
+ }
573
+ }
574
+ };
575
+
576
+ createTotalValsBolder = function(element){
577
+ if(opts.chartOptions.table_options.colorize_headers == true && (!useNewUx || !opts.chartOptions.table_options.use_new_table_design)){
578
+ element.style.setProperty("border-bottom", "3px double #000000", "important");
579
+ }
580
+ };
581
+ createGrandTotalBolder = function(element){
582
+ if(opts.chartOptions.table_options.colorize_headers == true && (!useNewUx || !opts.chartOptions.table_options.use_new_table_design)){
583
+ element.style.setProperty("border-top", "3px solid #000000", "important");
584
+ }
585
+ };
586
+ getHeaderColorProperties = function(element, col_number = 0){
587
+ if(opts.chartOptions.table_options.colorize_headers == true &&
588
+ opts.defaults_colors && opts.defaults_colors.length > 0){
589
+ const offsetColor = getColorsWithOffsetForTable(opts.chartOptions.table_options.table_colors_offset);
590
+ var color_to_set = offsetColor[col_number];
591
+ if(color_to_set){
592
+ element.style.setProperty("background-color", color_to_set, "important");
593
+ element.style.setProperty("border-color", color_to_set, "important");
594
+ element.style.setProperty("vertical-align", "baseline");
595
+ element.style.color = useNewUx && opts.chartOptions.table_options.use_new_table_design? '#3a3b39' : '#FFFFFF';
596
+ element.style.fontWeight = "bold";
597
+ if (opts.chartOptions.table_options.freeze_panes && element.firstChild) {
598
+ for (const child of element.children) {
599
+ child.style.setProperty("background-color", color_to_set, "important");
600
+ }
601
+ }
602
+ }
603
+ }
604
+ };
605
+ getTableEventHandlers = function(value, rowValues, colValues) {
606
+ var attr, event, eventHandlers, filters, handler, i, ref8;
607
+ if (!opts.table && !opts.table.eventHandlers) {
608
+ return;
609
+ }
610
+ eventHandlers = {};
611
+ ref8 = opts.table.eventHandlers;
612
+ for (event in ref8) {
613
+ if (!hasProp.call(ref8, event)) continue;
614
+ handler = ref8[event];
615
+ filters = {};
616
+ for (i in colAttrs) {
617
+ if (!hasProp.call(colAttrs, i)) continue;
618
+ attr = colAttrs[i];
619
+ if (colValues[i] != null) {
620
+ filters[attr] = colValues[i];
621
+ }
622
+ }
623
+ for (i in rowAttrs) {
624
+ if (!hasProp.call(rowAttrs, i)) continue;
625
+ attr = rowAttrs[i];
626
+ if (rowValues[i] != null) {
627
+ filters[attr] = rowValues[i];
628
+ }
629
+ }
630
+ eventHandlers[event] = function(e) {
631
+ return handler(e, value, filters, pivotData);
632
+ };
633
+ }
634
+ return eventHandlers;
635
+ };
636
+ createElement = function(elementType, className, textContent, attributes, eventHandlers) {
637
+ var attr, e, event, handler, val;
638
+ e = document.createElement(elementType);
639
+ if (className != null) {
640
+ e.className = className;
641
+ }
642
+ if (textContent != null) {
643
+ // We need html for negative items.
644
+ e.innerHTML = textContent;
645
+ }
646
+ if (attributes != null) {
647
+ for (attr in attributes) {
648
+ if (!hasProp.call(attributes, attr)) continue;
649
+ val = attributes[attr];
650
+ e.setAttribute(attr, val);
651
+ }
652
+ }
653
+ if (eventHandlers != null) {
654
+ for (event in eventHandlers) {
655
+ if (!hasProp.call(eventHandlers, event)) continue;
656
+ handler = eventHandlers[event];
657
+ e.addEventListener(event, handler);
658
+ }
659
+ }
660
+ return e;
661
+ };
662
+ setAttributes = function(e, attrs) {
663
+ var a, results, v;
664
+ results = [];
665
+ for (a in attrs) {
666
+ if (!hasProp.call(attrs, a)) continue;
667
+ v = attrs[a];
668
+ results.push(e.setAttribute(a, v));
669
+ }
670
+ return results;
671
+ };
672
+ getSubtotalInBrackets = function(keysArr, className, lastCol, lastRow, from, to) {
673
+ let aggregator, val, to_return;
674
+ if(opts.chartOptions.table_options.show_subtotals_in_brackets){
675
+ if(className == "pvtColLabel" && keysArr[from] && to < keysArr[from].length){
676
+ aggregator = pivotData.getAggregator([], keysArr[from].slice(0, to+1));
677
+ val = aggregator.value();
678
+ to_return = getFormattedNumber(val, aggregator, opts);
679
+ return ' ('+to_return+")";
680
+ }
681
+ else if(className == "pvtRowLabel" && keysArr[from] && to < keysArr[from].length){
682
+ aggregator = pivotData.getAggregator(keysArr[from].slice(0, to+1), []);
683
+ val = aggregator.value();
684
+ to_return = getFormattedNumber(val, aggregator, opts);
685
+ return ' ('+to_return+")";
686
+ }
687
+ }
688
+ return '';
689
+ };
690
+ encodeHtmlEntities = function(string_val) {
691
+ if(!string_val || typeof(string_val) != 'string' ){
692
+ return string_val;
693
+ }
694
+ var entityMap = {"'":"&apos;","<":"&lt;",">":"&gt;"," ":"&nbsp;","¡":"&iexcl;","¢":"&cent;","£":"&pound;","¤":"&curren;","¥":"&yen;","¦":"&brvbar;","§":"&sect;","¨":"&uml;","©":"&copy;","ª":"&ordf;","«":"&laquo;","¬":"&not;","®":"&reg;","¯":"&macr;","°":"&deg;","±":"&plusmn;","²":"&sup2;","³":"&sup3;","´":"&acute;","µ":"&micro;","¶":"&para;","·":"&middot;","¸":"&cedil;","¹":"&sup1;","º":"&ordm;","»":"&raquo;","¼":"&frac14;","½":"&frac12;","¾":"&frac34;","¿":"&iquest;","À":"&Agrave;","Á":"&Aacute;","Â":"&Acirc;","Ã":"&Atilde;","Ä":"&Auml;","Å":"&Aring;","Æ":"&AElig;","Ç":"&Ccedil;","È":"&Egrave;","É":"&Eacute;","Ê":"&Ecirc;","Ë":"&Euml;","Ì":"&Igrave;","Í":"&Iacute;","Î":"&Icirc;","Ï":"&Iuml;","Ð":"&ETH;","Ñ":"&Ntilde;","Ò":"&Ograve;","Ó":"&Oacute;","Ô":"&Ocirc;","Õ":"&Otilde;","Ö":"&Ouml;","×":"&times;","Ø":"&Oslash;","Ù":"&Ugrave;","Ú":"&Uacute;","Û":"&Ucirc;","Ü":"&Uuml;","Ý":"&Yacute;","Þ":"&THORN;","ß":"&szlig;","à":"&agrave;","á":"&aacute;","â":"&acirc;","ã":"&atilde;","ä":"&auml;","å":"&aring;","æ":"&aelig;","ç":"&ccedil;","è":"&egrave;","é":"&eacute;","ê":"&ecirc;","ë":"&euml;","ì":"&igrave;","í":"&iacute;","î":"&icirc;","ï":"&iuml;","ð":"&eth;","ñ":"&ntilde;","ò":"&ograve;","ó":"&oacute;","ô":"&ocirc;","õ":"&otilde;","ö":"&ouml;","÷":"&divide;","ø":"&oslash;","ù":"&ugrave;","ú":"&uacute;","û":"&ucirc;","ü":"&uuml;","ý":"&yacute;","þ":"&thorn;","ÿ":"&yuml;","Œ":"&OElig;","œ":"&oelig;","Š":"&Scaron;","š":"&scaron;","Ÿ":"&Yuml;","ƒ":"&fnof;","ˆ":"&circ;","˜":"&tilde;","Α":"&Alpha;","Β":"&Beta;","Γ":"&Gamma;","Δ":"&Delta;","Ε":"&Epsilon;","Ζ":"&Zeta;","Η":"&Eta;","Θ":"&Theta;","Ι":"&Iota;","Κ":"&Kappa;","Λ":"&Lambda;","Μ":"&Mu;","Ν":"&Nu;","Ξ":"&Xi;","Ο":"&Omicron;","Π":"&Pi;","Ρ":"&Rho;","Σ":"&Sigma;","Τ":"&Tau;","Υ":"&Upsilon;","Φ":"&Phi;","Χ":"&Chi;","Ψ":"&Psi;","Ω":"&Omega;","α":"&alpha;","β":"&beta;","γ":"&gamma;","δ":"&delta;","ε":"&epsilon;","ζ":"&zeta;","η":"&eta;","θ":"&theta;","ι":"&iota;","κ":"&kappa;","λ":"&lambda;","μ":"&mu;","ν":"&nu;","ξ":"&xi;","ο":"&omicron;","π":"&pi;","ρ":"&rho;","ς":"&sigmaf;","σ":"&sigma;","τ":"&tau;","υ":"&upsilon;","φ":"&phi;","χ":"&chi;","ψ":"&psi;","ω":"&omega;","ϑ":"&thetasym;","ϒ":"&Upsih;","ϖ":"&piv;","–":"&ndash;","—":"&mdash;","‘":"&lsquo;","’":"&rsquo;","‚":"&sbquo;","“":"&ldquo;","”":"&rdquo;","„":"&bdquo;","†":"&dagger;","‡":"&Dagger;","•":"&bull;","…":"&hellip;","‰":"&permil;","′":"&prime;","″":"&Prime;","‹":"&lsaquo;","›":"&rsaquo;","‾":"&oline;","⁄":"&frasl;","€":"&euro;","ℑ":"&image;","℘":"&weierp;","ℜ":"&real;","™":"&trade;","ℵ":"&alefsym;","←":"&larr;","↑":"&uarr;","→":"&rarr;","↓":"&darr;","↔":"&harr;","↵":"&crarr;","⇐":"&lArr;","⇑":"&UArr;","⇒":"&rArr;","⇓":"&dArr;","⇔":"&hArr;","∀":"&forall;","∂":"&part;","∃":"&exist;","∅":"&empty;","∇":"&nabla;","∈":"&isin;","∉":"&notin;","∋":"&ni;","∏":"&prod;","∑":"&sum;","−":"&minus;","∗":"&lowast;","√":"&radic;","∝":"&prop;","∞":"&infin;","∠":"&ang;","∧":"&and;","∨":"&or;","∩":"&cap;","∪":"&cup;","∫":"&int;","∴":"&there4;","∼":"&sim;","≅":"&cong;","≈":"&asymp;","≠":"&ne;","≡":"&equiv;","≤":"&le;","≥":"&ge;","⊂":"&sub;","⊃":"&sup;","⊄":"&nsub;","⊆":"&sube;","⊇":"&supe;","⊕":"&oplus;","⊗":"&otimes;","⊥":"&perp;","⋅":"&sdot;","⌈":"&lceil;","⌉":"&rceil;","⌊":"&lfloor;","⌋":"&rfloor;","⟨":"&lang;","⟩":"&rang;","◊":"&loz;","♠":"&spades;","♣":"&clubs;","♥":"&hearts;","♦":"&diams;"};
695
+ string_val = string_val.replace(/&/g, '&amp;');
696
+ string_val = string_val.replace(/"/g, '&quot;');
697
+ for (var key in entityMap) {
698
+ var entity = entityMap[key];
699
+ var regex = new RegExp(key, 'g');
700
+ string_val = string_val.replace(regex, entity);
701
+ }
702
+ return string_val;
703
+ };
704
+
705
+ processKeys = function(keysArr, className, dimention, attrs) {
706
+ var c, headers, k, key, lastCol, lastRow, node, nodePos, r, rMark, ref8, repeats, th, x;
707
+ const showAllData = opts && opts.chartOptions && opts.chartOptions.table_options && opts.chartOptions.table_options.show_all;
708
+
709
+ headers = [];
710
+ lastRow = keysArr.length - 1;
711
+ lastCol = keysArr[0].length - 1;
712
+ if(lastCol > 0 && className == "pvtColLabel" && !_.get(opts, 'chartOptions.table_options.transpose_table', false) && (charttype == 'column-chart' || charttype == 'column-chart-stacked')){
713
+ lastCol = 0;
714
+ }
715
+ rMark = [];
716
+ th = createElement("th", className, valueNoDashes(encodeHtmlEntities(keysArr[0][0]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, 0, 0)));
717
+ key = [];
718
+ key.push(keysArr[0][0]);
719
+ nodePos = 0;
720
+ node = {
721
+ node: nodePos,
722
+ row: 0,
723
+ col: 0,
724
+ th: th,
725
+ parent: null,
726
+ children: [],
727
+ descendants: lastCol,
728
+ leaves: 1,
729
+ key: key,
730
+ flatKey: key.join(delim)
731
+ };
732
+ headers.push(node);
733
+ rMark[0] = node;
734
+ c = 1;
735
+ while (c <= lastCol) {
736
+ th = createElement("th", className, valueNoDashes(encodeHtmlEntities(keysArr[0][c]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, 0, c)));
737
+ key = key.slice();
738
+ key.push(keysArr[0][c]);
739
+ ++nodePos;
740
+ node = {
741
+ node: nodePos,
742
+ row: 0,
743
+ col: c,
744
+ th: th,
745
+ parent: rMark[c - 1],
746
+ children: [],
747
+ descendants: lastCol - c,
748
+ leaves: 1,
749
+ key: key,
750
+ flatKey: key.join(delim)
751
+ };
752
+ rMark[c] = node;
753
+ rMark[c - 1].children.push(node);
754
+ ++c;
755
+ }
756
+ rMark[lastCol].leaves = 0;
757
+ r = 1;
758
+ while (r <= lastRow) {
759
+ repeats = true;
760
+ key = [];
761
+ c = 0;
762
+ while (c <= lastCol) {
763
+ key = key.slice();
764
+ key.push(keysArr[r][c]);
765
+ if ((keysArr[r][c] === keysArr[rMark[c].row][c]) && (c !== lastCol) && repeats) {
766
+ repeats = true;
767
+ ++c;
768
+ continue;
769
+ }
770
+
771
+ if(c === 0 && ((dimention == 'rows' && opts.show_more_function_rows)
772
+ || (dimention == 'cols' && opts.show_more_function_cols)
773
+ ) && headers.length > opts.show_more_max_items && !showAllData)
774
+ {
775
+ key=['...'];
776
+
777
+ let th_attr = {data_show_more:'1'};
778
+
779
+ th = createElement("th", className, '... Show All', th_attr);
780
+ ++nodePos;
781
+ node = {
782
+ node: nodePos,
783
+ row: r,
784
+ col: c,
785
+ th: th,
786
+ parent: null,
787
+ children: [],
788
+ descendants: 0,
789
+ leaves: 0,
790
+ key: key,
791
+ flatKey: key.join(delim)
792
+ };
793
+
794
+ headers.push(node);
795
+ rMark[c] = node;
796
+ repeats = false;
797
+ r = lastRow;
798
+ break;
799
+ }
800
+
801
+
802
+ th = createElement("th", className, valueNoDashes(encodeHtmlEntities(keysArr[r][c]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, r, c)));
803
+ ++nodePos;
804
+ node = {
805
+ node: nodePos,
806
+ row: r,
807
+ col: c,
808
+ th: th,
809
+ parent: null,
810
+ children: [],
811
+ descendants: 0,
812
+ leaves: 0,
813
+ key: key,
814
+ flatKey: key.join(delim)
815
+ };
816
+ if (c === 0) {
817
+ headers.push(node);
818
+ } else {
819
+ node.parent = rMark[c - 1];
820
+ rMark[c - 1].children.push(node);
821
+ x = 0;
822
+ while (x <= c - 1) {
823
+ ++rMark[x].descendants;
824
+ ++x;
825
+ }
826
+ }
827
+ rMark[c] = node;
828
+ repeats = false;
829
+ ++c;
830
+ }
831
+ for (c = k = 0, ref8 = lastCol; 0 <= ref8 ? k <= ref8 : k >= ref8; c = 0 <= ref8 ? ++k : --k) {
832
+ ++rMark[c].leaves;
833
+ }
834
+ rMark[lastCol].leaves = 0;
835
+ ++r;
836
+ }
837
+ return headers;
838
+ };
839
+ buildColHeaderHeader = function(thead, colHeaderHeaders, rowAttrs, colAttrs, tr, col) {
840
+ var className, colAttr, textContent, th, clickStatus;
841
+ colAttr = colAttrs[col];
842
+ textContent = opts.labelsConvertFunction(colAttr);
843
+ className = "pvtAxisLabel" + axisFreezePaneClass;
844
+ if (col < colAttrs.length - 1) {
845
+ if (!(isColDisableExpandCollapse || isColDisable || col > colDisableAfter)) {
846
+ if(opts.collapseColsAt == 0){
847
+ clickStatus = clickStatusCollapsed;
848
+ className += " "+classCollapsed;
849
+ textContent = " " + arrowCollapsed + " " + textContent;
850
+ }
851
+ else{
852
+ clickStatus = clickStatusExpanded;
853
+ className += " "+classExpanded;
854
+ textContent = " " + arrowExpanded + " " + textContent;
855
+ }
856
+ }
857
+ }
858
+ th = createElement("th", className, textContent);
859
+ th.setAttribute("data-colAttr", colAttr);
860
+ //getHeaderColorProperties(th, col);
861
+ tr.appendChild(th);
862
+ colHeaderHeaders.push({
863
+ tr: tr,
864
+ th: th,
865
+ clickStatus: clickStatus,
866
+ expandedCount: 0,
867
+ nHeaders: 0
868
+ });
869
+ return thead.appendChild(tr);
870
+ };
871
+ buildColHeaderHeaders = function(thead, colHeaderHeaders, rowAttrs, colAttrs) {
872
+ var c, k, ref8, results, tr, rowSpan;
873
+ tr = createElement("tr");
874
+ if (rowAttrs.length !== 0) {
875
+ if(opts.chartOptions.table_options.colorize_headers == true){
876
+ rowSpan = 1;
877
+ }
878
+ else{
879
+ rowSpan = colAttrs.length;
880
+ }
881
+ tr.appendChild(createElement("th", axisFreezePaneClass, null, {
882
+ colspan: rowAttrs.length,
883
+ rowspan: rowSpan
884
+ }));
885
+ }
886
+
887
+ buildColHeaderHeader(thead, colHeaderHeaders, rowAttrs, colAttrs, tr, 0);
888
+ getHeaderColorProperties(tr);
889
+ results = [];
890
+ for (c = k = 1, ref8 = colAttrs.length; 1 <= ref8 ? k <= ref8 : k >= ref8; c = 1 <= ref8 ? ++k : --k) {
891
+ if (!(c < colAttrs.length)) {
892
+ continue;
893
+ }
894
+ tr = createElement("tr");
895
+ if (opts.chartOptions.table_options.colorize_headers == true && rowAttrs.length !== 0) {
896
+ tr.appendChild(createElement("th", axisFreezePaneClass, null, {
897
+ colspan: rowAttrs.length
898
+ }));
899
+ }
900
+ getHeaderColorProperties(tr, c);
901
+ results.push(buildColHeaderHeader(thead, colHeaderHeaders, rowAttrs, colAttrs, tr, c));
902
+ }
903
+ return results;
904
+ };
905
+ buildColHeaderHeadersClickEvents = function(colHeaderHeaders, colHeaderCols, colAttrs) {
906
+ var colAttr, i, k, n, ref8, results, th;
907
+ n = colAttrs.length - 1;
908
+ results = [];
909
+ for (i = k = 0, ref8 = n; 0 <= ref8 ? k <= ref8 : k >= ref8; i = 0 <= ref8 ? ++k : --k) {
910
+ if (!(i < n)) {
911
+ continue;
912
+ }
913
+ th = colHeaderHeaders[i].th;
914
+ colAttr = colAttrs[i];
915
+ results.push(th.onclick = function(event) {
916
+ event = event || window.event;
917
+ if(!event.currentTarget)
918
+ event.currentTarget = event.target;
919
+ return toggleColHeaderHeader(colHeaderHeaders, colHeaderCols, colAttrs, event.currentTarget.getAttribute("data-colAttr"));
920
+ });
921
+ }
922
+ return results;
923
+ };
924
+ buildColHeaders = function(colHeaderHeaders, colHeaderCols, colHeader, rowAttrs, colAttrs) {
925
+ var colspan, h, hh, isColSubtotal, k, len, ref8, rowspan, sTh, style, th, tr;
926
+ ref8 = colHeader.children;
927
+ for (k = 0, len = ref8.length; k < len; k++) {
928
+ h = ref8[k];
929
+ buildColHeaders(colHeaderHeaders, colHeaderCols, h, rowAttrs, colAttrs);
930
+ }
931
+ isColSubtotal = colHeader.children.length !== 0;
932
+ colHeader.node = colHeaderCols.length;
933
+ hh = colHeaderHeaders[colHeader.col];
934
+ ++hh.expandedCount;
935
+ ++hh.nHeaders;
936
+ tr = hh.tr;
937
+ th = colHeader.th;
938
+ addClass(th, "col" + colHeader.row + " colcol" + colHeader.col + " " + classColShow + verticalFreezePaneClass);
939
+ //getHeaderColorProperties(th, colHeader.col);
940
+ if (isColHideOnExpand || isColDisable || (isColSubtotal && colHeader.col > colDisableAfter)) {
941
+ colspan = colHeader.leaves;
942
+ } else if (isColSubtotal && colHeader.col <= colDisableAfter) {
943
+ colspan = colHeader.leaves + 1;
944
+ } else {
945
+ colspan = colHeader.descendants + 1;
946
+ }
947
+
948
+ if(th.getAttribute('data_show_more') == '1'){
949
+ rowspan = colAttrs.length + 1;
950
+ addClass(th, 'show_more_header');
951
+ th.onclick = opts.show_more_function_cols;
952
+ }
953
+ else{
954
+ rowspan = colHeader.col === colAttrs.length - 1 && rowAttrs.length !== 0 ? 2 : 1;
955
+ }
956
+ setAttributes(th, {
957
+ "rowspan": rowspan,
958
+ "colspan": colspan,
959
+ "data-colnode": colHeader.node,
960
+ "data-colHeader": th.textContent
961
+ });
962
+ if (isColSubtotal) {
963
+ addClass(th, classColExpanded);
964
+ if (!(isColDisableExpandCollapse || isColDisable || colHeader.col > colDisableAfter)) {
965
+ th.innerHTML = " " + arrowExpanded + " " + th.textContent;
966
+ }
967
+ th.onclick = function(event) {
968
+ event = event || window.event;
969
+ return toggleCol(colHeaderHeaders, colHeaderCols, parseInt(event.currentTarget.getAttribute("data-colnode")));
970
+ };
971
+ rowspan = colAttrs.length - (colHeader.col + 1) + (rowAttrs.length !== 0 ? 1 : 0);
972
+ style = "pvtColLabel pvtColSubtotal " + classColExpanded + verticalFreezePaneClass;
973
+ style += " col" + colHeader.row + " colcol" + colHeader.col;
974
+ if (isColHideOnExpand || isColDisable || colHeader.col > colDisableAfter) {
975
+ style += " " + classColHide;
976
+ }
977
+ sTh = createElement("th", style, opts.localeStrings.subtotals, {
978
+ "rowspan": rowspan,
979
+ "data-colnode": colHeader.node
980
+ });
981
+ addClass(sTh, isColHideOnExpand || isColDisable ? " " + classColHide : " " + classColShow);
982
+ //getHeaderColorProperties(sTh, colHeader.col);
983
+ if (isColHideOnExpand || isColDisable || colHeader.col > colDisableAfter) {
984
+ sTh.style.display = "none";
985
+ }
986
+ colHeader.children[0].tr.appendChild(sTh);
987
+ colHeader.sTh = sTh;
988
+ }
989
+ colHeader.clickStatus = clickStatusExpanded;
990
+ tr.appendChild(th);
991
+ if (opts.chartOptions.table_options.freeze_panes) {
992
+ getHeaderColorProperties(tr);
993
+ }
994
+ colHeader.tr = tr;
995
+ return colHeaderCols.push(colHeader);
996
+ };
997
+ buildRowHeaderHeaders = function(thead, rowHeaderHeaders, rowAttrs, colAttrs) {
998
+ var className, i, rowAttr, textContent, th, tr, clickStatus;
999
+ tr = createElement("tr");
1000
+ rowHeaderHeaders.hh = [];
1001
+ for (i in rowAttrs) {
1002
+ if (!hasProp.call(rowAttrs, i)) continue;
1003
+ rowAttr = rowAttrs[i];
1004
+ textContent = opts.labelsConvertFunction(rowAttr);
1005
+ className = "pvtAxisLabel" + axisFreezePaneClass;
1006
+ if (i < rowAttrs.length - 1) {
1007
+ className += " expanded";
1008
+ if (!(isRowDisableExpandCollapse || isRowDisable || i > rowDisableAfter)) {
1009
+ if(opts.collapseRowsAt == 0){
1010
+ clickStatus = clickStatusCollapsed;
1011
+ className += " "+classCollapsed;
1012
+ textContent = " " + arrowCollapsed + " " + textContent;
1013
+ }
1014
+ else{
1015
+ clickStatus = clickStatusExpanded;
1016
+ className += " "+classExpanded;
1017
+ textContent = " " + arrowExpanded + " " + textContent;
1018
+ }
1019
+ }
1020
+ }
1021
+ th = createElement("th", className, textContent);
1022
+ th.setAttribute("data-rowAttr", rowAttr);
1023
+ tr.appendChild(th);
1024
+ rowHeaderHeaders.hh.push({
1025
+ th: th,
1026
+ clickStatus: clickStatus,
1027
+ expandedCount: 0,
1028
+ nHeaders: 0
1029
+ });
1030
+ }
1031
+ if (colAttrs.length !== 0) {
1032
+ th = createElement("th", axisFreezePaneClass);
1033
+ tr.appendChild(th);
1034
+ }
1035
+ colorizeRowLabelHeaders(tr, colAttrs.length);
1036
+ thead.appendChild(tr);
1037
+ return rowHeaderHeaders.tr = tr;
1038
+ };
1039
+ buildRowHeaderHeadersClickEvents = function(rowHeaderHeaders, rowHeaderRows, rowAttrs) {
1040
+ var i, k, n, ref8, results, rowAttr, th;
1041
+ n = rowAttrs.length - 1;
1042
+ results = [];
1043
+ for (i = k = 0, ref8 = n; 0 <= ref8 ? k <= ref8 : k >= ref8; i = 0 <= ref8 ? ++k : --k) {
1044
+ if (!(i < n)) {
1045
+ continue;
1046
+ }
1047
+ th = rowHeaderHeaders.hh[i];
1048
+ rowAttr = rowAttrs[i];
1049
+ results.push(th.th.onclick = function(event) {
1050
+ event = event || window.event;
1051
+ if(!event.currentTarget)
1052
+ event.currentTarget = event.target;
1053
+ return toggleRowHeaderHeader(rowHeaderHeaders, rowHeaderRows, rowAttrs, event.currentTarget.getAttribute("data-rowAttr"));
1054
+ });
1055
+ }
1056
+ return results;
1057
+ };
1058
+ buildRowTotalsHeader = function(tr, rowAttrs, colAttrs) {
1059
+ var rowspan, th;
1060
+ rowspan = 1;
1061
+ if (colAttrs.length !== 0) {
1062
+ rowspan = colAttrs.length + (rowAttrs.length === 0 ? 0 : 1);
1063
+ }
1064
+
1065
+ if(opts.chartOptions.table_options.colorize_headers == true && colAttrs.length > 1){
1066
+ rowspan = 1;
1067
+ }
1068
+
1069
+ th = createElement("th", "pvtTotalLabel rowTotal" + verticalFreezePaneClass , opts.localeStrings.totals, {
1070
+ rowspan: rowspan
1071
+ });
1072
+
1073
+ if (opts.totalFilterElements && opts.totalFilterElements.row_total) {
1074
+ th.innerHTML = '';
1075
+ th.appendChild(opts.totalFilterElements.row_total);
1076
+ }
1077
+
1078
+ //getHeaderColorProperties(th);
1079
+ if (opts.chartOptions.table_options.freeze_panes) {
1080
+ tr.appendChild(th);
1081
+ getHeaderColorProperties(tr);
1082
+ } else {
1083
+ return tr.appendChild(th);
1084
+ }
1085
+ };
1086
+ buildRowHeaders = function(tbody, rowHeaderHeaders, rowHeaderRows, rowHeader, rowAttrs, colAttrs, highlighted, hasColLabels) {
1087
+ var colspan, h, hh, isRowSubtotal, k, len, ref8, results, style, th, tr;
1088
+ hh = rowHeaderHeaders.hh[rowHeader.col];
1089
+ ++hh.expandedCount;
1090
+ ++hh.nHeaders;
1091
+ tr = createElement("tr", "pvtRowSubtotal row" + rowHeader.row, "", {
1092
+ "data-rownode": rowHeader.node
1093
+ });
1094
+ th = rowHeader.th;
1095
+
1096
+ if(th.getAttribute('data_show_more') == '1'){
1097
+ colspan = rowAttrs.length + 1;
1098
+ addClass(th, 'show_more_header');
1099
+ th.onclick = opts.show_more_function_rows;
1100
+ }
1101
+ else{
1102
+ colspan = rowHeader.col === rowAttrs.length - 1 && colAttrs.length !== 0 ? 2 : 1;
1103
+ }
1104
+
1105
+ isRowSubtotal = rowHeader.children.length !== 0;
1106
+ addClass(th, "row" + rowHeader.row + " rowcol" + rowHeader.col + " " + classRowShow + horizontalFreezePaneClass);
1107
+ if (highlighted) {
1108
+ addClass(th, "highlighted");
1109
+ }
1110
+ setAttributes(th, {
1111
+ "data-rowHeader": th.textContent,
1112
+ "data-rownode": rowHeader.node,
1113
+ "rowspan": rowHeader.descendants + 1,
1114
+ "colspan": colspan
1115
+ });
1116
+ if (opts.chartOptions.table_options.hide_nulls_in_headers) {
1117
+ th.textContent = th.textContent.replace('[null]', '');
1118
+ }
1119
+
1120
+ if (th.hasAttribute('data_show_more') && th.colSpan > 0 && !hasColLabels) {
1121
+ th.colSpan = th.colSpan - 1;
1122
+ }
1123
+
1124
+ tr.appendChild(th);
1125
+ if (isRowSubtotal) {
1126
+ addClass(tr, classRowExpanded);
1127
+ addClass(th, classRowExpanded);
1128
+ if (!(isRowDisableExpandCollapse || isRowDisable || rowHeader.col > rowDisableAfter)) {
1129
+ th.innerHTML = " " + arrowExpanded + " " + th.textContent;
1130
+ }
1131
+ th.onclick = function(event) {
1132
+ event = event || window.event;
1133
+ return toggleRow(rowHeaderHeaders, rowHeaderRows, parseInt(event.currentTarget.getAttribute("data-rownode")));
1134
+ };
1135
+ colspan = rowAttrs.length - (rowHeader.col + 1) + (colAttrs.length !== 0 ? 1 : 0);
1136
+ style = "pvtRowLabel pvtRowSubtotal " + classRowExpanded;
1137
+ style += " row" + rowHeader.row + " rowcol" + rowHeader.col;
1138
+ style += isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter ? " " + classRowHide : " " + classRowShow;
1139
+ style += horizontalFreezePaneClass;
1140
+ th = createElement("th", style, opts.localeStrings.subtotals, {
1141
+ "colspan": colspan,
1142
+ "data-rownode": rowHeader.node
1143
+ });
1144
+ if (isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter) {
1145
+ th.style.display = "none";
1146
+ }
1147
+ tr.appendChild(th);
1148
+ }
1149
+ rowHeader.clickStatus = clickStatusExpanded;
1150
+ rowHeader.tr = tr;
1151
+ rowHeaderRows.push(rowHeader);
1152
+ tbody.appendChild(tr);
1153
+ ref8 = rowHeader.children;
1154
+ results = [];
1155
+ for (k = 0, len = ref8.length; k < len; k++) {
1156
+ h = ref8[k];
1157
+ results.push(buildRowHeaders(tbody, rowHeaderHeaders, rowHeaderRows, h, rowAttrs, colAttrs, highlighted, hasColLabels));
1158
+ }
1159
+ return results;
1160
+ };
1161
+ buildValues = function(rowHeaderRows, colHeaderCols, rowAttrs, colAttrs) {
1162
+ var aggregator, colHeader, eventHandlers, flatColKey, flatRowKey, isColSubtotal, isRowSubtotal, k, l, len, len1, ref8, results, rowHeader, style, td, totalAggregator, tr, val;
1163
+ results = [];
1164
+ for (k = 0, len = rowHeaderRows.length; k < len; k++) {
1165
+ rowHeader = rowHeaderRows[k];
1166
+ tr = rowHeader.tr;
1167
+ flatRowKey = rowHeader.flatKey;
1168
+ isRowSubtotal = rowHeader.children.length !== 0;
1169
+ for (l = 0, len1 = colHeaderCols.length; l < len1; l++) {
1170
+ colHeader = colHeaderCols[l];
1171
+ flatColKey = colHeader.flatKey;
1172
+ if(tree && tree[flatRowKey] && tree[flatRowKey][flatColKey]){
1173
+ ref8 = tree[flatRowKey][flatColKey]
1174
+ }
1175
+ else{
1176
+ ref8 = null;
1177
+ }
1178
+
1179
+ aggregator = ref8 != null ? ref8 : {
1180
+ value: (function() {
1181
+ return null;
1182
+ }),
1183
+ format: function() {
1184
+ return "";
1185
+ }
1186
+ };
1187
+ val = aggregator.value();
1188
+ isColSubtotal = colHeader.children.length !== 0;
1189
+ style = "pvtVal";
1190
+ if (isColSubtotal) {
1191
+ style += " pvtColSubtotal " + classColExpanded;
1192
+ }
1193
+ if (isRowSubtotal) {
1194
+ style += " pvtRowSubtotal " + classRowExpanded;
1195
+ }
1196
+ style += isRowSubtotal && (isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter) ? " " + classRowHide : " " + classRowShow;
1197
+ style += isColSubtotal && (isColHideOnExpand || isColDisable || colHeader.col > colDisableAfter) ? " " + classColHide : " " + classColShow;
1198
+ style += (" row" + rowHeader.row) + (" col" + colHeader.row) + (" rowcol" + rowHeader.col) + (" colcol" + colHeader.col);
1199
+ eventHandlers = getTableEventHandlers(val, rowHeader.key, colHeader.key);
1200
+ td = createElement("td", style, getFormattedNumber(val, aggregator, opts), {
1201
+ "data-value": val,
1202
+ "data-rownode": rowHeader.node,
1203
+ "data-colnode": colHeader.node
1204
+ }, eventHandlers);
1205
+ if ((isRowSubtotal && (isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter)) || (isColSubtotal && (isColHideOnExpand || isColDisable || colHeader.col > colDisableAfter))) {
1206
+ td.style.display = "none";
1207
+ }
1208
+ assumptionSubscribe(td, rowHeader, rowAttrs, colHeader, colAttrs, val);
1209
+
1210
+ tr.appendChild(td);
1211
+ }
1212
+ totalAggregator = rowTotals[flatRowKey];
1213
+ if(!totalAggregator){
1214
+ totalAggregator = {
1215
+ value: (function () {
1216
+ return null;
1217
+ }),
1218
+ format: function () {
1219
+ return "";
1220
+ }
1221
+ };
1222
+ }
1223
+
1224
+ val = totalAggregator.value();
1225
+ style = "pvtTotal rowTotal";
1226
+ if (isRowSubtotal) {
1227
+ style += " pvtRowSubtotal";
1228
+ }
1229
+ style += isRowSubtotal && (isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter) ? " " + classRowHide : " " + classRowShow;
1230
+ style += " row" + rowHeader.row + " rowcol" + rowHeader.col;
1231
+ td = createElement("td", style, getFormattedNumber(val, totalAggregator, opts), {
1232
+ "data-value": val,
1233
+ "data-row": "row" + rowHeader.row,
1234
+ "data-rowcol": "col" + rowHeader.col,
1235
+ "data-rownode": rowHeader.node
1236
+ }, getTableEventHandlers(val, rowHeader.key, []));
1237
+ if (isRowSubtotal && (isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter)) {
1238
+ td.style.display = "none";
1239
+ }
1240
+
1241
+ assumptionSubscribe(td, rowHeader, rowAttrs, {key:[], flatKey:''}, colAttrs, val);
1242
+
1243
+ if(opts.chartOptions.table_options.show_row_total)
1244
+ tr.appendChild(td);
1245
+
1246
+ results.push(tr);
1247
+ }
1248
+ return results;
1249
+ };
1250
+
1251
+ assumptionSubscribe = function(td, rowHeader, rowAttrs, colHeader, colAttrs, val){
1252
+ if(edit_assumptions){
1253
+ var filters = [];
1254
+ var i=0;
1255
+ var temp;
1256
+ for(i=0; i<rowHeader.key.length; i++){
1257
+ temp = {
1258
+ name: rowAttrs[i],
1259
+ values: [rowHeader.key[i]],
1260
+ is_excluded:false
1261
+ }
1262
+ filters.push(temp);
1263
+ }
1264
+ for(i=0; i<colHeader.key.length; i++){
1265
+ temp = {
1266
+ name: colAttrs[i],
1267
+ values: [colHeader.key[i]],
1268
+ is_excluded:false
1269
+ }
1270
+ filters.push(temp);
1271
+ }
1272
+ var obj_to_send = {
1273
+ "flatColKey": colHeader.flatKey,
1274
+ "flatRowKey": rowHeader.flatKey,
1275
+ "val": val,
1276
+ "filters": filters
1277
+ };
1278
+
1279
+ // td.addEventListener('dblclick', function(){
1280
+ // edit_assumptions.fn(obj_to_send, this);
1281
+ // });
1282
+
1283
+ td.addEventListener('click', function(){
1284
+ edit_assumptions.fn(obj_to_send, this);
1285
+ });
1286
+ }
1287
+
1288
+ if(opts.value_drill_down_fn){
1289
+ td.classList.add('clickable');
1290
+ td.addEventListener('click', function(rowKey, colKey, rowAttrs, colAttrs){
1291
+ return function($event){
1292
+ $event.preventDefault();
1293
+ opts.value_drill_down_fn($event, rowKey, colKey);
1294
+ };
1295
+ }(rowHeader.key, colHeader.key, rowAttrs, colAttrs));
1296
+ }
1297
+ };
1298
+
1299
+ buildColTotalsHeader = function(rowAttrs, colAttrs) {
1300
+ var colspan, th, tr;
1301
+ tr = createElement("tr");
1302
+ colspan = rowAttrs.length + (colAttrs.length === 0 ? 0 : 1);
1303
+ th = createElement("th", "pvtTotalLabel colTotal" + horizontalFreezePaneClass, opts.localeStrings.totals, {
1304
+ colspan: colspan
1305
+ });
1306
+ if (opts.totalFilterElements && opts.totalFilterElements.col_total) {
1307
+ th.innerHTML = '';
1308
+ th.appendChild(opts.totalFilterElements.col_total);
1309
+ }
1310
+ tr.appendChild(th);
1311
+ return tr;
1312
+ };
1313
+ buildColTotals = function(tr, colHeaderCols, rowAttrs, colAttrs) {
1314
+ var h, isColSubtotal, k, len, results, style, td, totalAggregator, val;
1315
+ results = [];
1316
+ for (k = 0, len = colHeaderCols.length; k < len; k++) {
1317
+ h = colHeaderCols[k];
1318
+ isColSubtotal = h.children.length !== 0;
1319
+ totalAggregator = colTotals[h.flatKey];
1320
+ if(!totalAggregator){
1321
+ totalAggregator = {
1322
+ value: (function () {
1323
+ return null;
1324
+ }),
1325
+ format: function () {
1326
+ return "";
1327
+ }
1328
+ };
1329
+ }
1330
+ val = totalAggregator.value();
1331
+ style = "pvtVal pvtTotal colTotal";
1332
+ if (isColSubtotal) {
1333
+ style += " pvtColSubtotal";
1334
+ }
1335
+ style += " " + classColExpanded;
1336
+ style += " col" + h.row + " colcol" + h.col;
1337
+ td = createElement("td", style, getFormattedNumber(val, totalAggregator, opts), {
1338
+ "data-value": val,
1339
+ "data-for": "col" + h.col,
1340
+ "data-colnode": "" + h.node
1341
+ }, getTableEventHandlers(val, [], h.key));
1342
+ createTotalValsBolder(td)
1343
+ if (isColSubtotal && (isColHideOnExpand || isColDisable || h.col > colDisableAfter)) {
1344
+ td.style.display = "none";
1345
+ }
1346
+
1347
+ assumptionSubscribe(td, {key:[], flatKey:''}, rowAttrs, h, colAttrs, val);
1348
+
1349
+ results.push(tr.appendChild(td));
1350
+ }
1351
+ createGrandTotalBolder(tr);
1352
+ return results;
1353
+ };
1354
+ buildGrandTotal = function(result, tr, rowAttrs, colAttrs) {
1355
+ var td, totalAggregator, val;
1356
+ totalAggregator = allTotal;
1357
+ val = totalAggregator.value();
1358
+ td = createElement("td", "pvtGrandTotal", getFormattedNumber(val, totalAggregator, opts), {
1359
+ "data-value": val
1360
+ }, getTableEventHandlers(val, [], []));
1361
+ createTotalValsBolder(td);
1362
+ assumptionSubscribe(td, {key:[], flatKey:''}, rowAttrs, {key:[], flatKey:''}, colAttrs, val);
1363
+
1364
+ tr.appendChild(td);
1365
+ return result.appendChild(tr);
1366
+ };
1367
+ removeRowHeaderNullValue = function(h) {
1368
+ if (opts.chartOptions.table_options.hide_nulls_in_headers) {
1369
+ h.th.innerHTML = h.th.innerHTML.replace('[null]' , '');
1370
+ }
1371
+ };
1372
+ hideDescendantCol = function(d) {
1373
+ return $(d.th).closest('table.pvtTable').find("tbody tr td[data-colnode=\"" + d.node + "\"], th[data-colnode=\"" + d.node + "\"]").removeClass(classColShow).addClass(classColHide).css('display', "none");
1374
+ };
1375
+ collapseShowColSubtotal = function(h) {
1376
+ $(h.th).closest('table.pvtTable').find("tbody tr td[data-colnode=\"" + h.node + "\"], th[data-colnode=\"" + h.node + "\"]").removeClass(classColExpanded + " " + classColHide).addClass(classColCollapsed + " " + classColShow).not(".pvtRowSubtotal." + classRowHide).css('display', "");
1377
+ h.th.innerHTML = " " + arrowCollapsed + " " + h.th.getAttribute("data-colheader");
1378
+ return h.th.colSpan = 1;
1379
+ };
1380
+ collapseCol = function(colHeaderHeaders, colHeaderCols, c) {
1381
+ var colHeaderHeader, colspan, d, h, i, isColSubtotal, k, l, p, ref10, ref8, ref9, results;
1382
+ if (isColDisable) {
1383
+ return;
1384
+ }
1385
+ if (isColDisableExpandCollapse) {
1386
+ return;
1387
+ }
1388
+ if (!colHeaderCols[c]) {
1389
+ return;
1390
+ }
1391
+ h = colHeaderCols[c];
1392
+ if (h.col > colDisableAfter) {
1393
+ return;
1394
+ }
1395
+ if (h.clickStatus === clickStatusCollapsed) {
1396
+ return;
1397
+ }
1398
+ isColSubtotal = h.descendants !== 0;
1399
+ colspan = h.th.colSpan;
1400
+ for (i = k = 1, ref8 = h.descendants; 1 <= ref8 ? k <= ref8 : k >= ref8; i = 1 <= ref8 ? ++k : --k) {
1401
+ if (!(h.descendants !== 0)) {
1402
+ continue;
1403
+ }
1404
+ d = colHeaderCols[c - i];
1405
+ hideDescendantCol(d);
1406
+ }
1407
+ if (isColSubtotal) {
1408
+ collapseShowColSubtotal(h);
1409
+ --colspan;
1410
+ }
1411
+ p = h.parent;
1412
+ while (p !== null) {
1413
+ p.th.colSpan -= colspan;
1414
+ p = p.parent;
1415
+ }
1416
+ h.clickStatus = clickStatusCollapsed;
1417
+ colHeaderHeader = colHeaderHeaders[h.col];
1418
+ colHeaderHeader.expandedCount--;
1419
+ if (colHeaderHeader.expandedCount === 0) {
1420
+ results = [];
1421
+ for (i = l = ref9 = h.col, ref10 = colHeaderHeaders.length - 2; ref9 <= ref10 ? l <= ref10 : l >= ref10; i = ref9 <= ref10 ? ++l : --l) {
1422
+ if (!(i <= colDisableAfter)) {
1423
+ continue;
1424
+ }
1425
+ colHeaderHeader = colHeaderHeaders[i];
1426
+ replaceClass(colHeaderHeader.th, classExpanded, classCollapsed);
1427
+ colHeaderHeader.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(colHeaderHeader.th.getAttribute("data-colAttr"));
1428
+ results.push(colHeaderHeader.clickStatus = clickStatusCollapsed);
1429
+ }
1430
+ return results;
1431
+ }
1432
+ };
1433
+ showChildCol = function(ch) {
1434
+ return $(ch.th).closest('table.pvtTable').find("tbody tr td[data-colnode=\"" + ch.node + "\"], th[data-colnode=\"" + ch.node + "\"]").removeClass(classColHide).addClass(classColShow).not(".pvtRowSubtotal." + classRowHide).css('display', "");
1435
+ };
1436
+ expandHideColSubtotal = function(h) {
1437
+ $(h.th).closest('table.pvtTable').find("tbody tr td[data-colnode=\"" + h.node + "\"], th[data-colnode=\"" + h.node + "\"]").removeClass(classColCollapsed + " " + classColShow).addClass(classColExpanded + " " + classColHide).css('display', "none");
1438
+ return h.th.style.display = "";
1439
+ };
1440
+ expandShowColSubtotal = function(h) {
1441
+ $(h.th).closest('table.pvtTable').find("tbody tr td[data-colnode=\"" + h.node + "\"], th[data-colnode=\"" + h.node + "\"]").removeClass(classColCollapsed + " " + classColHide).addClass(classColExpanded + " " + classColShow).not(".pvtRowSubtotal." + classRowHide).css('display', "");
1442
+ h.th.style.display = "";
1443
+ ++h.th.colSpan;
1444
+ if (h.sTh != null) {
1445
+ return h.sTh.style.display = "";
1446
+ }
1447
+ };
1448
+ expandChildCol = function(ch) {
1449
+ var gch, k, len, ref8, results;
1450
+ if (ch.descendants !== 0 && hasClass(ch.th, classColExpanded) && (isColHideOnExpand || isColDisable || ch.col > colDisableAfter)) {
1451
+ ch.th.style.display = "";
1452
+ } else {
1453
+ showChildCol(ch);
1454
+ }
1455
+ if (ch.clickStatus !== clickStatusCollapsed) {
1456
+ ref8 = ch.children;
1457
+ results = [];
1458
+ for (k = 0, len = ref8.length; k < len; k++) {
1459
+ gch = ref8[k];
1460
+ results.push(expandChildCol(gch));
1461
+ }
1462
+ return results;
1463
+ }
1464
+ };
1465
+ expandCol = function(colHeaderHeaders, colHeaderCols, c) {
1466
+ var ch, colspan, h, hh, isColSubtotal, k, len, p, ref8;
1467
+ if (isColDisable) {
1468
+ return;
1469
+ }
1470
+ if (isColDisableExpandCollapse) {
1471
+ return;
1472
+ }
1473
+ if (!colHeaderCols[c]) {
1474
+ return;
1475
+ }
1476
+ h = colHeaderCols[c];
1477
+ if (h.col > colDisableAfter) {
1478
+ return;
1479
+ }
1480
+ if (h.clickStatus === clickStatusExpanded) {
1481
+ return;
1482
+ }
1483
+ isColSubtotal = h.descendants !== 0;
1484
+ colspan = 0;
1485
+ ref8 = h.children;
1486
+ for (k = 0, len = ref8.length; k < len; k++) {
1487
+ ch = ref8[k];
1488
+ expandChildCol(ch);
1489
+ colspan += ch.th.colSpan;
1490
+ }
1491
+ h.th.colSpan = colspan;
1492
+ if (isColSubtotal) {
1493
+ replaceClass(h.th, classColCollapsed, classColExpanded);
1494
+ h.th.innerHTML = " " + arrowExpanded + " " + h.th.getAttribute("data-colHeader");
1495
+ if (isColHideOnExpand) {
1496
+ expandHideColSubtotal(h);
1497
+ --colspan;
1498
+ } else {
1499
+ expandShowColSubtotal(h);
1500
+ }
1501
+ }
1502
+ p = h.parent;
1503
+ while (p) {
1504
+ p.th.colSpan += colspan;
1505
+ p = p.parent;
1506
+ }
1507
+ h.clickStatus = clickStatusExpanded;
1508
+ hh = colHeaderHeaders[h.col];
1509
+ ++hh.expandedCount;
1510
+ if (hh.expandedCount === hh.nHeaders) {
1511
+ replaceClass(hh.th, classCollapsed, classExpanded);
1512
+ hh.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(hh.th.getAttribute("data-colAttr"));
1513
+ return hh.clickStatus = clickStatusExpanded;
1514
+ }
1515
+ };
1516
+ collapseHideDescendantRow = function(h) {
1517
+ var cell, cells, k, len, ref8, results, tagName;
1518
+ h.tr.style.display = "none";
1519
+ ref8 = ["td", "th"];
1520
+ results = [];
1521
+ for (k = 0, len = ref8.length; k < len; k++) {
1522
+ tagName = ref8[k];
1523
+ cells = h.tr.getElementsByTagName(tagName);
1524
+ results.push((function() {
1525
+ var l, len1, results1;
1526
+ results1 = [];
1527
+ for (l = 0, len1 = cells.length; l < len1; l++) {
1528
+ cell = cells[l];
1529
+ replaceClass(cell, classRowShow, classRowHide);
1530
+ results1.push(cell.style.display = "none");
1531
+ }
1532
+ return results1;
1533
+ })());
1534
+ }
1535
+ return results;
1536
+ };
1537
+ collapseShowRowSubtotal = function(h) {
1538
+ var cell, cells, k, l, len, len1, ref8, tagName;
1539
+ ref8 = ["td", "th"];
1540
+ for (k = 0, len = ref8.length; k < len; k++) {
1541
+ tagName = ref8[k];
1542
+ cells = h.tr.getElementsByTagName(tagName);
1543
+ for (l = 0, len1 = cells.length; l < len1; l++) {
1544
+ cell = cells[l];
1545
+ removeClass(cell, classRowExpanded + " " + classRowHide);
1546
+ addClass(cell, classRowCollapsed + " " + classRowShow);
1547
+ if (!hasClass(cell, classColHide)) {
1548
+ cell.style.display = "";
1549
+ }
1550
+ }
1551
+ }
1552
+ h.th.rowSpan = 1;
1553
+ h.th.innerHTML = " " + arrowCollapsed + " " + h.th.getAttribute("data-rowHeader");
1554
+ return replaceClass(h.tr, classRowExpanded, classRowCollapsed);
1555
+ };
1556
+ collapseRow = function(rowHeaderHeaders, rowHeaderRows, r) {
1557
+ var d, h, i, isRowSubtotal, j, k, l, p, ref10, ref8, ref9, results, rowHeaderHeader, rowspan;
1558
+ if (isRowDisable) {
1559
+ return;
1560
+ }
1561
+ if (isRowDisableExpandCollapse) {
1562
+ return;
1563
+ }
1564
+ if (!rowHeaderRows[r]) {
1565
+ return;
1566
+ }
1567
+ h = rowHeaderRows[r];
1568
+ if (h.col > rowDisableAfter) {
1569
+ return;
1570
+ }
1571
+ if (h.clickStatus === clickStatusCollapsed) {
1572
+ return;
1573
+ }
1574
+ isRowSubtotal = h.descendants !== 0;
1575
+ rowspan = h.th.rowSpan;
1576
+ for (i = k = 1, ref8 = h.descendants; 1 <= ref8 ? k <= ref8 : k >= ref8; i = 1 <= ref8 ? ++k : --k) {
1577
+ if (!(h.descendants !== 0)) {
1578
+ continue;
1579
+ }
1580
+ d = rowHeaderRows[r + i];
1581
+ collapseHideDescendantRow(d);
1582
+ }
1583
+ if (isRowSubtotal) {
1584
+ collapseShowRowSubtotal(h);
1585
+ --rowspan;
1586
+ }
1587
+
1588
+ removeRowHeaderNullValue(h);
1589
+
1590
+ p = h.parent;
1591
+ while (p) {
1592
+ p.th.rowSpan -= rowspan;
1593
+ p = p.parent;
1594
+ }
1595
+ h.clickStatus = clickStatusCollapsed;
1596
+ rowHeaderHeader = rowHeaderHeaders.hh[h.col];
1597
+ rowHeaderHeader.expandedCount--;
1598
+ if (rowHeaderHeader.expandedCount !== 0) {
1599
+ return;
1600
+ }
1601
+ results = [];
1602
+ for (j = l = ref9 = h.col, ref10 = rowHeaderHeaders.hh.length - 2; ref9 <= ref10 ? l <= ref10 : l >= ref10; j = ref9 <= ref10 ? ++l : --l) {
1603
+ if (!(j <= rowDisableAfter)) {
1604
+ continue;
1605
+ }
1606
+ rowHeaderHeader = rowHeaderHeaders.hh[j];
1607
+ replaceClass(rowHeaderHeader.th, classExpanded, classCollapsed);
1608
+ rowHeaderHeader.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(rowHeaderHeader.th.getAttribute("data-rowAttr"));
1609
+ results.push(rowHeaderHeader.clickStatuatus = clickStatusCollapsed);
1610
+ }
1611
+ return results;
1612
+ };
1613
+ showChildRow = function(h) {
1614
+ var cell, cells, k, l, len, len1, ref8, tagName;
1615
+ ref8 = ["td", "th"];
1616
+ for (k = 0, len = ref8.length; k < len; k++) {
1617
+ tagName = ref8[k];
1618
+ cells = h.tr.getElementsByTagName(tagName);
1619
+ for (l = 0, len1 = cells.length; l < len1; l++) {
1620
+ cell = cells[l];
1621
+ replaceClass(cell, classRowHide, classRowShow);
1622
+ if (!hasClass(cell, classColHide)) {
1623
+ cell.style.display = "";
1624
+ }
1625
+ }
1626
+ }
1627
+ return h.tr.style.display = "";
1628
+ };
1629
+ expandShowRowSubtotal = function(h) {
1630
+ var cell, cells, k, l, len, len1, ref8, tagName;
1631
+ ref8 = ["td", "th"];
1632
+ for (k = 0, len = ref8.length; k < len; k++) {
1633
+ tagName = ref8[k];
1634
+ cells = h.tr.getElementsByTagName(tagName);
1635
+ for (l = 0, len1 = cells.length; l < len1; l++) {
1636
+ cell = cells[l];
1637
+ removeClass(cell, classRowCollapsed + " " + classRowHide);
1638
+ addClass(cell, classRowExpanded + " " + classRowShow);
1639
+ if (!hasClass(cell, classColHide)) {
1640
+ cell.style.display = "";
1641
+ }
1642
+ }
1643
+ }
1644
+ h.th.innerHTML = " " + arrowExpanded + " " + h.th.getAttribute("data-rowHeader");
1645
+ return replaceClass(h.tr, classRowCollapsed, classRowExpanded);
1646
+ };
1647
+ expandHideRowSubtotal = function(h) {
1648
+ var cell, cells, k, l, len, len1, ref8, tagName;
1649
+ ref8 = ["td", "th"];
1650
+ for (k = 0, len = ref8.length; k < len; k++) {
1651
+ tagName = ref8[k];
1652
+ cells = h.tr.getElementsByTagName(tagName);
1653
+ for (l = 0, len1 = cells.length; l < len1; l++) {
1654
+ cell = cells[l];
1655
+ removeClass(cell, classRowCollapsed + " " + classRowShow);
1656
+ addClass(cell, classRowExpanded + " " + classRowHide);
1657
+ cell.style.display = "none";
1658
+ }
1659
+ }
1660
+ h.th.style.display = "";
1661
+ h.th.innerHTML = " " + arrowExpanded + " " + h.th.getAttribute("data-rowHeader");
1662
+ return replaceClass(h.tr, classRowCollapsed, classRowExpanded);
1663
+ };
1664
+ expandChildRow = function(ch) {
1665
+ var gch, k, len, ref8, results;
1666
+ if (ch.descendants !== 0 && hasClass(ch.th, classRowExpanded) && (isRowHideOnExpand || isRowDisable || ch.col > rowDisableAfter)) {
1667
+ ch.tr.style.display = "";
1668
+ ch.th.style.display = "";
1669
+ } else {
1670
+ showChildRow(ch);
1671
+ }
1672
+ if (ch.clickStatus !== clickStatusCollapsed) {
1673
+ ref8 = ch.children;
1674
+ results = [];
1675
+ for (k = 0, len = ref8.length; k < len; k++) {
1676
+ gch = ref8[k];
1677
+ results.push(expandChildRow(gch));
1678
+ }
1679
+ return results;
1680
+ }
1681
+ };
1682
+ expandRow = function(rowHeaderHeaders, rowHeaderRows, r) {
1683
+ var ch, h, hh, isRowSubtotal, k, len, p, ref8, rowspan;
1684
+ if (isRowDisable) {
1685
+ return;
1686
+ }
1687
+ if (isRowDisableExpandCollapse) {
1688
+ return;
1689
+ }
1690
+ if (!rowHeaderRows[r]) {
1691
+ return;
1692
+ }
1693
+ h = rowHeaderRows[r];
1694
+ if (h.col > rowDisableAfter) {
1695
+ return;
1696
+ }
1697
+ if (h.clickStatus === clickStatusExpanded) {
1698
+ return;
1699
+ }
1700
+ isRowSubtotal = h.descendants !== 0;
1701
+ rowspan = 0;
1702
+ ref8 = h.children;
1703
+ for (k = 0, len = ref8.length; k < len; k++) {
1704
+ ch = ref8[k];
1705
+ expandChildRow(ch);
1706
+ rowspan += ch.th.rowSpan;
1707
+ }
1708
+ h.th.rowSpan = rowspan + 1;
1709
+ if (isRowSubtotal) {
1710
+ if (isRowHideOnExpand) {
1711
+ expandHideRowSubtotal(h);
1712
+ } else {
1713
+ expandShowRowSubtotal(h);
1714
+ }
1715
+ }
1716
+
1717
+ removeRowHeaderNullValue(h);
1718
+
1719
+ p = h.parent;
1720
+ while (p) {
1721
+ p.th.rowSpan += rowspan;
1722
+ p = p.parent;
1723
+ }
1724
+ h.clickStatus = clickStatusExpanded;
1725
+ hh = rowHeaderHeaders.hh[h.col];
1726
+ ++hh.expandedCount;
1727
+ if (hh.expandedCount === hh.nHeaders) {
1728
+ replaceClass(hh.th, classCollapsed, classExpanded);
1729
+ hh.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(hh.th.getAttribute("data-rowAttr"));
1730
+ return hh.clickStatus = clickStatusExpanded;
1731
+ }
1732
+ };
1733
+ toggleCol = function(colHeaderHeaders, colHeaderCols, c) {
1734
+ var h, allClass, mainClass, is_other, main_th;
1735
+ if (colHeaderCols[c] == null) {
1736
+ return;
1737
+ }
1738
+ h = colHeaderCols[c];
1739
+ if (h.clickStatus === clickStatusCollapsed) {
1740
+ allClass = classColCollapsed;
1741
+ mainClass = classCollapsed;
1742
+ expandCol(colHeaderHeaders, colHeaderCols, c);
1743
+ } else {
1744
+ collapseCol(colHeaderHeaders, colHeaderCols, c);
1745
+ mainClass = classExpanded;
1746
+ allClass = classColExpanded;
1747
+ }
1748
+
1749
+ is_other = $('.pvtColLabel.'+allClass,h.tr).not('.pvtColSubtotal').length;
1750
+ if(is_other == 0){
1751
+ $('.pvtAxisLabel.'+mainClass,h.tr).trigger( "click" );
1752
+ }
1753
+
1754
+ return h.th.scrollIntoView;
1755
+ };
1756
+ toggleRow = function(rowHeaderHeaders, rowHeaderRows, r) {
1757
+ var h, allClass, mainClass, is_other, main_th, hh;
1758
+
1759
+ if (rowHeaderRows[r] == null) {
1760
+ return;
1761
+ }
1762
+
1763
+ h = rowHeaderRows[r];
1764
+
1765
+ if (rowHeaderRows[r].clickStatus === clickStatusCollapsed) {
1766
+ expandRow(rowHeaderHeaders, rowHeaderRows, r);
1767
+ allClass = clickStatusCollapsed;
1768
+ mainClass = classCollapsed;
1769
+ } else {
1770
+ collapseRow(rowHeaderHeaders, rowHeaderRows, r);
1771
+ allClass = clickStatusExpanded;
1772
+ mainClass = classExpanded;
1773
+
1774
+ /*is_other = _.find(rowHeaderRows, {col:h.col, clickStatus:allClass});
1775
+ if(!is_other){
1776
+ hh = rowHeaderHeaders.hh[h.col];
1777
+ if(hh && hh.th && $(hh.th).hasClass(mainClass)){
1778
+ $(hh.th).trigger('click');
1779
+ }
1780
+ }*/
1781
+ }
1782
+
1783
+ return h.th.scrollIntoView;
1784
+ };
1785
+ collapseColsAt = function(colHeaderHeaders, colHeaderCols, colAttrs, colAttr) {
1786
+ var h, hh, i, idx, nAttrs, nCols, results;
1787
+ if (isColDisable) {
1788
+ return;
1789
+ }
1790
+ if (typeof colAttr === 'string') {
1791
+ idx = colAttrs.indexOf(colAttr);
1792
+ } else {
1793
+ idx = colAttr;
1794
+ }
1795
+ if (idx < 0 || idx === colAttrs.length - 1) {
1796
+ return;
1797
+ }
1798
+ i = idx;
1799
+ nAttrs = colAttrs.length - 1;
1800
+ while (i < nAttrs && i <= colDisableAfter) {
1801
+ hh = colHeaderHeaders[i];
1802
+ replaceClass(hh.th, classExpanded, classCollapsed);
1803
+ hh.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(colAttrs[i]);
1804
+ hh.clickStatus = clickStatusCollapsed;
1805
+ ++i;
1806
+ }
1807
+ i = 0;
1808
+ nCols = colHeaderCols.length;
1809
+ results = [];
1810
+ while (i < nCols) {
1811
+ h = colHeaderCols[i];
1812
+ if (h.col === idx && h.clickStatus !== clickStatusCollapsed && h.th.style.display !== "none") {
1813
+ collapseCol(colHeaderHeaders, colHeaderCols, parseInt(h.th.getAttribute("data-colnode")));
1814
+ }
1815
+ results.push(++i);
1816
+ }
1817
+ return results;
1818
+ };
1819
+ expandColsAt = function(colHeaderHeaders, colHeaderCols, colAttrs, colAttr) {
1820
+ var colHeaderHeader, h, hh, i, idx, j, k, nCols, ref8, results;
1821
+ if (isColDisable) {
1822
+ return;
1823
+ }
1824
+ if (typeof colAttr === 'string') {
1825
+ idx = colAttrs.indexOf(colAttr);
1826
+ } else {
1827
+ idx = colAttr;
1828
+ }
1829
+ if (idx < 0 || idx === colAttrs.length - 1) {
1830
+ return;
1831
+ }
1832
+ for (i = k = 0, ref8 = idx; 0 <= ref8 ? k <= ref8 : k >= ref8; i = 0 <= ref8 ? ++k : --k) {
1833
+ if (i <= colDisableAfter) {
1834
+ hh = colHeaderHeaders[i];
1835
+ replaceClass(hh.th, classCollapsed, classExpanded);
1836
+ hh.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(colAttrs[i]);
1837
+ hh.clickStatus = clickStatusExpanded;
1838
+ }
1839
+ j = 0;
1840
+ nCols = colHeaderCols.length;
1841
+ while (j < nCols) {
1842
+ h = colHeaderCols[j];
1843
+ if (h.col === i) {
1844
+ expandCol(colHeaderHeaders, colHeaderCols, j);
1845
+ }
1846
+ ++j;
1847
+ }
1848
+ }
1849
+ ++idx;
1850
+ results = [];
1851
+ while (idx < colAttrs.length - 1 && idx <= colDisableAfter) {
1852
+ colHeaderHeader = colHeaderHeaders[idx];
1853
+ if (colHeaderHeader.expandedCount === 0) {
1854
+ replaceClass(colHeaderHeader.th, classExpanded, classCollapsed);
1855
+ colHeaderHeader.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(colAttrs[idx]);
1856
+ colHeaderHeader.clickStatus = clickStatusCollapsed;
1857
+ } else if (colHeaderHeader.expandedCount === colHeaderHeader.nHeaders) {
1858
+ replaceClass(colHeaderHeader.th, classCollapsed, classExpanded);
1859
+ colHeaderHeader.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(colAttrs[idx]);
1860
+ colHeaderHeader.clickStatus = clickStatusExpanded;
1861
+ }
1862
+ results.push(++idx);
1863
+ }
1864
+ return results;
1865
+ };
1866
+ collapseRowsAt = function(rowHeaderHeaders, rowHeaderRows, rowAttrs, rowAttr) {
1867
+ var h, i, idx, j, nAttrs, nRows, results;
1868
+ if (isRowDisable) {
1869
+ return;
1870
+ }
1871
+ if (typeof rowAttr === 'string') {
1872
+ idx = rowAttrs.indexOf(rowAttr);
1873
+ } else {
1874
+ idx = rowAttr;
1875
+ }
1876
+ if (idx < 0 || idx === rowAttrs.length - 1) {
1877
+ return;
1878
+ }
1879
+ i = idx;
1880
+ nAttrs = rowAttrs.length - 1;
1881
+ while (i < nAttrs && i <= rowDisableAfter) {
1882
+ h = rowHeaderHeaders.hh[i];
1883
+ replaceClass(h.th, classExpanded, classCollapsed);
1884
+ h.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(rowAttrs[i]);
1885
+ h.clickStatus = clickStatusCollapsed;
1886
+ ++i;
1887
+ }
1888
+ j = 0;
1889
+ nRows = rowHeaderRows.length;
1890
+ results = [];
1891
+ while (j < nRows) {
1892
+ h = rowHeaderRows[j];
1893
+ if (h.col === idx && h.clickStatus !== clickStatusCollapsed && h.tr.style.display !== "none") {
1894
+ collapseRow(rowHeaderHeaders, rowHeaderRows, j);
1895
+ results.push(j = j + h.descendants + 1);
1896
+ } else {
1897
+ results.push(++j);
1898
+ }
1899
+ }
1900
+ return results;
1901
+ };
1902
+ expandRowsAt = function(rowHeaderHeaders, rowHeaderRows, rowAttrs, rowAttr) {
1903
+ var h, hh, i, idx, j, k, nRows, ref8, results, rowHeaderHeader;
1904
+ if (isRowDisable) {
1905
+ return;
1906
+ }
1907
+ if (typeof rowAttr === 'string') {
1908
+ idx = rowAttrs.indexOf(rowAttr);
1909
+ } else {
1910
+ idx = rowAttr;
1911
+ }
1912
+ if (idx < 0 || idx === rowAttrs.length - 1) {
1913
+ return;
1914
+ }
1915
+ for (i = k = 0, ref8 = idx; 0 <= ref8 ? k <= ref8 : k >= ref8; i = 0 <= ref8 ? ++k : --k) {
1916
+ if (i <= rowDisableAfter) {
1917
+ hh = rowHeaderHeaders.hh[i];
1918
+ replaceClass(hh.th, classCollapsed, classExpanded);
1919
+ hh.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(rowAttrs[i]);
1920
+ hh.clickStatus = clickStatusExpanded;
1921
+ }
1922
+ j = 0;
1923
+ nRows = rowHeaderRows.length;
1924
+ while (j < nRows) {
1925
+ h = rowHeaderRows[j];
1926
+ if (h.col === i) {
1927
+ expandRow(rowHeaderHeaders, rowHeaderRows, j);
1928
+ j += h.descendants + 1;
1929
+ } else {
1930
+ ++j;
1931
+ }
1932
+ }
1933
+ }
1934
+ ++idx;
1935
+ results = [];
1936
+ while (idx < rowAttrs.length - 1 && idx <= rowDisableAfter) {
1937
+ rowHeaderHeader = rowHeaderHeaders.hh[idx];
1938
+ if (rowHeaderHeader.expandedCount === 0) {
1939
+ replaceClass(rowHeaderHeader.th, classExpanded, classCollapsed);
1940
+ rowHeaderHeader.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(rowAttrs[idx]);
1941
+ rowHeaderHeader.clickStatus = clickStatusCollapsed;
1942
+ } else if (rowHeaderHeader.expandedCount === rowHeaderHeader.nHeaders) {
1943
+ replaceClass(rowHeaderHeader.th, classCollapsed, classExpanded);
1944
+ rowHeaderHeader.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(rowAttrs[idx]);
1945
+ rowHeaderHeader.clickStatus = clickStatusExpanded;
1946
+ }
1947
+ results.push(++idx);
1948
+ }
1949
+ return results;
1950
+ };
1951
+ toggleColHeaderHeader = function(colHeaderHeaders, colHeaderCols, colAttrs, colAttr) {
1952
+ var h, idx;
1953
+ if (isColDisable) {
1954
+ return;
1955
+ }
1956
+ if (isColDisableExpandCollapse) {
1957
+ return;
1958
+ }
1959
+ idx = colAttrs.indexOf(colAttr);
1960
+ h = colHeaderHeaders[idx];
1961
+ if (h.col > colDisableAfter) {
1962
+ return;
1963
+ }
1964
+ if (h.clickStatus === clickStatusCollapsed) {
1965
+ h.clickStatus = clickStatusExpanded;
1966
+ h.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(colAttr);
1967
+ replaceClass(h.th, classCollapsed, classExpanded);
1968
+ return expandColsAt(colHeaderHeaders, colHeaderCols, colAttrs, colAttr);
1969
+ } else {
1970
+ h.clickStatus = clickStatusCollapsed;
1971
+ h.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(colAttr);
1972
+ replaceClass(h.th, classExpanded, classCollapsed);
1973
+ return collapseColsAt(colHeaderHeaders, colHeaderCols, colAttrs, colAttr);
1974
+ }
1975
+ };
1976
+ toggleRowHeaderHeader = function(rowHeaderHeaders, rowHeaderRows, rowAttrs, rowAttr) {
1977
+ var idx, th;
1978
+ if (isRowDisable) {
1979
+ return;
1980
+ }
1981
+ if (isRowDisableExpandCollapse) {
1982
+ return;
1983
+ }
1984
+ idx = rowAttrs.indexOf(rowAttr);
1985
+ th = rowHeaderHeaders.hh[idx];
1986
+ if (th.col > rowDisableAfter) {
1987
+ return;
1988
+ }
1989
+ if (th.clickStatus === clickStatusCollapsed) {
1990
+ th.clickStatus = clickStatusExpanded;
1991
+ th.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(rowAttr);
1992
+ replaceClass(th.th, classCollapsed, classExpanded);
1993
+ return expandRowsAt(rowHeaderHeaders, rowHeaderRows, rowAttrs, rowAttr);
1994
+ } else {
1995
+ th.clickStatus = clickStatusCollapsed;
1996
+ th.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(rowAttr);
1997
+ replaceClass(th.th, classExpanded, classCollapsed);
1998
+ return collapseRowsAt(rowHeaderHeaders, rowHeaderRows, rowAttrs, rowAttr);
1999
+ }
2000
+ };
2001
+
2002
+ handleFreezePanesScroll = function(freezableElements) {
2003
+ return function(event) {
2004
+ const wrapper = event.target;
2005
+
2006
+ const translateY = `translate(0px, ${wrapper.scrollTop}px)`;
2007
+ const translateX = `translate(${wrapper.scrollLeft}px, 0px)`;
2008
+ const translateXY = `translate(${wrapper.scrollLeft}px, ${wrapper.scrollTop}px)`;
2009
+
2010
+ _.forEach(freezableElements, function (element) {
2011
+ let currentTranslate = translateY;
2012
+ currentTranslate = element.className.includes(elementToTransform.X) ? translateX : currentTranslate;
2013
+ currentTranslate = element.className.includes(elementToTransform.XY) ? translateXY : currentTranslate;
2014
+ element.style.transform = currentTranslate;
2015
+ });
2016
+ }
2017
+ };
2018
+
2019
+ selectFreezableElements = function(wrapper) {
2020
+ const selectString =_.map(Object.values(elementToTransform), function (item) {
2021
+ return `.${item.replace(' ', '')}`;
2022
+ }).join(',');
2023
+ return Array.from(wrapper.querySelectorAll(selectString));
2024
+ }
2025
+
2026
+ main = function(rowAttrs, rowKeys, colAttrs, colKeys) {
2027
+ var c,rowspan, colHeaderCols, colHeaderHeaders, colHeaders, h, k, l, len, len1, result, rowHeaderHeaders, rowHeaderRows, rowHeaders, tbody, thead, tr;
2028
+ rowHeaders = [];
2029
+ colHeaders = [];
2030
+ rowHeaderHeaders = {};
2031
+ rowHeaderRows = [];
2032
+ colHeaderHeaders = [];
2033
+ colHeaderCols = [];
2034
+ if (rowAttrs.length > 0 && rowKeys.length > 0) {
2035
+ rowHeaders = processKeys(rowKeys, "pvtRowLabel", 'rows', rowAttrs);
2036
+ }
2037
+ if (colAttrs.length > 0 && colKeys.length > 0) {
2038
+ colHeaders = processKeys(colKeys, "pvtColLabel", 'cols', colAttrs);
2039
+ }
2040
+ var tableClasses = useNewUx && opts.chartOptions.table_options.use_new_table_design ? 'pvtTable newPvtTable' : 'pvtTable';
2041
+ result = createElement("table", tableClasses , null, {
2042
+ style: "display: none;"
2043
+ });
2044
+
2045
+ colorizeTableIfNeed(result);
2046
+
2047
+ thead = createElement("thead");
2048
+ result.appendChild(thead);
2049
+ if (colAttrs.length > 0) {
2050
+ buildColHeaderHeaders(thead, colHeaderHeaders, rowAttrs, colAttrs);
2051
+ for (k = 0, len = colHeaders.length; k < len; k++) {
2052
+ h = colHeaders[k];
2053
+ buildColHeaders(colHeaderHeaders, colHeaderCols, h, rowAttrs, colAttrs);
2054
+ }
2055
+ buildColHeaderHeadersClickEvents(colHeaderHeaders, colHeaderCols, colAttrs);
2056
+ }
2057
+ if (rowAttrs.length > 0) {
2058
+ buildRowHeaderHeaders(thead, rowHeaderHeaders, rowAttrs, colAttrs);
2059
+ if (colAttrs.length === 0 && opts.chartOptions.table_options.show_row_total) {
2060
+ buildRowTotalsHeader(rowHeaderHeaders.tr, rowAttrs, colAttrs);
2061
+ }
2062
+ }
2063
+ if (colAttrs.length > 0 && opts.chartOptions.table_options.show_row_total) {
2064
+ buildRowTotalsHeader(colHeaderHeaders[0].tr, rowAttrs, colAttrs);
2065
+ if(opts.chartOptions.table_options.colorize_headers == true){
2066
+ for (c=1; c<colHeaderHeaders.length; c++){
2067
+ rowspan = 1;
2068
+ if(c == colHeaderHeaders.length-1){
2069
+ rowspan = 2;
2070
+ }
2071
+ colHeaderHeaders[c].tr.appendChild(createElement("th", verticalFreezePaneClass, "",{rowspan: rowspan}));
2072
+ if (opts.chartOptions.table_options.freeze_panes) {
2073
+ getHeaderColorProperties(colHeaderHeaders[c].tr, c);
2074
+ }
2075
+ }
2076
+ }
2077
+ }
2078
+ tbody = createElement("tbody");
2079
+ result.appendChild(tbody);
2080
+
2081
+ const hasColLabels = !!thead.querySelector('.pvtColLabel');
2082
+
2083
+ if (rowAttrs.length > 0) {
2084
+ for (l = 0, len1 = rowHeaders.length; l < len1; l++) {
2085
+ h = rowHeaders[l];
2086
+ buildRowHeaders(tbody, rowHeaderHeaders, rowHeaderRows, h, rowAttrs, colAttrs, l%2 === 0, hasColLabels);
2087
+ }
2088
+ }
2089
+ buildRowHeaderHeadersClickEvents(rowHeaderHeaders, rowHeaderRows, rowAttrs);
2090
+ buildValues(rowHeaderRows, colHeaderCols, rowAttrs, colAttrs);
2091
+ if(opts.chartOptions.table_options.show_column_total){
2092
+ tr = buildColTotalsHeader(rowAttrs, colAttrs);
2093
+ if (colAttrs.length > 0) {
2094
+ buildColTotals(tr, colHeaderCols, rowAttrs, colAttrs);
2095
+ }
2096
+ if(opts.chartOptions.table_options.show_row_total)
2097
+ buildGrandTotal(tbody, tr, rowAttrs, colAttrs);
2098
+ else
2099
+ tbody.appendChild(tr);
2100
+ }
2101
+
2102
+ result.setAttribute("data-numrows", rowKeys.length);
2103
+ result.setAttribute("data-numcols", colKeys.length);
2104
+ if ((opts.collapseRowsAt == null) && (opts.collapseColsAt == null)) {
2105
+ result.style.display = "";
2106
+ }
2107
+ if (opts.collapseRowsAt != null) {
2108
+ collapseRowsAt(rowHeaderHeaders, rowHeaderRows, rowAttrs, opts.collapseRowsAt);
2109
+ }
2110
+ if (opts.collapseColsAt != null) {
2111
+ collapseColsAt(colHeaderHeaders, colHeaderCols, colAttrs, opts.collapseColsAt);
2112
+ }
2113
+ result.style.display = "";
2114
+
2115
+ var resultsArr = [];
2116
+ var additionOptions = opts.chartOptions ? opts.chartOptions : null;
2117
+
2118
+ if (opts && opts.chart_title && !opts.chartOptions.hideChartHeader) {
2119
+ var title = document.createElement("div");
2120
+ title.className = "title";
2121
+ title.innerText = opts.chart_title;
2122
+ resultsArr.push(title);
2123
+ }
2124
+
2125
+ if (additionOptions && additionOptions.subtitle && !opts.chartOptions.hideChartHeader) {
2126
+ var subTitle = document.createElement("div");
2127
+ subTitle.className = "sub-title";
2128
+ subTitle.innerText = additionOptions.subtitle.subtitle;
2129
+ resultsArr.push(subTitle);
2130
+ }
2131
+
2132
+ if (tooMuch) {
2133
+ resultsArr.push($('<div class="noData"><i class="fa fa-info"></i> There are too many rows to display in the table.<br>Please filter or change the table type in options.</div>'));
2134
+ } else {
2135
+ var tableContainer = document.createElement("div");
2136
+ tableContainer.className = "pivot-div";
2137
+ tableContainer.appendChild(result);
2138
+ if (opts.chartOptions.table_options.freeze_panes) {
2139
+ tableContainer.onscroll = handleFreezePanesScroll(selectFreezableElements(tableContainer));
2140
+ }
2141
+ resultsArr.push(tableContainer);
2142
+ }
2143
+
2144
+ var wrapper = document.createElement("div");
2145
+ wrapper.className = "pivot-wrapper";
2146
+
2147
+ $(wrapper).append(resultsArr);
2148
+
2149
+ return wrapper;
2150
+ };
2151
+ return main(rowAttrs, rowKeys, colAttrs, colKeys);
2152
+ };
2153
+ // $.pivotUtilities.subtotal_renderers = SubtotalRenderer;
2154
+ $.pivotUtilities.subtotal_renderers = NovixRenderer;
2155
+ $.pivotUtilities.delim = delim;
2156
+
2157
+ $.pivotUtilities.getFormattedNumber = getFormattedNumber;
2158
+ $.pivotUtilities.sortDateStrings = sortDateStrings;
2159
+ $.pivotUtilities.largeToSmallSort = largeToSmallSort;
2160
+ $.pivotUtilities.getPivotDataModel = function(input, opts){ return new DRPivotData(input, opts); }
2161
+ $.pivotUtilities.getPivotTableFormula = function(rowData, opts, func, colFields, rowFields, aggregationDefaults, utils) {
2162
+ let totalStr = 'Grand Totals';
2163
+ let pivotData = new DRPivotData(rowData, opts);
2164
+ let rowAttrs = pivotData.rowAttrs;
2165
+ let rowKeys = pivotData.getRowKeys();
2166
+ let colAttrs = pivotData.colAttrs;
2167
+ let colKeys = pivotData.getColKeys();
2168
+
2169
+ if ((rowKeys.length || 1) * (colKeys.length || 1) > 10000) {
2170
+ throw new Error(`Can't create table formula. The table has many rows or columns`);
2171
+ }
2172
+
2173
+ let rowValuesIndex = colAttrs.length;
2174
+ let colValuesIndex = rowAttrs.length;
2175
+ let matrix = [];
2176
+ let colFormulas = [];
2177
+ let rowFormulas = [];
2178
+ let aggregation = utils.getAggregationConfigFromFields(func, colFields, rowFields, aggregationDefaults);
2179
+
2180
+ // Create headers
2181
+ if (rowAttrs && rowAttrs.length && colAttrs && colAttrs.length) {
2182
+ colValuesIndex += 1;
2183
+ rowValuesIndex += 1;
2184
+
2185
+ // Free place in formulas arrays
2186
+ colFormulas = new Array(colValuesIndex).fill(null);
2187
+ rowFormulas = new Array(rowValuesIndex).fill(null);
2188
+
2189
+ for (let i = 0; i < colAttrs.length; i++) {
2190
+ // Free place in row start
2191
+ let headerRow = new Array(rowAttrs.length).fill(null);
2192
+ // Add col field name
2193
+ headerRow.push(colAttrs[i]);
2194
+ // Add row keys
2195
+ _.forEach(colKeys, function (keys) {
2196
+ headerRow.push(utils.getHeaderValue(keys[i], colFields[i].type));
2197
+ // Calc formulas in first time
2198
+ if (i === 0) {
2199
+ colFormulas.push(utils.createKeysFormula(colFields, keys, colFormulas.length + 1, true));
2200
+ }
2201
+ });
2202
+
2203
+ // Add row to matrix
2204
+ matrix.push(headerRow);
2205
+ }
2206
+
2207
+ // Add row fields + free space under cols + Grand Totals right
2208
+ matrix.push(rowAttrs.concat(new Array(colKeys.length + 1).fill(null)).concat(totalStr));
2209
+ // Row Headers
2210
+ for (let i = 0; i < rowKeys.length; i++) {
2211
+ // Formatting row keys
2212
+ let keysFormatted = [];
2213
+ for (let k = 0; k < rowKeys[i].length; k++) {
2214
+ keysFormatted.push(utils.getHeaderValue(rowKeys[i][k], rowFields[k].type))
2215
+ }
2216
+ // Add row keys
2217
+ matrix.push(keysFormatted.concat(null));
2218
+ // Calc formulas
2219
+ rowFormulas.push(utils.createKeysFormula(rowFields, rowKeys[i], rowFormulas.length + 1));
2220
+ }
2221
+ // Add Grand Totals bottom
2222
+ matrix.push(new Array(rowAttrs.length).fill(null).concat(totalStr));
2223
+
2224
+ // Fill values
2225
+ for (let y = rowValuesIndex; y < matrix.length; y++) {
2226
+ for (let x = colValuesIndex; x < matrix[rowValuesIndex - 1].length; x++) {
2227
+ matrix[y][x] = utils.createCellFormula(func, colFormulas[x], rowFormulas[y], aggregation);
2228
+ }
2229
+ }
2230
+ } else if (colAttrs && colAttrs.length) {
2231
+ colFormulas = new Array(null);
2232
+
2233
+ for (let i = 0; i < colAttrs.length; i++) {
2234
+ // Add col field name
2235
+ let headerRow = [colAttrs[i]];
2236
+ // Add keys
2237
+ _.forEach(colKeys, function (keys) {
2238
+ headerRow.push(utils.getHeaderValue(keys[i], colFields[i].type));
2239
+ // Calc formulas in first time
2240
+ if (i === 0) {
2241
+ colFormulas.push(utils.createKeysFormula(colFields, keys, colFormulas.length + 1, true));
2242
+ }
2243
+ });
2244
+
2245
+ // Add row to matrix
2246
+ matrix.push(headerRow);
2247
+ }
2248
+
2249
+ // Add Grand Totals right
2250
+ matrix[matrix.length - 1].push(totalStr);
2251
+ // Add Grand Totals bottom
2252
+ matrix.push([totalStr]);
2253
+
2254
+ // Fill totals
2255
+ for (let x = 1; x < matrix[matrix.length - 2].length; x++) {
2256
+ matrix[matrix.length - 1][x] = utils.createCellFormula(func, colFormulas[x], '', aggregation);
2257
+ }
2258
+ } else if (rowAttrs && rowAttrs.length) {
2259
+ rowFormulas = new Array(null);
2260
+
2261
+ // Add row fields + Grand Totals right
2262
+ matrix.push(rowAttrs.concat(totalStr));
2263
+ // Row Headers
2264
+ for (let i = 0; i < rowKeys.length; i++) {
2265
+ // Formatting row keys
2266
+ let keysFormatted = [];
2267
+ for (let k = 0; k < rowKeys[i].length; k++) {
2268
+ keysFormatted.push(utils.getHeaderValue(rowKeys[i][k], rowFields[k].type))
2269
+ }
2270
+ // Add row keys
2271
+ matrix.push(keysFormatted);
2272
+ // Calc formulas
2273
+ rowFormulas.push(utils.createKeysFormula(rowFields, rowKeys[i], rowFormulas.length + 1));
2274
+ }
2275
+ // Add Grand Totals bottom
2276
+ matrix.push(new Array(rowAttrs.length - 1).fill(null).concat(totalStr));
2277
+
2278
+ // Fill totals
2279
+ for (let y = 1; y < matrix.length; y++) {
2280
+ matrix[y][rowAttrs.length] = utils.createCellFormula(func, '', rowFormulas[y], aggregation);
2281
+ }
2282
+ } else {
2283
+ matrix = [[totalStr, utils.createCellFormula(func, '', '', aggregation)]];
2284
+ }
2285
+
2286
+ return matrix;
2287
+ };
2288
+ };
2289
+
2290
+ module.exports = initDRPivotTable;