MCPcopy
hub / github.com/toorshia/justgage / animate

Method animate

src/core/GaugeAnimator.js:21–69  ·  view source on GitHub ↗

* Animate gauge from one value to another * @param {Object} options - Animation options * @param {number} options.fromValue - Starting value * @param {number} options.toValue - Target value * @param {number} options.duration - Animation duration in ms * @param {string} options.easing

({
    fromValue,
    toValue,
    duration,
    easing = 'linear',
    onUpdate,
    onComplete,
    onCounterUpdate,
  })

Source from the content-addressed store, hash-verified

19 * @param {Function} [options.onCounterUpdate] - Called for counter text updates
20 */
21 animate({
22 fromValue,
23 toValue,
24 duration,
25 easing = 'linear',
26 onUpdate,
27 onComplete,
28 onCounterUpdate,
29 }) {
30 // Cancel any existing animation
31 this.cancel();
32
33 if (duration <= 0) {
34 // No animation, just call update with final value
35 if (onUpdate) onUpdate(toValue);
36 if (onCounterUpdate) onCounterUpdate(toValue);
37 if (onComplete) onComplete();
38 return;
39 }
40
41 const startTime = Date.now();
42 const valueRange = toValue - fromValue;
43
44 const animate = () => {
45 const elapsed = Date.now() - startTime;
46 const progress = Math.min(elapsed / duration, 1);
47
48 // Apply easing function
49 const easedProgress = this._applyEasing(progress, easing);
50 const currentValue = fromValue + valueRange * easedProgress;
51
52 // Update gauge elements
53 if (onUpdate) onUpdate(currentValue);
54 if (onCounterUpdate) onCounterUpdate(currentValue);
55
56 if (progress < 1) {
57 this.currentAnimation = requestAnimationFrame(animate);
58 } else {
59 // Animation complete
60 this.currentAnimation = null;
61 if (onUpdate) onUpdate(toValue);
62 if (onCounterUpdate) onCounterUpdate(toValue);
63 if (onComplete) onComplete();
64 }
65 };
66
67 // Start animation
68 this.currentAnimation = requestAnimationFrame(animate);
69 }
70
71 /**
72 * Cancel current animation

Callers 6

refreshMethod · 0.80
animator.test.jsFile · 0.80
raphael.min.jsFile · 0.80
JustGageFunction · 0.80
justgage.jsFile · 0.80

Calls 2

cancelMethod · 0.95
_applyEasingMethod · 0.95

Tested by

no test coverage detected