def make_arrow_symbol(identifier: str, size=6, closed=False) -> EndpointSymbol: return EndpointSymbol( element=Node(children=[ Node(properties=NodeProperties(shape=Path.from_list( [(size / 2, -size / 3), (0, 0), (size / 2, size / 3)], closed=closed, ), ), ), ], ), identifier=identifier, path_offset=Point(x=(-size / 1.75) if closed else 0, y=0), symbol_offset=Point(x=-1, y=0), )
def test_simple_flat(): """Have factory generate graphs from two connected nodes""" n1 = Node() n2 = Node() n1.add_edge(n1, n2) factory = MarkFactory() g, tree = factory(n1, n2) assert len(g) == 2, "Expecting only two nodes" assert len(g.edges) == 1, "Expect only one edge" assert len(tree) == 0, "Expecting no hierarchy" assert len(tree.edges) == 0, "Expecting no hierarchy"
def make_redefinition_symbol(identifier: str, size=6) -> EndpointSymbol: return EndpointSymbol( element=Node(children=[ Node(properties=NodeProperties(shape=Path.from_list( [(size * 4 / 5, -size / 3), (size * 4 / 5, size / 3)], ), ), ), Node(properties=NodeProperties(shape=Path.from_list( [(size / 2, -size / 3), (0, 0), (size / 2, size / 3)], closed=True, ), ), ), ], ), identifier=identifier, path_offset=Point(x=-size / 1.75, y=0), symbol_offset=Point(x=-1, y=0), )
def make_subsetting_symbol(identifier: str, size=6) -> EndpointSymbol: return EndpointSymbol( element=Node(children=[ Node(properties=NodeProperties(shape=Circle( radius=size / 5, x=size / 5, y=0, ), ), ), Node(properties=NodeProperties(shape=Path.from_list( [(size, -size / 2.5), (size / 2.5, 0), (size, size / 2.5)], closed=False, ), ), ), ], ), identifier=identifier, path_offset=Point(x=-size / 1.9, y=0), symbol_offset=Point(x=-1, y=0), )
def make_containment_symbol(identifier: str, size=6) -> EndpointSymbol: return EndpointSymbol( identifier=identifier, element=Node(children=[ Node(properties=NodeProperties(shape=Circle( radius=size, x=size, y=0, ))), Node(properties=NodeProperties(shape=Path.from_list([( 0, 0), (2 * size, 0)]), )), Node(properties=NodeProperties(shape=Path.from_list([( size, -size), (size, size)]), )), ]), symbol_offset=Point(x=-1, y=0), path_offset=Point(x=-2 * size, y=0), )
def test_edge_port_instances(): n1 = Node() x = n1.add_port(Port(), "x") n2 = Node() e = Edge( source=x, target=n2, ) assert e.source is x, "Edge source instance changed" assert e.target is n2, "Edge target instance changed" n1.dict() x.dict() n2.dict() e.dict()
def test_add_child(): key = "child" n = Node() p = n.add_child(Node(), key) assert p.get_parent() is n, "Expect port parent to be the node" assert n.get_child(key) is p, "Expect node port dict to return same port" n.dict()
def test_edge_node_instances(): n1 = Node() n2 = Node() e = Edge( source=n1, target=n2, ) assert e.source is n1, "Edge source instance changed" assert e.target is n2, "Edge target instance changed" n1.dict() n2.dict() e.dict()
def test_simple_factory(): """Have factory generate graphs from only a single node""" n1 = Node() factory = MarkFactory() g, tree = factory(n1) assert len(g) == 1, "Expecting only one nodes" assert len(g.edges) == 0, "Expect no edges" assert len(tree) == 0, "Expecting no hierarchy" assert len(tree.edges) == 0, "Expecting no hierarchy"
def make_feature_typing_symbol(identifier: str, size=6) -> EndpointSymbol: return EndpointSymbol( element=Node(children=[ Node(properties=NodeProperties(shape=Circle( radius=size / 20, x=size * 4 / 5, y=size / 4, ), ), ), Node(properties=NodeProperties(shape=Circle( radius=size / 20, x=size * 4 / 5, y=-size / 4, ), ), ), Node(properties=NodeProperties(shape=Path.from_list( [(size / 2, -size / 3), (0, 0), (size / 2, size / 3)], closed=True, ), ), ), ], ), identifier=identifier, path_offset=Point(x=-size / 1.75, y=0), symbol_offset=Point(x=-1, y=0), )
def test_simple_hierarchy(): """Have factory generate graphs from connected parent child""" n1 = Node() n2 = Node() n1.add_edge(n1, n2) n1.add_child(n2, "x") factory = MarkFactory() g, tree = factory(n1) assert len(g) == 2, "Expecting only two nodes" assert len(g.edges) == 1, "Expect only one edge" assert len(tree) == 2, "Expecting two nodes in hierarchy" assert len(tree.edges) == 1, "Expect only one edge"
def make_rhombus_symbol(identifier: str, size: float = 6) -> EndpointSymbol: return EndpointSymbol( identifier=identifier, element=Node(properties=NodeProperties(shape=Path.from_list( [ (0, 0), (size, size / 2), (2 * size, 0), (size, -size / 2), ], closed=True, )), ), symbol_offset=Point(x=-1, y=0), path_offset=Point(x=-2 * size, y=0), )
async def test_pipeline_check_dirty(): f1 = ("a", ) f2 = ("b", ) f3 = ("c", ) p1 = Pipe( observes=f1, reports=f2, ) p2 = Pipe( observes=f3, reports=f3, ) p = Pipeline(pipes=(p1, p2)) assert p.check(), "pipeline should contain no broken pipes" p.inlet = MarkElementWidget( flow=f1, value=Node(), ) # test pipeline with only `p1` dirty assert len(p.outlet.flow) == 0 assert p.check_dirty() assert p.status.dirty() assert p1.status.dirty() assert not p2.status.dirty() assert len( p.outlet.flow) == 2, f"Expected two flow flags: `{p.outlet.flow}`" assert p.reports == f2, f"Expected pipeline reports to be f2: `{p.reports}`" # test pipeline with only `p2` dirty p.inlet.flow = f3 assert p.check_dirty() assert p.status.dirty() assert not p1.status.dirty() assert p2.status.dirty() assert len(p.outlet.flow ) == 1, f"Expected two flow flags. Recieved {p.outlet.flow}" assert p.reports == f3, f"Expected pipeline reports to be f3: `{p.reports}`" assert ( p.inlet.value is not p.outlet.value), "Inlet value should not have propagated yet" await p.run() assert p.inlet.value is p.outlet.value, "Inlet value should have propagated" assert not p.status.dirty(), "Pipeline should not still be dirty" assert not p1.status.dirty(), "`p1` should not still be dirty" assert not p2.status.dirty(), "`p2` should not still be dirty"
def test_node_label_instance(): label = Label() n = Node(labels=[label]) assert n.labels[0] is label, "Expect node label instance to match" label.dict()
def test_node_instances(): n1 = Node() n1.dict()
def test_node_shape(): shape = shapes.Ellipse() n = Node(properties={"shape": shape}) data = n.dict() assert data["properties"]["shape"].get("type") == shape.type
def _update_for_new_interpretation(self, *_): part_diagram = PartDiagram() repacked = repack_instance_dictionaries(self.interpretation, self.model) def is_draw_kind(entry, kind): if not entry.value: return False draw_kind = next(iter(entry.value)).owning_entry.draw_kind return draw_kind and kind in draw_kind elk_nodes = {} # part_definitions = [ # entry for entry in repacked if entry.base._metatype == "PartDefinition" # ] # TODO: Figure out if we need to do the part definitions # parts = part_diagram.add_child(Node( # labels=[ # Label(text="Parts"), # ], # layoutOptions=NODE_LAYOUT_OPTIONS, # )) # for entry in part_definitions: # for sequence in entry.value: # parent_node = parts # for instance in sequence.instances: # elk_node = elk_nodes.get(instance) # if elk_node is None: # elk_nodes[instance] = elk_node = parent_node.add_child( # Node( # labels=[ # # TODO: Find out how to represent type # Label(text=f"`{entry.base.label}`"), # Label(text=instance.name), # ], # layoutOptions=NODE_LAYOUT_OPTIONS, # ), # ) # parent_node = elk_node nodes = [ entry for entry in repacked if is_draw_kind(entry, "Rectangle") ] for interpreted_node in nodes: for sequence in interpreted_node.value: # parent_instance, *remaining_instances = sequence.instances # parent_node = elk_nodes[parent_instance] # for instance in remaining_instances: parent_node = part_diagram for instance in sequence.instances: elk_node = elk_nodes.get(instance) if elk_node is None: elk_nodes[instance] = elk_node = parent_node.add_child( Node( labels=[ # TODO: Find out how to represent type # Label(text=f"`{interpreted_node.base.label}`"), Label(text=instance.name), ], layoutOptions=NODE_LAYOUT_OPTIONS, ), ) parent_node = elk_node ports = [ entry.value for entry in repacked if is_draw_kind(entry, "Port") ] elk_ports = {} for port_set in ports: for sequence in port_set: *_, node, port = sequence.instances elk_ports[port] = elk_nodes[node].add_port(port=Port( layoutOptions={ "org.eclipse.elk.port.borderOffset": f"-{self.port_size}", }, labels=[Label(text=port.name.split("#")[-1])], width=self.port_size, height=self.port_size, ), ) lines = [ entry.value for entry in repacked if is_draw_kind(entry, "Line") ] for line in lines: for connection in line: src, tgt = connection.get_line_ends() part_diagram.add_edge( source=elk_ports[src.instances[-1]], target=elk_ports[tgt.instances[-1]], ) diagram = self.diagram diagram.source = self.loader.load(part_diagram) diagram.style = part_diagram.style diagram.view.symbols = part_diagram.symbols