Skip to content

Commit 776f332

Browse files
committed
More pretty Béziers.
1 parent 0ca148d commit 776f332

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

examples/tree/tree-radial.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@ d3.json("flare.json", function(json) {
2020
.enter().append("svg:g")
2121
.attr("class", "link");
2222

23-
link.selectAll("line")
23+
link.selectAll("path")
2424
.data(children)
25-
.enter().append("svg:line")
26-
.attr("x1", function(d) { return x(d.parent); })
27-
.attr("y1", function(d) { return y(d.parent); })
28-
.attr("x2", function(d) { return x(d.child); })
29-
.attr("y2", function(d) { return y(d.child); });
25+
.enter().append("svg:path")
26+
.attr("d", path);
3027

3128
var node = vis.selectAll("g.node")
3229
.data(nodes)
@@ -54,6 +51,19 @@ d3.json("flare.json", function(json) {
5451
});
5552
}
5653

54+
// Computes a pretty Bézier curve from parent to child. TODO reusable helper?
55+
function path(d) {
56+
var y0 = (d.parent.y + d.child.y) / 2,
57+
p0 = d.parent,
58+
p3 = d.child,
59+
p1 = {x: p0.x, y: y0},
60+
p2 = {x: p3.x, y: y0};
61+
return "M" + x(p0) + "," + y(p0)
62+
+ "C" + x(p1) + "," + y(p1)
63+
+ " " + x(p2) + "," + y(p2)
64+
+ " " + x(p3) + "," + y(p3);
65+
}
66+
5767
// Radial scales for x and y.
5868
function x(d) { return d.y * Math.cos((d.x - 90) / 180 * Math.PI); }
5969
function y(d) { return d.y * Math.sin((d.x - 90) / 180 * Math.PI); }

examples/tree/tree.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
}
1010

1111
.link {
12+
fill: none;
1213
stroke: #ccc;
1314
stroke-width: 1.5px;
1415
}

0 commit comments

Comments
 (0)