Debian Codegraph @

src/igraph/drawing/cairo/palette.py

raw
1 """This module provides implementation for a Cairo-specific palette drawer"""
2
3 from igraph.drawing.cairo.base import AbstractCairoDrawer
4
5 __all__ = ("CairoPaletteDrawer",)
6
7
8 class CairoPaletteDrawer(AbstractCairoDrawer):
9 """Default Cairo drawer object for palettes"""
10
11 def __init__(self, context):
12 """Constructs the vertex drawer and associates it to the given
13 palette.
14
15 @param context: the context on which we will draw
16 """
17 super().__init__(context, bbox=None)
18
19 def draw(self, palette, **kwds):
20 """TODO"""
21 from igraph.datatypes import Matrix
22 from igraph.drawing.utils import str_to_orientation
23
24 context = self.context
25 orientation = str_to_orientation(kwds.get("orientation", "lr"))
26
27 # Construct a matrix and plot that
28 indices = list(range(len(self)))
29 if orientation in ("rl", "bt"):
30 indices.reverse()
31 if orientation in ("lr", "rl"):
32 matrix = Matrix([indices])
33 else:
34 matrix = Matrix([[i] for i in indices])
35
36 bbox = self.bbox = kwds.pop("bbox", None)
37 if bbox is None:
38 raise ValueError("bbox is required for Cairo plots")
39
40 border_width = float(kwds.get("border_width", 1.0))
41 grid_width = float(kwds.get("grid_width", 0.0))
42
43 return matrix.__plot__(
44 "cairo",
45 context,
46 bbox=bbox,
47 palette=self,
48 style="palette",
49 square=False,
50 grid_width=grid_width,
51 border_width=border_width,
52 )