A force-based layout in which edges are regarded as springs. The forces are applied to the nodes, pulling them closer or pushing them apart.
(self, graph)
| 613 | class GraphSpringLayout(GraphLayout): |
| 614 | |
| 615 | def __init__(self, graph): |
| 616 | """ A force-based layout in which edges are regarded as springs. |
| 617 | The forces are applied to the nodes, pulling them closer or pushing them apart. |
| 618 | """ |
| 619 | # Based on: http://snipplr.com/view/1950/graph-javascript-framework-version-001/ |
| 620 | GraphLayout.__init__(self, graph) |
| 621 | self.k = 4.0 # Force constant. |
| 622 | self.force = 0.01 # Force multiplier. |
| 623 | self.repulsion = 15 # Maximum repulsive force radius. |
| 624 | |
| 625 | def _distance(self, node1, node2): |
| 626 | # Yields a tuple with distances (dx, dy, d, d**2). |