Convert d3 svg coordinates to canvas coordinates

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Convert d3 svg coordinates to canvas coordinates



I have some d3 svg elements in which I pass as attribute a list of coordinates x,y and I plot them on a svg map. Like the example below:


var svg = iniMarker().append("g")
.attr("data-lineData", JSON.stringify(lineData))



Now I need to represent each of these points taken from this coordinates list on a canvas map. And in that case the problem is that the svg coordinates of the list don't match with the canvas coordinate.



In fact if I try to generate some canvas coordinate points by using the function below:


document.getElementById("canv").onclick = function (e)
var localX = e.clientX - e.target.offsetLeft;
var localY = e.clientY - e.target.offsetTop;



Then the coordinates at the onclick event are pretty much different from the svg coordinates.
I need to find a way to convert the list of svg coordinates that I have in order to match or be more similar as possibile to the canvas coordinates system.



I'm open to suggestions.









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

cDlB,vz,f2RozHcyne x2D9n3Ml82ZPV7 dyQVO01,zHTgzuevz,zmgDAk n 6msqZuCJwDEG 3B0u,kPKDcMqfMJ
j I,59,ur6WaOAtsFZZMW6znEErB 8yq 4TQAz502IeEGDZxkvfSB wO,wb,j0oCTh6V,jXlU6IAdX i 9ZrfHG4I9g 3

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3