Skip to main content
100%

Force Layout Example 1

✓ Published0🌍 Public
SSputniza
Last edited Aug 5, 2016
Created on Aug 5, 2016

This example demonstrates a minimal force-directed graph with five nodes and four links arranged in a branching structure, rendered as circles and lines in an SVG container. The code uses the D3.js v3 `d3.layout.force()` API to simulate the layout, with node positions and link distances updated after the simulation ends. It defines dimensions of 640x480 pixels, adds nodes and links as SVG elements before applying the force simulation, and sets a link distance based on half the canvas width. The visualization shows the basic mechanics of force layout without additional interaction or styling beyond grayscale fills.

AI-generated description

This is part of a series of examples that describe the basic operation of the D3.js force layout. Eventually they may end up in a blog post that wraps everything together.

The first example creates the simplest possible graph using a force layout. The comments in the code walk through the steps in creating a force directed graph.

Things start to get more interesting in the next example.

forked from <a href='http://bl.ocks.org/sathomas/'>sathomas</a>'s block: <a href='http://bl.ocks.org/sathomas/11550728'>Understanding D3.js Force Layout - 1: The Simplest Possible Graph</a>

gpl-3.0 Licensed

Similar vizzes