Source code for pypath.visual.igraph_drawing.vertex
#!/usr/bin/env python# -*- coding: utf-8 -*-## This file is part of the `pypath` python module## Copyright 2014-2023# EMBL, EMBL-EBI, Uniklinik RWTH Aachen, Heidelberg University## Authors: see the file `README.rst`# Contact: Dénes Türei (turei.denes@gmail.com)## Distributed under the GPLv3 License.# See accompanying file LICENSE.txt or copy at# https://www.gnu.org/licenses/gpl-3.0.html## Website: https://pypath.omnipathdb.org/#"""Drawing routines to draw the vertices of graphs.This module provides implementations of vertex drawers, i.e. drawers that thedefault graph drawer will use to draw vertices."""importsystry:fromigraph.drawing.baseclassesimportAbstractDrawer,AbstractCairoDrawerfromigraph.drawing.metamagicimportAttributeCollectorBasefromigraph.drawing.shapesimportShapeDrawerDirectoryexceptModuleNotFoundError:sys.stdout.write('Module `igraph` is not available.''\nSome plotting functionalities won\'t be accessible.\n')
[docs]classAbstractVertexDrawer(AbstractDrawer):"""Abstract vertex drawer object from which all concrete vertex drawer implementations are derived."""
[docs]def__init__(self,palette,layout):"""Constructs the vertex drawer and associates it to the given palette. @param palette: the palette that can be used to map integer color indices to colors when drawing vertices @param layout: the layout of the vertices in the graph being drawn """self.layout=layoutself.palette=palette
[docs]defdraw(self,visual_vertex,vertex,coords):"""Draws the given vertex. @param visual_vertex: object specifying the visual properties of the vertex. Its structure is defined by the VisualVertexBuilder of the L{DefaultGraphDrawer}; see its source code. @param vertex: the raw igraph vertex being drawn @param coords: the X and Y coordinates of the vertex as specified by the layout algorithm, scaled into the bounding box. """raiseNotImplementedError("abstract class")
[docs]classAbstractCairoVertexDrawer(AbstractVertexDrawer,AbstractCairoDrawer):"""Abstract base class for vertex drawers that draw on a Cairo canvas."""
[docs]def__init__(self,context,bbox,palette,layout):"""Constructs the vertex drawer and associates it to the given Cairo context and the given L{BoundingBox}. @param context: the context on which we will draw @param bbox: the bounding box within which we will draw. Can be anything accepted by the constructor of L{BoundingBox} (i.e., a 2-tuple, a 4-tuple or a L{BoundingBox} object). @param palette: the palette that can be used to map integer color indices to colors when drawing vertices @param layout: the layout of the vertices in the graph being drawn """AbstractCairoDrawer.__init__(self,context,bbox)AbstractVertexDrawer.__init__(self,palette,layout)
[docs]classDefaultVertexDrawer(AbstractCairoVertexDrawer):"""The default vertex drawer implementation of igraph."""
def_construct_visual_vertex_builder(self):classVisualVertexBuilder(AttributeCollectorBase):"""Collects some visual properties of a vertex for drawing"""_kwds_prefix="vertex_"color=("red",self.palette.get)frame_color=("black",self.palette.get)frame_width=1.0label=Nonelabel_angle=-pi/2label_dist=0.0label_color=("black",self.palette.get)label_size=14.0label_family='sans-serif'position=dict(func=self.layout.__getitem__)shape=("circle",ShapeDrawerDirectory.resolve_default)size=20.0width=Noneheight=NonereturnVisualVertexBuilder