【问题标题】:Get coordinates of clicked on node in d3 tree and centre获取在 d3 树和中心单击节点的坐标
【发布时间】:2013-09-20 19:52:57
【问题描述】:

我有一棵带有点击事件侦听器的树。我想将我的树重新集中在用户单击的任何节点上。

如何在点击事件中获取树节点的实际 x / y 值?

【问题讨论】:

    标签: layout tree d3.js click


    【解决方案1】:

    要获得 x/y,您必须通过已应用的任何翻译将节点翻译回来:

    http://jsfiddle.net/WLaVU 显示了您想要的工作示例。

    // click event handler 
    function click_handler(d)
    {
      // these dudes must be smooshed back through the same transform
      var x = xs(d);
      var y = ys(d);
    
      // normalize for width/height
      var new_x = (-x + (width / 2));
      var new_y = (-y + (height / 2));
    
      // move the main container g
      svg.attr("transform", "translate(" + new_x + "," + new_y + ")");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-14
      • 2013-01-03
      相关资源
      最近更新 更多