ofrohn / d3-celestial

A star map with d3.js
BSD 3-Clause "New" or "Revised" License
632 stars 180 forks source link

prjMap.translate is not a function #68

Closed umutesen closed 4 years ago

umutesen commented 4 years ago

I am getting the following exception when I use the resize method on Chrome under MacOS:

    Celestial.resize(800);
     Celestial.reproject({
        projection: 'mercator'
      });
   stack:"TypeError: prjMap.translate is not a function
    at resize (https://localhost:4200/scripts.js:392:12)
    at Object.resize (https://localhost:4200/scripts.js:946:5)

Any ideas what might be causing it?

maisterr commented 4 years ago

Try to wrap your code in setTimeout function with some delay, 3-4s. This error can occur because script has not load yet, but you already start use it.

umutesen commented 4 years ago

As the canvas was on the page fully loaded prior to resizing as a result of a button click, my understanding was that there would be no need to load the script again. Your suggestion seems to work with a timeout of 500ms, could it take as long as 3-4 seconds to load the script?

ofrohn commented 4 years ago

The error may be in Celestial.resize, which also takes a config object as argument, so Celestial.resize(width: 800); should work. (width is the only parameter it checks, though)

Of course, this function should really be polymorphic, call it empty, get the current width, call it with a number or a correctly formatted object, take that as it appears to be. so I did just that in the latest version (0.7.9). I may eventually get around to let it take an anonymous function as well.

umutesen commented 4 years ago

Yes, the error occurs in resize method. The timeout works, however, the resize takes place after some time and it is noticeable in the UI so it is slightly bad experience.

Is 0.7.9 available to try?

ofrohn commented 4 years ago

It is now