python-igraph manual

For using igraph from Python

   Home       Trees       Indices       Help   
Package igraph :: Package drawing :: Module vertex
[hide private]

Source Code for Module igraph.drawing.vertex

 1  """ 
 2  Drawing routines to draw the vertices of graphs. 
 3   
 4  This module provides implementations of vertex drawers, i.e. drawers that the 
 5  default graph drawer will use to draw vertices. 
 6  """ 
 7   
 8  from igraph.drawing.baseclasses import AbstractDrawer, AbstractCairoDrawer 
 9  from igraph.drawing.metamagic import AttributeCollectorBase 
10  from igraph.drawing.shapes import ShapeDrawerDirectory 
11  from math import pi 
12   
13  __all__ = ["AbstractVertexDrawer", "AbstractCairoVertexDrawer", \ 
14          "DefaultVertexDrawer"] 
15  __license__ = "GPL" 
16   
17 -class AbstractVertexDrawer(AbstractDrawer):
18 """Abstract vertex drawer object from which all concrete vertex drawer 19 implementations are derived.""" 20
21 - def __init__(self, palette, layout):
22 """Constructs the vertex drawer and associates it to the given 23 palette. 24 25 @param palette: the palette that can be used to map integer 26 color indices to colors when drawing vertices 27 @param layout: the layout of the vertices in the graph being drawn 28 """ 29 self.layout = layout 30 self.palette = palette 31
32 - def draw(self, visual_vertex, vertex, coords):
33 """Draws the given vertex. 34 35 @param visual_vertex: object specifying the visual properties of the 36 vertex. Its structure is defined by the VisualVertexBuilder of the 37 L{DefaultGraphDrawer}; see its source code. 38 @param vertex: the raw igraph vertex being drawn 39 @param coords: the X and Y coordinates of the vertex as specified by the 40 layout algorithm, scaled into the bounding box. 41 """ 42 raise NotImplementedError("abstract class")
43
44 -class AbstractCairoVertexDrawer(AbstractVertexDrawer, AbstractCairoDrawer):
45 """Abstract base class for vertex drawers that draw on a Cairo canvas.""" 46
47 - def __init__(self, context, bbox, palette, layout):
48 """Constructs the vertex drawer and associates it to the given 49 Cairo context and the given L{BoundingBox}. 50 51 @param context: the context on which we will draw 52 @param bbox: the bounding box within which we will draw. 53 Can be anything accepted by the constructor 54 of L{BoundingBox} (i.e., a 2-tuple, a 4-tuple 55 or a L{BoundingBox} object). 56 @param palette: the palette that can be used to map integer 57 color indices to colors when drawing vertices 58 @param layout: the layout of the vertices in the graph being drawn 59 """ 60 AbstractCairoDrawer.__init__(self, context, bbox) 61 AbstractVertexDrawer.__init__(self, palette, layout)
62
63 -class DefaultVertexDrawer(AbstractCairoVertexDrawer):
64 """The default vertex drawer implementation of igraph.""" 65
66 - def __init__(self, context, bbox, palette, layout):
67 AbstractCairoVertexDrawer.__init__(self, context, bbox, palette, layout) 68 self.VisualVertexBuilder = self._construct_visual_vertex_builder() 69
71 class VisualVertexBuilder(AttributeCollectorBase): 72 """Collects some visual properties of a vertex for drawing""" 73 _kwds_prefix = "vertex_" 74 color = ("red", self.palette.get) 75 frame_color = ("black", self.palette.get) 76 frame_width = 1.0 77 label = None 78 label_angle = -pi/2 79 label_dist = 0.0 80 label_color = ("black", self.palette.get) 81 label_size = 14.0 82 position = dict(func=self.layout.__getitem__) 83 shape = ("circle", ShapeDrawerDirectory.resolve_default) 84 size = 20.0 85 return VisualVertexBuilder 86
87 - def draw(self, visual_vertex, vertex, coords):
88 context = self.context 89 90 visual_vertex.shape.draw_path(context, \ 91 coords[0], coords[1], visual_vertex.size) 92 context.set_source_rgba(*visual_vertex.color) 93 context.fill_preserve() 94 context.set_source_rgba(*visual_vertex.frame_color) 95 context.set_line_width(visual_vertex.frame_width) 96 context.stroke()
97

   Home       Trees       Indices       Help