all files / heatmap/utils/ tooltip.js

93.2% Statements 137/147
88.62% Branches 148/167
100% Functions 21/21
92.91% Lines 131/141
5 statements, 2 functions, 11 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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289    25× 25× 25×       129× 129× 129× 129×                         154× 154× 154×   682×   299× 234× 234× 182× 168×       168×     168×   182×     52×       153× 23×   153× 153×   38× 38× 38×   33×   38×   38×   38×   38×   38×   38×   38×     38×     38×     38×     38×               38×                                                                           202× 202× 202×     202× 202×     202× 202× 202×   53× 53× 53× 53× 53×                 50× 50×     53×   55× 55× 55× 55×         55×         53×                                         45× 45×       52× 38×     14× 14×                   52×     52× 52× 52× 52× 52× 52× 52×            
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        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 extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
/* istanbul ignore next */ 
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    Iif (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) Eif (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-svg-base", "../model/base", "../model/theme"], function (require, exports, ej2_base_1, ej2_svg_base_1, base_1, theme_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var TooltipSettings = (function (_super) {
        __extends(TooltipSettings, _super);
        function TooltipSettings() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        __decorate([
            ej2_base_1.Property('')
        ], TooltipSettings.prototype, "template", void 0);
        __decorate([
            ej2_base_1.Property('')
        ], TooltipSettings.prototype, "fill", void 0);
        __decorate([
            ej2_base_1.Complex({}, base_1.TooltipBorder)
        ], TooltipSettings.prototype, "border", void 0);
        __decorate([
            ej2_base_1.Complex(theme_1.Theme.tooltipFont, base_1.Font)
        ], TooltipSettings.prototype, "textStyle", void 0);
        return TooltipSettings;
    }(ej2_base_1.ChildProperty));
    exports.TooltipSettings = TooltipSettings;
    var Tooltip = (function () {
        function Tooltip(heatMap) {
            this.isFirst = true;
            this.isFadeout = false;
            this.heatMap = heatMap;
        }
        Tooltip.prototype.getModuleName = function () {
            return 'Tooltip';
        };
        Tooltip.prototype.showHideTooltip = function (isShow, isFadeout) {
            if (!ej2_base_1.isNullOrUndefined(this.heatMap)) {
                var ele = document.getElementById(this.heatMap.element.id + 'Celltooltipcontainer');
                if (!isShow) {
                    if (!ej2_base_1.isNullOrUndefined(ele) && ele.style.visibility !== 'hidden') {
                        Iif (!ej2_base_1.isNullOrUndefined(this.tooltipObject) && isFadeout && this.heatMap.isRectBoundary) {
                            this.tooltipObject.fadeOut();
                        }
                        else {
                            if (!ej2_base_1.isNullOrUndefined(this.tooltipObject) && !ej2_base_1.isNullOrUndefined(this.tooltipObject.element)) {
                                var tooltipElement = this.tooltipObject.element.firstChild;
                                tooltipElement.setAttribute('opacity', '0');
                            }
                        }
                        ele.style.visibility = 'hidden';
                    }
                    this.isFadeout = true;
                }
                else {
                    ele.style.visibility = 'visible';
                }
            }
        };
        Tooltip.prototype.destroy = function () {
            if (!ej2_base_1.isNullOrUndefined(this.tooltipObject)) {
                this.tooltipObject.destroy();
            }
            this.tooltipObject = null;
            this.heatMap = null;
        };
        Tooltip.prototype.createTooltip = function (currentRect, x, y, tempTooltipText) {
            var offset = null;
            var element = ej2_base_1.select('#' + this.heatMap.element.id + 'Celltooltipcontainer');
            if (this.heatMap.cellSettings.showLabel && this.heatMap.heatMapSeries.checkLabelXDisplay &&
                this.heatMap.heatMapSeries.checkLabelYDisplay) {
                offset = parseInt(this.heatMap.cellSettings.textStyle.size, 10) / 2;
            }
            if (this.heatMap.theme === 'Tailwind') {
                this.heatMap.setProperties({ tooltipSettings: { textStyle: { size: '12px', fontFamily: 'Inter', fontWeight: '500' } } }, true);
            }
            if (this.heatMap.theme === 'TailwindDark') {
                this.heatMap.setProperties({ tooltipSettings: { fill: '#F9FAFB', textStyle: { size: '12px', fontFamily: 'Inter', fontWeight: '500', color: '#1F2937' } } }, true);
            }
            if (this.heatMap.theme === 'Bootstrap5') {
                this.heatMap.setProperties({ tooltipSettings: { fill: '#000000', textStyle: { size: '12px', fontFamily: 'Segoe UI', fontWeight: '400', color: '#FFFFFF' } } }, true);
            }
            if (this.heatMap.theme === 'Bootstrap5Dark') {
                this.heatMap.setProperties({ tooltipSettings: { fill: '#FFFFFF', textStyle: { size: '12px', fontFamily: 'Segoe UI', fontWeight: '400', color: '#212529' } } }, true);
            }
            if (this.heatMap.theme === 'Fluent') {
                this.heatMap.setProperties({ tooltipSettings: { textStyle: { size: '12px', fontFamily: '"Segoe UI", -apple-system, BlinkMacSystemFont, "Roboto", "Helvetica Neue", sans-serif', fontWeight: '500' } } }, true);
            }
            if (this.heatMap.theme === 'FluentDark') {
                this.heatMap.setProperties({ tooltipSettings: { fill: '#252423', textStyle: { size: '12px', fontFamily: '"Segoe UI", -apple-system, BlinkMacSystemFont, "Roboto", "Helvetica Neue", sans-serif', fontWeight: '500', color: '#F3F2F1' } } }, true);
            }
            Iif (this.heatMap.theme === 'Material3') {
                this.heatMap.setProperties({ tooltipSettings: { fill: '#313033', textStyle: { size: '14px', fontFamily: 'Roboto', fontWeight: '400', color: '#F4EFF4' } } }, true);
            }
            Iif (this.heatMap.theme === 'Material3Dark') {
                this.heatMap.setProperties({ tooltipSettings: { fill: '#E6E1E5', textStyle: { size: '14px', fontFamily: 'Roboto', fontWeight: '400', color: '#313033' } } }, true);
            }
            Iif (this.heatMap.theme === 'Fluent2') {
                this.heatMap.setProperties({ tooltipSettings: { fill: '#FFFFFF', textStyle: { size: '12px', fontFamily: 'Segoe UI', fontWeight: '400', color: '#242424' } } }, true);
            }
            Iif (this.heatMap.theme === 'Fluent2Dark') {
                this.heatMap.setProperties({ tooltipSettings: { fill: '#292929', textStyle: { size: '12px', fontFamily: 'Segoe UI', fontWeight: '400', color: '#FFFFFF' } } }, true);
            }
            Iif (this.heatMap.theme === 'Fluent2HighContrast') {
                this.heatMap.setProperties({
                    tooltipSettings: {
                        fill: '#000000', textStyle: { size: '12px', fontFamily: 'Segoe UI', fontWeight: '400', color: '#FFFFFF' },
                        border: { width: 1, color: '#FFF' }
                    }
                }, true);
            }
            this.tooltipObject = new ej2_svg_base_1.Tooltip({
                opacity: (this.heatMap.theme === 'Tailwind' || this.heatMap.theme === 'TailwindDark' || this.heatMap.theme === 'Bootstrap5' || this.heatMap.theme === 'Bootstrap5Dark' || this.heatMap.theme === 'Fluent' || this.heatMap.theme === 'FluentDark'
                    || this.heatMap.theme === 'Fluent2' || this.heatMap.theme === 'Fluent2Dark' || this.heatMap.theme === 'Fluent2HighContrast') ? 1 : 0.75,
                enableAnimation: false,
                offset: offset,
                location: { x: x, y: y },
                availableSize: this.heatMap.availableSize,
                data: {
                    xValue: this.heatMap.heatMapSeries.hoverXAxisValue,
                    yValue: this.heatMap.heatMapSeries.hoverYAxisValue,
                    value: currentRect.value,
                    xLabel: this.heatMap.heatMapSeries.hoverXAxisLabel ?
                        this.heatMap.heatMapSeries.hoverXAxisLabel.toString() : null,
                    yLabel: this.heatMap.heatMapSeries.hoverYAxisLabel ?
                        this.heatMap.heatMapSeries.hoverYAxisLabel.toString() : null
                },
                theme: this.heatMap.theme,
                content: tempTooltipText,
                fill: this.heatMap.tooltipSettings.fill,
                enableShadow: true,
                template: this.heatMap.tooltipSettings.template === '' ? null : this.heatMap.tooltipSettings.template,
                border: {
                    width: this.heatMap.tooltipSettings.border.width,
                    color: this.heatMap.tooltipSettings.border.color
                },
                textStyle: {
                    size: this.heatMap.tooltipSettings.textStyle.size,
                    fontWeight: this.heatMap.tooltipSettings.textStyle.fontWeight.toLowerCase(),
                    color: this.heatMap.tooltipSettings.textStyle.color,
                    fontStyle: this.heatMap.tooltipSettings.textStyle.fontStyle.toLowerCase(),
                    fontFamily: this.heatMap.tooltipSettings.textStyle.fontFamily
                },
                areaBounds: {
                    height: this.heatMap.initialClipRect.height + this.heatMap.initialClipRect.y,
                    width: this.heatMap.initialClipRect.width, x: this.heatMap.initialClipRect.x
                }
            }, element);
        };
        Tooltip.prototype.createTooltipDiv = function (heatMap) {
            var position = 'absolute';
            var top = heatMap.enableCanvasRendering && heatMap.allowSelection ? heatMap.availableSize.height : 0;
            var element2 = ej2_base_1.createElement('div', {
                id: this.heatMap.element.id + 'Celltooltipcontainer'
            });
            element2.style.cssText = 'position:' + position + '; z-index: 3;top:-' + top + 'px';
            var tooltipElement = ej2_base_1.createElement('div', {
                id: this.heatMap.element.id + 'Celltooltipparent'
            });
            tooltipElement.style.position = 'relative';
            tooltipElement.appendChild(element2);
            this.heatMap.element.appendChild(tooltipElement);
        };
        Tooltip.prototype.getTooltipContent = function (currentRect, hetmapSeries) {
            var value;
            var content;
            var heatMap = this.heatMap;
            var adaptData = this.heatMap.dataSourceSettings;
            if (heatMap.bubbleSizeWithColor) {
                var xAxis = heatMap.xAxis.title && heatMap.xAxis.title.text !== '' ? heatMap.xAxis.title.text : 'X-Axis';
                var yAxis = heatMap.yAxis.title && heatMap.yAxis.title.text !== '' ? heatMap.yAxis.title.text : 'Y-Axis';
                var value1 = adaptData.isJsonData && adaptData.adaptorType === 'Cell' ?
                    adaptData.bubbleDataMapping.size : 'Value 1';
                var value2 = adaptData.isJsonData && adaptData.adaptorType === 'Cell' ?
                    adaptData.bubbleDataMapping.color : 'Value 2';
                value = hetmapSeries.getFormatedText(currentRect.value[0].bubbleData, this.heatMap.cellSettings.format);
                content = [xAxis + ' : ' + hetmapSeries.hoverXAxisLabel + '<br/>'
                        + yAxis + ' : ' + hetmapSeries.hoverYAxisLabel + '<br/>'
                        + value1 + ' : ' + value + '<br/>'
                        + value2 + ' : '
                        + hetmapSeries.getFormatedText(currentRect.value[1].bubbleData, this.heatMap.cellSettings.format)];
            }
            else {
                value = currentRect.value;
                content = [hetmapSeries.hoverXAxisLabel + ' | ' + hetmapSeries.hoverYAxisLabel + ' : ' +
                        hetmapSeries.getFormatedText(value, this.heatMap.cellSettings.format)];
            }
            return content;
        };
        Tooltip.prototype.renderTooltip = function (currentRect) {
            var _this = this;
            var hetmapSeries = this.heatMap.heatMapSeries;
            var tempTooltipText = [''];
            var showTooltip = this.heatMap.bubbleSizeWithColor ?
                !ej2_base_1.isNullOrUndefined(currentRect.value) && !ej2_base_1.isNullOrUndefined(currentRect.value[0].bubbleData)
                    && currentRect.value[0].bubbleData.toString() !== '' ? true : false
                : ej2_base_1.isNullOrUndefined(currentRect.value) || (!ej2_base_1.isNullOrUndefined(currentRect.value) &&
                    currentRect.value.toString() === '') ? false : true;
            if (!showTooltip) {
                this.showHideTooltip(false, false);
                Iif (!currentRect.visible) {
                    this.showHideTooltip(false, false);
                }
            }
            else {
                if (!ej2_base_1.isNullOrUndefined(this.heatMap.tooltipRender)) {
                    var content = this.getTooltipContent(currentRect, hetmapSeries);
                    var argData = {
                        heatmap: this.heatMap,
                        cancel: false,
                        name: 'tooltipRender',
                        value: currentRect.value,
                        xValue: this.heatMap.heatMapSeries.hoverXAxisValue,
                        yValue: this.heatMap.heatMapSeries.hoverYAxisValue,
                        xLabel: this.heatMap.heatMapSeries.hoverXAxisLabel ?
                            this.heatMap.heatMapSeries.hoverXAxisLabel.toString() : null,
                        yLabel: this.heatMap.heatMapSeries.hoverYAxisLabel ?
                            this.heatMap.heatMapSeries.hoverYAxisLabel.toString() : null,
                        content: content
                    };
                    this.heatMap.trigger('tooltipRender', argData, function (observedArgs) {
                        if (!observedArgs.cancel) {
                            tempTooltipText = observedArgs.content;
                            _this.tooltipCallback(currentRect, tempTooltipText);
                        }
                        else {
                            Iif (_this.tooltipObject) {
                                _this.showHideTooltip(false);
                            }
                        }
                    });
                }
                else {
                    tempTooltipText = this.getTooltipContent(currentRect, hetmapSeries);
                    this.tooltipCallback(currentRect, tempTooltipText);
                }
            }
        };
        Tooltip.prototype.tooltipCallback = function (currentRect, tempTooltipText) {
            if (!this.tooltipObject) {
                this.createTooltip(currentRect, currentRect.x + (currentRect.width / 2), currentRect.y + (currentRect.height / 2), tempTooltipText);
            }
            else {
                this.tooltipObject.content = tempTooltipText;
                this.tooltipObject.data = {
                    xValue: this.heatMap.heatMapSeries.hoverXAxisValue,
                    yValue: this.heatMap.heatMapSeries.hoverYAxisValue,
                    xLabel: this.heatMap.heatMapSeries.hoverXAxisLabel ?
                        this.heatMap.heatMapSeries.hoverXAxisLabel.toString() : null,
                    yLabel: this.heatMap.heatMapSeries.hoverYAxisLabel ?
                        this.heatMap.heatMapSeries.hoverYAxisLabel.toString() : null,
                    value: currentRect.value
                };
            }
            Iif (this.heatMap.isVue || this.heatMap.isVue3) {
                this.tooltipObject.controlInstance = this.heatMap;
            }
            this.showHideTooltip(true);
            this.tooltipObject.enableAnimation = (this.isFirst || this.isFadeout) ? false : true;
            this.isFirst = (this.isFirst) ? false : this.isFirst;
            this.isFadeout = (this.isFadeout) ? false : this.isFadeout;
            this.tooltipObject.location.x = currentRect.x + (currentRect.width / 2);
            this.tooltipObject.location.y = currentRect.y + (currentRect.height / 2);
            Iif (!currentRect.visible) {
                this.showHideTooltip(false, false);
            }
        };
        return Tooltip;
    }());
    exports.Tooltip = Tooltip;
});