Can D3 force layout visualize multigraph?

d3.js, force-layout, graph, social-networking, visualization

Solution

You could encode your multigraph trivially as a graph by creating a set of links, where each link is a bundle of the form:

{"links": [/* one or more links*/], "source": …, "target": …}

You could then run the force-directed layout as per usual to position your nodes. You would then need to represent each bundle appropriately e.g. by drawing parallel lines.

Related: Mike Bostock has used a simple hack to represent two parallel links between nodes, although this does not easily scale to more links.

Problem

It seems that if there exist multiple links between two nodes in D3 force layout, D3 just picks up one and ignores others. Is it possible to visualize multigraph?

Original source