@datarailsshared/dr_renderer 1.2.43 → 1.2.44-beta

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,2347 @@
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
+ let newProcessKey = function (record, totals, keys, attrs, getAggregator) {
137
+ var addKey, attr, flatKey, k, key, len, ref;
138
+ key = [];
139
+ addKey = false;
140
+ for (k = 0, len = attrs.length; k < len; k++) {
141
+ attr = attrs[k];
142
+ if (record.hasOwnProperty(attr)) {
143
+ key.push((ref = record[attr]));
144
+ flatKey = key.join(delim);
145
+ }
146
+ if (totals[flatKey] && totals[flatKey].isChangeable) {
147
+ continue;
148
+ }
149
+ if (!flatKey) return [];
150
+ if (!totals[flatKey]) {
151
+ totals[flatKey] = getAggregator(key.slice());
152
+ addKey = true;
153
+ } else {
154
+ totals[flatKey] = getAggregator(key.slice());
155
+ totals[flatKey].push(record);
156
+ }
157
+ }
158
+ if (addKey) {
159
+ keys.push(key);
160
+ }
161
+ return key;
162
+ };
163
+
164
+ DRPivotData.prototype.processRecord = function(record, isUserHasPermission) {
165
+ var colKey, fColKey, fRowKey, flatColKey, flatRowKey, i, j, k, m, n, ref, results, rowKey;
166
+ rowKey = [];
167
+ colKey = [];
168
+ if (isUserHasPermission) {
169
+ rowKey = newProcessKey(record, this.rowTotals, this.rowKeys, this.rowAttrs, (function(_this) {
170
+ return function(key) {
171
+ return _this.aggregator(_this, key, []);
172
+ };
173
+ })(this));
174
+ colKey = newProcessKey(record, this.colTotals, this.colKeys, this.colAttrs, (function(_this) {
175
+ return function(key) {
176
+ return _this.aggregator(_this, [], key);
177
+ };
178
+ })(this));
179
+
180
+ if (!colKey.length && !rowKey.length) {
181
+ this.allTotal.push(record);
182
+ }
183
+ if (!colKey.length && rowKey.length === 1) {
184
+ this.rowTotals[rowKey[0]].push(record);
185
+ this.rowTotals[rowKey[0]].isChangeable = true;
186
+ }
187
+ if (!rowKey.length && colKey.length === 1) {
188
+ this.colTotals[colKey[0]].push(record);
189
+ this.colTotals[colKey[0]].isChangeable = true;
190
+ }
191
+ } else {
192
+ this.allTotal.push(record);
193
+ rowKey = processKey(record, this.rowTotals, this.rowKeys, this.rowAttrs, (function(_this) {
194
+ return function(key) {
195
+ return _this.aggregator(_this, key, []);
196
+ };
197
+ })(this));
198
+ colKey = processKey(record, this.colTotals, this.colKeys, this.colAttrs, (function(_this) {
199
+ return function(key) {
200
+ return _this.aggregator(_this, [], key);
201
+ };
202
+ })(this));
203
+ }
204
+
205
+ m = rowKey.length - 1;
206
+ n = colKey.length - 1;
207
+ if (m < 0 || n < 0) {
208
+ return;
209
+ }
210
+ results = [];
211
+ for (i = k = 0, ref = m; 0 <= ref ? k <= ref : k >= ref; i = 0 <= ref ? ++k : --k) {
212
+ fRowKey = rowKey.slice(0, i + 1);
213
+ flatRowKey = fRowKey.join(delim);
214
+ if (!this.tree[flatRowKey]) {
215
+ this.tree[flatRowKey] = {};
216
+ }
217
+ results.push((function() {
218
+ var l, ref1, results1;
219
+ results1 = [];
220
+ for (j = l = 0, ref1 = n; 0 <= ref1 ? l <= ref1 : l >= ref1; j = 0 <= ref1 ? ++l : --l) {
221
+ fColKey = colKey.slice(0, j + 1);
222
+ flatColKey = fColKey.join(delim);
223
+ if (!this.tree[flatRowKey][flatColKey]) {
224
+ this.tree[flatRowKey][flatColKey] = this.aggregator(this, fRowKey, fColKey);
225
+ }
226
+ results1.push(this.tree[flatRowKey][flatColKey].push(record));
227
+ }
228
+ return results1;
229
+ }).call(this));
230
+ }
231
+ return results;
232
+ };
233
+
234
+ DRPivotData.prototype.getAggregator = function(rowKey, colKey) {
235
+ var agg, flatColKey, flatRowKey;
236
+ flatRowKey = rowKey.join(delim);
237
+ flatColKey = colKey.join(delim);
238
+ if (rowKey.length === 0 && colKey.length === 0) {
239
+ agg = this.allTotal;
240
+ } else if (rowKey.length === 0) {
241
+ agg = this.colTotals[flatColKey];
242
+ } else if (colKey.length === 0) {
243
+ agg = this.rowTotals[flatRowKey];
244
+ } else {
245
+ agg = this.tree[flatRowKey][flatColKey];
246
+ }
247
+ return agg != null ? agg : {
248
+ value: (function() {
249
+ return null;
250
+ }),
251
+ format: function() {
252
+ return "";
253
+ }
254
+ };
255
+ };
256
+
257
+ return DRPivotData;
258
+
259
+ })($.pivotUtilities.PivotData);
260
+
261
+ sortDateStrings = function(month_order) {
262
+ var i, mapping, x;
263
+ mapping = {};
264
+ var order = [
265
+ {"month":"jan", "versions": ['january', 'jan', 'ja'], weight:1},
266
+ {"month":"feb", "versions": ['february', 'feb', 'fe'], weight:2},
267
+ {"month":"mar", "versions": ['march', 'mar', 'mr'], weight:3},
268
+ {"month":"apr", "versions": ['april', 'apr', 'ap','al'], weight:4},
269
+ {"month":"may", "versions": ['may', 'ma'], weight:5},
270
+ {"month":"jun", "versions": ['june', 'jun','jn'], weight:6},
271
+ {"month":"jul", "versions": ['july', 'jul','jl'], weight:7},
272
+ {"month":"aug", "versions": ['august', 'aug', 'au'], weight:8},
273
+ {"month":"sep", "versions": ['september', 'sept', 'sep','sp','se'], weight:9},
274
+ {"month":"oct", "versions": ['october','oct', 'oc'], weight:10},
275
+ {"month":"nov", "versions": ['november', 'nov', 'no'], weight:11},
276
+ {"month":"dec", "versions": ['december', 'dec', 'de'], weight:12}
277
+ ];
278
+ 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
279
+ if(month_order){
280
+ for(i=0; i<month_order.length; i++){
281
+ var find_row = _.find(order, {month:month_order[i]});
282
+ if(find_row){
283
+ find_row.weight = i+1;
284
+ }
285
+ }
286
+ }
287
+
288
+ _.forEach(order, function(month_obj){
289
+ _.forEach(month_obj.versions, function(val){
290
+ mapping[val] = month_obj.weight*31;
291
+ });
292
+ });
293
+
294
+ var getIndexForVal = function(value){
295
+ var to_return = 0, matches, i;
296
+ if (typeof value === 'string' || value instanceof String){
297
+ matches = value.match(pattern);
298
+ var numbers = 0;
299
+ var i = 0;
300
+ _.forEach(matches, function(v)
301
+ {
302
+ i++;
303
+ v = v.trim().toLowerCase();
304
+ var res = 0;
305
+
306
+ if(mapping[v] != undefined){
307
+ res = mapping[v];
308
+ }
309
+ else{
310
+ try {
311
+ res = parseInt(v)
312
+ if(res > 31 || numbers > 1 || i == matches.length)
313
+ res *=1000
314
+ numbers++;
315
+ }
316
+ catch(er){
317
+ res = 0
318
+ }
319
+ }
320
+ if(res == NaN){
321
+ res = 0
322
+ }
323
+ to_return += res
324
+ });
325
+ }
326
+ else{
327
+ try {
328
+ to_return = parseInt(value)
329
+ }
330
+ catch(er){
331
+ to_return = value
332
+ }
333
+ }
334
+
335
+ return to_return;
336
+ };
337
+
338
+ return function(a, b) {
339
+ return $.pivotUtilities.naturalSort(getIndexForVal(a), getIndexForVal(b));
340
+ };
341
+ };
342
+
343
+ largeToSmallSort = function(as, bs) {
344
+ var a, a1, b, b1, rd, rx, rz;
345
+ rx = /(\d+)|(\D+)/g;
346
+ rd = /\d/;
347
+ rz = /^0/;
348
+ if (typeof as === "number" || typeof bs === "number") {
349
+ if (isNaN(as)) {
350
+ return -1;
351
+ }
352
+ if (isNaN(bs)) {
353
+ return 1;
354
+ }
355
+ return bs - as;
356
+ }
357
+ a = String(as).toLowerCase();
358
+ b = String(bs).toLowerCase();
359
+ if (a === b) {
360
+ return 0;
361
+ }
362
+ if (!(rd.test(a) && rd.test(b))) {
363
+ return (b > a ? 1 : -1);
364
+ }
365
+ a = a.match(rx);
366
+ b = b.match(rx);
367
+ while (a.length && b.length) {
368
+ a1 = a.shift();
369
+ b1 = b.shift();
370
+ if (a1 !== b1) {
371
+ if (rd.test(a1) && rd.test(b1)) {
372
+ return b1.replace(rz, ".0") - a1.replace(rz, ".0");
373
+ } else {
374
+ return (b1 > a1 ? 1 : -1);
375
+ }
376
+ }
377
+ }
378
+ return b.length - a.length;
379
+ };
380
+
381
+ $.pivotUtilities.DRPivotData = DRPivotData;
382
+
383
+ getFormattedNumber = function(val, aggregator, opts, format_argument) {
384
+ if (!aggregator) {
385
+ aggregator = {};
386
+ aggregator.format = function(val) {
387
+ return val.toLocaleString();
388
+ }
389
+ }
390
+ if (val < 0 && opts && opts.chartOptions && opts.chartOptions.negative_numbers && opts.chartOptions.negative_numbers.value) {
391
+ switch (opts.chartOptions.negative_numbers.value) {
392
+ case 'red_minus':
393
+ return '<span style="color: red; fill: red;">' + aggregator.format(val, format_argument) + '</span>';
394
+ break;
395
+ case 'absolute':
396
+ return '(' + aggregator.format(Math.abs(val), format_argument) + ')';
397
+ break;
398
+ case 'red_absolute':
399
+ return '<span style="color: red; fill: red;">(' + aggregator.format(Math.abs(val), format_argument) + ')</span>';
400
+ break;
401
+ default:
402
+ return aggregator.format(val, format_argument);
403
+ }
404
+ }
405
+ return aggregator.format(val, format_argument);
406
+ };
407
+
408
+ NovixRenderer = function(pvtData, opts, charttype) {
409
+ var resultsArr = [];
410
+ var additionOptions = opts.chartOptions ? opts.chartOptions : null;
411
+ if (additionOptions && additionOptions.table_options.use_handsOnTable) {
412
+ if (opts && opts.chart_title && !opts.chartOptions.hideChartHeader) {
413
+ var title = document.createElement("div");
414
+ title.className = "title";
415
+ title.innerText = opts.chart_title;
416
+ resultsArr.push(title);
417
+ }
418
+
419
+ if (additionOptions && additionOptions.subtitle && additionOptions.subtitle.subtitle && !opts.chartOptions.hideChartHeader) {
420
+ console.log("subtitle", additionOptions.subtitle);
421
+ var subTitle = document.createElement("div");
422
+ subTitle.className = "sub-title";
423
+ subTitle.innerText = additionOptions.subtitle.subtitle;
424
+ resultsArr.push(subTitle);
425
+ }
426
+
427
+ resultsArr.push($.pivotUtilities.novix_renderers["Pivot Table"](pvtData, opts));
428
+
429
+ // var wrapper = document.createElement("div");
430
+ // wrapper.className = "pivot-wrapper2";
431
+ // $(wrapper).append(resultsArr);
432
+
433
+ return resultsArr;
434
+ } else {
435
+ let tooMuch = false;
436
+ if (pvtData && (pvtData.rowKeys.length > 1000 || pvtData.colKeys.length > 500) &&
437
+ (!opts.show_more_function_cols || !opts.show_more_function_cols)) {
438
+ pvtData.rowKeys = [];
439
+ pvtData.colKeys = [];
440
+ tooMuch = true;
441
+ opts.error_has_occurred = true;
442
+ }
443
+ return SubtotalRenderer(pvtData, opts, charttype, tooMuch);
444
+ }
445
+ }
446
+
447
+ SubtotalRenderer = function(pivotData, opts, charttype, tooMuch = false) {
448
+ 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;
449
+ var createTotalValsBolder, createGrandTotalBolder, getHeaderColorProperties, colorizeRowLabelHeaders, colorizeTableIfNeed, valueNoDashes, getColorsWithOffsetForTable, offsetColors, handleFreezePanesScroll, selectFreezableElements, removeRowHeaderNullValue;
450
+ var edit_assumptions;
451
+
452
+ var horizontalFreezePaneClass = opts.chartOptions.table_options.freeze_panes ? ' horizontal-freeze-pane' : '';
453
+ var verticalFreezePaneClass = opts.chartOptions.table_options.freeze_panes ? ' vertical-freeze-pane' : '';
454
+ var axisFreezePaneClass = opts.chartOptions.table_options.freeze_panes ? ' axis-freeze-pane' : '';
455
+
456
+ var elementToTransform = {
457
+ X: horizontalFreezePaneClass,
458
+ Y: verticalFreezePaneClass,
459
+ XY: axisFreezePaneClass,
460
+ }
461
+
462
+ defaults = {
463
+ table: {
464
+ clickCallback: null
465
+ },
466
+ localeStrings: {
467
+ totals: "Grand Totals",
468
+ subtotals: "Subtotal"
469
+ },
470
+ chartOptions:{
471
+ table_options:{
472
+ show_column_total:true,
473
+ show_row_total:true
474
+ }
475
+ },
476
+ totalFilterElements: null,
477
+ resetSortingElement: null,
478
+ nextSortingElement: null,
479
+ prevSortingElement: null,
480
+ show_more_function_cols: null,
481
+ show_more_function_rows: null,
482
+ show_more_max_items: 10,
483
+ labelsConvertFunction: function(str){return str;}
484
+ };
485
+ opts = $.extend(true, {}, defaults, opts);
486
+
487
+ if(opts.chartOptions.table_options.start_collapsed_rows) {
488
+ opts.collapseRowsAt = 0;
489
+ }
490
+ if(opts.chartOptions.table_options.start_collapsed_columns) {
491
+ opts.collapseColsAt = 0;
492
+ }
493
+ edit_assumptions = opts.chartOptions.edit_assumptions;
494
+ isRowDisable = (ref = opts.rowSubtotalDisplay) != null ? ref.disableSubtotal : void 0;
495
+ isRowHideOnExpand = (ref1 = opts.rowSubtotalDisplay) != null ? ref1.hideOnExpand : !opts.chartOptions.table_options.show_subtotals_for_rows;
496
+ isRowDisableExpandCollapse = (ref2 = opts.rowSubtotalDisplay) != null ? ref2.disableExpandCollapse : void 0;
497
+ rowDisableAfter = (ref3 = opts.rowSubtotalDisplay) != null ? ref3.disableAfter != null ? ref3.disableAfter : ref3.disableAfter = 9999 : void 0;
498
+ isColDisable = (ref4 = opts.colSubtotalDisplay) != null ? ref4.disableSubtotal : void 0;
499
+ isColHideOnExpand = (ref5 = opts.colSubtotalDisplay) != null ? ref5.hideOnExpand : !opts.chartOptions.table_options.show_subtotals_for_columns;
500
+ isColDisableExpandCollapse = (ref6 = opts.colSubtotalDisplay) != null ? ref6.disableExpandCollapse : void 0;
501
+ colDisableAfter = (ref7 = opts.colSubtotalDisplay) != null ? ref7.disableAfter != null ? ref7.disableAfter : ref7.disableAfter = 9999 : void 0;
502
+ arrowCollapsed = opts.arrowCollapsed != null ? opts.arrowCollapsed : opts.arrowCollapsed = '<i class="fa fa-plus dr-icon-add"></i> ';
503
+ arrowExpanded = opts.arrowExpanded != null ? opts.arrowExpanded : opts.arrowExpanded = '<i class="fa fa-minus dr-icon-minus"></i> ';
504
+ colAttrs = pivotData.colAttrs;
505
+ rowAttrs = pivotData.rowAttrs;
506
+ rowKeys = pivotData.getRowKeys();
507
+
508
+ if (charttype == 'column-chart' || charttype == 'column-chart-stacked') {
509
+ if (_.get(opts, 'chartOptions.table_options.transpose_table', false)) {
510
+ rowAttrs = [rowAttrs[0]];
511
+ if (rowKeys && rowKeys.length) {
512
+ rowKeys = rowKeys.map( function(_, index) {
513
+ return [rowKeys[index][0]];
514
+ });
515
+ }
516
+ } else {
517
+ colAttrs = [colAttrs[0]];
518
+ }
519
+ }
520
+ colKeys = pivotData.getColKeys();
521
+ tree = pivotData.tree;
522
+ rowTotals = pivotData.rowTotals;
523
+ colTotals = pivotData.colTotals;
524
+ allTotal = pivotData.allTotal;
525
+ classRowExpanded = "rowexpanded";
526
+ classRowCollapsed = "rowcollapsed";
527
+ classRowHide = "rowhide";
528
+ classRowShow = "rowshow";
529
+ classColExpanded = "colexpanded";
530
+ classColCollapsed = "colcollapsed";
531
+ classColHide = "colhide";
532
+ classColShow = "colshow";
533
+ clickStatusExpanded = "expanded";
534
+ clickStatusCollapsed = "collapsed";
535
+ classExpanded = "expanded";
536
+ classCollapsed = "collapsed";
537
+ hasClass = function(element, className) {
538
+ var regExp;
539
+ regExp = new RegExp("(?:^|\\s)" + className + "(?!\\S)", "g");
540
+ return element.className.match(regExp) !== null;
541
+ };
542
+ removeClass = function(element, className) {
543
+ var k, len, name, ref8, regExp, results;
544
+ ref8 = className.split(" ");
545
+ results = [];
546
+ for (k = 0, len = ref8.length; k < len; k++) {
547
+ name = ref8[k];
548
+ regExp = new RegExp("(?:^|\\s)" + name + "(?!\\S)", "g");
549
+ results.push(element.className = element.className.replace(regExp, ''));
550
+ }
551
+ return results;
552
+ };
553
+ addClass = function(element, className) {
554
+ var k, len, name, ref8, results;
555
+ ref8 = className.split(" ");
556
+ results = [];
557
+ for (k = 0, len = ref8.length; k < len; k++) {
558
+ name = ref8[k];
559
+ if (!hasClass(element, name)) {
560
+ results.push(element.className += " " + name);
561
+ } else {
562
+ results.push(void 0);
563
+ }
564
+ }
565
+ return results;
566
+ };
567
+ replaceClass = function(element, replaceClassName, byClassName) {
568
+ removeClass(element, replaceClassName);
569
+ return addClass(element, byClassName);
570
+ };
571
+
572
+ colorizeTableIfNeed = function(element){
573
+ if(opts.chartOptions.table_options.colorize_headers == true){
574
+ element.className += " colorized";
575
+ }
576
+ };
577
+
578
+ valueNoDashes = function(value){
579
+
580
+ if(opts.chartOptions.table_options.remove_underscores == true && typeof(value) == 'string'){
581
+ return value.replace(/_/g, " ");
582
+ }
583
+ return value;
584
+ };
585
+
586
+ offsetColors = function (offset, colorsArray) {
587
+ if (offset > opts.defaults_colors.length) {
588
+ offset = offset % opts.defaults_colors;
589
+ }
590
+ var colors_to_return = JSON.parse(JSON.stringify(colorsArray));
591
+ for (var i = 0; i < offset; i++) {
592
+ colors_to_return.push(colors_to_return.shift());
593
+ }
594
+ return colors_to_return;
595
+ }
596
+
597
+ getColorsWithOffsetForTable = function (value) {
598
+ var isNewDesign = useNewUx && opts.chartOptions.table_options.use_new_table_design;
599
+ if (value) {
600
+ var offset = parseInt(value);
601
+ if (offset) {
602
+ if (isNewDesign) {
603
+ return offsetColors(offset, newTableColors);
604
+ } else {
605
+ return offsetColors(offset, opts.defaults_colors);
606
+ }
607
+ }
608
+ }
609
+ return isNewDesign ? newTableColors : opts.defaults_colors;
610
+ }
611
+
612
+ colorizeRowLabelHeaders = function(element, cols_count){
613
+ if(opts.chartOptions.table_options.colorize_headers == true &&
614
+ opts.defaults_colors && opts.defaults_colors.length > 0){
615
+ var offsetColor = getColorsWithOffsetForTable(opts.chartOptions.table_options.table_colors_offset);
616
+ var color_to_set = offsetColor[cols_count];
617
+ if(color_to_set){
618
+ element.style.setProperty("background-color", color_to_set, "important");
619
+ element.style.setProperty("border-color", color_to_set, "important");
620
+ element.style.color = useNewUx && opts.chartOptions.table_options.use_new_table_design? '#3a3b39' : '#FFFFFF';
621
+ element.style.fontWeight = "bold";
622
+ if (opts.chartOptions.table_options.freeze_panes && element.firstChild) {
623
+ for (const child of element.children) {
624
+ child.style.setProperty("background-color", color_to_set, "important");
625
+ }
626
+ }
627
+ }
628
+ }
629
+ };
630
+
631
+ createTotalValsBolder = function(element){
632
+ if(opts.chartOptions.table_options.colorize_headers == true && (!useNewUx || !opts.chartOptions.table_options.use_new_table_design)){
633
+ element.style.setProperty("border-bottom", "3px double #000000", "important");
634
+ }
635
+ };
636
+ createGrandTotalBolder = function(element){
637
+ if(opts.chartOptions.table_options.colorize_headers == true && (!useNewUx || !opts.chartOptions.table_options.use_new_table_design)){
638
+ element.style.setProperty("border-top", "3px solid #000000", "important");
639
+ }
640
+ };
641
+ getHeaderColorProperties = function(element, col_number = 0){
642
+ if(opts.chartOptions.table_options.colorize_headers == true &&
643
+ opts.defaults_colors && opts.defaults_colors.length > 0){
644
+ const offsetColor = getColorsWithOffsetForTable(opts.chartOptions.table_options.table_colors_offset);
645
+ var color_to_set = offsetColor[col_number];
646
+ if(color_to_set){
647
+ element.style.setProperty("background-color", color_to_set, "important");
648
+ element.style.setProperty("border-color", color_to_set, "important");
649
+ element.style.setProperty("vertical-align", "baseline");
650
+ element.style.color = useNewUx && opts.chartOptions.table_options.use_new_table_design? '#3a3b39' : '#FFFFFF';
651
+ element.style.fontWeight = "bold";
652
+ if (opts.chartOptions.table_options.freeze_panes && element.firstChild) {
653
+ for (const child of element.children) {
654
+ child.style.setProperty("background-color", color_to_set, "important");
655
+ }
656
+ }
657
+ }
658
+ }
659
+ };
660
+ getTableEventHandlers = function(value, rowValues, colValues) {
661
+ var attr, event, eventHandlers, filters, handler, i, ref8;
662
+ if (!opts.table && !opts.table.eventHandlers) {
663
+ return;
664
+ }
665
+ eventHandlers = {};
666
+ ref8 = opts.table.eventHandlers;
667
+ for (event in ref8) {
668
+ if (!hasProp.call(ref8, event)) continue;
669
+ handler = ref8[event];
670
+ filters = {};
671
+ for (i in colAttrs) {
672
+ if (!hasProp.call(colAttrs, i)) continue;
673
+ attr = colAttrs[i];
674
+ if (colValues[i] != null) {
675
+ filters[attr] = colValues[i];
676
+ }
677
+ }
678
+ for (i in rowAttrs) {
679
+ if (!hasProp.call(rowAttrs, i)) continue;
680
+ attr = rowAttrs[i];
681
+ if (rowValues[i] != null) {
682
+ filters[attr] = rowValues[i];
683
+ }
684
+ }
685
+ eventHandlers[event] = function(e) {
686
+ return handler(e, value, filters, pivotData);
687
+ };
688
+ }
689
+ return eventHandlers;
690
+ };
691
+ createElement = function(elementType, className, textContent, attributes, eventHandlers) {
692
+ var attr, e, event, handler, val;
693
+ e = document.createElement(elementType);
694
+ if (className != null) {
695
+ e.className = className;
696
+ }
697
+ if (textContent != null) {
698
+ // We need html for negative items.
699
+ e.innerHTML = textContent;
700
+ }
701
+ if (attributes != null) {
702
+ for (attr in attributes) {
703
+ if (!hasProp.call(attributes, attr)) continue;
704
+ val = attributes[attr];
705
+ e.setAttribute(attr, val);
706
+ }
707
+ }
708
+ if (eventHandlers != null) {
709
+ for (event in eventHandlers) {
710
+ if (!hasProp.call(eventHandlers, event)) continue;
711
+ handler = eventHandlers[event];
712
+ e.addEventListener(event, handler);
713
+ }
714
+ }
715
+ return e;
716
+ };
717
+ setAttributes = function(e, attrs) {
718
+ var a, results, v;
719
+ results = [];
720
+ for (a in attrs) {
721
+ if (!hasProp.call(attrs, a)) continue;
722
+ v = attrs[a];
723
+ results.push(e.setAttribute(a, v));
724
+ }
725
+ return results;
726
+ };
727
+ getSubtotalInBrackets = function(keysArr, className, lastCol, lastRow, from, to) {
728
+ let aggregator, val, to_return;
729
+ if(opts.chartOptions.table_options.show_subtotals_in_brackets){
730
+ if(className == "pvtColLabel" && keysArr[from] && to < keysArr[from].length){
731
+ aggregator = pivotData.getAggregator([], keysArr[from].slice(0, to+1));
732
+ val = aggregator.value();
733
+ to_return = getFormattedNumber(val, aggregator, opts);
734
+ return ' ('+to_return+")";
735
+ }
736
+ else if(className == "pvtRowLabel" && keysArr[from] && to < keysArr[from].length){
737
+ aggregator = pivotData.getAggregator(keysArr[from].slice(0, to+1), []);
738
+ val = aggregator.value();
739
+ to_return = getFormattedNumber(val, aggregator, opts);
740
+ return ' ('+to_return+")";
741
+ }
742
+ }
743
+ return '';
744
+ };
745
+ encodeHtmlEntities = function(string_val) {
746
+ if(!string_val || typeof(string_val) != 'string' ){
747
+ return string_val;
748
+ }
749
+ 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;"};
750
+ string_val = string_val.replace(/&/g, '&amp;');
751
+ string_val = string_val.replace(/"/g, '&quot;');
752
+ for (var key in entityMap) {
753
+ var entity = entityMap[key];
754
+ var regex = new RegExp(key, 'g');
755
+ string_val = string_val.replace(regex, entity);
756
+ }
757
+ return string_val;
758
+ };
759
+
760
+ processKeys = function(keysArr, className, dimention, attrs) {
761
+ var c, headers, k, key, lastCol, lastRow, node, nodePos, r, rMark, ref8, repeats, th, x;
762
+ const showAllData = opts && opts.chartOptions && opts.chartOptions.table_options && opts.chartOptions.table_options.show_all;
763
+
764
+ headers = [];
765
+ lastRow = keysArr.length - 1;
766
+ lastCol = keysArr[0].length - 1;
767
+ if(lastCol > 0 && className == "pvtColLabel" && !_.get(opts, 'chartOptions.table_options.transpose_table', false) && (charttype == 'column-chart' || charttype == 'column-chart-stacked')){
768
+ lastCol = 0;
769
+ }
770
+ rMark = [];
771
+ th = createElement("th", className, valueNoDashes(encodeHtmlEntities(keysArr[0][0]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, 0, 0)));
772
+ key = [];
773
+ key.push(keysArr[0][0]);
774
+ nodePos = 0;
775
+ node = {
776
+ node: nodePos,
777
+ row: 0,
778
+ col: 0,
779
+ th: th,
780
+ parent: null,
781
+ children: [],
782
+ descendants: lastCol,
783
+ leaves: 1,
784
+ key: key,
785
+ flatKey: key.join(delim)
786
+ };
787
+ headers.push(node);
788
+ rMark[0] = node;
789
+ c = 1;
790
+ while (c <= lastCol) {
791
+ th = createElement("th", className, valueNoDashes(encodeHtmlEntities(keysArr[0][c]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, 0, c)));
792
+ key = key.slice();
793
+ key.push(keysArr[0][c]);
794
+ ++nodePos;
795
+ node = {
796
+ node: nodePos,
797
+ row: 0,
798
+ col: c,
799
+ th: th,
800
+ parent: rMark[c - 1],
801
+ children: [],
802
+ descendants: lastCol - c,
803
+ leaves: 1,
804
+ key: key,
805
+ flatKey: key.join(delim)
806
+ };
807
+ rMark[c] = node;
808
+ rMark[c - 1].children.push(node);
809
+ ++c;
810
+ }
811
+ rMark[lastCol].leaves = 0;
812
+ r = 1;
813
+ while (r <= lastRow) {
814
+ repeats = true;
815
+ key = [];
816
+ c = 0;
817
+ while (c <= lastCol) {
818
+ key = key.slice();
819
+ key.push(keysArr[r][c]);
820
+ if ((keysArr[r][c] === keysArr[rMark[c].row][c]) && (c !== lastCol) && repeats) {
821
+ repeats = true;
822
+ ++c;
823
+ continue;
824
+ }
825
+
826
+ if(c === 0 && ((dimention == 'rows' && opts.show_more_function_rows)
827
+ || (dimention == 'cols' && opts.show_more_function_cols)
828
+ ) && headers.length > opts.show_more_max_items && !showAllData)
829
+ {
830
+ key=['...'];
831
+
832
+ let th_attr = {data_show_more:'1'};
833
+
834
+ th = createElement("th", className, '... Show All', th_attr);
835
+ ++nodePos;
836
+ node = {
837
+ node: nodePos,
838
+ row: r,
839
+ col: c,
840
+ th: th,
841
+ parent: null,
842
+ children: [],
843
+ descendants: 0,
844
+ leaves: 0,
845
+ key: key,
846
+ flatKey: key.join(delim)
847
+ };
848
+
849
+ headers.push(node);
850
+ rMark[c] = node;
851
+ repeats = false;
852
+ r = lastRow;
853
+ break;
854
+ }
855
+
856
+
857
+ th = createElement("th", className, valueNoDashes(encodeHtmlEntities(keysArr[r][c]) + getSubtotalInBrackets(keysArr, className, lastCol, lastRow, r, c)));
858
+ ++nodePos;
859
+ node = {
860
+ node: nodePos,
861
+ row: r,
862
+ col: c,
863
+ th: th,
864
+ parent: null,
865
+ children: [],
866
+ descendants: 0,
867
+ leaves: 0,
868
+ key: key,
869
+ flatKey: key.join(delim)
870
+ };
871
+ if (c === 0) {
872
+ headers.push(node);
873
+ } else {
874
+ node.parent = rMark[c - 1];
875
+ rMark[c - 1].children.push(node);
876
+ x = 0;
877
+ while (x <= c - 1) {
878
+ ++rMark[x].descendants;
879
+ ++x;
880
+ }
881
+ }
882
+ rMark[c] = node;
883
+ repeats = false;
884
+ ++c;
885
+ }
886
+ for (c = k = 0, ref8 = lastCol; 0 <= ref8 ? k <= ref8 : k >= ref8; c = 0 <= ref8 ? ++k : --k) {
887
+ ++rMark[c].leaves;
888
+ }
889
+ rMark[lastCol].leaves = 0;
890
+ ++r;
891
+ }
892
+ return headers;
893
+ };
894
+ buildColHeaderHeader = function(thead, colHeaderHeaders, rowAttrs, colAttrs, tr, col) {
895
+ var className, colAttr, textContent, th, clickStatus;
896
+ colAttr = colAttrs[col];
897
+ textContent = opts.labelsConvertFunction(colAttr);
898
+ className = "pvtAxisLabel" + axisFreezePaneClass;
899
+ if (col < colAttrs.length - 1) {
900
+ if (!(isColDisableExpandCollapse || isColDisable || col > colDisableAfter)) {
901
+ if(opts.collapseColsAt == 0){
902
+ clickStatus = clickStatusCollapsed;
903
+ className += " "+classCollapsed;
904
+ textContent = " " + arrowCollapsed + " " + textContent;
905
+ }
906
+ else{
907
+ clickStatus = clickStatusExpanded;
908
+ className += " "+classExpanded;
909
+ textContent = " " + arrowExpanded + " " + textContent;
910
+ }
911
+ }
912
+ }
913
+ th = createElement("th", className, textContent);
914
+ th.setAttribute("data-colAttr", colAttr);
915
+ //getHeaderColorProperties(th, col);
916
+ tr.appendChild(th);
917
+ colHeaderHeaders.push({
918
+ tr: tr,
919
+ th: th,
920
+ clickStatus: clickStatus,
921
+ expandedCount: 0,
922
+ nHeaders: 0
923
+ });
924
+ return thead.appendChild(tr);
925
+ };
926
+ buildColHeaderHeaders = function(thead, colHeaderHeaders, rowAttrs, colAttrs) {
927
+ var c, k, ref8, results, tr, rowSpan;
928
+ tr = createElement("tr");
929
+ if (rowAttrs.length !== 0) {
930
+ if(opts.chartOptions.table_options.colorize_headers == true){
931
+ rowSpan = 1;
932
+ }
933
+ else{
934
+ rowSpan = colAttrs.length;
935
+ }
936
+ tr.appendChild(createElement("th", axisFreezePaneClass, null, {
937
+ colspan: rowAttrs.length,
938
+ rowspan: rowSpan
939
+ }));
940
+ }
941
+
942
+ buildColHeaderHeader(thead, colHeaderHeaders, rowAttrs, colAttrs, tr, 0);
943
+ getHeaderColorProperties(tr);
944
+ results = [];
945
+ for (c = k = 1, ref8 = colAttrs.length; 1 <= ref8 ? k <= ref8 : k >= ref8; c = 1 <= ref8 ? ++k : --k) {
946
+ if (!(c < colAttrs.length)) {
947
+ continue;
948
+ }
949
+ tr = createElement("tr");
950
+ if (opts.chartOptions.table_options.colorize_headers == true && rowAttrs.length !== 0) {
951
+ tr.appendChild(createElement("th", axisFreezePaneClass, null, {
952
+ colspan: rowAttrs.length
953
+ }));
954
+ }
955
+ getHeaderColorProperties(tr, c);
956
+ results.push(buildColHeaderHeader(thead, colHeaderHeaders, rowAttrs, colAttrs, tr, c));
957
+ }
958
+ return results;
959
+ };
960
+ buildColHeaderHeadersClickEvents = function(colHeaderHeaders, colHeaderCols, colAttrs) {
961
+ var colAttr, i, k, n, ref8, results, th;
962
+ n = colAttrs.length - 1;
963
+ results = [];
964
+ for (i = k = 0, ref8 = n; 0 <= ref8 ? k <= ref8 : k >= ref8; i = 0 <= ref8 ? ++k : --k) {
965
+ if (!(i < n)) {
966
+ continue;
967
+ }
968
+ th = colHeaderHeaders[i].th;
969
+ colAttr = colAttrs[i];
970
+ results.push(th.onclick = function(event) {
971
+ event = event || window.event;
972
+ if(!event.currentTarget)
973
+ event.currentTarget = event.target;
974
+ return toggleColHeaderHeader(colHeaderHeaders, colHeaderCols, colAttrs, event.currentTarget.getAttribute("data-colAttr"));
975
+ });
976
+ }
977
+ return results;
978
+ };
979
+ buildColHeaders = function(colHeaderHeaders, colHeaderCols, colHeader, rowAttrs, colAttrs) {
980
+ var colspan, h, hh, isColSubtotal, k, len, ref8, rowspan, sTh, style, th, tr;
981
+ ref8 = colHeader.children;
982
+ for (k = 0, len = ref8.length; k < len; k++) {
983
+ h = ref8[k];
984
+ buildColHeaders(colHeaderHeaders, colHeaderCols, h, rowAttrs, colAttrs);
985
+ }
986
+ isColSubtotal = colHeader.children.length !== 0;
987
+ colHeader.node = colHeaderCols.length;
988
+ hh = colHeaderHeaders[colHeader.col];
989
+ ++hh.expandedCount;
990
+ ++hh.nHeaders;
991
+ tr = hh.tr;
992
+ th = colHeader.th;
993
+ addClass(th, "col" + colHeader.row + " colcol" + colHeader.col + " " + classColShow + verticalFreezePaneClass);
994
+ //getHeaderColorProperties(th, colHeader.col);
995
+ if (isColHideOnExpand || isColDisable || (isColSubtotal && colHeader.col > colDisableAfter)) {
996
+ colspan = colHeader.leaves;
997
+ } else if (isColSubtotal && colHeader.col <= colDisableAfter) {
998
+ colspan = colHeader.leaves + 1;
999
+ } else {
1000
+ colspan = colHeader.descendants + 1;
1001
+ }
1002
+
1003
+ if(th.getAttribute('data_show_more') == '1'){
1004
+ rowspan = colAttrs.length + 1;
1005
+ addClass(th, 'show_more_header');
1006
+ th.onclick = opts.show_more_function_cols;
1007
+ }
1008
+ else{
1009
+ rowspan = colHeader.col === colAttrs.length - 1 && rowAttrs.length !== 0 ? 2 : 1;
1010
+ }
1011
+ setAttributes(th, {
1012
+ "rowspan": rowspan,
1013
+ "colspan": colspan,
1014
+ "data-colnode": colHeader.node,
1015
+ "data-colHeader": th.textContent
1016
+ });
1017
+ if (isColSubtotal) {
1018
+ addClass(th, classColExpanded);
1019
+ if (!(isColDisableExpandCollapse || isColDisable || colHeader.col > colDisableAfter)) {
1020
+ th.innerHTML = " " + arrowExpanded + " " + th.textContent;
1021
+ }
1022
+ th.onclick = function(event) {
1023
+ event = event || window.event;
1024
+ return toggleCol(colHeaderHeaders, colHeaderCols, parseInt(event.currentTarget.getAttribute("data-colnode")));
1025
+ };
1026
+ rowspan = colAttrs.length - (colHeader.col + 1) + (rowAttrs.length !== 0 ? 1 : 0);
1027
+ style = "pvtColLabel pvtColSubtotal " + classColExpanded + verticalFreezePaneClass;
1028
+ style += " col" + colHeader.row + " colcol" + colHeader.col;
1029
+ if (isColHideOnExpand || isColDisable || colHeader.col > colDisableAfter) {
1030
+ style += " " + classColHide;
1031
+ }
1032
+ sTh = createElement("th", style, opts.localeStrings.subtotals, {
1033
+ "rowspan": rowspan,
1034
+ "data-colnode": colHeader.node
1035
+ });
1036
+ addClass(sTh, isColHideOnExpand || isColDisable ? " " + classColHide : " " + classColShow);
1037
+ //getHeaderColorProperties(sTh, colHeader.col);
1038
+ if (isColHideOnExpand || isColDisable || colHeader.col > colDisableAfter) {
1039
+ sTh.style.display = "none";
1040
+ }
1041
+ colHeader.children[0].tr.appendChild(sTh);
1042
+ colHeader.sTh = sTh;
1043
+ }
1044
+ colHeader.clickStatus = clickStatusExpanded;
1045
+ tr.appendChild(th);
1046
+ if (opts.chartOptions.table_options.freeze_panes) {
1047
+ getHeaderColorProperties(tr);
1048
+ }
1049
+ colHeader.tr = tr;
1050
+ return colHeaderCols.push(colHeader);
1051
+ };
1052
+ buildRowHeaderHeaders = function(thead, rowHeaderHeaders, rowAttrs, colAttrs) {
1053
+ var className, i, rowAttr, textContent, th, tr, clickStatus;
1054
+ tr = createElement("tr");
1055
+ rowHeaderHeaders.hh = [];
1056
+ for (i in rowAttrs) {
1057
+ if (!hasProp.call(rowAttrs, i)) continue;
1058
+ rowAttr = rowAttrs[i];
1059
+ textContent = opts.labelsConvertFunction(rowAttr);
1060
+ className = "pvtAxisLabel" + axisFreezePaneClass;
1061
+ if (i < rowAttrs.length - 1) {
1062
+ className += " expanded";
1063
+ if (!(isRowDisableExpandCollapse || isRowDisable || i > rowDisableAfter)) {
1064
+ if(opts.collapseRowsAt == 0){
1065
+ clickStatus = clickStatusCollapsed;
1066
+ className += " "+classCollapsed;
1067
+ textContent = " " + arrowCollapsed + " " + textContent;
1068
+ }
1069
+ else{
1070
+ clickStatus = clickStatusExpanded;
1071
+ className += " "+classExpanded;
1072
+ textContent = " " + arrowExpanded + " " + textContent;
1073
+ }
1074
+ }
1075
+ }
1076
+ th = createElement("th", className, textContent);
1077
+ th.setAttribute("data-rowAttr", rowAttr);
1078
+ tr.appendChild(th);
1079
+ rowHeaderHeaders.hh.push({
1080
+ th: th,
1081
+ clickStatus: clickStatus,
1082
+ expandedCount: 0,
1083
+ nHeaders: 0
1084
+ });
1085
+ }
1086
+ if (colAttrs.length !== 0) {
1087
+ th = createElement("th", axisFreezePaneClass);
1088
+ tr.appendChild(th);
1089
+ }
1090
+ colorizeRowLabelHeaders(tr, colAttrs.length);
1091
+ thead.appendChild(tr);
1092
+ return rowHeaderHeaders.tr = tr;
1093
+ };
1094
+ buildRowHeaderHeadersClickEvents = function(rowHeaderHeaders, rowHeaderRows, rowAttrs) {
1095
+ var i, k, n, ref8, results, rowAttr, th;
1096
+ n = rowAttrs.length - 1;
1097
+ results = [];
1098
+ for (i = k = 0, ref8 = n; 0 <= ref8 ? k <= ref8 : k >= ref8; i = 0 <= ref8 ? ++k : --k) {
1099
+ if (!(i < n)) {
1100
+ continue;
1101
+ }
1102
+ th = rowHeaderHeaders.hh[i];
1103
+ rowAttr = rowAttrs[i];
1104
+ results.push(th.th.onclick = function(event) {
1105
+ event = event || window.event;
1106
+ if(!event.currentTarget)
1107
+ event.currentTarget = event.target;
1108
+ return toggleRowHeaderHeader(rowHeaderHeaders, rowHeaderRows, rowAttrs, event.currentTarget.getAttribute("data-rowAttr"));
1109
+ });
1110
+ }
1111
+ return results;
1112
+ };
1113
+ buildRowTotalsHeader = function(tr, rowAttrs, colAttrs) {
1114
+ var rowspan, th;
1115
+ rowspan = 1;
1116
+ if (colAttrs.length !== 0) {
1117
+ rowspan = colAttrs.length + (rowAttrs.length === 0 ? 0 : 1);
1118
+ }
1119
+
1120
+ if(opts.chartOptions.table_options.colorize_headers == true && colAttrs.length > 1){
1121
+ rowspan = 1;
1122
+ }
1123
+
1124
+ th = createElement("th", "pvtTotalLabel rowTotal" + verticalFreezePaneClass , opts.localeStrings.totals, {
1125
+ rowspan: rowspan
1126
+ });
1127
+
1128
+ if (opts.totalFilterElements && opts.totalFilterElements.row_total) {
1129
+ th.innerHTML = '';
1130
+ th.appendChild(opts.totalFilterElements.row_total);
1131
+ }
1132
+
1133
+ //getHeaderColorProperties(th);
1134
+ if (opts.chartOptions.table_options.freeze_panes) {
1135
+ tr.appendChild(th);
1136
+ getHeaderColorProperties(tr);
1137
+ } else {
1138
+ return tr.appendChild(th);
1139
+ }
1140
+ };
1141
+ buildRowHeaders = function(tbody, rowHeaderHeaders, rowHeaderRows, rowHeader, rowAttrs, colAttrs, highlighted, hasColLabels) {
1142
+ var colspan, h, hh, isRowSubtotal, k, len, ref8, results, style, th, tr;
1143
+ hh = rowHeaderHeaders.hh[rowHeader.col];
1144
+ ++hh.expandedCount;
1145
+ ++hh.nHeaders;
1146
+ tr = createElement("tr", "pvtRowSubtotal row" + rowHeader.row, "", {
1147
+ "data-rownode": rowHeader.node
1148
+ });
1149
+ th = rowHeader.th;
1150
+
1151
+ if(th.getAttribute('data_show_more') == '1'){
1152
+ colspan = rowAttrs.length + 1;
1153
+ addClass(th, 'show_more_header');
1154
+ th.onclick = opts.show_more_function_rows;
1155
+ }
1156
+ else{
1157
+ colspan = rowHeader.col === rowAttrs.length - 1 && colAttrs.length !== 0 ? 2 : 1;
1158
+ }
1159
+
1160
+ isRowSubtotal = rowHeader.children.length !== 0;
1161
+ addClass(th, "row" + rowHeader.row + " rowcol" + rowHeader.col + " " + classRowShow + horizontalFreezePaneClass);
1162
+ if (highlighted) {
1163
+ addClass(th, "highlighted");
1164
+ }
1165
+ setAttributes(th, {
1166
+ "data-rowHeader": th.textContent,
1167
+ "data-rownode": rowHeader.node,
1168
+ "rowspan": rowHeader.descendants + 1,
1169
+ "colspan": colspan
1170
+ });
1171
+ if (opts.chartOptions.table_options.hide_nulls_in_headers) {
1172
+ th.textContent = th.textContent.replace('[null]', '');
1173
+ }
1174
+
1175
+ if (th.hasAttribute('data_show_more') && th.colSpan > 0 && !hasColLabels) {
1176
+ th.colSpan = th.colSpan - 1;
1177
+ }
1178
+
1179
+ tr.appendChild(th);
1180
+ if (isRowSubtotal) {
1181
+ addClass(tr, classRowExpanded);
1182
+ addClass(th, classRowExpanded);
1183
+ if (!(isRowDisableExpandCollapse || isRowDisable || rowHeader.col > rowDisableAfter)) {
1184
+ th.innerHTML = " " + arrowExpanded + " " + th.textContent;
1185
+ }
1186
+ th.onclick = function(event) {
1187
+ event = event || window.event;
1188
+ return toggleRow(rowHeaderHeaders, rowHeaderRows, parseInt(event.currentTarget.getAttribute("data-rownode")));
1189
+ };
1190
+ colspan = rowAttrs.length - (rowHeader.col + 1) + (colAttrs.length !== 0 ? 1 : 0);
1191
+ style = "pvtRowLabel pvtRowSubtotal " + classRowExpanded;
1192
+ style += " row" + rowHeader.row + " rowcol" + rowHeader.col;
1193
+ style += isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter ? " " + classRowHide : " " + classRowShow;
1194
+ style += horizontalFreezePaneClass;
1195
+ th = createElement("th", style, opts.localeStrings.subtotals, {
1196
+ "colspan": colspan,
1197
+ "data-rownode": rowHeader.node
1198
+ });
1199
+ if (isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter) {
1200
+ th.style.display = "none";
1201
+ }
1202
+ tr.appendChild(th);
1203
+ }
1204
+ rowHeader.clickStatus = clickStatusExpanded;
1205
+ rowHeader.tr = tr;
1206
+ rowHeaderRows.push(rowHeader);
1207
+ tbody.appendChild(tr);
1208
+ ref8 = rowHeader.children;
1209
+ results = [];
1210
+ for (k = 0, len = ref8.length; k < len; k++) {
1211
+ h = ref8[k];
1212
+ results.push(buildRowHeaders(tbody, rowHeaderHeaders, rowHeaderRows, h, rowAttrs, colAttrs, highlighted, hasColLabels));
1213
+ }
1214
+ return results;
1215
+ };
1216
+ buildValues = function(rowHeaderRows, colHeaderCols, rowAttrs, colAttrs) {
1217
+ var aggregator, colHeader, eventHandlers, flatColKey, flatRowKey, isColSubtotal, isRowSubtotal, k, l, len, len1, ref8, results, rowHeader, style, td, totalAggregator, tr, val;
1218
+ results = [];
1219
+ for (k = 0, len = rowHeaderRows.length; k < len; k++) {
1220
+ rowHeader = rowHeaderRows[k];
1221
+ tr = rowHeader.tr;
1222
+ flatRowKey = rowHeader.flatKey;
1223
+ isRowSubtotal = rowHeader.children.length !== 0;
1224
+ for (l = 0, len1 = colHeaderCols.length; l < len1; l++) {
1225
+ colHeader = colHeaderCols[l];
1226
+ flatColKey = colHeader.flatKey;
1227
+ if(tree && tree[flatRowKey] && tree[flatRowKey][flatColKey]){
1228
+ ref8 = tree[flatRowKey][flatColKey]
1229
+ }
1230
+ else{
1231
+ ref8 = null;
1232
+ }
1233
+
1234
+ aggregator = ref8 != null ? ref8 : {
1235
+ value: (function() {
1236
+ return null;
1237
+ }),
1238
+ format: function() {
1239
+ return "";
1240
+ }
1241
+ };
1242
+ val = aggregator.value();
1243
+ isColSubtotal = colHeader.children.length !== 0;
1244
+ style = "pvtVal";
1245
+ if (isColSubtotal) {
1246
+ style += " pvtColSubtotal " + classColExpanded;
1247
+ }
1248
+ if (isRowSubtotal) {
1249
+ style += " pvtRowSubtotal " + classRowExpanded;
1250
+ }
1251
+ style += isRowSubtotal && (isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter) ? " " + classRowHide : " " + classRowShow;
1252
+ style += isColSubtotal && (isColHideOnExpand || isColDisable || colHeader.col > colDisableAfter) ? " " + classColHide : " " + classColShow;
1253
+ style += (" row" + rowHeader.row) + (" col" + colHeader.row) + (" rowcol" + rowHeader.col) + (" colcol" + colHeader.col);
1254
+ eventHandlers = getTableEventHandlers(val, rowHeader.key, colHeader.key);
1255
+ td = createElement("td", style, getFormattedNumber(val, aggregator, opts), {
1256
+ "data-value": val,
1257
+ "data-rownode": rowHeader.node,
1258
+ "data-colnode": colHeader.node
1259
+ }, eventHandlers);
1260
+ if ((isRowSubtotal && (isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter)) || (isColSubtotal && (isColHideOnExpand || isColDisable || colHeader.col > colDisableAfter))) {
1261
+ td.style.display = "none";
1262
+ }
1263
+ assumptionSubscribe(td, rowHeader, rowAttrs, colHeader, colAttrs, val);
1264
+
1265
+ tr.appendChild(td);
1266
+ }
1267
+ totalAggregator = rowTotals[flatRowKey];
1268
+ if(!totalAggregator){
1269
+ totalAggregator = {
1270
+ value: (function () {
1271
+ return null;
1272
+ }),
1273
+ format: function () {
1274
+ return "";
1275
+ }
1276
+ };
1277
+ }
1278
+
1279
+ val = totalAggregator.value();
1280
+ style = "pvtTotal rowTotal";
1281
+ if (isRowSubtotal) {
1282
+ style += " pvtRowSubtotal";
1283
+ }
1284
+ style += isRowSubtotal && (isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter) ? " " + classRowHide : " " + classRowShow;
1285
+ style += " row" + rowHeader.row + " rowcol" + rowHeader.col;
1286
+ td = createElement("td", style, getFormattedNumber(val, totalAggregator, opts), {
1287
+ "data-value": val,
1288
+ "data-row": "row" + rowHeader.row,
1289
+ "data-rowcol": "col" + rowHeader.col,
1290
+ "data-rownode": rowHeader.node
1291
+ }, getTableEventHandlers(val, rowHeader.key, []));
1292
+ if (isRowSubtotal && (isRowHideOnExpand || isRowDisable || rowHeader.col > rowDisableAfter)) {
1293
+ td.style.display = "none";
1294
+ }
1295
+
1296
+ assumptionSubscribe(td, rowHeader, rowAttrs, {key:[], flatKey:''}, colAttrs, val);
1297
+
1298
+ if(opts.chartOptions.table_options.show_row_total)
1299
+ tr.appendChild(td);
1300
+
1301
+ results.push(tr);
1302
+ }
1303
+ return results;
1304
+ };
1305
+
1306
+ assumptionSubscribe = function(td, rowHeader, rowAttrs, colHeader, colAttrs, val){
1307
+ if(edit_assumptions){
1308
+ var filters = [];
1309
+ var i=0;
1310
+ var temp;
1311
+ for(i=0; i<rowHeader.key.length; i++){
1312
+ temp = {
1313
+ name: rowAttrs[i],
1314
+ values: [rowHeader.key[i]],
1315
+ is_excluded:false
1316
+ }
1317
+ filters.push(temp);
1318
+ }
1319
+ for(i=0; i<colHeader.key.length; i++){
1320
+ temp = {
1321
+ name: colAttrs[i],
1322
+ values: [colHeader.key[i]],
1323
+ is_excluded:false
1324
+ }
1325
+ filters.push(temp);
1326
+ }
1327
+ var obj_to_send = {
1328
+ "flatColKey": colHeader.flatKey,
1329
+ "flatRowKey": rowHeader.flatKey,
1330
+ "val": val,
1331
+ "filters": filters
1332
+ };
1333
+
1334
+ // td.addEventListener('dblclick', function(){
1335
+ // edit_assumptions.fn(obj_to_send, this);
1336
+ // });
1337
+
1338
+ td.addEventListener('click', function(){
1339
+ edit_assumptions.fn(obj_to_send, this);
1340
+ });
1341
+ }
1342
+
1343
+ if(opts.value_drill_down_fn){
1344
+ td.classList.add('clickable');
1345
+ td.addEventListener('click', function(rowKey, colKey, rowAttrs, colAttrs){
1346
+ return function($event){
1347
+ $event.preventDefault();
1348
+ opts.value_drill_down_fn($event, rowKey, colKey);
1349
+ };
1350
+ }(rowHeader.key, colHeader.key, rowAttrs, colAttrs));
1351
+ }
1352
+ };
1353
+
1354
+ buildColTotalsHeader = function(rowAttrs, colAttrs) {
1355
+ var colspan, th, tr;
1356
+ tr = createElement("tr");
1357
+ colspan = rowAttrs.length + (colAttrs.length === 0 ? 0 : 1);
1358
+ th = createElement("th", "pvtTotalLabel colTotal" + horizontalFreezePaneClass, opts.localeStrings.totals, {
1359
+ colspan: colspan
1360
+ });
1361
+ if (opts.totalFilterElements && opts.totalFilterElements.col_total) {
1362
+ th.innerHTML = '';
1363
+ th.appendChild(opts.totalFilterElements.col_total);
1364
+ }
1365
+ tr.appendChild(th);
1366
+ return tr;
1367
+ };
1368
+ buildColTotals = function(tr, colHeaderCols, rowAttrs, colAttrs) {
1369
+ var h, isColSubtotal, k, len, results, style, td, totalAggregator, val;
1370
+ results = [];
1371
+ for (k = 0, len = colHeaderCols.length; k < len; k++) {
1372
+ h = colHeaderCols[k];
1373
+ isColSubtotal = h.children.length !== 0;
1374
+ totalAggregator = colTotals[h.flatKey];
1375
+ if(!totalAggregator){
1376
+ totalAggregator = {
1377
+ value: (function () {
1378
+ return null;
1379
+ }),
1380
+ format: function () {
1381
+ return "";
1382
+ }
1383
+ };
1384
+ }
1385
+ val = totalAggregator.value();
1386
+ style = "pvtVal pvtTotal colTotal";
1387
+ if (isColSubtotal) {
1388
+ style += " pvtColSubtotal";
1389
+ }
1390
+ style += " " + classColExpanded;
1391
+ style += " col" + h.row + " colcol" + h.col;
1392
+ td = createElement("td", style, getFormattedNumber(val, totalAggregator, opts), {
1393
+ "data-value": val,
1394
+ "data-for": "col" + h.col,
1395
+ "data-colnode": "" + h.node
1396
+ }, getTableEventHandlers(val, [], h.key));
1397
+ createTotalValsBolder(td)
1398
+ if (isColSubtotal && (isColHideOnExpand || isColDisable || h.col > colDisableAfter)) {
1399
+ td.style.display = "none";
1400
+ }
1401
+
1402
+ assumptionSubscribe(td, {key:[], flatKey:''}, rowAttrs, h, colAttrs, val);
1403
+
1404
+ results.push(tr.appendChild(td));
1405
+ }
1406
+ createGrandTotalBolder(tr);
1407
+ return results;
1408
+ };
1409
+ buildGrandTotal = function(result, tr, rowAttrs, colAttrs) {
1410
+ var td, totalAggregator, val;
1411
+ totalAggregator = allTotal;
1412
+ val = totalAggregator.value();
1413
+ td = createElement("td", "pvtGrandTotal", getFormattedNumber(val, totalAggregator, opts), {
1414
+ "data-value": val
1415
+ }, getTableEventHandlers(val, [], []));
1416
+ createTotalValsBolder(td);
1417
+ assumptionSubscribe(td, {key:[], flatKey:''}, rowAttrs, {key:[], flatKey:''}, colAttrs, val);
1418
+
1419
+ tr.appendChild(td);
1420
+ return result.appendChild(tr);
1421
+ };
1422
+ removeRowHeaderNullValue = function(h) {
1423
+ if (opts.chartOptions.table_options.hide_nulls_in_headers) {
1424
+ h.th.innerHTML = h.th.innerHTML.replace('[null]' , '');
1425
+ }
1426
+ };
1427
+ hideDescendantCol = function(d) {
1428
+ 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");
1429
+ };
1430
+ collapseShowColSubtotal = function(h) {
1431
+ $(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', "");
1432
+ h.th.innerHTML = " " + arrowCollapsed + " " + h.th.getAttribute("data-colheader");
1433
+ return h.th.colSpan = 1;
1434
+ };
1435
+ collapseCol = function(colHeaderHeaders, colHeaderCols, c) {
1436
+ var colHeaderHeader, colspan, d, h, i, isColSubtotal, k, l, p, ref10, ref8, ref9, results;
1437
+ if (isColDisable) {
1438
+ return;
1439
+ }
1440
+ if (isColDisableExpandCollapse) {
1441
+ return;
1442
+ }
1443
+ if (!colHeaderCols[c]) {
1444
+ return;
1445
+ }
1446
+ h = colHeaderCols[c];
1447
+ if (h.col > colDisableAfter) {
1448
+ return;
1449
+ }
1450
+ if (h.clickStatus === clickStatusCollapsed) {
1451
+ return;
1452
+ }
1453
+ isColSubtotal = h.descendants !== 0;
1454
+ colspan = h.th.colSpan;
1455
+ for (i = k = 1, ref8 = h.descendants; 1 <= ref8 ? k <= ref8 : k >= ref8; i = 1 <= ref8 ? ++k : --k) {
1456
+ if (!(h.descendants !== 0)) {
1457
+ continue;
1458
+ }
1459
+ d = colHeaderCols[c - i];
1460
+ hideDescendantCol(d);
1461
+ }
1462
+ if (isColSubtotal) {
1463
+ collapseShowColSubtotal(h);
1464
+ --colspan;
1465
+ }
1466
+ p = h.parent;
1467
+ while (p !== null) {
1468
+ p.th.colSpan -= colspan;
1469
+ p = p.parent;
1470
+ }
1471
+ h.clickStatus = clickStatusCollapsed;
1472
+ colHeaderHeader = colHeaderHeaders[h.col];
1473
+ colHeaderHeader.expandedCount--;
1474
+ if (colHeaderHeader.expandedCount === 0) {
1475
+ results = [];
1476
+ for (i = l = ref9 = h.col, ref10 = colHeaderHeaders.length - 2; ref9 <= ref10 ? l <= ref10 : l >= ref10; i = ref9 <= ref10 ? ++l : --l) {
1477
+ if (!(i <= colDisableAfter)) {
1478
+ continue;
1479
+ }
1480
+ colHeaderHeader = colHeaderHeaders[i];
1481
+ replaceClass(colHeaderHeader.th, classExpanded, classCollapsed);
1482
+ colHeaderHeader.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(colHeaderHeader.th.getAttribute("data-colAttr"));
1483
+ results.push(colHeaderHeader.clickStatus = clickStatusCollapsed);
1484
+ }
1485
+ return results;
1486
+ }
1487
+ };
1488
+ showChildCol = function(ch) {
1489
+ 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', "");
1490
+ };
1491
+ expandHideColSubtotal = function(h) {
1492
+ $(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");
1493
+ return h.th.style.display = "";
1494
+ };
1495
+ expandShowColSubtotal = function(h) {
1496
+ $(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', "");
1497
+ h.th.style.display = "";
1498
+ ++h.th.colSpan;
1499
+ if (h.sTh != null) {
1500
+ return h.sTh.style.display = "";
1501
+ }
1502
+ };
1503
+ expandChildCol = function(ch) {
1504
+ var gch, k, len, ref8, results;
1505
+ if (ch.descendants !== 0 && hasClass(ch.th, classColExpanded) && (isColHideOnExpand || isColDisable || ch.col > colDisableAfter)) {
1506
+ ch.th.style.display = "";
1507
+ } else {
1508
+ showChildCol(ch);
1509
+ }
1510
+ if (ch.clickStatus !== clickStatusCollapsed) {
1511
+ ref8 = ch.children;
1512
+ results = [];
1513
+ for (k = 0, len = ref8.length; k < len; k++) {
1514
+ gch = ref8[k];
1515
+ results.push(expandChildCol(gch));
1516
+ }
1517
+ return results;
1518
+ }
1519
+ };
1520
+ expandCol = function(colHeaderHeaders, colHeaderCols, c) {
1521
+ var ch, colspan, h, hh, isColSubtotal, k, len, p, ref8;
1522
+ if (isColDisable) {
1523
+ return;
1524
+ }
1525
+ if (isColDisableExpandCollapse) {
1526
+ return;
1527
+ }
1528
+ if (!colHeaderCols[c]) {
1529
+ return;
1530
+ }
1531
+ h = colHeaderCols[c];
1532
+ if (h.col > colDisableAfter) {
1533
+ return;
1534
+ }
1535
+ if (h.clickStatus === clickStatusExpanded) {
1536
+ return;
1537
+ }
1538
+ isColSubtotal = h.descendants !== 0;
1539
+ colspan = 0;
1540
+ ref8 = h.children;
1541
+ for (k = 0, len = ref8.length; k < len; k++) {
1542
+ ch = ref8[k];
1543
+ expandChildCol(ch);
1544
+ colspan += ch.th.colSpan;
1545
+ }
1546
+ h.th.colSpan = colspan;
1547
+ if (isColSubtotal) {
1548
+ replaceClass(h.th, classColCollapsed, classColExpanded);
1549
+ h.th.innerHTML = " " + arrowExpanded + " " + h.th.getAttribute("data-colHeader");
1550
+ if (isColHideOnExpand) {
1551
+ expandHideColSubtotal(h);
1552
+ --colspan;
1553
+ } else {
1554
+ expandShowColSubtotal(h);
1555
+ }
1556
+ }
1557
+ p = h.parent;
1558
+ while (p) {
1559
+ p.th.colSpan += colspan;
1560
+ p = p.parent;
1561
+ }
1562
+ h.clickStatus = clickStatusExpanded;
1563
+ hh = colHeaderHeaders[h.col];
1564
+ ++hh.expandedCount;
1565
+ if (hh.expandedCount === hh.nHeaders) {
1566
+ replaceClass(hh.th, classCollapsed, classExpanded);
1567
+ hh.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(hh.th.getAttribute("data-colAttr"));
1568
+ return hh.clickStatus = clickStatusExpanded;
1569
+ }
1570
+ };
1571
+ collapseHideDescendantRow = function(h) {
1572
+ var cell, cells, k, len, ref8, results, tagName;
1573
+ h.tr.style.display = "none";
1574
+ ref8 = ["td", "th"];
1575
+ results = [];
1576
+ for (k = 0, len = ref8.length; k < len; k++) {
1577
+ tagName = ref8[k];
1578
+ cells = h.tr.getElementsByTagName(tagName);
1579
+ results.push((function() {
1580
+ var l, len1, results1;
1581
+ results1 = [];
1582
+ for (l = 0, len1 = cells.length; l < len1; l++) {
1583
+ cell = cells[l];
1584
+ replaceClass(cell, classRowShow, classRowHide);
1585
+ results1.push(cell.style.display = "none");
1586
+ }
1587
+ return results1;
1588
+ })());
1589
+ }
1590
+ return results;
1591
+ };
1592
+ collapseShowRowSubtotal = function(h) {
1593
+ var cell, cells, k, l, len, len1, ref8, tagName;
1594
+ ref8 = ["td", "th"];
1595
+ for (k = 0, len = ref8.length; k < len; k++) {
1596
+ tagName = ref8[k];
1597
+ cells = h.tr.getElementsByTagName(tagName);
1598
+ for (l = 0, len1 = cells.length; l < len1; l++) {
1599
+ cell = cells[l];
1600
+ removeClass(cell, classRowExpanded + " " + classRowHide);
1601
+ addClass(cell, classRowCollapsed + " " + classRowShow);
1602
+ if (!hasClass(cell, classColHide)) {
1603
+ cell.style.display = "";
1604
+ }
1605
+ }
1606
+ }
1607
+ h.th.rowSpan = 1;
1608
+ h.th.innerHTML = " " + arrowCollapsed + " " + h.th.getAttribute("data-rowHeader");
1609
+ return replaceClass(h.tr, classRowExpanded, classRowCollapsed);
1610
+ };
1611
+ collapseRow = function(rowHeaderHeaders, rowHeaderRows, r) {
1612
+ var d, h, i, isRowSubtotal, j, k, l, p, ref10, ref8, ref9, results, rowHeaderHeader, rowspan;
1613
+ if (isRowDisable) {
1614
+ return;
1615
+ }
1616
+ if (isRowDisableExpandCollapse) {
1617
+ return;
1618
+ }
1619
+ if (!rowHeaderRows[r]) {
1620
+ return;
1621
+ }
1622
+ h = rowHeaderRows[r];
1623
+ if (h.col > rowDisableAfter) {
1624
+ return;
1625
+ }
1626
+ if (h.clickStatus === clickStatusCollapsed) {
1627
+ return;
1628
+ }
1629
+ isRowSubtotal = h.descendants !== 0;
1630
+ rowspan = h.th.rowSpan;
1631
+ for (i = k = 1, ref8 = h.descendants; 1 <= ref8 ? k <= ref8 : k >= ref8; i = 1 <= ref8 ? ++k : --k) {
1632
+ if (!(h.descendants !== 0)) {
1633
+ continue;
1634
+ }
1635
+ d = rowHeaderRows[r + i];
1636
+ collapseHideDescendantRow(d);
1637
+ }
1638
+ if (isRowSubtotal) {
1639
+ collapseShowRowSubtotal(h);
1640
+ --rowspan;
1641
+ }
1642
+
1643
+ removeRowHeaderNullValue(h);
1644
+
1645
+ p = h.parent;
1646
+ while (p) {
1647
+ p.th.rowSpan -= rowspan;
1648
+ p = p.parent;
1649
+ }
1650
+ h.clickStatus = clickStatusCollapsed;
1651
+ rowHeaderHeader = rowHeaderHeaders.hh[h.col];
1652
+ rowHeaderHeader.expandedCount--;
1653
+ if (rowHeaderHeader.expandedCount !== 0) {
1654
+ return;
1655
+ }
1656
+ results = [];
1657
+ for (j = l = ref9 = h.col, ref10 = rowHeaderHeaders.hh.length - 2; ref9 <= ref10 ? l <= ref10 : l >= ref10; j = ref9 <= ref10 ? ++l : --l) {
1658
+ if (!(j <= rowDisableAfter)) {
1659
+ continue;
1660
+ }
1661
+ rowHeaderHeader = rowHeaderHeaders.hh[j];
1662
+ replaceClass(rowHeaderHeader.th, classExpanded, classCollapsed);
1663
+ rowHeaderHeader.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(rowHeaderHeader.th.getAttribute("data-rowAttr"));
1664
+ results.push(rowHeaderHeader.clickStatuatus = clickStatusCollapsed);
1665
+ }
1666
+ return results;
1667
+ };
1668
+ showChildRow = function(h) {
1669
+ var cell, cells, k, l, len, len1, ref8, tagName;
1670
+ ref8 = ["td", "th"];
1671
+ for (k = 0, len = ref8.length; k < len; k++) {
1672
+ tagName = ref8[k];
1673
+ cells = h.tr.getElementsByTagName(tagName);
1674
+ for (l = 0, len1 = cells.length; l < len1; l++) {
1675
+ cell = cells[l];
1676
+ replaceClass(cell, classRowHide, classRowShow);
1677
+ if (!hasClass(cell, classColHide)) {
1678
+ cell.style.display = "";
1679
+ }
1680
+ }
1681
+ }
1682
+ return h.tr.style.display = "";
1683
+ };
1684
+ expandShowRowSubtotal = function(h) {
1685
+ var cell, cells, k, l, len, len1, ref8, tagName;
1686
+ ref8 = ["td", "th"];
1687
+ for (k = 0, len = ref8.length; k < len; k++) {
1688
+ tagName = ref8[k];
1689
+ cells = h.tr.getElementsByTagName(tagName);
1690
+ for (l = 0, len1 = cells.length; l < len1; l++) {
1691
+ cell = cells[l];
1692
+ removeClass(cell, classRowCollapsed + " " + classRowHide);
1693
+ addClass(cell, classRowExpanded + " " + classRowShow);
1694
+ if (!hasClass(cell, classColHide)) {
1695
+ cell.style.display = "";
1696
+ }
1697
+ }
1698
+ }
1699
+ h.th.innerHTML = " " + arrowExpanded + " " + h.th.getAttribute("data-rowHeader");
1700
+ return replaceClass(h.tr, classRowCollapsed, classRowExpanded);
1701
+ };
1702
+ expandHideRowSubtotal = function(h) {
1703
+ var cell, cells, k, l, len, len1, ref8, tagName;
1704
+ ref8 = ["td", "th"];
1705
+ for (k = 0, len = ref8.length; k < len; k++) {
1706
+ tagName = ref8[k];
1707
+ cells = h.tr.getElementsByTagName(tagName);
1708
+ for (l = 0, len1 = cells.length; l < len1; l++) {
1709
+ cell = cells[l];
1710
+ removeClass(cell, classRowCollapsed + " " + classRowShow);
1711
+ addClass(cell, classRowExpanded + " " + classRowHide);
1712
+ cell.style.display = "none";
1713
+ }
1714
+ }
1715
+ h.th.style.display = "";
1716
+ h.th.innerHTML = " " + arrowExpanded + " " + h.th.getAttribute("data-rowHeader");
1717
+ return replaceClass(h.tr, classRowCollapsed, classRowExpanded);
1718
+ };
1719
+ expandChildRow = function(ch) {
1720
+ var gch, k, len, ref8, results;
1721
+ if (ch.descendants !== 0 && hasClass(ch.th, classRowExpanded) && (isRowHideOnExpand || isRowDisable || ch.col > rowDisableAfter)) {
1722
+ ch.tr.style.display = "";
1723
+ ch.th.style.display = "";
1724
+ } else {
1725
+ showChildRow(ch);
1726
+ }
1727
+ if (ch.clickStatus !== clickStatusCollapsed) {
1728
+ ref8 = ch.children;
1729
+ results = [];
1730
+ for (k = 0, len = ref8.length; k < len; k++) {
1731
+ gch = ref8[k];
1732
+ results.push(expandChildRow(gch));
1733
+ }
1734
+ return results;
1735
+ }
1736
+ };
1737
+ expandRow = function(rowHeaderHeaders, rowHeaderRows, r) {
1738
+ var ch, h, hh, isRowSubtotal, k, len, p, ref8, rowspan;
1739
+ if (isRowDisable) {
1740
+ return;
1741
+ }
1742
+ if (isRowDisableExpandCollapse) {
1743
+ return;
1744
+ }
1745
+ if (!rowHeaderRows[r]) {
1746
+ return;
1747
+ }
1748
+ h = rowHeaderRows[r];
1749
+ if (h.col > rowDisableAfter) {
1750
+ return;
1751
+ }
1752
+ if (h.clickStatus === clickStatusExpanded) {
1753
+ return;
1754
+ }
1755
+ isRowSubtotal = h.descendants !== 0;
1756
+ rowspan = 0;
1757
+ ref8 = h.children;
1758
+ for (k = 0, len = ref8.length; k < len; k++) {
1759
+ ch = ref8[k];
1760
+ expandChildRow(ch);
1761
+ rowspan += ch.th.rowSpan;
1762
+ }
1763
+ h.th.rowSpan = rowspan + 1;
1764
+ if (isRowSubtotal) {
1765
+ if (isRowHideOnExpand) {
1766
+ expandHideRowSubtotal(h);
1767
+ } else {
1768
+ expandShowRowSubtotal(h);
1769
+ }
1770
+ }
1771
+
1772
+ removeRowHeaderNullValue(h);
1773
+
1774
+ p = h.parent;
1775
+ while (p) {
1776
+ p.th.rowSpan += rowspan;
1777
+ p = p.parent;
1778
+ }
1779
+ h.clickStatus = clickStatusExpanded;
1780
+ hh = rowHeaderHeaders.hh[h.col];
1781
+ ++hh.expandedCount;
1782
+ if (hh.expandedCount === hh.nHeaders) {
1783
+ replaceClass(hh.th, classCollapsed, classExpanded);
1784
+ hh.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(hh.th.getAttribute("data-rowAttr"));
1785
+ return hh.clickStatus = clickStatusExpanded;
1786
+ }
1787
+ };
1788
+ toggleCol = function(colHeaderHeaders, colHeaderCols, c) {
1789
+ var h, allClass, mainClass, is_other, main_th;
1790
+ if (colHeaderCols[c] == null) {
1791
+ return;
1792
+ }
1793
+ h = colHeaderCols[c];
1794
+ if (h.clickStatus === clickStatusCollapsed) {
1795
+ allClass = classColCollapsed;
1796
+ mainClass = classCollapsed;
1797
+ expandCol(colHeaderHeaders, colHeaderCols, c);
1798
+ } else {
1799
+ collapseCol(colHeaderHeaders, colHeaderCols, c);
1800
+ mainClass = classExpanded;
1801
+ allClass = classColExpanded;
1802
+ }
1803
+
1804
+ is_other = $('.pvtColLabel.'+allClass,h.tr).not('.pvtColSubtotal').length;
1805
+ if(is_other == 0){
1806
+ $('.pvtAxisLabel.'+mainClass,h.tr).trigger( "click" );
1807
+ }
1808
+
1809
+ return h.th.scrollIntoView;
1810
+ };
1811
+ toggleRow = function(rowHeaderHeaders, rowHeaderRows, r) {
1812
+ var h, allClass, mainClass, is_other, main_th, hh;
1813
+
1814
+ if (rowHeaderRows[r] == null) {
1815
+ return;
1816
+ }
1817
+
1818
+ h = rowHeaderRows[r];
1819
+
1820
+ if (rowHeaderRows[r].clickStatus === clickStatusCollapsed) {
1821
+ expandRow(rowHeaderHeaders, rowHeaderRows, r);
1822
+ allClass = clickStatusCollapsed;
1823
+ mainClass = classCollapsed;
1824
+ } else {
1825
+ collapseRow(rowHeaderHeaders, rowHeaderRows, r);
1826
+ allClass = clickStatusExpanded;
1827
+ mainClass = classExpanded;
1828
+
1829
+ /*is_other = _.find(rowHeaderRows, {col:h.col, clickStatus:allClass});
1830
+ if(!is_other){
1831
+ hh = rowHeaderHeaders.hh[h.col];
1832
+ if(hh && hh.th && $(hh.th).hasClass(mainClass)){
1833
+ $(hh.th).trigger('click');
1834
+ }
1835
+ }*/
1836
+ }
1837
+
1838
+ return h.th.scrollIntoView;
1839
+ };
1840
+ collapseColsAt = function(colHeaderHeaders, colHeaderCols, colAttrs, colAttr) {
1841
+ var h, hh, i, idx, nAttrs, nCols, results;
1842
+ if (isColDisable) {
1843
+ return;
1844
+ }
1845
+ if (typeof colAttr === 'string') {
1846
+ idx = colAttrs.indexOf(colAttr);
1847
+ } else {
1848
+ idx = colAttr;
1849
+ }
1850
+ if (idx < 0 || idx === colAttrs.length - 1) {
1851
+ return;
1852
+ }
1853
+ i = idx;
1854
+ nAttrs = colAttrs.length - 1;
1855
+ while (i < nAttrs && i <= colDisableAfter) {
1856
+ hh = colHeaderHeaders[i];
1857
+ replaceClass(hh.th, classExpanded, classCollapsed);
1858
+ hh.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(colAttrs[i]);
1859
+ hh.clickStatus = clickStatusCollapsed;
1860
+ ++i;
1861
+ }
1862
+ i = 0;
1863
+ nCols = colHeaderCols.length;
1864
+ results = [];
1865
+ while (i < nCols) {
1866
+ h = colHeaderCols[i];
1867
+ if (h.col === idx && h.clickStatus !== clickStatusCollapsed && h.th.style.display !== "none") {
1868
+ collapseCol(colHeaderHeaders, colHeaderCols, parseInt(h.th.getAttribute("data-colnode")));
1869
+ }
1870
+ results.push(++i);
1871
+ }
1872
+ return results;
1873
+ };
1874
+ expandColsAt = function(colHeaderHeaders, colHeaderCols, colAttrs, colAttr) {
1875
+ var colHeaderHeader, h, hh, i, idx, j, k, nCols, ref8, results;
1876
+ if (isColDisable) {
1877
+ return;
1878
+ }
1879
+ if (typeof colAttr === 'string') {
1880
+ idx = colAttrs.indexOf(colAttr);
1881
+ } else {
1882
+ idx = colAttr;
1883
+ }
1884
+ if (idx < 0 || idx === colAttrs.length - 1) {
1885
+ return;
1886
+ }
1887
+ for (i = k = 0, ref8 = idx; 0 <= ref8 ? k <= ref8 : k >= ref8; i = 0 <= ref8 ? ++k : --k) {
1888
+ if (i <= colDisableAfter) {
1889
+ hh = colHeaderHeaders[i];
1890
+ replaceClass(hh.th, classCollapsed, classExpanded);
1891
+ hh.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(colAttrs[i]);
1892
+ hh.clickStatus = clickStatusExpanded;
1893
+ }
1894
+ j = 0;
1895
+ nCols = colHeaderCols.length;
1896
+ while (j < nCols) {
1897
+ h = colHeaderCols[j];
1898
+ if (h.col === i) {
1899
+ expandCol(colHeaderHeaders, colHeaderCols, j);
1900
+ }
1901
+ ++j;
1902
+ }
1903
+ }
1904
+ ++idx;
1905
+ results = [];
1906
+ while (idx < colAttrs.length - 1 && idx <= colDisableAfter) {
1907
+ colHeaderHeader = colHeaderHeaders[idx];
1908
+ if (colHeaderHeader.expandedCount === 0) {
1909
+ replaceClass(colHeaderHeader.th, classExpanded, classCollapsed);
1910
+ colHeaderHeader.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(colAttrs[idx]);
1911
+ colHeaderHeader.clickStatus = clickStatusCollapsed;
1912
+ } else if (colHeaderHeader.expandedCount === colHeaderHeader.nHeaders) {
1913
+ replaceClass(colHeaderHeader.th, classCollapsed, classExpanded);
1914
+ colHeaderHeader.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(colAttrs[idx]);
1915
+ colHeaderHeader.clickStatus = clickStatusExpanded;
1916
+ }
1917
+ results.push(++idx);
1918
+ }
1919
+ return results;
1920
+ };
1921
+ collapseRowsAt = function(rowHeaderHeaders, rowHeaderRows, rowAttrs, rowAttr) {
1922
+ var h, i, idx, j, nAttrs, nRows, results;
1923
+ if (isRowDisable) {
1924
+ return;
1925
+ }
1926
+ if (typeof rowAttr === 'string') {
1927
+ idx = rowAttrs.indexOf(rowAttr);
1928
+ } else {
1929
+ idx = rowAttr;
1930
+ }
1931
+ if (idx < 0 || idx === rowAttrs.length - 1) {
1932
+ return;
1933
+ }
1934
+ i = idx;
1935
+ nAttrs = rowAttrs.length - 1;
1936
+ while (i < nAttrs && i <= rowDisableAfter) {
1937
+ h = rowHeaderHeaders.hh[i];
1938
+ replaceClass(h.th, classExpanded, classCollapsed);
1939
+ h.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(rowAttrs[i]);
1940
+ h.clickStatus = clickStatusCollapsed;
1941
+ ++i;
1942
+ }
1943
+ j = 0;
1944
+ nRows = rowHeaderRows.length;
1945
+ results = [];
1946
+ while (j < nRows) {
1947
+ h = rowHeaderRows[j];
1948
+ if (h.col === idx && h.clickStatus !== clickStatusCollapsed && h.tr.style.display !== "none") {
1949
+ collapseRow(rowHeaderHeaders, rowHeaderRows, j);
1950
+ results.push(j = j + h.descendants + 1);
1951
+ } else {
1952
+ results.push(++j);
1953
+ }
1954
+ }
1955
+ return results;
1956
+ };
1957
+ expandRowsAt = function(rowHeaderHeaders, rowHeaderRows, rowAttrs, rowAttr) {
1958
+ var h, hh, i, idx, j, k, nRows, ref8, results, rowHeaderHeader;
1959
+ if (isRowDisable) {
1960
+ return;
1961
+ }
1962
+ if (typeof rowAttr === 'string') {
1963
+ idx = rowAttrs.indexOf(rowAttr);
1964
+ } else {
1965
+ idx = rowAttr;
1966
+ }
1967
+ if (idx < 0 || idx === rowAttrs.length - 1) {
1968
+ return;
1969
+ }
1970
+ for (i = k = 0, ref8 = idx; 0 <= ref8 ? k <= ref8 : k >= ref8; i = 0 <= ref8 ? ++k : --k) {
1971
+ if (i <= rowDisableAfter) {
1972
+ hh = rowHeaderHeaders.hh[i];
1973
+ replaceClass(hh.th, classCollapsed, classExpanded);
1974
+ hh.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(rowAttrs[i]);
1975
+ hh.clickStatus = clickStatusExpanded;
1976
+ }
1977
+ j = 0;
1978
+ nRows = rowHeaderRows.length;
1979
+ while (j < nRows) {
1980
+ h = rowHeaderRows[j];
1981
+ if (h.col === i) {
1982
+ expandRow(rowHeaderHeaders, rowHeaderRows, j);
1983
+ j += h.descendants + 1;
1984
+ } else {
1985
+ ++j;
1986
+ }
1987
+ }
1988
+ }
1989
+ ++idx;
1990
+ results = [];
1991
+ while (idx < rowAttrs.length - 1 && idx <= rowDisableAfter) {
1992
+ rowHeaderHeader = rowHeaderHeaders.hh[idx];
1993
+ if (rowHeaderHeader.expandedCount === 0) {
1994
+ replaceClass(rowHeaderHeader.th, classExpanded, classCollapsed);
1995
+ rowHeaderHeader.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(rowAttrs[idx]);
1996
+ rowHeaderHeader.clickStatus = clickStatusCollapsed;
1997
+ } else if (rowHeaderHeader.expandedCount === rowHeaderHeader.nHeaders) {
1998
+ replaceClass(rowHeaderHeader.th, classCollapsed, classExpanded);
1999
+ rowHeaderHeader.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(rowAttrs[idx]);
2000
+ rowHeaderHeader.clickStatus = clickStatusExpanded;
2001
+ }
2002
+ results.push(++idx);
2003
+ }
2004
+ return results;
2005
+ };
2006
+ toggleColHeaderHeader = function(colHeaderHeaders, colHeaderCols, colAttrs, colAttr) {
2007
+ var h, idx;
2008
+ if (isColDisable) {
2009
+ return;
2010
+ }
2011
+ if (isColDisableExpandCollapse) {
2012
+ return;
2013
+ }
2014
+ idx = colAttrs.indexOf(colAttr);
2015
+ h = colHeaderHeaders[idx];
2016
+ if (h.col > colDisableAfter) {
2017
+ return;
2018
+ }
2019
+ if (h.clickStatus === clickStatusCollapsed) {
2020
+ h.clickStatus = clickStatusExpanded;
2021
+ h.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(colAttr);
2022
+ replaceClass(h.th, classCollapsed, classExpanded);
2023
+ return expandColsAt(colHeaderHeaders, colHeaderCols, colAttrs, colAttr);
2024
+ } else {
2025
+ h.clickStatus = clickStatusCollapsed;
2026
+ h.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(colAttr);
2027
+ replaceClass(h.th, classExpanded, classCollapsed);
2028
+ return collapseColsAt(colHeaderHeaders, colHeaderCols, colAttrs, colAttr);
2029
+ }
2030
+ };
2031
+ toggleRowHeaderHeader = function(rowHeaderHeaders, rowHeaderRows, rowAttrs, rowAttr) {
2032
+ var idx, th;
2033
+ if (isRowDisable) {
2034
+ return;
2035
+ }
2036
+ if (isRowDisableExpandCollapse) {
2037
+ return;
2038
+ }
2039
+ idx = rowAttrs.indexOf(rowAttr);
2040
+ th = rowHeaderHeaders.hh[idx];
2041
+ if (th.col > rowDisableAfter) {
2042
+ return;
2043
+ }
2044
+ if (th.clickStatus === clickStatusCollapsed) {
2045
+ th.clickStatus = clickStatusExpanded;
2046
+ th.th.innerHTML = " " + arrowExpanded + " " + opts.labelsConvertFunction(rowAttr);
2047
+ replaceClass(th.th, classCollapsed, classExpanded);
2048
+ return expandRowsAt(rowHeaderHeaders, rowHeaderRows, rowAttrs, rowAttr);
2049
+ } else {
2050
+ th.clickStatus = clickStatusCollapsed;
2051
+ th.th.innerHTML = " " + arrowCollapsed + " " + opts.labelsConvertFunction(rowAttr);
2052
+ replaceClass(th.th, classExpanded, classCollapsed);
2053
+ return collapseRowsAt(rowHeaderHeaders, rowHeaderRows, rowAttrs, rowAttr);
2054
+ }
2055
+ };
2056
+
2057
+ handleFreezePanesScroll = function(freezableElements) {
2058
+ return function(event) {
2059
+ if (event.target.dataset.canFreezePanes) return;
2060
+
2061
+ const wrapper = event.target;
2062
+
2063
+ const translateY = `translate(0px, ${wrapper.scrollTop}px)`;
2064
+ const translateX = `translate(${wrapper.scrollLeft}px, 0px)`;
2065
+ const translateXY = `translate(${wrapper.scrollLeft}px, ${wrapper.scrollTop}px)`;
2066
+
2067
+ _.forEach(freezableElements, function (element) {
2068
+ let currentTranslate = translateY;
2069
+ currentTranslate = element.className.includes(elementToTransform.X) ? translateX : currentTranslate;
2070
+ currentTranslate = element.className.includes(elementToTransform.XY) ? translateXY : currentTranslate;
2071
+ element.style.transform = currentTranslate;
2072
+ });
2073
+ }
2074
+ };
2075
+
2076
+ selectFreezableElements = function(wrapper) {
2077
+ const selectString =_.map(Object.values(elementToTransform), function (item) {
2078
+ return `.${item.replace(' ', '')}`;
2079
+ }).join(',');
2080
+ return Array.from(wrapper.querySelectorAll(selectString));
2081
+ }
2082
+
2083
+ main = function(rowAttrs, rowKeys, colAttrs, colKeys) {
2084
+ var c,rowspan, colHeaderCols, colHeaderHeaders, colHeaders, h, k, l, len, len1, result, rowHeaderHeaders, rowHeaderRows, rowHeaders, tbody, thead, tr;
2085
+ rowHeaders = [];
2086
+ colHeaders = [];
2087
+ rowHeaderHeaders = {};
2088
+ rowHeaderRows = [];
2089
+ colHeaderHeaders = [];
2090
+ colHeaderCols = [];
2091
+ if (rowAttrs.length > 0 && rowKeys.length > 0) {
2092
+ rowHeaders = processKeys(rowKeys, "pvtRowLabel", 'rows', rowAttrs);
2093
+ }
2094
+ if (colAttrs.length > 0 && colKeys.length > 0) {
2095
+ colHeaders = processKeys(colKeys, "pvtColLabel", 'cols', colAttrs);
2096
+ }
2097
+ var tableClasses = useNewUx && opts.chartOptions.table_options.use_new_table_design ? 'pvtTable newPvtTable' : 'pvtTable';
2098
+ result = createElement("table", tableClasses , null, {
2099
+ style: "display: none;"
2100
+ });
2101
+
2102
+ colorizeTableIfNeed(result);
2103
+
2104
+ thead = createElement("thead");
2105
+ result.appendChild(thead);
2106
+ if (colAttrs.length > 0) {
2107
+ buildColHeaderHeaders(thead, colHeaderHeaders, rowAttrs, colAttrs);
2108
+ for (k = 0, len = colHeaders.length; k < len; k++) {
2109
+ h = colHeaders[k];
2110
+ buildColHeaders(colHeaderHeaders, colHeaderCols, h, rowAttrs, colAttrs);
2111
+ }
2112
+ buildColHeaderHeadersClickEvents(colHeaderHeaders, colHeaderCols, colAttrs);
2113
+ }
2114
+ if (rowAttrs.length > 0) {
2115
+ buildRowHeaderHeaders(thead, rowHeaderHeaders, rowAttrs, colAttrs);
2116
+ if (colAttrs.length === 0 && opts.chartOptions.table_options.show_row_total) {
2117
+ buildRowTotalsHeader(rowHeaderHeaders.tr, rowAttrs, colAttrs);
2118
+ }
2119
+ }
2120
+ if (colAttrs.length > 0 && opts.chartOptions.table_options.show_row_total) {
2121
+ buildRowTotalsHeader(colHeaderHeaders[0].tr, rowAttrs, colAttrs);
2122
+ if(opts.chartOptions.table_options.colorize_headers == true){
2123
+ for (c=1; c<colHeaderHeaders.length; c++){
2124
+ rowspan = 1;
2125
+ if(c == colHeaderHeaders.length-1){
2126
+ rowspan = 2;
2127
+ }
2128
+ colHeaderHeaders[c].tr.appendChild(createElement("th", verticalFreezePaneClass, "",{rowspan: rowspan}));
2129
+ if (opts.chartOptions.table_options.freeze_panes) {
2130
+ getHeaderColorProperties(colHeaderHeaders[c].tr, c);
2131
+ }
2132
+ }
2133
+ }
2134
+ }
2135
+ tbody = createElement("tbody");
2136
+ result.appendChild(tbody);
2137
+
2138
+ const hasColLabels = !!thead.querySelector('.pvtColLabel');
2139
+
2140
+ if (rowAttrs.length > 0) {
2141
+ for (l = 0, len1 = rowHeaders.length; l < len1; l++) {
2142
+ h = rowHeaders[l];
2143
+ buildRowHeaders(tbody, rowHeaderHeaders, rowHeaderRows, h, rowAttrs, colAttrs, l%2 === 0, hasColLabels);
2144
+ }
2145
+ }
2146
+ buildRowHeaderHeadersClickEvents(rowHeaderHeaders, rowHeaderRows, rowAttrs);
2147
+ buildValues(rowHeaderRows, colHeaderCols, rowAttrs, colAttrs);
2148
+ if(opts.chartOptions.table_options.show_column_total){
2149
+ tr = buildColTotalsHeader(rowAttrs, colAttrs);
2150
+ if (colAttrs.length > 0) {
2151
+ buildColTotals(tr, colHeaderCols, rowAttrs, colAttrs);
2152
+ }
2153
+ if(opts.chartOptions.table_options.show_row_total)
2154
+ buildGrandTotal(tbody, tr, rowAttrs, colAttrs);
2155
+ else
2156
+ tbody.appendChild(tr);
2157
+ }
2158
+
2159
+ result.setAttribute("data-numrows", rowKeys.length);
2160
+ result.setAttribute("data-numcols", colKeys.length);
2161
+ if ((opts.collapseRowsAt == null) && (opts.collapseColsAt == null)) {
2162
+ result.style.display = "";
2163
+ }
2164
+ if (opts.collapseRowsAt != null) {
2165
+ collapseRowsAt(rowHeaderHeaders, rowHeaderRows, rowAttrs, opts.collapseRowsAt);
2166
+ }
2167
+ if (opts.collapseColsAt != null) {
2168
+ collapseColsAt(colHeaderHeaders, colHeaderCols, colAttrs, opts.collapseColsAt);
2169
+ }
2170
+ result.style.display = "";
2171
+
2172
+ var resultsArr = [];
2173
+ var additionOptions = opts.chartOptions ? opts.chartOptions : null;
2174
+
2175
+ if (opts && opts.chart_title && !opts.chartOptions.hideChartHeader) {
2176
+ var title = document.createElement("div");
2177
+ title.className = "title";
2178
+ title.innerText = opts.chart_title;
2179
+ resultsArr.push(title);
2180
+ }
2181
+
2182
+ if (additionOptions && additionOptions.subtitle && !opts.chartOptions.hideChartHeader) {
2183
+ var subTitle = document.createElement("div");
2184
+ subTitle.className = "sub-title";
2185
+ subTitle.innerText = additionOptions.subtitle.subtitle;
2186
+ resultsArr.push(subTitle);
2187
+ }
2188
+
2189
+ if (tooMuch) {
2190
+ 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>'));
2191
+ } else {
2192
+ var tableContainer = document.createElement("div");
2193
+ tableContainer.className = "pivot-div";
2194
+ tableContainer.appendChild(result);
2195
+ if (opts.chartOptions.table_options.freeze_panes) {
2196
+ tableContainer.onscroll = handleFreezePanesScroll(selectFreezableElements(tableContainer));
2197
+ }
2198
+ resultsArr.push(tableContainer);
2199
+ }
2200
+
2201
+ var wrapper = document.createElement("div");
2202
+ wrapper.className = "pivot-wrapper";
2203
+
2204
+ $(wrapper).append(resultsArr);
2205
+
2206
+ return wrapper;
2207
+ };
2208
+ return main(rowAttrs, rowKeys, colAttrs, colKeys);
2209
+ };
2210
+ // $.pivotUtilities.subtotal_renderers = SubtotalRenderer;
2211
+ $.pivotUtilities.subtotal_renderers = NovixRenderer;
2212
+ $.pivotUtilities.delim = delim;
2213
+
2214
+ $.pivotUtilities.getFormattedNumber = getFormattedNumber;
2215
+ $.pivotUtilities.sortDateStrings = sortDateStrings;
2216
+ $.pivotUtilities.largeToSmallSort = largeToSmallSort;
2217
+ $.pivotUtilities.getPivotDataModel = function(input, opts){ return new DRPivotData(input, opts); }
2218
+ $.pivotUtilities.getPivotTableFormula = function(rowData, opts, func, colFields, rowFields, aggregationDefaults, utils) {
2219
+ let totalStr = 'Grand Totals';
2220
+ let pivotData = new DRPivotData(rowData, opts);
2221
+ let rowAttrs = pivotData.rowAttrs;
2222
+ let rowKeys = pivotData.getRowKeys();
2223
+ let colAttrs = pivotData.colAttrs;
2224
+ let colKeys = pivotData.getColKeys();
2225
+
2226
+ if ((rowKeys.length || 1) * (colKeys.length || 1) > 10000) {
2227
+ throw new Error(`Can't create table formula. The table has many rows or columns`);
2228
+ }
2229
+
2230
+ let rowValuesIndex = colAttrs.length;
2231
+ let colValuesIndex = rowAttrs.length;
2232
+ let matrix = [];
2233
+ let colFormulas = [];
2234
+ let rowFormulas = [];
2235
+ let aggregation = utils.getAggregationConfigFromFields(func, colFields, rowFields, aggregationDefaults);
2236
+
2237
+ // Create headers
2238
+ if (rowAttrs && rowAttrs.length && colAttrs && colAttrs.length) {
2239
+ colValuesIndex += 1;
2240
+ rowValuesIndex += 1;
2241
+
2242
+ // Free place in formulas arrays
2243
+ colFormulas = new Array(colValuesIndex).fill(null);
2244
+ rowFormulas = new Array(rowValuesIndex).fill(null);
2245
+
2246
+ for (let i = 0; i < colAttrs.length; i++) {
2247
+ // Free place in row start
2248
+ let headerRow = new Array(rowAttrs.length).fill(null);
2249
+ // Add col field name
2250
+ headerRow.push(colAttrs[i]);
2251
+ // Add row keys
2252
+ _.forEach(colKeys, function (keys) {
2253
+ headerRow.push(utils.getHeaderValue(keys[i], colFields[i].type));
2254
+ // Calc formulas in first time
2255
+ if (i === 0) {
2256
+ colFormulas.push(utils.createKeysFormula(colFields, keys, colFormulas.length + 1, true));
2257
+ }
2258
+ });
2259
+
2260
+ // Add row to matrix
2261
+ matrix.push(headerRow);
2262
+ }
2263
+
2264
+ // Add row fields + free space under cols + Grand Totals right
2265
+ matrix.push(rowAttrs.concat(new Array(colKeys.length + 1).fill(null)).concat(totalStr));
2266
+ // Row Headers
2267
+ for (let i = 0; i < rowKeys.length; i++) {
2268
+ // Formatting row keys
2269
+ let keysFormatted = [];
2270
+ for (let k = 0; k < rowKeys[i].length; k++) {
2271
+ keysFormatted.push(utils.getHeaderValue(rowKeys[i][k], rowFields[k].type))
2272
+ }
2273
+ // Add row keys
2274
+ matrix.push(keysFormatted.concat(null));
2275
+ // Calc formulas
2276
+ rowFormulas.push(utils.createKeysFormula(rowFields, rowKeys[i], rowFormulas.length + 1));
2277
+ }
2278
+ // Add Grand Totals bottom
2279
+ matrix.push(new Array(rowAttrs.length).fill(null).concat(totalStr));
2280
+
2281
+ // Fill values
2282
+ for (let y = rowValuesIndex; y < matrix.length; y++) {
2283
+ for (let x = colValuesIndex; x < matrix[rowValuesIndex - 1].length; x++) {
2284
+ matrix[y][x] = utils.createCellFormula(func, colFormulas[x], rowFormulas[y], aggregation);
2285
+ }
2286
+ }
2287
+ } else if (colAttrs && colAttrs.length) {
2288
+ colFormulas = new Array(null);
2289
+
2290
+ for (let i = 0; i < colAttrs.length; i++) {
2291
+ // Add col field name
2292
+ let headerRow = [colAttrs[i]];
2293
+ // Add keys
2294
+ _.forEach(colKeys, function (keys) {
2295
+ headerRow.push(utils.getHeaderValue(keys[i], colFields[i].type));
2296
+ // Calc formulas in first time
2297
+ if (i === 0) {
2298
+ colFormulas.push(utils.createKeysFormula(colFields, keys, colFormulas.length + 1, true));
2299
+ }
2300
+ });
2301
+
2302
+ // Add row to matrix
2303
+ matrix.push(headerRow);
2304
+ }
2305
+
2306
+ // Add Grand Totals right
2307
+ matrix[matrix.length - 1].push(totalStr);
2308
+ // Add Grand Totals bottom
2309
+ matrix.push([totalStr]);
2310
+
2311
+ // Fill totals
2312
+ for (let x = 1; x < matrix[matrix.length - 2].length; x++) {
2313
+ matrix[matrix.length - 1][x] = utils.createCellFormula(func, colFormulas[x], '', aggregation);
2314
+ }
2315
+ } else if (rowAttrs && rowAttrs.length) {
2316
+ rowFormulas = new Array(null);
2317
+
2318
+ // Add row fields + Grand Totals right
2319
+ matrix.push(rowAttrs.concat(totalStr));
2320
+ // Row Headers
2321
+ for (let i = 0; i < rowKeys.length; i++) {
2322
+ // Formatting row keys
2323
+ let keysFormatted = [];
2324
+ for (let k = 0; k < rowKeys[i].length; k++) {
2325
+ keysFormatted.push(utils.getHeaderValue(rowKeys[i][k], rowFields[k].type))
2326
+ }
2327
+ // Add row keys
2328
+ matrix.push(keysFormatted);
2329
+ // Calc formulas
2330
+ rowFormulas.push(utils.createKeysFormula(rowFields, rowKeys[i], rowFormulas.length + 1));
2331
+ }
2332
+ // Add Grand Totals bottom
2333
+ matrix.push(new Array(rowAttrs.length - 1).fill(null).concat(totalStr));
2334
+
2335
+ // Fill totals
2336
+ for (let y = 1; y < matrix.length; y++) {
2337
+ matrix[y][rowAttrs.length] = utils.createCellFormula(func, '', rowFormulas[y], aggregation);
2338
+ }
2339
+ } else {
2340
+ matrix = [[totalStr, utils.createCellFormula(func, '', '', aggregation)]];
2341
+ }
2342
+
2343
+ return matrix;
2344
+ };
2345
+ };
2346
+
2347
+ module.exports = initDRPivotTable;