panelini.panels.visnetwork.visnetwork

Entrypoint of visnetwork panel.

Module Contents

Classes

VisNetwork

A vis-network graph visualization component.

Data

API

panelini.panels.visnetwork.visnetwork.bundled_assets_dir

None

class panelini.panels.visnetwork.visnetwork.VisNetwork(nodes: Optional[list[dict[str, Any]]] = None, edges: Optional[list[dict[str, Any]]] = None, options: Optional[dict[str, Any]] = None, network_event_callback: Optional[Callable[[str, dict[str, Any]], None]] = None, file_drop_callback: Optional[Callable[[dict[str, Any]], None]] = None, **params: Any)[source]

Bases: panel.custom.AnyWidgetComponent

A vis-network graph visualization component.

This component wraps the vis-network JavaScript library to provide interactive network/graph visualization within Panel applications.

Initialization

Initialize the VisNetwork component.

Args: nodes: List of node objects with at least ‘id’ and optionally ‘label’, ‘shape’, etc. edges: List of edge objects with ‘from’ and ‘to’ node IDs. options: vis-network options for customizing appearance and behavior. network_event_callback: Callback function for network events (click, drag, etc.). file_drop_callback: Callback function for file drop events. **params: Additional parameters passed to AnyWidgetComponent.

nodes

‘List(…)’

edges

‘List(…)’

options

‘Dict(…)’

manipulation_state

‘String(…)’

handle_network_event(event_name: str, event_params: dict[str, Any]) None[source]

Handle a network event.

Args: event_name: Name of the event (click, doubleClick, dragEnd, etc.). event_params: Event parameters containing nodes, edges, positions, etc.

default_file_drop_callback(event_params: dict[str, Any]) None[source]

Default handler for file drop events.

Creates nodes for dropped files at the drop position.

Args: event_params: Contains x, y coordinates and files list with name and content.

disable_edit_mode() None[source]

Disable manipulation/edit mode.

add_node_mode() None[source]

Enable add node mode.

add_edge_mode() None[source]

Enable add edge mode.

request_position_update() None[source]

Request JavaScript to update all node positions from the network.

get_nodes() list[dict[str, Any]][source]

Get the current list of nodes.

get_edges() list[dict[str, Any]][source]

Get the current list of edges.

set_nodes(nodes: list[dict[str, Any]]) None[source]

Set the nodes.

set_edges(edges: list[dict[str, Any]]) None[source]

Set the edges.

add_node(node: dict[str, Any]) None[source]

Add a single node to the network.

Args: node: Node object with at least ‘id’ key.

add_edge(edge: dict[str, Any]) None[source]

Add a single edge to the network.

Args: edge: Edge object with ‘from’ and ‘to’ keys.

remove_node(node_id: Any) None[source]

Remove a node by ID.

Args: node_id: The ID of the node to remove.

remove_edge(from_id: Any, to_id: Any) None[source]

Remove an edge by from/to IDs.

Args: from_id: The source node ID. to_id: The target node ID.

update_node(node: dict[str, Any]) None[source]

Update an existing node’s properties (partial update).

Args: node: Node dict with ‘id’ and properties to update. Only provided properties will be updated.

update_nodes(nodes: list[dict[str, Any]]) None[source]

Update multiple nodes’ properties at once (partial updates).

Args: nodes: List of node dicts, each with ‘id’ and properties to update.

update_node_state(node_ids: list[Any], state: str) None[source]

Update the state of multiple nodes (changes border color).

Args: node_ids: List of node IDs to update. state: New state - ‘new’ (red), ‘modified’ (yellow), or ‘stored’ (black).

update_edge(edge: dict[str, Any]) None[source]

Update an existing edge’s properties (partial update).

Args: edge: Edge dict with ‘id’ or ‘from’/’to’ keys and properties to update.

get_node(node_id: Any) Optional[dict[str, Any]][source]

Get a single node by ID.

Args: node_id: The ID of the node to retrieve.

Returns: The node dict if found, None otherwise.

get_edge(edge_id: Any = None, from_id: Any = None, to_id: Any = None) Optional[dict[str, Any]][source]

Get a single edge by ID or by from/to combination.

Args: edge_id: The ID of the edge (if edges have IDs). from_id: The source node ID (used with to_id). to_id: The target node ID (used with from_id).

Returns: The edge dict if found, None otherwise.

clear() None[source]

Clear all nodes and edges from the network.

execute_step(step: dict[str, Any]) None[source]

Execute a step from a playbook sequence (flat JSON format).

Changes are synced back from JS via emitNodesAndEdges().

Args: step: Step dict with ‘actions’ list and optional ‘status’. Actions use flat format matching the JS playbook notation.

Supported action fields: addNode: id, label, type, state, json_data (dict, shown as YAML tooltip on hover) updateNode: id, label, state, json_data (dict, updates YAML tooltip) addEdge: from, to, label, dashed updateNodeState: nodeIds, state mergeNodes: sourceId, targetId removeNode: id

Example: graph.execute_step({ “actions”: [ {“action”: “addNode”, “id”: “n1”, “label”: “Node 1”, “type”: “instance”, “json_data”: {“temperature”: 25.0, “unit”: “celsius”}}, {“action”: “addEdge”, “from”: “n1”, “to”: “n2”, “label”: “connects”}, {“action”: “updateNodeState”, “nodeIds”: [“n1”], “state”: “stored”}, ], “status”: “Adding nodes…” })

batch_update(actions: list[dict[str, Any]]) None[source]

Execute multiple graph actions atomically.

Args: actions: List of action dicts, each containing: - action: One of ‘addNode’, ‘addEdge’, ‘updateNode’, ‘updateEdge’, ‘removeNode’, ‘removeEdge’ - payload: The node/edge data or ID to operate on

Example: graph.batch_update([ {“action”: “addNode”, “payload”: {“id”: 1, “label”: “A”}}, {“action”: “addEdge”, “payload”: {“from”: 1, “to”: 2}}, {“action”: “updateNode”, “payload”: {“id”: 2, “color”: “red”}}, {“action”: “removeNode”, “payload”: {“id”: 3}}, ])

merge_nodes(source_id: Any, target_id: Any, merge_properties: bool = True) None[source]

Merge source node into target node, redirecting all edges.

Args: source_id: ID of the node to be merged and removed. target_id: ID of the node to receive the merged edges. merge_properties: If True, merge source properties into target.