all files / chart3d/user-interaction/ tooltip.js

92.93% Statements 263/283
85.24% Branches 179/210
92.31% Functions 36/39
92.78% Lines 257/277
18 statements, 7 functions, 29 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 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423              54×                                                                 129× 129× 129× 129× 129×   129×     129× 129× 129× 129× 129×   129× 18×   111× 111× 111× 111× 111×                                           38× 38× 38× 38× 38× 37×           130× 117× 117× 117× 117× 117×     37× 37× 37× 37× 37× 37×     31× 10×   21× 21× 20×     37× 37× 37×     26× 26×     11×   37× 27×     31× 31× 31×               31× 31× 31× 31× 31× 31× 31× 31× 31×           31×   31× 31×   31× 31× 31× 53× 53× 22× 22× 1231×     31× 31× 31× 1712× 1712× 1712× 96×   1712×       31× 1231× 1231× 1231× 1231× 953×           330× 330× 330× 330× 330× 330×         31× 31× 31×     29×   31× 31× 31× 30×           31×       31×     31×   31×   31× 12× 12× 12× 12×     19×     27× 19×   19×           52× 52× 52× 52× 1248× 1248× 1248×   52× 3016× 3016× 3016× 3016×   52×   1272× 1272× 1272× 1272× 49× 49×     1223× 64× 64× 64×     1159×   1272×   31×     31×     31× 31× 31×   39× 39× 39× 39× 39× 39× 39× 39× 39× 39× 39×   29× 29× 29× 29× 29×     39× 29×   39× 29× 29×   29× 29×     10×   39×   4177×   129×        
/* 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;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (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", "../../common/utils/helper", "@syncfusion/ej2-svg-base", "../../common/user-interaction/tooltip", "../../common/model/constants", "@syncfusion/ej2-base", "../../common/model/base", "../../common/model/base", "../utils/chart3dRender"], function (require, exports, ej2_base_1, helper_1, ej2_svg_base_1, tooltip_1, constants_1, ej2_base_2, base_1, base_2, chart3dRender_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Chart3DTooltipSettings = (function (_super) {
        __extends(Chart3DTooltipSettings, _super);
        function Chart3DTooltipSettings() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        __decorate([
            ej2_base_1.Property(false)
        ], Chart3DTooltipSettings.prototype, "enable", void 0);
        __decorate([
            ej2_base_1.Property(true)
        ], Chart3DTooltipSettings.prototype, "enableMarker", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], Chart3DTooltipSettings.prototype, "fill", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], Chart3DTooltipSettings.prototype, "header", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], Chart3DTooltipSettings.prototype, "opacity", void 0);
        __decorate([
            ej2_base_1.Complex({ fontFamily: null, size: '12px', fontStyle: 'Normal', fontWeight: null, color: null }, base_1.Font)
        ], Chart3DTooltipSettings.prototype, "textStyle", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], Chart3DTooltipSettings.prototype, "format", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], Chart3DTooltipSettings.prototype, "template", void 0);
        __decorate([
            ej2_base_1.Property(true)
        ], Chart3DTooltipSettings.prototype, "enableAnimation", void 0);
        __decorate([
            ej2_base_1.Property(300)
        ], Chart3DTooltipSettings.prototype, "duration", void 0);
        __decorate([
            ej2_base_1.Property(1000)
        ], Chart3DTooltipSettings.prototype, "fadeOutDuration", void 0);
        __decorate([
            ej2_base_1.Property('Move')
        ], Chart3DTooltipSettings.prototype, "fadeOutMode", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], Chart3DTooltipSettings.prototype, "enableTextWrap", void 0);
        __decorate([
            ej2_base_1.Complex({ color: null, width: null }, base_1.Border)
        ], Chart3DTooltipSettings.prototype, "border", void 0);
        __decorate([
            ej2_base_1.Complex({ x: null, y: null }, base_2.Location)
        ], Chart3DTooltipSettings.prototype, "location", void 0);
        return Chart3DTooltipSettings;
    }(ej2_base_1.ChildProperty));
    exports.Chart3DTooltipSettings = Chart3DTooltipSettings;
    var Tooltip3D = (function (_super) {
        __extends(Tooltip3D, _super);
        function Tooltip3D(chart) {
            var _this = _super.call(this, chart) || this;
            _this.chart3D = chart;
            _this.commonXvalues = [];
            _this.addEventListener();
            return _this;
        }
        Tooltip3D.prototype.addEventListener = function () {
            Iif (this.chart.isDestroyed) {
                return;
            }
            var cancelEvent = ej2_base_1.Browser.isPointer ? 'pointerleave' : 'mouseleave';
            this.chart.on(cancelEvent, this.mouseLeaveHandler, this);
            this.chart.on('tapHold', this.longPress, this);
            this.chart.on(ej2_base_1.Browser.touchMoveEvent, this.mouseMoveHandler, this);
            this.chart.on(ej2_base_1.Browser.touchEndEvent, this.mouseUpHandler, this);
        };
        Tooltip3D.prototype.removeEventListener = function () {
            if (this.chart.isDestroyed) {
                return;
            }
            this.chart.off('pointerleave' || 'mouseleave', this.mouseLeaveHandler);
            this.chart.off('tapHold', this.longPress);
            this.chart.off(ej2_base_1.Browser.touchMoveEvent, this.mouseLeaveHandler);
            this.chart.off(ej2_base_1.Browser.touchMoveEvent, this.mouseMoveHandler);
            this.chart.off(ej2_base_1.Browser.touchEndEvent, this.mouseUpHandler);
        };
        Tooltip3D.prototype.mouseUpHandler = function (event) {
            var _this = this;
            var chart = this.control;
            var data = this.get3dData(event);
            Iif (chart.isTouch) {
                this.tooltip(event);
                if (chart.tooltip.fadeOutMode === 'Move') {
                    this.removeTooltip(chart.tooltip.fadeOutDuration);
                    clearTimeout(this.timerId);
                    this.timerId = +setTimeout(function () {
                        _this.removeBlurEffect();
                    }, 500);
                }
                if (chart.startMove && chart.tooltip.fadeOutMode === 'Move') {
                    this.removeTooltip(2000);
                    this.removeBlurEffect();
                }
            }
            else Iif (!this.findData(data, this.previousPoints[0]) && chart.tooltip.fadeOutMode === 'Click') {
                this.removeTooltip(0);
                this.removeBlurEffect();
            }
        };
        Tooltip3D.prototype.mouseLeaveHandler = function () {
            this.removeTooltip(this.chart.tooltip.fadeOutDuration);
            this.removeBlurEffect();
        };
        Tooltip3D.prototype.mouseMoveHandler = function (event) {
            var chart = this.chart3D;
            chart.mouseX = chart.mouseX / chart.scaleX;
            chart.mouseY = chart.mouseY / chart.scaleY;
            Eif (!chart.disableTrackTooltip && !chart.rotateActivate) {
                if (!chart.isTouch || (chart.startMove)) {
                    this.tooltip(event);
                }
            }
        };
        Tooltip3D.prototype.longPress = function () {
            return false;
        };
        Tooltip3D.prototype.seriesStyles = function () {
            if (!this.styleAdded) {
                var style = document.createElement('style');
                style.setAttribute('id', this.element.id + '_ej2_chart_tooltip');
                style.innerText += ' .' + this.element.id + '_ej2_tooltipDeselected { opacity:' + (0.2) + ';} ';
                document.body.appendChild(style);
                this.styleAdded = true;
            }
        };
        Tooltip3D.prototype.tooltip = function (e) {
            var elementId = this.element.id + '_tooltip_svg';
            var svgElement = this.getElement(elementId);
            var isTooltip = (svgElement && parseInt(svgElement.getAttribute('opacity'), 10) > 0);
            var tooltipDiv = this.getTooltipElement(isTooltip);
            Eif (this.chart3D.tooltip3DModule) {
                this.renderSeriesTooltip(this.chart3D, !isTooltip, tooltipDiv, e);
            }
        };
        Tooltip3D.prototype.findHeader = function (data) {
            if (this.header === '') {
                return '';
            }
            this.header = this.parseTemplate(data.point, data.series, this.header, data.series.xAxis, data.series.yAxis);
            if (this.header.replace(/<b>/g, '').replace(/<\/b>/g, '').trim() !== '') {
                return this.header;
            }
            return '';
        };
        Tooltip3D.prototype.renderSeriesTooltip = function (chart, isFirst, tooltipDiv, e) {
            var data = this.get3dData(e);
            this.currentPoints = [];
            if (this.findData(data, this.previousPoints[0]) &&
                ((this.previousPoints[0] && !((this.previousPoints[0].point.index === data.point.index && this.previousPoints[0].series.index
                    === data.series.index) && this.chart3D.isRemove)) || !this.previousPoints[0])) {
                Eif (this.pushData(data, isFirst, tooltipDiv, true)) {
                    this.triggerTooltipRender(data, isFirst, this.getTooltipText(data), this.findHeader(data));
                }
            }
            else if (!data.point && this.chart3D.isRemove && chart.tooltip.fadeOutMode === 'Move') {
                this.removeTooltip(this.chart.tooltip.fadeOutDuration);
                this.removeBlurEffect();
                this.chart3D.isRemove = false;
            }
            if (data && data.point) {
                this.findMouseValue(data, chart);
            }
        };
        Tooltip3D.prototype.triggerTooltipRender = function (point, isFirst, textCollection, headerText) {
            var _this = this;
            var tooltipTemplate;
            var argsData = {
                cancel: false, text: textCollection, headerText: headerText, template: tooltipTemplate,
                textStyle: this.textStyle,
                data: {
                    pointX: point.point.x, pointY: point.point.y, seriesIndex: point.series.index, seriesName: point.series.name,
                    pointIndex: point.point.index, pointText: point.point.text
                }
            };
            var borderWidth = this.chart.border.width;
            var padding = 3;
            var chartTooltipSuccess = function (argsData) {
                Eif (!argsData.cancel) {
                    _this.headerText = argsData.headerText;
                    _this.formattedText = _this.formattedText.concat(argsData.text);
                    _this.text = _this.formattedText;
                    _this.createTooltip(_this.chart, isFirst, _this.getSymbolLocation(point), point.series.clipRect, point.point, _this.chart3D.tooltip.enableMarker ? ['Circle'] : [], 0, new ej2_svg_base_1.Rect(borderWidth, borderWidth, _this.chart.availableSize.width - padding - borderWidth * 2, _this.chart.availableSize.height - padding - borderWidth * 2), false, null, _this.getTemplateText(point), _this.template ? argsData.template : '');
                    _this.blurEffect(_this.chart3D.visibleSeries, point.series);
                }
                else {
                    _this.removeHighlight();
                    ej2_base_1.remove(_this.getElement(_this.element.id + '_tooltip'));
                }
                _this.chart3D.isRemove = true;
            };
            chartTooltipSuccess.bind(this, point);
            this.chart.trigger(constants_1.tooltipRender, argsData, chartTooltipSuccess);
        };
        Tooltip3D.prototype.blurEffect = function (visibleSeries, tooltipSeries) {
            Eif (!this.chart3D.highlight3DModule || (this.chart3D.legendSettings.enableHighlight && this.chart3D.highlightMode === 'None')) {
                var pointElements_1 = [];
                for (var _i = 0, visibleSeries_1 = visibleSeries; _i < visibleSeries_1.length; _i++) {
                    var series = visibleSeries_1[_i];
                    if (series.visible && series.index !== tooltipSeries.index) {
                        var elements = document.querySelectorAll("[id*=\"region-series-" + series.index + "\"]");
                        elements.forEach(function (el) {
                            pointElements_1.push(el);
                        });
                    }
                    else Eif (series.visible) {
                        var tooltipElements = document.querySelectorAll("[id*=\"region-series-" + series.index + "\"]");
                        for (var i = 0; i < tooltipElements.length; i++) {
                            var element = tooltipElements[i];
                            var elementClassName = element.getAttribute('class') || '';
                            if (elementClassName.indexOf(this.element.id + '_ej2_tooltipDeselected') > -1) {
                                element.setAttribute('class', elementClassName.replace(this.element.id + '_ej2_tooltipDeselected', ''));
                            }
                            this.chart3D.stopElementAnimation(element, series.index);
                        }
                    }
                }
                for (var i = 0; i < pointElements_1.length; i++) {
                    Eif (pointElements_1[i]) {
                        var elementClassName = pointElements_1[i].getAttribute('class') || '';
                        elementClassName += ((elementClassName !== '') ? ' ' : '');
                        if (elementClassName.indexOf('_selection_') === -1 && elementClassName.indexOf(this.element.id + '_ej2_tooltipDeselected') === -1) {
                            pointElements_1[i].setAttribute('class', elementClassName + this.element.id + '_ej2_tooltipDeselected');
                        }
                    }
                }
            }
        };
        Tooltip3D.prototype.removeBlurEffect = function () {
            Eif (!this.chart3D.highlight3DModule || (this.chart3D.legendSettings.enableHighlight && this.chart3D.highlightMode === 'None')) {
                var elements = document.getElementsByClassName(this.element.id + '_ej2_tooltipDeselected');
                while (elements.length > 0) {
                    var element = elements[0];
                    var elementClassName = element.getAttribute('class') || '';
                    Eif (elementClassName.indexOf(this.element.id + '_ej2_tooltipDeselected') > -1) {
                        element.setAttribute('class', elementClassName.replace(this.element.id + '_ej2_tooltipDeselected', ''));
                        var index = parseFloat(element.id.split('-series-')[1].split('-point-')[0]);
                        this.chart3D.highlightAnimation(element, index, 700, 0.2);
                    }
                }
            }
        };
        Tooltip3D.prototype.getSymbolLocation = function (point) {
            var rect = document.getElementById(this.element.id + '_svg').getBoundingClientRect();
            var upperElement;
            if (point.series.columnFacet === 'Cylinder') {
                upperElement = document.querySelectorAll('[id*="' + this.element.id + '-svg-' + (point.series.type.indexOf('Column') === -1 ? '0' : '1') + '-region-series-' + point.series.index + '-point-' + point.point.index + '"]');
            }
            else {
                upperElement = document.querySelectorAll('[id*="' + this.element.id + '-svg-' + (point.series.type.indexOf('Column') === -1 ? '5' : '2') + '-region-series-' + point.series.index + '-point-' + point.point.index + '"]');
            }
            var tooltipElement;
            Eif (upperElement) {
                if (upperElement.length === 1) {
                    tooltipElement = upperElement[0].getBoundingClientRect();
                }
                else {
                    for (var i = 0; i < upperElement.length; i++) {
                        var element = upperElement[i];
                        if (element.id.indexOf('-' + point.point.index + '-back-front') !== -1 || element.id.indexOf('-' + point.point.index + '-front-back') !== -1) {
                            tooltipElement = element.getBoundingClientRect();
                            break;
                        }
                    }
                }
                Iif (upperElement.length !== 0 && !tooltipElement) {
                    tooltipElement = upperElement[0].getBoundingClientRect();
                }
            }
            var location = new helper_1.ChartLocation((this.chart3D.tooltip.location.x !== null) ? this.chart3D.tooltip.location.x :
                tooltipElement.left - rect.left + (tooltipElement.width / 2), (this.chart3D.tooltip.location.y !== null) ?
                this.chart3D.tooltip.location.y : tooltipElement.top - rect.top + (tooltipElement.height / 2));
            return location;
        };
        Tooltip3D.prototype.getTooltipText = function (pointData) {
            return this.parseTemplate(pointData.point, pointData.series, this.getFormat(this.chart3D, pointData.series), pointData.series.xAxis, pointData.series.yAxis);
        };
        Tooltip3D.prototype.getTemplateText = function (data) {
            if (this.template) {
                var point = ej2_base_1.extend({}, data.point);
                point.x = this.formatPointValue(data.point, data.series.xAxis, 'x', true, false);
                point.y = this.formatPointValue(data.point, data.series.yAxis, 'y', false, true);
                return point;
            }
            else {
                return data.point;
            }
        };
        Tooltip3D.prototype.findMouseValue = function (data, chart) {
            if (!chart.requireInvertedAxis) {
                this.valueX = chart3dRender_1.valueToCoefficients(data.point.xValue, data.series.xAxis) *
                    data.series.xAxis.rect.width + data.series.xAxis.rect.x;
                this.valueY = chart.mouseY;
            }
            else {
                this.valueY = (1 - chart3dRender_1.valueToCoefficients(data.point.xValue, data.series.xAxis)) * data.series.xAxis.rect.height
                    + data.series.xAxis.rect.y;
                this.valueX = chart.mouseX;
            }
        };
        Tooltip3D.prototype.parseTemplate = function (point, series, format, xAxis, yAxis) {
            var val;
            var textValue;
            var regExp = RegExp;
            for (var _i = 0, _a = Object.keys(point); _i < _a.length; _i++) {
                var dataValue = _a[_i];
                val = new regExp('${point' + '.' + dataValue + '}', 'gm');
                format = format.replace(val.source, this.formatPointValue(point, val.source === '${point.x}' ? xAxis : yAxis, dataValue, val.source === '${point.x}', (val.source === '${point.y}')));
            }
            for (var _b = 0, _c = Object.keys(Object.getPrototypeOf(series)); _b < _c.length; _b++) {
                var dataValue = _c[_b];
                val = new regExp('${series' + '.' + dataValue + '}', 'gm');
                textValue = series[dataValue];
                format = format.replace(val.source, textValue);
            }
            return format;
        };
        Tooltip3D.prototype.formatPointValue = function (point, axis, dataValue, isXPoint, isYPoint) {
            var textValue;
            var customLabelFormat;
            var value;
            if (axis.valueType !== 'Category' && isXPoint) {
                customLabelFormat = axis.labelFormat && axis.labelFormat.match('{value}') !== null;
                textValue = customLabelFormat ? axis.labelFormat.replace('{value}', axis.format(point[dataValue])) :
                    axis.format(point[dataValue]);
            }
            else if (isYPoint && !ej2_base_2.isNullOrUndefined(point[dataValue])) {
                customLabelFormat = axis.labelFormat && axis.labelFormat.match('{value}') !== null;
                value = axis.format(point[dataValue]);
                textValue = customLabelFormat ? axis.labelFormat.replace('{value}', value) : value;
            }
            else {
                textValue = point[dataValue];
            }
            return textValue;
        };
        Tooltip3D.prototype.getFormat = function (chart, series) {
            Iif (series.tooltipFormat) {
                return series.tooltipFormat;
            }
            Iif (!series.tooltipFormat && chart.tooltip.format) {
                return chart.tooltip.format;
            }
            var textX = '${point.x}';
            var format = textX;
            return format + ' : ' + ('<b>${point.y}</b>');
        };
        Tooltip3D.prototype.get3dData = function (event) {
            var chart = this.chart3D;
            var point = null;
            var series = null;
            var currentX = this.chart3D.mouseX;
            var currentY = this.chart3D.mouseY;
            var rect = this.chart3D.chartAxisLayoutPanel.seriesClipRect;
            var index;
            var pointIndex;
            var seriesIndex;
            var targetElement = event.target;
            if (targetElement && currentX > rect.x && currentX < (rect.x + rect.width) &&
                currentY > rect.y && currentY < (rect.y + rect.height)) {
                var nodeName = targetElement.nodeName;
                Eif ((nodeName === 'shape' || nodeName === 'path') && targetElement.id.indexOf('region') > 1) {
                    index = targetElement.id.match(/(\d+)/g);
                    pointIndex = parseInt(index[index.length - 1].toString(), 10);
                    seriesIndex = parseInt(index[index.length - 2].toString(), 10);
                }
            }
            if (!ej2_base_2.isNullOrUndefined(seriesIndex)) {
                series = chart.visibleSeries[seriesIndex];
            }
            if (series) {
                Eif (series.visible) {
                    point = series.points[pointIndex];
                }
                Eif (point) {
                    return new helper_1.Point3D(point, series);
                }
            }
            return new helper_1.Point3D(point, series);
        };
        Tooltip3D.prototype.findData = function (data, previous) {
            return data.point && ((!previous || (previous.point !== data.point)) || (previous.point === data.point));
        };
        Tooltip3D.prototype.getModuleName = function () {
            return 'Tooltip3D';
        };
        Tooltip3D.prototype.destroy = function () {
            this.removeEventListener();
        };
        return Tooltip3D;
    }(tooltip_1.BaseTooltip));
    exports.Tooltip3D = Tooltip3D;
});