D3: Substituting d3.svg.diagonal() with d3.svg.line()

后端 未结 4 952
离开以前
离开以前 2020-12-08 16:04

I have implemented the following graph with the edges rendered with d3.svg.diagonal(). However, when I try substituting the diagonal with d3.svg.line(), it doesn\'t appear t

4条回答
  •  猫巷女王i
    2020-12-08 16:13

    Perhaps encapsulating the diagonal function and editing its parameters could work for you:

    var diagonal = d3.svg.diagonal();
    var new_diagonal = function (obj, a, b) {
        //Here you may change the reference a bit.
        var nobj = {
            source : {
                x: obj.source.x,
                y: obj.source.y
            },
            target : {
                x: obj.target.x,
                y: obj.target.y
            }
        }
        return diagonal.apply(this, [nobj, a, b]);
    }
    var link= svg.selectAll("path")
        .data(links)
        .enter().append("path")
        .attr("d",new_diagonal)
        .attr("class", ".link")
        .attr("stroke", "black")
        .attr("stroke-width", "2px")
        .attr("shape-rendering", "auto")
        .attr("fill", "none"); 
    

提交回复
热议问题