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

93.88% Statements 138/147
93.38% Branches 127/136
94.44% Functions 17/18
93.75% Lines 135/144
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          57×   82× 82× 82× 82× 82× 82× 82× 82× 82× 82× 82× 82× 82× 82× 373× 373× 373× 373× 368× 368× 368× 368× 368× 368× 368× 19×   368× 368× 368× 368×   368× 368× 289× 289× 289× 289× 289× 289× 289× 289×       283×     283×     289×   206× 206×       83×   289× 12×   12×   12×       277×   277×       368×     82× 82×   82×   82×   82× 82×                               736× 38×   698×   736× 98×   638×   368× 368× 368× 368× 68×   300× 135×     165×   368×   81× 81× 81× 81× 81× 81× 20× 23× 132× 19× 18×       19×         81× 54× 92× 464× 55× 10×     45× 38×         55× 55×         81×   11×   41538×          
/* 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", "../../common/utils/helper", "./column-base", "@syncfusion/ej2-base"], function (require, exports, helper_1, ej2_svg_base_1, helper_2, column_base_1, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var WaterfallSeries = (function (_super) {
        __extends(WaterfallSeries, _super);
        function WaterfallSeries() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        WaterfallSeries.prototype.render = function (series) {
            var rect;
            var sideBySideInfo = this.getSideBySideInfo(series);
            var origin = Math.max(series.yAxis.visibleRange.min, 0);
            var argsData;
            var prevEndValue = 0;
            var direction = '';
            var currentEndValue = 0;
            var originValue;
            var prevRegion = null;
            var y;
            var isInversed = series.chart.requireInvertedAxis;
            var intermediateOrigin = 0;
            var redraw = series.chart.redraw;
            for (var _i = 0, _a = series.points; _i < _a.length; _i++) {
                var point = _a[_i];
                point.symbolLocations = [];
                point.regions = [];
                if (point.visible && helper_1.withInRange(series.points[point.index - 1], point, series.points[point.index + 1], series)) {
                    var isSum = this.isIntermediateSum(series, point.index);
                    var totalSum = this.isSumIndex(series, point.index);
                    currentEndValue += isSum || totalSum === true ? 0 : point.yValue;
                    originValue = (isSum === true ? intermediateOrigin : ((prevEndValue !== null && !totalSum) ? prevEndValue : origin));
                    rect = this.getRectangle(point.xValue + sideBySideInfo.start, currentEndValue, point.xValue + sideBySideInfo.end, originValue, series);
                    argsData = this.triggerPointRenderEvent(series, point);
                    if (isSum) {
                        intermediateOrigin = currentEndValue;
                    }
                    prevEndValue = currentEndValue;
                    Eif (!argsData.cancel) {
                        this.updateSymbolLocation(point, rect, series);
                        this.drawRectangle(series, point, rect, argsData);
                    }
                    var currentRegion = point.regions[0];
                    if (prevRegion !== null) {
                        var prevLeft = isInversed ? prevRegion.x : prevRegion.y;
                        var currentLeft = isInversed ? currentRegion.x : currentRegion.y;
                        var prevBottom = void 0;
                        var currentBottom = void 0;
                        var currentYValue = currentRegion.y;
                        var currentXValue = currentRegion.x;
                        var beforePoint = series.points[(point.index - 1 === -1) ? 1 : point.index - 1];
                        if (point.yValue === 0) {
                            prevBottom = isInversed ? prevRegion.x + prevRegion.width : prevRegion.y + prevRegion.height;
                            currentBottom = isInversed ?
                                point.symbolLocations[0].x : point.symbolLocations[0].y;
                        }
                        else {
                            prevBottom = isInversed ? (beforePoint.yValue === 0) ?
                                beforePoint.symbolLocations[0].x : prevRegion.x + prevRegion.width : (beforePoint.yValue === 0) ?
                                beforePoint.symbolLocations[0].y : prevRegion.y + prevRegion.height;
                            currentBottom = isInversed ?
                                currentRegion.x + currentRegion.width : currentRegion.y + currentRegion.height;
                        }
                        if (Math.round(prevLeft) === Math.round(currentLeft) ||
                            Math.round(prevBottom) === Math.round(currentLeft)) {
                            y = isInversed ? (currentRegion.x === 0 && prevRegion.x === 0) ? currentBottom : currentRegion.x : currentRegion.y;
                            y = (point.yValue === 0) ?
                                (isInversed ? point.symbolLocations[0].x : point.symbolLocations[0].y) : y;
                        }
                        else {
                            y = currentBottom;
                        }
                        if (isInversed) {
                            if (beforePoint.yValue === 0) {
                                prevRegion.y = ((prevRegion.y + prevRegion.height / 2) + (rect.height / 2)) - prevRegion.height;
                            }
                            if (point.yValue === 0) {
                                currentYValue = ((currentRegion.y + currentRegion.height / 2) - (rect.height / 2));
                            }
                            direction = direction.concat('M' + ' ' + y + ' ' + (series.xAxis.isInversed ? (prevRegion.y + prevRegion.height) : prevRegion.y) + ' ' +
                                'L' + ' ' + y + ' ' + (series.xAxis.isInversed ? currentYValue : (currentYValue + currentRegion.height)) + ' ');
                        }
                        else {
                            if (beforePoint.yValue === 0) {
                                prevRegion.x = ((prevRegion.x + prevRegion.width / 2) - (rect.width / 2));
                                currentXValue = ((currentRegion.x + currentRegion.width / 2) + (rect.width / 2)) - currentRegion.width;
                            }
                            direction = direction.concat('M' + ' ' + (series.xAxis.isInversed ? prevRegion.x : (prevRegion.x + prevRegion.width)) + ' ' + y + ' ' +
                                'L' + ' ' + (series.xAxis.isInversed ? (currentXValue + currentRegion.width) : currentXValue) + ' ' + y + ' ');
                        }
                    }
                    prevRegion = point.regions[0];
                }
            }
            var options = new ej2_svg_base_1.PathOption(series.chart.element.id + '_Series_' + series.index + '_Connector_', 'none', series.connector.width, series.connector.color, series.opacity, series.connector.dashArray, direction);
            if (redraw && helper_2.getElement(options.id)) {
                direction = helper_2.getElement(options.id).getAttribute('d');
            }
            var element = (helper_2.redrawElement(redraw, options.id, options, series.chart.renderer) ||
                series.chart.renderer.drawPath(options, new Int32Array([series.clipRect.x, series.clipRect.y])));
            element.style.visibility = (!series.chart.enableCanvas) ? ((((series.animation.enable && ej2_base_1.animationMode !== 'Disable') || ej2_base_1.animationMode === 'Enable') && series.chart.animateSeries) ?
                'hidden' : 'visible') : null;
            helper_2.appendChildElement(series.chart.enableCanvas, series.seriesElement, element, redraw, true, null, null, null, direction, null, null, null, series.chart.duration);
            this.renderMarker(series);
        };
        WaterfallSeries.prototype.updateDirection = function (series, point) {
            this.render(series);
            if (series.marker.visible) {
                helper_2.appendChildElement(series.chart.enableCanvas, series.chart.seriesElements, series.symbolElement, true);
            }
            if (series.marker.dataLabel.visible && series.chart.dataLabelModule) {
                for (var i = 0; i < point.length; i++) {
                    series.chart.dataLabelModule.commonId = series.chart.element.id + '_Series_' + series.index + '_Point_';
                    var dataLabelElement = series.chart.dataLabelModule.renderDataLabel(series, series.points[point[i]], null, series.marker.dataLabel);
                    for (var j = 0; j < dataLabelElement.length; j++) {
                        series.chart.dataLabelModule.doDataLabelAnimation(series, dataLabelElement[j]);
                    }
                }
            }
        };
        WaterfallSeries.prototype.isIntermediateSum = function (series, index) {
            if (series.intermediateSumIndexes !== undefined && series.intermediateSumIndexes.indexOf(index) !== -1) {
                return true;
            }
            return false;
        };
        WaterfallSeries.prototype.isSumIndex = function (series, index) {
            if (series.sumIndexes !== undefined && series.sumIndexes.indexOf(index) !== -1) {
                return true;
            }
            return false;
        };
        WaterfallSeries.prototype.triggerPointRenderEvent = function (series, point) {
            var color;
            var isSum = this.isIntermediateSum(series, point.index);
            var totalSum = this.isSumIndex(series, point.index);
            if (isSum || totalSum) {
                color = series.summaryFillColor;
            }
            else if (point.y < 0) {
                color = series.negativeFillColor;
            }
            else {
                color = series.interior;
            }
            return this.triggerEvent(series, point, color, { color: series.border.color, width: series.border.width });
        };
        WaterfallSeries.prototype.processInternalData = function (json, series) {
            var data = json;
            var index;
            var sumValue = 0;
            var intermediateSum = series.intermediateSumIndexes;
            var sumIndex = series.sumIndexes;
            if (intermediateSum !== undefined && intermediateSum.length > 0) {
                for (var i = 0; i < intermediateSum.length; i++) {
                    for (var j = 0; j < data.length; j++) {
                        if (j === intermediateSum[i]) {
                            if (i === 0) {
                                index = helper_2.subArraySum(data, -1, intermediateSum[i], null, series);
                            }
                            else {
                                index = helper_2.subArraySum(data, intermediateSum[i - 1], intermediateSum[i], null, series);
                            }
                            data[j][series.yName] = index;
                        }
                    }
                }
            }
            if (sumIndex !== undefined && sumIndex.length > 0) {
                for (var k = 0; k < sumIndex.length; k++) {
                    for (var j = 0; j < data.length; j++) {
                        if (j === sumIndex[k]) {
                            if (intermediateSum !== undefined) {
                                index = helper_2.subArraySum(data, intermediateSum[k] - 1, sumIndex[k], sumIndex, series);
                            }
                            else {
                                if (k === 0) {
                                    index = helper_2.subArraySum(data, -1, sumIndex[k], null, series);
                                }
                                else {
                                    index = helper_2.subArraySum(data, sumIndex[k - 1], sumIndex[k], null, series);
                                }
                            }
                            sumValue += index;
                            data[j][series.yName] = sumValue;
                        }
                    }
                }
            }
            return data;
        };
        WaterfallSeries.prototype.doAnimation = function (series) {
            this.animate(series);
        };
        WaterfallSeries.prototype.getModuleName = function () {
            return 'WaterfallSeries';
        };
        WaterfallSeries.prototype.destroy = function () {
        };
        return WaterfallSeries;
    }(column_base_1.ColumnBase));
    exports.WaterfallSeries = WaterfallSeries;
});