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

98.28% Statements 114/116
87.65% Branches 71/81
100% Functions 24/24
98.23% Lines 111/113
11 statements, 6 functions, 9 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          89× 89× 89× 89× 89×   89×     89× 89× 89×         24× 24× 23×     24×   29× 29× 29× 29× 29× 29× 22×       22× 22×             22× 22× 22×               22× 22× 21× 21× 21× 21×         22×   22× 22×   24× 24× 24× 20× 20× 20× 20× 20× 18×         20×   22× 22× 22× 22×   22× 14×       30× 30× 30× 30× 949× 949× 949×   949×   30× 1770× 1770× 1770× 1770×   30×   3272×          
/* 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 __());
    };
})();
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../../common/utils/helper", "../../common/user-interaction/tooltip", "../../common/model/constants"], function (require, exports, ej2_base_1, ej2_base_2, helper_1, tooltip_1, constants_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var AccumulationTooltip = (function (_super) {
        __extends(AccumulationTooltip, _super);
        function AccumulationTooltip(accumulation) {
            var _this = _super.call(this, accumulation) || this;
            _this.accumulation = accumulation;
            _this.addEventListener();
            _this.template = _this.accumulation.tooltip.template;
            return _this;
        }
        AccumulationTooltip.prototype.addEventListener = function () {
            Iif (this.accumulation.isDestroyed) {
                return;
            }
            this.accumulation.on(ej2_base_1.Browser.isPointer ? 'pointerleave' : 'mouseleave', this.mouseLeaveHandler, this);
            this.accumulation.on(ej2_base_1.Browser.touchMoveEvent, this.mouseMoveHandler, this);
            this.accumulation.on(ej2_base_1.Browser.touchEndEvent, this.mouseUpHandler, this);
        };
        AccumulationTooltip.prototype.mouseLeaveHandler = function () {
            this.removeTooltip(this.accumulation.tooltip.fadeOutDuration);
        };
        AccumulationTooltip.prototype.mouseUpHandler = function (e) {
            var control = this.accumulation;
            if (control.tooltip.enable && control.isTouch && helper_1.withInBounds(control.mouseX, control.mouseY, control.initialClipRect)) {
                this.tooltip(e);
                this.removeTooltip(2000);
            }
        };
        AccumulationTooltip.prototype.mouseMoveHandler = function (e) {
            var control = this.accumulation;
            if (control.tooltip.enable && helper_1.withInBounds(control.mouseX, control.mouseY, control.initialClipRect)) {
                this.tooltip(e);
            }
        };
        AccumulationTooltip.prototype.tooltip = function (event) {
            this.renderSeriesTooltip(this.accumulation, this.getPieData(event, this.accumulation));
        };
        AccumulationTooltip.prototype.renderSeriesTooltip = function (chart, data) {
            var svgElement = this.getElement(this.element.id + '_tooltip_svg');
            var isTooltip = svgElement && parseInt(svgElement.getAttribute('opacity'), 10) > 0;
            var tooltipDiv = this.getTooltipElement(isTooltip);
            var isFirst = !isTooltip;
            this.currentPoints = [];
            if (data.point && (!this.previousPoints[0] || (this.previousPoints[0].point !== data.point))) {
                Iif (this.previousPoints[0] && data.point.index === this.previousPoints[0].point.index
                    && data.series.index === this.previousPoints[0].series.index) {
                    return null;
                }
                Eif (this.pushData(data, isFirst, tooltipDiv, false)) {
                    this.triggerTooltipRender(data, isFirst, this.getTooltipText(data, chart.tooltip), this.findHeader(data));
                }
            }
            else {
                if (!data.point && this.isRemove) {
                    this.removeTooltip(this.accumulation.tooltip.fadeOutDuration);
                    this.isRemove = false;
                }
            }
        };
        AccumulationTooltip.prototype.triggerTooltipRender = function (point, isFirst, textCollection, headerText) {
            var _this = this;
            var tooltip = this.chart.tooltip;
            var argsData = {
                cancel: false, name: constants_1.tooltipRender, text: textCollection, point: point.point, textStyle: this.textStyle,
                series: this.accumulation.isBlazor ? {} : point.series, headerText: headerText,
                data: {
                    pointX: point.point.x, pointY: point.point.y, seriesIndex: point.series.index,
                    pointIndex: point.point.index, pointText: point.point.text, seriesName: point.series.name
                }
            };
            var tooltipSuccess = function (argsData) {
                if (!argsData.cancel) {
                    _this.formattedText = _this.formattedText.concat(argsData.text);
                    _this.text = _this.formattedText;
                    _this.headerText = argsData.headerText;
                    _this.createTooltip(_this.chart, isFirst, { x: (tooltip.location.x !== null) ? tooltip.location.x :
                            point.point.symbolLocation.x, y: (tooltip.location.y !== null) ? tooltip.location.y : point.point.symbolLocation.y }, point.series.clipRect, point.point, !tooltip.enableMarker ? [] : ['Circle'], 0, _this.chart.initialClipRect, false, null, point.point, _this.template ? _this.accumulation.enableHtmlSanitizer ? _this.accumulation.sanitize(_this.template) : argsData.template : '');
                }
                else {
                    _this.removeHighlight();
                    ej2_base_1.remove(_this.getElement(_this.element.id + '_tooltip'));
                }
                _this.isRemove = true;
            };
            tooltipSuccess.bind(this, point);
            this.chart.trigger(constants_1.tooltipRender, argsData, tooltipSuccess);
        };
        AccumulationTooltip.prototype.getPieData = function (e, chart) {
            var target = e.target;
            var id = helper_1.indexFinder(target.id, true);
            if (!isNaN(id.series)) {
                var seriesIndex = id.series;
                var pointIndex = id.point;
                Eif (!ej2_base_2.isNullOrUndefined(seriesIndex) && !isNaN(seriesIndex) && !ej2_base_2.isNullOrUndefined(pointIndex) && !isNaN(pointIndex)) {
                    var series = this.getSeriesFromIndex(seriesIndex, chart.visibleSeries);
                    if (series.enableTooltip) {
                        return new helper_1.AccPointData(series.points[pointIndex], series);
                    }
                }
            }
            return new helper_1.AccPointData(null, null);
        };
        AccumulationTooltip.prototype.getSeriesFromIndex = function (index, visibleSeries) {
            return visibleSeries[0];
        };
        AccumulationTooltip.prototype.getTooltipText = function (data, tooltip) {
            var series = data.series;
            var format = tooltip.format ? tooltip.format : '${point.x} : <b>${point.y}</b>';
            format = this.accumulation.useGroupingSeparator ? format.replace('${point.y}', '${point.separatorY}') : format;
            return this.parseTemplate(data.point, series, format);
        };
        AccumulationTooltip.prototype.findHeader = function (data) {
            if (this.header === '') {
                return '';
            }
            this.header = this.parseTemplate(data.point, data.series, this.header);
            if (this.header.replace(/<b>/g, '').replace(/<\/b>/g, '').trim() !== '') {
                return this.header;
            }
            return '';
        };
        AccumulationTooltip.prototype.parseTemplate = function (point, series, format) {
            var value;
            var textValue;
            var regExp = RegExp;
            for (var _i = 0, _a = Object.keys(point); _i < _a.length; _i++) {
                var dataValue = _a[_i];
                value = new regExp('${point' + '.' + dataValue + '}', 'gm');
                var pointValue = (dataValue === 'x' && this.accumulation.useGroupingSeparator && typeof point[dataValue] === 'number') ?
                    this.accumulation.intl.formatNumber(point.x, { useGrouping: true }) : point[dataValue];
                format = format.replace(value.source, pointValue);
            }
            for (var _b = 0, _c = Object.keys(Object.getPrototypeOf(series)); _b < _c.length; _b++) {
                var dataValue = _c[_b];
                value = new regExp('${series' + '.' + dataValue + '}', 'gm');
                textValue = series[dataValue];
                format = format.replace(value.source, textValue);
            }
            return format;
        };
        AccumulationTooltip.prototype.getModuleName = function () {
            return 'AccumulationTooltip';
        };
        AccumulationTooltip.prototype.destroy = function () {
        };
        return AccumulationTooltip;
    }(tooltip_1.BaseTooltip));
    exports.AccumulationTooltip = AccumulationTooltip;
});