(self, graph, *args, **kwds)
Draws the given graph on an UbiGraph display.

        @keyword clear: whether to clear the current UbiGraph display before
                        plotting. Default: C{True}.
Draws the given graph on an UbiGraph display.
Draws the given graph on an UbiGraph display .
def draw(self, graph, *args, **kwds):
        """Draws the given graph on an UbiGraph display.

        @keyword clear: whether to clear the current UbiGraph display before
                        plotting. Default: C{True}."""
        display = self.service

        # Clear the display and set the default visual attributes
        if kwds.get("clear", True):
            display.clear()

            for k, v in self.vertex_defaults.items():
                display.set_vertex_style_attribute(0, k, str(v))
            for k, v in self.edge_defaults.items():
                display.set_edge_style_attribute(0, k, str(v))

        # Custom color converter function
        def color_conv(color):
            return color_to_html_format(color_name_to_rgb(color))

        # Construct the visual vertex/edge builders
        class VisualVertexBuilder(AttributeCollectorBase):
            """Collects some visual properties of a vertex for drawing"""

            _kwds_prefix = "vertex_"
            color = (str(self.vertex_defaults["color"]), color_conv)
            label = None
            shape = str(self.vertex_defaults["shape"])
            size = float(self.vertex_defaults["size"])

        class VisualEdgeBuilder(AttributeCollectorBase):
            """Collects some visual properties of an edge for drawing"""

            _kwds_prefix = "edge_"
            color = (str(self.edge_defaults["color"]), color_conv)
            label = None
            width = float(self.edge_defaults["width"])

        vertex_builder = VisualVertexBuilder(graph.vs, kwds)
        edge_builder = VisualEdgeBuilder(graph.es, kwds)

        # Add the vertices
        n = graph.vcount()
        new_vertex = display.new_vertex
        vertex_ids = [new_vertex() for _ in range(n)]

        # Add the edges
        new_edge = display.new_edge
        eids = [
            new_edge(vertex_ids[edge.source], vertex_ids[edge.target])
            for edge in graph.es
        ]

        # Add arrowheads if needed
        if graph.is_directed():
            display.set_edge_style_attribute(0, "arrow", "true")

        # Set the vertex attributes
        set_attr = display.set_vertex_attribute
        vertex_defaults = self.vertex_defaults
        for vertex_id, vertex in zip(vertex_ids, vertex_builder):
            if vertex.color != vertex_defaults["color"]:
                set_attr(vertex_id, "color", vertex.color)
            if vertex.label:
                set_attr(vertex_id, "label", str(vertex.label))
            if vertex.shape != vertex_defaults["shape"]:
                set_attr(vertex_id, "shape", vertex.shape)
            if vertex.size != vertex_defaults["size"]:
                set_attr(vertex_id, "size", str(vertex.size))

        # Set the edge attributes
        set_attr = display.set_edge_attribute
        edge_defaults = self.edge_defaults
        for edge_id, edge in zip(eids, edge_builder):
            if edge.color != edge_defaults["color"]:
                set_attr(edge_id, "color", edge.color)
            if edge.label:
                set_attr(edge_id, "label", edge.label)
            if edge.width != edge_defaults["width"]:
                set_attr(edge_id, "width", str(edge.width))
def draw ( self , graph , * args , * * kwds ) : display = self . service # Clear the display and set the default visual attributes if kwds . get ( "clear" , True ) : display . clear ( ) for k , v in self . vertex_defaults . items ( ) : display . set_vertex_style_attribute ( 0 , k , str ( v ) ) for k , v in self . edge_defaults . items ( ) : display . set_edge_style_attribute ( 0 , k , str ( v ) ) # Custom color converter function def color_conv ( color ) : return color_to_html_format ( color_name_to_rgb ( color ) ) # Construct the visual vertex/edge builders class VisualVertexBuilder ( AttributeCollectorBase ) : """Collects some visual properties of a vertex for drawing""" _kwds_prefix = "vertex_" color = ( str ( self . vertex_defaults [ "color" ] ) , color_conv ) label = None shape = str ( self . vertex_defaults [ "shape" ] ) size = float ( self . vertex_defaults [ "size" ] ) class VisualEdgeBuilder ( AttributeCollectorBase ) : """Collects some visual properties of an edge for drawing""" _kwds_prefix = "edge_" color = ( str ( self . edge_defaults [ "color" ] ) , color_conv ) label = None width = float ( self . edge_defaults [ "width" ] ) vertex_builder = VisualVertexBuilder ( graph . vs , kwds ) edge_builder = VisualEdgeBuilder ( graph . es , kwds ) # Add the vertices n = graph . vcount ( ) new_vertex = display . new_vertex vertex_ids = [ new_vertex ( ) for _ in range ( n ) ] # Add the edges new_edge = display . new_edge eids = [ new_edge ( vertex_ids [ edge . source ] , vertex_ids [ edge . target ] ) for edge in graph . es ] # Add arrowheads if needed if graph . is_directed ( ) : display . set_edge_style_attribute ( 0 , "arrow" , "true" ) # Set the vertex attributes set_attr = display . set_vertex_attribute vertex_defaults = self . vertex_defaults for vertex_id , vertex in zip ( vertex_ids , vertex_builder ) : if vertex . color != vertex_defaults [ "color" ] : set_attr ( vertex_id , "color" , vertex . color ) if vertex . label : set_attr ( vertex_id , "label" , str ( vertex . label ) ) if vertex . shape != vertex_defaults [ "shape" ] : set_attr ( vertex_id , "shape" , vertex . shape ) if vertex . size != vertex_defaults [ "size" ] : set_attr ( vertex_id , "size" , str ( vertex . size ) ) # Set the edge attributes set_attr = display . set_edge_attribute edge_defaults = self . edge_defaults for edge_id , edge in zip ( eids , edge_builder ) : if edge . color != edge_defaults [ "color" ] : set_attr ( edge_id , "color" , edge . color ) if edge . label : set_attr ( edge_id , "label" , edge . label ) if edge . width != edge_defaults [ "width" ] : set_attr ( edge_id , "width" , str ( edge . width ) )