I donโt have much time to clarify this answer, but it helped me convert svg coordinates to absolute position
//this will convert an x, y coordinate within a viewBox - or not in one at all (I think) - to an absolute position on the document //my <svg>...</svg> element had a viewbox on it and it still worked... convertCoords: function(svgElement, elementToConvert, x, y) { var element_x = elementToConvert.getBBox().x; var element_y = elementToConvert.getBBox().y; var offset = svgElement.getBoundingClientRect(); var matrix = elementToConvert.getScreenCTM(); return { x: (matrix.a * x) + (matrix.c * y) + matrix.e - offset.left, y: (matrix.b * x) + (matrix.d * y) + matrix.f - offset.top }; },
and actually use the code to create useful things:
svgGraphLibObject.convertCoords(mysvg, allCircleElements[0], allCircleElements[0].getBBox().x, 0)
where mysvg is a container element. i.e.
var mysvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
allCircleElements [0] is a valid element for allCircleElements [0] .getBBox (). x is the position of x, which will be converted later to the absolute position, and finally, the last parameter (i.e. 0) is the y-position to convert to absolute position
hope this helps anyone in the future
remain blessed
source share