all files / linear-gauge/user-interaction/ tooltip.js

99.12% Statements 112/113
96% Branches 48/50
100% Functions 12/12
99.12% Lines 112/113
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   14× 14× 14× 14× 14× 14× 14×   26× 26× 26× 26× 26×     25× 25× 25× 25×   26× 26× 26× 14× 14× 14× 14× 14× 14× 14×   14×     13×         13×   14× 14×       14× 14× 14× 14× 14× 14×                                 14×       12×     14× 14×       14×   14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14×       14× 14× 14× 14× 14× 14× 14×       14× 14×   13× 11×       14×     14× 14×   14×   13× 13×   347×   14×        
define(["require", "exports", "@syncfusion/ej2-base", "../model/constant", "@syncfusion/ej2-svg-base", "../utils/helper", "../utils/helper"], function (require, exports, ej2_base_1, constant_1, ej2_svg_base_1, helper_1, helper_2) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var GaugeTooltip = (function () {
        function GaugeTooltip(gauge) {
            this.gauge = gauge;
            this.element = gauge.element;
            this.tooltip = gauge.tooltip;
            this.textStyle = this.tooltip.textStyle;
            this.borderStyle = this.tooltip.border;
            this.tooltipId = this.gauge.element.id + '_LinearGauge_Tooltip';
            this.addEventListener();
        }
        GaugeTooltip.prototype.renderTooltip = function (e) {
            var pageX;
            var pageY;
            var target;
            var touchArg;
            if (e.type.indexOf('touch') !== -1) {
                this.isTouch = true;
                touchArg = e;
                pageX = touchArg.changedTouches[0].pageX;
                pageY = touchArg.changedTouches[0].pageY;
                target = touchArg.target;
            }
            else {
                this.isTouch = e.pointerType === 'touch';
                pageX = e.pageX;
                pageY = e.pageY;
                target = e.target;
            }
            var tooltipEle;
            var tooltipContent = [];
            if (target.id.indexOf('Pointer') > -1) {
                this.pointerElement = target;
                var areaRect = this.gauge.element.getBoundingClientRect();
                var current = helper_2.getPointer(this.pointerElement, this.gauge);
                this.currentAxis = current.axis;
                this.axisIndex = current.axisIndex;
                this.currentPointer = current.pointer;
                tooltipContent = [helper_1.textFormatter(this.tooltip.format, { value: this.currentPointer.currentValue }, this.gauge) ||
                        helper_1.formatValue(this.currentPointer.currentValue, this.gauge).toString()];
                if (document.getElementById(this.tooltipId)) {
                    tooltipEle = document.getElementById(this.tooltipId);
                }
                else {
                    tooltipEle = ej2_base_1.createElement('div', {
                        id: this.tooltipId,
                        className: 'EJ2-LinearGauge-Tooltip',
                        styles: 'position: absolute;pointer-events:none;'
                    });
                    document.getElementById(this.gauge.element.id + '_Secondary_Element').appendChild(tooltipEle);
                }
                var location_1 = this.getTooltipLocation();
                var args = {
                    name: constant_1.tooltipRender, cancel: false, gauge: this.gauge, event: e, location: location_1, content: tooltipContent[0],
                    tooltip: this.tooltip, axis: this.currentAxis, pointer: this.currentPointer
                };
                var tooltipPos = this.getTooltipPosition();
                location_1.y += (this.tooltip.template && tooltipPos === 'Top') ? 20 : 0;
                location_1.x += (this.tooltip.template && tooltipPos === 'Right') ? 20 : 0;
                this.gauge.trigger(constant_1.tooltipRender, args);
                Eif (!args.cancel) {
                    this.svgTooltip = new ej2_svg_base_1.Tooltip({
                        enable: true,
                        header: '',
                        data: { value: args.pointer.currentValue },
                        template: args.tooltip.template,
                        content: [args.content],
                        shapes: [],
                        location: args.location,
                        palette: [],
                        inverted: !(args.gauge.orientation === 'Horizontal'),
                        enableAnimation: args.tooltip.enableAnimation,
                        fill: args.tooltip.fill,
                        areaBounds: new helper_1.Rect(areaRect.left, tooltipPos === 'Bottom' ? location_1.y : areaRect.top, tooltipPos === 'Right' ? Math.abs(areaRect.left - location_1.x) : areaRect.width, areaRect.height),
                        textStyle: args.tooltip.textStyle,
                        border: args.tooltip.border,
                        theme: args.gauge.theme
                    });
                    this.svgTooltip.appendTo(tooltipEle);
                }
            }
            else {
                this.removeTooltip();
            }
        };
        GaugeTooltip.prototype.getTooltipPosition = function () {
            var position;
            if (this.gauge.orientation === 'Vertical') {
                position = (!this.currentAxis.opposedPosition) ? 'Left' : 'Right';
            }
            else {
                position = (this.currentAxis.opposedPosition) ? 'Top' : 'Bottom';
            }
            return position;
        };
        GaugeTooltip.prototype.getTooltipLocation = function () {
            var location;
            var bounds;
            var radix = 10;
            var lineX;
            var lineY;
            var size = new helper_1.Size(this.gauge.availableSize.width, this.gauge.availableSize.height);
            var x;
            var y;
            var height;
            var width;
            var lineId = this.gauge.element.id + '_AxisLine_' + this.axisIndex;
            var tickID = this.gauge.element.id + '_MajorTicksLine_' + this.axisIndex;
            var lineBounds;
            if (helper_1.getElement(lineId)) {
                lineBounds = helper_1.getElement(lineId).getBoundingClientRect();
                lineX = lineBounds.left;
                lineY = lineBounds.top;
            }
            else {
                lineBounds = helper_1.getElement(tickID).getBoundingClientRect();
                lineX = (!this.currentAxis.opposedPosition) ? (lineBounds.left + lineBounds.width) : lineBounds.left;
                lineY = (!this.currentAxis.opposedPosition) ? (lineBounds.top + lineBounds.height) : lineBounds.top;
            }
            bounds = this.pointerElement.getBoundingClientRect();
            var elementRect = this.gauge.element.getBoundingClientRect();
            x = bounds.left - elementRect.left;
            y = bounds.top - elementRect.top;
            height = bounds.height;
            width = bounds.width;
            if (this.gauge.orientation === 'Vertical') {
                x = (lineX - elementRect.left);
                y = (this.currentPointer.type === 'Marker') ? y + (height / 2) : (!this.currentAxis.isInversed) ? y : y + height;
            }
            else {
                y = (lineY - elementRect.top);
                x = (this.currentPointer.type === 'Marker') ? (x + width / 2) : (!this.currentAxis.isInversed) ? x + width : x;
            }
            location = new helper_1.GaugeLocation(x, y);
            return location;
        };
        GaugeTooltip.prototype.removeTooltip = function () {
            if (document.getElementsByClassName('EJ2-LinearGauge-Tooltip').length > 0) {
                document.getElementsByClassName('EJ2-LinearGauge-Tooltip')[0].remove();
            }
        };
        GaugeTooltip.prototype.mouseUpHandler = function (e) {
            this.renderTooltip(e);
            clearTimeout(this.clearTimeout);
            this.clearTimeout = setTimeout(this.removeTooltip.bind(this), 2000);
        };
        GaugeTooltip.prototype.addEventListener = function () {
            Iif (this.gauge.isDestroyed) {
                return;
            }
            this.gauge.on(ej2_base_1.Browser.touchMoveEvent, this.renderTooltip, this);
            this.gauge.on(ej2_base_1.Browser.touchEndEvent, this.mouseUpHandler, this);
        };
        GaugeTooltip.prototype.removeEventListener = function () {
            if (this.gauge.isDestroyed) {
                return;
            }
            this.gauge.off(ej2_base_1.Browser.touchMoveEvent, this.renderTooltip);
            this.gauge.off(ej2_base_1.Browser.touchEndEvent, this.mouseUpHandler);
        };
        GaugeTooltip.prototype.getModuleName = function () {
            return 'Tooltip';
        };
        GaugeTooltip.prototype.destroy = function (gauge) {
            this.removeEventListener();
        };
        return GaugeTooltip;
    }());
    exports.GaugeTooltip = GaugeTooltip;
});