all files / treemap/user-interaction/ highlight-selection.js

92.95% Statements 409/440
85.49% Branches 271/317
100% Functions 17/17
92.95% Lines 409/440
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   47× 47× 47× 47× 47× 47× 47×   46× 46× 46× 46× 46× 46× 46× 46× 46× 46× 46× 46× 46× 46× 46× 36× 36× 36×           46× 19× 18× 18× 18× 18× 18× 12× 12× 12×     12× 12× 11× 11× 10× 10× 10×       10×   10× 10× 10×                         18× 18× 18×   17× 827× 827× 827× 827× 827× 827× 99×     827×     31× 31×     17× 17× 31× 31× 31× 31×   17× 17×             27× 18× 11×   18×     18×   18× 18× 18× 18× 18× 18× 18× 18× 18×   18× 18× 18× 18× 374× 19074×     453× 453× 453× 453× 11× 11× 11× 11×   453× 453× 453× 280×       173×     453× 453× 453× 453×       18× 280×                                             46×   47×     47×   47× 11×   36×   1070×   47× 47× 47× 47× 47× 47×     29× 29× 29× 29× 29× 29×   20× 20× 20× 20× 20× 20× 20× 20× 20× 20× 20× 20× 20× 20× 20× 20×   20×                     249× 249× 249× 249× 249×                                         13× 11× 11× 11×         170× 8670×     212× 212× 212× 212× 212×   212× 212× 212×             212×   212×   212× 212× 212× 212× 212× 212×   212×   212×       120×                                                     23×     51× 51× 51×                                                                     29×     29×   29×   23×   1070×   29× 29× 29× 29× 29×        
define(["require", "exports", "@syncfusion/ej2-base", "../model/constants", "../utils/helper"], function (require, exports, ej2_base_1, constants_1, helper_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var TreeMapHighlight = (function () {
        function TreeMapHighlight(treeMap) {
            this.target = 'highlight';
            this.shapeTarget = 'highlight';
            this.shapeHighlightCollection = [];
            this.legendHighlightCollection = [];
            this.currentElement = [];
            this.treemap = treeMap;
            this.addEventListener();
        }
        TreeMapHighlight.prototype.mouseMove = function (e) {
            var treemap = this.treemap;
            var processHighlight;
            var targetId = e.target.id;
            var eventArgs;
            var items = [];
            var highlight = this.treemap.highlightSettings;
            var item;
            var highLightElements = [];
            var process;
            var treeMapElement;
            var element;
            var orders;
            var selectionModule = this.treemap.treeMapSelectionModule;
            var shapeSelected = false;
            if (selectionModule && selectionModule.legendSelectionCollection.length > 0) {
                for (var i = 0; i < selectionModule.legendSelectionCollection.length; i++) {
                    for (var j = 0; j < selectionModule.legendSelectionCollection[i]['ShapeCollection']['Elements'].length; j++) {
                        var selectedElementIndex = parseFloat(selectionModule.legendSelectionCollection[i]['ShapeCollection']['Elements'][j].id.split('Item_Index_')[1].split('_')[0]);
                        var targetElementIndex = targetId.indexOf('_Item_Index_') > -1 ? parseFloat(targetId.split('Item_Index_')[1].split('_')[0]) : null;
                        if (selectionModule.legendSelectionCollection[i]['ShapeCollection']['Elements'][j].id === targetId ||
                            selectedElementIndex === targetElementIndex) {
                            shapeSelected = true;
                            break;
                        }
                    }
                }
            }
            if (targetId.indexOf('_Item_Index') > -1 && !shapeSelected) {
                if (this.highLightId !== targetId) {
                    treeMapElement = document.getElementById(treemap.element.id + '_TreeMap_' + treemap.layoutType + '_Layout');
                    var selectionElements = document.getElementsByClassName('treeMapSelection');
                    item = this.treemap.layout.renderItems[parseFloat(targetId.split('_Item_Index_')[1])];
                    var index = void 0;
                    if (this.treemap.legendSettings.visible) {
                        var collection = this.treemap.treeMapLegendModule.legendCollections;
                        var length_1 = this.treemap.treeMapLegendModule.legendCollections.length;
                        index = (!treemap.legendSettings.removeDuplicateLegend && treemap.palette && treemap.palette.length > 0 &&
                            treemap.leafItemSettings.colorMapping.length === 0 && treemap.levels.length === 0) ?
                            parseFloat(targetId.split('_Item_Index_')[1]) : helper_1.getLegendIndex(length_1, item, treemap);
                        this.shapeElement = this.treemap.legendSettings.mode === 'Default' ? document.getElementById(this.treemap.element.id + '_Legend_Shape_Index_' + index) : document.getElementById(this.treemap.element.id + '_Legend_Index_' + index);
                        if (this.shapeElement !== null && (selectionModule ? this.shapeElement.getAttribute('id') !== selectionModule.legendSelectId : true)) {
                            var legendShapeElement = selectionModule ? selectionModule.shapeElement : null;
                            if (selectionModule ? this.shapeElement !== legendShapeElement : true) {
                                this.currentElement.push({ currentElement: this.shapeElement });
                                helper_1.removeLegend(this.shapeHighlightCollection, treemap);
                                this.shapeHighlightCollection.push({ legendEle: this.shapeElement, oldFill: collection[index]['legendFill'],
                                    oldOpacity: collection[index]['opacity'], oldBorderColor: collection[index]['borderColor'],
                                    oldBorderWidth: collection[index]['borderWidth']
                                });
                                var legendText = this.treemap.legendSettings.mode === 'Default' ? document.getElementById(this.treemap.element.id + '_Legend_Text_Index_' + index)
                                    : document.getElementById(this.treemap.element.id + '_Legend_Index_' + index + '_Text');
                                helper_1.setColor(legendText, highlight.fill, highlight.opacity, highlight.border.color, highlight.border.width.toString());
                                helper_1.setColor(this.shapeElement, highlight.fill, highlight.opacity, highlight.border.color, highlight.border.width.toString());
                                this.target = 'highlight';
                            }
                            else Iif (this.currentElement.length > 0 && this.currentElement[this.currentElement.length - 1]['currentElement'] !== this.shapeElement) {
                                helper_1.removeSelectionWithHighlight(this.shapeHighlightCollection, this.currentElement, treemap);
                                this.highLightId = '';
                            }
                        }
                        else Iif (this.currentElement.length > 0 && this.currentElement[this.currentElement.length - 1]['currentElement'] !== this.shapeElement) {
                            helper_1.removeSelectionWithHighlight(this.shapeHighlightCollection, this.currentElement, treemap);
                            this.highLightId = '';
                            if (this.treemap.legendSettings.mode === 'Interactive') {
                                this.treemap.treeMapLegendModule.removeInteractivePointer();
                            }
                        }
                    }
                    orders = helper_1.findHightLightItems(item, [], highlight.mode, treemap);
                    Eif (this.treemap.legendSettings.visible ? selectionModule ? this.shapeElement ? this.shapeElement.getAttribute('id') !== selectionModule.legendSelectId : true : true : true) {
                        if (this.treemap.legendSettings.visible ? selectionModule ?
                            this.shapeElement !== selectionModule.shapeElement : true : true) {
                            for (var i = 0; i < treeMapElement.childElementCount; i++) {
                                element = treeMapElement.childNodes[i];
                                process = true;
                                var valuePath = treemap.rangeColorValuePath;
                                var targetItem = treemap.layout.renderItems[parseFloat(targetId.split('_Item_Index_')[1])];
                                item = treemap.layout.renderItems[parseFloat(element.id.split('_Item_Index_')[1])];
                                for (var j = 0; j < selectionElements.length; j++) {
                                    if (element.id === selectionElements[j].id) {
                                        process = false;
                                        break;
                                    }
                                }
                                if (orders.indexOf(item['levelOrderName']) > -1 && process &&
                                    (!ej2_base_1.isNullOrUndefined(valuePath) && valuePath !== '' ?
                                        item['data'][valuePath] === targetItem['data'][valuePath] : true)) {
                                    highLightElements.push(element);
                                    items.push(item);
                                }
                            }
                            helper_1.removeClassNames(document.getElementsByClassName('treeMapHighLight'), 'treeMapHighLight', treemap);
                            for (var k = 0; k < highLightElements.length; k++) {
                                element = highLightElements[k];
                                helper_1.applyOptions(element.childNodes[0], { border: highlight.border, fill: highlight.fill, opacity: highlight.opacity });
                                element.classList.add('treeMapHighLight');
                                this.highLightId = targetId;
                            }
                            eventArgs = { cancel: false, name: constants_1.itemHighlight, treemap: treemap, items: items, elements: highLightElements };
                            treemap.trigger(constants_1.itemHighlight, eventArgs);
                        }
                        else {
                            processHighlight = false;
                        }
                    }
                }
            }
            else if (targetId.indexOf('_Legend_Shape') > -1 || targetId.indexOf('_Legend_Index') > -1 || targetId.indexOf('_Legend_Text_Index') > -1) {
                if (!ej2_base_1.isNullOrUndefined(selectionModule)) {
                    selectionModule.legendSelectId = !ej2_base_1.isNullOrUndefined(treemap.legendId[0]) ? treemap.legendId[0] : null;
                }
                var selectedLegendIndex = selectionModule && selectionModule.legendSelectId ?
                    parseFloat(selectionModule.legendSelectId.split('Index_')[1]) :
                    (selectionModule && selectionModule.shapeSelectId ? parseFloat(selectionModule.shapeSelectId.split('Index_')[1]) : null);
                var targetIndex = this.treemap.legendSettings.mode === 'Default' ? (targetId.indexOf('Text') === -1 ? parseFloat(targetId.split('_Legend_Shape_Index_')[1]) : parseFloat(targetId.split('_Legend_Text_Index_')[1]))
                    : parseFloat(targetId.split('_Legend_Index_')[1]);
                Eif (this.treemap.legendSettings.visible && targetIndex !== selectedLegendIndex) {
                    var itemIndex = void 0;
                    var groupIndex = void 0;
                    var length_2;
                    var valuePath = treemap.rangeColorValuePath;
                    var targetEle = document.getElementById(targetId);
                    Eif (this.shapeTarget === 'highlight') {
                        helper_1.removeLegend(this.legendHighlightCollection, this.treemap);
                        this.legendHighlightCollection = [];
                    }
                    this.shapeTarget = 'highlight';
                    var dataLength = this.treemap.treeMapLegendModule.legendCollections[targetIndex]['legendData'].length;
                    var collection = this.treemap.treeMapLegendModule.legendCollections;
                    for (var i = 0; i < dataLength; i++) {
                        for (var j = 0; j < this.treemap.layout.renderItems.length; j++) {
                            if ((!ej2_base_1.isNullOrUndefined(valuePath) && valuePath !== '' && treemap.leafItemSettings.colorMapping.length > 0)
                                ? treemap.treeMapLegendModule.legendCollections[targetIndex]['legendData'][i]['data'][valuePath] === treemap.layout.renderItems[j]['data'][valuePath]
                                : (treemap.treeMapLegendModule.legendCollections[targetIndex]['legendData'][i]['levelOrderName'] === treemap.layout.renderItems[j]['levelOrderName'])) {
                                itemIndex = j;
                                groupIndex = this.treemap.layout.renderItems[j]['groupIndex'];
                                var nodeEle = document.getElementById(this.treemap.element.id + '_Level_Index_' + groupIndex + '_Item_Index_' + itemIndex + '_RectPath');
                                if (i === 0 || this.legendHighlightCollection.length === 0) {
                                    this.legendHighlightCollection = [];
                                    helper_1.pushCollection(this.legendHighlightCollection, targetIndex, j, targetEle, nodeEle, this.treemap.layout.renderItems, collection);
                                    length_2 = this.legendHighlightCollection.length;
                                    this.legendHighlightCollection[length_2 - 1]['ShapeCollection'] = { Elements: [] };
                                }
                                helper_1.setColor(targetEle, highlight.fill, highlight.opacity, highlight.border.color, highlight.border.width.toString());
                                var legendItem = void 0;
                                if (targetEle.id.indexOf('Text') > -1) {
                                    legendItem = this.treemap.legendSettings.mode === 'Interactive' ? document.getElementById(targetEle.id.replace('_Text', ''))
                                        : document.getElementById(this.treemap.element.id + '_Legend_Shape_Index_' + targetIndex);
                                }
                                else {
                                    legendItem = this.treemap.legendSettings.mode === 'Interactive' ? document.getElementById(targetEle.id + '_Text')
                                        : document.getElementById(this.treemap.element.id + '_Legend_Text_Index_' + targetIndex);
                                }
                                helper_1.setColor(legendItem, highlight.fill, highlight.opacity, highlight.border.color, highlight.border.width.toString());
                                helper_1.setColor(nodeEle, highlight.fill, highlight.opacity, highlight.border.color, highlight.border.width.toString());
                                length_2 = this.legendHighlightCollection.length;
                                this.legendHighlightCollection[length_2 - 1]['ShapeCollection']['Elements'].push(nodeEle);
                            }
                        }
                    }
                    if (dataLength === 0 && this.treemap.palette && this.treemap.palette.length > 0) {
                        for (var j = 0; j < this.treemap.layout.renderItems.length; j++) {
                            if ((this.treemap.treeMapLegendModule.legendCollections[targetIndex]['levelOrderName'] === this.treemap.layout.renderItems[j]['levelOrderName'] ||
                                this.treemap.layout.renderItems[j]['levelOrderName'].indexOf(this.treemap.treeMapLegendModule.legendCollections[targetIndex]['levelOrderName']) > -1) &&
                                ((!this.treemap.legendSettings.removeDuplicateLegend && treemap.palette && treemap.palette.length > 0) ?
                                    targetIndex === j : true)) {
                                itemIndex = j;
                                groupIndex = this.treemap.layout.renderItems[j]['groupIndex'];
                                var nodeEle = document.getElementById(this.treemap.element.id + '_Level_Index_' + groupIndex + '_Item_Index_' + itemIndex + '_RectPath');
                                helper_1.pushCollection(this.legendHighlightCollection, targetIndex, j, targetEle, nodeEle, this.treemap.layout.renderItems, collection);
                                length_2 = this.legendHighlightCollection.length;
                                this.legendHighlightCollection[length_2 - 1]['ShapeCollection'] = { Elements: [] };
                                var legendItem = void 0;
                                if (targetEle.id.indexOf('Text') > -1) {
                                    legendItem = this.treemap.legendSettings.mode === 'Interactive' ? document.getElementById(targetEle.id.replace('_Text', ''))
                                        : document.getElementById(this.treemap.element.id + '_Legend_Shape_Index_' + targetIndex);
                                }
                                else {
                                    legendItem = this.treemap.legendSettings.mode === 'Interactive' ? document.getElementById(targetEle.id + '_Text')
                                        : document.getElementById(this.treemap.element.id + '_Legend_Text_Index_' + targetIndex);
                                }
                                helper_1.setColor(legendItem, highlight.fill, highlight.opacity, highlight.border.color, highlight.border.width.toString());
                                helper_1.setColor(targetEle, highlight.fill, highlight.opacity, highlight.border.color, highlight.border.width.toString());
                                helper_1.setColor(nodeEle, highlight.fill, highlight.opacity, highlight.border.color, highlight.border.width.toString());
                                length_2 = this.legendHighlightCollection.length;
                                this.legendHighlightCollection[length_2 - 1]['ShapeCollection']['Elements'].push(nodeEle);
                            }
                        }
                    }
                }
            }
            else {
                Eif (selectionModule ? this.shapeElement ? this.shapeElement.getAttribute('id') !== selectionModule.legendSelectId : true : true) {
                    if (selectionModule ? this.shapeElement !== selectionModule.shapeElement : true && this.treemap.legendSettings.visible) {
                        helper_1.removeClassNames(document.getElementsByClassName('treeMapHighLight'), 'treeMapHighLight', treemap);
                    }
                }
                if ((this.shapeTarget === 'highlight' || this.target === 'highlight') && this.treemap.legendSettings.visible) {
                    Eif (selectionModule ? this.shapeElement ? this.shapeElement.getAttribute('id') !== selectionModule.legendSelectId : true : true) {
                        if (selectionModule ? this.shapeElement !== selectionModule.shapeElement : true && selectionModule ?
                            selectionModule.legendSelect : true) {
                            helper_1.removeLegend(this.shapeHighlightCollection, treemap);
                            this.shapeHighlightCollection = [];
                        }
                    }
                }
                if (this.shapeTarget === 'highlight' && this.treemap.legendSettings.visible) {
                    helper_1.removeLegend(this.legendHighlightCollection, this.treemap);
                }
                this.highLightId = '';
                processHighlight = false;
            }
            return processHighlight;
        };
        TreeMapHighlight.prototype.addEventListener = function () {
            Iif (this.treemap.isDestroyed) {
                return;
            }
            this.treemap.on(ej2_base_1.Browser.touchMoveEvent, this.mouseMove, this);
        };
        TreeMapHighlight.prototype.removeEventListener = function () {
            if (this.treemap.isDestroyed) {
                return;
            }
            this.treemap.off(ej2_base_1.Browser.touchMoveEvent, this.mouseMove);
        };
        TreeMapHighlight.prototype.getModuleName = function () {
            return 'treeMapHighlight';
        };
        TreeMapHighlight.prototype.destroy = function () {
            this.shapeElement = null;
            this.shapeHighlightCollection = [];
            this.legendHighlightCollection = [];
            this.currentElement = [];
            this.removeEventListener();
            this.treemap = null;
        };
        return TreeMapHighlight;
    }());
    exports.TreeMapHighlight = TreeMapHighlight;
    var TreeMapSelection = (function () {
        function TreeMapSelection(treeMap) {
            this.shapeSelectionCollection = [];
            this.legendSelectionCollection = [];
            this.shapeSelect = true;
            this.legendSelect = true;
            this.treemap = treeMap;
            this.addEventListener();
        }
        TreeMapSelection.prototype.mouseDown = function (e) {
            var targetEle = e.target;
            var eventArgs;
            var treemap = this.treemap;
            var items = [];
            var targetId = targetEle.id;
            var labelText = targetEle.innerHTML;
            var item;
            var selectionElements = [];
            var treeMapElement;
            var element;
            var orders;
            var selection = treemap.selectionSettings;
            var highlightModule = this.treemap.treeMapHighlightModule;
            var layoutID = treemap.element.id + '_TreeMap_' + treemap.layoutType + '_Layout';
            item = treemap.layout.renderItems[parseFloat(targetId.split('_Item_Index_')[1])];
            var isDrillItem = (item && !item.isLeafItem && treemap.enableDrillDown) &&
                (targetEle.nextSibling.textContent.indexOf('[+]') > -1 || targetEle.nextSibling.textContent.indexOf('[-]') > -1);
            if (targetId.indexOf('_Item_Index') > -1 && !isDrillItem) {
                e.preventDefault();
                if (this.treemap.selectionId !== targetId) {
                    treemap.levelSelection = [];
                    treemap.legendId = [];
                    this.shapeSelectId = '';
                    helper_1.removeLegend(this.legendSelectionCollection, treemap);
                    this.legendSelectionCollection = [];
                    treeMapElement = document.getElementById(layoutID);
                    var index = void 0;
                    if (this.treemap.legendSettings.visible) {
                        this.shapeSelect = false;
                        var length_3 = this.treemap.treeMapLegendModule.legendCollections.length;
                        var collection = this.treemap.treeMapLegendModule.legendCollections;
                        this.shapeElement = undefined;
                        helper_1.removeLegend(this.shapeSelectionCollection, treemap);
                        if (highlightModule) {
                            highlightModule.shapeTarget = 'selection';
                            highlightModule.shapeHighlightCollection = [];
                        }
                        index = (!treemap.legendSettings.removeDuplicateLegend && treemap.palette && treemap.palette.length > 0 &&
                            treemap.leafItemSettings.colorMapping.length === 0
                            && treemap.levels.length === 0) ?
                            parseFloat(targetId.split('_Item_Index_')[1]) : helper_1.getLegendIndex(length_3, item, treemap);
                        this.shapeElement = this.treemap.legendSettings.mode === 'Default' ? document.getElementById(this.treemap.element.id + '_Legend_Shape_Index_' + index) : document.getElementById(this.treemap.element.id + '_Legend_Index_' + index);
                        Eif (this.shapeElement !== null) {
                            this.shapeSelectId = this.shapeElement.getAttribute('id');
                            this.shapeSelectionCollection.push({ legendEle: this.shapeElement, oldFill: collection[index]['legendFill'],
                                oldOpacity: collection[index]['opacity'], oldBorderColor: collection[index]['borderColor'],
                                oldBorderWidth: collection[index]['borderWidth']
                            });
                            var legendText = this.treemap.legendSettings.mode === 'Default' ? document.getElementById(this.treemap.element.id + '_Legend_Text_Index_' + index)
                                : document.getElementById(this.treemap.element.id + '_Legend_Index_' + index + '_Text');
                            helper_1.setColor(legendText, selection.fill, selection.opacity, selection.border.color, selection.border.width.toString());
                            helper_1.setColor(this.shapeElement, selection.fill, selection.opacity, selection.border.color, selection.border.width.toString());
                            treemap.legendId.push(this.shapeElement.id);
                            treemap.legendId.push(legendText.id);
                        }
                    }
                    orders = helper_1.findHightLightItems(item, [], selection.mode, treemap);
                    for (var i = 0; i < treeMapElement.childElementCount; i++) {
                        element = treeMapElement.childNodes[i];
                        var targetItem = treemap.layout.renderItems[parseFloat(targetId.split('_Item_Index_')[1])];
                        item = treemap.layout.renderItems[parseFloat(element.id.split('_Item_Index_')[1])];
                        var valuePath = treemap.rangeColorValuePath;
                        if (orders.indexOf(item['levelOrderName']) > -1 &&
                            (!ej2_base_1.isNullOrUndefined(valuePath) && valuePath !== '' ?
                                item['data'][valuePath] === targetItem['data'][valuePath] : true)) {
                            selectionElements.push(element);
                            if (targetId.indexOf('_RectPath') > -1) {
                                treemap.levelSelection.push(targetId);
                            }
                            items.push(item);
                        }
                    }
                    helper_1.removeClassNames(document.getElementsByClassName('treeMapSelection'), 'treeMapSelection', treemap);
                    this.treemap.selectionId = targetId;
                    var highLightElements = document.getElementsByClassName('treeMapHighLight');
                    for (var k = 0; k < selectionElements.length; k++) {
                        element = selectionElements[k];
                        if (highLightElements.length > 0) {
                            for (var j = 0; j < highLightElements.length; j++) {
                                Eif (highLightElements[j].id === element.id) {
                                    highLightElements[j].classList.remove('treeMapHighLight');
                                }
                                helper_1.applyOptions(element.childNodes[0], { border: selection.border, fill: selection.fill, opacity: selection.opacity });
                                element.classList.add('treeMapSelection');
                            }
                        }
                        else {
                            helper_1.applyOptions(element.childNodes[0], { border: selection.border, fill: selection.fill, opacity: selection.opacity });
                            element.classList.add('treeMapSelection');
                        }
                        eventArgs = { cancel: false, name: constants_1.itemSelected, treemap: treemap, items: items, elements: selectionElements,
                            text: labelText, contentItemTemplate: labelText };
                        treemap.trigger(constants_1.itemSelected, eventArgs, function (observedArgs) {
                            Iif (observedArgs.contentItemTemplate !== labelText) {
                                helper_1.setItemTemplateContent(targetId, targetEle, observedArgs.contentItemTemplate);
                            }
                        });
                    }
                }
                else {
                    helper_1.removeLegend(this.shapeSelectionCollection, treemap);
                    this.treemap.legendId = [];
                    this.shapeSelectionCollection = [];
                    this.shapeElement = undefined;
                    this.shapeSelect = true;
                    this.shapeSelectId = '';
                    this.treemap.levelSelection = [];
                    Eif (this.legendSelect) {
                        helper_1.removeClassNames(document.getElementsByClassName('treeMapSelection'), 'treeMapSelection', treemap);
                        this.treemap.selectionId = '';
                    }
                }
            }
            else if (targetId.indexOf('_Legend_Shape') > -1 || targetId.indexOf('_Legend_Index') > -1 || targetId.indexOf('_Legend_Text_') > -1) {
                var collection = this.treemap.treeMapLegendModule.legendCollections;
                var legendSelectIdIndex = !ej2_base_1.isNullOrUndefined(this.legendSelectId) ? parseFloat(this.legendSelectId.split('_Index_')[1]) : null;
                if (this.treemap.legendSettings.visible && (legendSelectIdIndex !== parseFloat(targetId.split('_Index_')[1]))) {
                    var itemIndex = void 0;
                    var groupIndex = void 0;
                    var length_4;
                    treemap.legendId = [];
                    treemap.levelSelection = [];
                    this.legendSelectId = targetId;
                    this.legendSelect = false;
                    var legendIndex = !isNaN(parseInt(targetId[targetId.length - 1], 10)) ?
                        parseInt(targetId[targetId.length - 1], 10) :
                        parseInt(targetId[targetId.length - 6], 10);
                    var targetEle_1 = document.getElementById(targetId);
                    helper_1.removeLegend(this.legendSelectionCollection, treemap);
                    helper_1.removeClassNames(document.getElementsByClassName('treeMapSelection'), 'treeMapSelection', treemap);
                    helper_1.removeLegend(this.shapeSelectionCollection, treemap);
                    this.legendSelectionCollection = [];
                    if (highlightModule) {
                        highlightModule.shapeTarget = 'selection';
                        highlightModule.legendHighlightCollection = [];
                    }
                    var valuePath = treemap.rangeColorValuePath;
                    var index = this.treemap.legendSettings.mode === 'Default' ? (targetId.indexOf('Text') === -1 ? parseFloat(targetId.split('_Legend_Shape_Index_')[1]) : parseFloat(targetId.split('_Legend_Text_Index_')[1]))
                        : parseFloat(targetId.split('_Legend_Index_')[1]);
                    var dataLength = this.treemap.treeMapLegendModule.legendCollections[index]['legendData'].length;
                    for (var k = 0; k < dataLength; k++) {
                        for (var l = 0; l < this.treemap.layout.renderItems.length; l++) {
                            if ((!ej2_base_1.isNullOrUndefined(valuePath) && valuePath !== '' && treemap.leafItemSettings.colorMapping.length > 0) ?
                                (treemap.treeMapLegendModule.legendCollections[index]['legendData'][k]['data'][valuePath] === treemap.layout.renderItems[l]['data'][valuePath])
                                : (this.treemap.treeMapLegendModule.legendCollections[index]['legendData'][k]['levelOrderName'] === this.treemap.layout.renderItems[l]['levelOrderName'])) {
                                itemIndex = l;
                                groupIndex = this.treemap.layout.renderItems[l]['groupIndex'];
                                var nodeEle = document.getElementById(this.treemap.element.id + '_Level_Index_' + groupIndex + '_Item_Index_' + itemIndex + '_RectPath');
                                this.treemap.selectionId = nodeEle.id;
                                if (k === 0 || this.legendSelectionCollection.length === 0) {
                                    helper_1.pushCollection(this.legendSelectionCollection, legendIndex, l, targetEle_1, nodeEle, this.treemap.layout.renderItems, collection);
                                    length_4 = this.legendSelectionCollection.length;
                                    this.legendSelectionCollection[length_4 - 1]['ShapeCollection'] = { Elements: [] };
                                }
                                this.treemap.selectionId = nodeEle.id;
                                var legendItem = void 0;
                                Iif (targetEle_1.id.indexOf('Text') > -1) {
                                    legendItem = this.treemap.legendSettings.mode === 'Interactive' ? document.getElementById(targetEle_1.id.replace('_Text', ''))
                                        : document.getElementById(this.treemap.element.id + '_Legend_Shape_Index_' + index);
                                    this.legendSelectId = legendItem.id;
                                    this.shapeElement = legendItem;
                                }
                                else {
                                    legendItem = this.treemap.legendSettings.mode === 'Interactive' ? document.getElementById(targetEle_1.id + '_Text')
                                        : document.getElementById(this.treemap.element.id + '_Legend_Text_Index_' + index);
                                    this.shapeElement = targetEle_1;
                                }
                                helper_1.setColor(legendItem, selection.fill, selection.opacity, selection.border.color, selection.border.width.toString());
                                helper_1.setColor(targetEle_1, selection.fill, selection.opacity, selection.border.color, selection.border.width.toString());
                                helper_1.setColor(nodeEle, selection.fill, selection.opacity, selection.border.color, selection.border.width.toString());
                                length_4 = this.legendSelectionCollection.length;
                                treemap.levelSelection.push(nodeEle.id);
                                if (treemap.legendId.indexOf(targetEle_1.id) === -1) {
                                    treemap.legendId.push(targetEle_1.id);
                                }
                                if (treemap.legendId.indexOf(legendItem.id) === -1) {
                                    treemap.legendId.push(legendItem.id);
                                }
                                this.legendSelectionCollection[length_4 - 1]['ShapeCollection']['Elements'].push(nodeEle);
                            }
                        }
                    }
                    if (dataLength === 0 && this.treemap.palette && this.treemap.palette.length > 0) {
                        for (var j = 0; j < this.treemap.layout.renderItems.length; j++) {
                            if ((this.treemap.treeMapLegendModule.legendCollections[index]['levelOrderName'] === this.treemap.layout.renderItems[j]['levelOrderName'] ||
                                this.treemap.layout.renderItems[j]['levelOrderName'].indexOf(this.treemap.treeMapLegendModule.legendCollections[index]['levelOrderName']) > -1) &&
                                ((!this.treemap.legendSettings.removeDuplicateLegend && treemap.palette && treemap.palette.length > 0) ?
                                    index === j : true)) {
                                itemIndex = j;
                                groupIndex = this.treemap.layout.renderItems[j]['groupIndex'];
                                var nodeEle = document.getElementById(this.treemap.element.id + '_Level_Index_' + groupIndex + '_Item_Index_' + itemIndex + '_RectPath');
                                helper_1.pushCollection(this.legendSelectionCollection, index, j, targetEle_1, nodeEle, this.treemap.layout.renderItems, collection);
                                this.treemap.selectionId = nodeEle.id;
                                length_4 = this.legendSelectionCollection.length;
                                this.legendSelectionCollection[length_4 - 1]['ShapeCollection'] = { Elements: [] };
                                var legendItem = void 0;
                                if (targetEle_1.id.indexOf('Text') > -1) {
                                    legendItem = this.treemap.legendSettings.mode === 'Interactive' ? document.getElementById(targetEle_1.id.replace('_Text', ''))
                                        : document.getElementById(this.treemap.element.id + '_Legend_Shape_Index_' + index);
                                    this.legendSelectId = legendItem.id;
                                    this.shapeElement = legendItem;
                                }
                                else {
                                    legendItem = this.treemap.legendSettings.mode === 'Interactive' ? document.getElementById(targetEle_1.id + '_Text')
                                        : document.getElementById(this.treemap.element.id + '_Legend_Text_Index_' + index);
                                    this.legendSelectId = targetId;
                                    this.shapeElement = targetEle_1;
                                }
                                helper_1.setColor(legendItem, selection.fill, selection.opacity, selection.border.color, selection.border.width.toString());
                                helper_1.setColor(targetEle_1, selection.fill, selection.opacity, selection.border.color, selection.border.width.toString());
                                helper_1.setColor(nodeEle, selection.fill, selection.opacity, selection.border.color, selection.border.width.toString());
                                treemap.levelSelection.push(nodeEle.id);
                                Eif (treemap.legendId.indexOf(legendItem.id) === -1) {
                                    treemap.legendId.push(legendItem.id);
                                }
                                Eif (treemap.legendId.indexOf(targetEle_1.id) === -1) {
                                    treemap.legendId.push(targetEle_1.id);
                                }
                                length_4 = this.legendSelectionCollection.length;
                                this.legendSelectionCollection[length_4 - 1]['ShapeCollection']['Elements'].push(nodeEle);
                            }
                        }
                    }
                }
                else {
                    helper_1.removeLegend(this.legendSelectionCollection, this.treemap);
                    this.legendSelectionCollection = [];
                    if (highlightModule) {
                        highlightModule.shapeTarget = 'highlight';
                    }
                    this.legendSelect = true;
                    this.legendSelectId = '';
                    this.treemap.legendId = [];
                    this.treemap.levelSelection = [];
                }
            }
            else Iif (isDrillItem) {
                helper_1.removeLegend(this.legendSelectionCollection, this.treemap);
                this.legendSelectionCollection = [];
                this.legendSelect = true;
                this.legendSelectId = '';
                this.treemap.legendId = [];
                this.treemap.levelSelection = [];
            }
        };
        TreeMapSelection.prototype.selectTreemapItem = function (levelOrder, enable) {
            Eif (enable) {
                var item = void 0;
                for (var s = 0; s < this.treemap.layout.renderItems.length; s++) {
                    if (levelOrder === this.treemap.layout.renderItems[s]['levelOrderName']) {
                        item = this.treemap.layout.renderItems[s];
                        break;
                    }
                }
                var selection = this.treemap.selectionSettings;
                var selectionElements = [];
                var element = void 0;
                var index = void 0;
                var items = [];
                this.treemap.levelSelection = [];
                var layoutID = this.treemap.element.id + '_TreeMap_' + this.treemap.layoutType + '_Layout';
                var treeMapElement = document.getElementById(layoutID);
                var orders = helper_1.findHightLightItems(item, [], selection.mode, this.treemap);
                for (var i = 0; i < treeMapElement.childElementCount; i++) {
                    element = treeMapElement.childNodes[i];
                    item = this.treemap.layout.renderItems[parseFloat(element.id.split('_Item_Index_')[1])];
                    if (orders.indexOf(item['levelOrderName']) > -1) {
                        selectionElements.push(element);
                        this.treemap.levelSelection.push(element.id);
                        items.push(item);
                    }
                }
                Eif (this.treemap.legendSettings.visible) {
                    for (var m = 0; m < items.length; m++) {
                        this.shapeSelect = false;
                        var length_5 = this.treemap.treeMapLegendModule.legendCollections.length;
                        var collection = this.treemap.treeMapLegendModule.legendCollections;
                        this.shapeElement = undefined;
                        helper_1.removeShape(this.shapeSelectionCollection);
                        index = helper_1.getLegendIndex(length_5, items[m], this.treemap);
                        this.shapeElement = this.treemap.legendSettings.mode === 'Default' ? document.getElementById(this.treemap.element.id + '_Legend_Shape_Index_' + index) : document.getElementById(this.treemap.element.id + '_Legend_Index_' + index);
                        Eif (this.shapeElement !== null) {
                            this.shapeSelectId = this.shapeElement.getAttribute('id');
                            this.treemap.legendId.push(this.shapeSelectId);
                            this.shapeSelectionCollection.push({
                                legendEle: this.shapeElement, oldFill: collection[index]['legendFill'],
                                oldOpacity: collection[index]['opacity'], oldBorderColor: collection[index]['borderColor'],
                                oldBorderWidth: collection[index]['borderWidth']
                            });
                            helper_1.setColor(this.shapeElement, selection.fill, selection.opacity, selection.border.color, selection.border.width.toString());
                        }
                    }
                }
                helper_1.removeClassNames(document.getElementsByClassName('treeMapSelection'), 'treeMapSelection', this.treemap);
                var selectionElement = document.getElementById(this.treemap.levelSelection[0]);
                this.treemap.selectionId = selectionElement.childNodes[0]['id'];
                var highLightElements = document.getElementsByClassName('treeMapHighLight');
                for (var k = 0; k < selectionElements.length; k++) {
                    element = selectionElements[k];
                    Iif (highLightElements.length > 0) {
                        for (var j = 0; j < highLightElements.length; j++) {
                            if (highLightElements[j].id === element.id) {
                                highLightElements[j].classList.remove('treeMapHighLight');
                            }
                            helper_1.applyOptions(element.childNodes[0], { border: selection.border, fill: selection.fill, opacity: selection.opacity });
                            element.classList.add('treeMapSelection');
                        }
                    }
                    else {
                        selection.fill = selection.fill === 'null' ?
                            this.treemap.layout.renderItems[parseInt(element.id.split('Item_Index_')[1], 10)]['options']['fill']
                            : selection.fill;
                        helper_1.applyOptions(element.childNodes[0], { border: selection.border, fill: selection.fill, opacity: selection.opacity });
                        element.classList.add('treeMapSelection');
                    }
                }
            }
            else {
                helper_1.removeShape(this.shapeSelectionCollection);
                this.shapeElement = undefined;
                this.treemap.levelSelection = [];
                this.shapeSelect = true;
                this.shapeSelectId = '';
                this.treemap.legendId = [];
                helper_1.removeClassNames(document.getElementsByClassName('treeMapSelection'), 'treeMapSelection', this.treemap);
                this.treemap.selectionId = '';
            }
        };
        TreeMapSelection.prototype.addEventListener = function () {
            Iif (this.treemap.isDestroyed) {
                return;
            }
            this.treemap.on(ej2_base_1.Browser.touchStartEvent, this.mouseDown, this);
        };
        TreeMapSelection.prototype.removeEventListener = function () {
            if (this.treemap.isDestroyed) {
                return;
            }
            this.treemap.off(ej2_base_1.Browser.touchStartEvent, this.mouseDown);
        };
        TreeMapSelection.prototype.getModuleName = function () {
            return 'treeMapSelection';
        };
        TreeMapSelection.prototype.destroy = function () {
            this.shapeElement = null;
            this.shapeSelectionCollection = [];
            this.legendSelectionCollection = [];
            this.removeEventListener();
            this.treemap = null;
        };
        return TreeMapSelection;
    }());
    exports.TreeMapSelection = TreeMapSelection;
});