Пример #1
0
 def update_components(self, dic, animate=True):
     anims = []
     neighbors_to_update = set()
     for key in dic.keys():
         if key in self.nodes:
             Node.assert_primitive(key)
             anims.extend(self.nodes[key].update_attrs(
                 dic.get(key, None),
                 animate=animate,
             ))
             # update adjacent edges in case radius changes
             for pair in self.get_incident_edges(key, use_direction=False):
                 if pair not in dic and pair not in neighbors_to_update:
                     neighbors_to_update.add(pair)
         elif key in self.edges:
             Edge.assert_primitive(key)
             anims.extend(self.edges[key].update_attrs(
                 dic.get(key, None),
                 animate=animate,
             ))
         else:
             print("Unexpected key {}".format(key), file=sys.stderr)
             breakpoint(context=7)
     for pair in neighbors_to_update:
         anims.extend(self.edges[pair].update_attrs(animate=animate))
     return anims
Пример #2
0
    def __init__(self, nodes, edges, attrs=None, **kwargs):
        # typechecking
        for node in nodes:
            Node.assert_primitive(node)
        for edge in edges:
            Edge.assert_primitive(edge)

        if attrs is None:
            attrs = OrderedDict()

        # mobject init
        update_without_overwrite(kwargs, self.CONFIG)
        Group.__init__(self, **kwargs)

        # create submobjects
        self.nodes = {}
        self.edges = {}

        # create nodes
        for point in nodes:
            node_attrs = attrs.get(point, OrderedDict())
            node = Node(point, **update_without_overwrite(node_attrs, kwargs))
            self.nodes[node.key] = node
            self.add(node)

        # create edges
        for pair in edges:
            edge_attrs = attrs.get(pair, OrderedDict())
            u, v = pair[0], pair[1]
            edge_attrs["curved"] = (v, u) in edges
            u = self.nodes[u]
            v = self.nodes[v]
            edge = Edge(u, v, **update_without_overwrite(edge_attrs, kwargs))
            self.edges[edge.key] = edge
            self.add(edge)
Пример #3
0
 def set_labels(self, dic):
     anims = []
     for key in dic.keys():
         if key in self.nodes:
             Node.assert_primitive(key)
             anims.append(self.nodes[key].set_labels(dic[key]))
         elif key in self.edges:
             Edge.assert_primitive(key)
             anims.append(self.edges[key].set_labels(dic[key]))
         else:
             print("Unexpected key {}".format(key), file=sys.stderr)
             breakpoint(context=7)
     return anims
Пример #4
0
 def set_node_parent_edge(self, point, pair):
     Node.assert_primitive(point)
     Edge.assert_primitive(pair)
     self.nodes[point].parent_edge = pair
Пример #5
0
 def get_opposite_node(self, pair, point):
     Node.assert_primitive(point)
     Edge.assert_primitive(pair)
     return self.edges[pair].opposite(point)
Пример #6
0
 def get_edge(self, pair):
     Edge.assert_primitive(pair)
     return self.edges[pair]
Пример #7
0
 def get_edge_weight(self, pair):
     Edge.assert_primitive(pair)
     weight = self.edges[pair].get_label("weight")
     if weight:
         return weight.number
Пример #8
0
 def edge_has_label(self, pair, label):
     Edge.assert_primitive(pair)
     return label in self.edges[pair].labels
Пример #9
0
 def get_edge_label(self, pair, name):
     Edge.assert_primitive(pair)
     return self.edges[pair].get_label(name)