all files / chart3d/user-interaction/ selection.js

93.75% Statements 495/528
85.43% Branches 393/460
96.23% Functions 51/53
94.07% Lines 492/523
11 statements, 6 functions, 9 branches Ignored     
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 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785          226× 226× 226× 226× 226×   226×     226× 226× 226× 226× 226× 226×             105×   100× 100× 100× 100× 100×   113× 113× 113× 113×   113× 113× 113× 113× 113×   6103× 6103×       134× 22× 22×     177× 177× 177× 1044×   177×   31× 31× 91× 91× 91× 91× 91× 546×       31×   11×           127× 92× 92×   35× 35× 35× 35×   127× 23×     126×   150× 150×   66× 66× 66×       66× 66×     66× 66×   66×   84×         150×     126×   107× 107×     142×     142×   32×   110× 24×         110× 110× 110× 110×     132× 132×   45× 45× 45× 45×   58× 57× 57× 57×   58×   29× 29× 29× 29×   29×     131× 131× 131× 131× 131× 131× 131× 29× 85× 85× 85× 86× 86× 86× 86× 86× 86× 86×   84×     86×                 102× 45× 26× 38× 38× 38×             19×   19× 17×           57× 57× 57× 14×     43×   57× 79× 79× 79× 79× 79× 79× 79× 79× 23×   56×     79×             131×         131×   145×   44×   145× 145× 143×         143× 143× 143× 24×     119× 119× 95×   119× 119×   143× 35×     108×       29×   44× 44× 21× 21×       11× 11× 11×       168×   168× 435× 435× 435× 435× 424× 424× 18060×   424× 424×         168× 168× 435× 435×     438× 438× 438× 438× 95×   438× 438× 438× 438× 438× 18672× 18672× 18672× 4146×     18672×   11166×     7506× 7506×     7506× 7506×     438× 413× 413× 410× 188× 188× 185× 185× 185×       410× 137× 137×   273× 273× 273×   410× 137× 137× 137× 14× 14× 14×         273× 273× 32× 32× 32×     273× 78×     195× 195×               119× 2532× 2532× 2532× 2532× 2532× 180× 180× 180× 180× 180× 180×   180× 180× 132× 132×       2532× 2532× 168× 168×   2532× 240×         5365×   1313× 2240× 2240× 2240× 2240× 588× 588× 212×   588× 188×   588×         211× 92× 32× 32×     211× 119×     126×     21× 21× 18×     14×     21× 21× 21×     20×   21× 21×   19× 14×   14×     14× 14×   14×     11×         16× 16× 16× 16× 16× 16× 16× 16×     14× 42× 42× 24× 24× 24×     14× 14×       14×   14× 14× 14× 14× 14× 14×         26× 86×                         89× 89× 87× 87× 3756×     89×   6264× 6264× 6243×   21×   20×   19× 18× 18×   6264×   21× 21× 21× 35× 35× 28× 28× 28× 1248× 1248×                   41× 41× 41× 41× 41× 30×   11×       41× 41× 41×   41×     35× 35×       35×     20× 20× 20× 20× 141× 141× 141× 141× 55× 55× 18×   55× 18×   55×   55×       20× 20× 486× 486× 486× 486× 228×                                 4177×   105×        
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../../common/utils/helper", "../../common/model/base", "../../common/model/constants", "../../common/user-interaction/selection"], function (require, exports, ej2_base_1, ej2_base_2, helper_1, base_1, constants_1, selection_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Selection3D = (function (_super) {
        __extends(Selection3D, _super);
        function Selection3D(chart) {
            var _this = _super.call(this, chart) || this;
            _this.seriesIndex = 0;
            _this.chart = chart;
            _this.addEventListener();
            return _this;
        }
        Selection3D.prototype.addEventListener = function () {
            Iif (this.chart.isDestroyed) {
                return;
            }
            var cancelEvent = ej2_base_1.Browser.isPointer ? 'pointerleave' : 'mouseleave';
            this.chart.on(ej2_base_1.Browser.touchMoveEvent, this.mouseMove, this);
            this.chart.on(cancelEvent, this.mouseLeave, this);
            this.chart.on('click', this.mouseClick, this);
            this.chart.on(ej2_base_1.Browser.touchStartEvent, this.mousedown, this);
            this.chart.on(ej2_base_1.Browser.touchEndEvent, this.mouseLeave, this);
        };
        Selection3D.prototype.mousedown = function () {
            var chart = this.chart;
            if (chart.isPointMouseDown || chart.selectionMode === 'Point') {
                return;
            }
        };
        Selection3D.prototype.removeEventListener = function () {
            if (this.chart.isDestroyed) {
                return;
            }
            this.chart.off(ej2_base_1.Browser.touchMoveEvent, this.mouseMove);
            this.chart.off('pointerleave' || 'mouseleave', this.mouseLeave);
            this.chart.off('click', this.mouseClick);
            this.chart.off(ej2_base_1.Browser.touchStartEvent, this.mousedown);
            this.chart.off(ej2_base_1.Browser.touchEndEvent, this.mouseLeave);
        };
        Selection3D.prototype.initPrivateVariables = function (chart) {
            this.styleId = chart.element.id + '_ej2_chart_selection';
            this.unselected = chart.element.id + '_ej2_deselected';
            this.selectedDataIndexes = [];
            this.isSeriesMode = chart.selectionMode === 'Series';
        };
        Selection3D.prototype.invokeSelection = function (chart) {
            this.initPrivateVariables(chart);
            this.series = ej2_base_2.extend({}, chart.visibleSeries, null, true);
            this.seriesStyles();
            this.currentMode = chart.selectionMode;
            this.selectDataIndex(chart, this.concatIndexes(chart.selectedDataIndexes, this.selectedDataIndexes));
        };
        Selection3D.prototype.generateStyle = function (series) {
            Eif (series) {
                return (this.styleId + '_series_' + series.index);
            }
            return 'undefined';
        };
        Selection3D.prototype.selectDataIndex = function (chart, indexes) {
            for (var _i = 0, indexes_1 = indexes; _i < indexes_1.length; _i++) {
                var index = indexes_1[_i];
                this.performSelection(index, chart, this.getElementByIndex(chart, index)[0]);
            }
        };
        Selection3D.prototype.getElementByIndex = function (chart, index) {
            var pointElements = [];
            var elements = document.querySelectorAll('[id*="-region-series-' + index.series + '-point-' + index.point + '"]');
            elements.forEach(function (pointElement) {
                pointElements.push(pointElement);
            });
            return pointElements;
        };
        Selection3D.prototype.getClusterElements = function (chart, index) {
            var clusters = [];
            for (var _i = 0, _a = chart.visibleSeries; _i < _a.length; _i++) {
                var series = _a[_i];
                Eif (series.visible) {
                    index = new base_1.Index(series.index, index.point);
                    var pointElements = this.getElementByIndex(chart, index);
                    for (var i = 0; i < pointElements.length; i++) {
                        clusters.push(pointElements[i]);
                    }
                }
            }
            return clusters;
        };
        Selection3D.prototype.findElements = function (chart, series, index) {
            if (this.isSeriesMode) {
                return this.getSeriesElements(series);
            }
            else if (this.currentMode === 'Cluster') {
                return this.getClusterElements(chart, index);
            }
            else {
                return this.getElementByIndex(chart, index);
            }
        };
        Selection3D.prototype.isAlreadySelected = function (targetElem, eventType, index) {
            if (eventType === 'click') {
                this.currentMode = this.chart.selectionMode;
                this.styleId = this.chart.element.id + '_ej2_chart_selection';
            }
            else Eif (eventType === 'mousemove' || eventType === 'pointermove') {
                this.currentMode = this.chart.highlightMode;
                this.highlightDataIndexes = [];
                this.styleId = this.chart.element.id + '_ej2_chart_highlight';
            }
            if (this.chart.highlightMode !== 'None' && this.chart.selectionMode === 'None') {
                if (eventType === 'click') {
                    return false;
                }
            }
            if (((this.chart.highlightMode !== 'None' || this.chart.legendSettings.enableHighlight) && this.previousSelectedEle && this.previousSelectedEle[0])) {
                var isElement = void 0;
                var nodeName = targetElem.nodeName;
                Eif (targetElem.parentNode) {
                    isElement = ((nodeName === 'path' || nodeName === 'shape') && targetElem.id.indexOf('region') > 1) ? true : false;
                }
                var _loop_1 = function (i) {
                    Eif (this_1.previousSelectedEle[i].hasAttribute('class')) {
                        if (this_1.previousSelectedEle[i].getAttribute('class').indexOf('highlight') > -1 &&
                            (isElement || eventType === 'click')) {
                            var selectionClass_1;
                            this_1.previousSelectedEle[i].classList.forEach(function (className) {
                                Iif (className.indexOf('selection') > -1) {
                                    selectionClass_1 = className;
                                }
                            });
                            this_1.previousSelectedEle[i].removeAttribute('class');
                            Iif (selectionClass_1) {
                                this_1.addSvgClass(this_1.previousSelectedEle[i], selectionClass_1);
                            }
                            this_1.previousSelectedEle[i].classList.remove(this_1.styleId + '_series_' + index.series);
                            if (this_1.chart.highlightColor !== '' && !ej2_base_2.isNullOrUndefined(this_1.chart.highlightColor) && this_1.chart.highlightPattern === 'None') {
                                this_1.previousSelectedEle[i].setAttribute('fill', this_1.control.visibleSeries[this_1.indexFinder(this_1.previousSelectedEle[i].id).series].interior);
                            }
                            this_1.addOrRemoveIndex(this_1.highlightDataIndexes, this_1.indexFinder(this_1.previousSelectedEle[i].id));
                        }
                        else Iif (!isElement && this_1.previousSelectedEle[i].getAttribute('class').indexOf('highlight') > -1) {
                            this_1.performSelection(this_1.indexFinder(this_1.previousSelectedEle[i].id), this_1.chart, this_1.previousSelectedEle[i]);
                        }
                    }
                };
                var this_1 = this;
                for (var i = 0; i < this.previousSelectedEle.length; i++) {
                    _loop_1(i);
                }
            }
            return true;
        };
        Selection3D.prototype.mouseClick = function (event) {
            Eif (!this.chart.rotateActivate) {
                this.calculateSelectedElements(event.target, event.type);
            }
        };
        Selection3D.prototype.calculateSelectedElements = function (targetElement, eventType) {
            Iif (ej2_base_2.isNullOrUndefined(targetElement)) {
                return;
            }
            if ((this.chart.selectionMode === 'None' && this.chart.highlightMode === 'None') ||
                targetElement.id && targetElement.id.indexOf(this.chart.element.id + '-') === -1) {
                return;
            }
            if (eventType === 'mousemove' || eventType === 'pointermove') {
                Iif (targetElement.hasAttribute('class') && (targetElement.getAttribute('class').indexOf('highlight') > -1 ||
                    targetElement.getAttribute('class').indexOf('selection') > -1)) {
                    return;
                }
            }
            this.isAlreadySelected(targetElement, eventType, this.indexFinder(targetElement.id));
            Eif (targetElement.id && targetElement.id.indexOf('-series-') > -1 && targetElement.id.indexOf('_Text_') === -1) {
                var element = void 0;
                this.performSelection(this.indexFinder(targetElement.id), this.chart, element || targetElement);
            }
        };
        Selection3D.prototype.performSelection = function (index, chart, element) {
            this.isSeriesMode = this.currentMode === 'Series';
            switch (this.currentMode) {
                case 'Series':
                    this.selection(chart, index, this.getSeriesElements(chart.series[index.series]));
                    this.selectionComplete(chart, index, this.currentMode);
                    this.blurEffect(chart.element.id, chart.visibleSeries);
                    break;
                case 'Point':
                    if (!isNaN(index.point) && element) {
                        this.selection(chart, index, this.getElementByIndex(chart, index));
                        this.selectionComplete(chart, index, this.currentMode);
                        this.blurEffect(chart.element.id, chart.visibleSeries);
                    }
                    break;
                case 'Cluster':
                    Eif (!isNaN(index.point)) {
                        this.clusterSelection(chart, index);
                        this.selectionComplete(chart, index, this.currentMode);
                        this.blurEffect(chart.element.id, chart.visibleSeries);
                    }
                    break;
            }
        };
        Selection3D.prototype.selectionComplete = function (chart, index, selectionMode) {
            var points;
            var pointIndex;
            var seriesIndex;
            var selectedPointValues = [];
            var yValue;
            var selectedPointX;
            if (selectionMode === 'Cluster') {
                for (var _i = 0, _a = chart.visibleSeries; _i < _a.length; _i++) {
                    var series = _a[_i];
                    Eif (series.visible) {
                        for (var i = 0; i < this.selectedDataIndexes.length; i++) {
                            pointIndex = chart.isMultiSelect ? this.selectedDataIndexes[i].point : index.point;
                            seriesIndex = series.index;
                            points = series.points;
                            Eif (!isNaN(pointIndex)) {
                                yValue = points[pointIndex].yValue;
                                selectedPointX = points[pointIndex].xValue;
                                if (chart.primaryXAxis.valueType === 'Category') {
                                    selectedPointX = points[pointIndex].x.toLocaleString();
                                }
                                else Iif (chart.primaryXAxis.valueType === 'DateTime') {
                                    selectedPointX = new Date(points[pointIndex].xValue);
                                }
                                selectedPointValues.push({
                                    x: selectedPointX, y: yValue, seriesIndex: seriesIndex,
                                    pointIndex: pointIndex
                                });
                            }
                        }
                    }
                }
            }
            else if (selectionMode === 'Series') {
                if (chart.isMultiSelect) {
                    for (var i = 0; i < this.selectedDataIndexes.length; i++) {
                        seriesIndex = this.selectedDataIndexes[i].series;
                        Eif (this.selectedDataIndexes.length > 0) {
                            selectedPointValues.push({
                                seriesIndex: seriesIndex
                            });
                        }
                    }
                }
                else {
                    seriesIndex = (this.selectedDataIndexes.length > 0) ? this.selectedDataIndexes[0].series :
                        (this.highlightDataIndexes && this.highlightDataIndexes.length > 0) ? this.highlightDataIndexes[0].series : 0;
                    if (this.selectedDataIndexes.length > 0 || (this.highlightDataIndexes && this.highlightDataIndexes.length > 0)) {
                        selectedPointValues.push({
                            seriesIndex: seriesIndex
                        });
                    }
                }
            }
            else Eif (selectionMode === 'Point') {
                var selectedData = [];
                if (this.styleId.indexOf('highlight') > -1) {
                    selectedData = this.highlightDataIndexes;
                }
                else {
                    selectedData = this.selectedDataIndexes;
                }
                for (var i = 0; i < selectedData.length; i++) {
                    pointIndex = selectedData[i].point;
                    seriesIndex = selectedData[i].series;
                    var series = chart.series[seriesIndex];
                    points = series.points;
                    Eif (!isNaN(pointIndex)) {
                        selectedPointX = points[pointIndex].xValue;
                        yValue = points[pointIndex].yValue;
                        if (chart.primaryXAxis.valueType === 'Category') {
                            selectedPointX = points[pointIndex].x.toLocaleString();
                        }
                        else Iif (chart.primaryXAxis.valueType === 'DateTime') {
                            selectedPointX = new Date(points[pointIndex].xValue);
                        }
                        selectedPointValues.push({
                            x: selectedPointX, y: yValue, seriesIndex: seriesIndex,
                            pointIndex: pointIndex
                        });
                    }
                }
            }
            var args = {
                selectedDataValues: selectedPointValues,
                cancel: false,
                chart: chart
            };
            chart.trigger(constants_1.selectionComplete, args);
        };
        Selection3D.prototype.selection = function (chart, index, selectedElements) {
            if (!chart.isMultiSelect && (this.styleId.indexOf('highlight') === -1 &&
                chart.selectionMode !== 'None')) {
                this.removeMultiSelectElements(chart, this.selectedDataIndexes, index, chart.series);
            }
            var indexValue = index.series;
            if (!ej2_base_2.isNullOrUndefined(selectedElements[0])) {
                if (chart.visibleSeries[indexValue].isRectSeries) {
                    Eif (selectedElements[0].id) {
                        Iif (document.getElementById(selectedElements[0].id + '_Symbol')) {
                            selectedElements.push(helper_1.getElement(selectedElements[0].id + '_Symbol'));
                        }
                    }
                }
                var isAdd = void 0;
                var className = selectedElements[0] && (selectedElements[0].getAttribute('class') || '');
                if (selectedElements[0] && className.indexOf(this.getSelectionClass(selectedElements[0].id)) > -1) {
                    this.removeStyles(selectedElements);
                }
                else {
                    this.previousSelectedEle = (chart.highlightMode !== 'None' || chart.legendSettings.enableHighlight) ? selectedElements : [];
                    if (this.chart.selection3DModule) {
                        this.chart.selection3DModule.previousSelectedEle = selectedElements;
                    }
                    this.applyStyles(selectedElements);
                    isAdd = true;
                }
                if (this.styleId.indexOf('highlight') > 0 && (chart.highlightMode !== 'None' || chart.legendSettings.enableHighlight)) {
                    this.addOrRemoveIndex(this.highlightDataIndexes, index, isAdd);
                }
                else {
                    this.addOrRemoveIndex(this.selectedDataIndexes, index, isAdd);
                }
            }
        };
        Selection3D.prototype.clusterSelection = function (chart, index) {
            this.selection(chart, index, this.getClusterElements(chart, new base_1.Index(index.series, index.point)));
        };
        Selection3D.prototype.removeMultiSelectElements = function (chart, index, currentIndex, seriesCollection) {
            var series;
            for (var i = 0; i < index.length; i++) {
                series = seriesCollection[index[i].series];
                if ((this.isSeriesMode && !this.toEquals(index[i], currentIndex, this.isSeriesMode)) ||
                    (this.currentMode === 'Cluster' && !this.toEquals(index[i], currentIndex, false)) ||
                    (!this.isSeriesMode && this.toEquals(index[i], currentIndex, true) &&
                        !this.toEquals(index[i], currentIndex, false))) {
                    this.removeStyles(this.findElements(chart, series, index[i]));
                    index.splice(i, 1);
                    i--;
                }
            }
        };
        Selection3D.prototype.blurEffect = function (chartId, visibleSeries) {
            var visibility = (this.checkVisibility(this.highlightDataIndexes, this.chart) ||
                this.checkVisibility(this.selectedDataIndexes, this.chart));
            var _loop_2 = function (series) {
                var legendIndex = series.index;
                var legendStrokeColor = this_2.chart.visibleSeries[series.index].interior;
                var pointElements = [];
                if (series.visible) {
                    var elements = document.querySelectorAll("[id*=\"region-series-" + series.index + "\"]");
                    elements.forEach(function (el) {
                        pointElements.push(el);
                    });
                    this_2.checkSelectionElements(pointElements, this_2.generateStyle(series), visibility, legendIndex, legendStrokeColor);
                    Iif (!ej2_base_2.isNullOrUndefined(helper_1.getElement(chartId + 'SymbolGroup' + series.index))) {
                        this_2.checkSelectionElements(pointElements, this_2.generateStyle(series), visibility, legendIndex, legendStrokeColor);
                    }
                }
            };
            var this_2 = this;
            for (var _i = 0, visibleSeries_1 = visibleSeries; _i < visibleSeries_1.length; _i++) {
                var series = visibleSeries_1[_i];
                _loop_2(series);
            }
        };
        Selection3D.prototype.checkSelectionElements = function (element, className, visibility, series, legendStrokeColor) {
            Iif (series === void 0) { series = 0; }
            Iif (legendStrokeColor === void 0) { legendStrokeColor = '#D3D3D3'; }
            var children = (this.isSeriesMode ? element || [element] : element);
            if (this.chart.selectionMode !== 'None' && (this.chart.highlightMode !== 'None' || this.chart.legendSettings.enableHighlight)) {
                children = element;
            }
            var elementClassName;
            var parentClassName;
            var legendShape;
            var selectElement = element;
            for (var i = 0; i < children.length; i++) {
                elementClassName = children[i].getAttribute('class') || '';
                parentClassName = children[i].parentNode.getAttribute('class') || '';
                if (this.chart.selectionMode !== 'None' && (this.chart.highlightMode !== 'None' || this.chart.legendSettings.enableHighlight)) {
                    className = elementClassName.indexOf('selection') > 0 ||
                        elementClassName.indexOf('highlight') > 0 ? elementClassName : className;
                }
                if (elementClassName.indexOf(className) === -1 &&
                    parentClassName.indexOf(className) === -1 && visibility) {
                    this.addSvgClass(children[i], this.unselected);
                }
                else {
                    selectElement = children[i];
                    Iif (elementClassName.indexOf(this.unselected) !== -1 && this.chart.tooltip3DModule && className.indexOf('highlight') > 0) {
                        this.chart.highlightAnimation(children[i], series, 700, 0.3);
                    }
                    this.removeSvgClass(children[i], this.unselected);
                    this.removeSvgClass(children[i].parentNode, this.unselected);
                }
            }
            if (this.control.legend3DModule && this.control.legendSettings.visible) {
                legendShape = helper_1.getElement(this.control.element.id + '_chart_legend_shape_' + series);
                if (legendShape) {
                    if (legendShape.hasAttribute('class')) {
                        this.removeSvgClass(legendShape, legendShape.getAttribute('class'));
                        if (!ej2_base_2.isNullOrUndefined(this.chart.highlightColor && this.chart.highlightColor !== '') && !this.chart.legendSettings.enableHighlight) {
                            legendShape.setAttribute('stroke', legendStrokeColor);
                            Eif (this.chart.highlightPattern === 'None') {
                                legendShape.setAttribute('fill', legendStrokeColor);
                            }
                        }
                    }
                    if (selectElement.length > 0) {
                        elementClassName = selectElement[0].getAttribute('class');
                        parentClassName = selectElement[0].parentNode.getAttribute('class') || '';
                    }
                    else Eif (selectElement) {
                        elementClassName = selectElement.getAttribute('class') || '';
                        parentClassName = selectElement.parentNode.getAttribute('class') || '';
                    }
                    if (elementClassName.indexOf(className) === -1 && parentClassName.indexOf(className) === -1 && visibility) {
                        this.addSvgClass(legendShape, (this.chart.highlightMode === 'None' && this.chart.legendSettings.enableHighlight) ? className : this.unselected);
                        this.removeSvgClass(legendShape, className);
                        if (this.chart.highlightColor !== '' && !ej2_base_2.isNullOrUndefined(this.chart.highlightColor)) {
                            legendShape.setAttribute('stroke', this.control.visibleSeries[series].interior);
                            Eif (this.chart.highlightPattern === 'None') {
                                legendShape.setAttribute('fill', this.control.visibleSeries[series].interior);
                            }
                        }
                    }
                    else {
                        this.removeSvgClass(legendShape, this.unselected);
                        if (!ej2_base_2.isNullOrUndefined(this.chart.highlightColor) && this.chart.highlightColor !== '') {
                            legendShape.setAttribute('stroke', this.control.visibleSeries[series].interior);
                            Eif (this.chart.highlightPattern === 'None') {
                                legendShape.setAttribute('fill', this.control.visibleSeries[series].interior);
                            }
                        }
                        if ((elementClassName === '' && parentClassName === '') || elementClassName.trim() === 'EJ2-Trackball') {
                            this.removeSvgClass(legendShape, className);
                        }
                        else {
                            this.addSvgClass(legendShape, className);
                            if (className.indexOf('highlight') > 0 && this.chart.highlightColor !== '' && this.chart.highlightColor !== 'transparent' && !ej2_base_2.isNullOrUndefined(this.chart.highlightColor)) {
                                legendShape.setAttribute('stroke', this.chart.highlightColor);
                                Eif (this.styleId.indexOf('highlight') > 0 && this.chart.highlightPattern === 'None') {
                                    legendShape.setAttribute('fill', this.chart.highlightColor);
                                }
                            }
                        }
                    }
                }
            }
        };
        Selection3D.prototype.applyStyles = function (elements) {
            for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
                var element = elements_1[_i];
                Eif (element) {
                    this.removeSvgClass(element.parentNode, this.unselected);
                    this.removeSvgClass(element, this.unselected);
                    if (this.chart.series[0].pointColorMapping === 'fill') {
                        var className = this.getSelectionClass(element.id);
                        var index = className.indexOf('highlight') > -1 ? parseInt(className.split(this.chart.element.id + '_ej2_chart_highlight_series_')[1], 10) : parseInt(className.split(this.chart.element.id + '_ej2_chart_selection_series_')[1], 10);
                        var patternName = this.styleId.indexOf('highlight') > 0 ? this.chart.highlightPattern : this.chart.selectionPattern;
                        var pattern = void 0;
                        Eif (className.indexOf('highlight') > -1 || className.indexOf('selection') > -1) {
                            pattern = document.getElementById(this.chart.element.id + '_' + patternName + '_' + 'Selection' + '_' + index);
                        }
                        Eif (element.id.indexOf('legend') === -1 && element.id.indexOf('Group') === -1 && pattern != null) {
                            for (var i = 1; i < pattern.children.length; i++) {
                                pattern.children[i].setAttribute('fill', element.getAttribute('fill'));
                                pattern.children[i].setAttribute('stroke', element.getAttribute('fill'));
                            }
                        }
                    }
                    this.addSvgClass(element, this.getSelectionClass(element.id));
                    if (this.chart.tooltip3DModule && this.getSelectionClass(element.id).indexOf('highlight') > 0) {
                        var index = parseFloat(element.id.split('-series-')[1].split('-point-')[0]);
                        this.chart.stopElementAnimation(element, index);
                    }
                    if (this.styleId.indexOf('highlight') > 0 && this.chart.highlightColor !== '' && !ej2_base_2.isNullOrUndefined(this.chart.highlightColor) && this.chart.highlightPattern === 'None' && this.chart.highlightColor !== 'transparent') {
                        element.setAttribute('fill', this.chart.highlightColor);
                    }
                }
            }
        };
        Selection3D.prototype.getSelectionClass = function (id) {
            return this.generateStyle(this.control.visibleSeries[this.indexFinder(id).series]);
        };
        Selection3D.prototype.removeStyles = function (elements) {
            for (var _i = 0, elements_2 = elements; _i < elements_2.length; _i++) {
                var element = elements_2[_i];
                Eif (element) {
                    this.removeSvgClass(element, this.getSelectionClass(element.id));
                    if (this.chart.highlightPattern === 'None' && this.chart.highlightColor !== '' && !ej2_base_2.isNullOrUndefined(this.chart.highlightColor) && this.chart.highlightColor !== 'transparent') {
                        var color = this.control.visibleSeries[this.indexFinder(element.id).series].interior;
                        if (element.getAttribute('name') === 'ZLight') {
                            color = this.chart.polygon.applyZLight(color, this.control);
                        }
                        if (element.getAttribute('name') === 'XLight') {
                            color = this.chart.polygon.applyXLight(color, this.control);
                        }
                        element.setAttribute('fill', color);
                    }
                }
            }
        };
        Selection3D.prototype.addOrRemoveIndex = function (indexes, index, isAdd) {
            for (var i = 0; i < indexes.length; i++) {
                if (this.toEquals(indexes[i], index, this.isSeriesMode)) {
                    indexes.splice(i, 1);
                    i--;
                }
            }
            if (isAdd) {
                indexes.push(index);
            }
        };
        Selection3D.prototype.toEquals = function (first, second, checkSeriesOnly) {
            return ((first.series === second.series || (this.currentMode === 'Cluster' && !checkSeriesOnly))
                && (checkSeriesOnly || (first.point === second.point)));
        };
        Selection3D.prototype.redrawSelection = function (chart, oldMode, chartRedraw) {
            this.isSeriesMode = oldMode === 'Series';
            if (!ej2_base_2.isNullOrUndefined(oldMode)) {
                if (chartRedraw) {
                    chart.isRedrawSelection = false;
                }
                else {
                    chart.isRedrawSelection = true;
                }
            }
            var selectedDataIndexes = ej2_base_2.extend([], this.selectedDataIndexes, null, true);
            var highlightDataIndexes = ej2_base_2.extend([], this.highlightDataIndexes, null, true);
            if (this.styleId.indexOf('highlight') > 0 && highlightDataIndexes.length > 0) {
                this.removeSelectedElements(chart, this.highlightDataIndexes, chart.series);
                selectedDataIndexes = highlightDataIndexes;
            }
            else {
                this.removeSelectedElements(chart, this.selectedDataIndexes, chart.series);
            }
            this.blurEffect(chart.element.id, chart.visibleSeries);
            this.selectDataIndex(chart, selectedDataIndexes);
        };
        Selection3D.prototype.legendSelection = function (chart, series, targetElement, eventType) {
            if (eventType === 'mousemove') {
                if (targetElement.id.indexOf('text') > 1) {
                    targetElement = helper_1.getElement(targetElement.id.replace('text', 'shape'));
                }
                Iif (targetElement.id.indexOf('marker') > 1) {
                    targetElement = helper_1.getElement(targetElement.id.replace('_marker', ''));
                }
                Eif (targetElement.id.indexOf('g') > 1) {
                    targetElement = helper_1.getElement(targetElement.id.replace('_g_', '_shape_'));
                }
                if (targetElement.hasAttribute('class') && (targetElement.getAttribute('class').indexOf('highlight') > -1 ||
                    targetElement.getAttribute('class').indexOf('selection') > -1)) {
                    return;
                }
                this.currentMode = this.chart.highlightMode;
            }
            else Eif (eventType === 'click') {
                if (targetElement.id.indexOf('text') > 1) {
                    targetElement = helper_1.getElement(targetElement.id.replace('text', 'shape'));
                }
                Eif (targetElement.id.indexOf('g') > 1) {
                    targetElement = helper_1.getElement(targetElement.id.replace('_g_', '_shape_'));
                }
            }
            var index = this.indexFinder(targetElement.id);
            var isPreSelected = this.isAlreadySelected(targetElement, eventType, index);
            Eif (isPreSelected) {
                var seriesStyle = this.generateStyle(chart.visibleSeries[series]);
                var selectedElements = (document.querySelectorAll('.' + seriesStyle));
                this.isSeriesMode = this.currentMode === 'Series';
                var isBlurEffectNeeded = true;
                if (selectedElements.length > 0) {
                    this.removeSelection(chart, series, selectedElements, seriesStyle, isBlurEffectNeeded);
                }
                else {
                    for (var _i = 0, _a = chart.visibleSeries; _i < _a.length; _i++) {
                        var element = _a[_i];
                        if (element.index !== series && !chart.isMultiSelect) {
                            seriesStyle = this.generateStyle(chart.visibleSeries[element.index]);
                            selectedElements = document.querySelectorAll('.' + seriesStyle);
                            this.removeSelection(chart, series, selectedElements, seriesStyle, isBlurEffectNeeded);
                        }
                    }
                    var seriesElements = [];
                    Iif (this.chart.legendSettings.mode === 'Point') {
                        seriesElements = this.getElementByIndex(chart, index);
                    }
                    else {
                        seriesElements = this.getSeriesElements(chart.visibleSeries[series]);
                    }
                    Eif (seriesElements.length > 0) {
                        this.checkSelectionElements(seriesElements, seriesStyle, false, series, '');
                        this.isSeriesMode = true;
                        this.selection(chart, new base_1.Index(index.series, NaN), seriesElements);
                        this.isSeriesMode = chart.selectionMode === 'Series';
                        this.blurEffect(chart.element.id, chart.visibleSeries);
                    }
                }
            }
        };
        Selection3D.prototype.removeSelection = function (chart, series, selectedElements, seriesStyle, isBlurEffectNeeded) {
            if (selectedElements.length > 0) {
                var elements = [];
                for (var i = 0; i < selectedElements.length; i++) {
                    elements.push(selectedElements[i]);
                }
                this.removeStyles(elements);
                this.isSeriesMode = true;
                this.addOrRemoveIndex(this.selectedDataIndexes, new base_1.Index(series, NaN));
                for (var _i = 0, _a = chart.visibleSeries; _i < _a.length; _i++) {
                    var value = _a[_i];
                    seriesStyle = this.generateStyle(value);
                    Iif (document.querySelectorAll('.' + seriesStyle).length > 0) {
                        for (var _b = 0, elements_3 = elements; _b < elements_3.length; _b++) {
                            var element = elements_3[_b];
                            this.checkSelectionElements(element, seriesStyle, true, series, '');
                        }
                        isBlurEffectNeeded = false;
                        break;
                    }
                }
                Eif (isBlurEffectNeeded) {
                    this.isSeriesMode = chart.selectionMode === 'Series';
                    this.blurEffect(chart.element.id, chart.visibleSeries);
                }
            }
        };
        Selection3D.prototype.getSeriesElements = function (series) {
            var seriesElements = [];
            if (series.visible) {
                var elements = document.querySelectorAll("[id*=\"region-series-" + series.index + "\"]");
                elements.forEach(function (seriesElement) {
                    seriesElements.push(seriesElement);
                });
            }
            return seriesElements;
        };
        Selection3D.prototype.indexFinder = function (id) {
            var ids = ['NaN', 'NaN'];
            if (id.indexOf('-point-') > -1) {
                ids = id.split('-series-')[1].split('-point-');
            }
            else if (id.indexOf('-border-') > -1) {
                ids[0] = id.split('-border-')[1];
            }
            else if (id.indexOf('-series-') > -1) {
                ids[0] = id.split('-series-')[1];
            }
            else if (id.indexOf('_chart_legend_shape_') > -1) {
                ids = id.split('_chart_legend_shape_');
                ids[0] = ids[1];
            }
            return new base_1.Index(parseInt(ids[0], 10), parseInt(ids[1], 10));
        };
        Selection3D.prototype.removeSelectedElements = function (chart, index, seriesCollection) {
            index = chart.isRedrawSelection ? index : index.splice(0, index.length);
            var seriesElements;
            for (var _i = 0, seriesCollection_1 = seriesCollection; _i < seriesCollection_1.length; _i++) {
                var series = seriesCollection_1[_i];
                if (series.visible) {
                    seriesElements = this.getSeriesElements(series);
                    this.removeStyles(seriesElements);
                    for (var _a = 0, seriesElements_1 = seriesElements; _a < seriesElements_1.length; _a++) {
                        var seriesElement = seriesElements_1[_a];
                        this.removeStyles(this.getChildren(seriesElement));
                    }
                }
            }
        };
        Selection3D.prototype.mouseLeave = function () {
            this.completeSelection();
        };
        Selection3D.prototype.completeSelection = function () {
            var chart = this.chart;
            Eif (chart.selectionMode === 'None') {
                return;
            }
            this.currentMode = chart.selectionMode;
        };
        Selection3D.prototype.mouseMove = function (event) {
            var chart = this.chart;
            var target = event.target;
            var eventType = event.type;
            this.highlightChart(target, eventType);
            if (chart.selectionMode === 'None') {
                return;
            }
            Iif (eventType === 'touchmove' && (ej2_base_1.Browser.isIos || ej2_base_1.Browser.isIos7) && event.preventDefault) {
                event.preventDefault();
            }
        };
        Selection3D.prototype.highlightChart = function (target, eventType) {
            Eif (!this.chart.rotateActivate && (this.chart.highlightMode !== 'None' || this.chart.legendSettings.enableHighlight)) {
                Eif (!ej2_base_2.isNullOrUndefined(target)) {
                    if (target.id.indexOf('_legend_text') > 1) {
                        target = helper_1.getElement(target.id.replace('text', 'shape'));
                    }
                    if ((target).hasAttribute('class') && ((target).getAttribute('class').indexOf('highlight') > -1 ||
                        target.getAttribute('class').indexOf('selection') > -1)) {
                        return;
                    }
                    this.calculateSelectedElements(target, eventType);
                    if (this.chart.highlight3DModule.highlightDataIndexes && this.chart.highlight3DModule.highlightDataIndexes.length > 0 &&
                        target.id.indexOf('_chart_legend_') === -1 && target.id.indexOf('-series-') === -1) {
                        this.removeLegendHighlightStyles();
                    }
                }
                return;
            }
        };
        Selection3D.prototype.removeLegendHighlightStyles = function () {
            this.chart.highlight3DModule.highlightDataIndexes = [];
            var elementCollection;
            for (var i = 0; i < this.chart.visibleSeries.length; i++) {
                elementCollection = document.getElementsByClassName(this.generateStyle(this.chart.visibleSeries[i]));
                Eif (this.selectedDataIndexes.length === 0) {
                    elementCollection = document.getElementsByClassName(this.generateStyle(this.chart.visibleSeries[i]));
                    while (elementCollection.length > 0) {
                        var element = elementCollection[0];
                        Eif (element) {
                            this.removeSvgClass(element, element.getAttribute('class'));
                            if (this.chart.highlightPattern === 'None' && this.chart.highlightColor !== '' && !ej2_base_2.isNullOrUndefined(this.chart.highlightColor) && this.chart.highlightColor !== 'transparent') {
                                var color = this.control.visibleSeries[i].interior;
                                if (element.getAttribute('name') === 'ZLight') {
                                    color = this.chart.polygon.applyZLight(color, this.control);
                                }
                                if (element.getAttribute('name') === 'XLight') {
                                    color = this.chart.polygon.applyXLight(color, this.control);
                                }
                                if (element.id.indexOf('_chart_legend_shape') !== -1 && element.getAttribute('stroke')) {
                                    element.setAttribute('stroke', color);
                                }
                                element.setAttribute('fill', color);
                            }
                        }
                    }
                    elementCollection = document.getElementsByClassName(this.unselected);
                    while (elementCollection.length > 0) {
                        var element = elementCollection[0];
                        Eif (element) {
                            this.removeSvgClass(element, element.getAttribute('class'));
                            if (this.chart.tooltip3DModule && this.generateStyle(this.chart.visibleSeries[i]).indexOf('highlight') > -1) {
                                this.chart.highlightAnimation(element, i, 700, 0.3);
                            }
                        }
                    }
                }
                else {
                    elementCollection = document.getElementsByClassName(this.generateStyle(this.chart.visibleSeries[i]));
                    while (elementCollection.length > 0) {
                        var element = elementCollection[0];
                        if (element) {
                            this.removeSvgClass(element, element.getAttribute('class'));
                            this.addSvgClass(element, this.unselected);
                        }
                    }
                }
            }
        };
        Selection3D.prototype.getModuleName = function () {
            return 'Selection3D';
        };
        Selection3D.prototype.destroy = function () {
            this.removeEventListener();
        };
        return Selection3D;
    }(selection_1.BaseSelection));
    exports.Selection3D = Selection3D;
});