Bahador Saket Bahador Saket - 1 year ago 157
jQuery Question

How to convert pixel to translate value in d3?

I have a g element that I am trying to put on a top of my circle element by giving the cx and cy position of the circle to g element. However, this does not work because the g uses translate. Any idea how to convert pixel to translate?

colorPickerX ="cx");
colorPickerY ="cy");
var svg ="body")
.attr("width", 300)
.attr("height", 300)
.attr("transform", "translate("+colorPickerX+","+colorPickerX+")"); \\This is wrong because Cx and Cy are Pixels

Answer Source

Do this using parseFloat:

//parseFloat will get the number and ignore the px in the end.
colorPickerX = parseFloat("cx"));
colorPickerY = parseFloat("cy"));

Then use it to translate the g group as you doing above.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download