all files / smithchart/series/ tooltip.js

100% Statements 69/69
90.91% Branches 20/22
100% Functions 9/9
100% Lines 69/69
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                                                           75× 75× 75× 75× 75× 75× 75× 75×       65×          
define(["require", "exports", "../../smithchart/utils/utils", "@syncfusion/ej2-svg-base", "@syncfusion/ej2-base"], function (require, exports, utils_1, ej2_svg_base_1, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var TooltipRender = (function () {
        function TooltipRender() {
        }
        TooltipRender.prototype.smithchartMouseMove = function (smithchart, e) {
            var touchArg;
            var pageX;
            var pageY;
            if (e.type === 'touchend' || e.type === 'touchmove') {
                touchArg = e;
                pageX = touchArg.changedTouches[0].clientX;
                pageY = touchArg.changedTouches[0].clientY;
                this.tooltipElement = undefined;
            }
            else {
                pageY = e.clientY;
                pageX = e.clientX;
            }
            this.setMouseXY(smithchart, pageX, pageY);
            for (var i = 0; i < smithchart.series.length; i++) {
                var series = smithchart.series[i];
                var seriesIndex = i;
                var closestPoint = new utils_1.ClosestPoint();
                closestPoint = this.closestPointXY(smithchart, this.mouseX, this.mouseY, series, seriesIndex);
                if (closestPoint.location && series.tooltip.visible && series.visibility === 'visible') {
                    this.createTooltip(smithchart, e, closestPoint.index, seriesIndex, series);
                    break;
                }
                else if (this.tooltipElement && this.tooltipElement.enable && !series.tooltip.template) {
                    this.tooltipElement.fadeOut();
                    this.tooltipElement.enable = false;
                }
                else if (series.tooltip.template) {
                    this.tooltipElement.fadeOut();
                }
            }
            return this.tooltipElement;
        };
        TooltipRender.prototype.setMouseXY = function (smithchart, pageX, pageY) {
            var rect = smithchart.element.getBoundingClientRect();
            var svgRect = document.getElementById(smithchart.element.id + '_svg').getBoundingClientRect();
            this.mouseX = (pageX - rect.left) - Math.max(svgRect.left - rect.left, 0);
            this.mouseY = (pageY - rect.top) - Math.max(svgRect.top - rect.top, 0);
        };
        TooltipRender.prototype.createTooltip = function (smithchart, e, pointindex, seriesindex, series) {
            var pointX = series.points[pointindex].resistance;
            var pointY = series.points[pointindex].reactance;
            var tooltipText = [pointX + ' ' + ':' + ' ' + '<b>' + pointY + '</b>'];
            var markerHeight = smithchart.series[seriesindex].marker.height / 2;
            var div = document.getElementById(smithchart.element.id + '_smithchart_tooltip_div');
            Eif (ej2_base_1.isNullOrUndefined(div)) {
                div = ej2_base_1.createElement('div', { id: smithchart.element.id + '_smithchart_tooltip_div',
                    styles: 'pointer-events: none; position: absolute;z-index:1;' });
                document.getElementById(smithchart.element.id + '_Secondary_Element').appendChild(div);
            }
            this.tooltipElement = new ej2_svg_base_1.Tooltip({
                enable: true,
                header: '<b>' + series.name + '</b>',
                content: tooltipText,
                border: series.tooltip.border,
                fill: smithchart.themeStyle.tooltipFill,
                data: { reactance: pointY },
                template: series.tooltip.template,
                location: { x: this.locationX + smithchart.element.offsetLeft,
                    y: this.locationY - markerHeight + smithchart.element.offsetTop },
                shared: false,
                areaBounds: new utils_1.SmithchartRect(smithchart.bounds.x, smithchart.bounds.y, smithchart.bounds.width, smithchart.bounds.height),
                palette: [series.fill || smithchart.seriesColors[seriesindex % smithchart.seriesColors.length]],
                shapes: ['Circle'],
                theme: smithchart.theme
            });
            this.tooltipElement.textStyle.fontFamily = 'Roboto, Segoe UI, Noto, Sans-serif';
            this.tooltipElement.appendTo(div);
        };
        TooltipRender.prototype.closestPointXY = function (smithchart, x, y, series, seriesindex) {
            var pointIndex;
            var chartPoint;
            var closePoint;
            for (var j = 0; j < series.points.length; j++) {
                chartPoint = smithchart.seriesrender.getLocation(seriesindex, j);
                this.locationX = chartPoint.x;
                this.locationY = chartPoint.y;
                pointIndex = j;
                var a = x - chartPoint.x;
                var b = y - chartPoint.y;
                var distance = Math.abs(Math.sqrt((a * a) + (b * b)));
                if (distance < series.marker.width) {
                    closePoint = chartPoint;
                    pointIndex = j;
                    break;
                }
            }
            return { location: closePoint, index: pointIndex };
        };
        TooltipRender.prototype.getModuleName = function () {
            return 'TooltipRender';
        };
        TooltipRender.prototype.destroy = function (smithchart) {
        };
        return TooltipRender;
    }());
    exports.TooltipRender = TooltipRender;
});