all files / chart/series/ marker-explode.js

92.31% Statements 192/208
89.21% Branches 215/241
95.83% Functions 23/24
93.53% Lines 188/201
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          3657× 3657× 3657× 3657×   3657×     3657× 3657×   3384×     3384× 3384×   242× 242× 22×     1093× 1093×   761×     785× 785× 785× 785× 785× 785× 785× 785× 451× 451× 451× 451×     451× 451×   108×   451× 11×       334×   327× 327× 327×     326× 640× 640× 105×   535× 512×   23×   535× 475× 475×           778× 778× 430×   349× 30× 31× 31× 31×       349× 457×   457× 457× 457× 598× 377×         349× 349× 457× 457×   349×     778×   40× 40×               778×   373× 373×     373×     373×   377× 377× 377× 377× 377×   373× 373× 373×   373× 166×   373×   373× 373× 373× 373×   373× 373× 373×   373×   373× 252×   373×           373× 746× 746× 746× 746× 746×   746×     746× 746× 746×     744×     373×   373× 373× 373× 373× 373× 896×     896× 896× 896× 896× 896× 896×       7646× 6732× 6732×         896× 896× 896× 236×   896×           869× 869× 869× 869× 32×   32× 32×                 32× 64×   32× 26×       837× 5588× 5588× 5588×   5588×         869× 838×          
/* 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", "../../common/utils/helper", "@syncfusion/ej2-svg-base", "@syncfusion/ej2-base", "../../chart/utils/get-data", "../../common/utils/helper", "../../common/utils/helper"], function (require, exports, helper_1, ej2_svg_base_1, ej2_base_1, get_data_1, helper_2, helper_3) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var MarkerExplode = (function (_super) {
        __extends(MarkerExplode, _super);
        function MarkerExplode(chart) {
            var _this = _super.call(this, chart) || this;
            _this.elementId = chart.element.id;
            _this.commonXvalues = [];
            return _this;
        }
        MarkerExplode.prototype.addEventListener = function () {
            Iif (this.chart.isDestroyed) {
                return;
            }
            this.chart.on(ej2_base_1.Browser.touchMoveEvent, this.mouseMoveHandler, this);
            this.chart.on(ej2_base_1.Browser.touchEndEvent, this.mouseUpHandler, this);
        };
        MarkerExplode.prototype.removeEventListener = function () {
            Iif (this.chart.isDestroyed) {
                return;
            }
            this.chart.off(ej2_base_1.Browser.touchMoveEvent, this.mouseMoveHandler);
            this.chart.off(ej2_base_1.Browser.touchEndEvent, this.mouseUpHandler);
        };
        MarkerExplode.prototype.mouseUpHandler = function () {
            var chart = this.chart;
            if (chart.isTouch && !chart.crosshair.enable && !this.isSelected(chart) && !(this.chart.zoomModule && helper_2.getElement(this.elementId + '_ZoomArea'))) {
                this.markerMove(true);
            }
        };
        MarkerExplode.prototype.mouseMoveHandler = function () {
            var chart = this.chart;
            if ((chart.highlightMode !== 'None' || (chart.tooltip.enable)) && (!chart.isTouch || chart.startMove) && !this.isSelected(chart)
                && !(this.chart.zoomModule && helper_2.getElement(this.elementId + '_ZoomArea'))) {
                this.markerMove(false);
            }
        };
        MarkerExplode.prototype.markerMove = function (remove) {
            var _this = this;
            var chart = this.chart;
            this.currentPoints = [];
            var data;
            var previous;
            var explodeSeries;
            var series;
            if (!chart.tooltip.shared || !chart.tooltip.enable) {
                data = this.getData();
                series = data.series;
                previous = this.previousPoints[0];
                explodeSeries = series && ((series.type === 'Bubble' || series.drawType === 'Scatter' || series.type === 'Scatter') ||
                    (((series.type !== 'Candle') && (series.type !== 'Hilo') && (series.type !== 'HiloOpenClose')) &&
                        (series.marker.visible && series.marker.width !== 0 && series.marker.height !== 0)));
                data.lierIndex = this.lierIndex;
                if (data.point && explodeSeries && ((!previous || (previous.point !== data.point)) ||
                    (previous && previous.lierIndex > 3 && previous.lierIndex !== this.lierIndex))) {
                    this.currentPoints.push(data);
                }
                if (data.point && explodeSeries && chart.isPointMouseDown) {
                    this.currentPoints.push(data);
                }
            }
            else {
                if (!helper_2.withInBounds(chart.mouseX, chart.mouseY, chart.chartAxisLayoutPanel.seriesClipRect)) {
                    return null;
                }
                Eif (chart.tooltip.enable) {
                    var pointData = chart.chartAreaType === 'PolarRadar' ? this.getData() : null;
                    if (!this.chart.tooltip.showNearestPoint) {
                        this.currentPoints = this.chart.tooltipModule.currentPoints;
                    }
                    else {
                        for (var _i = 0, _a = chart.visibleSeries; _i < _a.length; _i++) {
                            var chartSeries = _a[_i];
                            if (!chartSeries.enableTooltip || chartSeries.category === 'Indicator') {
                                continue;
                            }
                            if (chart.chartAreaType === 'Cartesian' && chartSeries.visible) {
                                data = this.getClosestX(chart, chartSeries, this.commonXValue(this.chart.visibleSeries));
                            }
                            else if (chart.chartAreaType === 'PolarRadar' && chartSeries.visible && pointData.point !== null) {
                                data = new helper_2.PointData(chartSeries.points[pointData.point.index], chartSeries);
                            }
                            if (data) {
                                this.currentPoints.push(data);
                                data = null;
                            }
                        }
                    }
                }
            }
            var length = this.previousPoints.length;
            if (this.currentPoints.length > 0 || (length > 0 && chart.tooltip.shared)) {
                if (length === 0 || chart.isPointMouseDown || (length > 0 && (this.currentPoints.length === 0 ||
                    (this.previousPoints[0].point !== this.currentPoints[0].point)))) {
                    if (length > 0) {
                        for (var _b = 0, _c = this.previousPoints; _b < _c.length; _b++) {
                            var previousPoint = _c[_b];
                            Eif (!ej2_base_1.isNullOrUndefined(previousPoint)) {
                                this.removeHighlightedMarker(previousPoint.series, previousPoint.point);
                            }
                        }
                    }
                    var _loop_1 = function (data_1) {
                        Eif ((data_1 && data_1.point) || ((series.type !== 'Candle') &&
                            (series.type !== 'Hilo') && (series.type !== 'HiloOpenClose'))) {
                            helper_2.stopTimer(this_1.markerExplode);
                            this_1.isRemove = true;
                            data_1.point.symbolLocations.map(function (location, index) {
                                if (data_1.series.marker.allowHighlight && (!data_1.series.isRectSeries || data_1.point.marker.visible)) {
                                    _this.drawTrackBall(data_1.series, data_1.point, location, index);
                                }
                            });
                        }
                    };
                    var this_1 = this;
                    for (var _d = 0, _e = this.currentPoints; _d < _e.length; _d++) {
                        var data_1 = _e[_d];
                        _loop_1(data_1);
                    }
                    this.previousPoints = ej2_base_1.extend([], this.currentPoints, null, true);
                }
            }
            if (!chart.tooltip.enable && ((this.currentPoints.length === 0 && this.isRemove) || (remove && this.isRemove) ||
                !helper_2.withInBounds(chart.mouseX, chart.mouseY, chart.chartAxisLayoutPanel.seriesClipRect))) {
                this.isRemove = false;
                Iif (!ej2_base_1.isNullOrUndefined(this.previousPoints[0])) {
                    this.markerExplode = +setTimeout(function () {
                        if (_this.previousPoints[0]) {
                            _this.removeHighlightedMarker(_this.previousPoints[0].series, _this.previousPoints[0].point);
                        }
                    }, 2000);
                }
            }
            this.currentPoints = [];
        };
        MarkerExplode.prototype.animationDuration = function () {
            var duration = 200;
            Iif (this.chart.maxPointCount > 100) {
                duration = 10;
            }
            else Iif (this.chart.maxPointCount > 50) {
                duration = 100;
            }
            return duration;
        };
        MarkerExplode.prototype.drawTrackBall = function (series, point, location, index) {
            var marker = point.marker;
            var seriesMarker = series.marker;
            var shape = marker.shape || seriesMarker.shape || 'Circle';
            var svg;
            if (shape === 'None' || shape === 'Image') {
                return null;
            }
            var element = series.symbolElement || series.seriesElement;
            var className;
            if (this.chart.highlightModule && this.chart.highlightMode !== 'None') {
                className = this.chart.highlightModule.generateStyle(series);
            }
            if (this.chart.selectionModule && this.chart.selectionMode !== 'None') {
                className = this.chart.selectionModule.generateStyle(series);
            }
            var symbolId = this.elementId + '_Series_' + series.index + '_Point_' + point.index + '_Trackball' +
                (index ? index : '');
            var size = new ej2_svg_base_1.Size((marker.width || seriesMarker.width) + 3, (marker.height || seriesMarker.height) + 3);
            var border = (marker.border || series.border);
            var explodeSeries = (series.type === 'BoxAndWhisker' || series.type === 'Bubble' || series.type === 'Scatter');
            var borderColor = (border.color && border.color !== 'transparent') ? border.color :
                marker.fill || point.interior || (explodeSeries ? point.color : series.interior);
            var colorValue = helper_3.convertHexToColor(helper_3.colorNameToHex(borderColor));
            var borderWidth = marker.border ? marker.border.width : seriesMarker.border.width;
            var markerShadow = series.chart.themeStyle.markerShadow ||
                'rgba(' + colorValue.r + ',' + colorValue.g + ',' + colorValue.b + ',0.2)';
            var markerElement = document.getElementById(this.elementId + '_Series_' + series.index + '_Point_' +
                point.index + '_Symbol');
            if (!ej2_base_1.isNullOrUndefined(markerElement)) {
                markerElement.setAttribute('visibility', 'hidden');
            }
            if (this.chart.enableCanvas) {
                var trackElement = document.getElementById(this.chart.element.id + '_Secondary_Element');
                svg = this.chart.svgRenderer.createSvg({
                    id: this.chart.element.id + '_trackball_svg',
                    width: this.chart.availableSize.width,
                    height: this.chart.availableSize.height
                });
                svg.style.cssText = 'position: absolute; display:block; pointer-events: none';
                trackElement.appendChild(svg);
            }
            for (var i = 0; i < 2; i++) {
                var options = new ej2_svg_base_1.PathOption(symbolId + '_' + i, i ? (marker.fill || point.color || (explodeSeries ? series.interior : '#ffffff')) : 'transparent', borderWidth + (i ? 0 : 8), i ? borderColor : markerShadow, (marker.opacity || seriesMarker.opacity), series.marker.border.dashArray, '');
                var symbol = helper_1.drawSymbol(location, shape, size, marker.imageUrl, options, '', this.chart.svgRenderer, series.clipRect);
                symbol.setAttribute('class', this.elementId + '_EJ2-Trackball_Series_' + series.index + '_Point_' + point.index);
                var selectionId = element.id.indexOf('Symbol') !== -1 ? '_Symbol' : '';
                var seletionElem = document.getElementById(this.elementId + '_Series_' + series.index + '_Point_' +
                    point.index + selectionId);
                if (className !== '' && !ej2_base_1.isNullOrUndefined(className) && !ej2_base_1.isNullOrUndefined(seletionElem) &&
                    seletionElem.hasAttribute('class') && (className === seletionElem.getAttribute('class'))) {
                    symbol.classList.add(className);
                }
                symbol.setAttribute('clip-path', element.getAttribute('clip-path'));
                symbol.setAttribute('transform', element.getAttribute('transform'));
                if (this.chart.enableCanvas) {
                    svg.appendChild(symbol);
                }
                else {
                    this.chart.svgObject.appendChild(symbol);
                }
            }
            this.doAnimation(series, point, false);
        };
        MarkerExplode.prototype.doAnimation = function (series, point, endAnimate) {
            Iif (endAnimate === void 0) { endAnimate = false; }
            var duration = this.animationDuration();
            var delay = 0;
            var rectElements = document.getElementsByClassName(this.elementId + '_EJ2-Trackball_Series_' + series.index + '_Point_' + point.index);
            for (var i = 0, len = rectElements.length; i < len; i++) {
                this.trackballAnimate(rectElements[i], delay, duration, series, point.index, point.symbolLocations[0], false, endAnimate);
            }
        };
        MarkerExplode.prototype.trackballAnimate = function (elements, delays, durations, series, pointIndex, point, isLabel, endAnimate) {
            var centerX = point.x;
            var centerY = point.y;
            var clipX = (series.type !== 'Polar' && series.type !== 'Radar') ? series.clipRect.x : 0;
            var clipY = (series.type !== 'Polar' && series.type !== 'Radar') ? series.clipRect.y : 0;
            var transform = elements.getAttribute('transform');
            new ej2_base_1.Animation({}).animate(elements, {
                duration: durations,
                delay: delays,
                progress: function (args) {
                    if (args.timeStamp > args.delay) {
                        args.element.style.visibility = 'visible';
                        elements.setAttribute('transform', 'translate(' + (centerX + clipX)
                            + ' ' + (centerY + clipY) + ') scale(1) translate(' + (-centerX) + ' ' + (-centerY) + ')');
                    }
                },
                end: function () {
                    elements.style.visibility = '';
                    elements.setAttribute('transform', transform);
                    if (!isLabel && (pointIndex === series.points.length - 1)) {
                        series.chart.trigger('animationComplete', { series: series.chart.isBlazor ? {} : series });
                    }
                    Iif (endAnimate) {
                        ej2_base_1.remove(elements);
                    }
                }
            });
        };
        MarkerExplode.prototype.removeHighlightedMarker = function (series, point, fadeOut) {
            Iif (series === void 0) { series = null; }
            Iif (point === void 0) { point = null; }
            if (fadeOut === void 0) { fadeOut = false; }
            if (!ej2_base_1.isNullOrUndefined(series) && !ej2_base_1.isNullOrUndefined(point)) {
                var markerElement = document.getElementById(this.elementId + '_Series_' + series.index + '_Point_' +
                    point.index + '_Symbol');
                var trackballElements = document.getElementsByClassName(this.elementId + '_EJ2-Trackball_Series_' + series.index + '_Point_' + point.index);
                Iif (trackballElements.length === 0) {
                    var elements = document.querySelectorAll("[class*=\"" + (this.elementId + '_EJ2-Trackball_Series_' + series.index + '_Point_' + point.index) + "\"]");
                    if (elements[1]) {
                        elements[1].remove();
                    }
                    if (elements[0]) {
                        elements[0].remove();
                    }
                }
                for (var i = 0, len = trackballElements.length; i < len; i++) {
                    ej2_base_1.remove(trackballElements[0]);
                }
                if (!ej2_base_1.isNullOrUndefined(markerElement)) {
                    markerElement.setAttribute('visibility', 'visible');
                }
            }
            else {
                for (var _i = 0, _a = series.points; _i < _a.length; _i++) {
                    var point_1 = _a[_i];
                    var elements = document.getElementsByClassName(this.elementId + '_EJ2-Trackball_Series_' + series.index + '_Point_' + point_1.index);
                    var markerElement = document.getElementById(this.elementId + '_Series_' + series.index + '_Point_' +
                        point_1.index + '_Symbol');
                    for (var i = 0, len = elements.length; i < len; i++) {
                        Eif (!ej2_base_1.isNullOrUndefined(markerElement)) {
                            markerElement.setAttribute('visibility', 'visible');
                        }
                        ej2_base_1.remove(elements[0]);
                    }
                }
            }
            if (fadeOut) {
                this.previousPoints = [];
            }
        };
        return MarkerExplode;
    }(get_data_1.ChartData));
    exports.MarkerExplode = MarkerExplode;
});