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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

only one svgspace possible #128

Closed
jaro-io opened this issue Dec 15, 2020 · 11 comments
Closed

only one svgspace possible #128

jaro-io opened this issue Dec 15, 2020 · 11 comments

Comments

@jaro-io
Copy link

jaro-io commented Dec 15, 2020

heyho @williamngan! 馃尦 馃尵

you can make a microwaved quick meal, or you can take the full on adventure time travel to dinosaur land. and this for me is pts. wow. what an amazing library! and i am just scratching the surface.. 馃く

because of performance issues with the canvas element and locomotive-scroll in safari, i had to switch to the svg renderer which works beautifully fine, even though its still marked as experimental.

there's just one major problem i am facing. i can only get one svg space working at the same time. as soon as i create more than one, it only renders the last one.

i created a pretty basic pen just to demonstrate. actually we should be able to see two lines here. but we only see one. is it me who's not understanding how to setup the library correctly, or is there something wrong on the other side?

https://codepen.io/jaro_io/pen/MWjpZxL

thank you so much for taking a quick look!
jaro
馃悿

@williamngan
Copy link
Owner

Heyho @jaro-io 馃槂 Thanks for trying out Pts and sending the detailed bug report.

Looks like there's a bug here where the svg id won't get updated unless you passed an svg element.

I'll patch this soon in the next release. But a quick fix now would be to add an empty element inside the div. Eg:

<div class="wrapper">
  <div class="canvas"><svg id="one" /></div>
  <div class="canvas"><svg id="two" /></div>
</div>

Just curious what kind of performance issue did you encounter with Safari -- can you create a new issue when you get a chance?

Thanks again. Cheers!

@jaro-io
Copy link
Author

jaro-io commented Dec 15, 2020

wow, thank you for the super fast heads-up. 馃馃徎 i already had the same idea, but in my specific case, it didn't fix the problem. in fact, in the pen it does. so i'll investigate! trying to find out how i can reproduce my problem here. i will let you know soon!

@jaro-io jaro-io changed the title Only one SVGSpace possible only one svgspace possible Dec 15, 2020
@jaro-io
Copy link
Author

jaro-io commented Dec 16, 2020

hello again @williamngan!
i changed my pen to illustrate what i meant yesterday. even though now i have two empty svg elements with unique ids, the library is still only rendering one of the two lines. it does add all the setup attributes to the second svg element, but the svg itself stays empty.

https://codepen.io/jaro_io/pen/NWRjPpg

when this is still nothing on my end (please check my code, i only just started), it might be another bug or related to the one we found yesterday.

thank you so much for looking into this!
jaro
馃嵂

@williamngan
Copy link
Owner

Thanks @jaro-io -- I should have a patch coming later today or tomorrow. Hang on :)

@jaro-io
Copy link
Author

jaro-io commented Dec 17, 2020

@williamngan thank you so much for the immediate support! 馃崱

@williamngan
Copy link
Owner

v0.9.6 should fix this issue hopefully. Give it a try.

@jaro-io
Copy link
Author

jaro-io commented Dec 17, 2020

thank you so much @williamngan. that was super fast. 馃槷 it did in fact fix something but not everything.

when using empty svg elements with unique ids it works fine, as long as i use an id string (like '#custom-id') to create the new svg space.


if i pass the svg element via javascript directly when creating the space, it still only renders the first of all animations.

if i add an empty div to my site and pass its unqiue id string to create the space, it does the same thing. so only rendering one animation.


we're getting there.
but please don't stress yourself. with the empty svg elements i now have a working solution!

again, thank you!
馃尵

@williamngan
Copy link
Owner

williamngan commented Dec 17, 2020

The empty div with id approach should work. I tested with your CodePen example and it seems to work. Can you check if you're using v0.9.6?

Here's a simplified example:

<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pts/0.9.6/pts.min.js"></script>
  </head>
  <body>
    <div id="one" style="width: 200px; height: 200px; background: #ccc"></div>
    <div id="two" style="width: 200px; height: 200px; background: #ccc"></div>
    <div id="three" style="width: 200px; height: 200px; background: #ccc"></div>
    
    <script>
      (function() {

      Pts.namespace(this);

      function createLine(id) {

        let space = new SVGSpace(id).setup({ bgcolor: 'transparent', resize: true });
        let form  = space.getForm();

        space.add({

          animate: function() {
            form.scope(this);
            form.fill('#F00').point( [
              Math.random()*space.innerBound.width, 
              Math.random()*space.innerBound.height],
              30, 'circle');
          }
        });

        space.play();
      }

      createLine('#one');
      createLine('#two');
      createLine('#three');

      })();    
    </script>

  </body>
</html>

There might be another issue with "svg element" approach -- I'll take a look.

Thanks!

@jaro-io
Copy link
Author

jaro-io commented Dec 18, 2020

you're right. sorry, this has been a mistake on my end. so, passing ids as a string when creating a new SVGSpace works fine when targeting both svgs and divs.

only passing javascript elements, like you can do with CanvasSpaces, is not working yet.

馃

@williamngan
Copy link
Owner

Hi @jaro-io , I'm revisiting this issue but cannot reproduce the "passing javascript element" problem you mentioned.

If I replace createLine("#three") in my minimal example above with createLine( document.querySelector("#three") ), it seems to work without issue. Can you provide more details on the error you encountered?

@williamngan
Copy link
Owner

Hi, closing this now. Please reopen if it continues to be an issue.

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