GraphWidget

Contents

GraphWidget#

class graph_tool.draw.GraphWidget(g, pos, vprops=None, eprops=None, vorder=None, eorder=None, nodesfirst=False, update_layout=False, layout_K=1.0, layout_init_step=0.1, multilevel=False, coarse_method='hybrid', sfdp_args={}, display_props=None, display_props_size=11, fit_view=True, fit_view_ink=None, bg_color=None, max_render_time=300, layout_callback=None, key_press_callback=None, highlight_color=None, **kwargs)[source]#

Interactive GTK+ widget displaying a given graph.

Parameters:
gGraph

Graph to be drawn.

posVertexPropertyMap

Vector-valued vertex property map containing the x and y coordinates of the vertices.

vpropsdict (optional, default: None)

Dictionary with the vertex properties. Individual properties may also be given via the vertex_<prop-name> parameters, where <prop-name> is the name of the property.

epropsdict (optional, default: None)

Dictionary with the edge properties. Individual properties may also be given via the edge_<prop-name> parameters, where <prop-name> is the name of the property.

vorderVertexPropertyMap (optional, default: None)

If provided, defines the relative order in which the vertices are drawn.

eorderEdgePropertyMap (optional, default: None)

If provided, defines the relative order in which the edges are drawn.

nodesfirstbool (optional, default: False)

If True, the vertices are drawn first, otherwise the edges are.

update_layoutbool (optional, default: False)

If True, the layout will be updated dynamically.

layout_Kfloat (optional, default: 1.0)

Parameter K passed to sfdp_layout().

layout_init_stepfloat (optional, default: 0.1)

Initial speed of the layout algorithm.

multilevelbool (optional, default: False)

Parameter multilevel passed to sfdp_layout().

coarse_methodbool (optional, default: hybrid)

Parameter coarse_method passed to sfdp_layout().

sfdp_argsdict (optional, default: {})

Additional parameters to be passed to sfdp_layout().

display_propslist of VertexPropertyMap instances (optional, default: None)

List of properties to be displayed when the mouse passes over a vertex.

display_props_sizefloat (optional, default: 11.)

Font size used to display the vertex properties.

fit_viewbool, float or tuple (optional, default: True)

If True, the layout will be scaled to fit the entire clip region. If a float value is given, it will be interpreted as True, and in addition the viewport will be scaled out by that factor. If a tuple value is given, it should have four values (x, y, w, h) that specify the view in user coordinates.

fit_view_inkbool (optional, default: None)

If True, and fit_view == True the drawing will be performed once to figure out the bounding box, before the actual drawing is made. Otherwise, only the vertex positions will be used for this purpose. If the value is None, then it will be assumed True for networks of size 10,000 nodes or less, otherwise it will be assumed False.

bg_colorstr or sequence (optional, default: None)

Background color. The default is white.

max_render_timeint (optional, default: 300)

Maximum amount of time (in milliseconds) spent rendering portions of the graph.

layout_callbackfunction (optional, default: Node)

User-supplied callback to be called whenever the positions of the layout have changed. It needs to have the following signature:

def callback(g, picked, pos, vprops, eprops):
    ...

where g is the graph being drawn, picked is either a single vertex or a boolean vertex property map representing the vertices currently selected, pos the vertex positions, and vprops and eprops are dictionaries with the vertex and edge properties currently being used by the layout.

key_press_callbackfunction (optional, default: Node)

User-supplied callback to be called whenever a key-press event has happened. It needs to have the following signature:

def callback(g, keyval, picked, pos, vprops, eprops):
    ...

where g is the graph being drawn, keyval is the key id, picked is either a single vertex or a boolean vertex property map representing the vertices currently selected, pos the vertex positions, and vprops and eprops are dictionaries with the vertex and edge properties currently being used by the layout.

highligth_colorstr or sequence (optional, default: None)

Color used to highlight the currently selected node and its incident edges. The default is red.

vertex_*VertexPropertyMap or arbitrary types (optional, default: None)

Parameters following the pattern vertex_<prop-name> specify the vertex property with name <prop-name>, as an alternative to the vprops parameter.

edge_*EdgePropertyMap or arbitrary types (optional, default: None)

Parameters following the pattern edge_<prop-name> specify the edge property with name <prop-name>, as an alternative to the eprops parameter.

**kwargs

Any extra parameters are passed to cairo_draw().

Notes

The graph drawing can be panned by dragging with the middle mouse button pressed. The graph may be zoomed by scrolling with the mouse wheel, or equivalent (if the “shift” key is held, the vertex/edge sizes are scaled accordingly). The layout may be rotated by dragging while holding the “control” key. Pressing the “r” key centers and zooms the layout around the graph. By pressing the “a” key, the current translation, scaling and rotation transformations are applied to the vertex positions themselves, and the transformation matrix is reset (if this is never done, the given position properties are never modified).

Individual vertices may be selected by pressing the left mouse button. The currently selected vertex follows the mouse pointer. To stop the selection, the right mouse button must be pressed. Alternatively, a group of vertices may be selected by holding the “shift” button while the pointer is dragged while pressing the left button. The selected vertices may be moved by dragging the pointer with the left button pressed. They may be rotated by holding the “control” key and scrolling with the mouse. If the key “z” is pressed, the layout is zoomed to fit the selected vertices only.

If the key “s” is pressed, the dynamic spring-block layout is activated. Vertices which are currently selected are not updated.