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

for dynamically appended svg, im getting this error #247

Closed
sharpvarun opened this issue Jun 13, 2017 · 7 comments
Closed

for dynamically appended svg, im getting this error #247

sharpvarun opened this issue Jun 13, 2017 · 7 comments

Comments

@sharpvarun
Copy link

sharpvarun commented Jun 13, 2017

Uncaught DOMException: Failed to execute 'inverse' on 'SVGMatrix': The matrix is not invertible.
at SvgPanZoom.zoomAtPoint (http://localhost/school/js/svg-pan-zoom.js:753:52)
at SvgPanZoom.handleMouseWheel (http://localhost/school/js/svg-pan-zoom.js:724:8)
at SVGSVGElement.wheelListener (http://localhost/school/js/svg-pan-zoom.js:667:19)

observation: initial transform matrix is setting to zero, here's how it's setting: transform="matrix(0,0,0,0,0,0)"

svg is appended like this:
//html

@bumbu
Copy link
Owner

bumbu commented Jun 17, 2017

Hi,

Please read the support section of the Readme.
Also check the dynamic loading demo.

@sharpvarun
Copy link
Author

sharpvarun commented Jun 17, 2017 via email

@bumbu
Copy link
Owner

bumbu commented Jun 17, 2017

That depends on the browser implementation, some browsers are detaching foreign objects (like iframe, svg) when an ancestors is hidden. It would be possible for the library to check at any event that all parent elements are visible, but that's computationally inefficient and too specific. The developer should be responsible for knowing when to initialise the library.

Also see this comment.

@sharpvarun
Copy link
Author

sharpvarun commented Jun 17, 2017 via email

@jacobwindsor
Copy link
Collaborator

I had this same issue when SVG mounted to DOM and fixed it by just giving a height and width to the container. Any value works it seems, even %

@m-podlesny
Copy link

Thanks for inspiration @jacobwindsor. What was working for me is:

// view.tsx
      <div className={classes.container} ref={setRef}>
        <svg viewBox={`0 0 ${width} ${height}`} style={{ width, height }}>
          <g className="svg-pan-zoom_viewport">
            <image x="0" y="0" xlinkHref={url} width={width} height={height} />
          </g>
        </svg>
      </div>
  • classes.container has width: "100%" and height: "100%" CSS props, but it wasn't enough in my case.
  • setRef creates the ref from which some React hook/helper reads the rendered size in pixels, that are available by width and height variables (given to the svg and image elements)

@HammadManzoor
Copy link

Faced the same issue. The problem occurs when you try to use reset when the container for the svg is not visible on the viewport. I fixed it by checking for this before performing reset.

const divElement = this.el.nativeElement.querySelector( '#myContainer' ); if (divElement) { const viewportHeight = window.innerHeight; const divOffset = divElement.getBoundingClientRect().top; // Check if the div is in the viewport if (divOffset < viewportHeight) { this.svgPanZoom.resize(); this.svgPanZoom.reset(); } }

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

No branches or pull requests

5 participants