@datarailsshared/dr_renderer 1.1.41 → 1.2.2

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