all files / chart/technical-indicators/ indicator-base.js

100% Statements 108/108
93.33% Branches 42/45
100% Functions 15/15
100% Lines 103/103
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          596×   543× 543× 543×   1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221× 1221×   608× 576×   608× 608× 576×   608×       608× 608×         608× 608×   608× 1214× 1214× 1214×       1214× 1214×   1214×   608× 608×     36651× 36651× 36651× 36651× 36651× 36651× 36651× 36651× 36651× 36651× 36651× 36651× 36651× 36651× 36651× 177× 44×     133×     36651×   2097× 2097× 2097× 2097× 2097× 2097× 2097× 2097× 2097× 2097×   1135× 1135× 286×     849×          
/* 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", "../series/line-base", "../series/chart-series", "../../common/utils/helper", "../../common/utils/helper", "@syncfusion/ej2-svg-base"], function (require, exports, line_base_1, chart_series_1, helper_1, helper_2, ej2_svg_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var TechnicalAnalysis = (function (_super) {
        __extends(TechnicalAnalysis, _super);
        function TechnicalAnalysis() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        TechnicalAnalysis.prototype.initSeriesCollection = function (indicator, chart) {
            indicator.targetSeries = [];
            var signalLine = new chart_series_1.Series(indicator, 'targetSeries', {}, true);
            this.setSeriesProperties(signalLine, indicator, indicator.type, indicator.fill, indicator.width, chart);
        };
        TechnicalAnalysis.prototype.setSeriesProperties = function (series, indicator, name, fill, width, chart) {
            series.name = name.length <= 4 ? name.toLocaleUpperCase() : name;
            series.xName = 'x';
            series.yName = 'y';
            series.fill = fill || '#606eff';
            series.dashArray = indicator.dashArray;
            series.width = width;
            series.xAxisName = indicator.xAxisName;
            series.animation = indicator.animation;
            series.yAxisName = indicator.yAxisName;
            series.clipRectElement = indicator.clipRectElement;
            series.points = [];
            series.enableTooltip = true;
            series.interior = series.fill;
            series.category = 'Indicator';
            series.index = indicator.index;
            series.chart = chart;
            series.xMin = Infinity;
            series.xMax = -Infinity;
            series.yMin = Infinity;
            series.yMax = -Infinity;
            series.xData = [];
            series.yData = [];
            series.marker.visible = false;
            indicator.targetSeries.push(series);
        };
        TechnicalAnalysis.prototype.createIndicatorElements = function (chart, indicator, index) {
            if (indicator.seriesName || indicator.dataSource) {
                helper_2.findClipRect(indicator.targetSeries[0]);
            }
            var clipRect = new ej2_svg_base_1.Rect(0, 0, 0, 0);
            if (indicator.seriesName || indicator.dataSource) {
                clipRect = indicator.targetSeries[0].clipRect;
            }
            var options = new helper_1.RectOption(chart.element.id + '_ChartIndicatorClipRect_' + index, 'transparent', { width: 1, color: 'Gray' }, 1, {
                x: 0, y: 0, width: clipRect.width,
                height: clipRect.height
            });
            var clipRectElement = helper_1.appendClipElement(chart.redraw, options, chart.renderer);
            indicator.indicatorElement = chart.renderer.createGroup({
                'id': chart.element.id + 'IndicatorGroup' + index,
                'transform': 'translate(' + clipRect.x + ',' + clipRect.y + ')',
                'clip-path': 'url(#' + chart.element.id + '_ChartIndicatorClipRect_' + index + ')'
            });
            Eif (indicator.indicatorElement) {
                indicator.indicatorElement.appendChild(clipRectElement);
            }
            for (var _i = 0, _a = indicator.targetSeries; _i < _a.length; _i++) {
                var series = _a[_i];
                series.clipRectElement = clipRectElement;
                var element = series.chart.renderer.createGroup({
                    'id': series.chart.element.id + '_Indicator_' +
                        indicator.index + '_' + series.name + '_Group'
                });
                Eif (indicator.indicatorElement) {
                    indicator.indicatorElement.appendChild(element);
                }
                series.seriesElement = element;
            }
            Eif (chart.indicatorElements) {
                chart.indicatorElements.appendChild(indicator.indicatorElement);
            }
        };
        TechnicalAnalysis.prototype.getDataPoint = function (x, y, sourcePoint, series, index, indicator) {
            if (indicator === void 0) { indicator = null; }
            var point = new chart_series_1.Points();
            point.x = x;
            point.y = y;
            point.xValue = sourcePoint.xValue;
            point.color = series.fill;
            point.index = index;
            point.yValue = y;
            point.visible = true;
            series.xMin = Math.min(series.xMin, point.xValue);
            series.yMin = Math.min(series.yMin, point.yValue);
            series.xMax = Math.max(series.xMax, point.xValue);
            series.yMax = Math.max(series.yMax, point.yValue);
            series.xData.push(point.xValue);
            if (indicator && indicator.type === 'Macd' && series.type === 'Column') {
                if (point.y >= 0) {
                    point.color = indicator.macdPositiveColor;
                }
                else {
                    point.color = indicator.macdNegativeColor;
                }
            }
            return point;
        };
        TechnicalAnalysis.prototype.getRangePoint = function (x, high, low, sourcePoint, series, index) {
            var point = new chart_series_1.Points();
            point.x = x;
            point.high = high;
            point.low = low;
            point.xValue = sourcePoint.xValue;
            point.color = series.fill;
            point.index = index;
            point.visible = true;
            series.xData.push(point.xValue);
            return point;
        };
        TechnicalAnalysis.prototype.setSeriesRange = function (points, indicator, series) {
            if (series === void 0) { series = null; }
            if (!series) {
                indicator.targetSeries[0].points = points;
            }
            else {
                series.points = points;
            }
        };
        return TechnicalAnalysis;
    }(line_base_1.LineBase));
    exports.TechnicalAnalysis = TechnicalAnalysis;
});