all files / chart/axis/ strip-line.js

99.02% Statements 101/102
98.28% Branches 57/58
100% Functions 15/15
99.02% Lines 101/102
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     42× 42× 42×     37× 37×   42× 42× 42× 42× 42×   42× 42×       42× 42× 42×   42×     40×     83×   83×   82×   83×   46× 46× 46× 46× 46× 46× 132× 132× 84× 84× 42× 42× 42× 42×       46×   42×   42× 42× 42× 42× 42× 42× 42× 42× 42× 25× 25× 25×     17× 17× 17×   42× 42×   25×       25×   42× 42×       42×   84× 84×   12× 12×   18× 18×   84×   20665×          
define(["require", "exports", "@syncfusion/ej2-base", "../../common/utils/helper"], function (require, exports, ej2_base_1, helper_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var StripLine = (function () {
        function StripLine() {
        }
        StripLine.prototype.measureStripLine = function (axis, stripline, seriesClipRect) {
            var actualStart;
            var actualEnd;
            if (axis.valueType === 'DateTimeCategory') {
                var start = stripline.start;
                var end = stripline.end;
                actualStart = start ? axis.labels.indexOf(start.getTime().toString()) : null;
                actualEnd = end ? axis.labels.indexOf(end.getTime().toString()) : null;
            }
            else {
                actualStart = stripline.start;
                actualEnd = stripline.end;
            }
            var rect = this.getFromTovalue(actualStart, actualEnd, stripline.size, stripline.startFromAxis, axis);
            var height = (axis.orientation === 'Vertical') ? (rect.to - rect.from) * axis.rect.height : seriesClipRect.height;
            var width = (axis.orientation === 'Horizontal') ? (rect.to - rect.from) * axis.rect.width : seriesClipRect.width;
            var x = (axis.orientation === 'Vertical') ? seriesClipRect.x : ((rect.from * axis.rect.width) + axis.rect.x);
            var y = (axis.orientation === 'Horizontal') ? seriesClipRect.y : (axis.rect.y + axis.rect.height -
                (rect.to * axis.rect.height));
            Eif (height !== 0 && width !== 0) {
                return new helper_1.Rect(x, y, width, height);
            }
            return new helper_1.Rect(0, 0, 0, 0);
        };
        StripLine.prototype.getFromTovalue = function (start, end, size, startFromAxis, axis) {
            var from = startFromAxis ? axis.visibleRange.min : this.findValue(Math.min(start, ej2_base_1.isNullOrUndefined(end) ? start : end), axis);
            var to = this.findValue(this.getToValue(Math.max(start, ej2_base_1.isNullOrUndefined(end) ? start : end), from, size, axis, end), axis);
            return { from: helper_1.valueToCoefficient(axis.isInversed ? to : from, axis), to: helper_1.valueToCoefficient(axis.isInversed ? from : to, axis) };
        };
        StripLine.prototype.getToValue = function (to, from, size, axis, end) {
            if (axis.valueType === 'DateTime') {
                return (ej2_base_1.isNullOrUndefined(end) ? new Date(new Date(from).getTime() + size) : to);
            }
            else {
                return ej2_base_1.isNullOrUndefined(end) ? (axis.valueType === 'Logarithmic' ? Math.pow(axis.logBase, from) : from) + size : to;
            }
        };
        StripLine.prototype.findValue = function (value, axis) {
            if (axis.valueType === 'Logarithmic') {
                value = helper_1.logBase(value, axis.logBase);
            }
            if (value < axis.visibleRange.min) {
                value = axis.visibleRange.min;
            }
            else if (value > axis.visibleRange.max) {
                value = axis.visibleRange.max;
            }
            return value;
        };
        StripLine.prototype.renderStripLine = function (chart, position, axes) {
            var id = chart.element.id + '_stripline_' + position + '_';
            var striplineGroup = chart.renderer.createGroup({ id: id + 'collections' });
            var seriesClipRect = chart.chartAxisLayoutPanel.seriesClipRect;
            var rect;
            var count = 0;
            for (var _i = 0, axes_1 = axes; _i < axes_1.length; _i++) {
                var axis = axes_1[_i];
                for (var _a = 0, _b = axis.stripLines; _a < _b.length; _a++) {
                    var stripline = _b[_a];
                    if (stripline.visible && stripline.zIndex === position) {
                        rect = this.measureStripLine(axis, stripline, seriesClipRect);
                        this.renderRectangle(stripline, rect, id + 'rect_' + count, striplineGroup, chart);
                        this.renderText(stripline, rect, id + 'text_' + count, striplineGroup, chart, axis);
                        count++;
                    }
                }
            }
            chart.svgObject.appendChild(striplineGroup);
        };
        StripLine.prototype.renderRectangle = function (stripline, rect, id, parent, chart) {
            parent.appendChild(chart.renderer.drawRectangle(new helper_1.RectOption(id, stripline.color, stripline.border, stripline.opacity, rect, 0, 0, '', '')));
        };
        StripLine.prototype.renderText = function (stripline, rect, id, parent, chart, axis) {
            var textSize = helper_1.measureText(stripline.text, stripline.textStyle);
            var textMid = 3 * (textSize.height / 8);
            var ty = rect.y + (rect.height / 2) + textMid;
            var rotation = (stripline.rotation === null) ? ((axis.orientation === 'Vertical') ? 0 : -90) : stripline.rotation;
            var tx = rect.x + (rect.width / 2);
            var alignment;
            var anchor;
            var padding = 5;
            if (axis.orientation === 'Horizontal') {
                tx = this.getTextStart(tx + (textMid * this.factor(stripline.horizontalAlignment)), rect.width, stripline.horizontalAlignment);
                ty = this.getTextStart(ty - textMid, rect.height, stripline.verticalAlignment);
                alignment = this.invertAlignment(stripline.horizontalAlignment);
            }
            else {
                tx = this.getTextStart(tx, rect.width, stripline.horizontalAlignment);
                ty = this.getTextStart(ty + (textMid * this.factor(stripline.verticalAlignment)) - padding, rect.height, stripline.verticalAlignment);
                alignment = stripline.verticalAlignment;
            }
            anchor = alignment;
            helper_1.textElement(new helper_1.TextOption(id, tx, ty, anchor, stripline.text, 'rotate(' + rotation + ' ' + tx + ',' + ty + ')', 'middle'), stripline.textStyle, stripline.textStyle.color, parent);
        };
        StripLine.prototype.invertAlignment = function (anchor) {
            switch (anchor) {
                case 'Start':
                    anchor = 'Start';
                    break;
                case 'End':
                    anchor = 'End';
                    break;
            }
            return anchor;
        };
        StripLine.prototype.factor = function (anchor) {
            var factor = 0;
            switch (anchor) {
                case 'Start':
                    factor = 1;
                    break;
                case 'End':
                    factor = -1;
                    break;
            }
            return factor;
        };
        StripLine.prototype.getTextStart = function (xy, size, textAlignment) {
            var padding = 5;
            switch (textAlignment) {
                case 'Start':
                    xy = xy - (size / 2) + padding;
                    break;
                case 'End':
                    xy = xy + (size / 2) - padding;
                    break;
            }
            return xy;
        };
        StripLine.prototype.getModuleName = function () {
            return 'StripLine';
        };
        StripLine.prototype.destroy = function () {
        };
        return StripLine;
    }());
    exports.StripLine = StripLine;
});