all files / linear-gauge/axes/ animation.js

98.79% Statements 163/165
87.23% Branches 123/141
100% Functions 9/9
98.79% Lines 163/165
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   498×   32× 32× 32× 32× 32× 32× 32× 32× 32×     23×   32× 32× 32×   32× 32× 32× 32× 32× 32× 32× 32× 32× 32× 32×           502× 502× 502× 502× 300×   300× 300× 120×   300× 90×   210× 120×     90×   300×     188×   188× 188× 121×   188× 22×   166× 123×     43×   188×         18×   12×       18× 18× 18× 18× 18× 18× 11× 10× 10×               21× 21× 21× 21× 21× 21× 21× 21× 21× 21× 21× 21× 21× 21× 21× 21× 21× 21× 21× 21× 21× 21× 21× 21× 21× 21×   21×   21× 21×               21× 21× 21× 21×           166× 166× 166× 166× 160× 160× 160× 135× 135×     25× 25×   160× 151× 101×       150× 150× 150×                   14×                   14× 14× 14× 14× 14×                        
define(["require", "exports", "@syncfusion/ej2-base", "../model/constant", "../utils/helper", "../utils/helper"], function (require, exports, ej2_base_1, constant_1, helper_1, helper_2) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Animations = (function () {
        function Animations(gauge) {
            this.gauge = gauge;
        }
        Animations.prototype.performMarkerAnimation = function (element, axis, pointer) {
            var _this = this;
            var markerElement = element;
            var options;
            var textOptions;
            var timeStamp;
            var range = axis.visibleRange;
            var rectHeight = (this.gauge.orientation === 'Vertical') ? axis.lineBounds.height : axis.lineBounds.width;
            var rectY = (this.gauge.orientation === 'Vertical') ? axis.lineBounds.y : axis.lineBounds.x;
            if (this.gauge.orientation === 'Vertical') {
                pointer.bounds.y = (helper_1.valueToCoefficient(pointer.currentValue, axis, this.gauge.orientation, range) * rectHeight) + rectY;
            }
            else {
                pointer.bounds.x = (helper_1.valueToCoefficient(pointer.currentValue, axis, this.gauge.orientation, range) * rectHeight) + rectY;
            }
            options = new helper_1.PathOption(markerElement.id, null, null, null);
            options = helper_2.calculateShapes(pointer.bounds, pointer.markerType, new helper_1.Size(pointer.width, pointer.height), pointer.imageUrl, options, this.gauge.orientation, axis, pointer);
            if (pointer.markerType === 'Text') {
                textOptions = new helper_1.TextOption(markerElement.id, 0, 0, 'middle', pointer.text, null, 'auto');
                textOptions = helper_2.calculateTextPosition(pointer.bounds, pointer.markerType, textOptions, this.gauge.orientation, axis, pointer);
            }
            var currentValue;
            var start = typeof (pointer.startValue) === 'string' ? parseInt(pointer.startValue, 10) : pointer.startValue;
            var end = pointer.currentValue;
            start = (start === end) ? range.min : start;
            var val = Math.abs(start - end);
            var currentPath = options.d;
            var cx = options['cx'];
            var cy = options['cy'];
            var x = pointer.markerType === 'Text' ? textOptions['x'] : options['x'];
            var y = pointer.markerType === 'Text' ? textOptions['y'] : options['y'];
            new ej2_base_1.Animation({}).animate(markerElement, {
                name: 'Linear',
                duration: (ej2_base_1.animationMode === 'Enable' && ((pointer.animationDuration === 0 && !this.gauge.allowLoadingAnimation) ||
                    this.gauge.animationDuration === 0)) ? 1000 : (this.gauge.allowLoadingAnimation && pointer.animationDuration === 0 ?
                    (this.gauge.animationDuration / this.gauge.splitUpCount) : pointer.animationDuration),
                progress: function (args) {
                    Eif (args.timeStamp >= args.delay) {
                        timeStamp = ((args.timeStamp - args.delay) / args.duration);
                        currentValue = (start < end) ? start + (timeStamp * val) : start - (timeStamp * val);
                        if (_this.gauge.orientation === 'Vertical') {
                            pointer.bounds.y = (helper_1.valueToCoefficient(currentValue, axis, _this.gauge.orientation, range) *
                                rectHeight) + rectY;
                            options = helper_2.calculateShapes(pointer.bounds, pointer.markerType, new helper_1.Size(pointer.width, pointer.height), pointer.imageUrl, options, _this.gauge.orientation, axis, pointer);
                            if (pointer.markerType === 'Text') {
                                textOptions = helper_2.calculateTextPosition(pointer.bounds, pointer.markerType, textOptions, _this.gauge.orientation, axis, pointer);
                            }
                            if (!ej2_base_1.isNullOrUndefined(options['r'])) {
                                markerElement.setAttribute('cy', options['cy'].toString());
                            }
                            else if (!ej2_base_1.isNullOrUndefined(pointer.markerType === 'Text' ? textOptions['y'] : options['y'])) {
                                markerElement.setAttribute('y', pointer.markerType === 'Text' ? textOptions['y'] : options['y'].toString());
                            }
                            else {
                                markerElement.setAttribute('d', options.d);
                            }
                            markerElement.style.visibility = 'visible';
                        }
                        else {
                            pointer.bounds.x = (helper_1.valueToCoefficient(currentValue, axis, _this.gauge.orientation, range) *
                                rectHeight) + rectY;
                            options = helper_2.calculateShapes(pointer.bounds, pointer.markerType, new helper_1.Size(pointer.width, pointer.height), pointer.imageUrl, options, _this.gauge.orientation, axis, pointer);
                            if (pointer.markerType === 'Text') {
                                textOptions = helper_2.calculateTextPosition(pointer.bounds, pointer.markerType, textOptions, _this.gauge.orientation, axis, pointer);
                            }
                            if (!ej2_base_1.isNullOrUndefined(options['r'])) {
                                markerElement.setAttribute('cx', options['cx'].toString());
                            }
                            else if (!ej2_base_1.isNullOrUndefined(pointer.markerType === 'Text' ? textOptions['x'] : options['x'])) {
                                markerElement.setAttribute('x', pointer.markerType === 'Text' ? textOptions['x'] : options['x'].toString());
                            }
                            else {
                                markerElement.setAttribute('d', options.d);
                            }
                            markerElement.style.visibility = 'visible';
                        }
                    }
                },
                end: function () {
                    if (!ej2_base_1.isNullOrUndefined(cy)) {
                        markerElement.setAttribute('cy', cy.toString());
                        markerElement.setAttribute('cx', cx.toString());
                    }
                    else if (!ej2_base_1.isNullOrUndefined(y)) {
                        markerElement.setAttribute('y', y.toString());
                        markerElement.setAttribute('x', x.toString());
                    }
                    else {
                        markerElement.setAttribute('d', currentPath);
                    }
                    markerElement.style.visibility = 'visible';
                    pointer.isPointerAnimation = false;
                    pointer.animationComplete = true;
                    pointer.startValue = pointer.value = pointer.currentValue;
                    _this.gauge.trigger(constant_1.animationComplete, { axis: axis, pointer: pointer });
                    if (_this.gauge.allowLoadingAnimation) {
                        if (!ej2_base_1.isNullOrUndefined(_this.gauge.annotationsModule) && (_this.gauge.annotations.length > 0 && (_this.gauge.annotations[0].content !== '' || _this.gauge.annotations.length > 1))) {
                            var element_1 = document.getElementById(_this.gauge.element.id + '_AnnotationsGroup');
                            _this.gauge.annotationsModule.annotationAnimate(element_1, _this.gauge);
                        }
                        else {
                            _this.gauge.allowLoadingAnimation = false;
                            _this.gauge.isOverAllAnimationComplete = true;
                        }
                    }
                }
            });
        };
        Animations.prototype.performBarAnimation = function (element, axis, pointer) {
            var _this = this;
            var radix = 10;
            var timeStamp;
            var value2;
            var value1;
            var currentValue;
            var clipHeight;
            var clipY;
            var clipX;
            var clipVal;
            var clipWidth;
            var currentHeight;
            var clipElement;
            var range = axis.visibleRange;
            var pointerElement = element;
            var lineHeight = (this.gauge.orientation === 'Vertical') ? axis.lineBounds.height : axis.lineBounds.width;
            var lineY = (this.gauge.orientation === 'Vertical') ? axis.lineBounds.y : axis.lineBounds.x;
            var start = typeof (pointer.startValue) === 'string' ? parseInt(pointer.startValue, 10) : pointer.startValue;
            var end = pointer.currentValue;
            start = (start === end) ? range.min : start;
            var path = '';
            var currentPath = '';
            var tagName = pointerElement.tagName;
            var val = Math.abs(start - end);
            var pointerValue = (helper_1.valueToCoefficient(end, axis, this.gauge.orientation, range) * lineHeight) + lineY;
            var startPointerVal = (helper_1.valueToCoefficient(range.min, axis, this.gauge.orientation, range) *
                lineHeight) + lineY;
            var rectY = (this.gauge.orientation === 'Vertical') ? !axis.isInversed ? pointerValue : startPointerVal :
                axis.isInversed ? pointerValue : startPointerVal;
            var rectHeight = Math.abs(startPointerVal - pointerValue);
            if (this.gauge.container.type === 'Thermometer' && start === 0 && this.gauge.container.width > 0) {
                if (end === axis.minimum) {
                    element.style.visibility = 'visible';
                }
                else {
                    clipElement = pointerElement.parentElement.childNodes[1].childNodes[0].childNodes[0];
                    if (this.gauge.orientation === 'Vertical') {
                        clipY = clipElement.getAttribute('y');
                        clipHeight = clipElement.getAttribute('height');
                        clipVal = parseInt(clipY, radix) + parseInt(clipHeight, radix);
                        clipElement.setAttribute('y', clipVal.toString());
                    }
                    else {
                        clipX = clipElement.getAttribute('x');
                        clipWidth = clipElement.getAttribute('width');
                        clipVal = parseInt(clipX, radix) + parseInt(clipWidth, radix);
                        clipElement.setAttribute('width', '0');
                    }
                }
            }
            path = pointer.value === axis.minimum && this.gauge.container.type === 'RoundedRectangle' ? '' : helper_2.getBox(pointer.bounds, this.gauge.container.type, this.gauge.orientation, new helper_1.Size(pointer.bounds.width, pointer.bounds.height), 'bar', this.gauge.container.width, axis, pointer.roundedCornerRadius);
            var animatedPointerWidth = pointer.bounds.width;
            var animatedPointerHeight = pointer.bounds.height;
            new ej2_base_1.Animation({}).animate(pointerElement, {
                name: 'Linear',
                duration: (ej2_base_1.animationMode === 'Enable' && ((pointer.animationDuration === 0 && !this.gauge.allowLoadingAnimation) ||
                    this.gauge.animationDuration === 0)) ? 1000 : (this.gauge.allowLoadingAnimation && pointer.animationDuration === 0 ?
                    (this.gauge.animationDuration / this.gauge.splitUpCount) : pointer.animationDuration),
                progress: function (animate) {
                    Eif (animate.timeStamp >= animate.delay) {
                        timeStamp = ((animate.timeStamp - animate.delay) / animate.duration);
                        currentValue = (start < end) ? start + (timeStamp * val) : start - (timeStamp * val);
                        value2 = (helper_1.valueToCoefficient(currentValue, axis, _this.gauge.orientation, range) * lineHeight) + lineY;
                        value1 = (helper_1.valueToCoefficient(range.min, axis, _this.gauge.orientation, range) * lineHeight) + lineY;
                        currentHeight = Math.abs(value2 - value1);
                        if (_this.gauge.orientation === 'Vertical') {
                            pointer.bounds.y = (!axis.isInversed) ? value2 : value1;
                            animatedPointerHeight = currentHeight;
                        }
                        else {
                            pointer.bounds.x = (axis.isInversed) ? value2 : value1;
                            animatedPointerWidth = currentHeight;
                        }
                        if (tagName === 'path') {
                            if (start === 0 && _this.gauge.container.type === 'Thermometer') {
                                (_this.gauge.orientation === 'Vertical') ?
                                    clipElement.setAttribute('y', (clipVal - (timeStamp * parseInt(clipHeight, radix))).toString()) :
                                    clipElement.setAttribute('width', (timeStamp * parseInt(clipWidth, radix)).toString());
                            }
                            currentPath = pointer.value === axis.minimum && _this.gauge.container.type === 'RoundedRectangle' ? '' : helper_2.getBox(new helper_1.Rect(pointer.bounds.x, pointer.bounds.y, animatedPointerWidth, animatedPointerHeight), _this.gauge.container.type, _this.gauge.orientation, new helper_1.Size(animatedPointerWidth, animatedPointerHeight), 'bar', _this.gauge.container.width, axis, pointer.roundedCornerRadius);
                            pointerElement.setAttribute('d', currentPath);
                            pointerElement.style.visibility = 'visible';
                        }
                        else {
                            if (_this.gauge.orientation === 'Vertical') {
                                pointerElement.setAttribute('y', pointer.bounds.y.toString());
                                pointerElement.setAttribute('height', animatedPointerHeight.toString());
                            }
                            else {
                                pointerElement.setAttribute('x', pointer.bounds.x.toString());
                                pointerElement.setAttribute('width', animatedPointerWidth.toString());
                            }
                            pointerElement.style.visibility = 'visible';
                        }
                    }
                },
                end: function () {
                    if (tagName === 'path') {
                        if (start === 0 && _this.gauge.container.type === 'Thermometer') {
                            pointerElement.parentElement.children[1].remove();
                        }
                        else {
                            pointerElement.setAttribute('d', path);
                        }
                    }
                    else {
                        if (_this.gauge.orientation === 'Vertical') {
                            pointerElement.setAttribute('y', rectY.toString());
                            pointerElement.setAttribute('height', rectHeight.toString());
                        }
                        else {
                            pointerElement.setAttribute('x', rectY.toString());
                            pointerElement.setAttribute('width', rectHeight.toString());
                        }
                    }
                    pointerElement.style.visibility = 'visible';
                    pointer.isPointerAnimation = false;
                    pointer.startValue = pointer.value = pointer.currentValue;
                    _this.gauge.trigger(constant_1.animationComplete, { axis: axis, pointer: pointer });
                    if (_this.gauge.allowLoadingAnimation) {
                        Eif (!ej2_base_1.isNullOrUndefined(_this.gauge.annotationsModule) && (_this.gauge.annotations.length > 0 && (_this.gauge.annotations[0].content !== '' || _this.gauge.annotations.length > 1))) {
                            var element_2 = document.getElementById(_this.gauge.element.id + '_AnnotationsGroup');
                            _this.gauge.annotationsModule.annotationAnimate(element_2, _this.gauge);
                        }
                        else {
                            _this.gauge.allowLoadingAnimation = false;
                            _this.gauge.isOverAllAnimationComplete = true;
                        }
                    }
                }
            });
        };
        return Animations;
    }());
    exports.Animations = Animations;
});