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