那么你需要注意的部分是:
var circles = vis.append("circle")
.attr("stroke", "black")
.style("fill", function(d) { return !d.children ? "tan" : "beige"; })
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; })
.attr("r", function(d) { return d.r; });
这里发生的情况是,您正在创建一个具有 cx、cy 和 r 属性的 svg 圆形元素,类似于<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
要将其转换为省略号,您需要知道需要设置哪些属性。可以像这样创建 svg 椭圆元素:<ellipse cx="200" cy="80" rx="100" ry="50">
请注意您需要如何设置cx
, cy
, rx
, and ry
相对于cx
, cy
, and r
for <circle>
基于这些知识,您现在应该能够将圆转换为椭圆,如下所示:
var ellipses = vis.append("ellipse")
.attr("stroke", "black")
.style("fill", function(d) { return !d.children ? "tan" : "beige"; })
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; })
.attr("rx", 10) // define your own rule for x radius
.attr("ry", 5); // define your own rule for y radius