GraphView#
- class omni.kit.widget.graph.GraphView(**kwargs)#
Bases:
object
The visualisation layer of omni.kit.widget.graph. It behaves like a regular widget and displays nodes and their connections.
- DEFAULT_DISTANCE_BETWEEN_NODES#
Default space between graph nodes.
- Type:
float
- Parameters:
kwargs (dict) – Arbitrary keyword arguments for widget initialization.
settings (Any) – Settings related to graph visualization and interaction.
rect_corner_start (Any) – Starting corner for a selection rectangle.
rect_corner_end (Any) – Ending corner for a selection rectangle.
Methods
__init__
(**kwargs)Initialize a GraphView widget.
destroy
()Destroy the GraphView and clean up associated resources.
filter_upstream
(nodes)Filter the graph to show only nodes upstream of the specified nodes.
focus_on_nodes
([nodes])Center the view on the specified nodes.
get_bbox_of_nodes
(nodes)Get the bounding box that encompasses the specified nodes.
Reset positions of all the nodes in the model
set_delegate
(delegate)Set the delegate responsible for drawing nodes.
set_expansion
(state)Open, close or minimize all the nodes in the model.
set_model
(model)Set the graph model for the view.
Subscribe to the event triggered when a connection is dropped on an empty area.
Subscribe to the event triggered after a delayed layout build.
Subscribe to the event triggered before a delayed layout build.
Attributes
Gets the current graph model.
Gets the current horizontal pan position of the graph.
Gets the current vertical pan position of the graph.
Gets whether node rasterization is enabled.
Gets the currently selected nodes in the graph.
Gets whether virtual ports are enabled.
Gets the current zoom level of the graph.
Gets the maximum zoom level of the graph.
Gets the minimum zoom level of the graph.
- __init__(**kwargs)#
Initialize a GraphView widget.
- Keyword Arguments:
`model – GraphModel` Model to display the node graph
`delegate – AbstractGraphNodeDelegate` Delegate to draw the node
`virtual_ports – bool` True when the model should use reversed output for better look of the graph.
`port_grouping – bool` True when the widget should use sub-ports for port grouping.
`draw_curve_top_layer – bool` When True, connections are drawn in 2 passes. The “under” layer is for the opaque curve, and the “top” or “over” layer is meant for floating curve anchor decorations that need to be on top of all nodes, like a value display. Its curve should be drawn transparent. False by default, so both layers are not drawn.
`allow_same_side_connections – bool` When True, connections can happen between two input ports or two output ports. This is only used within one node. We don’t support same side connection between different nodes yet.
widget. (All other kwargs are passed to CanvasFrame which is the root)
- destroy()#
Destroy the GraphView and clean up associated resources.
Called by extension before destroying this object. It doesn’t happen automatically. Without this hot reloading doesn’t work.
- filter_upstream(nodes: list)#
Filter the graph to show only nodes upstream of the specified nodes.
- Parameters:
nodes (list) – A list of nodes to filter by.
- focus_on_nodes(
- nodes: List[Any] | None = None,
Center the view on the specified nodes.
- Parameters:
nodes (Optional[List[Any]]) – A list of nodes to focus on. Defaults to None, which will focus on all nodes.
- get_bbox_of_nodes(nodes: list)#
Get the bounding box that encompasses the specified nodes.
- Parameters:
nodes (list) – A list of nodes to calculate the bounding box for.
- Returns:
A tuple containing the width, height, and position (x, y) of the bounding box.
- layout_all()#
Reset positions of all the nodes in the model
- set_delegate(
- delegate: AbstractGraphNodeDelegate,
Set the delegate responsible for drawing nodes.
- Parameters:
delegate (AbstractGraphNodeDelegate) – The delegate to use for drawing nodes.
- set_expansion(
- state: ExpansionState,
Open, close or minimize all the nodes in the model.
- Parameters:
state (GraphModel.ExpansionState) – The expansion state to set for all nodes.
- set_model(
- model: GraphModel,
Set the graph model for the view. It will refresh all the content.
- Parameters:
model (GraphModel) – The graph model to display.
- subscribe_empty_connection_drop(fn)#
Subscribe to the event triggered when a connection is dropped on an empty area.
- Parameters:
fn (callable) – The function to call when the event is triggered.
- Returns:
An _EventSubscription object that will unsubscribe when destroyed.
- subscribe_post_delayed_build_layout(fn)#
Subscribe to the event triggered after a delayed layout build.
- Parameters:
fn (callable) – The function to call when the event is triggered.
- Returns:
An _EventSubscription object that will unsubscribe when destroyed.
- subscribe_pre_delayed_build_layout(fn)#
Subscribe to the event triggered before a delayed layout build.
- Parameters:
fn (callable) – The function to call when the event is triggered.
- Returns:
An _EventSubscription object that will unsubscribe when destroyed.
- property model#
Gets the current graph model.
- Returns:
The current GraphModel instance.
- property pan_x#
Gets the current horizontal pan position of the graph.
- Returns:
The horizontal pan position.
- property pan_y#
Gets the current vertical pan position of the graph.
- Returns:
The vertical pan position.
- property raster_nodes#
Gets whether node rasterization is enabled.
- Returns:
A boolean indicating if rasterization is enabled.
- property selection#
Gets the currently selected nodes in the graph.
- Returns:
A list of the currently selected nodes.
- property virtual_ports#
Gets whether virtual ports are enabled.
- Returns:
A boolean indicating if virtual ports are enabled.
- property zoom#
Gets the current zoom level of the graph.
- Returns:
The current zoom level.
- property zoom_max#
Gets the maximum zoom level of the graph.
- Returns:
The maximum zoom level.
- property zoom_min#
Gets the minimum zoom level of the graph.
- Returns:
The minimum zoom level.