d3 retrieve and add to current selection's attribute value

前端 未结 2 1179
忘了有多久
忘了有多久 2021-02-07 07:37

I\'m trying to get the values for an element\'s translation.

For example, if I select the x axis:

d3.select(\'.x.axis\').attr(\"transform\")

相关标签:
2条回答
  • 2021-02-07 08:29

    if you would like to use selectAll you could try something like this:

    // move ticks to the center of the x-axis   
    var transform;
    d3.selectAll('.tick').attr('transform', function(){
      transform = d3.transform(d3.select(this).attr("transform"));
      return "translate("+transform.translate[0]+", -3)";
    });
    
    0 讨论(0)
  • 2021-02-07 08:37

    D3 provides the transform() function for exactly this purpose:

    var t = d3.transform(d3.select('.x.axis').attr("transform")),
        x = t.translate[0],
        y = t.translate[1];
    
    0 讨论(0)
提交回复
热议问题