MCPcopy Index your code
hub / github.com/clips/pattern / update

Method update

pattern/graph/__init__.py:659–678  ·  view source on GitHub ↗

Updates the position of nodes in the graph. The weight parameter determines the impact of edge weight. The limit parameter determines the maximum movement each update().

(self, weight=10.0, limit=0.5)

Source from the content-addressed store, hash-verified

657 node1.force.y += f * dy
658
659 def update(self, weight=10.0, limit=0.5):
660 """ Updates the position of nodes in the graph.
661 The weight parameter determines the impact of edge weight.
662 The limit parameter determines the maximum movement each update().
663 """
664 GraphLayout.update(self)
665 # Forces on all nodes due to node-node repulsions.
666 for i, n1 in enumerate(self.graph.nodes):
667 for j, n2 in enumerate(self.graph.nodes[i+1:]):
668 self._repulse(n1, n2)
669 # Forces on nodes due to edge attractions.
670 for e in self.graph.edges:
671 self._attract(e.node1, e.node2, weight*e.weight, 1.0/(e.length or 0.01))
672 # Move nodes by given force.
673 for n in self.graph.nodes:
674 if not n.fixed:
675 n._x += max(-limit, min(self.force * n.force.x, limit))
676 n._y += max(-limit, min(self.force * n.force.y, limit))
677 n.force.x = 0
678 n.force.y = 0
679
680 def copy(self, graph):
681 g = GraphSpringLayout(graph)

Callers

nothing calls this directly

Calls 3

_repulseMethod · 0.95
_attractMethod · 0.95
updateMethod · 0.45

Tested by

no test coverage detected