[core] add node position property

Nodes can now be placed at a certain position
* add Position namedtuple
* expose 'position', 'x' and 'y' properties on BaseNode
This commit is contained in:
Yann Lanthony 2018-07-26 15:06:26 +02:00
parent 5843c36435
commit dfb0934ef4
2 changed files with 39 additions and 9 deletions

View file

@ -426,13 +426,14 @@ class Graph(BaseObject):
return inEdges, outEdges
def addNewNode(self, nodeType, name=None, **kwargs):
def addNewNode(self, nodeType, name=None, position=None, **kwargs):
"""
Create and add a new node to the graph.
Args:
nodeType (str): the node type name.
name (str): if specified, the desired name for this node. If not unique, will be prefixed (_N).
position (Position): (optional) the position of the node
**kwargs: keyword arguments to initialize node's attributes
Returns:
@ -441,7 +442,7 @@ class Graph(BaseObject):
if name and name in self._nodes.keys():
name = self._createUniqueNodeName(name)
n = self.addNode(Node(nodeType, **kwargs), uniqueName=name)
n = self.addNode(Node(nodeType, position=position, **kwargs), uniqueName=name)
n.updateInternals()
return n