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