I have a bunch of dots that I'm placing at even intervals around a circle. I'm doing this by setting their cx
and cy
attributes to the initial position, then iterating over each dot and giving it a transform(rotate)
to move it to where I want it.
var dot = dotPlaces.append("circle")
.attr("cx", dotOriginX )
.attr("cy", dotOriginY )
.attr("r", 20 / 2)
.attr("opacity", 1)
.attr("id", function(d) { return d.name; })
.attr('fill', function(d) {
return color(d.type);
})
.attr("transform", function(d,i) {
return "rotate("+ (i * (360/actualData.length)) +"," + originX + "," + originY + ")";
})
.attr("stroke", "white");
My problem arrives when later in the code I want to draw lines to these dots. Whether I get their cx
/cy
attributes or their bounding box, it always references the original pre-transform position. I need their post-transform position. Apparently in d3 v3 there was a transform
call that could be used, but in v4 this has vanished. Since I'm using a rotation and not a simple translation, this is less trivial than just adding some x and y offset.
This is what I'm using now, for reference:
var x = svg2.select("#"+key).node().getAttribute("cx");
var y = svg2.select("#"+key).node().getAttribute("cy");
//alternatively node().getBBox(); which also fails to give post-transform position.