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

98.96% Statements 95/96
94.29% Branches 66/70
100% Functions 19/19
98.92% Lines 92/93
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          434× 434× 434×   567× 567× 567× 9982× 9982×     9984× 9984× 9984× 9984× 9984× 9984× 9558× 9558× 9555× 9555×       9558× 9558× 9558× 9558× 9558× 9558× 9558×             9558× 9558× 9558×   9558× 9558× 8971× 442×     8529×         587×       9558× 9558×   9558×     9558×           9558×         9558×   9558× 9558×     9558×   9558× 9558× 9558× 9558× 9558× 9558×   9558× 9558×   9558× 9558×   9558×   106×   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", "./column-base"], function (require, exports, helper_1, ej2_svg_base_1, column_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var CandleSeries = (function (_super) {
        __extends(CandleSeries, _super);
        function CandleSeries() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.sideBySideInfo = [];
            return _this;
        }
        CandleSeries.prototype.render = function (series) {
            this.sideBySideInfo[series.index] = this.getSideBySideInfo(series);
            var borderWidth = Math.max(series.border.width, 1);
            for (var _i = 0, _a = series.points; _i < _a.length; _i++) {
                var point = _a[_i];
                this.renderPoint(series, point, this.sideBySideInfo[series.index], borderWidth);
            }
        };
        CandleSeries.prototype.renderPoint = function (series, point, sideBySideInfo, borderWidth) {
            var direction = '';
            var centerRegion;
            var tickRegion;
            point.regions = [];
            point.symbolLocations = [];
            if (point.visible && helper_1.withInRange(series.points[point.index - 1], point, series.points[point.index + 1], series)) {
                tickRegion = this.getRectangle((point.xValue + sideBySideInfo.median), Math.max(point.high, point.low), (point.xValue + sideBySideInfo.median), Math.min(point.high, point.low), series);
                if (!series.chart.requireInvertedAxis) {
                    tickRegion.x -= borderWidth / 2;
                    tickRegion.width = borderWidth;
                }
                else {
                    tickRegion.y -= borderWidth / 2;
                    tickRegion.height = borderWidth;
                }
                centerRegion = this.getRectangle((point.xValue + sideBySideInfo.start), Math.max(point.open, point.close), (point.xValue + sideBySideInfo.end), Math.min(point.open, point.close), series);
                direction = this.getPathString(tickRegion, centerRegion, series);
                var argsData = this.triggerPointRenderEvent(series, point);
                Eif (!argsData.cancel) {
                    this.drawCandle(series, point, centerRegion, argsData, direction);
                    this.updateSymbolLocation(point, tickRegion, series);
                    this.updateSymbolLocation(point, centerRegion, series);
                }
            }
        };
        CandleSeries.prototype.updateDirection = function (series, point) {
            var borderWidth = Math.max(series.border.width, 1);
            for (var i = 0; i < point.length; i++) {
                this.renderPoint(series, series.points[point[i]], this.sideBySideInfo[series.index], borderWidth);
                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);
                }
            }
        };
        CandleSeries.prototype.triggerPointRenderEvent = function (series, point) {
            var fill = this.getCandleColor(point, series);
            var border = { color: series.border.color, width: Math.max(series.border.width, 1) };
            return this.triggerEvent(series, point, fill, border);
        };
        CandleSeries.prototype.getCandleColor = function (point, series) {
            var previousPoint = series.points[point.index - 1];
            if (series.enableSolidCandles === false) {
                if (!previousPoint) {
                    return series.bearFillColor || series.chart.themeStyle.bearFillColor;
                }
                else {
                    return previousPoint.close > point.close ? series.bullFillColor
                        || series.chart.themeStyle.bullFillColor : series.bearFillColor || series.chart.themeStyle.bearFillColor;
                }
            }
            else {
                return point.open > point.close ? series.bullFillColor || series.chart.themeStyle.bullFillColor :
                    series.bearFillColor || series.chart.themeStyle.bearFillColor;
            }
        };
        CandleSeries.prototype.getPathString = function (topRect, midRect, series) {
            var direction = '';
            var center = series.chart.requireInvertedAxis ? topRect.y + topRect.height / 2 :
                topRect.x + topRect.width / 2;
            direction += !series.chart.requireInvertedAxis ?
                'M' + ' ' + (center) + ' ' + (topRect.y) + ' ' + 'L' + ' ' + (center) + ' ' + midRect.y :
                'M' + ' ' + (topRect.x) + ' ' + (center) + ' ' + 'L' + ' ' + (midRect.x) + ' ' + center;
            direction = direction.concat(' M' + ' ' + (midRect.x) + ' ' + (midRect.y) + ' ' +
                'L' + ' ' + (midRect.x + midRect.width) + ' ' + (midRect.y) + ' ' +
                'L' + ' ' + (midRect.x + midRect.width) + ' ' +
                (midRect.y + midRect.height) + ' ' +
                'L' + ' ' + (midRect.x) + ' ' + (midRect.y + midRect.height) +
                ' ' + 'Z');
            direction += !series.chart.requireInvertedAxis ?
                ' M' + ' ' + (center) + ' ' + (midRect.y + midRect.height) + ' ' + 'L' + ' ' + (center) + ' ' + (topRect.y +
                    topRect.height) :
                ' M' + ' ' + (midRect.x + midRect.width) + ' ' + (center) + ' ' + 'L' + ' ' +
                    (topRect.x + topRect.width) + ' ' + center;
            return direction;
        };
        CandleSeries.prototype.drawCandle = function (series, point, rect, argsData, direction) {
            var check = series.chart.requireInvertedAxis ? rect.height : rect.width;
            Iif (check <= 0) {
                return null;
            }
            var fill = !series.enableSolidCandles ?
                (point.open > point.close ? argsData.fill : 'transparent') : argsData.fill;
            argsData.border.color = argsData.fill;
            var options = new ej2_svg_base_1.PathOption(series.chart.element.id + '_Series_' + series.index + '_Point_' + ((series.removedPointIndex !== null && series.removedPointIndex <= point.index) ? (point.index + 1) : point.index), fill, argsData.border.width, argsData.border.color, series.opacity, series.dashArray, direction);
            var element = helper_1.getElement(options.id);
            var previousDirection = element ? element.getAttribute('d') : null;
            var candleElement = series.chart.renderer.drawPath(options, new Int32Array([series.clipRect.x, series.clipRect.y]));
            if (series.removedPointIndex !== null && series.removedPointIndex <= point.index) {
                candleElement.id = series.chart.element.id + '_Series_' + series.index + '_Point_' + point.index;
            }
            candleElement.setAttribute('role', 'img');
            candleElement.setAttribute('aria-label', point.x.toString() + ':' + point.high.toString()
                + ':' + point.low.toString() + ':' + point.close.toString() + ':' + point.open.toString());
            Eif (!series.chart.enableCanvas) {
                series.seriesElement.appendChild(candleElement);
            }
            helper_1.pathAnimation(element, direction, series.chart.redraw, previousDirection, series.chart.duration);
        };
        CandleSeries.prototype.doAnimation = function (series) {
            this.animate(series);
        };
        CandleSeries.prototype.getModuleName = function () {
            return 'CandleSeries';
        };
        CandleSeries.prototype.destroy = function () {
        };
        return CandleSeries;
    }(column_base_1.ColumnBase));
    exports.CandleSeries = CandleSeries;
});