Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins and drawing #12

Closed
VarolOkan opened this issue Dec 13, 2014 · 4 comments
Closed

plugins and drawing #12

VarolOkan opened this issue Dec 13, 2014 · 4 comments

Comments

@VarolOkan
Copy link

The top of planetary.js holds doDrawLoop. It would be very valuable if one could refine it such that you specify a timeout after which you call requestAnimationFrame instead. This will decrease the load for complex web based applications.

Also I think the startDraw function has a bug. The folowing code should not belong in there. It may be neccesary to init the plugins separate from the stopped state.
if (planet.stopped !== true) {
initPlugins(planet, localPlugins);
}

I had > 100 plugins after a few minutes and the whole system came to a crawl. I fixed it by calling
globe.stop ( );
globe.draw ( canvas );
anytime

@BinaryMuse
Copy link
Owner

It sounds like there are two issues here.

For the first one, I'm not sure exactly what you mean; the timer is managed via d3, and should be implemented by rAF in the default case (assuming it's available). That said, I'm not opposed to making the implementation more flexible.

For the second one, do you have an example of a situation where the plugins were incorrectly initialized?

@VarolOkan
Copy link
Author

I was thinking about something like the below, where the 500ms should be adjustable.

  var doDrawLoop = function ( planet, canvas, hooks )  {
    timerRef = setInterval ( function ( )  {
      if (planet.stopped) {
        clearInterval ( timerRef );
        timerRef = null;
        return;
      }
      function doIt ( )  {
        planet.context.clearRect(0, 0, canvas.width, canvas.height);
        for (var i = 0; i < hooks.onDraw.length; i++) {
          hooks.onDraw[i]();
        }
      }
      if ( typeof window.requestAnimationFrame !== 'undefined' )  {
        window.requestAnimationFrame ( doIt );
      }
      else  {
        doIt ( );
      }
    }, 500 );
  };

The second one, when you call
globe.draw ( this._canvas ); without first setting 'stopped'
it will do

if (planet.stopped !== true) {
      initPlugins(planet, localPlugins);
    }

and re-add the plugins again.

Hope that helps.

@BinaryMuse
Copy link
Owner

I'm still not sure I fully follow your example's rAF usage, but I agree that it would be nice to allow for customization of the draw timer. I've opened #13 to change this.


The first time you call globe.draw(), planet.stopped is not true, and initPlugins() correctly runs. You should not call globe.draw() again on the same planet instance without first calling globe.stop(). I will update the docs to reflect this information, and have opened #14 to better support draw()ing more than once.

@VarolOkan
Copy link
Author

Ah if this is expected, may I suggest to rename the function, maybe initPlanet or similar.
a function called draw will confuse if it does other things, like initializing etc.

If you leave the function 'draw', then it should only do somthing like:
planet.context.clearRect(0, 0, canvas.width, canvas.height);
for (var i = 0; i < hooks.onDraw.length; i++) {
hooks.onDrawi;
}

BTW, I like your project. Quite nice. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants