Using templates to add an image to a rectangle can make your visualization pretty slow.
Instead, you can do something like this, this is the code that I used for my rectangular nodes in the force layout, I wanted to put rectangles filled with nodes in the image:
var node = svg.selectAll(".node") .data(force.nodes()) .enter().append("g") .attr("class", "node"); node.append("rect") .attr("width", 80) .attr("height", 120) .attr("fill", 'none') .attr("stroke", function (d) { return colors(d.importance); }); node.append("image") .attr("xlink:href", function (d) { return d.cover;}) .attr("x", 2) .attr("width", 76) .attr("height", 120) .on('dblclick', showInfo);
Audrey san
source share