Get coordinates of clicked on node in d3 tree and centre

一曲冷凌霜 提交于 2019-12-04 18:52:52

To get the x/y you must translate the nodes back through whatever translation you've already applied:

http://jsfiddle.net/WLaVU shows a working example of what you want.

// 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 + ")");
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!