all files / accumulation-chart/user-interaction/ selection.js

99.36% Statements 155/156
93.83% Branches 76/81
100% Functions 31/31
99.35% Lines 152/153
9 statements, 5 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        39× 39× 39×   47× 47× 47× 47×   47× 47× 47× 47×   352×   10×   40× 40×   69×     69× 59×     79×     79×   79× 79× 79×   79×     83× 29×   83× 83× 23× 23×     60× 60×             53× 53× 21× 21× 21× 20×       29× 29× 18× 18× 10× 10× 10×       89× 89× 89× 89× 89×       89× 89× 89× 89× 89× 736× 736× 736× 489×     247×   736× 550× 550× 550× 328×     222×           60× 60× 60× 60× 60× 46× 46× 46×   60× 60× 60×       259×   42× 42× 42× 42× 41× 29× 29×   41×       83× 149× 30× 30×     83× 60×     167×   89× 89× 80× 80× 79× 79×     89×   1157×          
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var 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 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", "../../common/utils/helper", "../model/acc-base", "../../common/model/base", "../../common/user-interaction/selection"], function (require, exports, ej2_base_1, helper_1, acc_base_1, base_1, selection_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var AccumulationSelection = (function (_super) {
        __extends(AccumulationSelection, _super);
        function AccumulationSelection(accumulation) {
            var _this = _super.call(this, accumulation) || this;
            _this.renderer = accumulation.renderer;
            return _this;
        }
        AccumulationSelection.prototype.initPrivateVariables = function (accumulation) {
            this.styleId = accumulation.element.id + '_ej2_chart_selection';
            this.unselected = accumulation.element.id + '_ej2_deselected';
            this.selectedDataIndexes = [];
            this.rectPoints = null;
        };
        AccumulationSelection.prototype.invokeSelection = function (accumulation) {
            this.initPrivateVariables(accumulation);
            this.series = ej2_base_1.extend({}, accumulation.visibleSeries, null, true);
            this.seriesStyles();
            this.selectDataIndex(this.concatIndexes(accumulation.selectedDataIndexes, this.selectedDataIndexes), accumulation);
        };
        AccumulationSelection.prototype.generateStyle = function (series) {
            return (series.selectionStyle || this.styleId + '_series_' + series.index);
        };
        AccumulationSelection.prototype.findElements = function (accumulation, series, index) {
            return [this.getElementByIndex(index)];
        };
        AccumulationSelection.prototype.getElementByIndex = function (index) {
            var elementId = this.control.element.id + '_Series_' + index.series + '_Point_' + index.point;
            return document.getElementById(elementId);
        };
        AccumulationSelection.prototype.calculateSelectedElements = function (accumulation, event) {
            Iif (event.target.id.indexOf(accumulation.element.id + '_') === -1) {
                return;
            }
            if (event.target.id.indexOf('_Series_') > -1 || event.target.id.indexOf('_datalabel_') > -1) {
                this.performSelection(helper_1.indexFinder(event.target.id), accumulation, event.target);
            }
        };
        AccumulationSelection.prototype.performSelection = function (index, accumulation, element) {
            element = element.id.indexOf('datalabel') > -1 ?
                accumulation.getSeriesElement().childNodes[index.series].childNodes[index.point]
                : element;
            switch (accumulation.selectionMode) {
                case 'Point':
                    Eif (!isNaN(index.point)) {
                        this.selection(accumulation, index, [element]);
                        this.blurEffect(accumulation.element.id, accumulation.visibleSeries);
                    }
                    break;
            }
        };
        AccumulationSelection.prototype.selection = function (accumulation, index, selectedElements) {
            if (!accumulation.isMultiSelect) {
                this.removeMultiSelectEelments(accumulation, this.selectedDataIndexes, index, accumulation.series);
            }
            var className = selectedElements[0] && (selectedElements[0].getAttribute('class') || '');
            if (selectedElements[0] && className.indexOf(this.getSelectionClass(selectedElements[0].id)) > -1) {
                this.removeStyles(selectedElements, index);
                this.addOrRemoveIndex(this.selectedDataIndexes, index);
            }
            else {
                this.applyStyles(selectedElements, index);
                this.addOrRemoveIndex(this.selectedDataIndexes, index, true);
            }
        };
        AccumulationSelection.prototype.redrawSelection = function (accumulation, oldMode) {
            var selectedDataIndexes = ej2_base_1.extend([], this.selectedDataIndexes, null, true);
            this.removeSelectedElements(accumulation, this.selectedDataIndexes);
            this.blurEffect(accumulation.element.id, accumulation.visibleSeries);
            this.selectDataIndex(selectedDataIndexes, accumulation);
        };
        AccumulationSelection.prototype.removeSelectedElements = function (accumulation, indexes) {
            var seriesgroup = accumulation.getSeriesElement();
            for (var _i = 0, indexes_1 = indexes; _i < indexes_1.length; _i++) {
                var index = indexes_1[_i];
                this.removeStyles([this.getElementByIndex(index)], index);
            }
        };
        AccumulationSelection.prototype.legendSelection = function (accumulation, series, pointIndex) {
            var element = accumulation.getSeriesElement().childNodes[series].childNodes[pointIndex];
            var seriesStyle = this.generateStyle(accumulation.visibleSeries[series]);
            var seriesElements = accumulation.getSeriesElement().childNodes[series].childNodes[pointIndex];
            this.selection(accumulation, new base_1.Index(series, pointIndex), [seriesElements]);
            this.blurEffect(accumulation.element.id, accumulation.visibleSeries);
        };
        AccumulationSelection.prototype.selectDataIndex = function (indexes, accumulation) {
            var element;
            for (var _i = 0, indexes_2 = indexes; _i < indexes_2.length; _i++) {
                var index = indexes_2[_i];
                element = this.getElementByIndex(index);
                if (element) {
                    this.performSelection(index, accumulation, element);
                }
            }
        };
        AccumulationSelection.prototype.removeMultiSelectEelments = function (accumulation, index, currentIndex, seriesCollection) {
            var series;
            for (var i = 0; i < index.length; i++) {
                series = seriesCollection[index[i].series];
                if (!this.checkEquals(index[i], currentIndex)) {
                    this.removeStyles(this.findElements(accumulation, series, index[i]), index[i]);
                    index.splice(i, 1);
                    i--;
                }
            }
        };
        AccumulationSelection.prototype.blurEffect = function (pieId, visibleSeries) {
            var visibility = this.checkPointVisibility(this.selectedDataIndexes);
            for (var _i = 0, visibleSeries_1 = visibleSeries; _i < visibleSeries_1.length; _i++) {
                var series = visibleSeries_1[_i];
                Eif (series.visible) {
                    this.checkSelectionElements(document.getElementById(pieId + '_SeriesCollection'), this.generateStyle(series), visibility);
                }
            }
        };
        AccumulationSelection.prototype.checkSelectionElements = function (element, className, visibility) {
            var children = (element.childNodes[0].childNodes);
            var legendShape;
            var elementClass;
            var parentClass;
            for (var i = 0; i < children.length; i++) {
                elementClass = children[i].getAttribute('class') || '';
                parentClass = children[i].parentNode.getAttribute('class') || '';
                if (elementClass.indexOf(className) === -1 && parentClass.indexOf(className) === -1 && visibility) {
                    this.addSvgClass(children[i], this.unselected);
                }
                else {
                    this.removeSvgClass(children[i], this.unselected);
                }
                if (this.control.accumulationLegendModule && this.control.legendSettings.visible) {
                    legendShape = document.getElementById(this.control.element.id + '_chart_legend_shape_' + i);
                    Eif (legendShape) {
                        if (elementClass.indexOf(className) === -1 && parentClass.indexOf(className) === -1 && visibility) {
                            this.addSvgClass(legendShape, this.unselected);
                        }
                        else {
                            this.removeSvgClass(legendShape, this.unselected);
                        }
                    }
                }
            }
        };
        AccumulationSelection.prototype.applyStyles = function (elements, index) {
            for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
                var element = elements_1[_i];
                var legendShape = void 0;
                Eif (element) {
                    if (this.control.accumulationLegendModule && this.control.legendSettings.visible) {
                        legendShape = document.getElementById(this.control.element.id + '_chart_legend_shape_' + index.point);
                        this.removeSvgClass(legendShape, this.unselected);
                        this.addSvgClass(legendShape, this.getSelectionClass(legendShape.id));
                    }
                    this.removeSvgClass(element.parentNode, this.unselected);
                    this.removeSvgClass(element, this.unselected);
                    this.addSvgClass(element, this.getSelectionClass(element.id));
                }
            }
        };
        AccumulationSelection.prototype.getSelectionClass = function (id) {
            return this.generateStyle(this.control.series[helper_1.indexFinder(id).series]);
        };
        AccumulationSelection.prototype.removeStyles = function (elements, index) {
            var legendShape;
            for (var _i = 0, elements_2 = elements; _i < elements_2.length; _i++) {
                var element = elements_2[_i];
                if (element) {
                    if (this.control.accumulationLegendModule && this.control.legendSettings.visible) {
                        legendShape = document.getElementById(this.control.element.id + '_chart_legend_shape_' + index.point);
                        this.removeSvgClass(legendShape, this.getSelectionClass(legendShape.id));
                    }
                    this.removeSvgClass(element, this.getSelectionClass(element.id));
                }
            }
        };
        AccumulationSelection.prototype.addOrRemoveIndex = function (indexes, index, add) {
            for (var i = 0; i < indexes.length; i++) {
                if (this.checkEquals(indexes[i], index)) {
                    indexes.splice(i, 1);
                    i--;
                }
            }
            if (add) {
                indexes.push(index);
            }
        };
        AccumulationSelection.prototype.checkEquals = function (first, second) {
            return ((first.point === second.point) && (first.series === second.series));
        };
        AccumulationSelection.prototype.checkPointVisibility = function (selectedDataIndexes) {
            var visible = false;
            for (var _i = 0, selectedDataIndexes_1 = selectedDataIndexes; _i < selectedDataIndexes_1.length; _i++) {
                var data = selectedDataIndexes_1[_i];
                if (acc_base_1.pointByIndex(data.point, this.control.visibleSeries[0].points).visible) {
                    visible = true;
                    break;
                }
            }
            return visible;
        };
        AccumulationSelection.prototype.getModuleName = function () {
            return 'AccumulationSelection';
        };
        AccumulationSelection.prototype.destroy = function (accumulation) {
        };
        return AccumulationSelection;
    }(selection_1.BaseSelection));
    exports.AccumulationSelection = AccumulationSelection;
});