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

100% Statements 113/113
98.78% Branches 81/82
100% Functions 16/16
100% Lines 110/110
9 statements, 5 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        51×   76× 76× 76× 76× 76× 76× 76× 76× 76× 76× 76× 76× 76× 349× 349× 349× 349× 344× 344× 344× 344× 344× 344× 344× 13×   344× 344× 344× 344×   344× 344× 271× 271× 271× 271×   271×   192×     79×   271×       265×       344×     76× 76× 76× 66×   76×   688× 26×   662×   688× 98×   590×   344× 344× 344× 344× 62×   282× 135×     147×   344×   75× 75× 75× 75× 75× 75× 14× 17× 108× 13× 12×       13×         75× 48× 86× 440× 55× 10×     45×   55×         75×     20665×          
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var 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 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", "./column-base"], function (require, exports, helper_1, column_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;
            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 = isInversed ? prevRegion.x + prevRegion.width : prevRegion.y + prevRegion.height;
                        var 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 : currentRegion.y;
                        }
                        else {
                            y = currentBottom;
                        }
                        if (isInversed) {
                            direction = direction.concat('M' + ' ' + y + ' ' + (prevRegion.y + prevRegion.height) + ' ' +
                                'L' + ' ' + y + ' ' + currentRegion.y + ' ');
                        }
                        else {
                            direction = direction.concat('M' + ' ' + prevRegion.x + ' ' + y + ' ' +
                                'L' + ' ' + (currentRegion.x + currentRegion.width) + ' ' + y + ' ');
                        }
                    }
                    prevRegion = point.regions[0];
                }
            }
            var options = new helper_1.PathOption(series.chart.element.id + '_Series_' + series.index + '_Connector_', 'none', series.connector.width, series.connector.color, series.opacity, series.connector.dashArray, direction);
            var element = series.chart.renderer.drawPath(options);
            if (series.chart.animateSeries) {
                element.style.visibility = 'hidden';
            }
            series.seriesElement.appendChild(element);
        };
        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 length = json.length;
            var index;
            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_1.subArraySum(data, -1, intermediateSum[i], null, series);
                            }
                            else {
                                index = helper_1.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_1.subArraySum(data, -1, sumIndex[k], sumIndex, series);
                            }
                            else {
                                index = helper_1.subArraySum(data, -1, sumIndex[k], null, series);
                            }
                            data[j][series.yName] = index;
                        }
                    }
                }
            }
            return data;
        };
        WaterfallSeries.prototype.doAnimation = function (series) {
            this.animate(series);
        };
        WaterfallSeries.prototype.getModuleName = function () {
            return 'WaterfallSeries';
        };
        WaterfallSeries.prototype.destroy = function (chart) {
        };
        return WaterfallSeries;
    }(column_base_1.ColumnBase));
    exports.WaterfallSeries = WaterfallSeries;
});