all files / range-navigator/renderer/ chart-render.js

100% Statements 147/147
95.08% Branches 58/61
100% Functions 21/21
100% Lines 143/143
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 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        185× 185× 185× 185× 185× 185× 185× 185× 185× 185×   194× 194× 194× 194× 194× 194× 155× 171× 171× 171× 171×       39×     210× 210× 207× 207×     210× 210× 210× 210× 194× 194× 194× 194×     210× 210× 210× 210× 210× 32034× 32034× 32034× 32034× 31437×   32034× 32034× 32034× 32034× 32034× 32034×     194× 194×           194× 194× 194× 194× 194× 194× 194× 194× 194× 194× 194× 194× 194× 184×   194× 194× 194×   194×           194× 194× 194× 194× 194× 194× 194× 194× 194× 194× 194×   194× 194× 194× 194× 171× 171× 171× 171× 171× 171× 171× 171× 171× 171×     194× 194× 155×     171× 171× 171×         171×         171×   194× 194× 194× 194×   42×     194× 39× 39×     155×       155× 155×        
/* 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", "../../chart/index", "../utils/helper", "@syncfusion/ej2-base", "../../common/model/theme", "../../chart/index", "../../common/model/data"], function (require, exports, index_1, helper_1, ej2_base_1, theme_1, index_2, data_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var RangeSeries = (function (_super) {
        __extends(RangeSeries, _super);
        function RangeSeries(range) {
            var _this = _super.call(this) || this;
            _this.dataSource = range.dataSource;
            _this.xName = range.xName;
            _this.yName = range.yName;
            _this.query = range.query;
            _this.xMin = Infinity;
            _this.xMax = -Infinity;
            _this.yMin = Infinity;
            _this.yMax = -Infinity;
            return _this;
        }
        RangeSeries.prototype.renderChart = function (control) {
            var _this = this;
            var dataSource;
            var query;
            this.seriesLength = 0;
            control.rangeSlider.points = [];
            if (control.series.length) {
                control.series.map(function (series) {
                    dataSource = series.dataSource || control.dataSource;
                    query = series.query || control.query;
                    series.points = [];
                    _this.processDataSource(dataSource, query, control, series);
                });
            }
            else {
                this.processDataSource(control.dataSource, control.query, control);
            }
        };
        RangeSeries.prototype.processDataSource = function (dataSource, query, control, series) {
            var _this = this;
            if (ej2_base_1.isNullOrUndefined(query) && !ej2_base_1.isNullOrUndefined(dataSource)) {
                this.dataManagerSuccess({ result: dataSource, count: dataSource.length }, control, series);
                return;
            }
            control.dataModule = new data_1.Data(dataSource, query);
            var dataManager = control.dataModule.getData(control.dataModule.generateQuery().requiresCount());
            dataManager.then(function (e) { return _this.dataManagerSuccess(e, control, series); });
        };
        RangeSeries.prototype.dataManagerSuccess = function (e, control, series) {
            var viewData = e.result !== '' ? e.result : [];
            this.processJsonData(viewData, control, Object.keys(viewData).length, series);
            this.seriesLength += series ? 1 : this.seriesLength;
            if (!series || this.seriesLength === control.series.length) {
                this.processXAxis(control);
                this.calculateGroupingBounds(control);
                this.processYAxis(control);
                control.renderChart();
            }
        };
        RangeSeries.prototype.processJsonData = function (viewData, control, len, series) {
            var i = 0;
            var point;
            var xName = (series && series.xName) || control.xName;
            var yName = (series && series.yName) || control.yName;
            while (i < len) {
                point = new helper_1.DataPoint(ej2_base_1.getValue(xName, viewData[i]), ej2_base_1.getValue(yName, viewData[i]));
                point.xValue = +point.x;
                point.yValue = +point.y;
                if (series) {
                    series.points.push(point);
                }
                this.xMin = Math.min(this.xMin, point.xValue);
                this.yMin = Math.min(this.yMin, point.yValue);
                this.xMax = Math.max(this.xMax, point.xValue);
                this.yMax = Math.max(this.yMax, point.yValue);
                control.rangeSlider.points.push(point);
                i++;
            }
        };
        RangeSeries.prototype.processXAxis = function (control) {
            var axisModule;
            var axis = {
                minimum: control.minimum, maximum: control.maximum,
                interval: control.interval, valueType: control.valueType,
                isInversed: control.enableRtl, labelFormat: control.labelFormat,
                logBase: control.logBase, skeleton: control.skeleton, skeletonType: control.skeletonType
            };
            this.xAxis = axis;
            this.xAxis.intervalType = control.intervalType;
            this.xAxis.maximumLabels = 3;
            this.xAxis.skeleton = control.skeleton;
            this.xAxis.intervalDivs = [10, 5, 2, 1];
            this.xAxis.rect = control.bounds;
            this.xAxis.visibleLabels = [];
            this.xAxis.orientation = 'Horizontal';
            axisModule = control[index_1.firstToLowerCase(control.valueType) + 'Module'];
            axisModule.min = this.xMin;
            axisModule.max = this.xMax;
            axisModule.getActualRange(this.xAxis, control.bounds);
            if (this.xAxis.valueType !== 'Logarithmic') {
                axisModule.updateActualRange(this.xAxis, this.xAxis.actualRange.min, this.xAxis.actualRange.max, this.xAxis.actualRange.interval);
            }
            this.xAxis.actualRange.delta = this.xAxis.actualRange.max - this.xAxis.actualRange.min;
            this.xAxis.visibleRange = this.xAxis.actualRange;
            axisModule.calculateVisibleLabels(this.xAxis, control);
        };
        RangeSeries.prototype.processYAxis = function (control) {
            var axis = {
                majorGridLines: { width: 0 }, rangePadding: 'None',
                majorTickLines: { width: 0 }, labelStyle: { size: '0' },
                visible: false, valueType: 'Double', minimum: null, maximum: null,
                interval: null
            };
            this.yAxis = axis;
            this.yAxis.rect = control.bounds;
            this.yAxis.maximumLabels = 3;
            this.yAxis.intervalDivs = [10, 5, 2, 1];
            this.yAxis.orientation = 'Vertical';
            control.doubleModule.min = this.yMin;
            control.doubleModule.max = this.yMax;
            control.doubleModule.getActualRange(this.yAxis, control.bounds);
            control.doubleModule.updateActualRange(this.yAxis, this.yAxis.actualRange.min, this.yAxis.actualRange.max, this.yAxis.actualRange.interval);
            this.yAxis.actualRange.delta = this.yAxis.actualRange.max - this.yAxis.actualRange.min;
            this.yAxis.visibleRange = this.yAxis.actualRange;
        };
        RangeSeries.prototype.renderSeries = function (control) {
            var _this = this;
            var chartGroup = control.renderer.createGroup({ id: control.element.id + '_chart' });
            var colors = theme_1.getSeriesColor(control.theme);
            control.series.map(function (series, index) {
                series.xAxis = _this.xAxis;
                series.yAxis = _this.yAxis;
                series.chart = control;
                series.index = index;
                series.xAxis.isInversed = control.enableRtl;
                series.interior = series.fill || colors[index % colors.length];
                _this.createSeriesElement(control, series, index);
                control[index_1.firstToLowerCase(series.type) + 'SeriesModule'].render(series, _this.xAxis, _this.yAxis, false);
                chartGroup.appendChild(series.seriesElement);
                if (series.animation.enable && control.animateSeries) {
                    control[index_1.firstToLowerCase(series.type) + 'SeriesModule'].doAnimation(series);
                }
            });
            control.svgObject.appendChild(chartGroup);
            if (control.series.length) {
                this.drawSeriesBorder(control, chartGroup);
            }
        };
        RangeSeries.prototype.createSeriesElement = function (control, series, index) {
            var elementId = control.element.id;
            series.clipRect = new index_1.Rect(this.xAxis.rect.x, this.yAxis.rect.y, this.xAxis.rect.width, this.yAxis.rect.height);
            series.clipRectElement = control.renderer.drawClipPath(new index_1.RectOption(elementId + '_RangeSeriesClipRect_' + index, 'transparent', { width: 1, color: 'Gray' }, 1, {
                x: 0, y: 0,
                width: series.clipRect.width,
                height: series.clipRect.height
            }));
            series.seriesElement = control.renderer.createGroup({
                'id': elementId + 'SeriesGroup' + index,
                'transform': 'translate(' + series.clipRect.x + ',' + (series.clipRect.y) + ')',
                'clip-path': 'url(#' + elementId + '_RangeSeriesClipRect_' + index + ')'
            });
            series.seriesElement.appendChild(series.clipRectElement);
        };
        RangeSeries.prototype.calculateGroupingBounds = function (control) {
            var padding = control.margin.bottom;
            var labelHeight = index_1.measureText('string', control.labelStyle).height;
            this.calculateDateTimeNiceInterval(this.xAxis, new index_2.Size(control.bounds.width, control.bounds.height), this.xMin, this.xMax, false);
            if (control.enableGrouping && control.valueType === 'DateTime'
                && (this.xAxis.actualIntervalType !== 'Years' || !control.series.length)) {
                control.bounds.height -= (control.labelPosition === 'Outside' || control.series.length === 0) ? padding + labelHeight :
                    (labelHeight + 2 * padding);
            }
            if (!control.series.length) {
                control.bounds.y += control.bounds.height / 4;
                control.bounds.height = control.bounds.height / 2;
            }
        };
        RangeSeries.prototype.drawSeriesBorder = function (control, chartElement) {
            var options = new index_2.PathOption(control.element.id + '_SeriesBorder', 'transparent', control.navigatorBorder.width, control.navigatorBorder.color, 1, '', ('M ' + (control.bounds.x) + ' ' + (control.bounds.y) +
                ' L ' + (control.bounds.x + control.bounds.width) + ' ' + control.bounds.y +
                ' L ' + (control.bounds.x + control.bounds.width) + ' ' + (control.bounds.y + control.bounds.height) +
                ' L ' + (control.bounds.x) + ' ' + (control.bounds.y + control.bounds.height) + 'Z'));
            var htmlObject = control.renderer.drawPath(options);
            control.svgObject.appendChild(htmlObject);
        };
        return RangeSeries;
    }(index_2.NiceInterval));
    exports.RangeSeries = RangeSeries;
});