I have a big circle SVG element and four rect
elements that are correctly rotated around the edges of it. I'm using
.attr('transform', function(d, i) {return 'rotate(' + 40 + ((i+1)*30) + ', 110, 155)'; })
to rotate these rectangles around the origin, where 110 and 155 are the center coordinates of the circle.
I want to add text off to the side of the rectangles and I don't want them to be rotated. Typically I would do something like
svg.selectAll('text')
.data(data)
.enter()
.append('text')
Then I would use the same x and y coordinates specified for the rectangles for the text. However, because I'm using a transform rotate for the rectangles, I can't specify the same x
and y
attributes. I want the text to look like this:
The rectangles are rotated around the origin, but the text is not. I tried using each
to add the text and have it appear next to the rectangle, but to no avail.
I've made a codepen to demonstrate. How can I get the text to appear next to the rectangles without being rotated?