I am newbie to D3. I am using force directed graph. I want to add two different type of shapes at node\'s places.
My json is following:
{
\"nodes\"
You can do this, as shown in e.g. this example, by using a symbol generator and path
elements instead of SVG elements for specific shapes. The code to add shapes becomes
var node = svg.selectAll(".node")
.data(data.nodes)
.enter().append("path")
.attr("class", "node")
.attr("d", d3.svg.symbol()
.type(function(d) { return d3.svg.symbolTypes[d.s]; }))
.style("fill", function(d) { return color(d.group); })
.call(force.drag);
Then you also need to change your tick
handler to change the transform
attribute of the path
elements:
node.attr("transform", function(d) {
return "translate(" + d.x + "," + d.y + ")";
});
Complete jsfiddle here.