You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why? Because #foo's DOM position is not provided to the SVG class during instantiation.
However, this will work, because the HTMLElement has an instantiated {x,y} position within its node.
// ... draw() instantiation// ...constgetHTMLElementPositionById=(selector)=>{const{ x , y }=document.getElementById(selector).getBoundingClientRect()// or spread whatever else you needreturn{ x , y }}const{ fooX, fooY }=getHTMLElementPositionById('foo')const{ barX , barY }=getHTMLElementPositionById('bar)
draw.line(fooX, fooY, barX, barY)
Any positional data should be collected upon instantiation if heavy positional manipulation is required- this can be done by putting svgs into other elements in the DOM tree and using them as references in the case that things move.
SVG.js elements have getters and setters for position, but these are abstracted from the DOM position of these elements. Unless provided in the constructor and/or manipulated later, you're not going to be able to get positional information from referencing your SVG object.
I would try again by instantiating the SVG class with native attributes.
If an element is already instantiated and THEN provided to the SVG class, its position will be {0,0}:{ x , y}. This is not a valid way to get the position of these elements unless they are instantiated with x and y values, in which case the getter can provide this information. Otherwise, these values were not set in the constructor of the instance and will return their relative value to their initial position when a positional getter is called.
i have below layout:
Want to click rect and draw a polyline to item-1. Stuck in the position of item-1's top.
Anyone can give me a tips? I would be very grateful.
enter image description here
Have tried bbox, getBoundingClientRect, all are not correct.
The text was updated successfully, but these errors were encountered: