Graph Drawer

Module for graph drawing on a canvas in jupyter notebook.

class pyrigi.graph_drawer.GraphDrawer(graph=None, size=(600, 600), layout_type='spring', place='all')[source]

Bases: object

Class for graph drawing.

An instance of this class creates a canvas and takes mouse inputs in order to construct a graph. The vertices of the graph are labeled using non-negative integers.

Supported inputs are:

  • Press mouse button on an empty place on canvas:

    Add a vertex at the pointer position.

  • Press mouse button on an existing vertex (or empty space) and

    release the mouse button on another vertex (or empty space): Add/remove an edge between the two vertices.

  • Drag a vertex with Ctrl being pressed:

    Reposition the vertex.

  • Double-click on an existing vertex:

    Remove the corresponding vertex.

  • Double-click on an existing edge:

    Remove the corresponding edge.

Parameters:
  • graph (Graph) – A graph without loops which is to be drawn on canvas when the object is created. The non-integer labels are relabeled

  • size (Sequence[int]) – Width and height of the canvas, defaults to [600,600]. The width and height are adjusted so that they are multiples of 100 with minimum value 400 and maximum value 1000.

  • layout_type (str) – Layout type to visualise the graph. For supported layout types see Graph.layout(). The default is spring. If graph is None or empty, this parameter has no effect.

  • place (str) – The part of the canvas that is used for drawing graph. Options are all (default, use all canvas), E (use the east part), W (use the west part), N (use the north part), S (use the south part), and also NE, NW, SE and SW. If graph is None or empty, this parameter has no effect.

Examples

>>> from pyrigi import GraphDrawer
>>> Drawer = GraphDrawer()
HBox(children=(MultiCanvas(height=600, width=600)...
>>> print(Drawer.graph())
Graph with vertices [] and edges []
framework(grid=False)[source]

Return a copy of the current 2D framework on the multicanvas.

Parameters:

grid (bool) – If True and Grid Snapping is checked, the realization is scaled so that the grid points correspond to integral points.

Return type:

Framework

graph()[source]

Return a copy of the current graph on the multicanvas.

Return type:

Graph