d3.js Indented tree with straight links

前端 未结 2 1982
误落风尘
误落风尘 2021-02-06 10:40

My code is based on the D3.js Indented tree example.

I want straight links instead of the curved links between parent/child-objects.

I understand this has someth

2条回答
  •  悲哀的现实
    2021-02-06 11:19

    The problem is to extract the x and y points from the links. One way of doing this is:

    Link generator:

    self.diagonal = d3.svg.line().interpolate('step')
            .x(function (d) { return d.x; })
            .y(function (d) { return d.y; });
    

    And then use the generator like this:

    link.enter().append('svg:path', 'g')
            .duration(self.duration)
            .attr('d', function (d) {
                return self.diagonal([{
                    y: d.source.x,
                    x: d.source.y
                }, {
                    y: d.target.x,
                    x: d.target.y
                }]);
            });
    

提交回复
热议问题