Skip to content
New issue

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

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

Already on GitHub? # to your account

Standalone SVG: Uncaught TypeError: node.getAttribute is not a function #720

Closed
simonwidjaja opened this issue Jul 19, 2017 · 8 comments
Closed

Comments

@simonwidjaja
Copy link

I have a very basic standalone SVG that look like this:

<?xml version="1.0" encoding="utf-8" ?>
<svg version="1.1"
  id="stage"
  xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
  x="0px" y="0px" width="800px" height="500px" viewBox="0 0 800 500" xml:space="preserve">
<script xlink:href="svg.js"></script>
<script>
  var draw = SVG('stage')
  draw.image('car1.jpg', 800, 500);
</script>
</svg>

This approach works. And I can draw all kinds of native SVG elements (rect, circle etc.)
EXCEPT images are throwing the following error (they will be rendered properly though...)

screen shot 2017-07-19 at 16 16 37

Any ideas what is going wrong here?

@simonwidjaja
Copy link
Author

Is the assumption that draw.image(...) should be fully supported in a pure/standalone SVG right? or are there any known issues? This is critical for my current project, so any hint is highly appreciated

@Fuzzyma
Copy link
Member

Fuzzyma commented Jul 21, 2017

I tried this and in my case the image is loading. It throws an error anyway. However - this only happens when using a standalone svg and when the image is not used in a pattern.

How it comes, that the image does not load in your case? The error does not impact the image loading itself

@simonwidjaja
Copy link
Author

thanks for the feedback.
The image WILL BE loaded and displayed.
quote: "(they will be rendered properly though...)"
I just wanted to know if this is the wrong path I am taking and if there is a known issue. I don't like uncaught errors in my project ;) So I need to know if SVG.js is the right library for pure/standalone SVGs.

@Fuzzyma
Copy link
Member

Fuzzyma commented Jul 21, 2017

Its a bug which will be fixed in the next release. However it wont anything bad in your case

@simonwidjaja
Copy link
Author

ok. so you are saying a try...catch and good to go? I will do that. Any update when we can roughly expect the next release?
I have heavily worked with SVG.js for the last two weeks and it's really fun. Keep up the great work!

@simonwidjaja
Copy link
Author

I cannot even catch that error:

    var s = SVG('stage')
    s.circle(200,200)
    try {
      s.image('car1.jpg', 200, 200)
    }
    catch(err) {
      console.warn(err.toString())
    }

BTW: Is branch 3.0.0 already useful? I'm not implementing production code yet, so "beta" version would be fine...

@Fuzzyma
Copy link
Member

Fuzzyma commented Jul 21, 2017

The error is asyncronous and cant be catched by a syncronous try catch. The fix is released with 2.6.3.

In 3.0 i didnt see that error popping up. Its under development and will change rapidly in the next weaks (I already have some commits prepared which change a lot. However I need to test everything properly)

@simonwidjaja
Copy link
Author

Oh just saw your fix/commit. Just replaced 2.6.2 with your 2.6.3. Works like a charm so far.
Thanks a lot! Looking forward to v3.

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

No branches or pull requests

2 participants