all files / progressbar/utils/ progress-animation.js

81.9% Statements 181/221
67.37% Branches 128/190
66.67% Functions 18/27
81.9% Lines 181/221
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     81× 81× 81× 81× 81× 81× 81× 81× 81× 81×   81× 81× 81×       749× 749× 387× 387× 387× 255× 255× 255× 255×     132× 132×         362× 328× 328× 104× 104× 104× 104×     224× 224×                                                                 118× 68× 68× 68×             50× 50× 20×     30×                                       16× 16×                 37× 37× 37× 37× 37× 37× 37× 37× 37×   37×   37×   37× 6840× 6840×     37× 37× 37× 37×       275× 275× 275× 275× 80× 80× 80× 80×     195× 195×                                     58× 58× 58× 58×                 18× 18× 18× 18× 18× 18× 18× 18× 18× 18× 18× 18× 18× 18× 15×   15× 15×   18×       146× 146× 146× 124× 124×         22× 22× 15× 15× 15× 15×                                                 14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14×       14× 14×   14× 14× 14×   14× 14× 14×       14×       244× 244× 244× 244× 244×                   439× 439× 439×        
define(["require", "exports", "@syncfusion/ej2-base", "../utils/helper", "../model/constant"], function (require, exports, ej2_base_1, helper_1, constant_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ProgressAnimation = (function () {
        function ProgressAnimation() {
        }
        ProgressAnimation.prototype.doLinearAnimation = function (element, progress, delay, previousWidth, active) {
            var _this = this;
            var animation = new ej2_base_1.Animation({});
            var linearPath = element;
            var duration = (progress.isActive) ? 3000 : progress.animation.duration;
            var width = linearPath.getAttribute('width');
            var x = linearPath.getAttribute('x');
            var opacityValue = 0;
            var value = 0;
            var start = (!progress.enableRtl || (progress.cornerRadius === 'Round4px')) ? previousWidth : parseInt(x, 10);
            var end = (!progress.enableRtl || (progress.cornerRadius === 'Round4px')) ? parseInt(width, 10) - start :
                parseInt(width, 10) - previousWidth;
            var rtlX = parseInt(x, 10) - end;
            linearPath.style.visibility = 'hidden';
            animation.animate(linearPath, {
                duration: (progress.animation.duration === 0 && ej2_base_1.animationMode === 'Enable') ? 2000 : duration,
                delay: delay,
                progress: function (args) {
                    progress.cancelResize = true;
                    if (progress.enableRtl && !(progress.cornerRadius === 'Round4px')) {
                        Eif (args.timeStamp >= args.delay) {
                            linearPath.style.visibility = 'visible';
                            if (progress.isActive) {
                                value = _this.activeAnimate((args.timeStamp / args.duration), parseInt(x, 10), parseInt(width, 10), true);
                                opacityValue = helper_1.effect(args.timeStamp, 0.5, 0.5, args.duration, true);
                                active.setAttribute('opacity', opacityValue.toString());
                                linearPath.setAttribute('x', value.toString());
                            }
                            else {
                                value = helper_1.effect(args.timeStamp, start, end, args.duration, true);
                                linearPath.setAttribute('x', value.toString());
                            }
                        }
                    }
                    else {
                        if (args.timeStamp >= args.delay) {
                            linearPath.style.visibility = 'visible';
                            if (progress.isActive) {
                                value = _this.activeAnimate((args.timeStamp / args.duration), 0, parseInt(width, 10), false);
                                opacityValue = helper_1.effect(args.timeStamp, 0.5, 0.5, args.duration, true);
                                active.setAttribute('opacity', opacityValue.toString());
                                linearPath.setAttribute('width', value.toString());
                            }
                            else {
                                value = helper_1.effect(args.timeStamp, start, end, args.duration, false);
                                linearPath.setAttribute('width', value.toString());
                            }
                        }
                    }
                },
                end: function () {
                    progress.cancelResize = false;
                    linearPath.style.visibility = '';
                    if (progress.enableRtl && !(progress.cornerRadius === 'Round4px')) {
                        if (progress.isActive) {
                            linearPath.setAttribute('x', x.toString());
                            _this.doLinearAnimation(element, progress, delay, previousWidth, active);
                        }
                        else {
                            linearPath.setAttribute('x', rtlX.toString());
                        }
                    }
                    else {
                        linearPath.setAttribute('width', width);
                        if (progress.isActive) {
                            _this.doLinearAnimation(element, progress, delay, previousWidth, active);
                        }
                    }
                    progress.trigger('animationComplete', {
                        value: progress.value, trackColor: progress.trackColor,
                        progressColor: progress.progressColor
                    });
                }
            });
        };
        ProgressAnimation.prototype.doLinearIndeterminate = function (element, progressWidth, thickness, progress, clipPath) {
            var _this = this;
            var animation = new ej2_base_1.Animation({});
            var linearPath = element;
            var x = linearPath.getAttribute('x');
            var width = linearPath.getAttribute('width');
            var value = 0;
            var start = (width) ? -(parseInt(width, 10)) : -progressWidth;
            var end = (progress.progressRect.x + progress.progressRect.width) + ((width) ? (parseInt(width, 10)) : progressWidth);
            var duration = (!progress.enableProgressSegments) ? progress.animation.duration : progress.animation.duration + 1000;
            animation.animate(clipPath, {
                duration: (progress.animation.duration === 0 && ej2_base_1.animationMode === 'Enable') ? 2000 : duration,
                delay: 0,
                progress: function (args) {
                    if (progress.enableRtl && !(progress.cornerRadius === 'Round4px')) {
                        value = helper_1.effect(args.timeStamp, parseInt(x, 10) || progress.progressRect.x + progressWidth, end, args.duration, true);
                        Eif (!progress.enableProgressSegments) {
                            linearPath.setAttribute('x', value.toString());
                        }
                        else {
                            linearPath.setAttribute('d', progress.getPathLine(value, progressWidth, thickness));
                        }
                    }
                    else {
                        value = helper_1.effect(args.timeStamp, start, end, args.duration, false);
                        if (!progress.enableProgressSegments) {
                            linearPath.setAttribute('x', value.toString());
                        }
                        else {
                            linearPath.setAttribute('d', progress.getPathLine(value, progressWidth, thickness));
                        }
                    }
                },
                end: function () {
                    if (progress.enableRtl && !progress.enableProgressSegments && !(progress.cornerRadius === 'Round4px')) {
                        linearPath.setAttribute('x', x.toString());
                    }
                    else if (!progress.enableProgressSegments) {
                        linearPath.setAttribute('x', start.toString());
                    }
                    if (!progress.destroyIndeterminate) {
                        _this.doLinearIndeterminate(element, progressWidth, thickness, progress, clipPath);
                    }
                }
            });
        };
        ProgressAnimation.prototype.doStripedAnimation = function (element, progress, value) {
            var _this = this;
            var animation = new ej2_base_1.Animation({});
            var point = 1000 / progress.animation.duration;
            animation.animate(element, {
                duration: (progress.animation.duration === 0 && ej2_base_1.animationMode === 'Enable') ? 2000 : progress.animation.duration,
                delay: progress.animation.delay,
                progress: function () {
                    value += (progress.enableRtl) ? -point : point;
                    element.setAttribute('gradientTransform', 'translate(' + value + ') rotate(-45)');
                },
                end: function () {
                    if (!progress.destroyIndeterminate) {
                        _this.doStripedAnimation(element, progress, value);
                    }
                }
            });
        };
        ProgressAnimation.prototype.doCircularAnimation = function (x, y, radius, progressEnd, totalEnd, element, progress, thickness, delay, startValue, previousTotal, active) {
            var _this = this;
            var animation = new ej2_base_1.Animation({});
            var circularPath = element;
            var start = progress.startAngle;
            var pathRadius = radius + (thickness / 2);
            var end = 0;
            var opacityValue = 0;
            var duration = (progress.isActive) ? 3000 : progress.animation.duration;
            start += (progress.cornerRadius === 'Round' && totalEnd !== constant_1.completeAngle && totalEnd !== 0) ?
                ((progress.enableRtl) ? (constant_1.lineCapRadius / 2) * thickness : -(constant_1.lineCapRadius / 2) * thickness) : 0;
            totalEnd += (progress.cornerRadius === 'Round' && totalEnd !== constant_1.completeAngle && totalEnd !== 0) ?
                (constant_1.lineCapRadius / 2) * thickness : 0;
            progressEnd += (progress.cornerRadius === 'Round' && totalEnd !== constant_1.completeAngle && totalEnd !== 0) ?
                ((progress.enableRtl) ? -(constant_1.lineCapRadius / 2) * thickness : (constant_1.lineCapRadius / 2) * thickness) : 0;
            if (progress.cornerRadius === 'Round' && totalEnd !== constant_1.completeAngle && totalEnd !== 0 && progress.startAngle === progress.endAngle) {
                var startPosition = helper_1.degreeToLocation(x, y, pathRadius, start).x;
                var endPosition = helper_1.degreeToLocation(x, y, pathRadius, progressEnd).x;
                while (((progress.enableRtl !== progress.startAngle >= 180) ? endPosition <= startPosition : endPosition >= startPosition)) {
                    progressEnd += (progress.enableRtl ? 0.1 : -0.1);
                    endPosition = helper_1.degreeToLocation(x, y, pathRadius, progressEnd).x;
                }
            }
            var startPos = (!ej2_base_1.isNullOrUndefined(startValue)) ? startValue : start;
            var endPos = (!ej2_base_1.isNullOrUndefined(startValue)) ? totalEnd - previousTotal : totalEnd;
            circularPath.setAttribute('visibility', 'Hidden');
            animation.animate(circularPath, {
                duration: (progress.animation.duration === 0 && ej2_base_1.animationMode === 'Enable') ? 2000 : duration,
                delay: delay,
                progress: function (args) {
                    progress.cancelResize = true;
                    Eif (args.timeStamp >= args.delay) {
                        circularPath.setAttribute('visibility', 'visible');
                        if (progress.isActive) {
                            end = _this.activeAnimate((args.timeStamp / args.duration), startPos, endPos, progress.enableRtl);
                            opacityValue = helper_1.effect(args.timeStamp, 0.5, 0.5, args.duration, true);
                            active.setAttribute('opacity', opacityValue.toString());
                            circularPath.setAttribute('d', helper_1.getPathArc(x, y, pathRadius, start, end % 360, progress.enableRtl, true));
                        }
                        else {
                            end = helper_1.effect(args.timeStamp, startPos, endPos, args.duration, progress.enableRtl);
                            circularPath.setAttribute('d', helper_1.getPathArc(x, y, pathRadius, start, end % 360, progress.enableRtl, true));
                        }
                    }
                },
                end: function () {
                    progress.cancelResize = false;
                    circularPath.setAttribute('visibility', '');
                    circularPath.setAttribute('d', helper_1.getPathArc(x, y, pathRadius, start, progressEnd, progress.enableRtl, true));
                    if (progress.isActive) {
                        _this.doCircularAnimation(x, y, radius, progressEnd, totalEnd, element, progress, thickness, delay, startValue, previousTotal, active);
                    }
                    progress.trigger('animationComplete', {
                        value: progress.value, trackColor: progress.trackColor,
                        progressColor: progress.progressColor
                    });
                }
            });
        };
        ProgressAnimation.prototype.doCircularIndeterminate = function (circularProgress, progress, start, end, x, y, radius, thickness, clipPath) {
            var _this = this;
            var animation = new ej2_base_1.Animation({});
            var pathRadius = radius + ((!progress.enableProgressSegments) ? (thickness / 2) : 0);
            var duration = (progress.animation.duration === 0 && ej2_base_1.animationMode === 'Enable') ? 2000 : progress.animation.duration;
            var value = (!progress.enableProgressSegments) ? 6000 / duration : 4000 / duration;
            animation.animate(clipPath, {
                progress: function () {
                    circularProgress.style.visibility = 'visible';
                    start += (progress.enableRtl) ? -value : value;
                    end += (progress.enableRtl) ? -value : value;
                    circularProgress.setAttribute('d', helper_1.getPathArc(x, y, pathRadius, start % 360, end % 360, progress.enableRtl, !progress.enableProgressSegments));
                },
                end: function () {
                    if (!progress.destroyIndeterminate) {
                        _this.doCircularIndeterminate(circularProgress, progress, start, end, x, y, radius, thickness, clipPath);
                    }
                }
            });
        };
        ProgressAnimation.prototype.doLabelAnimation = function (labelPath, start, end, progress, delay, textSize) {
            var animation = new ej2_base_1.Animation({});
            var label = new ej2_base_1.Animation({});
            var startPos;
            var endPos;
            var text = labelPath.innerHTML;
            var value = 0;
            var xPos = 0;
            var valueChanged = 0;
            var percentage = 100;
            var labelText = progress.labelStyle.text;
            var labelPos = progress.labelStyle.textAlignment;
            var posX = parseInt(labelPath.getAttribute('x'), 10);
            labelPath.setAttribute('visibility', 'Hidden');
            if (progress.type === 'Linear') {
                startPos = (progress.enableRtl) ? (progress.progressRect.x + progress.progressRect.width) + (textSize / 2) :
                    start - (textSize / 2);
                startPos = (startPos <= 0) ? 0 : startPos;
                endPos = (progress.enableRtl) ? startPos - posX : posX - startPos;
            }
            animation.animate(labelPath, {
                duration: (progress.animation.duration === 0 && ej2_base_1.animationMode === 'Enable') ? 2000 : progress.animation.duration,
                delay: delay,
                progress: function (args) {
                    progress.cancelResize = true;
                    args.name = 'SlideRight';
                    if (progress.type === 'Linear') {
                        Eif (args.timeStamp >= args.delay) {
                            if (labelText === '') {
                                labelPath.setAttribute('visibility', 'visible');
                                value = helper_1.effect(args.timeStamp, start, end, args.duration, false);
                                valueChanged = parseInt((((Math.round(value)) / progress.progressRect.width) * percentage).toString(), 10);
                                labelPath.innerHTML = valueChanged.toString() + '%';
                                Eif (labelPos === 'Far' || labelPos === 'Center') {
                                    xPos = helper_1.effect(args.timeStamp, startPos, endPos, args.duration, progress.enableRtl);
                                    labelPath.setAttribute('x', xPos.toString());
                                }
                            }
                        }
                    }
                    else Eif (progress.type === 'Circular') {
                        if (labelText === '') {
                            labelPath.setAttribute('visibility', 'visible');
                            value = helper_1.effect(args.timeStamp, start, end - start, args.duration, false);
                            valueChanged = parseInt((((Math.round(value)) / progress.totalAngle) * percentage).toString(), 10);
                            labelPath.innerHTML = valueChanged.toString() + '%';
                        }
                    }
                },
                end: function () {
                    progress.cancelResize = false;
                    if (labelText === '') {
                        labelPath.innerHTML = text;
                        labelPath.setAttribute('x', posX.toString());
                    }
                    else {
                        label.animate(labelPath, {
                            progress: function (args) {
                                labelPath.setAttribute('visibility', 'visible');
                                value = helper_1.effect(args.timeStamp, 0, 1, args.duration, false);
                                labelPath.setAttribute('opacity', value.toString());
                            },
                            end: function () {
                                labelPath.setAttribute('opacity', '1');
                            }
                        });
                    }
                }
            });
        };
        ProgressAnimation.prototype.doAnnotationAnimation = function (circularPath, progress, previousEnd, previousTotal) {
            var animation = new ej2_base_1.Animation({});
            var value = 0;
            var percentage = 100;
            var isAnnotation = progress.annotations.length > 0;
            var annotatElementChanged;
            var firstAnnotatElement;
            var start = progress.startAngle;
            var totalAngle = progress.totalAngle;
            var totalEnd;
            var annotateValueChanged;
            var annotateValue;
            Eif (isAnnotation && progress.progressAnnotationModule) {
                firstAnnotatElement = document.getElementById(progress.element.id + 'Annotation0').children[0];
                Eif (firstAnnotatElement && firstAnnotatElement.children[0]) {
                    Eif (firstAnnotatElement.children[0].tagName === 'SPAN') {
                        annotatElementChanged = firstAnnotatElement.children[0];
                    }
                }
            }
            totalEnd = ((progress.argsData.value - progress.minimum) / (progress.maximum - progress.minimum)) * progress.totalAngle;
            progress.annotateTotal = totalEnd =
                (progress.argsData.value < progress.minimum) ? 0 : totalEnd;
            progress.annotateEnd = start + totalEnd;
            annotateValue = ((progress.argsData.value - progress.minimum) / (progress.maximum - progress.minimum)) * percentage;
            annotateValue = (progress.argsData.value < progress.minimum) ? 0 :
                Math.round(annotateValue);
            var startValue = (!ej2_base_1.isNullOrUndefined(previousEnd)) ? previousEnd : start;
            var endValue = (!ej2_base_1.isNullOrUndefined(previousEnd)) ? totalEnd - previousTotal : totalEnd;
            Iif (progress.argsData.value <= progress.minimum) {
                annotatElementChanged.innerHTML = annotateValue + '%';
            }
            else {
                animation.animate(circularPath, {
                    duration: (progress.animation.duration === 0 && ej2_base_1.animationMode === 'Enable') ? 2000 : progress.animation.duration,
                    delay: progress.animation.delay,
                    progress: function (args) {
                        progress.cancelResize = true;
                        Eif (isAnnotation && annotatElementChanged) {
                            value = helper_1.effect(args.timeStamp, startValue, endValue, args.duration, false);
                            annotateValueChanged = parseInt((((Math.round(value) - start) / totalAngle) * percentage).toString(), 10);
                            annotatElementChanged.innerHTML = annotateValueChanged ? annotateValueChanged.toString() + '%' : '0%';
                        }
                    },
                    end: function () {
                        progress.cancelResize = false;
                        annotatElementChanged.innerHTML = annotateValue + '%';
                    }
                });
            }
        };
        ProgressAnimation.prototype.activeAnimate = function (t, start, end, enableRtl) {
            var time = 1 - Math.pow(1 - t, 3);
            var attrValue = start + ((!enableRtl) ? (time * end) : -(time * end));
            return attrValue;
        };
        return ProgressAnimation;
    }());
    exports.ProgressAnimation = ProgressAnimation;
});