all files / bullet-chart/user-interaction/ tooltip.js

95.93% Statements 118/123
85.71% Branches 84/98
100% Functions 8/8
95.93% Lines 118/123
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   13× 13× 13×   24× 24× 24× 24× 24× 24× 24× 24×   24× 24× 24×       24× 24×   22×   24×     21×   20× 20× 20× 20× 20× 20× 20×     20× 20× 20× 20× 20× 20× 20× 20× 20×   20× 20× 20× 20× 20× 20× 20× 20× 20×   20×     20×             18× 18× 18×   18× 18× 18× 18×   18× 18×   20× 20× 20× 20× 20× 20× 20×   20×   20×     20×     20×     20×   20×     18× 18× 18×           18× 18×       18×   18×     20×                             87×          
define(["require", "exports", "@syncfusion/ej2-base", "../../common/utils/helper", "../../common/model/constants", "../renderer/bullet-axis"], function (require, exports, ej2_base_1, helper_1, constants_1, bullet_axis_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var BulletTooltip = (function () {
        function BulletTooltip(bullet) {
            this.control = bullet;
            this.elementId = bullet.element.id;
            this.bulletAxis = new bullet_axis_1.BulletChartAxis(this.control);
        }
        BulletTooltip.prototype._elementTooltip = function (e, targetClass, targetId, mouseX) {
            var tooltipDiv = this.control.createElement('div');
            tooltipDiv.id = 'tooltip';
            tooltipDiv.className = 'tooltipDiv';
            var target = e.target;
            var pageX = mouseX + 20;
            var pageY = e.clientY;
            var str = '';
            var font = this.control.tooltip.textStyle.fontStyle ? this.control.tooltip.textStyle.fontStyle :
                this.control.themeStyle.tooltipLabelFont.fontStyle;
            var fill = this.control.tooltip.fill ? this.control.tooltip.fill : this.control.themeStyle.tooltipFill;
            var color = this.control.themeStyle.tooltipLabelFont.color || this.control.themeStyle.tooltipBoldLabel;
            var style = 'left:' + pageX + 'px;' + 'top:' + pageY + 'px;' +
                'display: block; position: absolute; "z-index": "13000",cursor: default;' +
                'font-family: Segoe UI;' + 'color:' + color + '; font-size: 13px; background-color:' +
                fill + '; border: 1px solid #707070;' + 'font-style:' + font + ';';
            tooltipDiv.style.cssText = style;
            if (targetClass === this.control.svgObject.id + '_Caption') {
                str = target.textContent === this.control.title ? '' : this.control.title;
            }
            else if (targetClass === this.control.svgObject.id + '_SubTitle') {
                str = target.textContent === this.control.subtitle ? '' : this.control.subtitle;
            }
            if (str !== '') {
                tooltipDiv.innerHTML = '&nbsp' + str + '&nbsp';
                document.body.insertAdjacentElement('afterbegin', tooltipDiv);
            }
        };
        BulletTooltip.prototype._displayTooltip = function (e, targetClass, targetId, mouseX, mouseY) {
            if (targetClass !== 'undefined' && this.control.tooltip.enable && (targetClass === this.control.svgObject.id + '_FeatureMeasure' ||
                targetClass === this.control.svgObject.id + '_ComparativeMeasure')) {
                var targetVal = [];
                var tooltipdiv = void 0;
                var format = this.bulletAxis.getFormat(this.control);
                var isCustomFormat = format.match('{value}') !== null;
                var measureId = targetId.substring(targetId.lastIndexOf('_') + 1);
                var targetValues = [];
                this.bulletAxis.format = this.bulletAxis.bulletChart.intl.getNumberFormat({
                    format: isCustomFormat ? '' : format, useGrouping: this.bulletAxis.bulletChart.enableGroupSeparator
                });
                var currentVal = this.control.dataSource[measureId][this.control.valueField];
                targetVal = targetVal.concat(this.control.dataSource[measureId][this.control.targetField]);
                var categoryVal = this.control.dataSource[measureId][this.control.categoryField];
                var labelCurrentText = currentVal ? (currentVal).toString() : '';
                var labelTargetText = targetVal ? (targetVal).toString() : '';
                var labelCategoryText = categoryVal ? (categoryVal).toString() : '';
                labelCurrentText = this.bulletAxis.formatValue(this.bulletAxis, isCustomFormat, format, +currentVal);
                for (var i = 0; i < targetVal.length; i++) {
                    targetValues = targetValues.concat(this.bulletAxis.formatValue(this.bulletAxis, isCustomFormat, format, +targetVal[i]));
                }
                labelCategoryText = this.bulletAxis.formatValue(this.bulletAxis, isCustomFormat, format, +categoryVal);
                var data = { value: labelCurrentText, target: targetValues, category: labelCategoryText };
                var tooltipData = { value: labelCurrentText, target: labelTargetText, category: labelCategoryText };
                var style = 'position: absolute; z-index: 13000; display: block;';
                Eif (document.getElementsByClassName('tooltipDiv' + this.control.element.id).length === 0) {
                    tooltipdiv = this.control.createElement('div');
                    tooltipdiv.id = 'tooltipDiv' + this.control.element.id;
                    tooltipdiv.style.cssText = style;
                    document.getElementById(this.control.element.id + '_Secondary_Element').appendChild(tooltipdiv);
                }
                var argsData = {
                    value: data.value, target: data.target, name: constants_1.tooltipRender
                };
                if (this.control.tooltip.template !== '' && this.control.tooltip.template != null) {
                    this.updateTemplateFn();
                    var elem = this.control.createElement('div', { id: this.control.element.id + 'parent_template' });
                    var templateElement = this.templateFn(tooltipData, this.control, 'template', elem.id + '_blazorTemplate', '', null, elem);
                    while (templateElement && templateElement.length > 0) {
                        if (templateElement.length === 1) {
                            elem.appendChild(templateElement[0]);
                            templateElement = null;
                        }
                        else {
                            elem.appendChild(templateElement[0]);
                        }
                    }
                    argsData.template = elem.innerHTML;
                    this.control.trigger(constants_1.tooltipRender, argsData);
                    elem.innerHTML = argsData.template;
                    tooltipdiv.appendChild(elem);
                }
                else {
                    var argsText = 'Value : ' + argsData.value;
                    for (var i = 0; i < argsData.target.length; i++) {
                        argsText += '<br/> Target' + (i === 0 ? '' : '_' + i) + ' : ' + argsData.target[i];
                    }
                    argsData.text = argsText;
                    this.control.trigger(constants_1.tooltipRender, argsData);
                    tooltipdiv.innerHTML = argsData.text;
                    tooltipdiv.style.font = this.control.tooltip.textStyle.fontStyle ? this.control.tooltip.textStyle.fontStyle :
                        this.control.themeStyle.tooltipLabelFont.fontStyle;
                    tooltipdiv.style.color = this.control.themeStyle.tooltipLabelFont.color || this.control.themeStyle.tooltipBoldLabel;
                    tooltipdiv.style.fontSize = this.control.themeStyle.titleFont.size;
                }
                var fill = this.control.tooltip.fill ? this.control.tooltip.fill : this.control.themeStyle.tooltipFill;
                var borderWidth = ((this.control.theme === 'Fabric' || this.control.theme === 'Fluent' && !this.control.tooltip.border.width) ? 1 : this.control.tooltip.border.width);
                var borderColor = ((this.control.theme === 'Fabric' || this.control.theme === 'Fluent' && !this.control.tooltip.border.color) ? '#D2D0CE' : this.control.tooltip.border.color);
                var borderDashArray = this.control.tooltip.border.dashArray ? 'dashed ' + borderColor + '; border-dasharray: ' + this.control.tooltip.border.dashArray + ';' : 'Solid' + ' ' + borderColor + ';';
                var xPos = mouseX;
                var yPos = mouseY;
                xPos = ((xPos + helper_1.stringToNumber(tooltipdiv.getAttribute('width'), this.control.containerWidth) < window.innerWidth) ?
                    (xPos) : helper_1.stringToNumber(tooltipdiv.getAttribute('width'), this.control.containerWidth));
                yPos = ((yPos + helper_1.stringToNumber(tooltipdiv.getAttribute('height'), this.control.containerHeight) < window.innerHeight) ?
                    (yPos) : helper_1.stringToNumber(tooltipdiv.getAttribute('height'), this.control.containerHeight));
                Iif (xPos === undefined || xPos === null) {
                    xPos = mouseX;
                }
                Iif ((xPos + tooltipdiv.clientWidth) > this.control.availableSize.width) {
                    xPos -= tooltipdiv.clientWidth + 20;
                }
                Iif (yPos === undefined || yPos === null) {
                    yPos = e.clientY;
                }
                if (yPos + tooltipdiv.clientHeight > this.control.availableSize.height) {
                    yPos -= tooltipdiv.clientHeight + 20;
                }
                if (this.control.tooltip.template !== '' && this.control.tooltip.template != null) {
                    tooltipdiv.style.cssText = 'position: absolute;left:' + (xPos + 20) + 'px;' + 'top:' + (yPos + 20) + 'px;';
                }
                else {
                    var fontFamily = this.control.tooltip.textStyle.fontFamily || this.control.themeStyle.tooltipLabelFont.fontFamily;
                    var color = this.control.tooltip.textStyle.color || this.control.themeStyle.tooltipLabelFont.color;
                    var divStyle = style + 'left:' + (xPos + 20) + 'px;' + 'top:' + (yPos + 20) + 'px;' +
                        '-webkit-border-radius: 5px 5px 5px 5px; -moz-border-radius: 5px 5px 5px 5px;-o-border-radius: 5px 5px 5px 5px;' +
                        'border-radius: 5px 5px 5px 5px;' + 'background-color:' + fill + ';' + 'color:' +
                        color + '; border:' + borderWidth + 'px ' + borderDashArray +
                        'padding-bottom: 7px;' + 'font-style:' + this.control.themeStyle.tooltipLabelFont.fontStyle +
                        '; padding-left: 10px; font-family:' + fontFamily + '; font-size:' + this.control.tooltip.textStyle.size + '; padding-right: 10px; padding-top: 7px';
                    tooltipdiv.style.cssText = divStyle;
                    if (this.control.theme.indexOf('Fluent2') > -1) {
                        var shadowId = this.control.element.id + '_shadow';
                        var shadow = "<filter id=\"" + shadowId + "\" height=\"130%\"><feGaussianBlur in=\"SourceAlpha\" stdDeviation=\"3\"/>" +
                            '<feOffset dx="-1" dy="3.6" result="offsetblur"/><feComponentTransfer><feFuncA type="linear" slope="0.2"/>' +
                            '</feComponentTransfer><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge></filter>';
                        var defElement = this.control.renderer.createDefs();
                        defElement.setAttribute('id', this.control.element.id + 'SVG_tooltip_definition');
                        tooltipdiv.appendChild(defElement);
                        defElement.innerHTML = shadow;
                        tooltipdiv.style.filter = "url(#" + shadowId + ")";
                    }
                    Eif ((targetClass === this.control.svgObject.id + '_FeatureMeasure') ||
                        (targetClass === this.control.svgObject.id + '_ComparativeMeasure')) {
                        document.getElementById(targetId).setAttribute('opacity', '0.6');
                    }
                }
                if (this.control.isReact) {
                    this.control.renderReactTemplates();
                }
            }
        };
        BulletTooltip.prototype.updateTemplateFn = function () {
            if (this.control.tooltip.template) {
                try {
                    if (typeof this.control.tooltip.template !== 'function' &&
                        document.querySelectorAll(this.control.tooltip.template).length) {
                        this.templateFn = ej2_base_1.compile(document.querySelector(this.control.tooltip.template).innerHTML.trim());
                    }
                    else {
                        this.templateFn = ej2_base_1.compile(this.control.tooltip.template);
                    }
                }
                catch (e) {
                    this.templateFn = ej2_base_1.compile(this.control.tooltip.template);
                }
            }
        };
        BulletTooltip.prototype.getModuleName = function () {
            return 'BulletTooltip';
        };
        BulletTooltip.prototype.destroy = function () {
        };
        return BulletTooltip;
    }());
    exports.BulletTooltip = BulletTooltip;
});