Textual Widget
GraphView
GraphView(
graph: DiGraph,
name: str | None = None,
id: str | None = None,
classes: str | None = None,
disabled: bool = False,
zoom: float
| tuple[float, float]
| ZoomSpec
| AutoZoom = 1.0,
scroll_via_viewport: bool = False,
**console_graph_kwargs,
)
Bases: ScrollView
Initializes a new instance of the Widget class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
DiGraph
|
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
|
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. |
graph
property
writable
Returns and sets the graph object associated with this widget.
Returns:
Name | Type | Description |
---|---|---|
DiGraph |
DiGraph
|
The graph object associated with this widget. |
add_node
add_node(
node: Hashable,
position: FloatPoint | None = None,
data: dict[str, Any] | None = None,
) -> 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: Hashable,
position: Offset | None = None,
data: dict[str, Any] | None = None,
update_data: bool = True,
) -> None
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 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
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: Hashable,
v: Hashable,
data: dict[str, Any],
update_data: bool = True,
update_layout: bool = True,
) -> None
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
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
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 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
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
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
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. |