3d -js的强制布局是否支持图像作为节点?

Does Force-Directed Layout of d3-js support image as node?

本文关键字:图像 节点 支持 是否 -js 布局 3d      更新时间:2023-09-26

d3有一个力定向图形布局的演示。

我希望图中的所有节点都是图像,而不是圆圈。

所以,我改变了

 .append("svg:circle")
      .attr("class", "node")
      .attr("cx", function(d) { return d.x; })
      .attr("cy", function(d) { return d.y; })
      .attr("r", 5)
      .style("fill", function(d) { return fill(d.group); })
      .call(force.drag);

.append("xhtml:img")
   .attr("src", "http://a577.phobos.apple.com/us/r1000/081/Purple/12/61/13/mzi.lgqdzwfu.png")
   .call(force.drag);

但是我看不到任何图像。我做错了什么?

node.append("svg:image")
    .attr("class", "circle")
    .attr("xlink:href", "https://d3nwyuy0nl342s.cloudfront.net/images/icons/public.png")
    .attr("x", "-8px")
    .attr("y", "-8px")
    .attr("width", "16px")
    .attr("height", "16px");

下面是使用图像作为节点的示例:http://bl.ocks.org/950642