all files / chart/series/ column-base.js

99.32% Statements 145/146
96.88% Branches 93/96
100% Functions 19/19
99.32% Lines 145/146
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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243     2132× 1581×   2132× 2132× 2132× 2132× 2132× 2132×   2132× 2132× 2132× 2132× 2132× 2132× 2132× 2132× 2132×   2132×   21401× 21401× 21401×   1581× 1581× 1581× 1778× 1778× 2149× 2149×       2149× 2149× 2149× 3451× 1316× 182× 112× 112×     70×       1134× 484× 484×     650×         2135×     2149× 3451×     18592× 15688×     2904×   18592× 128× 128×     15688× 15688×           2904× 2904×           14982×         14982× 14982× 14982×   9942× 9942×     9942× 9942×   9942× 9942× 9942×   8343× 8343×   1599× 1599×   9942×   100× 100× 100× 960× 960× 83×   877× 877×     877× 877× 877× 877× 877× 877× 877× 877× 877× 877× 806× 806× 75× 75× 75×     731× 731×   731×       71× 71× 31× 31× 31×     40× 40× 40×       877× 877× 877×       45427× 44704× 44704× 40783× 40783× 40783×       3921× 3921× 3921×           877× 877× 877×   100× 100× 44×               9942×                          
define(["require", "exports", "@syncfusion/ej2-base", "../utils/double-range", "../../common/utils/helper", "../../common/utils/helper", "../../common/model/constants"], function (require, exports, ej2_base_1, double_range_1, helper_1, helper_2, constants_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ColumnBase = (function () {
        function ColumnBase() {
        }
        ColumnBase.prototype.getSideBySideInfo = function (series) {
            if (series.chart.enableSideBySidePlacement && !series.position) {
                this.getSideBySidePositions(series);
            }
            var position = !series.chart.enableSideBySidePlacement ? 0 : series.position;
            var rectCount = !series.chart.enableSideBySidePlacement ? 1 : series.rectCount;
            series.isRectSeries = true;
            var visibleSeries = series.chart.visibleSeries;
            var seriesSpacing = series.chart.enableSideBySidePlacement ? series.columnSpacing : 0;
            var pointSpacing = (series.columnWidth === null) ? ((series.type === 'Histogram') ? 1 : 0.7) :
                series.columnWidth;
            var minimumPointDelta = helper_1.getMinPointsDelta(series.xAxis, visibleSeries);
            var width = minimumPointDelta * pointSpacing;
            var radius;
            var location = (position) / rectCount - 0.5;
            var doubleRange = new double_range_1.DoubleRange(location, location + (1 / rectCount));
            Eif (!(isNaN(doubleRange.start) || isNaN(doubleRange.end))) {
                doubleRange = new double_range_1.DoubleRange(doubleRange.start * width, doubleRange.end * width);
                radius = seriesSpacing * doubleRange.delta;
                doubleRange = new double_range_1.DoubleRange(doubleRange.start + radius / 2, doubleRange.end - radius / 2);
            }
            return doubleRange;
        };
        ColumnBase.prototype.getRectangle = function (x1, y1, x2, y2, series) {
            var point1 = helper_2.getPoint(x1, y1, series.xAxis, series.yAxis, series.chart.requireInvertedAxis);
            var point2 = helper_2.getPoint(x2, y2, series.xAxis, series.yAxis, series.chart.requireInvertedAxis);
            return new helper_1.Rect(Math.min(point1.x, point2.x), Math.min(point1.y, point2.y), Math.abs(point2.x - point1.x), Math.abs(point2.y - point1.y));
        };
        ColumnBase.prototype.getSideBySidePositions = function (series) {
            var chart = series.chart;
            var seriesCollection = [];
            for (var _i = 0, _a = chart.columns; _i < _a.length; _i++) {
                var columnItem = _a[_i];
                for (var _b = 0, _c = chart.rows; _b < _c.length; _b++) {
                    var item = _c[_b];
                    this.findRectPosition(series.findSeriesCollection(columnItem, item, false));
                }
            }
        };
        ColumnBase.prototype.findRectPosition = function (seriesCollection) {
            var stackingGroup = [];
            var vSeries = { rectCount: 0, position: null };
            seriesCollection.forEach(function (value) {
                if (value.type.indexOf('Stacking') !== -1) {
                    if (value.stackingGroup) {
                        if (stackingGroup[value.stackingGroup] === undefined) {
                            value.position = vSeries.rectCount;
                            stackingGroup[value.stackingGroup] = vSeries.rectCount++;
                        }
                        else {
                            value.position = stackingGroup[value.stackingGroup];
                        }
                    }
                    else {
                        if (vSeries.position === null) {
                            value.position = vSeries.rectCount;
                            vSeries.position = vSeries.rectCount++;
                        }
                        else {
                            value.position = vSeries.position;
                        }
                    }
                }
                else {
                    value.position = vSeries.rectCount++;
                }
            });
            seriesCollection.forEach(function (value) {
                value.rectCount = vSeries.rectCount;
            });
        };
        ColumnBase.prototype.updateSymbolLocation = function (point, rect, series) {
            if (!series.chart.requireInvertedAxis) {
                this.updateXRegion(point, rect, series);
            }
            else {
                this.updateYRegion(point, rect, series);
            }
            if (series.type === 'Histogram') {
                point.minimum = +point.x - series.histogramValues.binWidth / 2;
                point.maximum = +point.x + series.histogramValues.binWidth / 2;
            }
        };
        ColumnBase.prototype.updateXRegion = function (point, rect, series) {
            point.regions.push(rect);
            point.symbolLocations.push({
                x: rect.x + (rect.width) / 2,
                y: (series.seriesType === 'BoxPlot' || series.seriesType.indexOf('HighLow') !== -1 ||
                    (point.yValue >= 0 === !series.yAxis.isInversed)) ? rect.y : (rect.y + rect.height)
            });
        };
        ColumnBase.prototype.updateYRegion = function (point, rect, series) {
            point.regions.push(rect);
            point.symbolLocations.push({
                x: (series.seriesType === 'BoxPlot' || series.seriesType.indexOf('HighLow') !== -1 ||
                    (point.yValue >= 0 === !series.yAxis.isInversed)) ? rect.x + rect.width : rect.x,
                y: rect.y + rect.height / 2
            });
        };
        ColumnBase.prototype.triggerEvent = function (series, point, fill, border) {
            var argsData = {
                cancel: false, name: constants_1.pointRender, series: series, point: point,
                fill: series.setPointColor(point, fill),
                border: series.setBorderColor(point, border)
            };
            series.chart.trigger(constants_1.pointRender, argsData);
            point.color = argsData.fill;
            return argsData;
        };
        ColumnBase.prototype.drawRectangle = function (series, point, rect, argsData) {
            var check = series.chart.requireInvertedAxis ? rect.height : rect.width;
            Iif (check <= 0) {
                return null;
            }
            var direction = this.calculateRoundedRectPath(rect, series.cornerRadius.topLeft, series.cornerRadius.topRight, series.cornerRadius.bottomLeft, series.cornerRadius.bottomRight);
            var name = series.category === 'Indicator' ? series.chart.element.id + '_Indicator_' + series.index + '_' + series.name +
                '_Point_' + point.index : series.chart.element.id + '_Series_' + series.index + '_Point_' + point.index;
            var options = new helper_1.PathOption(name, argsData.fill, argsData.border.width, argsData.border.color, series.opacity, series.dashArray, direction);
            var element = series.chart.renderer.drawPath(options);
            switch (series.seriesType) {
                case 'XY':
                    element.setAttribute('aria-label', point.x.toString() + ':' + point.yValue.toString());
                    break;
                case 'HighLow':
                    element.setAttribute('aria-label', point.x.toString() + ':' + point.high.toString() + ':' + point.low.toString());
                    break;
            }
            series.seriesElement.appendChild(element);
        };
        ColumnBase.prototype.animate = function (series) {
            var rectElements = series.seriesElement.childNodes;
            var count = series.category === 'Indicator' ? 0 : 1;
            for (var _i = 0, _a = series.points; _i < _a.length; _i++) {
                var point = _a[_i];
                if (!point.symbolLocations.length && !(series.type === 'BoxAndWhisker' && point.regions.length)) {
                    continue;
                }
                this.animateRect(rectElements[count], series, point);
                count++;
            }
        };
        ColumnBase.prototype.animateRect = function (element, series, point) {
            var option = series.animation;
            var effect = helper_2.getAnimationFunction('Linear');
            var isPlot = point.yValue < 0;
            var x;
            var y;
            var elementHeight = +point.regions[0].height;
            var elementWidth = +point.regions[0].width;
            var centerX;
            var centerY;
            if (!series.chart.requireInvertedAxis) {
                x = +point.regions[0].x;
                if (series.type.indexOf('Stacking') > -1) {
                    y = (1 - helper_1.valueToCoefficient(0, series.yAxis)) * (series.yAxis.rect.height);
                    centerX = x;
                    centerY = y;
                }
                else {
                    y = +point.regions[0].y;
                    centerY = (series.seriesType.indexOf('HighLow') !== -1 || series.type.indexOf('Waterfall') !== -1) ? y + elementHeight / 2 :
                        (isPlot !== series.yAxis.isInversed) ? y : y + elementHeight;
                    centerX = isPlot ? x : x + elementWidth;
                }
            }
            else {
                y = +point.regions[0].y;
                if (series.type.indexOf('Stacking') > -1) {
                    x = (helper_1.valueToCoefficient(0, series.yAxis)) * series.yAxis.rect.width;
                    centerX = x;
                    centerY = y;
                }
                else {
                    x = +point.regions[0].x;
                    centerY = isPlot ? y : y + elementHeight;
                    centerX = (series.seriesType.indexOf('HighLow') !== -1 || series.type.indexOf('Waterfall') !== -1) ? x + elementWidth / 2 :
                        (isPlot !== series.yAxis.isInversed) ? x + elementWidth : x;
                }
            }
            var value;
            element.style.visibility = 'hidden';
            new ej2_base_1.Animation({}).animate(element, {
                duration: option.duration,
                delay: option.delay,
                progress: function (args) {
                    if (args.timeStamp >= args.delay) {
                        element.style.visibility = 'visible';
                        if (!series.chart.requireInvertedAxis) {
                            elementHeight = elementHeight ? elementHeight : 1;
                            value = effect(args.timeStamp - args.delay, 0, elementHeight, args.duration);
                            element.setAttribute('transform', 'translate(' + centerX + ' ' + centerY +
                                ') scale(1,' + (value / elementHeight) + ') translate(' + (-centerX) + ' ' + (-centerY) + ')');
                        }
                        else {
                            elementWidth = elementWidth ? elementWidth : 1;
                            value = effect(args.timeStamp - args.delay, 0, elementWidth, args.duration);
                            element.setAttribute('transform', 'translate(' + centerX + ' ' + centerY +
                                ') scale(' + (value / elementWidth) + ', 1) translate(' + (-centerX) + ' ' + (-centerY) + ')');
                        }
                    }
                },
                end: function (model) {
                    element.setAttribute('transform', 'translate(0,0)');
                    var seriesElement = series.seriesElement;
                    if (element === seriesElement.lastElementChild || point.index === series.points.length - 1 ||
                        (series.type === 'Waterfall' && element === seriesElement.children[seriesElement.childElementCount - 2])) {
                        series.chart.trigger('animationComplete', { series: series });
                        if (series.type === 'Waterfall') {
                            var rectElements = seriesElement.childNodes;
                            for (var i = 0; i < rectElements.length; i++) {
                                if (rectElements[i].id.indexOf('Connector') !== -1) {
                                    rectElements[i].style.visibility = 'visible';
                                    rectElements[i].setAttribute('transform', 'translate(0,0)');
                                }
                            }
                        }
                    }
                }
            });
        };
        ColumnBase.prototype.calculateRoundedRectPath = function (rect, topLeft, topRight, bottomLeft, bottomRight) {
            return 'M' + ' ' + rect.x + ' ' + (topLeft + rect.y) +
                ' Q ' + rect.x + ' ' + rect.y + ' ' + (rect.x + topLeft) + ' ' +
                rect.y + ' ' + 'L' + ' ' + (rect.x + rect.width - topRight) + ' ' + rect.y +
                ' Q ' + (rect.x + rect.width) + ' ' + rect.y + ' ' +
                (rect.x + rect.width) + ' ' + (rect.y + topRight) + ' ' + 'L ' +
                (rect.x + rect.width) + ' ' + (rect.y + rect.height - bottomRight)
                + ' Q ' + (rect.x + rect.width) + ' ' + (rect.y + rect.height) + ' ' + (rect.x + rect.width - bottomRight) + ' ' +
                (rect.y + rect.height) + ' ' + 'L ' + (rect.x + bottomLeft) + ' ' + (rect.y + rect.height) + ' Q ' + rect.x + ' ' +
                (rect.y + rect.height) + ' ' + rect.x + ' ' + (rect.y + rect.height - bottomLeft) + ' ' + 'L' + ' ' + rect.x + ' ' +
                (topLeft + rect.y) + ' ' + 'Z';
        };
        return ColumnBase;
    }());
    exports.ColumnBase = ColumnBase;
});