Graph Drawer¶
Module for graph drawing on a canvas in jupyter notebook.
Classes:
|
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.
- Drag a vertex with
- 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 seeGraph.layout()
. The default isspring
. Ifgraph
isNone
or empty this parameter will not have any effect.place (str) – The part of the canvas that will be used for drawing
graph
. Options areall
(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 alsoNE
,NW
,SE
andSW
. Ifgraph
isNone
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.