GraphWidget#
- class graph_tool.draw.GraphWidget(g, pos, vprops=None, eprops=None, vorder=None, eorder=None, nodesfirst=False, update_layout=False, multilevel=False, layout_args={}, layout_K=None, layout_init_step=None, coarse_method=None, sfdp_args=None, 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)[git][source]#
Bases:
DrawingAreaInteractive GTK+ widget displaying a given graph.
- Parameters:
- g
Graph Graph to be drawn.
- pos
VertexPropertyMap Vector-valued vertex property map containing the x and y coordinates of the vertices.
- vprops
dict(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.- eprops
dict(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.- vorder
VertexPropertyMap(optional, default:None) If provided, defines the relative order in which the vertices are drawn.
- eorder
EdgePropertyMap(optional, default:None) If provided, defines the relative order in which the edges are drawn.
- nodesfirst
bool(optional, default:False) If
True, the vertices are drawn first, otherwise the edges are.- update_layout
bool(optional, default:False) If
True, the layout will be updated dynamically, withhfd_layout().- multilevel
bool(optional, default:False) If
True, the layout is obtained hierarchically (parameterhierarchicalofhfd_layout()), and the coarse graph of every level of the hierarchy is shown while it is laid out. Otherwise, the given positions are refined directly.- layout_args
dict(optional, default:{}) Additional parameters to be passed to
hfd_layout()(e.g.borrank).- layout_K
None(optional, default:None) Deprecated and ignored (the scale is set by
hfd_layout()).- layout_init_step
None(optional, default:None) Deprecated and ignored.
- coarse_method
None(optional, default:None) Deprecated and ignored.
- sfdp_args
None(optional, default:None) Deprecated and ignored (use
layout_args).- display_props
listofVertexPropertyMapinstances (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_view
bool, 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 asTrue, 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_ink
bool(optional, default:None) If
True, andfit_view == Truethe 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 isNone, then it will be assumedTruefor networks of size 1,000 nodes or less, otherwise it will be assumedFalse.- bg_colorstr or sequence (optional, default:
None) Background color. The default is white.
- max_render_time
int(optional, default:300) Maximum amount of time (in milliseconds) spent rendering portions of the graph.
- layout_callbackfunction (optional, default:
None) User-supplied callback to be called whenever the positions of the layout have changed. It needs to have the following signature:
def callback(widget, g, picked, pos, vprops, eprops): ...
where
widgetis theGraphWidgetinstance,gis the graph being drawn,pickedis either a single vertex or a boolean vertex property map representing the vertices currently selected,posthe vertex positions, andvpropsandepropsare dictionaries with the vertex and edge properties currently being used by the layout.- key_press_callbackfunction (optional, default:
None) User-supplied callback to be called whenever a key-press event has happened. It needs to have the following signature:
def callback(widget, g, keyval, picked, pos, vprops, eprops): ...
where
widgetis theGraphWidgetinstance,gis the graph being drawn,keyvalis the key id,pickedis either a single vertex or a boolean vertex property map representing the vertices currently selected,posthe vertex positions, andvpropsandepropsare dictionaries with the vertex and edge properties currently being used by the layout.- highlight_colorstr or sequence (optional, default:
None) Color used to highlight the currently selected node and its incident edges. The default is red.
- vertex_*
VertexPropertyMapor arbitrary types (optional, default:None) Parameters following the pattern
vertex_<prop-name>specify the vertex property with name<prop-name>, as an alternative to thevpropsparameter.- edge_*
EdgePropertyMapor arbitrary types (optional, default:None) Parameters following the pattern
edge_<prop-name>specify the edge property with name<prop-name>, as an alternative to theepropsparameter.- **kwargs
Any extra parameters are passed to
cairo_draw().
- g
Notes
The graph drawing can be panned by dragging with the middle mouse button pressed, or with the left button while holding the “control” key. The graph may be zoomed by scrolling with the mouse wheel, or equivalent, or with a pinch gesture (if the “shift” key is held while scrolling, the vertex/edge sizes are scaled accordingly). The layout may be rotated by scrolling while holding the “control” key (in finer steps if “shift” is also held), or with a two-finger rotation gesture; with a touchscreen, it may also be panned by dragging with one finger. 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, starting from the current positions with a small random jitter. Vertices which are currently selected are not updated. The amplitude of the jitter is doubled at every press, so that pressing the key repeatedly perturbs the layout increasingly. As the layout settles, the amplitude returns to its initial value: its excess over the initial value is proportional to the displacement of the vertices in the last step of the layout algorithm, relative to the largest one since the key was pressed.
Methods
adjust_default_sizes(geometry[, force])Set the default sizes, according to the window geometry, or to the layout, if the sizes are given in layout units.
angle_changed(gesture, angle, angle_delta)Apply current transform matrix to vertex coordinates.
button_press_event(widget, event)Handle button press.
button_release_event(widget, event)Handle button release.
cleanup(*args)Cleanup callbacks.
drag_gesture_begin(gesture, seq)drag_gesture_end(gesture, seq)drag_gesture_update(gesture, dx, dy)draw(da, cr)Redraw the widget.
fit_to_window([ink, g])Fit graph to window.
Init picked vertices.
key_press_event(widget, event)Handle key press.
key_release_event(widget, event)Handle release event.
Perform one step of the layout algorithm.
Render with a short time limit while the view is being changed, restoring the full limit after two seconds.
motion_notify_event(widget, event)Handle pointer motion.
pos_from_device(pos[, dist, surface, cr])Convert a position from the widget space to the graph space.
pos_to_device(pos[, dist, surface, cr])Convert a position from the graph space to the widget space.
regenerate_surface([reset, complete])Redraw the graph surface.
reset_layout([hierarchical])Reset the layout algorithm, which refines the current positions, or lays out the graph from scratch if
hierarchical == True.rotate_begin(gesture, seq)rotate_end(gesture, seq)scale_changed(gesture, scale)scroll_event(widget, event)Handle scrolling.
update([pos, vprops, eprops, vorder, ...])update_jitter(X_prev, X)Update the jitter amplitude according to the displacement of the vertices in a sweep, given their positions before and after it (as 2 x N arrays).
zoom_at(center, zoom)Zoom the layout by the factor
zoom, keeping the device pointcenterfixed.zoom_begin(gesture, seq)zoom_end(gesture, seq)Attributes
- adjust_default_sizes(geometry, force=False)[git][source]#
Set the default sizes, according to the window geometry, or to the layout, if the sizes are given in layout units.
- cleanup(*args)[git][source]#
Cleanup callbacks. This is called when the widget is destroyed, so that the layout does not keep running after the window is closed.
- limit_render_time()[git][source]#
Render with a short time limit while the view is being changed, restoring the full limit after two seconds.
- pos_from_device(pos, dist=False, surface=False, cr=None)[git][source]#
Convert a position from the widget space to the graph space.
- pos_to_device(pos, dist=False, surface=False, cr=None)[git][source]#
Convert a position from the graph space to the widget space.
- reset_layout(hierarchical=False)[git][source]#
Reset the layout algorithm, which refines the current positions, or lays out the graph from scratch if
hierarchical == True.
- update(pos=None, vprops=None, eprops=None, vorder=None, eorder=None, nodesfirst=None, display_props=None, fit_view=True, bg_color=None, **kwargs)[git][source]#
- update_jitter(X_prev, X)[git][source]#
Update the jitter amplitude according to the displacement of the vertices in a sweep, given their positions before and after it (as 2 x N arrays).
- zoom_at(center, zoom)[git][source]#
Zoom the layout by the factor
zoom, keeping the device pointcenterfixed.
- dummy#
- g_type_instance#
- parent_instance#
- priv#
- props = <gi._gi.GProps object>#
- qdata#
- ref_count#
- widget#