def build(self, tree): self.diagram = Diagram() diagram = self.instantiate(self.diagram, tree) self.bind_edges(diagram) if len(self.diagram.lanes) == 0: self.diagram.lanes.append(NodeGroup.get(None)) for node in self.diagram.nodes: if node.lane is None: edges = DiagramEdge.find(None, node) parents = [e.node1 for e in edges if e.node1.lane] parents.sort(key=lambda x: x.order) if parents: node.lane = parents[0].lane node.lane.nodes.append(node) else: node.lane = self.diagram.lanes[0] node.lane.nodes.append(node) for lane in diagram.lanes: if len(lane.nodes) == 0: diagram.lanes.remove(lane) return diagram
def bind_edges(self, group): for node in group.nodes: if isinstance(node, DiagramNode): group.edges += DiagramEdge.find(node) else: self.bind_edges(node)