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

95.68% Statements 133/139
88% Branches 110/125
100% Functions 17/17
95.59% Lines 130/136
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          86×   285× 285× 285× 285× 285× 285× 285× 285× 285×     285× 285× 285× 285× 285× 285× 285×   285× 285× 285× 285× 263× 263×     285× 2055× 2055× 2055× 2055× 1964×     1964×   1964× 1964× 1964×     91× 82× 244× 244× 244×   82×   76× 76× 76×   82×       285× 16× 16× 16× 16× 16× 16×       285× 273× 1638× 1638×     1638× 1638× 1634×     1634× 34×   1634×         285× 285× 285× 79× 79× 79×   285× 262×                 10× 10× 10× 10× 10× 10× 10×               10× 27× 17× 17×               10× 10×     41538×   1638× 1638× 3608× 861×     777×   17× 17× 17× 17×              
/* 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", "./line-base"], function (require, exports, helper_1, ej2_svg_base_1, line_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var StackingAreaSeries = (function (_super) {
        __extends(StackingAreaSeries, _super);
        function StackingAreaSeries() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        StackingAreaSeries.prototype.render = function (series, xAxis, yAxis, isInverted, pointAnimate, pointUpdate) {
            var polarAreaType = series.chart.chartAreaType === 'PolarRadar';
            var getCoordinate = polarAreaType ? helper_1.TransformToVisible : helper_1.getPoint;
            var lineDirection = '';
            var visiblePoints = this.enableComplexProperty(series);
            var pointsLength = visiblePoints.length;
            var stackedvalue = series.stackedValues;
            var pointIndex;
            var nextPointIndex;
            var origin = polarAreaType ?
                Math.max(series.yAxis.visibleRange.min, stackedvalue.endValues[0]) :
                Math.max(series.yAxis.visibleRange.min, stackedvalue.startValues[0]);
            var startPoint = 0;
            var point1;
            var point2;
            var emptyPointDirection = '';
            Eif (pointsLength > 0) {
                point1 = getCoordinate(visiblePoints[0].xValue, origin, xAxis, yAxis, isInverted, series);
                lineDirection = lineDirection.concat('M' + ' ' + (point1.x) + ' ' + (point1.y) + ' ');
            }
            var isPolar = (series.chart && series.chart.chartAreaType === 'PolarRadar');
            var index;
            for (var i = series.index; i >= 0; i--) {
                if (series.chart.visibleSeries[i].visible) {
                    index = series.chart.visibleSeries[i].index;
                    break;
                }
            }
            for (var i = 0; i < pointsLength; i++) {
                pointIndex = visiblePoints[i].index;
                visiblePoints[i].symbolLocations = [];
                visiblePoints[i].regions = [];
                if (visiblePoints[i].visible && helper_1.withInRange(visiblePoints[i - 1], visiblePoints[i], visiblePoints[i + 1], series)) {
                    var startvalue = series.index > 0 && index !== undefined ?
                        this.chart.visibleSeries[index].stackedValues.endValues[pointIndex] :
                        stackedvalue.startValues[pointIndex];
                    point1 = getCoordinate(visiblePoints[i].xValue, (!series.visible && series.isLegendClicked) ? startvalue :
                        stackedvalue.endValues[pointIndex], xAxis, yAxis, isInverted, series);
                    lineDirection = lineDirection.concat('L' + ' ' + (point1.x) + ' ' + (point1.y) + ' ');
                    visiblePoints[i].symbolLocations.push(getCoordinate(visiblePoints[i].xValue, stackedvalue.endValues[pointIndex], xAxis, yAxis, isInverted, series));
                    visiblePoints[i].regions.push(new ej2_svg_base_1.Rect(visiblePoints[i].symbolLocations[0].x - series.marker.width, visiblePoints[i].symbolLocations[0].y - series.marker.height, 2 * series.marker.width, 2 * series.marker.height));
                }
                else {
                    if (!isPolar && series.emptyPointSettings.mode !== 'Drop') {
                        for (var j = i - 1; j >= startPoint; j--) {
                            pointIndex = visiblePoints[j].index;
                            point2 = getCoordinate(visiblePoints[j].xValue, stackedvalue.startValues[pointIndex], xAxis, yAxis, isInverted, series);
                            lineDirection = lineDirection.concat('L' + ' ' + (point2.x) + ' ' + (point2.y) + ' ');
                        }
                        if (visiblePoints[i + 1] && (visiblePoints[i + 1].visible &&
                            (!isPolar || (isPolar && this.withinYRange(visiblePoints[i + 1], yAxis))))) {
                            nextPointIndex = visiblePoints[i + 1].index;
                            point1 = getCoordinate(visiblePoints[i + 1].xValue, stackedvalue.startValues[nextPointIndex], xAxis, yAxis, isInverted, series);
                            lineDirection = lineDirection.concat('M' + ' ' + (point1.x) + ' ' + (point1.y) + ' ');
                        }
                        startPoint = i + 1;
                    }
                }
            }
            if (series.chart.chartAreaType === 'PolarRadar' && visiblePoints.length > 1) {
                var connectPoints = this.getFirstLastVisiblePoint(series.points);
                var chart = this.chart;
                point1 = { 'x': connectPoints.first.xValue, 'y': stackedvalue.endValues[connectPoints.first.index] };
                point2 = getCoordinate(point1.x, point1.y, xAxis, yAxis, isInverted, series);
                lineDirection += ('L' + ' ' + (point2.x) + ' ' + (point2.y) + ' ');
                if (this.chart.visible === 1 && (xAxis.isAxisInverse || yAxis.isAxisInverse)) {
                    this.chart.enableAnimation = false;
                    lineDirection = (series.type === 'Polar' ? chart.polarSeriesModule.getPolarIsInversedPath(xAxis, lineDirection) :
                        chart.radarSeriesModule.getRadarIsInversedPath(xAxis, lineDirection));
                }
            }
            if (!isPolar || (isPolar && series.index !== this.getFirstSeriesIndex(series.chart.visibleSeries))) {
                for (var j = pointsLength - 1; j >= startPoint; j--) {
                    pointIndex = visiblePoints[j].index;
                    Iif (isPolar && !visiblePoints[j].visible) {
                        continue;
                    }
                    var previousSeries = this.getPreviousSeries(series);
                    if (previousSeries.emptyPointSettings.mode !== 'Drop' || !previousSeries.points[j].isEmpty) {
                        point2 = getCoordinate(visiblePoints[j].xValue, (!series.visible && series.isLegendClicked && series.index > 0
                            && index !== undefined) ? this.chart.visibleSeries[index].stackedValues.endValues[pointIndex]
                            : stackedvalue.startValues[pointIndex], xAxis, yAxis, isInverted, series);
                        if (stackedvalue.startValues[pointIndex] === stackedvalue.endValues[pointIndex]) {
                            point2.y = Math.floor(point2.y);
                        }
                        lineDirection = lineDirection.concat(((j === (pointsLength - 1) && polarAreaType) ? 'M' : 'L')
                            + ' ' + (point2.x) + ' ' + (point2.y) + ' ');
                    }
                }
            }
            var options = new ej2_svg_base_1.PathOption(series.chart.element.id + '_Series_' + series.index, series.interior, 0, 'transparent', series.opacity, series.dashArray, lineDirection);
            this[pointAnimate ? 'addAreaPath' : 'appendLinePath'](options, series, '');
            if (series.border.width !== 0 && series.visible) {
                emptyPointDirection = this.removeEmptyPointsBorder(this.getBorderDirection(lineDirection));
                var options_1 = new ej2_svg_base_1.PathOption(series.chart.element.id + '_Series_border_' + series.index, 'transparent', series.visible ? series.border.width : 0, series.border.color ? series.border.color : series.interior, 1, series.border.dashArray, emptyPointDirection);
                this[pointAnimate ? 'addAreaPath' : 'appendLinePath'](options_1, series, '');
            }
            if (!pointUpdate && series.visible) {
                this.renderMarker(series);
            }
        };
        StackingAreaSeries.prototype.updateDirection = function (series, point) {
            for (var i = 0; i < series.xAxis.series.length; i++) {
                var stackSeries = series.xAxis.series[i];
                this.render(stackSeries, stackSeries.xAxis, stackSeries.yAxis, stackSeries.chart.requireInvertedAxis, false, true);
                for (var j = 0; j < point.length; j++) {
                    Eif (stackSeries.marker && stackSeries.marker.visible) {
                        stackSeries.chart.markerRender.renderMarker(stackSeries, stackSeries.points[point[j]], stackSeries.points[point[j]].symbolLocations[0], null, true);
                    }
                    Eif (stackSeries.marker.dataLabel.visible && stackSeries.chart.dataLabelModule) {
                        stackSeries.chart.dataLabelModule.commonId = stackSeries.chart.element.id + '_Series_' + stackSeries.index + '_Point_';
                        stackSeries.chart.dataLabelModule.
                            renderDataLabel(stackSeries, stackSeries.points[point[j]], null, stackSeries.marker.dataLabel);
                    }
                }
            }
        };
        StackingAreaSeries.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);
                Iif (startPathCommands.length < endPathCommands.length) {
                    for (var i = startPathCommands.length; i < endPathCommands.length; i++) {
                        if (endPathCommands.length !== startPathCommands.length) {
                            startPathCommands.splice((startPathCommands.length + 1) / 2, 0, startPathCommands.slice((startPathCommands.length - 1) / 2)[0], startPathCommands.slice((startPathCommands.length - 1) / 2)[1]);
                        }
                    }
                    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++) {
                        if (endPathCommands.length !== startPathCommands.length) {
                            endPathCommands.splice(1, 0, endPathCommands[1]);
                            endPathCommands.splice(endPathCommands.length - 1, 0, endPathCommands[endPathCommands.length - 1]);
                        }
                    }
                    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);
                }
            }
        };
        StackingAreaSeries.prototype.doAnimation = function (series) {
            var option = series.animation;
            this.doLinearAnimation(series, option);
        };
        StackingAreaSeries.prototype.destroy = function () {
        };
        StackingAreaSeries.prototype.getModuleName = function () {
            return 'StackingAreaSeries';
        };
        StackingAreaSeries.prototype.getPreviousSeries = function (series) {
            var seriesCollection = series.chart.visibleSeries;
            for (var i = 0, length_1 = seriesCollection.length; i < length_1; i++) {
                if (series.index === seriesCollection[i].index && i !== 0) {
                    return seriesCollection[i - 1];
                }
            }
            return seriesCollection[0];
        };
        StackingAreaSeries.prototype.getFirstSeriesIndex = function (seriesCollection) {
            for (var _i = 0, seriesCollection_1 = seriesCollection; _i < seriesCollection_1.length; _i++) {
                var series = seriesCollection_1[_i];
                Eif (series.visible) {
                    return series.index;
                }
            }
            return 0;
        };
        return StackingAreaSeries;
    }(line_base_1.LineBase));
    exports.StackingAreaSeries = StackingAreaSeries;
});