all files / linear-gauge/annotations/ annotations.js

100% Statements 85/85
91.18% Branches 31/34
100% Functions 8/8
100% Lines 85/85
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   201×   211× 211× 211× 211× 211× 211× 211× 211× 210×     211× 208×     215× 215× 215× 215× 215× 215× 215× 215× 215× 215× 215× 215×     215×       215× 215× 215× 215× 14× 14× 14×       201×         215× 215×           211× 211× 211× 211× 211× 211× 211× 211×         211×           215× 215× 215× 215×       347×          
define(["require", "exports", "@syncfusion/ej2-base", "../utils/helper", "../utils/helper", "../model/constant"], function (require, exports, ej2_base_1, helper_1, helper_2, constant_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Annotations = (function () {
        function Annotations(gauge) {
            this.gauge = gauge;
        }
        Annotations.prototype.renderAnnotationElements = function () {
            var _this = this;
            var secondaryID = this.gauge.element.id + '_Secondary_Element';
            var annotationGroup = ej2_base_1.createElement('div', { id: this.gauge.element.id + '_AnnotationsGroup' });
            annotationGroup.style.position = 'absolute';
            annotationGroup.style.top = '0px';
            annotationGroup.style.left = '0px';
            this.gauge.annotations.map(function (annotation, index) {
                if (annotation.content !== null) {
                    _this.createAnnotationTemplate(annotationGroup, index);
                }
            });
            if (annotationGroup.childElementCount > 0 && !(ej2_base_1.isNullOrUndefined(helper_1.getElement(secondaryID)))) {
                helper_1.getElement(secondaryID).appendChild(annotationGroup);
            }
        };
        Annotations.prototype.createAnnotationTemplate = function (element, annotationIndex) {
            var left;
            var top;
            var templateFn;
            var renderAnnotation = false;
            var templateElement;
            var axis;
            var axisIndex;
            var axisValue;
            var id = this.gauge.element.id + '_Annotation_' + annotationIndex;
            var annotation = this.gauge.annotations[annotationIndex];
            var childElement;
            childElement = ej2_base_1.createElement('div', {
                id: this.gauge.element.id + '_Annotation_' + annotationIndex, styles: 'position: absolute; z-index:' + annotation.zIndex + ';'
            });
            var argsData = {
                cancel: false, name: constant_1.annotationRender, content: annotation.content,
                annotation: annotation, textStyle: annotation.font
            };
            this.gauge.trigger(constant_1.annotationRender, argsData);
            Eif (!argsData.cancel) {
                templateFn = helper_1.getTemplateFunction(argsData.content);
                if (templateFn && templateFn(this.gauge).length) {
                    templateElement = templateFn(this.gauge);
                    while (templateElement.length > 0) {
                        childElement.appendChild(templateElement[0]);
                    }
                }
                else {
                    childElement.appendChild(ej2_base_1.createElement('div', {
                        innerHTML: argsData.content,
                        styles: helper_2.getFontStyle(argsData.textStyle)
                    }));
                }
                var offset = helper_1.getElementOffset(childElement.cloneNode(true), this.gauge.element);
                if (!(ej2_base_1.isNullOrUndefined(annotation.axisValue))) {
                    axisIndex = ej2_base_1.isNullOrUndefined(annotation.axisIndex) ? 0 : annotation.axisIndex;
                    axis = this.gauge.axes[axisIndex];
                    var range = axis.visibleRange;
                    renderAnnotation = (annotation.axisValue >= range.min && annotation.axisValue <= range.max) ? true : false;
                    var line = axis.lineBounds;
                    if (this.gauge.orientation === 'Vertical') {
                        left = line.x + annotation.x;
                        top = ((helper_2.valueToCoefficient(annotation.axisValue, axis, this.gauge.orientation, range) * line.height) + line.y);
                        top += annotation.y;
                    }
                    else {
                        left = ((helper_2.valueToCoefficient(annotation.axisValue, axis, this.gauge.orientation, range) * line.width) + line.x);
                        left += annotation.x;
                        top = line.y + annotation.y;
                    }
                    left -= (offset.width / 2);
                    top -= (offset.height / 2);
                }
                else {
                    var elementRect = this.gauge.element.getBoundingClientRect();
                    var bounds = this.gauge.svgObject.getBoundingClientRect();
                    renderAnnotation = true;
                    left = Math.abs(bounds.left - elementRect.left);
                    top = Math.abs(bounds.top - elementRect.top);
                    left = (annotation.horizontalAlignment === 'None') ? (left + annotation.x) : left;
                    top = (annotation.verticalAlignment === 'None') ? top + annotation.y : top;
                    switch (annotation.verticalAlignment) {
                        case 'Near':
                            top = top + annotation.y;
                            break;
                        case 'Center':
                            top = top + annotation.y + ((bounds.height / 2) - (offset.height / 2));
                            break;
                        case 'Far':
                            top = (top + bounds.height) + annotation.y - offset.height;
                            break;
                    }
                    switch (annotation.horizontalAlignment) {
                        case 'Near':
                            left = left + annotation.x;
                            break;
                        case 'Center':
                            left = left + annotation.x + ((bounds.width / 2) - (offset.width / 2));
                            break;
                        case 'Far':
                            left = (left + bounds.width) + annotation.x - offset.width;
                            break;
                    }
                }
                childElement.style.left = left + 'px';
                childElement.style.top = top + 'px';
                Eif (renderAnnotation) {
                    element.appendChild(childElement);
                }
            }
        };
        Annotations.prototype.getModuleName = function () {
            return 'Annotations';
        };
        Annotations.prototype.destroy = function (gauge) {
        };
        return Annotations;
    }());
    exports.Annotations = Annotations;
});