D3.js: rotate group, keep text the same orientation?

前端 未结 1 829
遥遥无期
遥遥无期 2021-01-23 20:02

I have the following data, relating to arrow strikes on a target:

var data = [
    { name: \"Bullseye\", dist: 0, angle: 0 },   
    { name: \"Strike 1\", dist         


        
相关标签:
1条回答
  • 2021-01-23 20:18

    Regarding your fiddle, an update:

     return "rotate(" + d.angle + ") " + 
            "translate(" + d.dist + ",0) " + 
            "rotate(" + (-1 * d.angle) + ")";
    

    By rotating first, the translation on the "x" is now moving in the rotated coordinate space. This puts the strike points where you want. By rotating back again, the text is corrected.

    0 讨论(0)
提交回复
热议问题