pyvis-optimized 4.5.0__tar.gz → 5.0.0__tar.gz

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.
Files changed (52) hide show
  1. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/CHANGELOG.md +75 -0
  2. {pyvis_optimized-4.5.0/pyvis_optimized.egg-info → pyvis_optimized-5.0.0}/PKG-INFO +7 -8
  3. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/README.md +4 -4
  4. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/examples/shiny_demo.py +17 -7
  5. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/examples/shiny_editor_demo.py +11 -6
  6. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/examples/shiny_simple_demo.py +2 -2
  7. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyproject.toml +4 -5
  8. pyvis_optimized-5.0.0/pyvis/_version.py +1 -0
  9. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/network.py +39 -3
  10. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/shiny/__init__.py +2 -2
  11. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/shiny/bindings.js +92 -15
  12. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/shiny/wrapper.py +120 -13
  13. pyvis_optimized-5.0.0/pyvis/templates/lib/vis-10.1.5/vis-network.min.js +78 -0
  14. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/templates/template.html +20 -12
  15. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/vis_config.py +8 -2
  16. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0/pyvis_optimized.egg-info}/PKG-INFO +7 -8
  17. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis_optimized.egg-info/SOURCES.txt +2 -2
  18. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis_optimized.egg-info/requires.txt +1 -1
  19. pyvis_optimized-4.5.0/pyvis/_version.py +0 -1
  20. pyvis_optimized-4.5.0/pyvis/templates/lib/vis-10.1.2/vis-network.min.js +0 -78
  21. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/LICENSE_BSD.txt +0 -0
  22. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/MANIFEST.in +0 -0
  23. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/examples/edge_attribute_editing_example.py +0 -0
  24. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/notebooks/01_basics.ipynb +0 -0
  25. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/notebooks/02_networkx.ipynb +0 -0
  26. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/notebooks/03_typed_options.ipynb +0 -0
  27. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/notebooks/04_advanced.ipynb +0 -0
  28. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/notebooks/NetworkOfThrones.csv +0 -0
  29. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/notebooks/test.dot +0 -0
  30. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/__init__.py +0 -0
  31. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/edge.py +0 -0
  32. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/node.py +0 -0
  33. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/shiny/styles.css +0 -0
  34. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/templates/lib/bindings/utils.js +0 -0
  35. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/templates/lib/tom-select/tom-select.complete.min.js +0 -0
  36. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/templates/lib/tom-select/tom-select.css +0 -0
  37. {pyvis_optimized-4.5.0/pyvis/templates/lib/vis-10.1.2 → pyvis_optimized-5.0.0/pyvis/templates/lib/vis-10.1.5}/vis-network.min.css +0 -0
  38. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/types/__init__.py +0 -0
  39. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/types/base.py +0 -0
  40. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/types/common.py +0 -0
  41. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/types/configure.py +0 -0
  42. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/types/edges.py +0 -0
  43. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/types/interaction.py +0 -0
  44. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/types/layout.py +0 -0
  45. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/types/manipulation.py +0 -0
  46. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/types/network.py +0 -0
  47. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/types/nodes.py +0 -0
  48. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/types/physics.py +0 -0
  49. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis/utils.py +0 -0
  50. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis_optimized.egg-info/dependency_links.txt +0 -0
  51. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/pyvis_optimized.egg-info/top_level.txt +0 -0
  52. {pyvis_optimized-4.5.0 → pyvis_optimized-5.0.0}/setup.cfg +0 -0
@@ -3,6 +3,81 @@
3
3
  All notable changes to this project are documented in this file.
4
4
 
5
5
 
6
+ ## [5.0.0] - 2026-11-18
7
+
8
+ ### Breaking Changes
9
+ - **Python 3.11+.** `requires-python` is now `>=3.11` (was `>=3.10`),
10
+ following Shiny for Python, whose next release drops 3.10. Python 3.10
11
+ users stay on pyvis-optimized 4.5.x.
12
+ - **`shiny>=1.6.4`** for the `shiny` extra (was `>=1.0`, never tested):
13
+ 1.6.4 fixes a bookmark path-traversal vulnerability, and 1.6.1 added the
14
+ `session.on_destroy()` that module cleanup uses.
15
+ - **Shiny output size is honoured.** `output_pyvis_network(height=...,
16
+ width=...)` used to be ignored once the network rendered: the output div
17
+ carried Shiny's `shiny-html-output` class, which Shiny's CSS turns into
18
+ `display: contents` (no box, so no size). The class is dropped, so the
19
+ size you ask for is the size you get. Apps that relied on the old
20
+ behaviour (network sized by its parent) may need `fill=True`.
21
+
22
+ ### Added
23
+ - `output_pyvis_network(fill=True)` is a standard Shiny fill item, so the
24
+ network grows inside `page_fillable()`, full-screen cards and sidebars.
25
+ - `theme="auto"` for `output_pyvis_network()` / `render_pyvis_network()` /
26
+ `set_theme()`: the network follows the page's Bootstrap colour mode
27
+ (`data-bs-theme` on `<html>`, as toggled by `ui.input_dark_mode()`),
28
+ including node label colours. An explicit `set_theme("light"/"dark")`
29
+ stops following; `set_theme("auto")` resumes.
30
+
31
+ ### Changed
32
+ - Shiny output: node labels follow the theme. With `theme="dark"` labels
33
+ default to `#e0e0e0` (was vis-network's dark grey `#343434`, unreadable on
34
+ the dark canvas), and `set_theme()` switches them. A label colour you set
35
+ yourself (`options.nodes.font`, at render or via `set_options()`) or per
36
+ node is never overridden.
37
+ - Bundled vis-network upgraded from 10.1.2 to 10.1.5. Picks up the upstream
38
+ fixes for escaped quotes in DOT strings (a `from_DOT()` file with a label
39
+ such as `"say \"hi\""` previously failed to render at all) and for starting
40
+ a view animation while another is pending (`fit()`/`focus()`/`move_to()`
41
+ and the search box's animated focus).
42
+
43
+ ### Security
44
+ - Remote vis-network assets now carry Subresource Integrity hashes
45
+ (`integrity` + `crossorigin` on the unpkg `<script>`/`<link>`), as the
46
+ `cdn_resources="remote"` docs already claimed. `remote_esm` covers the CSS;
47
+ its JS is loaded by an ES-module `import`, which cannot carry SRI.
48
+
49
+ ### Fixed
50
+ - `pyvis_network_server` releases its browser-side network (vis instance,
51
+ DataSets, observers) when the parent removes the module with
52
+ `await session.destroy(id)` (Shiny >= 1.6.1).
53
+ - Shiny controller commands (`ctrl.fit()`, `select_nodes()`, `add_node()`,
54
+ ...) issued while their network is being re-rendered (e.g. by the effect
55
+ that just changed its data) used to reach the old network and be lost
56
+ when the new one replaced it. They are now sent right after the outputs
57
+ carrying the new network (via `session.on_flushed()`), in the order
58
+ issued. All other commands are still sent immediately, so step-by-step
59
+ async effects show each step.
60
+ - `add_node(color=..., group=...)` warns that the colour is ignored (the
61
+ group's style applies) instead of dropping it silently, and points to
62
+ `set_group()`. `group=None` now means "no group", so the colour is kept.
63
+ - `cdn_resources="remote_esm"` rendered nothing: the main script ran as an
64
+ ES module, so strict mode threw on an undeclared loop variable and its
65
+ globals were invisible to `utils.js` (highlighting, menus). It is now a
66
+ classic script that draws once the module has loaded vis-network, and the
67
+ module exposes the full namespace, so `from_DOT()` works in this mode too.
68
+ - CSS dimensions accept a flat `calc()` expression, e.g.
69
+ `output_pyvis_network(..., height="calc(100vh - 40px)")` or
70
+ `Network(height="calc(100% - 2rem)")`. Only numbers, the existing units and
71
+ `+ - * /` are allowed inside, so the injection guard still holds. The
72
+ pattern is now shared by `Network` and the Shiny wrapper. This had made
73
+ `examples/shiny_demo.py` and `examples/shiny_editor_demo.py` crash at
74
+ startup.
75
+ - Dark-theme demos are readable: sidebar text no longer inherits bslib's
76
+ near-black sidebar colour, and `shiny_demo.py` applies its per-group colours via `set_group()`
77
+ (a node's own `color` is ignored when it has a `group`).
78
+ - `pyvis_network_ui()` no longer emits a `ShinyDeprecationWarning` on
79
+ Shiny >= 1.8: it uses `ui.output_code()`/`@render.code` instead of the
80
+ deprecated `ui.output_text_verbatim()`. Docs and examples updated likewise.
6
81
 
7
82
  ## [4.5.0] - 2026-10-24
8
83
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyvis-optimized
3
- Version: 4.5.0
3
+ Version: 5.0.0
4
4
  Summary: A Python network graph visualization library - Optimized Edition
5
5
  Author-email: Jose Unpingco <datascience@westhealth.org>
6
6
  Maintainer: PyVis Contributors
@@ -17,20 +17,19 @@ Classifier: Intended Audience :: Science/Research
17
17
  Classifier: License :: OSI Approved :: BSD License
18
18
  Classifier: Operating System :: OS Independent
19
19
  Classifier: Programming Language :: Python :: 3
20
- Classifier: Programming Language :: Python :: 3.10
21
20
  Classifier: Programming Language :: Python :: 3.11
22
21
  Classifier: Programming Language :: Python :: 3.12
23
22
  Classifier: Programming Language :: Python :: 3.13
24
23
  Classifier: Topic :: Scientific/Engineering :: Visualization
25
24
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
- Requires-Python: >=3.10
25
+ Requires-Python: >=3.11
27
26
  Description-Content-Type: text/markdown
28
27
  License-File: LICENSE_BSD.txt
29
28
  Requires-Dist: jinja2>=2.9.6
30
29
  Requires-Dist: networkx>=1.11
31
30
  Requires-Dist: jsonpickle>=1.4.1
32
31
  Provides-Extra: shiny
33
- Requires-Dist: shiny>=1.0; extra == "shiny"
32
+ Requires-Dist: shiny>=1.6.4; extra == "shiny"
34
33
  Requires-Dist: htmltools; extra == "shiny"
35
34
  Provides-Extra: notebook
36
35
  Requires-Dist: ipython>=5.3.0; extra == "notebook"
@@ -69,7 +68,7 @@ PyVis is a Python library for creating and visualizing interactive network graph
69
68
 
70
69
  ## Installation
71
70
 
72
- **Requires Python >= 3.10**
71
+ **Requires Python >= 3.11**
73
72
 
74
73
  ```bash
75
74
  pip install pyvis-optimized
@@ -101,7 +100,7 @@ pip install .
101
100
  | [jinja2](https://jinja.palletsprojects.com/) >= 2.9.6 | HTML template rendering |
102
101
  | [jsonpickle](https://jsonpickle.github.io/) >= 1.4.1 | JSON serialization |
103
102
 
104
- Optional: [ipython](https://ipython.org/) >= 5.3.0 (`pyvis-optimized[notebook]`), [shiny](https://shiny.posit.co/py/) >= 1.0 and [htmltools](https://pypi.org/project/htmltools/) (`pyvis-optimized[shiny]`)
103
+ Optional: [ipython](https://ipython.org/) >= 5.3.0 (`pyvis-optimized[notebook]`), [shiny](https://shiny.posit.co/py/) >= 1.6.4 and [htmltools](https://pypi.org/project/htmltools/) (`pyvis-optimized[shiny]`)
105
104
 
106
105
  ## Quick Start
107
106
 
@@ -182,7 +181,7 @@ from pyvis.shiny import (
182
181
  app_ui = ui.page_fluid(
183
182
  output_pyvis_network("network", height="600px"),
184
183
  ui.input_action_button("fit", "Fit to View"),
185
- ui.output_text_verbatim("selected")
184
+ ui.output_code("selected")
186
185
  )
187
186
 
188
187
  def server(input, output, session):
@@ -201,7 +200,7 @@ def server(input, output, session):
201
200
  def _():
202
201
  ctrl.fit()
203
202
 
204
- @render.text
203
+ @render.code
205
204
  def selected():
206
205
  event = input.network_selectNode()
207
206
  return f"Selected: {event['nodeId']}" if event else "Click a node"
@@ -17,7 +17,7 @@ PyVis is a Python library for creating and visualizing interactive network graph
17
17
 
18
18
  ## Installation
19
19
 
20
- **Requires Python >= 3.10**
20
+ **Requires Python >= 3.11**
21
21
 
22
22
  ```bash
23
23
  pip install pyvis-optimized
@@ -49,7 +49,7 @@ pip install .
49
49
  | [jinja2](https://jinja.palletsprojects.com/) >= 2.9.6 | HTML template rendering |
50
50
  | [jsonpickle](https://jsonpickle.github.io/) >= 1.4.1 | JSON serialization |
51
51
 
52
- Optional: [ipython](https://ipython.org/) >= 5.3.0 (`pyvis-optimized[notebook]`), [shiny](https://shiny.posit.co/py/) >= 1.0 and [htmltools](https://pypi.org/project/htmltools/) (`pyvis-optimized[shiny]`)
52
+ Optional: [ipython](https://ipython.org/) >= 5.3.0 (`pyvis-optimized[notebook]`), [shiny](https://shiny.posit.co/py/) >= 1.6.4 and [htmltools](https://pypi.org/project/htmltools/) (`pyvis-optimized[shiny]`)
53
53
 
54
54
  ## Quick Start
55
55
 
@@ -130,7 +130,7 @@ from pyvis.shiny import (
130
130
  app_ui = ui.page_fluid(
131
131
  output_pyvis_network("network", height="600px"),
132
132
  ui.input_action_button("fit", "Fit to View"),
133
- ui.output_text_verbatim("selected")
133
+ ui.output_code("selected")
134
134
  )
135
135
 
136
136
  def server(input, output, session):
@@ -149,7 +149,7 @@ def server(input, output, session):
149
149
  def _():
150
150
  ctrl.fit()
151
151
 
152
- @render.text
152
+ @render.code
153
153
  def selected():
154
154
  event = input.network_selectNode()
155
155
  return f"Selected: {event['nodeId']}" if event else "Click a node"
@@ -64,6 +64,10 @@ INITIAL_EDGES = [
64
64
  {"from": 10, "to": 9, "title": "uses"},
65
65
  ]
66
66
 
67
+ # A node's own color is dropped when it has a group (the group's style wins),
68
+ # so the per-group colors above are applied as group definitions.
69
+ GROUP_COLORS = {"language": "#3776ab", "framework": "#27ae60", "library": "#e67e22"}
70
+
67
71
  # Node IDs for select dropdowns -- built from initial data
68
72
  INITIAL_NODE_CHOICES = {str(n["id"]): f'{n["label"]} ({n["id"]})' for n in INITIAL_NODES}
69
73
 
@@ -140,6 +144,8 @@ header::after, .navbar::after {
140
144
 
141
145
  /* ── Sidebar ── */
142
146
  .bslib-sidebar-layout > .sidebar {
147
+ --bslib-sidebar-fg: var(--pv-text);
148
+ color: var(--pv-text) !important;
143
149
  background: var(--pv-bg-surface) !important;
144
150
  border-right: 1px solid var(--pv-border) !important;
145
151
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3) !important;
@@ -419,7 +425,7 @@ def _tab_editor():
419
425
  ),
420
426
  ui.accordion_panel(
421
427
  "Selected Node",
422
- ui.output_text_verbatim("selected_info"),
428
+ ui.output_code("selected_info"),
423
429
  ui.input_text("edit_label", "New Label"),
424
430
  ui.input_text("edit_color", "New Color", value="#e74c3c"),
425
431
  ui.layout_columns(
@@ -522,7 +528,7 @@ def _tab_events():
522
528
  ),
523
529
  ui.accordion_panel(
524
530
  "Event Log",
525
- ui.output_text_verbatim("event_log"),
531
+ ui.output_code("event_log"),
526
532
  icon=ui.tags.i(class_="fa fa-stream"),
527
533
  ),
528
534
  id="events_acc",
@@ -562,7 +568,7 @@ def _tab_queries():
562
568
  ),
563
569
  ui.accordion_panel(
564
570
  "Response",
565
- ui.output_text_verbatim("query_response"),
571
+ ui.output_code("query_response"),
566
572
  icon=ui.tags.i(class_="fa fa-terminal"),
567
573
  ),
568
574
  id="queries_acc",
@@ -664,8 +670,11 @@ def server(input, output, session):
664
670
  @render_pyvis_network(theme="dark")
665
671
  def network():
666
672
  net = Network(heading="")
673
+ for group, color in GROUP_COLORS.items():
674
+ net.set_group(group, color=color)
667
675
  for n in INITIAL_NODES:
668
- net.add_node(n["id"], label=n["label"], color=n["color"],
676
+ # Grouped nodes take their colour from GROUP_COLORS via set_group().
677
+ net.add_node(n["id"], label=n["label"],
669
678
  shape=n["shape"], size=n["size"], group=n.get("group"))
670
679
  for e in INITIAL_EDGES:
671
680
  net.add_edge(e["from"], e["to"], title=e.get("title", ""))
@@ -676,6 +685,7 @@ def server(input, output, session):
676
685
  @reactive.effect
677
686
  @reactive.event(input.theme, ignore_init=True)
678
687
  def _switch_theme():
688
+ # Node labels follow the theme automatically.
679
689
  ctrl.set_theme(input.theme())
680
690
 
681
691
  # ── Helper: refresh node-select dropdowns ─────────────────────────
@@ -729,7 +739,7 @@ def server(input, output, session):
729
739
  def _on_deselect_node():
730
740
  selected_node_id.set(None)
731
741
 
732
- @render.text
742
+ @render.code
733
743
  def selected_info():
734
744
  ev = input.network_selectNode()
735
745
  if ev and ev.get("nodeData"):
@@ -930,7 +940,7 @@ def server(input, output, session):
930
940
  def _clear_log():
931
941
  event_log_entries.set([])
932
942
 
933
- @render.text
943
+ @render.code
934
944
  def event_log():
935
945
  entries = event_log_entries()
936
946
  if not entries:
@@ -1053,7 +1063,7 @@ def server(input, output, session):
1053
1063
  known_nodes.set(nodes_update)
1054
1064
  _refresh_selects()
1055
1065
 
1056
- @render.text
1066
+ @render.code
1057
1067
  def query_response():
1058
1068
  return last_query_response()
1059
1069
 
@@ -32,7 +32,9 @@ INITIAL_NODES = [
32
32
  {"id": 5, "label": "Epsilon", "color": "#9b59b6", "shape": "diamond", "size": 32},
33
33
  {"id": 6, "label": "Zeta", "color": "#1abc9c", "shape": "dot", "size": 22},
34
34
  {"id": 7, "label": "Eta", "color": "#e67e22", "shape": "ellipse", "size": 26},
35
- {"id": 8, "label": "Theta", "color": "#34495e", "shape": "box", "size": 28},
35
+ # Box labels sit inside the (dark) node, so keep them white in both themes.
36
+ {"id": 8, "label": "Theta", "color": "#34495e", "shape": "box", "size": 28,
37
+ "font": {"color": "#ffffff"}},
36
38
  ]
37
39
 
38
40
  INITIAL_EDGES = [
@@ -124,6 +126,8 @@ header::after, .navbar::after {
124
126
  }
125
127
 
126
128
  .bslib-sidebar-layout > .sidebar {
129
+ --bslib-sidebar-fg: var(--text);
130
+ color: var(--text) !important;
127
131
  background: var(--bg-surface) !important;
128
132
  border-right: 1px solid var(--border) !important;
129
133
  }
@@ -251,7 +255,7 @@ app_ui = ui.page_sidebar(
251
255
  # ── Edit Node ──
252
256
  ui.accordion_panel(
253
257
  "Edit Node",
254
- ui.output_text_verbatim("selected_node_info"),
258
+ ui.output_code("selected_node_info"),
255
259
  ui.input_text("edit_node_label", "Label"),
256
260
  ui.layout_columns(
257
261
  ui.input_text("edit_node_color", "Color", value="#e74c3c"),
@@ -268,7 +272,7 @@ app_ui = ui.page_sidebar(
268
272
  # ── Edit Edge ──
269
273
  ui.accordion_panel(
270
274
  "Edit Edge",
271
- ui.output_text_verbatim("selected_edge_info"),
275
+ ui.output_code("selected_edge_info"),
272
276
  ui.input_text("edit_edge_label", "Label"),
273
277
  ui.layout_columns(
274
278
  ui.input_text("edit_edge_color", "Color", value="#95a5a6"),
@@ -373,8 +377,9 @@ def server(input, output, session):
373
377
  def network():
374
378
  net = Network(heading="")
375
379
  for n in INITIAL_NODES:
380
+ extra = {"font": n["font"]} if "font" in n else {}
376
381
  net.add_node(n["id"], label=n["label"], color=n["color"],
377
- shape=n["shape"], size=n["size"])
382
+ shape=n["shape"], size=n["size"], **extra)
378
383
  for e in INITIAL_EDGES:
379
384
  net.add_edge(e["from"], e["to"], id=e["id"],
380
385
  width=e.get("width", 1), color=e.get("color"),
@@ -421,7 +426,7 @@ def server(input, output, session):
421
426
  def _on_deselect_node():
422
427
  selected_node_id.set(None)
423
428
 
424
- @render.text
429
+ @render.code
425
430
  def selected_node_info():
426
431
  ev = input.network_selectNode()
427
432
  if ev and ev.get("nodeData"):
@@ -465,7 +470,7 @@ def server(input, output, session):
465
470
  def _on_deselect_edge():
466
471
  selected_edge_id.set(None)
467
472
 
468
- @render.text
473
+ @render.code
469
474
  def selected_edge_info():
470
475
  ev = input.network_selectEdge()
471
476
  if ev and ev.get("edgeData") and not ev.get("nodeIds"):
@@ -25,7 +25,7 @@ app_ui = ui.page_fillable(
25
25
  ui.input_action_button("add", "Add Random Node", class_="btn-outline-secondary w-100"),
26
26
  ui.hr(),
27
27
  ui.h6("Last Event"),
28
- ui.output_text_verbatim("event_display"),
28
+ ui.output_code("event_display"),
29
29
  width=280,
30
30
  ),
31
31
  output_pyvis_network("network", height="100%"),
@@ -66,7 +66,7 @@ def server(input, output, session):
66
66
  "color": "#818cf8", "shape": "dot", "size": 20,
67
67
  })
68
68
 
69
- @render.text
69
+ @render.code
70
70
  def event_display():
71
71
  sel = input.network_selectNode()
72
72
  if sel:
@@ -7,7 +7,7 @@ name = "pyvis-optimized"
7
7
  dynamic = ["version"]
8
8
  description = "A Python network graph visualization library - Optimized Edition"
9
9
  readme = "README.md"
10
- requires-python = ">=3.10"
10
+ requires-python = ">=3.11"
11
11
  license = {text = "BSD"}
12
12
  authors = [
13
13
  {name = "Jose Unpingco", email = "datascience@westhealth.org"}
@@ -23,7 +23,6 @@ classifiers = [
23
23
  "License :: OSI Approved :: BSD License",
24
24
  "Operating System :: OS Independent",
25
25
  "Programming Language :: Python :: 3",
26
- "Programming Language :: Python :: 3.10",
27
26
  "Programming Language :: Python :: 3.11",
28
27
  "Programming Language :: Python :: 3.12",
29
28
  "Programming Language :: Python :: 3.13",
@@ -40,7 +39,7 @@ dependencies = [
40
39
  [project.optional-dependencies]
41
40
  # Shiny integration support
42
41
  shiny = [
43
- "shiny>=1.0",
42
+ "shiny>=1.6.4", # 1.6.4: bookmark path-traversal fix; 1.6.1: session.on_destroy
44
43
  "htmltools",
45
44
  ]
46
45
 
@@ -104,7 +103,7 @@ python_functions = "test_*"
104
103
 
105
104
  [tool.black]
106
105
  line-length = 100
107
- target-version = ['py310', 'py311', 'py312', 'py313']
106
+ target-version = ['py311', 'py312', 'py313']
108
107
  include = '\.pyi?$'
109
108
  exclude = '''
110
109
  /(
@@ -121,7 +120,7 @@ exclude = '''
121
120
  '''
122
121
 
123
122
  [tool.mypy]
124
- python_version = "3.10"
123
+ python_version = "3.11"
125
124
  warn_return_any = true
126
125
  warn_unused_configs = true
127
126
  disallow_untyped_defs = false
@@ -0,0 +1 @@
1
+ __version__ = '5.0.0'
@@ -51,9 +51,21 @@ CDN_REMOTE = CDNResource.REMOTE.value
51
51
  CDN_REMOTE_ESM = CDNResource.REMOTE_ESM.value
52
52
  VALID_CDN_RESOURCES = [CDN_LOCAL, CDN_INLINE, CDN_REMOTE, CDN_REMOTE_ESM]
53
53
 
54
+ # add_node()'s default colour (vis-network's own default node colour).
55
+ _DEFAULT_NODE_COLOR = '#97c2fc'
56
+
54
57
  # --- CSS Validation Patterns (Security) ---
55
58
  # Prevent CSS injection attacks
56
- _CSS_DIM_RE = re.compile(r'^\d+(\.\d+)?(px|%|em|rem|vh|vw)$')
59
+ # A dimension is a plain length (e.g. "600px", "100%") or a flat calc() of
60
+ # lengths and unitless numbers joined by + - * / (e.g. "calc(100vh - 40px)").
61
+ # No nested parentheses, functions, quotes or semicolons can match, so the
62
+ # value cannot break out of the style attribute it is interpolated into.
63
+ _CSS_LEN = r'\d+(?:\.\d+)?(?:px|%|em|rem|vh|vw)'
64
+ _CSS_CALC_TERM = r'\d+(?:\.\d+)?(?:px|%|em|rem|vh|vw)?'
65
+ _CSS_DIM_RE = re.compile(
66
+ rf'^(?:{_CSS_LEN}'
67
+ rf'|calc\(\s*{_CSS_CALC_TERM}(?:\s*[-+*/]\s*{_CSS_CALC_TERM})*\s*\))\Z' # \Z: no trailing newline
68
+ )
57
69
  _CSS_COLOR_RE = re.compile(
58
70
  r'^(#[0-9a-fA-F]{3,8}|[a-zA-Z]+|rgba?\(\s*[\d.,\s%]+\)|hsla?\(\s*[\d.,\s%]+\))$'
59
71
  )
@@ -466,7 +478,7 @@ class Network:
466
478
  n_id: Union[str, int],
467
479
  label: Optional[Union[str, int]] = None,
468
480
  shape: Optional[str] = None,
469
- color: str = '#97c2fc',
481
+ color: str = _DEFAULT_NODE_COLOR,
470
482
  options: Optional[Union[Dict[str, Any], Any]] = None,
471
483
  **kw_options: Any
472
484
  ) -> None:
@@ -620,9 +632,24 @@ class Network:
620
632
  # overrides the network-wide default; merge_font_color holds
621
633
  # the precedence rule shared with the typed path.
622
634
  node_font_color = kw_options.pop("font_color", None)
635
+ # group=None (e.g. group=d.get("group")) means "no group".
636
+ if "group" in kw_options and kw_options["group"] is None:
637
+ del kw_options["group"]
623
638
  if shape is None and "group" not in kw_options:
624
639
  shape = "dot"
625
640
  if "group" in kw_options:
641
+ # The default colour must not override the group's style,
642
+ # so colour is dropped for grouped nodes. An explicit one
643
+ # would be silently lost: say so.
644
+ if color is not None and color != _DEFAULT_NODE_COLOR:
645
+ warnings.warn(
646
+ f"add_node({n_id!r}): color={color!r} is ignored because the "
647
+ f"node is in group {kw_options['group']!r}; the group's style "
648
+ f"applies. Set the colour with set_group({kw_options['group']!r}, "
649
+ f"color=...) or drop the group.",
650
+ UserWarning,
651
+ stacklevel=2,
652
+ )
626
653
  n = Node(n_id, shape, label=node_label, font_color=node_font_color,
627
654
  network_font_color=self.font_color, **kw_options)
628
655
  else:
@@ -1241,6 +1268,8 @@ class Network:
1241
1268
  vis_css_cdn=vis_config.VIS_CSS_UNPKG,
1242
1269
  vis_js_cdn=vis_config.VIS_JS_UNPKG,
1243
1270
  vis_esm_cdn=vis_config.VIS_ESM_UNPKG,
1271
+ vis_js_sri=vis_config.VIS_JS_SRI,
1272
+ vis_css_sri=vis_config.VIS_CSS_SRI,
1244
1273
  legend=self.legend,
1245
1274
  groups=self.groups,
1246
1275
  highlight_degree=self.highlight_degree,
@@ -1351,7 +1380,14 @@ class Network:
1351
1380
  "show(notebook=True) needs IPython. "
1352
1381
  "Install with: pip install 'pyvis-optimized[notebook]'"
1353
1382
  ) from e
1354
- return IFrame(name, width=self.width, height=self.height)
1383
+ # IFrame writes width/height as HTML attributes, which cannot
1384
+ # express calc(); repeat them as CSS (it wins over attributes).
1385
+ # Re-checked here because the attributes are public and may have
1386
+ # been reassigned since the constructor validated them.
1387
+ extras = []
1388
+ if all(isinstance(v, str) and _CSS_DIM_RE.match(v) for v in (self.width, self.height)):
1389
+ extras.append(f'style="width: {self.width}; height: {self.height};"')
1390
+ return IFrame(name, width=self.width, height=self.height, extras=extras)
1355
1391
 
1356
1392
  def prep_notebook(self,
1357
1393
  custom_template=False, custom_template_path=None):
@@ -30,7 +30,7 @@ from pyvis.network import Network
30
30
 
31
31
  app_ui = ui.page_fluid(
32
32
  output_pyvis_network("my_network", height="600px"),
33
- ui.output_text_verbatim("selected")
33
+ ui.output_code("selected")
34
34
  )
35
35
 
36
36
  def server(input, output, session):
@@ -42,7 +42,7 @@ def server(input, output, session):
42
42
  net.add_edge(1, 2)
43
43
  return net
44
44
 
45
- @render.text
45
+ @render.code
46
46
  def selected():
47
47
  event = input.my_network_selectNode()
48
48
  if event: