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

99.23% Statements 129/130
85.05% Branches 91/107
100% Functions 14/14
99.21% Lines 126/127
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          73×   120× 120× 120× 120× 120× 120× 120× 120× 120× 120× 120× 120× 120× 120× 120× 120× 938× 938×     937× 937× 937×     120× 120× 120× 120×   120× 937× 937× 937× 937× 937×   878× 733× 733× 733× 733× 733× 733×       145× 145× 145× 145×   878× 878×     59× 59×   937×   141× 141×     120× 120× 44× 44×   120× 119×     11× 11×   11× 11× 11×       33× 33× 31×       31×       31× 31× 31× 31× 31×                   27× 25× 134× 134× 134×                   129× 65×     64×   129×       25×           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 SplineAreaSeries = (function (_super) {
        __extends(SplineAreaSeries, _super);
        function SplineAreaSeries() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        SplineAreaSeries.prototype.render = function (series, xAxis, yAxis, isInverted, pointAnimate, pointUpdate) {
            var firstPoint = null;
            var direction = '';
            var startPoint = null;
            var startPoint1 = null;
            var pt2;
            var bpt1;
            var bpt2;
            var controlPt1;
            var controlPt2;
            var realPoints = [];
            var points = [];
            var point;
            var pointIndex = 0;
            realPoints = this.filterEmptyPoints(series);
            var emptyPointDirection = '';
            for (var i = 0; i < realPoints.length; i++) {
                point = realPoints[i];
                if (point.x === null || point.x === '') {
                    continue;
                }
                else {
                    point.index = pointIndex;
                    pointIndex++;
                    points.push(point);
                }
            }
            var pointsLength = points.length;
            var previous;
            var getCoordinate = series.chart.chartAreaType === 'PolarRadar' ? helper_1.TransformToVisible : helper_1.getPoint;
            var origin = series.chart.chartAreaType === 'PolarRadar' ? series.points[0].yValue :
                Math.max(series.yAxis.visibleRange.min, 0);
            for (var i = 0; i < pointsLength; i++) {
                point = points[i];
                point.symbolLocations = [];
                point.regions = [];
                previous = this.getPreviousIndex(points, point.index - 1, series);
                if (point.visible &&
                    helper_1.withInRange(points[previous], point, points[this.getNextIndex(points, point.index - 1, series)], series)) {
                    if (firstPoint) {
                        controlPt1 = series.drawPoints[previous].controlPoint1;
                        controlPt2 = series.drawPoints[previous].controlPoint2;
                        pt2 = getCoordinate(point.xValue, point.yValue, xAxis, yAxis, isInverted, series);
                        bpt1 = getCoordinate(controlPt1.x, controlPt1.y, xAxis, yAxis, isInverted, series);
                        bpt2 = getCoordinate(controlPt2.x, controlPt2.y, xAxis, yAxis, isInverted, series);
                        direction = direction.concat('C ' + bpt1.x + ' '
                            + bpt1.y + ' ' + bpt2.x + ' ' + bpt2.y + ' ' + pt2.x + ' ' + pt2.y + ' ');
                    }
                    else {
                        startPoint = getCoordinate(point.xValue, origin, xAxis, yAxis, isInverted, series);
                        direction += ('M ' + startPoint.x + ' ' + startPoint.y + ' ');
                        startPoint1 = getCoordinate(point.xValue, point.yValue, xAxis, yAxis, isInverted, series);
                        direction += ('L ' + startPoint1.x + ' ' + startPoint1.y + ' ');
                    }
                    this.storePointLocation(point, series, isInverted, getCoordinate);
                    firstPoint = point;
                }
                else {
                    firstPoint = null;
                    point.symbolLocations = [];
                }
                if (((i + 1 < pointsLength && !points[i + 1].visible) || i === pointsLength - 1)
                    && pt2 && startPoint) {
                    startPoint = getCoordinate(point.xValue, origin, xAxis, yAxis, isInverted, series);
                    direction = direction.concat('L ' + (startPoint.x) + ' ' + (startPoint.y) + ' ');
                }
            }
            this[pointAnimate ? 'addPath' : 'appendLinePath'](new ej2_svg_base_1.PathOption(series.chart.element.id + '_Series_' + series.index, series.interior, 0, 'transparent', series.opacity, series.dashArray, direction), series, '');
            if (series.border.width !== 0) {
                emptyPointDirection = this.removeEmptyPointsBorder(this.getBorderDirection(direction));
                this[pointAnimate ? 'addPath' : 'appendLinePath'](new ej2_svg_base_1.PathOption(series.chart.element.id + '_Series_border_' + series.index, 'transparent', series.border.width, series.border.color ? series.border.color : series.interior, 1, series.border.dashArray, emptyPointDirection), series, '');
            }
            if (!pointUpdate) {
                this.renderMarker(series);
            }
        };
        SplineAreaSeries.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);
                }
            }
        };
        SplineAreaSeries.prototype.addPath = function (options, series, clipRect) {
            var points = this.appendPathElement(options, series, clipRect);
            if (points.previousDirection !== '' && options.d !== '') {
                if (points.previousDirection.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/g).length === 2) {
                    points.previousDirection = points.previousDirection.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/g)[0] + 'L ' + points.previousDirection.split(' ')[1] + ' ' + points.previousDirection.split(' ')[2]
                        + ' C ' + points.previousDirection.split(' ')[1] + ' ' + points.previousDirection.split(' ')[2] + ' ' + points.previousDirection.split(' ')[1] + ' ' + points.previousDirection.split(' ')[2] + ' ' + points.previousDirection.split(' ')[1] + ' ' + points.previousDirection.split(' ')[2]
                        + ' L ' + points.previousDirection.split(' ')[1] + ' ' + points.previousDirection.split(' ')[2];
                }
                if ((options.d).match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/g).length === 2) {
                    options.d = points.previousDirection.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/g)[0] + 'L ' + points.previousDirection.split(' ')[1] + ' ' + points.previousDirection.split(' ')[2]
                        + ' C ' + points.previousDirection.split(' ')[1] + ' ' + points.previousDirection.split(' ')[2] + ' ' + points.previousDirection.split(' ')[1] + ' ' + points.previousDirection.split(' ')[2] + ' ' + points.previousDirection.split(' ')[1] + ' ' + points.previousDirection.split(' ')[2]
                        + ' L ' + points.previousDirection.split(' ')[1] + ' ' + points.previousDirection.split(' ')[2];
                }
                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 = startPathCommands.length; i < endPathCommands.length; i++) {
                        Eif (endPathCommands.length !== startPathCommands.length) {
                            var lastPointBeforeCurve = void 0;
                            if ((startPathCommands[startPathCommands.length - 1]).split(' ').length === 4 && options.id.indexOf('border') !== -1) {
                                lastPointBeforeCurve = startPathCommands[startPathCommands.length - (options.id.indexOf('border') !== -1 ? 1 : 2)].split(' ').slice(1).join(' ');
                            }
                            else {
                                lastPointBeforeCurve = startPathCommands[startPathCommands.length - (options.id.indexOf('border') !== -1 ? 1 : 2)].split(' ').slice(5).join(' ');
                            }
                            var curveCommand = 'C ' + lastPointBeforeCurve + lastPointBeforeCurve + lastPointBeforeCurve;
                            if (options.id.indexOf('border') !== -1) {
                                startPathCommands.push(curveCommand);
                            }
                            else {
                                startPathCommands.splice(startPathCommands.length - 1, 0, curveCommand);
                            }
                        }
                    }
                    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) {
                            var firstPointBeforeCurve = void 0;
                            if (series.removedPointIndex === series.points.length) {
                                Iif ((startPathCommands[startPathCommands.length - 1]).split(' ').length === 4 && options.id.indexOf('border') !== -1) {
                                    firstPointBeforeCurve = endPathCommands[endPathCommands.length - (options.id.indexOf('border') !== -1 ? 1 : 2)].split(' ').slice(1).join(' ');
                                }
                                else {
                                    firstPointBeforeCurve = endPathCommands[endPathCommands.length - (options.id.indexOf('border') !== -1 ? 1 : 2)].split(' ').slice(5).join(' ');
                                }
                                var curveCommand = 'C ' + firstPointBeforeCurve + firstPointBeforeCurve + firstPointBeforeCurve;
                                if (options.id.indexOf('border') !== -1) {
                                    endPathCommands.push(curveCommand);
                                }
                                else {
                                    endPathCommands.splice(endPathCommands.length - 1, 0, curveCommand);
                                }
                            }
                            else {
                                if ((startPathCommands[startPathCommands.length - 1]).split(' ').length === 4) {
                                    firstPointBeforeCurve = 'C ' + endPathCommands[options.id.indexOf('border') !== -1 ? 0 : 1].split(' ').slice(-3).join(' ') + endPathCommands[options.id.indexOf('border') !== -1 ? 0 : 1].split(' ').slice(1).join(' ') + endPathCommands[options.id.indexOf('border') !== -1 ? 0 : 1].split(' ').slice(1).join(' ');
                                }
                                else {
                                    firstPointBeforeCurve = 'C ' + endPathCommands[options.id.indexOf('border') !== -1 ? 0 : 1].split(' ').slice(-3).join(' ') + endPathCommands[options.id.indexOf('border') !== -1 ? 0 : 1].split(' ').slice(-3).join(' ') + endPathCommands[options.id.indexOf('border') !== -1 ? 0 : 1].split(' ').slice(-3).join(' ');
                                }
                                endPathCommands.splice((options.id.indexOf('border') !== -1 ? 1 : 2), 0, firstPointBeforeCurve);
                            }
                        }
                    }
                    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);
                }
            }
        };
        SplineAreaSeries.prototype.getModuleName = function () {
            return 'SplineAreaSeries';
        };
        SplineAreaSeries.prototype.destroy = function () {
        };
        return SplineAreaSeries;
    }(spline_base_1.SplineBase));
    exports.SplineAreaSeries = SplineAreaSeries;
});