简体   繁体   中英

Move position of tree using javascript d3

I'm creating a diagram with D3 and JSON which is based on this:

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. 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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