Module draw_graph
source code
Graphically display a graph. This module defines two new canvas
widgets: GraphEdgeWidget, and GraphWidget. Together, these two widgets can be used to
display directed graphs.
GraphEdgeWidget
is an arrow, optionally annotated with a
'label', which can be any canvas widget. In addition to a source
location and a destination location, it has a 'curve' attribute, which
can be used to define how curved it is (positive values curve one way,
and negative values the other). This is useful, e.g., if you want to
have two separate graph edges with the same source and the same
destination. It is also useful for drawing arrows that have the same
source and destination (i.e., loops).
The GraphWidget
widget is used to display a single
directed graph. It is a container widget, containing zero or more node
widgets, which are connected by zero or more edge widgets.
Any canvas widget can be used as a node widget. E.g., a StackWidget
containing an OvalWidget and a LabelWidget could be used to draw a circle
with a label below it. Edge widgets must be
GraphEdgeWidgets
. The GraphWidget
is
responsible for adjusting the start and end positions of edge widgets
whenever node widgets move. Thus, you can make a node widget draggable,
and when the user drags it, the edges will update automatically. The
GraphWidget
also defines a method arrange
,
which will automatically choose a layout for the nodes, attempting to
minimize crossing edges.