pyvis-optimized 4.3.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyvis/__init__.py +2 -0
- pyvis/_version.py +1 -0
- pyvis/edge.py +26 -0
- pyvis/network.py +1498 -0
- pyvis/node.py +35 -0
- pyvis/shiny/__init__.py +213 -0
- pyvis/shiny/bindings.js +1310 -0
- pyvis/shiny/styles.css +382 -0
- pyvis/shiny/wrapper.py +1368 -0
- pyvis/templates/lib/bindings/utils.js +189 -0
- pyvis/templates/lib/tom-select/tom-select.complete.min.js +5021 -0
- pyvis/templates/lib/tom-select/tom-select.css +2 -0
- pyvis/templates/lib/vis-10.0.2/vis-network.min.css +2 -0
- pyvis/templates/lib/vis-10.0.2/vis-network.min.js +78 -0
- pyvis/templates/template.html +911 -0
- pyvis/types/__init__.py +59 -0
- pyvis/types/base.py +109 -0
- pyvis/types/common.py +74 -0
- pyvis/types/configure.py +13 -0
- pyvis/types/edges.py +139 -0
- pyvis/types/interaction.py +42 -0
- pyvis/types/layout.py +34 -0
- pyvis/types/manipulation.py +18 -0
- pyvis/types/network.py +34 -0
- pyvis/types/nodes.py +158 -0
- pyvis/types/physics.py +90 -0
- pyvis/utils.py +26 -0
- pyvis/vis_config.py +24 -0
- pyvis_optimized-4.3.1.dist-info/METADATA +269 -0
- pyvis_optimized-4.3.1.dist-info/RECORD +33 -0
- pyvis_optimized-4.3.1.dist-info/WHEEL +5 -0
- pyvis_optimized-4.3.1.dist-info/licenses/LICENSE_BSD.txt +27 -0
- pyvis_optimized-4.3.1.dist-info/top_level.txt +1 -0
pyvis/node.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Node module for pyvis network visualization.
|
|
2
|
+
|
|
3
|
+
This module provides the Node class for representing nodes in a network graph.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Union, Dict, Any, Optional
|
|
7
|
+
|
|
8
|
+
__all__ = ['Node']
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Node:
|
|
12
|
+
"""Represents a node in a network visualization.
|
|
13
|
+
|
|
14
|
+
A Node encapsulates the properties and visual attributes of a single node
|
|
15
|
+
in the network graph, including its ID, label, shape, and other visual options.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, n_id: Union[str, int], shape: str, label: Union[str, int], font_color: Optional[str] = None, **opts):
|
|
19
|
+
self.options: Dict[str, Any] = opts
|
|
20
|
+
self.options["id"] = n_id
|
|
21
|
+
self.options["label"] = label
|
|
22
|
+
self.options["shape"] = shape
|
|
23
|
+
if font_color is not None and font_color is not False:
|
|
24
|
+
existing_font = self.options.get("font", {})
|
|
25
|
+
if isinstance(existing_font, dict):
|
|
26
|
+
existing_font["color"] = font_color
|
|
27
|
+
self.options["font"] = existing_font
|
|
28
|
+
else:
|
|
29
|
+
import warnings
|
|
30
|
+
warnings.warn(
|
|
31
|
+
f"font_color cannot be merged into string font value {existing_font!r}. "
|
|
32
|
+
"The string font will be replaced with a dict containing the color.",
|
|
33
|
+
UserWarning, stacklevel=3
|
|
34
|
+
)
|
|
35
|
+
self.options["font"] = {"color": font_color}
|
pyvis/shiny/__init__.py
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PyVis Shiny Integration
|
|
3
|
+
|
|
4
|
+
This module provides integration between PyVis (vis.js) network visualizations
|
|
5
|
+
and Shiny for Python applications.
|
|
6
|
+
|
|
7
|
+
Basic Usage (Simple iframe approach):
|
|
8
|
+
------------------------------------
|
|
9
|
+
```python
|
|
10
|
+
from shiny import App, ui, render
|
|
11
|
+
from pyvis.shiny import render_network
|
|
12
|
+
from pyvis.network import Network
|
|
13
|
+
|
|
14
|
+
def server(input, output, session):
|
|
15
|
+
@render.ui
|
|
16
|
+
def my_network():
|
|
17
|
+
net = Network()
|
|
18
|
+
net.add_node(1, label="Node 1")
|
|
19
|
+
net.add_node(2, label="Node 2")
|
|
20
|
+
net.add_edge(1, 2)
|
|
21
|
+
return render_network(net)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Advanced Usage (Custom output binding with events):
|
|
25
|
+
-------------------------------------------------
|
|
26
|
+
```python
|
|
27
|
+
from shiny import App, ui, render, reactive
|
|
28
|
+
from pyvis.shiny import output_pyvis_network, render_pyvis_network
|
|
29
|
+
from pyvis.network import Network
|
|
30
|
+
|
|
31
|
+
app_ui = ui.page_fluid(
|
|
32
|
+
output_pyvis_network("my_network", height="600px"),
|
|
33
|
+
ui.output_text_verbatim("selected")
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
def server(input, output, session):
|
|
37
|
+
@render_pyvis_network
|
|
38
|
+
def my_network():
|
|
39
|
+
net = Network()
|
|
40
|
+
net.add_node(1, label="Node 1")
|
|
41
|
+
net.add_node(2, label="Node 2")
|
|
42
|
+
net.add_edge(1, 2)
|
|
43
|
+
return net
|
|
44
|
+
|
|
45
|
+
@render.text
|
|
46
|
+
def selected():
|
|
47
|
+
event = input.my_network_selectNode()
|
|
48
|
+
if event:
|
|
49
|
+
return f"Selected: {event['nodeId']}"
|
|
50
|
+
return "Click a node"
|
|
51
|
+
|
|
52
|
+
app = App(app_ui, server)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Controlling Network from Python:
|
|
56
|
+
-------------------------------
|
|
57
|
+
```python
|
|
58
|
+
from pyvis.shiny import PyVisNetworkController, network_fit, network_select_nodes
|
|
59
|
+
|
|
60
|
+
def server(input, output, session):
|
|
61
|
+
# Option 1: Use controller class
|
|
62
|
+
ctrl = PyVisNetworkController("my_network", session)
|
|
63
|
+
|
|
64
|
+
@reactive.effect
|
|
65
|
+
@reactive.event(input.fit_btn)
|
|
66
|
+
def _():
|
|
67
|
+
ctrl.fit() # Zoom to fit all nodes
|
|
68
|
+
ctrl.select_nodes([1, 2]) # Select specific nodes
|
|
69
|
+
|
|
70
|
+
# Option 2: Use standalone functions
|
|
71
|
+
@reactive.effect
|
|
72
|
+
@reactive.event(input.focus_btn)
|
|
73
|
+
def _():
|
|
74
|
+
network_focus(session, "my_network", node_id=1, scale=2.0)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Available Events (as Shiny inputs):
|
|
78
|
+
----------------------------------
|
|
79
|
+
- input.{id}_click - Network clicked
|
|
80
|
+
- input.{id}_doubleClick - Network double-clicked
|
|
81
|
+
- input.{id}_contextMenu - Right-click
|
|
82
|
+
- input.{id}_selectNode - Node selected (includes nodeData)
|
|
83
|
+
- input.{id}_selectEdge - Edge selected (includes edgeData)
|
|
84
|
+
- input.{id}_deselectNode - Node deselected
|
|
85
|
+
- input.{id}_deselectEdge - Edge deselected
|
|
86
|
+
- input.{id}_hoverNode - Hovering over node
|
|
87
|
+
- input.{id}_blurNode - Hover left node
|
|
88
|
+
- input.{id}_hoverEdge - Hovering over edge
|
|
89
|
+
- input.{id}_blurEdge - Hover left edge
|
|
90
|
+
- input.{id}_dragStart - Dragging started
|
|
91
|
+
- input.{id}_dragEnd - Dragging ended (includes new positions)
|
|
92
|
+
- input.{id}_zoom - Zoom changed
|
|
93
|
+
- input.{id}_stabilized - Physics stabilization complete
|
|
94
|
+
- input.{id}_ready - Network fully initialized
|
|
95
|
+
|
|
96
|
+
Response Inputs (from query commands):
|
|
97
|
+
------------------------------------
|
|
98
|
+
- input.{id}_response_positions - Node positions
|
|
99
|
+
- input.{id}_response_selection - Current selection
|
|
100
|
+
- input.{id}_response_scale - Zoom scale
|
|
101
|
+
- input.{id}_response_viewPosition - Camera position
|
|
102
|
+
- input.{id}_response_allData - All network data
|
|
103
|
+
|
|
104
|
+
Module Usage (Reusable component):
|
|
105
|
+
---------------------------------
|
|
106
|
+
```python
|
|
107
|
+
from shiny import App, ui, reactive
|
|
108
|
+
from pyvis.shiny import pyvis_network_ui, pyvis_network_server
|
|
109
|
+
|
|
110
|
+
app_ui = ui.page_fluid(
|
|
111
|
+
pyvis_network_ui("net1", height="400px")
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
def server(input, output, session):
|
|
115
|
+
network_data = reactive.Value({
|
|
116
|
+
'nodes': [{'id': 1, 'label': 'A'}, {'id': 2, 'label': 'B'}],
|
|
117
|
+
'edges': [{'from': 1, 'to': 2}]
|
|
118
|
+
})
|
|
119
|
+
pyvis_network_server("net1", network_data)
|
|
120
|
+
|
|
121
|
+
app = App(app_ui, server)
|
|
122
|
+
```
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
from .wrapper import (
|
|
126
|
+
# Core rendering
|
|
127
|
+
render_network,
|
|
128
|
+
output_pyvis_network,
|
|
129
|
+
render_pyvis_network,
|
|
130
|
+
# Module
|
|
131
|
+
pyvis_network_ui,
|
|
132
|
+
pyvis_network_server,
|
|
133
|
+
# Controller class
|
|
134
|
+
PyVisNetworkController,
|
|
135
|
+
# Standalone command functions
|
|
136
|
+
network_select_nodes,
|
|
137
|
+
network_select_edges,
|
|
138
|
+
network_unselect_all,
|
|
139
|
+
network_fit,
|
|
140
|
+
network_focus,
|
|
141
|
+
network_move_to,
|
|
142
|
+
network_start_physics,
|
|
143
|
+
network_stop_physics,
|
|
144
|
+
network_stabilize,
|
|
145
|
+
network_add_node,
|
|
146
|
+
network_add_edge,
|
|
147
|
+
network_update_node,
|
|
148
|
+
network_update_edge,
|
|
149
|
+
network_remove_node,
|
|
150
|
+
network_remove_edge,
|
|
151
|
+
network_open_cluster,
|
|
152
|
+
network_set_options,
|
|
153
|
+
network_set_theme,
|
|
154
|
+
network_toggle_manipulation,
|
|
155
|
+
network_set_edge_edit_mode,
|
|
156
|
+
network_set_node_template_mode,
|
|
157
|
+
network_get_positions,
|
|
158
|
+
network_get_selection,
|
|
159
|
+
network_add_nodes,
|
|
160
|
+
network_add_edges,
|
|
161
|
+
network_cluster_by_connection,
|
|
162
|
+
network_cluster_by_hubsize,
|
|
163
|
+
network_get_scale,
|
|
164
|
+
network_get_view_position,
|
|
165
|
+
network_get_all_data,
|
|
166
|
+
network_get_data,
|
|
167
|
+
network_update_data,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
__all__ = [
|
|
171
|
+
# Core rendering
|
|
172
|
+
'render_network',
|
|
173
|
+
'output_pyvis_network',
|
|
174
|
+
'render_pyvis_network',
|
|
175
|
+
# Module
|
|
176
|
+
'pyvis_network_ui',
|
|
177
|
+
'pyvis_network_server',
|
|
178
|
+
# Controller class
|
|
179
|
+
'PyVisNetworkController',
|
|
180
|
+
# Standalone command functions
|
|
181
|
+
'network_select_nodes',
|
|
182
|
+
'network_select_edges',
|
|
183
|
+
'network_unselect_all',
|
|
184
|
+
'network_fit',
|
|
185
|
+
'network_focus',
|
|
186
|
+
'network_move_to',
|
|
187
|
+
'network_start_physics',
|
|
188
|
+
'network_stop_physics',
|
|
189
|
+
'network_stabilize',
|
|
190
|
+
'network_add_node',
|
|
191
|
+
'network_add_edge',
|
|
192
|
+
'network_update_node',
|
|
193
|
+
'network_update_edge',
|
|
194
|
+
'network_remove_node',
|
|
195
|
+
'network_remove_edge',
|
|
196
|
+
'network_open_cluster',
|
|
197
|
+
'network_set_options',
|
|
198
|
+
'network_set_theme',
|
|
199
|
+
'network_toggle_manipulation',
|
|
200
|
+
'network_set_edge_edit_mode',
|
|
201
|
+
'network_set_node_template_mode',
|
|
202
|
+
'network_get_positions',
|
|
203
|
+
'network_get_selection',
|
|
204
|
+
'network_add_nodes',
|
|
205
|
+
'network_add_edges',
|
|
206
|
+
'network_cluster_by_connection',
|
|
207
|
+
'network_cluster_by_hubsize',
|
|
208
|
+
'network_get_scale',
|
|
209
|
+
'network_get_view_position',
|
|
210
|
+
'network_get_all_data',
|
|
211
|
+
'network_get_data',
|
|
212
|
+
'network_update_data',
|
|
213
|
+
]
|