首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用D3对角线函数绘制曲线?

如何使用D3对角线函数绘制曲线?
EN

Stack Overflow用户
提问于 2013-02-22 00:53:01
回答 1查看 20.1K关注 0票数 21

我查看了示例http://bl.ocks.org/mbostock/raw/4063570/

它从源目标从左到右生成漂亮的合并行。

在我的例子中,我需要手动布局节点并放置x,y坐标。在这种情况下,线条不会在源节点上合并。以下是重现此问题的测试代码:

var data = [ {name: "p1", children: [{name: "c1"}, {name: "c2"}, {name: "c3"}, {name: "c4"}]}];
var width = 400, height = 200, radius = 10, gap = 50;

// test layout
var nodes = [];
var links = [];
data.forEach(function(d, i) {
    d.x = width/4;
    d.y = height/2;
    nodes.push(d);
    d.children.forEach(function(c, i) {
        c.x = 3*width/4;
        c.y = gap * (i +1) -2*radius;
        nodes.push(c);
        links.push({source: d, target: c});
    })
})

var color = d3.scale.category20();

var svg = d3.select("#chart").append("svg")
        .attr("width", width)
        .attr("height", height)
        .append("g");
var diagonal = d3.svg.diagonal()
        .projection(function(d) { return [d.x, d.y]; });

var link = svg.selectAll(".link")
        .data(links)
        .enter().append("path")
        .attr("class", "link")
        .attr("d", diagonal);

var circle = svg.selectAll(".circle")
        .data(nodes)
        .enter()
        .append("g")
        .attr("class", "circle");

var el = circle.append("circle")
        .attr("cx", function(d) {return d.x})
        .attr("cy", function(d) {return d.y})
        .attr("r", radius)
        .style("fill", function(d) {return color(d.name)})
        .append("title").text(function(d) {return d.name});

http://jsfiddle.net/zmagdum/qsEbd/上有这样的示例

但是,接近节点的曲线的行为似乎与所需的相反。我希望它们在节点处水平直起,并在中间形成一条曲线。有什么技巧可以做到这一点吗?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15007877

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档