Graph Drawer

Module for graph drawing on a canvas in jupyter notebook.

Classes:

GraphDrawer([graph, layout_type, place])

Class for graph drawing.

class pyrigi.graph_drawer.GraphDrawer(graph=None, 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 will be labeled using non-negative integers. Supported inputs are listed below.

  • 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 is 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) – (optional) A graph without loops which is to be drawn on canvas when the object is created. The non-integer labels are relabeled

  • 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 will not have any effect.

  • place (str) – The part of the canvas that will be 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 will not have any effect.

Examples

>>> from pyrigi import GraphDrawer
>>> Drawer = GraphDrawer()
HBox(children=(MultiCanvas(height=600, width=600), VBox(children=(ColorPicker(value='blue', description='V-Color'), ColorPicker(value='black', description='E-Color'), IntSlider(value=10, description='V-Size:', max=20, min=8), IntSlider(value=2, description='E-Size:', max=10, min=1), Checkbox(value=True, description='Show V-Labels', indent=False)))))
Output()
press and hold ctrl key to move vertices around with mouse.
>>> Drawer.graph()
Graph with vertices [] and edges []

Todo

  • Add width/height parameters to canvas. Currently width=600 and height=600 are fixed.

  • Add a background grid option.

framework()[source]

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

Return type:

Framework

graph()[source]

Return a copy of the current graph on the multicanvas.

Return type:

Graph