1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
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
444
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
482
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
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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
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 | 1×
1×
1×
1×
339×
1×
347×
347×
347×
339×
339×
339×
245×
245×
339×
339×
3×
339×
339×
1×
28×
28×
28×
28×
5×
25×
3×
3×
3×
5×
25×
28×
1×
359×
359×
359×
359×
6×
353×
353×
353×
1×
142×
142×
142×
142×
142×
142×
142×
142×
142×
72×
72×
70×
136×
136×
136×
136×
136×
136×
136×
142×
1×
72×
72×
72×
72×
72×
144×
72×
144×
72×
72×
72×
144×
144×
144×
67×
67×
67×
77×
77×
77×
144×
144×
1×
4267×
4267×
4267×
4267×
4267×
4267×
4267×
4267×
4267×
4169×
351×
351×
4169×
4169×
4112×
11155×
11155×
11155×
11155×
11155×
11155×
11155×
3914×
1×
4169×
4169×
4169×
1×
24041×
24041×
4169×
4169×
4169×
19872×
19872×
19872×
19872×
13116×
13116×
6756×
6756×
6756×
8937×
6756×
6756×
6756×
6756×
1×
19872×
10925×
8947×
8947×
8947×
8947×
1×
17894×
17894×
17894×
17894×
17894×
32741×
32741×
31847×
32741×
17894×
32741×
17894×
17894×
1×
6756×
6756×
6756×
6756×
6756×
6756×
4179×
4179×
4179×
4179×
2577×
2577×
2577×
2577×
1×
10925×
10925×
10925×
10925×
10925×
10925×
10925×
10925×
10925×
10925×
10925×
13116×
10925×
10925×
10925×
10925×
10925×
10925×
10925×
10925×
10925×
13116×
13116×
13116×
13116×
13116×
13116×
13116×
7833×
7833×
7833×
5283×
5283×
5283×
13116×
13114×
13114×
10925×
1×
4169×
4169×
4169×
13116×
13116×
13116×
157414×
13116×
13116×
13116×
157414×
157414×
157414×
4169×
1×
2×
2×
2×
2×
2×
2×
1×
1×
2×
2×
2×
2×
3×
3×
1×
2×
2×
2×
1×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
359×
13258×
13258×
13258×
79×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13035×
13035×
13179×
28×
13151×
40×
13111×
40×
40×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
24×
13×
13×
13×
13×
11×
13155×
419×
13155×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
12960×
30×
12960×
12960×
13179×
110×
110×
110×
110×
13179×
13179×
2301×
2301×
2301×
10878×
13179×
13179×
359×
359×
13258×
359×
11×
359×
1×
12960×
12960×
12960×
12960×
12960×
12960×
12960×
12960×
12960×
12960×
12960×
665×
665×
665×
18×
18×
18×
18×
12960×
12960×
207×
207×
207×
207×
414×
414×
414×
414×
414×
207×
207×
207×
12960×
12936×
13225×
13225×
13225×
12637×
12936×
41×
41×
41×
41×
41×
41×
24×
24×
12960×
12960×
1×
13179×
13179×
13179×
13179×
13179×
13179×
13179×
2904×
2904×
2904×
2904×
10275×
132302×
10741×
13179×
1×
12931×
12931×
12931×
12931×
12931×
1×
110×
110×
110×
110×
110×
990×
990×
110×
110×
110×
110×
110×
110×
110×
110×
110×
110×
1×
12960×
12960×
12960×
24×
24×
12483×
12483×
32×
32×
421×
421×
12960×
1×
339×
339×
339×
339×
339×
339×
1×
1×
| define(["require", "exports", "../utils/helper", "@syncfusion/ej2-base", "../utils/helper", "../model/constants"], function (require, exports, helper_1, ej2_base_1, helper_2, constants_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var LayoutPanel = (function () {
function LayoutPanel(treemap) {
this.treemap = treemap;
}
LayoutPanel.prototype.processLayoutPanel = function () {
var data;
var totalRect;
if (this.treemap.treemapLevelData.levelsData && this.treemap.treemapLevelData.levelsData.length > 0) {
data = (!ej2_base_1.isNullOrUndefined(this.treemap.initialDrillDown.groupIndex) &&
!ej2_base_1.isNullOrUndefined(this.treemap.initialDrillDown.groupName)) &&
(ej2_base_1.isNullOrUndefined(this.treemap.drilledItems) ? ej2_base_1.isNullOrUndefined(this.treemap.drilledItems)
: this.treemap.drilledItems.length === 0) ?
this.getDrilldownData(this.treemap.treemapLevelData.levelsData[0], [])[0] : this.treemap.treemapLevelData.levelsData[0];
totalRect = ej2_base_1.extend({}, this.treemap.areaRect, totalRect, false);
if (!ej2_base_1.isNullOrUndefined(this.treemap.treeMapLegendModule) && !ej2_base_1.isNullOrUndefined(this.treemap.totalRect)) {
Eif (this.treemap.legendSettings.position !== 'Float') {
totalRect = this.treemap.totalRect;
}
}
Iif (!ej2_base_1.isNullOrUndefined(this.treemap.currentLevel) &&
(ej2_base_1.isNullOrUndefined(this.treemap.drilledItems) ? !ej2_base_1.isNullOrUndefined(this.treemap.drilledItems)
: this.treemap.drilledItems.length !== 0)) {
var count = this.treemap.drilledItems.length - 1;
var x = this.treemap.drilledItems[count]['data'];
var y = {};
y[this.treemap.drilledItems[count]['data']['groupName']] = [x];
if (!ej2_base_1.isNullOrUndefined(this.treemap.initialDrillDown.groupIndex) && !this.treemap.enableBreadcrumb) {
this.treemap.currentLevel = this.treemap.drilledItems[count]['data']['groupIndex'];
}
this.calculateLayoutItems(y || this.treemap.treemapLevelData.levelsData[0], totalRect);
this.renderLayoutItems();
}
else {
if (!ej2_base_1.isNullOrUndefined(this.treemap.initialDrillDown.groupIndex) &&
(ej2_base_1.isNullOrUndefined(this.treemap.drilledItems) ? ej2_base_1.isNullOrUndefined(this.treemap.drilledItems)
: this.treemap.drilledItems.length === 0)) {
this.treemap.currentLevel = this.treemap.initialDrillDown.groupIndex;
}
this.calculateLayoutItems(data || this.treemap.treemapLevelData.levelsData[0], totalRect);
this.renderLayoutItems();
}
}
};
LayoutPanel.prototype.getDrilldownData = function (data, drillData) {
var treemap = this.treemap;
var newData = {};
var child = helper_2.findChildren(data)['values'];
if (child && child.length > 0 && drillData.length === 0) {
for (var i = 0; i < child.length; i++) {
if (child[i]['groupIndex'] === treemap.initialDrillDown.groupIndex &&
child[i]['name'] === treemap.initialDrillDown.groupName) {
child[i]['isDrilled'] = true;
newData[child[i]['groupName']] = [child[i]];
drillData.push(newData);
}
}
for (var j = 0; j < child.length; j++) {
this.getDrilldownData(child[j], drillData);
}
}
return drillData;
};
LayoutPanel.prototype.calculateLayoutItems = function (data, rect) {
this.renderItems = [];
this.parentData = [];
Eif (!ej2_base_1.isNullOrUndefined(this.treemap.weightValuePath)) {
if (this.treemap.layoutType.indexOf('SliceAndDice') > -1) {
this.computeSliceAndDiceDimensional(data, rect);
}
else {
rect.height = rect.height + rect.y;
rect.width = rect.width + rect.x;
this.computeSquarifyDimensional(data, rect);
}
}
};
LayoutPanel.prototype.computeSliceAndDiceDimensional = function (data, coords) {
var leafItem = this.treemap.leafItemSettings;
var rect;
var groups = this.treemap.levels;
var groupIndex;
var isLeafItem = false;
var children = helper_2.findChildren(data)['values'];
var gap;
var headerHeight;
if (children && children.length > 0) {
this.sliceAndDiceProcess(children, coords);
if (this.treemap.levels.length > 0) {
for (var i = 0; i < children.length; i++) {
groupIndex = children[i]['groupIndex'];
isLeafItem = (groups.length === 0 || groupIndex === groups.length);
gap = isLeafItem ? leafItem.gap : groups[groupIndex].groupGap;
headerHeight = groups.length === 0 ? 0 : groups[groupIndex] ? groups[groupIndex].showHeader ?
groups[groupIndex].headerHeight : 0 : groups[groupIndex - 1].showHeader ?
groups[groupIndex - 1].headerHeight : 0;
rect = children[i]['rect'];
rect = new helper_1.Rect(rect.x + (gap / 2), rect.y + (headerHeight + (gap / 2)), rect.width - gap, Math.abs(rect.height - (gap + headerHeight)));
this.computeSliceAndDiceDimensional(children[i], rect);
}
}
}
return data;
};
LayoutPanel.prototype.sliceAndDiceProcess = function (processData, rect) {
var parentArea = rect.height * rect.width;
var levels = this.treemap.levels;
var childValue;
var alottedValue = 0;
var totalWeight = 0;
processData.forEach(function (data) { totalWeight += data['weight']; });
processData.forEach(function (child) {
child['weightArea'] = parentArea * child['weight'] / totalWeight;
});
var isHorizontal = (this.treemap.layoutType === 'SliceAndDiceAuto') ? (rect.width > rect.height) :
(this.treemap.layoutType === 'SliceAndDiceHorizontal');
processData.sort(helper_1.itemsToOrder);
for (var i = 0; i < processData.length; i++) {
var item = processData[i];
item['isLeafItem'] = (levels.length === 0) || ((this.treemap.isHierarchicalData ||
ej2_base_1.isNullOrUndefined(this.treemap.leafItemSettings.labelPath)) ?
item['groupIndex'] === levels.length - 1 : item['groupIndex'] === this.treemap.levels.length);
if (isHorizontal) {
childValue = ((parentArea / totalWeight) * processData[i]['weight']) / rect.height;
Eif (alottedValue <= rect.width) {
processData[i]['rect'] = new helper_1.Rect(alottedValue + rect.x, rect.y, childValue, rect.height);
}
}
else {
childValue = ((parentArea / totalWeight) * processData[i]['weight']) / rect.width;
Eif (alottedValue <= rect.height) {
processData[i]['rect'] = new helper_1.Rect(rect.x, alottedValue + rect.y, rect.width, childValue);
}
}
alottedValue += childValue;
this.renderItems.push(processData[i]);
}
};
LayoutPanel.prototype.computeSquarifyDimensional = function (data, coords) {
var leaf = this.treemap.leafItemSettings;
var rect;
var levels = this.treemap.levels;
var item;
var child = helper_2.findChildren(data)['values'];
var index;
var padding;
var headerHeight;
if (child && child.length > 0) {
if (this.parentData.length === 0) {
this.parentData = [];
this.parentData.push(child);
}
this.calculateChildrenLayout(data, child, coords);
if (this.treemap.levels.length > 0) {
for (var i = 0; i < child.length; i++) {
item = child[i];
index = item['groupIndex'];
rect = item['rect'];
padding = (item['isLeafItem'] ? leaf.padding : levels[index].groupPadding) / 2;
headerHeight = this.treemap.isHierarchicalData ? index === 0 && item['isLeafItem'] ? 0 : levels[index] ?
levels[index].showHeader ? levels[index].headerHeight : 0 : 0 :
(levels.length === 0) ? 0 : levels[index] ?
levels[index].showHeader ? levels[index].headerHeight : 0 : 0;
rect = new helper_1.Rect(rect.x + padding, rect.y + (headerHeight + padding), rect.width - padding, rect.height - padding);
if (!item['isLeafItem'] && item['weight'] > 0) {
this.computeSquarifyDimensional(child[i], rect);
}
}
}
}
};
LayoutPanel.prototype.calculateChildrenLayout = function (parent, children, coords) {
this.computeTotalArea(children, helper_1.getArea(coords));
children.sort(helper_1.orderByArea);
this.performRowsLayout(children, [], coords, []);
};
LayoutPanel.prototype.performRowsLayout = function (data, currentRow, rect, stack) {
var dataLength = data.length;
if (dataLength === 0) {
var newCoordinates = this.getCoordinates(currentRow, rect);
var newStack = stack.concat(newCoordinates);
return newStack;
}
var width = helper_1.getShortestEdge(rect);
var nextDatum = data[0];
var restData = data.slice(1, dataLength);
if (this.aspectRatio(currentRow, nextDatum, width)) {
var newRow = currentRow.concat(nextDatum);
return this.performRowsLayout(restData, newRow, rect, stack);
}
else {
var currentRowLength = currentRow.length;
var valueSum = 0;
for (var i = 0; i < currentRowLength; i += 1) {
valueSum += currentRow[i]['itemArea'];
}
var newContainer = this.cutArea(rect, valueSum);
var newCoordinates = this.getCoordinates(currentRow, rect);
var newStack = stack.concat(newCoordinates);
return this.performRowsLayout(data, [], newContainer, newStack);
}
};
LayoutPanel.prototype.aspectRatio = function (currentRow, nextDatum, length) {
if (currentRow.length === 0) {
return true;
}
else {
var newRow = currentRow.concat(nextDatum);
var currentMaxAspectRatio = this.findMaxAspectRatio(currentRow, length);
var newMaxAspectRatio = this.findMaxAspectRatio(newRow, length);
return (currentMaxAspectRatio >= newMaxAspectRatio);
}
};
LayoutPanel.prototype.findMaxAspectRatio = function (row, length) {
var rowLength = row.length;
var minArea = Infinity;
var maxArea = -Infinity;
var sumArea = 0;
for (var i = 0; i < rowLength; i += 1) {
var area = row[i]['itemArea'];
if (area < minArea) {
minArea = area;
}
if (area > maxArea) {
maxArea = area;
}
sumArea += area;
}
var result = Math.max((Math.pow(length, 2)) * maxArea / (Math.pow(sumArea, 2)), (Math.pow(sumArea, 2)) /
((Math.pow(length, 2)) * minArea));
return result;
};
LayoutPanel.prototype.cutArea = function (rect, area) {
var newContainer = helper_1.convertToContainer(rect);
var width = newContainer.width;
var height = newContainer.height;
var xOffset = newContainer.x;
var yOffset = newContainer.y;
if (width >= height) {
var areaWidth = area / height;
var newWidth = width - areaWidth;
var container = {
x: xOffset + areaWidth,
y: yOffset,
width: newWidth,
height: height
};
return helper_1.convertToRect(container);
}
else {
var areaHeight = area / width;
var newHeight = height - areaHeight;
var container = {
x: xOffset,
y: yOffset + areaHeight,
width: width,
height: newHeight
};
return helper_1.convertToRect(container);
}
};
LayoutPanel.prototype.getCoordinates = function (row, rect) {
var container = helper_1.convertToContainer(rect);
var width = container.width;
var height = container.height;
var xOffset = container.x;
var yOffset = container.y;
var rowLength = row.length;
var levels = this.treemap.levels;
var leaf = this.treemap.leafItemSettings;
var index;
var valueSum = 0;
for (var i = 0; i < rowLength; i += 1) {
valueSum += row[i]['itemArea'];
}
var areaWidth = valueSum / height;
var areaHeight = valueSum / width;
var subXOffset = xOffset;
var subYOffset = yOffset;
var padding;
var coordinates = [];
var isParent;
var parentRect;
for (var i = 0; i < rowLength; i += 1) {
var item = row[i];
index = item['groupIndex'];
item['isLeafItem'] = (levels.length === 0) || (this.treemap.isHierarchicalData ? index === levels.length :
ej2_base_1.isNullOrUndefined(leaf.labelPath) ? false : index === levels.length);
isParent = helper_1.isParentItem(this.parentData[0], item);
parentRect = isParent ? this.treemap.areaRect : item['parent'].rect;
padding = item['isLeafItem'] ? leaf.padding : levels[index].groupPadding;
if (width >= height) {
var y1 = subYOffset + item['itemArea'] / areaWidth;
item['rect'] = {
x: subXOffset,
y: subYOffset,
width: subXOffset + areaWidth,
height: y1
};
subYOffset = y1;
}
else {
var x1 = subXOffset + item['itemArea'] / areaHeight;
item['rect'] = {
x: subXOffset,
y: subYOffset,
width: x1,
height: subYOffset + areaHeight
};
subXOffset = x1;
}
if (item['weight'] > 0 && (isParent || (Math.round(rect.y + (padding / 2)) <=
Math.round(parentRect.y + (parentRect.height - parentRect.y)) && Math.round(rect.x + (padding / 2)) <=
Math.round(parentRect.x + (parentRect.width - parentRect.x))))) {
this.renderItems.push(item);
coordinates.push(item);
}
}
return coordinates;
};
LayoutPanel.prototype.computeTotalArea = function (data, area) {
var dataLength = data.length;
var result = [];
for (var i = 0; i < dataLength; i += 1) {
var dataLength_1 = data.length;
var dataSum = 0;
for (var i_1 = 0; i_1 < dataLength_1; i_1 += 1) {
dataSum += data[i_1]['weight'];
}
var multiplier = area / dataSum;
var datum = void 0;
for (var j = 0; j < dataLength_1; j++) {
datum = data[j];
datum['itemArea'] = datum['weight'] * multiplier;
result.push(datum);
}
}
return result;
};
LayoutPanel.prototype.onDemandProcess = function (childItems) {
var parentItem = {};
var totalRect;
parentItem = childItems[0]['parent'];
this.treemap.currentLevel = parentItem['isDrilled'] ? parentItem['groupIndex'] : null;
var parentItemGroupname = {};
if (ej2_base_1.isNullOrUndefined(parentItem['groupName'])) {
parentItemGroupname = parentItem;
}
else {
parentItemGroupname[parentItem['groupName']] = [parentItem];
}
totalRect = ej2_base_1.extend({}, this.treemap.areaRect, totalRect, false);
Iif (!ej2_base_1.isNullOrUndefined(this.treemap.treeMapLegendModule) && !ej2_base_1.isNullOrUndefined(this.treemap.totalRect)) {
totalRect = this.treemap.totalRect;
}
var count = this.treemap.levels.length;
for (var i = 0; i < count; i++) {
var levelCount = childItems[0]['groupIndex'];
if (count === levelCount) {
this.treemap.levels[count] = this.treemap.levels[i];
}
else {
this.treemap.levels.splice(count - 1, 1);
}
}
this.calculateLayoutItems(parentItemGroupname, totalRect);
this.renderLayoutItems();
};
LayoutPanel.prototype.renderLayoutItems = function () {
var _this = this;
var position;
var treeMap = this.treemap;
var txtVisible;
var getItemColor;
var eventArgs;
this.renderer = treeMap.renderer;
var pathOptions;
var elementID = treeMap.element.id;
var index;
var templatePosition;
var mode = treeMap.layoutType;
var rect;
var format;
var interSectAction = this.treemap.leafItemSettings.interSectAction;
var fill;
var item;
var renderText;
var opacity;
var rectPath = '';
var secondaryEle = document.getElementById(treeMap.element.id + '_Secondary_Element');
var groupId;
var templateEle;
var gap;
var textStyle;
var levels = treeMap.levels;
this.layoutGroup = this.renderer.createGroup({ id: elementID + '_TreeMap_' + mode + '_Layout' });
var itemGroup;
var template;
var border;
var templateGroup = ej2_base_1.createElement('div', {
id: treeMap.element.id + '_Label_Template_Group',
className: 'template'
});
templateGroup.style.cssText = 'overflow: hidden; position: absolute;pointer-events: none;' +
'top:' + treeMap.areaRect.y + 'px;' +
'left:' + treeMap.areaRect.x + 'px;' +
'height:' + treeMap.areaRect.height + 'px;' +
'width:' + treeMap.areaRect.width + 'px;';
var isLeafItem = false;
var leaf = treeMap.leafItemSettings;
var childItems;
var connectorText;
var _loop_1 = function (i) {
item = this_1.renderItems[i];
index = item['groupIndex'];
if (this_1.treemap.drillDownView && ej2_base_1.isNullOrUndefined(this_1.treemap.currentLevel)
&& index > 0 || this_1.treemap.drillDownView
&& index > (this_1.treemap.currentLevel + 1)) {
return "continue";
}
rect = item['rect'];
isLeafItem = item['isLeafItem'];
groupId = elementID + '_Level_Index_' + index + '_Item_Index_' + i;
itemGroup = this_1.renderer.createGroup({ id: groupId + '_Group' });
gap = (isLeafItem ? leaf.gap : levels[index].groupGap) / 2;
var treemapItemRect = this_1.treemap.totalRect ? helper_1.convertToContainer(this_1.treemap.totalRect) : this_1.treemap.areaRect;
if (treeMap.layoutType === 'Squarified') {
rect.width = Math.abs(rect.x - rect.width) - gap;
rect.height = Math.abs(rect.y - rect.height) - gap;
}
if (treeMap.renderDirection === 'TopRightBottomLeft') {
rect.x = (treemapItemRect.x + treemapItemRect.width) - rect.width - Math.abs(treemapItemRect.x - rect.x);
}
else if (treeMap.renderDirection === 'BottomLeftTopRight') {
rect.y = (treemapItemRect.y + treemapItemRect.height) - rect.height - Math.abs(treemapItemRect.y - rect.y);
}
else if (treeMap.renderDirection === 'BottomRightTopLeft') {
rect.x = (treemapItemRect.x + treemapItemRect.width) - rect.width - Math.abs(treemapItemRect.x - rect.x);
rect.y = (treemapItemRect.y + treemapItemRect.height) - rect.height - Math.abs(treemapItemRect.y - rect.y);
}
getItemColor = this_1.getItemColor(isLeafItem, item);
fill = getItemColor['fill'];
opacity = getItemColor['opacity'];
format = isLeafItem ? leaf.labelFormat : (levels[index]).headerFormat;
var levelName;
txtVisible = isLeafItem ? leaf.showLabels : (levels[index]).showHeader;
if (index === this_1.treemap.currentLevel) {
if (this_1.treemap.enableBreadcrumb) {
var re = /#/gi;
connectorText = '#' + this_1.treemap.breadcrumbConnector + '#';
levelName = item['levelOrderName'].replace(re, connectorText);
levelName = index !== 0 ? '#' + levelName : levelName;
}
else {
levelName = item['name'];
}
}
else {
if (this_1.treemap.enableBreadcrumb) {
item['isDrilled'] = false;
}
levelName = item['name'];
}
renderText = helper_1.textFormatter(format, item['data'], this_1.treemap) || levelName || 'undefined';
childItems = helper_2.findChildren(item)['values'];
renderText = !isLeafItem && childItems && childItems.length > 0 && this_1.treemap.enableDrillDown ?
!item['isDrilled'] ? treeMap.enableRtl ? renderText + ' [+]' : '[+] ' + renderText :
treeMap.enableRtl ? renderText + ' [-]' : '[-] ' + renderText : renderText;
var fontFamily = (isLeafItem ? leaf.labelStyle.fontFamily : levels[index].headerStyle.fontFamily);
fontFamily = fontFamily || this_1.treemap.themeStyle.labelFontFamily;
var size = (isLeafItem ? leaf.labelStyle.size : levels[index].headerStyle.size);
size = size || this_1.treemap.themeStyle.labelFontSize;
var fontWeight = (isLeafItem ? leaf.labelStyle.fontWeight : levels[index].headerStyle.fontWeight);
fontWeight = fontWeight || this_1.treemap.themeStyle.fontWeight;
var color = (isLeafItem ? leaf.labelStyle.color : levels[index].headerStyle.color);
var fontStyle = (isLeafItem ? leaf.labelStyle.fontStyle : levels[index].headerStyle.fontStyle);
var textStyleOpacity = (isLeafItem ? leaf.labelStyle.opacity : levels[index].headerStyle.opacity);
textStyle = {
fontFamily: fontFamily, size: size, fontWeight: fontWeight, color: color, fontStyle: fontStyle, opacity: textStyleOpacity
};
border = isLeafItem ? leaf.border : levels[index].border;
position = !isLeafItem ? (levels[index].headerAlignment) === 'Near' ? 'TopLeft' : (levels[index].headerAlignment) === 'Center' ?
'TopCenter' : 'TopRight' : leaf.labelPosition;
templatePosition = isLeafItem ? leaf.templatePosition : levels[index].templatePosition;
template = isLeafItem ? leaf.labelTemplate : levels[index].headerTemplate;
item['options'] = { border: border, opacity: opacity, fill: fill };
eventArgs = {
cancel: false, name: constants_1.itemRendering, treemap: this_1.treemap, text: renderText,
currentItem: item, RenderItems: this_1.renderItems, options: item['options'], textColor: textStyle.color
};
this_1.treemap.trigger(constants_1.itemRendering, eventArgs, function (observedArgs) {
Eif (!observedArgs.cancel) {
rectPath = ' M ' + rect.x + ' ' + rect.y + ' L ' + (rect.x + rect.width) + ' ' + rect.y +
' L ' + (rect.x + rect.width) + ' ' + (rect.y + rect.height) + ' L ' + rect.x + ' ' + (rect.y + rect.height) + 'z';
pathOptions = new helper_1.PathOption(groupId + '_RectPath', fill, border.width, border.color, opacity, null, rectPath);
var path = _this.renderer.drawPath(pathOptions);
itemGroup.appendChild(path);
if (txtVisible) {
if (eventArgs.text !== renderText) {
eventArgs.text = helper_1.textFormatter(eventArgs.text, item['data'], _this.treemap) || levelName;
}
textStyle.color = eventArgs.textColor ? eventArgs.textColor : textStyle.color;
_this.renderItemText(eventArgs.text.toString(), itemGroup, textStyle, rect, interSectAction, groupId, fill, position, connectorText);
}
if (template) {
templateEle = _this.renderTemplate(secondaryEle, groupId, rect, templatePosition, template, item, isLeafItem);
Eif (!ej2_base_1.isNullOrUndefined(templateEle)) {
templateGroup.appendChild(templateEle);
_this.treemap.renderReactTemplates();
}
}
itemGroup.setAttribute('aria-label', item['name']);
if ((_this.treemap.enableDrillDown && isLeafItem) || (_this.treemap.selectionSettings.enable ||
_this.treemap.highlightSettings.enable)) {
itemGroup.setAttribute('role', 'button');
itemGroup.setAttribute('tabindex', _this.treemap.tabIndex.toString());
itemGroup.style.cursor = _this.treemap.highlightSettings.enable && !_this.treemap.selectionSettings.enable && (_this.treemap.enableDrillDown && item['groupIndex'] === (_this.treemap.levels.length - 1)) ? 'default' :
_this.treemap.highlightSettings.enable && !_this.treemap.selectionSettings.enable && !_this.treemap.enableDrillDown ? 'default' : 'pointer';
}
else {
itemGroup.setAttribute('role', 'region');
}
helper_1.maintainSelection(_this.treemap, itemGroup, 'treeMapSelection');
_this.layoutGroup.appendChild(itemGroup);
}
});
};
var this_1 = this;
for (var i = 0; i < this.renderItems.length; i++) {
_loop_1(i);
}
if (templateGroup.childNodes.length > 0) {
secondaryEle.appendChild(templateGroup);
}
this.treemap.svgObject.appendChild(this.layoutGroup);
};
LayoutPanel.prototype.renderItemText = function (text, parentElement, textStyle, rect, interSectAction, groupId, fill, position, connectorText) {
var padding = 5;
var textSize;
var textCollection = [];
var customText;
var tspanText = [];
var height = 0;
var textName;
textCollection = ((text.indexOf('<br>')) !== -1) ? text.split('<br>') : null;
customText = this.labelInterSectAction(rect, text, textStyle, interSectAction);
textSize = helper_1.measureText(textCollection && textCollection[0] || customText[0], textStyle);
if (this.treemap.enableRtl) {
var labelSize = helper_1.measureText(text, textStyle);
var drillSymbolCount = text.search('[+]') || text.search('[-]');
if (rect.width < labelSize.width && drillSymbolCount > 0) {
var label = text.substring(drillSymbolCount - 1, text.length);
var drillSymbol = '[+]';
var drillSymbolSize = helper_1.measureText(drillSymbol, textStyle);
customText['0'] = helper_1.textTrim(rect.width - drillSymbolSize.width - padding, customText[0], textStyle) + label;
}
}
var textLocation = helper_1.findLabelLocation(rect, position, textSize, 'Text', this.treemap);
if (!ej2_base_1.isNullOrUndefined(textCollection)) {
var collection = [];
var texts = null;
var maxNumber = [];
for (var i = 0; i < textCollection.length; i++) {
texts = helper_1.textTrim((rect.width - 5), textCollection[i], textStyle);
textSize = helper_1.measureText(texts, textStyle);
height += textSize.height;
maxNumber.push(textSize.width);
collection.push(texts);
}
customText = collection;
textSize.width = Math.max.apply(null, maxNumber);
textSize.height = height;
}
if (interSectAction === 'WrapByWord' || interSectAction === 'Wrap' || interSectAction === 'Trim') {
for (var j = 0; j < customText.length; j++) {
textSize = helper_1.measureText(customText[j], textStyle);
height += textSize.height;
if ((rect.height - padding) > height) {
tspanText.push(customText[j]);
}
}
if (interSectAction === 'Wrap' && customText.length !== tspanText.length && tspanText.length) {
var collectionLength = tspanText.length - 1;
var stringText = tspanText[collectionLength];
stringText = stringText.substring(0, (stringText.length - 1)) + '...';
tspanText.splice(collectionLength);
Eif (stringText !== '...') {
tspanText.push(stringText);
}
}
}
else {
textName = customText;
tspanText.push(textName);
}
var textOptions = new helper_1.TextOption(groupId + '_Text', textLocation.x, textLocation.y, 'start', tspanText, '', '', connectorText);
helper_2.renderTextElement(textOptions, textStyle, textStyle.color || this.getSaturatedColor(fill), parentElement);
};
LayoutPanel.prototype.getItemColor = function (isLeafItem, item) {
var treemap = this.treemap;
var itemFill = isLeafItem ? treemap.leafItemSettings.fill : treemap.levels[item['groupIndex']].fill;
var itemOpacity = isLeafItem ? treemap.leafItemSettings.opacity : treemap.levels[item['groupIndex']].opacity;
Iif (!ej2_base_1.isNullOrUndefined(treemap.treemapLevelData.defaultLevelsData)) {
if (treemap.treemapLevelData.defaultLevelsData.length > 0) {
treemap.treemapLevelData.levelsData = treemap.treemapLevelData.defaultLevelsData;
}
}
var parentData = helper_2.findChildren(treemap.treemapLevelData.levelsData[0])['values'];
var colorMapping = isLeafItem ? treemap.leafItemSettings.colorMapping :
treemap.levels[item['groupIndex']].colorMapping;
if (colorMapping.length > 0) {
var option = helper_1.colorMap(colorMapping, item['data'][treemap.equalColorValuePath], item['data'][treemap.rangeColorValuePath]);
Eif (!ej2_base_1.isNullOrUndefined(option)) {
itemFill = !ej2_base_1.isNullOrUndefined(option['fill']) ? option['fill'] : treemap.leafItemSettings.fill;
itemOpacity = option['opacity'];
}
}
else {
for (var i = 0; i < parentData.length; i++) {
if (parentData[i]['levelOrderName'] === item['levelOrderName'].split('#')[0]) {
itemFill = !ej2_base_1.isNullOrUndefined(itemFill) ? itemFill : !ej2_base_1.isNullOrUndefined(treemap.colorValuePath) ?
parentData[i]['data'][treemap.colorValuePath] : (!ej2_base_1.isNullOrUndefined(treemap.palette) && treemap.palette.length > 0) ?
treemap.palette[i % treemap.palette.length] : '#808080';
}
}
}
return { fill: itemFill, opacity: itemOpacity };
};
LayoutPanel.prototype.getSaturatedColor = function (color) {
var saturatedColor = color;
saturatedColor = (saturatedColor === 'transparent') ? window.getComputedStyle(document.body, null).backgroundColor : saturatedColor;
var rgbValue = helper_1.convertHexToColor(helper_1.colorNameToHex(saturatedColor));
var contrast = Math.round((rgbValue.r * 299 + rgbValue.g * 587 + rgbValue.b * 114) / 1000);
return contrast >= 128 ? 'black' : 'white';
};
LayoutPanel.prototype.renderTemplate = function (secondaryEle, groupId, rect, position, template, item, isLeafItem) {
var templateId = isLeafItem ? groupId + '_LabelTemplate' : groupId + '_HeaderTemplate';
var baseTemplateId = isLeafItem ? '_LabelTemplate' : '_HeaderTemplate';
Eif (ej2_base_1.isNullOrUndefined(template['prototype']) && typeof template === 'string') {
var keys = Object.keys(item['data']);
for (var i = 0; i < keys.length; i++) {
var regExp = RegExp;
template = template.replace(new regExp('{{:' + keys[i] + '}}', 'g'), item['data'][keys[i].toString()]);
}
}
var labelElement;
Eif (!ej2_base_1.isNullOrUndefined(document.getElementById(this.treemap.element.id + '_Secondary_Element'))) {
var templateFn = helper_1.getTemplateFunction(template);
var templateElement = templateFn(item['data'], this.treemap, template, this.treemap.element.id + baseTemplateId, false);
labelElement = helper_1.convertElement(templateElement, templateId, item['data']);
var templateSize = helper_1.measureElement(labelElement, secondaryEle);
var templateLocation = helper_1.findLabelLocation(rect, position, templateSize, 'Template', this.treemap);
labelElement.style.left = templateLocation.x + 'px';
labelElement.style.top = templateLocation.y + 'px';
}
return labelElement;
};
LayoutPanel.prototype.labelInterSectAction = function (rect, text, textStyle, alignment) {
var textValue;
var maxWidth = rect.width - 10;
switch (alignment) {
case 'Hide':
textValue = [helper_1.hide(maxWidth, rect.height, text, textStyle)];
break;
case 'Trim':
textValue = [helper_1.textTrim((maxWidth + 3), text, textStyle)];
break;
case 'WrapByWord':
textValue = helper_1.wordWrap(maxWidth, text, textStyle);
break;
case 'Wrap':
textValue = helper_1.textWrap(maxWidth, text, textStyle);
break;
}
return textValue;
};
LayoutPanel.prototype.destroy = function () {
this.treemap = null;
this.currentRect = null;
this.layoutGroup = null;
this.renderer = null;
this.renderItems = [];
this.parentData = [];
};
return LayoutPanel;
}());
exports.LayoutPanel = LayoutPanel;
});
|