简体   繁体   English

使用javascript d3移动树的位置

[英]Move position of tree using javascript d3

I'm creating a diagram with D3 and JSON which is based on this: 我正在基于D3和JSON创建一个图:

http://bl.ocks.org/mbostock/4063550 http://bl.ocks.org/mbostock/4063550

I'm completely new to this...and I just can't seem to figure out how to move the position of the tree to the right or left of the page. 我对此完全陌生...我似乎无法弄清楚如何将树的位置移至页面的右侧或左侧。 Seems simple enough? 看起来足够简单?

Reason I'm asking is because some of my text are cut out on the left side of screen. 我问的原因是因为我的一些文本在屏幕左侧被切掉了。

Any help appreciated! 任何帮助表示赞赏!

The easiest way to do this is to adjust the transform parameter of the top-level g element. 最简单的方法是调整顶级g元素的transform参数。 In the example, it is created like this. 在示例中,它是这样创建的。

var svg = d3.select("body").append("svg")
  .attr("width", diameter)
  .attr("height", diameter - 150)
.append("g")
  .attr("transform", "translate(" + diameter / 2 + "," + diameter / 2 + ")");

To move everything to the right, you would need to add something to the x translation, eg 要将所有内容移到右侧,您需要在x转换中添加一些内容,例如

var svg = d3.select("body").append("svg")
  .attr("width", diameter)
  .attr("height", diameter - 150)
.append("g")
  .attr("transform", "translate(" + (diameter / 2 + 10) + "," + diameter / 2 + ")");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM