Skip to content

Textual Widget

GraphView

Bases: ScrollView, Generic[G]

graph property writable

graph

Returns and sets the graph object associated with this widget.

Returns:

Name Type Description
G G

The graph object associated with this widget.

__init__

__init__(graph, name=None, id=None, classes=None, disabled=False, zoom=1.0, viewport=None, scroll_via_viewport=False, **console_graph_kwargs)

Initializes a new instance of the Widget class.

Parameters:

Name Type Description Default
graph G

A graph object to be displayed in the widget.

required
name str | None

A string representing the name of the widget (optional).

None
id str | None

A string representing the ID of the widget (optional).

None
classes str | None

A string representing the CSS classes of the widget (optional).

None
disabled bool

A boolean indicating whether the widget is disabled (optional).

False
zoom float | tuple[float, float] | ZoomSpec | AutoZoom

A float or tuple of floats representing the zoom level of the widget (optional).

1.0
viewport Region | None

A Region object representing the viewport of the widget (optional).

None
scroll_via_viewport bool

A boolean indicating whether the widget should scroll via the viewport (optional).

False
**console_graph_kwargs

Additional keyword arguments to be passed to the ConsoleGraph constructor.

{}

Raises:

Type Description
ValueError

If both viewport and scroll_via_viewport are specified.

add_node

add_node(node, position=None, data=None)

Adds a node to the graph widget.

Parameters:

Name Type Description Default
node Hashable

The node to add to the graph.

required
position FloatPoint | None

The position of the node in the graph (optional). If set add the node at the specific position in graph space coordinates. If not set the node will be added and the layout will be recomputed.

None
data dict[str, Any] | None

Optional dictionary of node attributes, see ConsoleGraph.add_node (optional).

None

Returns:

Type Description
None

None

update_node

update_node(node, position=None, data=None, update_data=True)

Updates a node in the graph and reflects the changes in the console graph.

See ConsoleGraph.update_node for comparison.

Parameters:

Name Type Description Default
node Hashable

The node to update.

required
position Offset | None

The new position of the node. Defaults to None.

None
data dict[str, Any] | None

The new data to associate with the node. Defaults to None.

None
update_data bool

Whether to merge the data associated with the node. Defaults to True.

True

remove_node

remove_node(node)

Remove a node from the graph and updates the console graph and the internal graph.

Parameters:

Name Type Description Default
node Hashable

The node to remove from the graph.

required

Returns:

Type Description
None

None

add_edge

add_edge(u, v, data=None)

Adds an edge to the graph widget.

Parameters:

Name Type Description Default
u Hashable

The source node of the edge.

required
v Hashable

The destination node of the edge.

required
data dict[str, Any] | None

Optional dictionary of edge attributes, see ConsoleGraph.add_edge (optional).

None

Returns:

Type Description
None

None

update_edge

update_edge(u, v, data, update_data=True, update_layout=True)

Updates the edge between nodes u and v with the given data.

See ConsoleGraph.update_edge for comparison.

Parameters:

Name Type Description Default
u Hashable

The source node of the edge.

required
v Hashable

The destination node of the edge.

required
data dict[str, Any]

The data to update the edge with.

required
update_data bool

Whether to merge the data of the edge. Defaults to True.

True
update_layout bool

Whether to update the layout of the graph. Defaults to True.

True

Returns:

Type Description
None

None

remove_edge

remove_edge(u, v)

Removes an edge from the graph and updates the console graph and the internal graph.

Parameters:

Name Type Description Default
u Hashable

The source node of the edge.

required
v Hashable

The destination node of the edge.

required

Returns:

Type Description
None

None

attach_widget_to_node

attach_widget_to_node(widget, node, size=None)

Attaches a widget to a node in the console graph.

Parameters:

Name Type Description Default
widget Widget

The textual widget to attach.

required
node Hashable

The node to attach the widget to.

required
size Size | None

The size of the widget, by default uses the node size (optional).

None

detach_widget_from_node

detach_widget_from_node(node)

Detach a widget from a node.

Parameters:

Name Type Description Default
node Hashable

The node to detach the widget from.

required

Returns:

Type Description
None

None

to_graph_coordinates

to_graph_coordinates(p)

Converts a point or offset to graph coordinates.

Parameters:

Name Type Description Default
p Point | Offset

The point or offset to convert.

required

Returns:

Name Type Description
FloatPoint FloatPoint

The converted point in graph coordinates.

view_to_widget_coordinates

view_to_widget_coordinates(p)

Converts a point in the view's coordinate system to a point in the widget's coordinate system.

Parameters:

Name Type Description Default
p Point

The point to convert.

required

Returns:

Name Type Description
Offset Offset

The converted point in the widget's coordinate system.

graph_to_widget_coordinates

graph_to_widget_coordinates(p)

Converts a point in graph coordinates to widget coordinates.

Parameters:

Name Type Description Default
p FloatPoint

The point in graph coordinates.

required

Returns:

Name Type Description
Offset Offset

The point in widget coordinates.

widget_to_view_coordinates

widget_to_view_coordinates(offset)

Converts widget coordinates to view coordinates.

Parameters:

Name Type Description Default
offset Offset

The offset to convert.

required

Returns:

Name Type Description
Point Point

The converted point.