javascript - d3.js - Tree Layout - How can I flip it? - Stack Overflow

I'm using this example for a D3.js tree layout. .htmlI need to flip it, so the root node is on the

I'm using this example for a D3.js tree layout.

.html

I need to flip it, so the root node is on the right hand side, and the links... etc.

How can I achieve this?

I'm using this example for a D3.js tree layout.

http://mbostock.github./d3/talk/20111018/tree.html

I need to flip it, so the root node is on the right hand side, and the links... etc.

How can I achieve this?

Share Improve this question asked Mar 27, 2013 at 23:12 user1277546user1277546 8,7823 gold badges19 silver badges26 bronze badges 1
  • possible duplicate of Tree drawing orientation – Ian Commented Feb 9, 2015 at 15:47
Add a ment  | 

1 Answer 1

Reset to default 8
  • Change the offset of each node to be from the right rather than offset from the left:

    // Normalize for fixed-depth.
    nodes.forEach(function(d) { d.y = d.depth * 180; });
    

Bees:

    // Normalize for fixed-depth from right.
    nodes.forEach(function(d) { d.y = w - (d.depth * 180); });
  • Change the labels to be on the opposite sides

    nodeEnter.append("svg:text")
      .attr("x", function(d) { return d.children || d._children ? -10 : 10; })
      .attr("dy", ".35em")
      .attr("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; })    
      .text(function(d) { return d.name; })
      .style("fill-opacity", 1e-6);
    

Bees:

    nodeEnter.append("svg:text")
      .attr("x", function(d) { return d.children || d._children ? 10 : -10; })
      .attr("dy", ".35em")
      .attr("text-anchor", function(d) { return d.children || d._children ? "start" : "end"; })    
      .text(function(d) { return d.name; })
      .style("fill-opacity", 1e-6);
  • Make original position of the root node on the right hand side, rather than the left so first transition isn't weird:

    root = json;
    root.x0 = h / 2;
    root.y0 = 0;
    

Bees:

    root = json;
    root.x0 = h / 2;
    root.y0 = w;

Fiddle: http://jsfiddle/Ak5tP/1/embedded/result/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744316095a4568190.html

相关推荐

  • javascript - d3.js - Tree Layout - How can I flip it? - Stack Overflow

    I'm using this example for a D3.js tree layout. .htmlI need to flip it, so the root node is on the

    7天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信