@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.
- package/.circleci/config.yml +86 -0
- package/README.md +23 -23
- package/babel.config.js +3 -0
- package/jest.config.js +27 -0
- package/package.json +50 -28
- package/src/charts/dr_gauge_chart.js +566 -0
- package/src/dataformatter.d.ts +13 -0
- package/src/dataformatter.js +1076 -1023
- package/src/dr-renderer-helpers.js +58 -0
- package/src/dr_chart_tooltip.js +277 -0
- package/src/dr_pivottable.js +2639 -2178
- package/src/graph-table-renderer.js +147 -0
- package/src/highcharts_renderer.js +10020 -6262
- package/src/index.js +27 -21
- package/src/novix_renderer.js +906 -829
- package/src/pivot.css +426 -301
- package/src/pivottable.js +1901 -1824
- package/src/published_items_renderer.js +365 -0
- package/src/seriesPointStyles-helper.js +43 -0
- package/start_run.sh +3 -3
- package/tests/dr-renderer-helpers.test.js +150 -0
- package/tests/dr_chart_tooltip.test.js +739 -0
- package/tests/dr_gauge_chart.test.js +1931 -0
- package/tests/highcharts_renderer.test.js +9358 -0
- package/tests/mock/add-in-dynamic-ranges.json +127 -0
- package/tests/mock/add-in-functions.json +410 -0
- package/tests/mock/add-in-tables.json +347 -0
- package/tests/mock/tables.json +2258 -0
- package/tests/mock/widgets.json +403 -0
- package/tests/seriesPointStyles-helper.test.js +114 -0
- package/tsconfig.json +15 -0
- package/types/graph-table-renderer.d.ts +79 -0
- package/types/index.d.ts +1 -0
package/src/novix_renderer.js
CHANGED
|
@@ -1,829 +1,906 @@
|
|
|
1
|
-
let initNovixRenderer = function($, window, document, Handsontable){
|
|
2
|
-
//register custom editor for format numeric editor
|
|
3
|
-
(function (Handsontable) {
|
|
4
|
-
|
|
5
|
-
var GenericEditor = Handsontable.editors.NumericEditor.prototype.extend();
|
|
6
|
-
|
|
7
|
-
GenericEditor.prototype.beginEditing = function (initialValue) {
|
|
8
|
-
|
|
9
|
-
var BaseEditor = Handsontable.editors.NumericEditor.prototype;
|
|
10
|
-
|
|
11
|
-
if (typeof (initialValue) === 'undefined' && this.originalValue) {
|
|
12
|
-
|
|
13
|
-
var value = '' + this.originalValue;
|
|
14
|
-
if (!isNaN(parseFloat(value))) {
|
|
15
|
-
value = value.replace(",", "");
|
|
16
|
-
value = parseFloat(value).toFixed(10);
|
|
17
|
-
}
|
|
18
|
-
BaseEditor.beginEditing.apply(this, [value]);
|
|
19
|
-
} else {
|
|
20
|
-
BaseEditor.beginEditing.apply(this, arguments);
|
|
21
|
-
}
|
|
22
|
-
BaseEditor.beginEditing.apply(this, [initialValue]);
|
|
23
|
-
};
|
|
24
|
-
Handsontable.editors.GenericEditor = GenericEditor;
|
|
25
|
-
|
|
26
|
-
}(Handsontable));
|
|
27
|
-
|
|
28
|
-
const delim = " , ";
|
|
29
|
-
const subtotal = "subtotalDatarailsPlaceholder";
|
|
30
|
-
const replaceValue = "SubTotals";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
//
|
|
369
|
-
|
|
370
|
-
rowData.push(
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
if (
|
|
444
|
-
rowData.push(
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
if (
|
|
482
|
-
addMergeCell(
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
if (
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
td.
|
|
635
|
-
|
|
636
|
-
if (
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
if
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
if (row < dataSource.fixedRows || col < dataSource.fixedColumns) {
|
|
777
|
-
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
1
|
+
let initNovixRenderer = function($, window, document, Handsontable){
|
|
2
|
+
//register custom editor for format numeric editor
|
|
3
|
+
(function (Handsontable) {
|
|
4
|
+
|
|
5
|
+
var GenericEditor = Handsontable.editors.NumericEditor.prototype.extend();
|
|
6
|
+
|
|
7
|
+
GenericEditor.prototype.beginEditing = function (initialValue) {
|
|
8
|
+
|
|
9
|
+
var BaseEditor = Handsontable.editors.NumericEditor.prototype;
|
|
10
|
+
|
|
11
|
+
if (typeof (initialValue) === 'undefined' && this.originalValue) {
|
|
12
|
+
|
|
13
|
+
var value = '' + this.originalValue;
|
|
14
|
+
if (!isNaN(parseFloat(value))) {
|
|
15
|
+
value = value.replace(",", "");
|
|
16
|
+
value = parseFloat(value).toFixed(10);
|
|
17
|
+
}
|
|
18
|
+
BaseEditor.beginEditing.apply(this, [value]);
|
|
19
|
+
} else {
|
|
20
|
+
BaseEditor.beginEditing.apply(this, arguments);
|
|
21
|
+
}
|
|
22
|
+
BaseEditor.beginEditing.apply(this, [initialValue]);
|
|
23
|
+
};
|
|
24
|
+
Handsontable.editors.GenericEditor = GenericEditor;
|
|
25
|
+
|
|
26
|
+
}(Handsontable));
|
|
27
|
+
|
|
28
|
+
const delim = " , ";
|
|
29
|
+
const subtotal = "subtotalDatarailsPlaceholder";
|
|
30
|
+
const replaceValue = "SubTotals";
|
|
31
|
+
|
|
32
|
+
$.pivotUtilities.novix_renderers = {
|
|
33
|
+
|
|
34
|
+
"Pivot Table": function (pvtData, opts) {
|
|
35
|
+
return $.pivotUtilities.novix_renderers["Input Table"](pvtData, $.extend({}, opts, { readOnly: true }));
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
"Input Table": function (pvtData, opts) {
|
|
39
|
+
|
|
40
|
+
// for (let i in pvtData.input) {
|
|
41
|
+
// pvtData.input[i].value = pvtData.processRecord(pvtData.input[i]);
|
|
42
|
+
// }
|
|
43
|
+
|
|
44
|
+
var table;
|
|
45
|
+
var def = {
|
|
46
|
+
$el: $(document),
|
|
47
|
+
showTotals: true,
|
|
48
|
+
header: {
|
|
49
|
+
className: "header"
|
|
50
|
+
},
|
|
51
|
+
total: {
|
|
52
|
+
className: "total",
|
|
53
|
+
format: "0,0.00"
|
|
54
|
+
},
|
|
55
|
+
subTotal: {
|
|
56
|
+
className: "subTotal",
|
|
57
|
+
format: "0,0.00"
|
|
58
|
+
},
|
|
59
|
+
data: {
|
|
60
|
+
className: "data",
|
|
61
|
+
format: "0,0.00"
|
|
62
|
+
},
|
|
63
|
+
getIndexContent: function (indexName) {
|
|
64
|
+
// to customize content index on table. For pivot implementation
|
|
65
|
+
return indexName;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
var minColWidth = 50;
|
|
70
|
+
var maxColWidth = 250;
|
|
71
|
+
|
|
72
|
+
var calculateMaxWidths = function(ds) {
|
|
73
|
+
const mc = findMergeCols(ds);
|
|
74
|
+
return ds.data
|
|
75
|
+
.reduce((acc, row, index) => {
|
|
76
|
+
for (let [col, value] of row.entries()) {
|
|
77
|
+
if (value === subtotal) value = "SubTotals";
|
|
78
|
+
value = typeof value === 'number' ? String(value) : value;
|
|
79
|
+
if (
|
|
80
|
+
typeof value !== "undefined" &&
|
|
81
|
+
(!acc[col] || acc[col].len <= value.length) &&
|
|
82
|
+
!(index === ds.totalRows - 1 && col < ds.fixedColumns)
|
|
83
|
+
) {
|
|
84
|
+
acc[col] = { str: value, len: value.length || 0, lastRow: index === ds.totalRows - 1 };
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
return acc;
|
|
88
|
+
}, new Array(ds.totalColumns).fill(null))
|
|
89
|
+
.map((item) => getTdWidth(item))
|
|
90
|
+
.reduce((acc, width, col, arr) => {
|
|
91
|
+
acc[col] = mc[col] ? getMergeColsWidth(arr, col, mc[col]) : width;
|
|
92
|
+
return acc;
|
|
93
|
+
}, {});
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
var getTdWidth = function(item) {
|
|
97
|
+
let tdStyles = {
|
|
98
|
+
borderLeft: 'solid 1px',
|
|
99
|
+
borderRight: 'solid 1px',
|
|
100
|
+
fontSize: '11px',
|
|
101
|
+
fontFamily: '"Open Sans",sans-serif',
|
|
102
|
+
fontWeight: item.lastRow && opts.chartOptions.table_options.show_row_total ? '700' : '400',
|
|
103
|
+
paddingRight: '4px',
|
|
104
|
+
paddingLeft: '4px',
|
|
105
|
+
wrap: 'nowrap',
|
|
106
|
+
visibility: 'hidden',
|
|
107
|
+
};
|
|
108
|
+
let td = document.createElement('td');
|
|
109
|
+
for (let [key, value] of _.entries(tdStyles)) {
|
|
110
|
+
td.style[key] = value;
|
|
111
|
+
};
|
|
112
|
+
td.innerHTML = item.str;
|
|
113
|
+
document.body.appendChild(td);
|
|
114
|
+
let width = Math.min(Math.max(td.offsetWidth, minColWidth), maxColWidth);
|
|
115
|
+
document.body.removeChild(td);
|
|
116
|
+
return width;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
var findMergeCols = function(ds) {
|
|
120
|
+
return ds.mergeCells
|
|
121
|
+
.filter(cell => cell.row === ds.fixedRows - 1)
|
|
122
|
+
.reduce((acc, val) => {
|
|
123
|
+
if (!acc[val.col] && val.colspan > 1) acc[val.col] = val.colspan - 1;
|
|
124
|
+
return acc;
|
|
125
|
+
}, {});
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
var getMergeColsWidth = function(cw, col, m) {
|
|
129
|
+
let rightColsWidth = 0;
|
|
130
|
+
for (let _col = col + 1; _col <= col + m; _col++) {
|
|
131
|
+
rightColsWidth += cw[_col];
|
|
132
|
+
};
|
|
133
|
+
return rightColsWidth >= cw[col] ? 0 : cw[col] - rightColsWidth;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
opts = $.extend(def, opts, true);
|
|
137
|
+
|
|
138
|
+
var headerRenderer = function (cellProperties) {
|
|
139
|
+
cellProperties.readOnly = true;
|
|
140
|
+
cellProperties.className = opts.header.className;
|
|
141
|
+
};
|
|
142
|
+
var totalRenderer = function (cellProperties) {
|
|
143
|
+
cellProperties.readOnly = opts.showTotals;
|
|
144
|
+
cellProperties.format = opts.total.format;
|
|
145
|
+
cellProperties.className = opts.total.className;
|
|
146
|
+
};
|
|
147
|
+
var subTotalRenderer = function (cellProperties) {
|
|
148
|
+
cellProperties.readOnly = true;
|
|
149
|
+
cellProperties.format = opts.subTotal.format;
|
|
150
|
+
cellProperties.className = opts.subTotal.className;
|
|
151
|
+
};
|
|
152
|
+
var dataRenderer = function (cellProperties) {
|
|
153
|
+
cellProperties.readOnly = opts.readOnly;
|
|
154
|
+
cellProperties.className = opts.data.className;
|
|
155
|
+
cellProperties.format = opts.data.format;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// get changes on pivot table
|
|
159
|
+
var getPivotChange = function (change, pvtData, dataSource) {
|
|
160
|
+
var rowIdx = change[0] - dataSource.fixedRows;
|
|
161
|
+
var colIdx = change[1] - dataSource.fixedColumns;
|
|
162
|
+
var dataFilter = {
|
|
163
|
+
filterList: [],
|
|
164
|
+
oldValue: change[2],
|
|
165
|
+
newValue: change[3]
|
|
166
|
+
};
|
|
167
|
+
if (colIdx >= 0) {
|
|
168
|
+
var colKeys = pvtData.getColKeys();
|
|
169
|
+
for (var cAttrIdx = 0; cAttrIdx < pvtData.colAttrs.length; cAttrIdx++) {
|
|
170
|
+
if (colIdx < colKeys.length) {
|
|
171
|
+
var cValues = colKeys[colIdx];
|
|
172
|
+
dataFilter.filterList.push({
|
|
173
|
+
Key: pvtData.colAttrs[cAttrIdx],
|
|
174
|
+
Value: cValues[cAttrIdx]
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (rowIdx >= 0) {
|
|
180
|
+
var rowKeys = pvtData.getRowKeys();
|
|
181
|
+
for (var rAttrIdx = 0; rAttrIdx < pvtData.rowAttrs.length; rAttrIdx++) {
|
|
182
|
+
if (rowIdx < rowKeys.length) {
|
|
183
|
+
var rValues = rowKeys[rowIdx];
|
|
184
|
+
dataFilter.filterList.push({
|
|
185
|
+
Key: pvtData.rowAttrs[rAttrIdx],
|
|
186
|
+
Value: rValues[rAttrIdx]
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return dataFilter;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Parse the pvtData and create datasource to handsontable
|
|
195
|
+
var parsePivotData = function (pvtData) {
|
|
196
|
+
var dataSource = {
|
|
197
|
+
data: [],
|
|
198
|
+
columns: [],
|
|
199
|
+
fixedColumns: 0,
|
|
200
|
+
fixedRows: 0,
|
|
201
|
+
mergeCells: [],
|
|
202
|
+
totalColumns: 0,
|
|
203
|
+
totalRows: 0,
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// add rows subtotals
|
|
207
|
+
var addRowSubTotals = function (pvtData) {
|
|
208
|
+
|
|
209
|
+
const tmpNewRows = [];
|
|
210
|
+
const newRowsKeys = [];
|
|
211
|
+
for (let i = 1; i < pvtData.rowAttrs.length; i++) {
|
|
212
|
+
for (let rowKeyArr of pvtData.rowKeys) {
|
|
213
|
+
|
|
214
|
+
let tmpRowKeyArr = rowKeyArr.slice(0, i);
|
|
215
|
+
let tmpRowKey = tmpRowKeyArr.join(delim);
|
|
216
|
+
|
|
217
|
+
let newKeyArr = tmpRowKeyArr.concat(subtotal);
|
|
218
|
+
let newKey = newKeyArr.join(delim);
|
|
219
|
+
|
|
220
|
+
if (!pvtData.rowTotals[newKey]) {
|
|
221
|
+
pvtData.rowTotals[newKey] = pvtData.rowTotals[tmpRowKey];
|
|
222
|
+
newRowsKeys.push(newKeyArr);
|
|
223
|
+
|
|
224
|
+
pvtData.tree[newKey] = {};
|
|
225
|
+
for (let colKeyArr of pvtData.colKeys) {
|
|
226
|
+
let colKey = colKeyArr.join(delim);
|
|
227
|
+
if (pvtData.tree[tmpRowKey][colKey]) {
|
|
228
|
+
pvtData.tree[newKey][colKey] = pvtData.tree[tmpRowKey][colKey];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
for (let j = 1; j < pvtData.colAttrs.length; j++) {
|
|
232
|
+
let tmpColKeyArr = colKeyArr.slice(0, j);
|
|
233
|
+
let tmpColKeyStr = tmpColKeyArr.join(delim);
|
|
234
|
+
|
|
235
|
+
let grandSubTotal = pvtData.tree[tmpRowKey][tmpColKeyStr];
|
|
236
|
+
pvtData.tree[newKey][tmpColKeyStr + delim + subtotal] = grandSubTotal;
|
|
237
|
+
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
pvtData.rowKeys = pvtData.rowKeys.concat(newRowsKeys);
|
|
244
|
+
return pvtData;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// add cols subtotals
|
|
248
|
+
var addColSubTotals = function (pvtData) {
|
|
249
|
+
// console.log("handson col data", pvtData);
|
|
250
|
+
const tmpNewColumns = [];
|
|
251
|
+
const newColumnKeys = [];
|
|
252
|
+
for (let i = 1; i < pvtData.colAttrs.length; i++) {
|
|
253
|
+
for (let colKeyArr of pvtData.colKeys) {
|
|
254
|
+
|
|
255
|
+
let tmpColKeyArr = colKeyArr.slice(0, i);
|
|
256
|
+
let tmpColKey = tmpColKeyArr.join(delim);
|
|
257
|
+
|
|
258
|
+
let newKeyArr = tmpColKeyArr.concat(subtotal);
|
|
259
|
+
let newKey = newKeyArr.join(delim);
|
|
260
|
+
|
|
261
|
+
if (!pvtData.colTotals[newKey]) {
|
|
262
|
+
pvtData.colTotals[newKey] = pvtData.colTotals[tmpColKey];
|
|
263
|
+
newColumnKeys.push(newKeyArr);
|
|
264
|
+
|
|
265
|
+
for (let rowKeyArr of pvtData.rowKeys) {
|
|
266
|
+
let rowKey = rowKeyArr.join(delim);
|
|
267
|
+
if (pvtData.tree[rowKey][tmpColKey]) {
|
|
268
|
+
pvtData.tree[rowKey][newKey] = pvtData.tree[rowKey][tmpColKey];
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
pvtData.colKeys = pvtData.colKeys.concat(newColumnKeys);
|
|
275
|
+
// console.log("handson data2", pvtData);
|
|
276
|
+
return pvtData;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
if (opts.chartOptions.table_options.show_subtotals_for_rows) {
|
|
280
|
+
pvtData = addRowSubTotals(pvtData);
|
|
281
|
+
}
|
|
282
|
+
if (opts.chartOptions.table_options.show_subtotals_for_columns) {
|
|
283
|
+
pvtData = addColSubTotals(pvtData);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
var colKeys = pvtData.getColKeys();
|
|
288
|
+
var rowKeys = pvtData.getRowKeys();
|
|
289
|
+
var hasColumnAttr = (pvtData.colAttrs.length > 0 ? true : false);
|
|
290
|
+
var hasRowAttr = (pvtData.rowAttrs.length > 0 ? true : false);
|
|
291
|
+
|
|
292
|
+
var addMergeCell = function (row, col, rows, columns, noHAlign, noVAlign) {
|
|
293
|
+
dataSource.mergeCells.push({
|
|
294
|
+
row: row,
|
|
295
|
+
col: col,
|
|
296
|
+
rowspan: rows,
|
|
297
|
+
colspan: columns
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
//fixed columns and rows
|
|
302
|
+
dataSource.fixedColumns = pvtData.rowAttrs.length + (hasColumnAttr ? 1 : 0);
|
|
303
|
+
dataSource.fixedRows = pvtData.colAttrs.length + (hasRowAttr ? 1 : 0);
|
|
304
|
+
|
|
305
|
+
for (let i = 0; i < pvtData.rowAttrs.length; i++) {
|
|
306
|
+
rowKeys.sort((a,b) => {
|
|
307
|
+
if (_.isEqual(a.slice(0, i), b.slice(0,i)) && a[i] && a[i] === subtotal) return -1;
|
|
308
|
+
if (_.isEqual(a.slice(0, i), b.slice(0,i)) && b[i] && b[i] === subtotal) return 1;
|
|
309
|
+
return 0;
|
|
310
|
+
});
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// for extra rows on edit mode. Where show only one dimension on row o column.
|
|
314
|
+
var extraColumnLabel = "Grand Totals";
|
|
315
|
+
var extraRowLabel = "Grand Totals";
|
|
316
|
+
if (opts.totalFilterElements && opts.totalFilterElements.row_total) {
|
|
317
|
+
extraColumnLabel = opts.totalFilterElements.row_total.innerHTML;
|
|
318
|
+
}
|
|
319
|
+
if (opts.totalFilterElements && opts.totalFilterElements.col_total) {
|
|
320
|
+
extraRowLabel = opts.totalFilterElements.col_total.innerHTML;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
var addExtraColumn = false;
|
|
324
|
+
var addExtraRow = false;
|
|
325
|
+
if (pvtData.colKeys.length == 0) {
|
|
326
|
+
addExtraColumn = true;
|
|
327
|
+
}
|
|
328
|
+
if (pvtData.rowKeys.length == 0) {
|
|
329
|
+
addExtraRow = true;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
//columns
|
|
333
|
+
var totalColumns = dataSource.totalColumns = pvtData.colKeys.length + pvtData.rowAttrs.length +
|
|
334
|
+
(pvtData.colAttrs.length > 0 ? 1 : 0) +
|
|
335
|
+
(opts.showTotals || addExtraColumn ? 1 : 0);
|
|
336
|
+
|
|
337
|
+
if (!opts.chartOptions.table_options.show_column_total) {
|
|
338
|
+
totalColumns--;
|
|
339
|
+
}
|
|
340
|
+
for (var cc = 0; cc < totalColumns; cc++) {
|
|
341
|
+
|
|
342
|
+
if (cc < dataSource.fixedColumns) {
|
|
343
|
+
dataSource.columns.push({
|
|
344
|
+
type: 'text',
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
dataSource.columns.push({
|
|
349
|
+
type: 'text',
|
|
350
|
+
editor: Handsontable.editors.GenericEditor
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
//first merge cells
|
|
356
|
+
if (hasRowAttr && hasColumnAttr) {
|
|
357
|
+
addMergeCell(0, 0, hasColumnAttr ? pvtData.colAttrs.length : 1, (hasRowAttr ? pvtData.rowAttrs.length : 1));
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// ##
|
|
361
|
+
// HEADERS (columns)
|
|
362
|
+
for (var nn = 0; nn < pvtData.colAttrs.length + (hasRowAttr ? 1 : 0) ; nn++) {
|
|
363
|
+
var rowData = [];
|
|
364
|
+
|
|
365
|
+
// rows with dimensions on columns
|
|
366
|
+
if (nn < pvtData.colAttrs.length) {
|
|
367
|
+
|
|
368
|
+
// columns for row attrs
|
|
369
|
+
for (var cc = 0; cc < pvtData.rowAttrs.length; cc++) {
|
|
370
|
+
rowData.push("");
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
//column for colum attr,
|
|
374
|
+
rowData.push(opts.getIndexContent(pvtData.colAttrs[nn]));
|
|
375
|
+
|
|
376
|
+
//data columns
|
|
377
|
+
if (pvtData.colKeys.length > 0) {
|
|
378
|
+
|
|
379
|
+
const formattedColKeys = pvtData.getFormattedColKeys(colKeys);
|
|
380
|
+
var aux = rowData.length;
|
|
381
|
+
var startCol = aux;
|
|
382
|
+
var prior = formattedColKeys[0][nn];
|
|
383
|
+
var toMerge = 0;
|
|
384
|
+
for (var cc = 0; cc < formattedColKeys.length; cc++) {
|
|
385
|
+
|
|
386
|
+
var textHeader = formattedColKeys[cc][nn];
|
|
387
|
+
|
|
388
|
+
if (nn < pvtData.colAttrs.length - 1 && prior != textHeader) {
|
|
389
|
+
rowData.push(textHeader);
|
|
390
|
+
prior = textHeader;
|
|
391
|
+
// merge cell
|
|
392
|
+
addMergeCell(nn, aux, 1, toMerge);
|
|
393
|
+
aux = aux + toMerge;
|
|
394
|
+
toMerge = 1;
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
toMerge++;
|
|
398
|
+
rowData.push(textHeader);
|
|
399
|
+
|
|
400
|
+
// vertical merge on last row of header columns. Disabled for performance analysis
|
|
401
|
+
//if (nn == pvtData.colAttrs.length - 1 && hasRowAttr) {
|
|
402
|
+
//addMergeCell(nn,startCol+cc ,2,1);
|
|
403
|
+
//}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
//merge last cell
|
|
408
|
+
if (nn < pvtData.colAttrs.length - 1) {
|
|
409
|
+
addMergeCell(nn, aux, 1, toMerge);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// total column
|
|
415
|
+
if (opts.showTotals || addExtraColumn) {
|
|
416
|
+
rowData.push(extraColumnLabel);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
else { // rows with dimensions on columns
|
|
420
|
+
|
|
421
|
+
// columns for row attrs
|
|
422
|
+
for (var cc = 0; cc < pvtData.rowAttrs.length; cc++) {
|
|
423
|
+
|
|
424
|
+
rowData.push(opts.getIndexContent(pvtData.rowAttrs[cc]));
|
|
425
|
+
//merge cell
|
|
426
|
+
if (cc == pvtData.rowAttrs.length - 1 && hasColumnAttr) {
|
|
427
|
+
addMergeCell(nn, cc, 1, 2);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
//empty column for colum attr,
|
|
433
|
+
if (hasColumnAttr > 0) {
|
|
434
|
+
rowData.push("");
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
//data columns (empty)
|
|
438
|
+
for (var cc = 0; cc < colKeys.length; cc++) {
|
|
439
|
+
rowData.push("");
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// total column
|
|
443
|
+
if (opts.showTotals || addExtraColumn) {
|
|
444
|
+
rowData.push(extraColumnLabel);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
dataSource.data.push(rowData);
|
|
450
|
+
}
|
|
451
|
+
// END HEADER
|
|
452
|
+
// ######
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
// ######
|
|
457
|
+
// DATA
|
|
458
|
+
|
|
459
|
+
var mergeDic = {};
|
|
460
|
+
const formattedRowKeys = pvtData.getFormattedRowKeys(rowKeys);
|
|
461
|
+
|
|
462
|
+
for (var rr = 0; rr < formattedRowKeys.length; rr++) {
|
|
463
|
+
|
|
464
|
+
var rowData = [];
|
|
465
|
+
|
|
466
|
+
if (rr == 0) {
|
|
467
|
+
for (var cc = 0; cc < dataSource.fixedColumns; cc++) {
|
|
468
|
+
mergeDic[cc] = {
|
|
469
|
+
toMerge: 1,
|
|
470
|
+
row: 0,
|
|
471
|
+
priorText: formattedRowKeys[rr][cc]
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
//column for row atts
|
|
477
|
+
for (var cc = 0; cc < pvtData.rowAttrs.length; cc++) {
|
|
478
|
+
rowData.push(formattedRowKeys[rr][cc]);
|
|
479
|
+
if (formattedRowKeys[rr][cc] === subtotal) {
|
|
480
|
+
addMergeCell(rr + pvtData.colAttrs.length + 1, cc, 1, dataSource.fixedColumns - cc, true, true);
|
|
481
|
+
} else if (cc === formattedRowKeys[rr].length - 1 && hasColumnAttr) {
|
|
482
|
+
addMergeCell(rr + pvtData.colAttrs.length + 1, cc, 1, 2, true, true);
|
|
483
|
+
}
|
|
484
|
+
// merge cell (last column)
|
|
485
|
+
if (opts.chartOptions.table_options.show_column_total && rr != 0 && mergeDic[cc]) { // check for merge dic
|
|
486
|
+
if (formattedRowKeys[rr][cc] == mergeDic[cc].priorText) {
|
|
487
|
+
mergeDic[cc].toMerge++;
|
|
488
|
+
} else if (cc < formattedRowKeys[rr].length - 1) {
|
|
489
|
+
//create merge cell for this column
|
|
490
|
+
addMergeCell(mergeDic[cc].row + pvtData.colAttrs.length + 1, cc, mergeDic[cc].toMerge, 1);
|
|
491
|
+
mergeDic[cc].row = rr;
|
|
492
|
+
mergeDic[cc].toMerge = 1;
|
|
493
|
+
mergeDic[cc].priorText = formattedRowKeys[rr][cc];
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// empty column (for colum atts)
|
|
499
|
+
if (hasColumnAttr) {
|
|
500
|
+
rowData.push("");
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// columns data
|
|
504
|
+
var agg;
|
|
505
|
+
for (var cc = 0; cc < colKeys.length; cc++) {
|
|
506
|
+
agg = pvtData.getAggregator(rowKeys[rr], colKeys[cc])
|
|
507
|
+
|
|
508
|
+
var cellValue = $.pivotUtilities.getFormattedNumber(agg.value(), agg, opts);
|
|
509
|
+
// var cellValue = agg.value();
|
|
510
|
+
|
|
511
|
+
if (cellValue) {
|
|
512
|
+
rowData.push(cellValue);
|
|
513
|
+
}
|
|
514
|
+
else if (cellValue === 0) {
|
|
515
|
+
rowData.push("0");
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
rowData.push("");
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// column total
|
|
524
|
+
if (opts.showTotals || addExtraColumn) {
|
|
525
|
+
// var rowKeyAtt = rowKeys[rr].join(String.fromCharCode(0));
|
|
526
|
+
var rowKeyAtt = rowKeys[rr].join(delim);
|
|
527
|
+
if (pvtData.rowTotals[rowKeyAtt]) {
|
|
528
|
+
let agg = pvtData.getAggregator(rowKeys[rr], []);
|
|
529
|
+
let preValue = pvtData.rowTotals[rowKeyAtt].value();
|
|
530
|
+
let cellValue = $.pivotUtilities.getFormattedNumber(preValue, agg, opts);
|
|
531
|
+
rowData.push(cellValue);
|
|
532
|
+
// rowData.push(pvtData.rowTotals[rowKeyAtt].value());
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
rowData.push("");
|
|
536
|
+
// rowData.push(0);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
dataSource.data.push(rowData);
|
|
541
|
+
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// add last rows merge cells for each column
|
|
545
|
+
if (opts.chartOptions.table_options.show_column_total) {
|
|
546
|
+
|
|
547
|
+
for (var cc = 0; cc < pvtData.rowAttrs.length - 1; cc++) {
|
|
548
|
+
|
|
549
|
+
if (mergeDic[cc] && mergeDic[cc].toMerge > 1) {
|
|
550
|
+
addMergeCell(mergeDic[cc].row + pvtData.colAttrs.length + 1, cc, mergeDic[cc].toMerge, 1);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// END DATA
|
|
556
|
+
// ######
|
|
557
|
+
|
|
558
|
+
// ######
|
|
559
|
+
// TOTAL
|
|
560
|
+
// colums totals area
|
|
561
|
+
if (opts.showTotals || addExtraRow) {
|
|
562
|
+
|
|
563
|
+
var rowData = [];
|
|
564
|
+
|
|
565
|
+
// columns for row attrs
|
|
566
|
+
for (var cc = 0; cc < pvtData.rowAttrs.length; cc++) {
|
|
567
|
+
rowData.push(extraRowLabel);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
//empty column for colum attr,
|
|
571
|
+
if (hasColumnAttr) {
|
|
572
|
+
rowData.push(extraRowLabel);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
//column totals
|
|
577
|
+
if (opts.chartOptions.table_options.show_row_total) {
|
|
578
|
+
for (var cc = 0; cc < colKeys.length; cc++) {
|
|
579
|
+
|
|
580
|
+
var colKeyAtt = colKeys[cc].join(delim);
|
|
581
|
+
if (pvtData.colTotals[colKeyAtt]) {
|
|
582
|
+
let agg = pvtData.getAggregator([], colKeys[cc]);
|
|
583
|
+
let preValue = pvtData.colTotals[colKeyAtt].value();
|
|
584
|
+
let cellValue = $.pivotUtilities.getFormattedNumber(preValue, agg, opts);
|
|
585
|
+
rowData.push(cellValue);
|
|
586
|
+
}
|
|
587
|
+
else {
|
|
588
|
+
rowData.push(0);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
//all total column
|
|
594
|
+
rowData.push($.pivotUtilities.getFormattedNumber(pvtData.allTotal.value(), pvtData.allTotal, opts));
|
|
595
|
+
|
|
596
|
+
// END TOTAL
|
|
597
|
+
// ######
|
|
598
|
+
|
|
599
|
+
if (opts.chartOptions.table_options.show_row_total) {
|
|
600
|
+
|
|
601
|
+
dataSource.data.push(rowData);
|
|
602
|
+
}
|
|
603
|
+
// end total columns
|
|
604
|
+
}
|
|
605
|
+
dataSource.totalRows = dataSource.data.length;
|
|
606
|
+
|
|
607
|
+
if (opts.showTotals || addExtraRow) {
|
|
608
|
+
|
|
609
|
+
// columns total merge cell
|
|
610
|
+
if (opts.chartOptions.table_options.show_row_total) {
|
|
611
|
+
if (pvtData.rowAttrs.length > 0) {
|
|
612
|
+
addMergeCell(dataSource.totalRows - 1, 0, 1, pvtData.rowAttrs.length + (hasColumnAttr ? 1 : 0));
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
if (opts.chartOptions.table_options.show_column_total) {
|
|
617
|
+
// rows total merge cell
|
|
618
|
+
if (pvtData.colAttrs.length > 0) {
|
|
619
|
+
addMergeCell(0, totalColumns - 1, pvtData.colAttrs.length + (hasRowAttr ? 1 : 0), 1);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
return dataSource;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// render the table
|
|
627
|
+
var renderTable = function (pvtData, opts) {
|
|
628
|
+
var dataSource = parsePivotData(pvtData);
|
|
629
|
+
|
|
630
|
+
// function to data render
|
|
631
|
+
var genericRenderer = function (instance, td, row, col, prop, value, cellProperties) {
|
|
632
|
+
|
|
633
|
+
var newValue = '' + value;
|
|
634
|
+
td.innerHTML = opts.labelsConvertFunction(newValue);
|
|
635
|
+
|
|
636
|
+
if (row < dataSource.fixedRows || col < dataSource.fixedColumns) {
|
|
637
|
+
// header
|
|
638
|
+
td.className = opts.header.className;
|
|
639
|
+
|
|
640
|
+
if (opts.chartOptions.table_options.colorize_headers == true && opts.defaults_colors) {
|
|
641
|
+
let color_to_set;
|
|
642
|
+
if (row < dataSource.fixedRows) {
|
|
643
|
+
if (row < 1) {
|
|
644
|
+
color_to_set = opts.defaults_colors[row];
|
|
645
|
+
} else {
|
|
646
|
+
color_to_set = opts.defaults_colors[1];
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
if (col < dataSource.fixedColumns) {
|
|
650
|
+
td.className = opts.header.className + " sideHeader";
|
|
651
|
+
if (row < dataSource.fixedRows) {
|
|
652
|
+
color_to_set = opts.defaults_colors[row];
|
|
653
|
+
} else {
|
|
654
|
+
// color_to_set = "#fff";
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
if(color_to_set){
|
|
659
|
+
td.style.setProperty("background-color", color_to_set, "important");
|
|
660
|
+
// td.style.setProperty("border-color", color_to_set, "important");
|
|
661
|
+
td.style.color = "#FFFFFF";
|
|
662
|
+
// td.style.fontWeight = "bold";
|
|
663
|
+
} else {
|
|
664
|
+
td.style.setProperty("background-color", "#fff", "important");
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
else if (col < dataSource.fixedColumns) {
|
|
670
|
+
if ((dataSource.data[0] && dataSource.data[0][col] == subtotal) ||
|
|
671
|
+
(dataSource.data[1] && dataSource.data[1][col] == subtotal)) {
|
|
672
|
+
td.className = opts.subTotal.className;
|
|
673
|
+
} else if (dataSource.data[row] && dataSource.data[row].indexOf(subtotal) !== -1 &&
|
|
674
|
+
dataSource.data[row].indexOf(subtotal) < 3) {
|
|
675
|
+
td.className = opts.subTotal.className;
|
|
676
|
+
}
|
|
677
|
+
if (newValue === subtotal) {
|
|
678
|
+
td.innerHTML = replaceValue;
|
|
679
|
+
} else if (opts.chartOptions.table_options.remove_underscores == true) {
|
|
680
|
+
td.innerHTML = newValue.replace("_", " ");
|
|
681
|
+
}
|
|
682
|
+
} else if (opts.chartOptions.table_options.show_row_total && opts.showTotals && row == dataSource.totalRows - 1) {
|
|
683
|
+
//total row
|
|
684
|
+
td.className = opts.total.className;
|
|
685
|
+
} else if (opts.chartOptions.table_options.show_column_total && opts.showTotals && col == dataSource.totalColumns - 1) {
|
|
686
|
+
//total col
|
|
687
|
+
td.className = opts.total.className;
|
|
688
|
+
} else if (dataSource.data[row] && dataSource.data[row].includes(subtotal)) {
|
|
689
|
+
//subTotal row class
|
|
690
|
+
td.className = opts.subTotal.className;
|
|
691
|
+
} else if ((dataSource.data[0] && dataSource.data[0][col] == subtotal) ||
|
|
692
|
+
(dataSource.data[1] && dataSource.data[1][col] == subtotal)) {
|
|
693
|
+
//subTotal col class
|
|
694
|
+
td.className = opts.subTotal.className;
|
|
695
|
+
} else {
|
|
696
|
+
//data
|
|
697
|
+
td.className = opts.data.className;
|
|
698
|
+
}
|
|
699
|
+
td.className += " __" + row + "," + col + "__";
|
|
700
|
+
|
|
701
|
+
if (opts.chartOptions.table_options.colorize_headers == true) {
|
|
702
|
+
td.className += " colorized";
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
if (opts.chartOptions.table_options.show_row_total && row == dataSource.totalRows-1) {
|
|
706
|
+
td.className += " withTopBorder";
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
if (td.innerHTML === subtotal) {
|
|
710
|
+
td.innerHTML = replaceValue;
|
|
711
|
+
}
|
|
712
|
+
if (td.innerHTML === "undefined") {
|
|
713
|
+
td.innerHTML = "";
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
if (opts.chartOptions.table_options.hide_nulls_in_headers && td.innerHTML === '[null]') {
|
|
717
|
+
td.innerHTML = '';
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
if (opts.chartOptions.table_options.styles) {
|
|
721
|
+
for (let rule of opts.chartOptions.table_options.styles) {
|
|
722
|
+
|
|
723
|
+
if (!rule.styles || rule.styles.length === 0) {
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
if (rule.row && rule.col) {
|
|
728
|
+
if (row === parseInt(rule.row) && col === parseInt(rule.col)) {
|
|
729
|
+
for (let style of rule.styles) {
|
|
730
|
+
td.style.setProperty(style.name, style.val, "important");
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
} else if (rule.row && row !== 0 && col !== 0) {
|
|
734
|
+
if (rule.repeat) {
|
|
735
|
+
const offset = rule.offset || 0;
|
|
736
|
+
if (row > offset && (row - offset) % rule.row === 0) {
|
|
737
|
+
for (let style of rule.styles) {
|
|
738
|
+
td.style.setProperty(style.name, style.val, "important");
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
} else if (row === parseInt(rule.row)) {
|
|
742
|
+
for (let style of rule.styles) {
|
|
743
|
+
td.style.setProperty(style.name, style.val, "important");
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
} else if (rule.col && col !== 0 && row !== 0) {
|
|
747
|
+
if (rule.repeat) {
|
|
748
|
+
const offset = rule.offset || 0;
|
|
749
|
+
if (col > offset && (col - offset) % rule.col === 0) {
|
|
750
|
+
for (let style of rule.styles) {
|
|
751
|
+
td.style.setProperty(style.name, style.val, "important");
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
} else if (col === parseInt(rule.col)) {
|
|
755
|
+
for (let style of rule.styles) {
|
|
756
|
+
td.style.setProperty(style.name, style.val, "important");
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
return td;
|
|
763
|
+
};
|
|
764
|
+
|
|
765
|
+
var _this = this;
|
|
766
|
+
if (table) {
|
|
767
|
+
table.destroy();
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
var contextMenu = null;
|
|
771
|
+
|
|
772
|
+
if(opts.value_drill_down_fn){
|
|
773
|
+
let calBackFn = function(key, selection, clickEvent) {
|
|
774
|
+
let row = selection[0].start.row;
|
|
775
|
+
let col = selection[0].start.col;
|
|
776
|
+
if (row < dataSource.fixedRows || col < dataSource.fixedColumns) {
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
else{
|
|
780
|
+
let cols = [];
|
|
781
|
+
let rows = [];
|
|
782
|
+
|
|
783
|
+
for(let i=0; i< pvtData.rowAttrs.length; i++){
|
|
784
|
+
rows.push(dataSource.data[row][i]);
|
|
785
|
+
}
|
|
786
|
+
for(let i=0; i< pvtData.colAttrs.length; i++){
|
|
787
|
+
cols.push(dataSource.data[i][col]);
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
if (opts.showTotals && row == dataSource.totalRows - 1) {
|
|
791
|
+
rows = [];
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
if (opts.showTotals && col == dataSource.totalColumns - 1) {
|
|
795
|
+
cols = [];
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
opts.value_drill_down_fn(clickEvent, rows, cols, key);
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
let disableFn = function () {
|
|
803
|
+
let selection = this.getSelectedLast();
|
|
804
|
+
if (selection[0] < dataSource.fixedRows || selection[1] < dataSource.fixedColumns) {
|
|
805
|
+
return true;
|
|
806
|
+
}
|
|
807
|
+
return false;
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
contextMenu = {
|
|
811
|
+
items: {
|
|
812
|
+
"open_drill_down_view": {
|
|
813
|
+
name: 'Open drill down view',
|
|
814
|
+
callback: calBackFn,
|
|
815
|
+
disabled: disableFn
|
|
816
|
+
},
|
|
817
|
+
"export_drill_down": {
|
|
818
|
+
name: 'Export drill down to excel',
|
|
819
|
+
callback: calBackFn,
|
|
820
|
+
disabled: disableFn
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
var $tableArea = opts.$el.find(".widget-id-" + opts.widgetId);
|
|
827
|
+
$tableArea.empty();
|
|
828
|
+
console.log('Handsontable data', dataSource);
|
|
829
|
+
var maxWidths = calculateMaxWidths(dataSource);
|
|
830
|
+
table = new Handsontable($tableArea.get(0), {
|
|
831
|
+
licenseKey: 'b0eda-7220b-32d15-e4128-c2f4c', //98463-b132b-fcea0-24f22-da020
|
|
832
|
+
data: dataSource.data,
|
|
833
|
+
contextMenu: contextMenu,
|
|
834
|
+
selectionMode: "single",
|
|
835
|
+
colHeaders: false,
|
|
836
|
+
allowInsertColumn: false,
|
|
837
|
+
allowInsertRow: false,
|
|
838
|
+
columns: dataSource.columns,
|
|
839
|
+
fixedColumnsLeft: dataSource.fixedColumns,
|
|
840
|
+
fixedRowsTop: dataSource.fixedRows,
|
|
841
|
+
mergeCells: dataSource.mergeCells,
|
|
842
|
+
colWidths: function(index) {
|
|
843
|
+
return maxWidths[index];
|
|
844
|
+
},
|
|
845
|
+
cells: function (row, col, prop) {
|
|
846
|
+
var cellProperties = {};
|
|
847
|
+
cellProperties.renderer = genericRenderer;
|
|
848
|
+
if (row < dataSource.fixedRows || col < dataSource.fixedColumns) {
|
|
849
|
+
headerRenderer(cellProperties);
|
|
850
|
+
} else {
|
|
851
|
+
if (opts.showTotals && (row == dataSource.totalRows - 1 || col == dataSource.totalColumns - 1)) {
|
|
852
|
+
totalRenderer(cellProperties);
|
|
853
|
+
} else {
|
|
854
|
+
dataRenderer(cellProperties);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
return cellProperties;
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
setTimeout(function () {
|
|
862
|
+
|
|
863
|
+
var currentState = opts.$el.data("currentState");
|
|
864
|
+
|
|
865
|
+
if (currentState) {
|
|
866
|
+
if (currentState && currentState.lastRowChanged) {
|
|
867
|
+
table.selectCell(currentState.lastRowChanged + 1, currentState.lasColChanged, currentState.lastRowChanged + 1, currentState.lasColChanged);
|
|
868
|
+
currentState.lastRowChanged = null;
|
|
869
|
+
if (currentState.scrollX && currentState.scrollX > 0) {
|
|
870
|
+
opts.$el.scrollLeft(currentState.scrollX);
|
|
871
|
+
}
|
|
872
|
+
if (currentState.scrollY && currentState.scrollY > 0) {
|
|
873
|
+
opts.$el.scrollTop(currentState.scrollY);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
currentState = null;
|
|
877
|
+
opts.$el.data("currentState", null);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
}, 5);
|
|
882
|
+
return false;
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
var _this = this;
|
|
886
|
+
setTimeout(function () {
|
|
887
|
+
renderTable(pvtData, opts);
|
|
888
|
+
}, 10);
|
|
889
|
+
|
|
890
|
+
// inject the widgetId to the class name so we can separate the tables by it
|
|
891
|
+
// look for the search side on line 653 "opts.$el.find(".widget-id-" + opts.widgetId);"
|
|
892
|
+
var tableClasses = ['novixPivot', `widget-id-${opts.widgetId}`];
|
|
893
|
+
if (opts.chartOptions.table_options.use_new_table_design) {
|
|
894
|
+
tableClasses.push('handsontable-new');
|
|
895
|
+
}
|
|
896
|
+
if (!pvtData.aggregator().uniq) {
|
|
897
|
+
tableClasses.push('numbers-to-right');
|
|
898
|
+
}
|
|
899
|
+
return `<div class='${tableClasses.join(' ')}' style='overflow:auto'></div>`;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
};
|
|
903
|
+
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
module.exports = initNovixRenderer;
|