all files / maps/user-interaction/ annotation.js

100% Statements 73/73
86.67% Branches 26/30
100% Functions 9/9
100% Lines 73/73
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   27×   27× 27× 27× 27× 27× 27× 27× 30× 30×     27× 27×   27×   30× 30× 30× 30× 30× 30× 30× 30×     30× 30×       30× 30×   29× 29× 23× 23× 23× 27×               30× 30× 30× 30× 30× 30× 30× 30×   30×   30× 30× 30×         30×         30× 30× 30×   3430×   27×        
define(["require", "exports", "../index", "@syncfusion/ej2-base", "../utils/helper"], function (require, exports, index_1, ej2_base_1, helper_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Annotations = (function () {
        function Annotations(map) {
            this.map = map;
        }
        Annotations.prototype.renderAnnotationElements = function () {
            var _this = this;
            var secondaryID = this.map.element.id + '_Secondary_Element';
            var annotationGroup = ej2_base_1.createElement('div', { id: this.map.element.id + '_Annotations_Group' });
            annotationGroup.style.position = 'absolute';
            annotationGroup.style.top = '0px';
            annotationGroup.style.left = '0px';
            this.map.annotations.map(function (annotation, index) {
                Eif (annotation.content !== null) {
                    _this.createAnnotationTemplate(annotationGroup, annotation, index);
                }
            });
            Eif (annotationGroup.childElementCount > 0 && !(ej2_base_1.isNullOrUndefined(helper_1.getElementByID(secondaryID)))) {
                helper_1.getElementByID(secondaryID).appendChild(annotationGroup);
            }
            this.map.renderReactTemplates();
        };
        Annotations.prototype.createAnnotationTemplate = function (parentElement, annotation, annotationIndex) {
            var _this = this;
            var left;
            var top;
            var templateFn;
            var map = this.map;
            var templateElement;
            var availSize = map.availableSize;
            var childElement = ej2_base_1.createElement('div', {
                id: map.element.id + '_Annotation_' + annotationIndex
            });
            childElement.style.cssText = 'position: absolute; z-index:' + annotation.zIndex + ';';
            var argsData = {
                cancel: false, name: index_1.annotationRendering, content: annotation.content,
                annotation: annotation
            };
            this.map.trigger(index_1.annotationRendering, argsData, function (annotationArgs) {
                if (argsData.cancel) {
                    return;
                }
                templateFn = helper_1.getTemplateFunction(argsData.content, _this.map);
                if (templateFn && templateFn(_this.map, _this.map, argsData.content, _this.map.element.id + '_ContentTemplate_' + annotationIndex).length) {
                    templateElement = Array.prototype.slice.call(templateFn(_this.map, _this.map, argsData.content, _this.map.element.id + '_ContentTemplate_' + annotationIndex));
                    var length_1 = templateElement.length;
                    for (var i = 0; i < length_1; i++) {
                        childElement.appendChild(templateElement[i]);
                    }
                }
                else {
                    childElement.appendChild(ej2_base_1.createElement('div', {
                        innerHTML: argsData.content
                    }));
                }
            });
            var offset = helper_1.getElementOffset(childElement.cloneNode(true), map.element);
            var elementRect = map.element.getBoundingClientRect();
            var bounds = map.svgObject.getBoundingClientRect();
            left = Math.abs(bounds.left - elementRect.left);
            top = Math.abs(bounds.top - elementRect.top);
            var annotationX = !ej2_base_1.isNullOrUndefined(annotation.x) ? annotation.x : '0%';
            var annotationY = !ej2_base_1.isNullOrUndefined(annotation.y) ? annotation.y : '0%';
            var annotationXValue = (annotationX.indexOf('%') > -1) ? (availSize.width / 100) * parseFloat(annotationX) :
                parseFloat(annotationX);
            var annotationYValue = (annotationY.indexOf('%') > -1) ? (availSize.height / 100) * parseFloat(annotationY) :
                parseFloat(annotationY);
            left = (annotation.horizontalAlignment === 'None') ? (left + annotationXValue) : left;
            top = (annotation.verticalAlignment === 'None') ? (top + annotationYValue) : top;
            switch (annotation.verticalAlignment) {
                case 'Near':
                    top = (top + annotationYValue);
                    break;
                case 'Center':
                    top = (top + annotationYValue) + ((bounds.height / 2) - (offset.height / 2));
                    break;
                case 'Far':
                    top = (top + bounds.height + annotationYValue) - offset.height;
                    break;
            }
            switch (annotation.horizontalAlignment) {
                case 'Near':
                    left = (left + annotationXValue);
                    break;
                case 'Center':
                    left = (left + annotationXValue) + ((bounds.width / 2) - (offset.width / 2));
                    break;
                case 'Far':
                    left = (left + bounds.width + annotationXValue) - offset.width;
                    break;
            }
            childElement.style.left = left + 'px';
            childElement.style.top = top + 'px';
            parentElement.appendChild(childElement);
        };
        Annotations.prototype.getModuleName = function () {
            return 'Annotations';
        };
        Annotations.prototype.destroy = function () {
            this.map = null;
        };
        return Annotations;
    }());
    exports.Annotations = Annotations;
});