mbostock/d3 — Issue #358: The chord & force layouts are stateful.
Author: mbostock
Created: 2011-10-28 23:25:26+00:00
State: open

Layouts are generally supposed to be stateless; they are high-level functions that you use to transform (pre-process) data. But the chord layout and force layout are different in that they are bound to specific datasets, rather than as reusable functions.

The reason for this is that a layout may have multiple inputs and multiple outputs, which makes the standard approach of a function with one input and one output more difficult to use. The chord layout takes a matrix as input but returns a set of chords and groups. The force layout takes nodes and links as input; you also need something which controls the force simulation, so that it can be started and stopped.

I'm not sure there's any strong need to change the design of these layouts. There's no strict convention about how layouts are designed. Perhaps doing anything else would just make them harder to use. But I'm filing this issue to track this potential design issue.