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