@lumeer/pivot 0.0.1 → 0.0.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.
Files changed (56) hide show
  1. package/esm2022/lib/directives/lmr-templates.directive.mjs +27 -0
  2. package/esm2022/lib/lmr-pivot-table.component.mjs +81 -0
  3. package/esm2022/lib/lmr-pivot-table.module.mjs +42 -0
  4. package/esm2022/lib/pipes/contrast-color.pipe.mjs +41 -0
  5. package/esm2022/lib/pipes/pivot-data-empty.pipe.mjs +38 -0
  6. package/esm2022/lib/pipes/pivot-table-value.pipe.mjs +35 -0
  7. package/esm2022/lib/util/lmr-pivot-config.mjs +12 -0
  8. package/esm2022/lib/util/lmr-pivot-constants.mjs +12 -0
  9. package/esm2022/lib/util/lmr-pivot-data.mjs +2 -0
  10. package/esm2022/lib/util/lmr-pivot-table.mjs +2 -0
  11. package/esm2022/lib/util/pivot-data-converter.mjs +502 -0
  12. package/esm2022/lib/util/pivot-table-converter.mjs +803 -0
  13. package/esm2022/lib/util/pivot-util.mjs +72 -0
  14. package/esm2022/lumeer-pivot.mjs +5 -0
  15. package/esm2022/public-api.mjs +11 -0
  16. package/fesm2022/lumeer-pivot.mjs +1644 -0
  17. package/fesm2022/lumeer-pivot.mjs.map +1 -0
  18. package/index.d.ts +5 -0
  19. package/lib/directives/lmr-templates.directive.d.ts +14 -0
  20. package/lib/lmr-pivot-table.component.d.ts +31 -0
  21. package/lib/lmr-pivot-table.module.d.ts +12 -0
  22. package/lib/pipes/contrast-color.pipe.d.ts +11 -0
  23. package/lib/pipes/pivot-data-empty.pipe.d.ts +8 -0
  24. package/lib/pipes/pivot-table-value.pipe.d.ts +8 -0
  25. package/lib/util/lmr-pivot-config.d.ts +57 -0
  26. package/lib/util/lmr-pivot-constants.d.ts +11 -0
  27. package/lib/util/lmr-pivot-data.d.ts +34 -0
  28. package/lib/util/lmr-pivot-table.d.ts +18 -0
  29. package/lib/util/pivot-data-converter.d.ts +46 -0
  30. package/lib/util/pivot-table-converter.d.ts +62 -0
  31. package/lib/util/pivot-util.d.ts +12 -0
  32. package/lumeer-pivot-0.0.2.tgz +0 -0
  33. package/package.json +16 -3
  34. package/{src/public-api.ts → public-api.d.ts} +0 -4
  35. package/.eslintrc.json +0 -35
  36. package/ng-package.json +0 -7
  37. package/src/lib/directives/lmr-templates.directive.ts +0 -11
  38. package/src/lib/lmr-pivot-table.component.html +0 -69
  39. package/src/lib/lmr-pivot-table.component.scss +0 -69
  40. package/src/lib/lmr-pivot-table.component.ts +0 -108
  41. package/src/lib/lmr-pivot-table.module.ts +0 -28
  42. package/src/lib/pipes/contrast-color.pipe.ts +0 -33
  43. package/src/lib/pipes/pivot-data-empty.pipe.ts +0 -36
  44. package/src/lib/pipes/pivot-table-value.pipe.ts +0 -32
  45. package/src/lib/util/lmr-pivot-config.ts +0 -68
  46. package/src/lib/util/lmr-pivot-constants.ts +0 -13
  47. package/src/lib/util/lmr-pivot-data.ts +0 -57
  48. package/src/lib/util/lmr-pivot-table.ts +0 -38
  49. package/src/lib/util/pivot-data-converter.spec.ts +0 -647
  50. package/src/lib/util/pivot-data-converter.ts +0 -803
  51. package/src/lib/util/pivot-table-converter.spec.ts +0 -1045
  52. package/src/lib/util/pivot-table-converter.ts +0 -1118
  53. package/src/lib/util/pivot-util.ts +0 -92
  54. package/tsconfig.lib.json +0 -14
  55. package/tsconfig.lib.prod.json +0 -10
  56. package/tsconfig.spec.json +0 -14
@@ -1,1045 +0,0 @@
1
- /*
2
- * Lumeer: Modern Data Definition and Processing Platform
3
- *
4
- * Copyright (C) since 2017 Lumeer.io, s.r.o. and/or its affiliates.
5
- *
6
- * This program is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
- */
19
- import {PercentageConstraint, PercentageConstraintConfig} from '@lumeer/data-filters';
20
-
21
- import {LmrPivotData} from './lmr-pivot-data';
22
- import {PivotTableConverter} from './pivot-table-converter';
23
- import {COLOR_GRAY100, COLOR_GRAY200} from './lmr-pivot-constants';
24
- import {LmrPivotStrings} from './lmr-pivot-config';
25
-
26
- describe('Pivot table converter', () => {
27
- const headerSummaryString = 'H';
28
- const summaryString = 'S';
29
- const strings: LmrPivotStrings = {headerSummaryString, summaryString}
30
- const converter: PivotTableConverter = new PivotTableConverter();
31
-
32
- it('should return empty rows', () => {
33
- const data: LmrPivotData = {
34
- data: [
35
- {
36
- valueTitles: [],
37
- rowHeaders: [],
38
- rowSticky: [],
39
- columnHeaders: [],
40
- values: [],
41
- dataResources: [],
42
- rowSorts: [],
43
- rowShowSums: [],
44
- columnSorts: [],
45
- columnShowSums: [],
46
- valueTypes: [],
47
- columnSticky: [],
48
- },
49
- ],
50
- };
51
- expect(converter.createTables(data, strings)).toEqual([{cells: []}]);
52
- });
53
-
54
- it('should return table by only values', () => {
55
- const data: LmrPivotData = {
56
- data: [
57
- {
58
- valueTitles: ['A', 'B', 'C'],
59
- rowHeaders: [],
60
- rowSticky: [],
61
- columnHeaders: [
62
- {title: 'A', targetIndex: 0, color: undefined, isValueHeader: false},
63
- {title: 'B', targetIndex: 1, color: undefined, isValueHeader: false},
64
- {title: 'C', targetIndex: 2, color: undefined, isValueHeader: false},
65
- ],
66
- values: [[10, 20, 30]],
67
- dataResources: [],
68
- rowShowSums: [],
69
- columnShowSums: [],
70
- columnSticky: [],
71
- hasAdditionalColumnLevel: true,
72
- },
73
- ],
74
- };
75
-
76
- const pivotTable = converter.createTables(data, strings)[0];
77
- expect(pivotTable.cells.length).toEqual(2);
78
- expect(pivotTable.cells[0].length).toEqual(3);
79
- expect(pivotTable.cells[1].length).toEqual(3);
80
- expect(pivotTable.cells[0][0]).toEqual({
81
- value: 'A',
82
- rowSpan: 1,
83
- colSpan: 1,
84
- isHeader: true,
85
- cssClass: PivotTableConverter.columnHeaderClass,
86
- background: undefined,
87
- constraint: undefined,
88
- label: undefined,
89
- stickyTop: undefined,
90
- });
91
- expect(pivotTable.cells[0][1]).toEqual({
92
- value: 'B',
93
- rowSpan: 1,
94
- colSpan: 1,
95
- isHeader: true,
96
- cssClass: PivotTableConverter.columnHeaderClass,
97
- background: undefined,
98
- constraint: undefined,
99
- label: undefined,
100
- stickyTop: undefined,
101
- });
102
- expect(pivotTable.cells[0][2]).toEqual({
103
- value: 'C',
104
- rowSpan: 1,
105
- colSpan: 1,
106
- isHeader: true,
107
- cssClass: PivotTableConverter.columnHeaderClass,
108
- background: undefined,
109
- constraint: undefined,
110
- label: undefined,
111
- stickyTop: undefined,
112
- });
113
- expect(pivotTable.cells[1][0]).toEqual({
114
- value: '10',
115
- dataResources: [],
116
- rowSpan: 1,
117
- colSpan: 1,
118
- isHeader: false,
119
- cssClass: PivotTableConverter.dataClass,
120
- });
121
- expect(pivotTable.cells[1][1]).toEqual({
122
- value: '20',
123
- dataResources: [],
124
- rowSpan: 1,
125
- colSpan: 1,
126
- isHeader: false,
127
- cssClass: PivotTableConverter.dataClass,
128
- });
129
- expect(pivotTable.cells[1][2]).toEqual({
130
- value: '30',
131
- dataResources: [],
132
- rowSpan: 1,
133
- colSpan: 1,
134
- isHeader: false,
135
- cssClass: PivotTableConverter.dataClass,
136
- });
137
- });
138
-
139
- it('should return table by only rows', () => {
140
- const data: LmrPivotData = {
141
- data: [
142
- {
143
- valueTitles: [],
144
- rowSticky: [],
145
- rowHeaders: [
146
- {
147
- title: 'A',
148
- children: [
149
- {title: 'a1', targetIndex: 0, color: undefined, isValueHeader: false},
150
- {title: 'a2', targetIndex: 1, color: undefined, isValueHeader: false},
151
- ],
152
- color: undefined,
153
- isValueHeader: false,
154
- },
155
- {
156
- title: 'B',
157
- children: [{title: 'a1', targetIndex: 2, color: undefined, isValueHeader: false}],
158
- color: undefined,
159
- isValueHeader: false,
160
- },
161
- {
162
- title: 'C',
163
- children: [
164
- {title: 'a2', targetIndex: 3, color: undefined, isValueHeader: false},
165
- {title: 'a3', targetIndex: 4, color: undefined, isValueHeader: false},
166
- {title: 'a4', targetIndex: 5, color: undefined, isValueHeader: false},
167
- ],
168
- color: undefined,
169
- isValueHeader: false,
170
- },
171
- ],
172
- columnHeaders: [],
173
- columnSticky: [],
174
- values: [],
175
- dataResources: [],
176
- rowShowSums: [true, true],
177
- columnShowSums: [],
178
- hasAdditionalColumnLevel: false,
179
- },
180
- ],
181
- };
182
-
183
- const pivotTable = converter.createTables(data, strings)[0];
184
- expect(pivotTable.cells.length).toEqual(10);
185
- expect(pivotTable.cells[0][0]).toEqual({
186
- value: 'A',
187
- rowSpan: 2,
188
- colSpan: 1,
189
- isHeader: true,
190
- cssClass: PivotTableConverter.rowHeaderClass,
191
- background: undefined,
192
- constraint: undefined,
193
- label: undefined,
194
- stickyStart: undefined,
195
- });
196
- expect(pivotTable.cells[0][1]).toEqual({
197
- value: 'a1',
198
- rowSpan: 1,
199
- colSpan: 1,
200
- isHeader: true,
201
- cssClass: PivotTableConverter.rowHeaderClass,
202
- background: undefined,
203
- constraint: undefined,
204
- label: undefined,
205
- stickyStart: undefined,
206
- });
207
- expect(pivotTable.cells[1][0]).toEqual(undefined);
208
- expect(pivotTable.cells[1][1]).toEqual({
209
- value: 'a2',
210
- rowSpan: 1,
211
- colSpan: 1,
212
- isHeader: true,
213
- cssClass: PivotTableConverter.rowHeaderClass,
214
- background: undefined,
215
- constraint: undefined,
216
- label: undefined,
217
- stickyStart: undefined,
218
- });
219
- expect(pivotTable.cells[2][0]).toEqual({
220
- value: 'A',
221
- summary: headerSummaryString,
222
- rowSpan: 1,
223
- colSpan: 2,
224
- isHeader: true,
225
- cssClass: PivotTableConverter.rowGroupHeaderClass,
226
- constraint: undefined,
227
- background: COLOR_GRAY200,
228
- label: undefined,
229
- stickyStart: undefined,
230
- });
231
- expect(pivotTable.cells[2][1]).toEqual(undefined);
232
-
233
- expect(pivotTable.cells[3][0]).toEqual({
234
- value: 'B',
235
- rowSpan: 1,
236
- colSpan: 1,
237
- isHeader: true,
238
- cssClass: PivotTableConverter.rowHeaderClass,
239
- background: undefined,
240
- constraint: undefined,
241
- label: undefined,
242
- stickyStart: undefined,
243
- });
244
- expect(pivotTable.cells[3][1]).toEqual({
245
- value: 'a1',
246
- rowSpan: 1,
247
- colSpan: 1,
248
- isHeader: true,
249
- cssClass: PivotTableConverter.rowHeaderClass,
250
- background: undefined,
251
- constraint: undefined,
252
- label: undefined,
253
- stickyStart: undefined,
254
- });
255
- expect(pivotTable.cells[4][0]).toEqual({
256
- value: 'B',
257
- summary: headerSummaryString,
258
- rowSpan: 1,
259
- colSpan: 2,
260
- isHeader: true,
261
- cssClass: PivotTableConverter.rowGroupHeaderClass,
262
- background: COLOR_GRAY200,
263
- constraint: undefined,
264
- label: undefined,
265
- stickyStart: undefined,
266
- });
267
- expect(pivotTable.cells[4][1]).toEqual(undefined);
268
-
269
- expect(pivotTable.cells[5][0]).toEqual({
270
- value: 'C',
271
- rowSpan: 3,
272
- colSpan: 1,
273
- isHeader: true,
274
- cssClass: PivotTableConverter.rowHeaderClass,
275
- background: undefined,
276
- constraint: undefined,
277
- label: undefined,
278
- stickyStart: undefined,
279
- });
280
- expect(pivotTable.cells[5][1]).toEqual({
281
- value: 'a2',
282
- rowSpan: 1,
283
- colSpan: 1,
284
- isHeader: true,
285
- cssClass: PivotTableConverter.rowHeaderClass,
286
- background: undefined,
287
- constraint: undefined,
288
- label: undefined,
289
- stickyStart: undefined,
290
- });
291
- expect(pivotTable.cells[6][0]).toEqual(undefined);
292
- expect(pivotTable.cells[6][1]).toEqual({
293
- value: 'a3',
294
- rowSpan: 1,
295
- colSpan: 1,
296
- isHeader: true,
297
- cssClass: PivotTableConverter.rowHeaderClass,
298
- background: undefined,
299
- constraint: undefined,
300
- label: undefined,
301
- stickyStart: undefined,
302
- });
303
- expect(pivotTable.cells[7][0]).toEqual(undefined);
304
- expect(pivotTable.cells[7][1]).toEqual({
305
- value: 'a4',
306
- rowSpan: 1,
307
- colSpan: 1,
308
- isHeader: true,
309
- cssClass: PivotTableConverter.rowHeaderClass,
310
- background: undefined,
311
- constraint: undefined,
312
- label: undefined,
313
- stickyStart: undefined,
314
- });
315
- expect(pivotTable.cells[8][0]).toEqual({
316
- value: 'C',
317
- summary: headerSummaryString,
318
- rowSpan: 1,
319
- colSpan: 2,
320
- isHeader: true,
321
- cssClass: PivotTableConverter.rowGroupHeaderClass,
322
- constraint: undefined,
323
- background: COLOR_GRAY200,
324
- label: undefined,
325
- stickyStart: undefined,
326
- });
327
- expect(pivotTable.cells[8][1]).toEqual(undefined);
328
- expect(pivotTable.cells[9][0]).toEqual({
329
- value: undefined,
330
- summary: summaryString,
331
- rowSpan: 1,
332
- colSpan: 2,
333
- isHeader: true,
334
- cssClass: PivotTableConverter.rowGroupHeaderClass,
335
- constraint: undefined,
336
- background: COLOR_GRAY100,
337
- label: undefined,
338
- stickyStart: undefined,
339
- });
340
- expect(pivotTable.cells[9][1]).toEqual(undefined);
341
-
342
- const dataWithoutSums: LmrPivotData = {...data, data: [{...data.data[0], rowShowSums: [false, false]}]};
343
- const pivotTableWithoutSums = converter.createTables(dataWithoutSums, strings)[0];
344
- expect(pivotTableWithoutSums.cells.length).toEqual(6);
345
- });
346
-
347
- it('should return table by only columns', () => {
348
- const data: LmrPivotData = {
349
- data: [
350
- {
351
- valueTitles: [],
352
- rowHeaders: [],
353
- rowSticky: [],
354
- columnHeaders: [
355
- {
356
- title: 'X',
357
- children: [{title: 'a1', targetIndex: 0, color: undefined, isValueHeader: false}],
358
- color: undefined,
359
- isValueHeader: false,
360
- },
361
- {
362
- title: 'Y',
363
- children: [
364
- {title: 'a1', targetIndex: 1, color: undefined, isValueHeader: false},
365
- {title: 'a2', targetIndex: 2, color: undefined, isValueHeader: false},
366
- ],
367
- color: undefined,
368
- isValueHeader: false,
369
- },
370
- {
371
- title: 'Z',
372
- children: [
373
- {title: 'a2', targetIndex: 3, color: undefined, isValueHeader: false},
374
- {title: 'a3', targetIndex: 4, color: undefined, isValueHeader: false},
375
- ],
376
- color: undefined,
377
- isValueHeader: false,
378
- },
379
- ],
380
- values: [],
381
- dataResources: [],
382
- columnSticky: [],
383
- columnShowSums: [true, true],
384
- rowShowSums: [],
385
- },
386
- ],
387
- };
388
-
389
- const pivotTable = converter.createTables(data, strings)[0];
390
- expect(pivotTable.cells.length).toEqual(2);
391
- expect(pivotTable.cells[0].length).toEqual(9);
392
- expect(pivotTable.cells[0][0]).toEqual({
393
- value: 'X',
394
- rowSpan: 1,
395
- colSpan: 1,
396
- isHeader: true,
397
- cssClass: PivotTableConverter.columnHeaderClass,
398
- background: undefined,
399
- constraint: undefined,
400
- label: undefined,
401
- stickyTop: undefined,
402
- });
403
- expect(pivotTable.cells[1][0]).toEqual({
404
- value: 'a1',
405
- rowSpan: 1,
406
- colSpan: 1,
407
- isHeader: true,
408
- cssClass: PivotTableConverter.columnHeaderClass,
409
- background: undefined,
410
- constraint: undefined,
411
- label: undefined,
412
- stickyTop: undefined,
413
- });
414
- expect(pivotTable.cells[0][1]).toEqual({
415
- value: 'X',
416
- summary: headerSummaryString,
417
- rowSpan: 2,
418
- colSpan: 1,
419
- isHeader: true,
420
- cssClass: PivotTableConverter.columnGroupHeaderClass,
421
- constraint: undefined,
422
- background: COLOR_GRAY200,
423
- label: undefined,
424
- stickyTop: undefined,
425
- });
426
- expect(pivotTable.cells[1][1]).toEqual(undefined);
427
-
428
- expect(pivotTable.cells[0][2]).toEqual({
429
- value: 'Y',
430
- rowSpan: 1,
431
- colSpan: 2,
432
- isHeader: true,
433
- cssClass: PivotTableConverter.columnHeaderClass,
434
- background: undefined,
435
- constraint: undefined,
436
- label: undefined,
437
- stickyTop: undefined,
438
- });
439
- expect(pivotTable.cells[0][3]).toEqual(undefined);
440
- expect(pivotTable.cells[1][2]).toEqual({
441
- value: 'a1',
442
- rowSpan: 1,
443
- colSpan: 1,
444
- isHeader: true,
445
- cssClass: PivotTableConverter.columnHeaderClass,
446
- background: undefined,
447
- constraint: undefined,
448
- label: undefined,
449
- stickyTop: undefined,
450
- });
451
- expect(pivotTable.cells[1][3]).toEqual({
452
- value: 'a2',
453
- rowSpan: 1,
454
- colSpan: 1,
455
- isHeader: true,
456
- cssClass: PivotTableConverter.columnHeaderClass,
457
- background: undefined,
458
- constraint: undefined,
459
- label: undefined,
460
- stickyTop: undefined,
461
- });
462
- expect(pivotTable.cells[0][4]).toEqual({
463
- value: 'Y',
464
- summary: headerSummaryString,
465
- rowSpan: 2,
466
- colSpan: 1,
467
- isHeader: true,
468
- cssClass: PivotTableConverter.columnGroupHeaderClass,
469
- constraint: undefined,
470
- background: COLOR_GRAY200,
471
- label: undefined,
472
- stickyTop: undefined,
473
- });
474
- expect(pivotTable.cells[1][4]).toEqual(undefined);
475
-
476
- expect(pivotTable.cells[0][5]).toEqual({
477
- value: 'Z',
478
- rowSpan: 1,
479
- colSpan: 2,
480
- isHeader: true,
481
- cssClass: PivotTableConverter.columnHeaderClass,
482
- background: undefined,
483
- constraint: undefined,
484
- label: undefined,
485
- stickyTop: undefined,
486
- });
487
- expect(pivotTable.cells[0][6]).toEqual(undefined);
488
- expect(pivotTable.cells[1][5]).toEqual({
489
- value: 'a2',
490
- rowSpan: 1,
491
- colSpan: 1,
492
- isHeader: true,
493
- cssClass: PivotTableConverter.columnHeaderClass,
494
- background: undefined,
495
- constraint: undefined,
496
- label: undefined,
497
- stickyTop: undefined,
498
- });
499
- expect(pivotTable.cells[1][6]).toEqual({
500
- value: 'a3',
501
- rowSpan: 1,
502
- colSpan: 1,
503
- isHeader: true,
504
- cssClass: PivotTableConverter.columnHeaderClass,
505
- background: undefined,
506
- constraint: undefined,
507
- label: undefined,
508
- stickyTop: undefined,
509
- });
510
- expect(pivotTable.cells[0][7]).toEqual({
511
- value: 'Z',
512
- summary: headerSummaryString,
513
- rowSpan: 2,
514
- colSpan: 1,
515
- isHeader: true,
516
- cssClass: PivotTableConverter.columnGroupHeaderClass,
517
- constraint: undefined,
518
- background: COLOR_GRAY200,
519
- label: undefined,
520
- stickyTop: undefined,
521
- });
522
- expect(pivotTable.cells[1][7]).toEqual(undefined);
523
- expect(pivotTable.cells[0][8]).toEqual({
524
- value: undefined,
525
- summary: summaryString,
526
- rowSpan: 2,
527
- colSpan: 1,
528
- isHeader: true,
529
- cssClass: PivotTableConverter.columnGroupHeaderClass,
530
- constraint: undefined,
531
- background: COLOR_GRAY100,
532
- label: undefined,
533
- stickyTop: undefined,
534
- });
535
- expect(pivotTable.cells[1][8]).toEqual(undefined);
536
-
537
- const dataWithoutSums: LmrPivotData = {...data, data: [{...data.data[0], columnShowSums: [false, false]}]};
538
- const pivotTableWithoutSums = converter.createTables(dataWithoutSums, strings)[0];
539
- expect(pivotTableWithoutSums.cells.length).toEqual(2);
540
- expect(pivotTableWithoutSums.cells[0].length).toEqual(5);
541
- });
542
-
543
- it('should return table by row and values', () => {
544
- const data: LmrPivotData = {
545
- data: [
546
- {
547
- valueTitles: ['X', 'Y'],
548
- rowSticky: [],
549
- rowHeaders: [
550
- {
551
- title: 'A',
552
- children: [
553
- {title: 'a1', targetIndex: 0, color: undefined, isValueHeader: false},
554
- {title: 'a2', targetIndex: 1, color: undefined, isValueHeader: false},
555
- {title: 'a3', targetIndex: 2, color: undefined, isValueHeader: false},
556
- ],
557
- color: undefined,
558
- isValueHeader: false,
559
- },
560
- {
561
- title: 'B',
562
- children: [
563
- {title: 'a2', targetIndex: 3, color: undefined, isValueHeader: false},
564
- {title: 'a3', targetIndex: 4, color: undefined, isValueHeader: false},
565
- ],
566
- color: undefined,
567
- isValueHeader: false,
568
- },
569
- {
570
- title: 'C',
571
- children: [{title: 'a1', targetIndex: 5, color: undefined, isValueHeader: false}],
572
- color: undefined,
573
- isValueHeader: false,
574
- },
575
- ],
576
- columnHeaders: [
577
- {title: 'X', targetIndex: 0, color: undefined, isValueHeader: false},
578
- {title: 'Y', targetIndex: 1, color: undefined, isValueHeader: false},
579
- ],
580
- values: [
581
- [1, 2],
582
- [2, null],
583
- [3, 5],
584
- [8, 9],
585
- [1, 9],
586
- [null, 4],
587
- ],
588
- dataResources: [],
589
- rowShowSums: [true, true],
590
- columnShowSums: [],
591
- columnSticky: [],
592
- hasAdditionalColumnLevel: true,
593
- },
594
- ],
595
- };
596
-
597
- const pivotTable = converter.createTables(data, strings)[0];
598
- expect(pivotTable.cells.length).toEqual(11);
599
- expect(pivotTable.cells[0].length).toEqual(4);
600
- expect(pivotTable.cells[0][0]).toEqual({
601
- value: '',
602
- rowSpan: 1,
603
- colSpan: 1,
604
- isHeader: false,
605
- cssClass: PivotTableConverter.emptyClass,
606
- stickyStart: undefined,
607
- stickyTop: undefined,
608
- });
609
- expect(pivotTable.cells[0][2]).toEqual({
610
- value: 'X',
611
- rowSpan: 1,
612
- colSpan: 1,
613
- isHeader: true,
614
- cssClass: PivotTableConverter.columnHeaderClass,
615
- background: undefined,
616
- constraint: undefined,
617
- label: undefined,
618
- stickyTop: undefined,
619
- });
620
- expect(pivotTable.cells[0][3]).toEqual({
621
- value: 'Y',
622
- rowSpan: 1,
623
- colSpan: 1,
624
- isHeader: true,
625
- cssClass: PivotTableConverter.columnHeaderClass,
626
- background: undefined,
627
- constraint: undefined,
628
- label: undefined,
629
- stickyTop: undefined,
630
- });
631
-
632
- expect(pivotTable.cells[1][2].value).toEqual('1');
633
- expect(pivotTable.cells[1][3].value).toEqual('2');
634
- expect(pivotTable.cells[2][2].value).toEqual('2');
635
- expect(pivotTable.cells[2][3].value).toEqual('');
636
- expect(pivotTable.cells[4][2].value).toEqual('6');
637
- expect(pivotTable.cells[4][3].value).toEqual('7');
638
-
639
- expect(pivotTable.cells[7][2].value).toEqual('9');
640
- expect(pivotTable.cells[7][3].value).toEqual('18');
641
-
642
- expect(pivotTable.cells[8][2].value).toEqual('');
643
- expect(pivotTable.cells[8][3].value).toEqual('4');
644
- expect(pivotTable.cells[9][2].value).toEqual('0');
645
- expect(pivotTable.cells[9][3].value).toEqual('4');
646
-
647
- expect(pivotTable.cells[10][2].value).toEqual('15');
648
- expect(pivotTable.cells[10][3].value).toEqual('29');
649
- });
650
-
651
- it('should return table by column and values percentage', () => {
652
- const data: LmrPivotData = {
653
- data: [
654
- {
655
- valueTitles: ['X', 'Y'],
656
- rowHeaders: [
657
- {
658
- title: 'A',
659
- children: [
660
- {title: 'a1', targetIndex: 0, color: undefined, isValueHeader: false},
661
- {title: 'a2', targetIndex: 1, color: undefined, isValueHeader: false},
662
- {title: 'a3', targetIndex: 2, color: undefined, isValueHeader: false},
663
- ],
664
- color: undefined,
665
- isValueHeader: false,
666
- },
667
- {
668
- title: 'B',
669
- children: [
670
- {title: 'a2', targetIndex: 3, color: undefined, isValueHeader: false},
671
- {title: 'a3', targetIndex: 4, color: undefined, isValueHeader: false},
672
- ],
673
- color: undefined,
674
- isValueHeader: false,
675
- },
676
- {
677
- title: 'C',
678
- children: [{title: 'a1', targetIndex: 5, color: undefined, isValueHeader: false}],
679
- color: undefined,
680
- isValueHeader: false,
681
- },
682
- ],
683
- columnHeaders: [
684
- {title: 'X', targetIndex: 0, color: undefined, isValueHeader: false},
685
- {title: 'Y', targetIndex: 1, color: undefined, isValueHeader: false},
686
- ],
687
- values: [
688
- ['10%', '20%'],
689
- ['20%', null],
690
- ['30%', '50%'],
691
- ['80%', '90%'],
692
- ['10%', '90%'],
693
- [null, '40%'],
694
- ],
695
- dataResources: [],
696
- valuesConstraints: [
697
- new PercentageConstraint({} as PercentageConstraintConfig),
698
- new PercentageConstraint({} as PercentageConstraintConfig),
699
- ],
700
- rowShowSums: [true, true],
701
- rowSticky: [],
702
- columnShowSums: [],
703
- columnSticky: [],
704
- hasAdditionalColumnLevel: true,
705
- },
706
- ],
707
- };
708
-
709
- const pivotTable = converter.createTables(data, strings)[0];
710
-
711
- expect(pivotTable.cells[1][2].value).toEqual('10%');
712
- expect(pivotTable.cells[1][3].value).toEqual('20%');
713
- expect(pivotTable.cells[2][2].value).toEqual('20%');
714
- expect(pivotTable.cells[2][3].value).toEqual('');
715
- expect(pivotTable.cells[4][2].value).toEqual('60%');
716
- expect(pivotTable.cells[4][3].value).toEqual('70%');
717
-
718
- expect(pivotTable.cells[7][2].value).toEqual('90%');
719
- expect(pivotTable.cells[7][3].value).toEqual('180%');
720
-
721
- expect(pivotTable.cells[8][2].value).toEqual('');
722
- expect(pivotTable.cells[8][3].value).toEqual('40%');
723
- expect(pivotTable.cells[9][2].value).toEqual('0%');
724
- expect(pivotTable.cells[9][3].value).toEqual('40%');
725
-
726
- expect(pivotTable.cells[10][2].value).toEqual('150%');
727
- expect(pivotTable.cells[10][3].value).toEqual('290%');
728
- });
729
-
730
- it('should return table by column and values', () => {
731
- const data: LmrPivotData = {
732
- data: [
733
- {
734
- valueTitles: ['X', 'Y', 'Z'],
735
- rowHeaders: [],
736
- columnHeaders: [
737
- {
738
- title: 'A',
739
- children: [
740
- {title: 'X', targetIndex: 0, color: undefined, isValueHeader: false},
741
- {title: 'Y', targetIndex: 1, color: undefined, isValueHeader: false},
742
- {title: 'Z', targetIndex: 2, color: undefined, isValueHeader: false},
743
- ],
744
- color: undefined,
745
- isValueHeader: false,
746
- },
747
- {
748
- title: 'B',
749
- children: [
750
- {title: 'X', targetIndex: 3, color: undefined, isValueHeader: false},
751
- {title: 'Y', targetIndex: 4, color: undefined, isValueHeader: false},
752
- {title: 'Z', targetIndex: 5, color: undefined, isValueHeader: false},
753
- ],
754
- color: undefined,
755
- isValueHeader: false,
756
- },
757
- {
758
- title: 'C',
759
- children: [
760
- {title: 'X', targetIndex: 6, color: undefined, isValueHeader: false},
761
- {title: 'Y', targetIndex: 7, color: undefined, isValueHeader: false},
762
- {title: 'Z', targetIndex: 8, color: undefined, isValueHeader: false},
763
- ],
764
- color: undefined,
765
- isValueHeader: false,
766
- },
767
- ],
768
- values: [[1, 5, 6, 2, null, 1, 4, 5, null]],
769
- dataResources: [],
770
- rowSticky: [],
771
- rowShowSums: [],
772
- columnShowSums: [true],
773
- columnSticky: [],
774
- hasAdditionalColumnLevel: true,
775
- },
776
- ],
777
- };
778
-
779
- const pivotTable = converter.createTables(data, strings)[0];
780
- expect(pivotTable.cells[0][0]).toEqual({
781
- value: 'A',
782
- isHeader: true,
783
- colSpan: 3,
784
- rowSpan: 1,
785
- cssClass: PivotTableConverter.columnHeaderClass,
786
- background: undefined,
787
- constraint: undefined,
788
- label: undefined,
789
- stickyTop: undefined,
790
- });
791
- expect(pivotTable.cells[0][3]).toEqual({
792
- value: 'B',
793
- isHeader: true,
794
- colSpan: 3,
795
- rowSpan: 1,
796
- cssClass: PivotTableConverter.columnHeaderClass,
797
- background: undefined,
798
- constraint: undefined,
799
- label: undefined,
800
- stickyTop: undefined,
801
- });
802
- expect(pivotTable.cells[0][6]).toEqual({
803
- value: 'C',
804
- isHeader: true,
805
- colSpan: 3,
806
- rowSpan: 1,
807
- cssClass: PivotTableConverter.columnHeaderClass,
808
- background: undefined,
809
- constraint: undefined,
810
- label: undefined,
811
- stickyTop: undefined,
812
- });
813
- expect(pivotTable.cells[0][9]).toEqual({
814
- value: undefined,
815
- summary: summaryString,
816
- isHeader: true,
817
- colSpan: 3,
818
- rowSpan: 1,
819
- cssClass: PivotTableConverter.columnGroupHeaderClass,
820
- constraint: undefined,
821
- background: COLOR_GRAY100,
822
- label: undefined,
823
- stickyTop: undefined,
824
- });
825
-
826
- expect(pivotTable.cells[1][9]).toEqual({
827
- value: 'X',
828
- isHeader: true,
829
- colSpan: 1,
830
- rowSpan: 1,
831
- cssClass: PivotTableConverter.columnGroupHeaderClass,
832
- background: COLOR_GRAY100,
833
- stickyTop: undefined,
834
- });
835
- expect(pivotTable.cells[1][10]).toEqual({
836
- value: 'Y',
837
- isHeader: true,
838
- colSpan: 1,
839
- rowSpan: 1,
840
- cssClass: PivotTableConverter.columnGroupHeaderClass,
841
- background: COLOR_GRAY100,
842
- stickyTop: undefined,
843
- });
844
- expect(pivotTable.cells[1][11]).toEqual({
845
- value: 'Z',
846
- isHeader: true,
847
- colSpan: 1,
848
- rowSpan: 1,
849
- cssClass: PivotTableConverter.columnGroupHeaderClass,
850
- background: COLOR_GRAY100,
851
- stickyTop: undefined,
852
- });
853
-
854
- expect(pivotTable.cells[2][0].value).toEqual('1');
855
- expect(pivotTable.cells[2][1].value).toEqual('5');
856
- expect(pivotTable.cells[2][2].value).toEqual('6');
857
- expect(pivotTable.cells[2][3].value).toEqual('2');
858
- expect(pivotTable.cells[2][4].value).toEqual('');
859
- expect(pivotTable.cells[2][5].value).toEqual('1');
860
- expect(pivotTable.cells[2][6].value).toEqual('4');
861
- expect(pivotTable.cells[2][7].value).toEqual('5');
862
- expect(pivotTable.cells[2][8].value).toEqual('');
863
- expect(pivotTable.cells[2][9].value).toEqual('7');
864
- expect(pivotTable.cells[2][10].value).toEqual('10');
865
- expect(pivotTable.cells[2][11].value).toEqual('7');
866
- });
867
-
868
- it('should return table by rows and columns and values', () => {
869
- const data: LmrPivotData = {
870
- data: [
871
- {
872
- valueTitles: ['V'],
873
- rowHeaders: [
874
- {
875
- title: 'A',
876
- children: [
877
- {title: 'a1', targetIndex: 0, color: undefined, isValueHeader: false},
878
- {title: 'a2', targetIndex: 1, color: undefined, isValueHeader: false},
879
- {title: 'a3', targetIndex: 2, color: undefined, isValueHeader: false},
880
- ],
881
- color: undefined,
882
- isValueHeader: false,
883
- },
884
- {
885
- title: 'B',
886
- children: [
887
- {title: 'a2', targetIndex: 3, color: undefined, isValueHeader: false},
888
- {title: 'a3', targetIndex: 4, color: undefined, isValueHeader: false},
889
- ],
890
- color: undefined,
891
- isValueHeader: false,
892
- },
893
- ],
894
- columnHeaders: [
895
- {
896
- title: 'X',
897
- children: [
898
- {title: 'x1', targetIndex: 0, color: undefined, isValueHeader: false},
899
- {title: 'x2', targetIndex: 1, color: undefined, isValueHeader: false},
900
- ],
901
- color: undefined,
902
- isValueHeader: false,
903
- },
904
- {
905
- title: 'Y',
906
- children: [
907
- {title: 'x2', targetIndex: 2, color: undefined, isValueHeader: false},
908
- {title: 'x3', targetIndex: 3, color: undefined, isValueHeader: false},
909
- {title: 'x4', targetIndex: 4, color: undefined, isValueHeader: false},
910
- ],
911
- color: undefined,
912
- isValueHeader: false,
913
- },
914
- ],
915
- values: [
916
- [1, 2, 4, 1, 2],
917
- [4, 3, 3, 3, 3],
918
- [5, 0, 1, 2, 2],
919
- [2, 4, 7, 1, 3],
920
- [1, 0, 1, 1, 2],
921
- ],
922
- dataResources: [],
923
- rowSticky: [],
924
- rowShowSums: [false, true],
925
- columnSticky: [],
926
- columnShowSums: [true, true],
927
- },
928
- ],
929
- };
930
-
931
- const pivotTable = converter.createTables(data, strings)[0];
932
- expect(pivotTable.cells[0][0]).toEqual({
933
- value: '',
934
- rowSpan: 1,
935
- colSpan: 1,
936
- isHeader: false,
937
- cssClass: PivotTableConverter.emptyClass,
938
- stickyTop: undefined,
939
- stickyStart: undefined,
940
- });
941
-
942
- expect(pivotTable.cells[5][0]).toEqual({
943
- value: 'A',
944
- summary: headerSummaryString,
945
- rowSpan: 1,
946
- colSpan: 2,
947
- isHeader: true,
948
- cssClass: PivotTableConverter.rowGroupHeaderClass,
949
- constraint: undefined,
950
- background: COLOR_GRAY200,
951
- label: undefined,
952
- stickyStart: undefined,
953
- });
954
- expect(pivotTable.cells[6][0]).toEqual({
955
- value: 'B',
956
- rowSpan: 2,
957
- colSpan: 1,
958
- isHeader: true,
959
- cssClass: PivotTableConverter.rowHeaderClass,
960
- background: undefined,
961
- constraint: undefined,
962
- label: undefined,
963
- stickyStart: undefined,
964
- });
965
- expect(pivotTable.cells[8][0]).toEqual({
966
- value: 'B',
967
- summary: headerSummaryString,
968
- rowSpan: 1,
969
- colSpan: 2,
970
- isHeader: true,
971
- cssClass: PivotTableConverter.rowGroupHeaderClass,
972
- constraint: undefined,
973
- background: COLOR_GRAY200,
974
- label: undefined,
975
- stickyStart: undefined,
976
- });
977
-
978
- expect(pivotTable.cells[0][2]).toEqual({
979
- value: 'X',
980
- rowSpan: 1,
981
- colSpan: 2,
982
- isHeader: true,
983
- cssClass: PivotTableConverter.columnHeaderClass,
984
- background: undefined,
985
- constraint: undefined,
986
- label: undefined,
987
- stickyTop: undefined,
988
- });
989
- expect(pivotTable.cells[0][5]).toEqual({
990
- value: 'Y',
991
- rowSpan: 1,
992
- colSpan: 3,
993
- isHeader: true,
994
- cssClass: PivotTableConverter.columnHeaderClass,
995
- background: undefined,
996
- constraint: undefined,
997
- label: undefined,
998
- stickyTop: undefined,
999
- });
1000
- expect(pivotTable.cells[0][4]).toEqual({
1001
- value: 'X',
1002
- summary: headerSummaryString,
1003
- rowSpan: 2,
1004
- colSpan: 1,
1005
- isHeader: true,
1006
- cssClass: PivotTableConverter.columnGroupHeaderClass,
1007
- constraint: undefined,
1008
- background: COLOR_GRAY200,
1009
- label: undefined,
1010
- stickyTop: undefined,
1011
- });
1012
- expect(pivotTable.cells[0][8]).toEqual({
1013
- value: 'Y',
1014
- summary: headerSummaryString,
1015
- rowSpan: 2,
1016
- colSpan: 1,
1017
- isHeader: true,
1018
- cssClass: PivotTableConverter.columnGroupHeaderClass,
1019
- constraint: undefined,
1020
- background: COLOR_GRAY200,
1021
- label: undefined,
1022
- stickyTop: undefined,
1023
- });
1024
- expect(pivotTable.cells[0][9]).toEqual({
1025
- value: undefined,
1026
- summary: summaryString,
1027
- rowSpan: 2,
1028
- colSpan: 1,
1029
- isHeader: true,
1030
- cssClass: PivotTableConverter.columnGroupHeaderClass,
1031
- constraint: undefined,
1032
- background: COLOR_GRAY100,
1033
- label: undefined,
1034
- stickyTop: undefined,
1035
- });
1036
-
1037
- expect(pivotTable.cells[2].slice(2).map(v => v.value)).toEqual(['1', '2', '3', '4', '1', '2', '7', '10']);
1038
- expect(pivotTable.cells[3].slice(2).map(v => v.value)).toEqual(['4', '3', '7', '3', '3', '3', '9', '16']);
1039
- expect(pivotTable.cells[4].slice(2).map(v => v.value)).toEqual(['5', '0', '5', '1', '2', '2', '5', '10']);
1040
- expect(pivotTable.cells[5].slice(2).map(v => v.value)).toEqual(['10', '5', '15', '8', '6', '7', '21', '36']);
1041
- expect(pivotTable.cells[6].slice(2).map(v => v.value)).toEqual(['2', '4', '6', '7', '1', '3', '11', '17']);
1042
- expect(pivotTable.cells[7].slice(2).map(v => v.value)).toEqual(['1', '0', '1', '1', '1', '2', '4', '5']);
1043
- expect(pivotTable.cells[8].slice(2).map(v => v.value)).toEqual(['3', '4', '7', '8', '2', '5', '15', '22']);
1044
- });
1045
- });