all files / chart/series/ line-base.js

98.04% Statements 200/204
86.31% Branches 145/168
100% Functions 23/23
98.52% Lines 200/203
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   3510×   4817× 4817× 4817× 4817× 4817× 4817× 4817×   4817×   4817× 4817× 4817× 4817× 4817× 4817× 4817× 136390× 136390× 136390× 136390× 136390× 131346× 131346× 131346×     4817× 4817× 131346× 131346× 2281×     129065×     4817×   99725× 99725× 96048× 96048× 96048×     99725×   6478× 6478×   6589× 6589× 6589× 6589× 6589× 6589×   6589× 6589× 6545×   6589× 6589×                                                                       5131× 2150×     467× 467× 467× 467× 467× 467× 467×       22007× 22007× 22007×     467× 467×     467× 467× 467×       119442× 119442× 119442× 119442×     5454× 5454× 5454× 1242× 1242×     4212× 687× 687×       3525×       151× 151× 151× 2654× 2654× 151×   2654×   151×   125× 125× 44×   81× 79× 79× 33×     125×   201× 201× 201× 201×   197× 414× 414× 217× 217× 217× 22× 22×       197×   109× 109× 109× 109× 109× 109× 109×   109× 109× 109× 109× 37× 37× 37×     146×       7746× 7746× 1182× 1182×       6564× 6564×         146× 146×     146× 146×            
define(["require", "exports", "../../common/utils/helper", "@syncfusion/ej2-svg-base", "@syncfusion/ej2-base"], function (require, exports, helper_1, ej2_svg_base_1, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var LineBase = (function () {
        function LineBase(chartModule) {
            this.chart = chartModule;
        }
        LineBase.prototype.enableComplexProperty = function (series) {
            var tempPoints = [];
            var tempPoints2 = [];
            var xVisibleRange = series.xAxis.visibleRange;
            var yVisibleRange = series.yAxis.visibleRange;
            var seriesPoints = series.points;
            var areaBounds = series.clipRect;
            var xTolerance = this.chart && this.chart.zoomRedraw && this.chart.redraw ? this.previousX :
                Math.abs(xVisibleRange.delta / areaBounds.width);
            var yTolerance = this.chart && this.chart.zoomRedraw && this.chart.redraw ? this.previousY :
                Math.abs(yVisibleRange.delta / areaBounds.height);
            var prevXValue = (seriesPoints[0] && seriesPoints[0].xValue > xTolerance) ? 0 : xTolerance;
            var prevYValue = (seriesPoints[0] && seriesPoints[0].y > yTolerance) ? 0 : yTolerance;
            this.previousX = xTolerance;
            this.previousY = yTolerance;
            var xVal = 0;
            var yVal = 0;
            for (var _i = 0, seriesPoints_1 = seriesPoints; _i < seriesPoints_1.length; _i++) {
                var currentPoint = seriesPoints_1[_i];
                currentPoint.symbolLocations = [];
                xVal = !ej2_base_1.isNullOrUndefined(currentPoint.xValue) ? currentPoint.xValue : xVisibleRange.min;
                yVal = !ej2_base_1.isNullOrUndefined(currentPoint.yValue) ? currentPoint.yValue : yVisibleRange.min;
                if (Math.abs(prevXValue - xVal) >= xTolerance || Math.abs(prevYValue - yVal) >= yTolerance) {
                    tempPoints.push(currentPoint);
                    prevXValue = xVal;
                    prevYValue = yVal;
                }
            }
            var tempPoint;
            for (var i = 0; i < tempPoints.length; i++) {
                tempPoint = tempPoints[i];
                if (ej2_base_1.isNullOrUndefined(tempPoint.x) || (series.category === 'Indicator' && (isNaN(tempPoint.xValue) || isNaN(tempPoint.yValue)))) {
                    continue;
                }
                else {
                    tempPoints2.push(tempPoint);
                }
            }
            return tempPoints2;
        };
        LineBase.prototype.getLineDirection = function (firstPoint, secondPoint, series, isInverted, getPointLocation, startPoint) {
            var direction = '';
            if (firstPoint != null) {
                var point1 = getPointLocation(firstPoint.xValue, firstPoint.yValue, series.xAxis, series.yAxis, isInverted, series);
                var point2 = getPointLocation(secondPoint.xValue, secondPoint.yValue, series.xAxis, series.yAxis, isInverted, series);
                direction = startPoint + ' ' + (point1.x) + ' ' + (point1.y) + ' ' +
                    'L' + ' ' + (point2.x) + ' ' + (point2.y) + ' ';
            }
            return direction;
        };
        LineBase.prototype.appendLinePath = function (options, series, clipRect) {
            var points = this.appendPathElement(options, series, clipRect);
            helper_1.pathAnimation(points.element, options.d, series.chart.redraw, points.previousDirection, points.chart.duration);
        };
        LineBase.prototype.appendPathElement = function (options, series, clipRect) {
            var element = helper_1.getElement(options.id);
            var chart = series.chart;
            var previousDirection = element ? element.getAttribute('d') : null;
            var htmlObject = series.chart.renderer.drawPath(options, new Int32Array([series.clipRect.x, series.clipRect.y]));
            Eif (htmlObject) {
                htmlObject.setAttribute('clip-path', clipRect);
            }
            series.pathElement = htmlObject;
            if (!series.chart.enableCanvas) {
                series.seriesElement.appendChild(htmlObject);
            }
            series.isRectSeries = false;
            return { element: element, previousDirection: previousDirection, chart: chart };
        };
        LineBase.prototype.addPath = function (options, series, clipRect) {
            var points = this.appendPathElement(options, series, clipRect);
            Eif (points.previousDirection !== '' && options.d !== '') {
                var startPathCommands = points.previousDirection.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/g);
                var endPathCommands = (options.d).match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/g);
                var maxLength = Math.max(startPathCommands.length, endPathCommands.length);
                var minLength = Math.min(startPathCommands.length, endPathCommands.length);
                if (startPathCommands.length < endPathCommands.length) {
                    for (var i = minLength; i < maxLength; i++) {
                        Eif (endPathCommands.length !== startPathCommands.length) {
                            startPathCommands.push((startPathCommands[startPathCommands.length - 1]).replace('M', 'L'));
                        }
                    }
                    helper_1.animateAddPoints(points.element, options.d, series.chart.redraw, startPathCommands.join(' '), this.chart.duration);
                }
                else if (startPathCommands.length > endPathCommands.length) {
                    for (var i = minLength; i < maxLength; i++) {
                        Eif (endPathCommands.length !== startPathCommands.length) {
                            if (series.removedPointIndex === series.points.length) {
                                endPathCommands.push((endPathCommands[endPathCommands.length - 1]).replace('M', 'L'));
                            }
                            else {
                                endPathCommands.splice(1, 0, endPathCommands[0].replace('M', 'L'));
                            }
                        }
                    }
                    helper_1.animateAddPoints(points.element, endPathCommands.join(''), series.chart.redraw, points.previousDirection, this.chart.duration, options.d);
                }
                else {
                    helper_1.animateAddPoints(points.element, options.d, series.chart.redraw, points.previousDirection, this.chart.duration);
                }
            }
        };
        LineBase.prototype.addAreaPath = function (options, series, clipRect) {
            var points = this.appendPathElement(options, series, clipRect);
            Eif (points.previousDirection !== '' && options.d !== '') {
                var startPathCommands = points.previousDirection.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/g);
                var endPathCommands = (options.d).match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/g);
                var maxLength = Math.max(startPathCommands.length, endPathCommands.length);
                var minLength = Math.min(startPathCommands.length, endPathCommands.length);
                if (minLength < endPathCommands.length) {
                    for (var i = minLength; i < maxLength; i++) {
                        Eif (endPathCommands.length !== startPathCommands.length) {
                            Eif (endPathCommands.length !== startPathCommands.length) {
                                if (startPathCommands.length === 1) {
                                    startPathCommands.push(startPathCommands[startPathCommands.length - (options.id.indexOf('border') !== -1 ? 1 : 2)].replace('M', 'L'));
                                }
                                else {
                                    startPathCommands.splice(startPathCommands.length - 1, 0, startPathCommands[startPathCommands.length - (options.id.indexOf('border') !== -1 ? 1 : 2)]);
                                }
                            }
                        }
                    }
                    helper_1.animateAddPoints(points.element, options.d, series.chart.redraw, startPathCommands.join(' '), this.chart.duration);
                }
                else Eif (startPathCommands.length > endPathCommands.length) {
                    for (var i = minLength; i < maxLength; i++) {
                        Eif (endPathCommands.length !== startPathCommands.length) {
                            if (series.removedPointIndex === series.points.length) {
                                if (endPathCommands.length === 1) {
                                    endPathCommands.push(endPathCommands[endPathCommands.length - (options.id.indexOf('border') !== -1 ? 1 : 2)].replace('M', 'L'));
                                }
                                else {
                                    endPathCommands.splice(endPathCommands.length - 1, 0, endPathCommands[endPathCommands.length - (options.id.indexOf('border') !== -1 ? 1 : 2)]);
                                }
                            }
                            else {
                                endPathCommands.splice(1, 0, endPathCommands[1] ? endPathCommands[1] : endPathCommands[0]);
                            }
                        }
                    }
                    helper_1.animateAddPoints(points.element, endPathCommands.join(''), series.chart.redraw, points.previousDirection, this.chart.duration, options.d);
                }
                else {
                    helper_1.animateAddPoints(points.element, options.d, series.chart.redraw, points.previousDirection, this.chart.duration);
                }
            }
        };
        LineBase.prototype.renderMarker = function (series) {
            if (series.marker && series.marker.visible) {
                series.chart.markerRender.render(series);
            }
        };
        LineBase.prototype.doProgressiveAnimation = function (series, option) {
            var animation = new ej2_base_1.Animation({});
            var path = series.pathElement;
            var strokeDashArray = path.getAttribute('stroke-dasharray');
            var pathLength = series.pathElement.getTotalLength();
            var currentTime;
            path.style.visibility = 'hidden';
            animation.animate(path, {
                duration: (option.duration === 0 && ej2_base_1.animationMode === 'Enable') ? 1000 : option.duration,
                delay: option.delay,
                progress: function (args) {
                    path.style.visibility = 'visible';
                    currentTime = Math.abs(Math.round(((args.timeStamp) * pathLength) / args.duration));
                    path.setAttribute('stroke-dasharray', currentTime + ',' + pathLength);
                },
                end: function () {
                    var annotations = helper_1.getElement(series.chart.element.id + '_Annotation_Collections');
                    Iif (annotations) {
                        annotations.style.visibility = 'visible';
                    }
                    path.setAttribute('stroke-dasharray', strokeDashArray);
                    path.style.visibility = '';
                    series.chart.trigger('animationComplete', { series: series.chart.isBlazor ? {} : series });
                }
            });
        };
        LineBase.prototype.storePointLocation = function (point, series, isInverted, getLocation) {
            var markerWidth = (series.marker && series.marker.width) ? series.marker.width : 0;
            var markerHeight = (series.marker && series.marker.height) ? series.marker.height : 0;
            point.symbolLocations.push(getLocation(point.xValue, point.yValue, series.xAxis, series.yAxis, isInverted, series));
            point.regions.push(new ej2_svg_base_1.Rect(point.symbolLocations[0].x - markerWidth, point.symbolLocations[0].y - markerHeight, 2 * markerWidth, 2 * markerHeight));
        };
        LineBase.prototype.withinYRange = function (point, yAxis) {
            return point.yValue >= yAxis.visibleRange.min && point.yValue <= yAxis.visibleRange.max;
        };
        LineBase.prototype.GetStepLineDirection = function (currentPoint, previousPoint, stepLineType, command, series, isBorder) {
            Iif (command === void 0) { command = 'L'; }
            var X = (series.noRisers && isBorder) ? ' M ' : ' L ';
            if (stepLineType === 'Right') {
                command = (series.noRisers && isBorder) ? 'M' : 'L';
                return (command + ' ' +
                    (previousPoint.x) + ' ' + (currentPoint.y) + ' L ' + (currentPoint.x) + ' ' + (currentPoint.y) + ' ');
            }
            else if (stepLineType === 'Center') {
                var centerX = previousPoint.x + (currentPoint.x - previousPoint.x) / 2;
                return (command + ' ' +
                    (centerX) + ' ' + (previousPoint.y) + X + (centerX) + ' ' + (currentPoint.y) + ' L ' + (currentPoint.x) + ' ' + (currentPoint.y) + ' ');
            }
            else {
                return (command + ' ' +
                    (currentPoint.x) + ' ' + (previousPoint.y) + X + (currentPoint.x) + ' ' + (currentPoint.y) + ' ');
            }
        };
        LineBase.prototype.getFirstLastVisiblePoint = function (points) {
            var first = null;
            var last = null;
            for (var _i = 0, points_1 = points; _i < points_1.length; _i++) {
                var point = points_1[_i];
                if (first === null && point.visible) {
                    first = last = point;
                }
                last = point.visible ? point : last;
            }
            return { first: first ? first : points[0], last: last ? last : points[points.length - 1] };
        };
        LineBase.prototype.getBorderDirection = function (direction) {
            var coordinates = direction.split(' ');
            if (coordinates.length > 3 && !(this.chart.stackingAreaSeriesModule) && !(this.chart.stackingStepAreaSeriesModule)) {
                coordinates.splice(coordinates.length - 4, 3);
            }
            else if (this.chart.stackingAreaSeriesModule || this.chart.stackingStepAreaSeriesModule) {
                coordinates.splice(coordinates.length / 2 + 1, coordinates.length / 2 + 1);
                if (coordinates[coordinates.length - 1] === 'L' || coordinates[coordinates.length - 1] === 'M') {
                    coordinates.splice(coordinates.length - 1, 1);
                }
            }
            return coordinates.join(' ');
        };
        LineBase.prototype.removeEmptyPointsBorder = function (borderDirection) {
            var startIndex = 0;
            var coordinates = borderDirection.split(' ');
            var point;
            if (coordinates.length === 4) {
                return coordinates.join(' ');
            }
            do {
                point = coordinates.indexOf('M', startIndex);
                if (point > -1) {
                    coordinates.splice(point + 1, 3);
                    startIndex = point + 1;
                    if (point - 6 > 0) {
                        coordinates.splice(point - 6, 6);
                        startIndex -= 6;
                    }
                }
            } while (point !== -1);
            return coordinates.join(' ');
        };
        LineBase.prototype.doLinearAnimation = function (series, animation) {
            var clipRect = series.clipRectElement.childNodes[0].childNodes[0];
            var duration = series.chart.animated ? series.chart.duration : animation.duration;
            var effect = helper_1.getAnimationFunction('Linear');
            var elementHeight = +clipRect.getAttribute('height');
            var elementWidth = +clipRect.getAttribute('width');
            var xCenter = +clipRect.getAttribute('x');
            var yCenter = series.chart.requireInvertedAxis ? +clipRect.getAttribute('height') + +clipRect.getAttribute('y') :
                +clipRect.getAttribute('y');
            var value;
            clipRect.style.visibility = 'hidden';
            this.animateRect(series, animation, clipRect, duration, effect, elementHeight, elementWidth, xCenter, yCenter, value);
            if (series.marker && series.marker.visible && series.symbolElement) {
                var markerClipRect = series.symbolElement.childNodes[0].childNodes[0];
                markerClipRect.style.visibility = 'hidden';
                this.animateRect(series, animation, markerClipRect, duration, effect, elementHeight, elementWidth, xCenter, yCenter, value);
            }
        };
        LineBase.prototype.animateRect = function (series, animation, clipRect, duration, effect, elementHeight, elementWidth, xCenter, yCenter, value) {
            new ej2_base_1.Animation({}).animate(clipRect, {
                duration: (duration === 0 && ej2_base_1.animationMode === 'Enable') ? 1000 : duration,
                delay: animation.delay,
                progress: function (args) {
                    clipRect.style.visibility = 'visible';
                    if (series.chart.requireInvertedAxis) {
                        value = effect(args.timeStamp, 0, elementHeight, args.duration);
                        clipRect.setAttribute('transform', 'translate(' + xCenter + ' ' + yCenter +
                            ') scale(1,' + (value / elementHeight) + ') translate(' + (-xCenter) + ' ' + (-yCenter) + ')');
                    }
                    else {
                        value = effect(args.timeStamp, 0, elementWidth, args.duration);
                        clipRect.setAttribute('transform', 'translate(' + xCenter + ' ' + yCenter +
                            ') scale(' + (value / elementWidth) + ', 1) translate(' + (-xCenter) + ' ' + (-yCenter) + ')');
                    }
                },
                end: function () {
                    var annotations = helper_1.getElement(series.chart.element.id + '_Annotation_Collections');
                    Iif (annotations) {
                        annotations.style.visibility = 'visible';
                    }
                    clipRect.setAttribute('transform', 'translate(0,0)');
                    series.chart.trigger('animationComplete', { series: series.chart.isBlazor ? {} : series });
                }
            });
        };
        return LineBase;
    }());
    exports.LineBase = LineBase;
});