all files / chart/series/ spline-series.js

91.6% Statements 109/119
87.1% Branches 81/93
100% Functions 15/15
91.38% Lines 106/116
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          232×   259× 259× 259× 259× 259× 259× 259× 259× 259× 2908× 2908× 253×   2908× 2908× 2908× 2908× 2897× 2897× 2631× 2631×   2897× 2897×   2897×     2897×     11× 11× 11×     259× 12× 12× 12×   259×   259× 259× 259× 258×     2643× 2643× 2643× 2643× 2643× 2643× 2643×     11× 11×   11× 11× 11×                                   44× 12×                 32×       32× 16×                   41750×          
/* 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", "./spline-base"], function (require, exports, helper_1, ej2_svg_base_1, spline_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var SplineSeries = (function (_super) {
        __extends(SplineSeries, _super);
        function SplineSeries() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        SplineSeries.prototype.render = function (series, xAxis, yAxis, isInverted, pointAnimate, pointUpdate) {
            var firstPoint = null;
            var direction = '';
            var startPoint = 'M';
            var points = [];
            var tempPoints = series.category === 'TrendLine' ? series.points : this.enableComplexProperty(series);
            points = this.filterEmptyPoints(series, tempPoints);
            var previous;
            var getCoordinate = series.chart.chartAreaType === 'PolarRadar' ? helper_1.TransformToVisible : helper_1.getPoint;
            for (var _i = 0, points_1 = points; _i < points_1.length; _i++) {
                var point = points_1[_i];
                if (point.index === 1) {
                    direction = '';
                }
                previous = this.getPreviousIndex(points, point.index - 1, series);
                point.symbolLocations = [];
                point.regions = [];
                if (point.visible) {
                    Eif (helper_1.withInRange(points[previous], point, points[this.getNextIndex(points, point.index - 1, series)], series)) {
                        if (firstPoint !== null) {
                            direction = this.getSplineDirection(series.drawPoints[previous], firstPoint, point, xAxis, yAxis, isInverted, series, startPoint, getCoordinate, direction);
                            startPoint = 'L';
                        }
                        this.storePointLocation(point, series, isInverted, getCoordinate);
                        if (direction === '' && points.length === 1) {
                            direction = 'M ' + point.symbolLocations[0].x + ' ' + point.symbolLocations[0].y;
                        }
                        if (firstPoint === null && direction !== '' && (point.index === points.length - 1 || (points[point.index + 1] && !points[point.index + 1].visible))) {
                            direction += 'M ' + point.symbolLocations[0].x + ' ' + point.symbolLocations[0].y + ' ';
                        }
                    }
                    firstPoint = point;
                }
                else {
                    startPoint = 'M';
                    firstPoint = null;
                    point.symbolLocations = [];
                }
            }
            if ((points.length > 0 && series.drawPoints.length > 0) && series.chart.chartAreaType === 'PolarRadar' && series.isClosed) {
                var connectPoints = this.getFirstLastVisiblePoint(points);
                direction = this.getSplineDirection(series.drawPoints[series.drawPoints.length - 1], connectPoints.last, { xValue: connectPoints.first.xValue, yValue: connectPoints.first.yValue }, xAxis, yAxis, isInverted, series, startPoint, getCoordinate, direction);
                startPoint = 'L';
            }
            var name = series.category === 'TrendLine' ? series.chart.element.id + '_Series_' + series.sourceIndex + '_TrendLine_' + series.index :
                series.chart.element.id + '_Series_' + series.index;
            var options = new ej2_svg_base_1.PathOption(name, 'transparent', series.width, series.interior, series.opacity, series.dashArray, direction);
            this[pointAnimate ? 'addPath' : 'appendLinePath'](options, series, '');
            if (!pointUpdate) {
                this.renderMarker(series);
            }
        };
        SplineSeries.prototype.getSplineDirection = function (data, firstPoint, point, xAxis, yAxis, isInverted, series, startPoint, getCoordinate, direction) {
            var controlPoint1 = data.controlPoint1;
            var controlPoint2 = data.controlPoint2;
            var pt1 = getCoordinate(firstPoint.xValue, firstPoint.yValue, xAxis, yAxis, isInverted, series);
            var pt2 = getCoordinate(point.xValue, point.yValue, xAxis, yAxis, isInverted, series);
            var bpt1 = getCoordinate(controlPoint1.x, controlPoint1.y, xAxis, yAxis, isInverted, series);
            var bpt2 = getCoordinate(controlPoint2.x, controlPoint2.y, xAxis, yAxis, isInverted, series);
            return direction.concat((startPoint + ' ' + (pt1.x) + ' ' + (pt1.y) + ' ' + 'C' + ' ' + (bpt1.x) + ' '
                + (bpt1.y) + ' ' + (bpt2.x) + ' ' + (bpt2.y) + ' ' + (pt2.x) + ' ' + (pt2.y) + ' '));
        };
        SplineSeries.prototype.updateDirection = function (series, point) {
            this.render(series, series.xAxis, series.yAxis, series.chart.requireInvertedAxis, false, true);
            for (var i = 0; i < point.length; i++) {
                Eif (series.marker && series.marker.visible) {
                    series.chart.markerRender.renderMarker(series, series.points[point[i]], series.points[point[i]].symbolLocations[0], null, true);
                }
                Eif (series.marker.dataLabel.visible && series.chart.dataLabelModule) {
                    series.chart.dataLabelModule.commonId = series.chart.element.id + '_Series_' + series.index + '_Point_';
                    series.chart.dataLabelModule.renderDataLabel(series, series.points[point[i]], null, series.marker.dataLabel);
                }
            }
        };
        SplineSeries.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);
                Iif (series.removedPointIndex === 0 && startPathCommands.length > endPathCommands.length && startPathCommands[2] && startPathCommands[2].indexOf('M') === 0) {
                    startPathCommands.splice(0, startPathCommands.length - endPathCommands.length);
                    points.previousDirection = startPathCommands.join('');
                }
                if (startPathCommands.length < endPathCommands.length) {
                    for (var i = startPathCommands.length; i < endPathCommands.length; i++) {
                        Eif (endPathCommands.length !== startPathCommands.length) {
                            Iif (endPathCommands.length === startPathCommands.length + 1 && endPathCommands[endPathCommands.length - 1].indexOf('M') === 0) {
                                startPathCommands.push(endPathCommands[endPathCommands.length - 1]);
                            }
                            else if (startPathCommands[startPathCommands.length - 1].indexOf('C') === 0) {
                                startPathCommands.push('L ' + ((startPathCommands[startPathCommands.length - 1]).split(' ').slice(-3)).join(' '));
                            }
                            else Eif (startPathCommands[startPathCommands.length - 1].indexOf('L') === 0) {
                                var points_2 = ((startPathCommands[startPathCommands.length - 1])).split(' ').slice(-3);
                                startPathCommands.push('C ' + points_2.join(' ') + points_2.join(' ') + points_2.join(' '));
                            }
                            else {
                                var points_3 = (startPathCommands[startPathCommands.length - 1]).replace('M', '');
                                startPathCommands.push('C' + points_3 + points_3 + points_3);
                            }
                        }
                    }
                    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++) {
                        if (series.removedPointIndex === series.points.length && endPathCommands.length !== startPathCommands.length) {
                            if (endPathCommands[endPathCommands.length - 1].indexOf('C') === 0) {
                                endPathCommands.push('L ' + ((endPathCommands[endPathCommands.length - 1]).split(' ').slice(-3)).join(' '));
                            }
                            else Eif (endPathCommands[endPathCommands.length - 1].indexOf('L') === 0) {
                                var points_4 = ((endPathCommands[endPathCommands.length - 1])).split(' ').slice(-3);
                                endPathCommands.push('C ' + points_4.join(' ') + points_4.join(' ') + points_4.join(' '));
                            }
                            else {
                                var points_5 = (endPathCommands[endPathCommands.length - 1]).replace('M', '');
                                endPathCommands.push('C' + points_5 + points_5 + points_5);
                            }
                        }
                        else {
                            Iif (endPathCommands.length === 1) {
                                var points_6 = (endPathCommands[endPathCommands.length - 1]).replace('M', '');
                                endPathCommands.push('C' + points_6 + points_6 + points_6);
                            }
                            else if (endPathCommands.length !== startPathCommands.length) {
                                endPathCommands.splice(1, 0, 'C ' + endPathCommands[0].split(' ').slice(-3).join(' ') + endPathCommands[0].split(' ').slice(-3).join(' ') + endPathCommands[0].split(' ').slice(-3).join(' '), 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);
                }
            }
        };
        SplineSeries.prototype.getModuleName = function () {
            return 'SplineSeries';
        };
        SplineSeries.prototype.destroy = function () {
        };
        return SplineSeries;
    }(spline_base_1.SplineBase));
    exports.SplineSeries = SplineSeries;
});