Performance issues if I change the data in the middle of an animation - Official support forum | RGraph.net

Performance issues if I change the data in the middle of an animation

Post a reply

Posted by AKN at 14:18 on Tuesday 24th January 2023 [link]
Hey, during the initial chart animation where bars animate, if I change the data or any appearance setting animation starts over but stutters a lot. This problem does not occur when I change the data or any appearance settings after the animation ended. What can I do to solve this problem so that during animation if I change anything it does not stutter?

Posted by Richard at 18:45 on Tuesday 24th January 2023 [link]
Hmmmm. Why are you changing settings in the middle of the animation? I'm guessing that because the frames all initiated immediately with an increasing delay for each frame - the remaining frames are drawing when you start the new animation.

There's no way to cancel the remaining frames currently.

Now I think about it - it might actually not be that at all.

Is it possible to delay your update until the current animation has finished? Maybe with setTimeout or perhaps with the animation callback function.

eg The animation callback could check a variable to see if it contains any new properties and if it does set them on the object.

Posted by Richard at 22:59 on Tuesday 24th January 2023 [link]
OK, after a bit of experimentation, it's looking like I might be able to add a stop() function that might look something like this:

obj = new RGraph.Bar({
    idx: 'cvs',
    data: [1,6,3,5,8,4,9],
    options: {
    }
}).wave(); // This effect takes two seconds by default (IIRC)

// Call this half-way through the wave() effect
setTimeout(function ()
{
    obj.wave.stop();
}, 1000);

Something like that - or perhaps one of these:

obj.stop();
obj.stopEffect();
RGraph.Effects.stop();

Or maybe all of them! Keep in mind it's still just a maybe at this point.

Posted by Richard at 11:28 on Thursday 26th January 2023 [link]
What chart type and effect are you using btw? The Bar chart?

Posted by AKN at 12:08 on Thursday 26th January 2023 [link]
I'm using bipolar chart. I've tried to add stop functions but my browser keep crashed after that not sure why. After changing data or filters without waiting 1-2 seconds causing stuttering. So I have a appearance tab that changes the color of the bars and that sets the title position etc. When I change any settings the chart redraws from zero, plays the animation and all. I've tried to set animation frames to 1 so that it'd be kinda instant .grow({ frames: 1 }) or .wave({ frames: 1 }) still same problem occurred. So I'm kinda lost, what's the problem here.

Posted by Richard at 16:31 on Thursday 26th January 2023 [link]
I'm currently trying to add a stop() function which will exactly that - stop the animation so that you can start another.

I've added one to the Bar chart successfully but I'm now thinking of another way which might be a little better so that you could do this:

myBipolar.grow.stop();

And it would stop the grow effect.

Posted by AKN at 17:53 on Thursday 26th January 2023 [link]
I'm not even sure if the growing animation causing the stuttering at this point. But please let me know if you got something.

Posted by Richard at 18:09 on Thursday 26th January 2023 [link]
OK, I've made a stop() animation function and you can see it in action here:

https://www.rgraph.net/tests/canvas.bipolar/effects-stop-animation.html

And there are also links to download the updated libraries.

Posted by AKN at 12:32 on Friday 27th January 2023 [link]
myBipolar.grow.stop(); is this how I use it?

Posted by AKN at 12:58 on Friday 27th January 2023 [link]
.grow.stop(); is this how I use it? Or maybe .stopAnimation(); ?

Posted by AKN at 13:10 on Friday 27th January 2023 [link]
Btw any line of code I write after the draw() function doesn't work. Why do you think that is? Here's an example js code https://i.imgur.com/shTSId7.png

Posted by AKN at 13:52 on Friday 27th January 2023 [link]
Nvm I figured it out... Thank you dude. I've added a toggle animation button, when disabled I change any setting I want and then enable the animation. Seems like the stuttering is kind of gone. It just stutters a tiny bit.

Posted by Richard at 16:42 on Friday 27th January 2023 [link]
> Nvm I figured it out... Thank you dude. I've added a toggle
> animation button, when disabled I change any setting I want and
> then enable the animation. Seems like the stuttering is kind of
> gone. It just stutters a tiny bit.

Marvellous. Did the obj.stopAnimation() function help at all?

Posted by AKN at 19:06 on Friday 27th January 2023 [link]
Yep it was exactly what I needed :)

Post a reply

What's your name?
What do you want to say?