我在我的私人网站中使用this图形来显示产品关系,它效果很好。d3.js支持每个节点的图像
我发现this site节点为图像。试图找出如何重构我当前的图形以支持每个节点的图像。
任何帮助,将不胜感激
编辑:与“形象”(而不是img
)的问题是,我不能对应用CSS。我使用twitter bootstrap并试图添加名为img-circle
的类(仅添加border-radius: 50%
),但它不适用于图像。都尝试:
var nodeImage = node.append("image")
.attr("xlink:href", function (d) { return d.image })
.attr("height", function (d) { return d.height + "" })
.attr("width", function (d) { return d.width + "" })
.attr("x", function (d) {return -0.5 * d.width })
.attr("y", function (d) {return -0.5 * d.height })
.attr("class", "img-circle");
和:
var nodeImage = node.append("image")
.attr("xlink:href", function (d) { return d.image })
.attr("height", function (d) { return d.height + "" })
.attr("width", function (d) { return d.width + "" })
.attr("x", function (d) {return -0.5 * d.width })
.attr("y", function (d) {return -0.5 * d.height })
.attr("style", "border-radius: 50%;");
都不起作用
EDIT2: DONE!
通过添加以下行:
.attr("clip-path", function (d) { return "circle(" + (0.48 * Math.max(d.width, d.height)) + "px)"});
标签是d3.js但标题是3d.js – manassehkatz
@manassehkatz感谢,固定 – ItayB