anywidget-graph 0.4.4__tar.gz → 0.4.6__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.
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/CHANGELOG.md +20 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/PKG-INFO +4 -1
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/README.md +3 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/pyproject.toml +1 -1
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/__init__.py +1 -1
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/__init__.py +7 -2
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/defaults.js +2 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/index.js +93 -7
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/lanes.js +48 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/widget.py +13 -7
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/tests/js/lanes.test.mjs +35 -1
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/tests/test_graph.py +27 -5
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/uv.lock +1 -1
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/.github/workflows/ci.yml +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/.github/workflows/grafeo-latest.yml +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/.github/workflows/pypi.yml +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/.gitignore +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/.python-version +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/LICENSE +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/assets/demo.png +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/examples/demo.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/examples/test_hierarchy.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/examples/test_large_graph.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/scripts/vendor/build.mjs +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/scripts/vendor/entry.mjs +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/scripts/vendor/package-lock.json +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/scripts/vendor/package.json +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/backends/__init__.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/backends/arango.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/backends/cosmosdb.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/backends/grafeo.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/backends/ladybug.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/backends/neo4j.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/converters/__init__.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/converters/base.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/converters/common.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/converters/cypher.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/converters/gql.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/converters/graphql.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/converters/gremlin.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/converters/sparql.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/demo.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/py.typed +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/grafeo-embed.js +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/grafeo-result.js +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/grafeo.js +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/icons.js +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/neo4j.js +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/properties.js +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/results.js +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/schema.js +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/settings.js +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/styles.css +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/toolbar.js +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/vendor/graph-libs.LICENSES.txt +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/vendor/graph-libs.min.js +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/tests/__init__.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/tests/conftest.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/tests/js/grafeo-result.test.mjs +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/tests/test_backends_grafeo.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/tests/test_demo.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/tests/test_grafeo_contract.py +0 -0
- {anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/tests/test_ui.py +0 -0
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.6 2026-10-20
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
- **Dimmed items read the same on a light and a dark canvas**: a selection dims the other nodes and edges by mixing their colour towards the canvas colour (opaque) instead of making it translucent. Sigma's blending does not treat a colour's alpha as transparency, so the old translucent dimming barely dimmed on a dark canvas and all but vanished on a light one
|
|
8
|
+
|
|
9
|
+
## 0.4.5 2026-10-20
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
- **Arrows**: `edge_arrows=True` draws every edge as an arrow from source to target (also in `to_html()`)
|
|
14
|
+
- **Self-loops**: an edge from a node to itself is drawn as a loop over the node's edge, nested when a node has several, with its label (`show_edge_labels`) and an arrowhead (`edge_arrows`); sigma drew such edges as nothing
|
|
15
|
+
- **Neighbour highlight**: with `highlight_neighbors=True` a selected node keeps its neighbours and their edges lit; everything else dims and loses its labels
|
|
16
|
+
- **`preset` layout**: `layout="preset"` keeps the positions the nodes bring (`x`, `y`), also after trying another layout from the toolbar, which then offers Preset to go back
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
- **Settings follow the model**: `show_edge_labels` and the new `edge_arrows` and `highlight_neighbors` apply when they change after the widget is drawn
|
|
21
|
+
- **`to_html()` and `save_html()` need no CDN**: the exported page carries the bundled graph libraries itself instead of loading graphology and sigma from esm.sh, so it opens offline and behind a network filter
|
|
22
|
+
|
|
3
23
|
## 0.4.4 2026-10-19
|
|
4
24
|
|
|
5
25
|
### Bug Fixes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: anywidget-graph
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.6
|
|
4
4
|
Summary: Interactive graph visualization for Python notebooks using anywidget
|
|
5
5
|
Project-URL: Homepage, https://grafeo.dev/
|
|
6
6
|
Project-URL: Repository, https://github.com/GrafeoDB/anywidget-graph
|
|
@@ -297,6 +297,7 @@ graph.edge_size_range = [1, 8]
|
|
|
297
297
|
Graph.from_dict(data, layout="force") # ForceAtlas2 (default)
|
|
298
298
|
Graph.from_dict(data, layout="circular")
|
|
299
299
|
Graph.from_dict(data, layout="random")
|
|
300
|
+
Graph(nodes=[{"id": "a", "x": 0, "y": 0}, {"id": "b", "x": 10, "y": 5}], layout="preset") # The nodes' own x and y
|
|
300
301
|
```
|
|
301
302
|
|
|
302
303
|
## Options
|
|
@@ -311,6 +312,8 @@ graph = Graph(
|
|
|
311
312
|
background="#fafafa", # Background color
|
|
312
313
|
show_labels=True, # Node labels
|
|
313
314
|
show_edge_labels=False, # Edge labels
|
|
315
|
+
edge_arrows=False, # Edges as arrows from source to target
|
|
316
|
+
highlight_neighbors=False, # A selected node keeps its neighbours and their edges lit
|
|
314
317
|
show_toolbar=True, # Toolbar visibility
|
|
315
318
|
show_settings=True, # Settings panel
|
|
316
319
|
show_query_input=True, # Query input box
|
|
@@ -254,6 +254,7 @@ graph.edge_size_range = [1, 8]
|
|
|
254
254
|
Graph.from_dict(data, layout="force") # ForceAtlas2 (default)
|
|
255
255
|
Graph.from_dict(data, layout="circular")
|
|
256
256
|
Graph.from_dict(data, layout="random")
|
|
257
|
+
Graph(nodes=[{"id": "a", "x": 0, "y": 0}, {"id": "b", "x": 10, "y": 5}], layout="preset") # The nodes' own x and y
|
|
257
258
|
```
|
|
258
259
|
|
|
259
260
|
## Options
|
|
@@ -268,6 +269,8 @@ graph = Graph(
|
|
|
268
269
|
background="#fafafa", # Background color
|
|
269
270
|
show_labels=True, # Node labels
|
|
270
271
|
show_edge_labels=False, # Edge labels
|
|
272
|
+
edge_arrows=False, # Edges as arrows from source to target
|
|
273
|
+
highlight_neighbors=False, # A selected node keeps its neighbours and their edges lit
|
|
271
274
|
show_toolbar=True, # Toolbar visibility
|
|
272
275
|
show_settings=True, # Settings panel
|
|
273
276
|
show_query_input=True, # Query input box
|
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
import re
|
|
6
6
|
from pathlib import Path
|
|
7
7
|
|
|
8
|
-
__all__ = ["get_css", "get_esm"]
|
|
8
|
+
__all__ = ["get_css", "get_esm", "get_vendor_js"]
|
|
9
9
|
|
|
10
10
|
_UI_DIR = Path(__file__).parent
|
|
11
11
|
|
|
@@ -91,6 +91,11 @@ def _resolve_schema_imports(code: str) -> str:
|
|
|
91
91
|
return _strip_imports_exports(code)
|
|
92
92
|
|
|
93
93
|
|
|
94
|
+
def get_vendor_js() -> str:
|
|
95
|
+
"""The bundled graph libraries (a script that sets the global ``anywidgetGraphVendor``)."""
|
|
96
|
+
return _read_file(_UI_DIR / "vendor" / "graph-libs.min.js")
|
|
97
|
+
|
|
98
|
+
|
|
94
99
|
def get_esm() -> str:
|
|
95
100
|
"""Get aggregated ESM JavaScript."""
|
|
96
101
|
defaults_js = _read_file(_UI_DIR / "defaults.js")
|
|
@@ -107,7 +112,7 @@ def get_esm() -> str:
|
|
|
107
112
|
toolbar_js = _read_file(_UI_DIR / "toolbar.js")
|
|
108
113
|
index_js = _read_file(_UI_DIR / "index.js")
|
|
109
114
|
|
|
110
|
-
vendor_js =
|
|
115
|
+
vendor_js = get_vendor_js()
|
|
111
116
|
|
|
112
117
|
return f"""\
|
|
113
118
|
// === Auto-generated ESM bundle for anywidget-graph ===
|
|
@@ -20,6 +20,7 @@ export const TRAIT_DEFAULTS = {
|
|
|
20
20
|
"connection_username": "",
|
|
21
21
|
"dark_mode": true,
|
|
22
22
|
"database_backend": "grafeo",
|
|
23
|
+
"edge_arrows": false,
|
|
23
24
|
"edge_color_field": null,
|
|
24
25
|
"edge_color_scale": "viridis",
|
|
25
26
|
"edge_size_field": null,
|
|
@@ -32,6 +33,7 @@ export const TRAIT_DEFAULTS = {
|
|
|
32
33
|
"grafeo_connection_mode": "embedded",
|
|
33
34
|
"grafeo_server_url": "http://localhost:7474",
|
|
34
35
|
"height": 600,
|
|
36
|
+
"highlight_neighbors": false,
|
|
35
37
|
"hovered_edge": null,
|
|
36
38
|
"hovered_node": null,
|
|
37
39
|
"lane_action": {},
|
|
@@ -12,7 +12,7 @@ import { createSchemaPanel } from "./schema.js";
|
|
|
12
12
|
import { createSettingsPanel } from "./settings.js";
|
|
13
13
|
import { createPropertiesPanel } from "./properties.js";
|
|
14
14
|
import { createResultsDrawer } from "./results.js";
|
|
15
|
-
import { laneOf, laneBands, lanesBBox, columnPositions, glyphHit, fitBox, LANE_HEIGHT, fitToBand, isCrossEdge, crossKey, placeAppended, hashUnit, curveControl, curveUntil, staggerSchedule, progress, pulseScale, themeVariables, withAlpha, labelColor, nextLaneAction, mergeItems, sameItems, extentBand, crossNeighbours, fitScale, LABEL_ROW, LABEL_COLUMN, laneIcon, applyBatchItems, edgeMatches, insetBand, seededRandom, clampInto, partnerHeights, laneSpacing, labelClear, laneSizeScale, rowOf, rowBands, bigBatch, colorFor, labelsThatFit, shortenLabel } from "./lanes.js";
|
|
15
|
+
import { laneOf, laneBands, lanesBBox, columnPositions, glyphHit, fitBox, LANE_HEIGHT, fitToBand, isCrossEdge, crossKey, placeAppended, hashUnit, curveControl, curveUntil, staggerSchedule, progress, pulseScale, themeVariables, withAlpha, labelColor, nextLaneAction, mergeItems, sameItems, extentBand, crossNeighbours, fitScale, LABEL_ROW, LABEL_COLUMN, laneIcon, applyBatchItems, edgeMatches, insetBand, seededRandom, clampInto, partnerHeights, laneSpacing, labelClear, laneSizeScale, rowOf, rowBands, bigBatch, colorFor, labelsThatFit, shortenLabel, neighbourhood, loopCircle, presetPositions, dimColor } from "./lanes.js";
|
|
16
16
|
import * as neo4jBackend from "./neo4j.js";
|
|
17
17
|
import * as grafeoBackend from "./grafeo.js";
|
|
18
18
|
import * as grafeoEmbedBackend from "./grafeo-embed.js";
|
|
@@ -337,11 +337,18 @@ function render({ model: host, el }) {
|
|
|
337
337
|
return false;
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
+
// The canvas colour that dimmed nodes and edges are mixed towards: read again when the theme changes, not per node
|
|
341
|
+
let canvasBackground = "";
|
|
342
|
+
function readCanvasBackground() {
|
|
343
|
+
canvasBackground = getComputedStyle(wrapper).getPropertyValue("--awg-bg").trim();
|
|
344
|
+
}
|
|
345
|
+
|
|
340
346
|
// Host theme: the host's colours win over the widget's light and dark defaults
|
|
341
347
|
function applyHostTheme() {
|
|
342
348
|
// A key the theme leaves out is "" and removes its variable: the widget's light or dark colour shows again
|
|
343
349
|
const variables = themeVariables(model.get("theme"));
|
|
344
350
|
for (const [name, value] of Object.entries(variables)) wrapper.style.setProperty(name, value);
|
|
351
|
+
readCanvasBackground();
|
|
345
352
|
rendererRef?.setSetting("labelColor", { color: labelColor(model.get("theme"), model.get("dark_mode")) });
|
|
346
353
|
rendererRef?.refresh();
|
|
347
354
|
}
|
|
@@ -350,6 +357,7 @@ function render({ model: host, el }) {
|
|
|
350
357
|
function updateTheme() {
|
|
351
358
|
const dark = model.get("dark_mode");
|
|
352
359
|
wrapper.classList.toggle("awg-dark", dark);
|
|
360
|
+
readCanvasBackground();
|
|
353
361
|
rendererRef?.setSetting("labelColor", { color: labelColor(model.get("theme"), dark) });
|
|
354
362
|
rendererRef?.refresh();
|
|
355
363
|
}
|
|
@@ -616,6 +624,13 @@ function render({ model: host, el }) {
|
|
|
616
624
|
});
|
|
617
625
|
|
|
618
626
|
switch (layoutName) {
|
|
627
|
+
case "preset": {
|
|
628
|
+
// The host placed the nodes: back to the positions they came with (also after another layout was tried)
|
|
629
|
+
for (const [id, at] of presetPositions(drawn.nodes.values())) {
|
|
630
|
+
if (graph.hasNode(id)) graph.mergeNodeAttributes(id, at);
|
|
631
|
+
}
|
|
632
|
+
break;
|
|
633
|
+
}
|
|
619
634
|
case "circular":
|
|
620
635
|
circular.assign(graph);
|
|
621
636
|
break;
|
|
@@ -1124,8 +1139,8 @@ function render({ model: host, el }) {
|
|
|
1124
1139
|
labelRenderedSizeThreshold: nodeCount > 200 ? 8 : nodeCount > 50 ? 5 : 2,
|
|
1125
1140
|
// Limit label density to reduce clutter on large graphs
|
|
1126
1141
|
labelDensity: nodeCount > 200 ? 0.5 : nodeCount > 50 ? 1 : 2,
|
|
1127
|
-
//
|
|
1128
|
-
defaultEdgeType: "line",
|
|
1142
|
+
// Plain lines, or arrows from source to target (edge_arrows)
|
|
1143
|
+
defaultEdgeType: model.get("edge_arrows") ? "arrow" : "line",
|
|
1129
1144
|
// Enable edge interaction events (click, hover)
|
|
1130
1145
|
enableEdgeEvents: true,
|
|
1131
1146
|
// A host may mount the widget in a hidden or not yet sized container (a closed panel, a tab)
|
|
@@ -1165,12 +1180,54 @@ function render({ model: host, el }) {
|
|
|
1165
1180
|
overlay.style.height = `${height}px`;
|
|
1166
1181
|
}
|
|
1167
1182
|
|
|
1183
|
+
// Edges from a node to itself (the edge reducer hides them from sigma and marks them `loop`): a circle over the
|
|
1184
|
+
// node's edge, nested when a node has several, with an arrowhead (edge_arrows) and the label (show_edge_labels)
|
|
1185
|
+
function drawLoops(ctx) {
|
|
1186
|
+
const perNode = new Map();
|
|
1187
|
+
const arrows = model.get("edge_arrows"), labels = model.get("show_edge_labels");
|
|
1188
|
+
graph.forEachEdge((edge, attrs, source, target) => {
|
|
1189
|
+
if (source !== target) return;
|
|
1190
|
+
const shown = renderer.getEdgeDisplayData(edge);
|
|
1191
|
+
const node = renderer.getNodeDisplayData(source);
|
|
1192
|
+
if (!shown?.loop || !node || node.hidden) return;
|
|
1193
|
+
const index = perNode.get(source) || 0;
|
|
1194
|
+
perNode.set(source, index + 1);
|
|
1195
|
+
const circle = loopCircle(renderer.framedGraphToViewport(node), renderer.scaleSize(node.size), index);
|
|
1196
|
+
const color = shown.color || "#94a3b8";
|
|
1197
|
+
ctx.strokeStyle = color;
|
|
1198
|
+
ctx.lineWidth = Math.min(4, Math.max(1, shown.size || 1));
|
|
1199
|
+
ctx.beginPath();
|
|
1200
|
+
ctx.arc(circle.x, circle.y, circle.r, 0, Math.PI * 2);
|
|
1201
|
+
ctx.stroke();
|
|
1202
|
+
if (arrows) {
|
|
1203
|
+
// The head where the loop comes back into the node (lower left of the circle), pointing along the loop
|
|
1204
|
+
const angle = Math.PI * 0.8, tip = { x: circle.x + circle.r * Math.cos(angle), y: circle.y + circle.r * Math.sin(angle) };
|
|
1205
|
+
const heading = angle + Math.PI / 2, size = 6 + ctx.lineWidth;
|
|
1206
|
+
ctx.fillStyle = color;
|
|
1207
|
+
ctx.beginPath();
|
|
1208
|
+
ctx.moveTo(tip.x, tip.y);
|
|
1209
|
+
ctx.lineTo(tip.x - size * Math.cos(heading - 0.45), tip.y - size * Math.sin(heading - 0.45));
|
|
1210
|
+
ctx.lineTo(tip.x - size * Math.cos(heading + 0.45), tip.y - size * Math.sin(heading + 0.45));
|
|
1211
|
+
ctx.closePath();
|
|
1212
|
+
ctx.fill();
|
|
1213
|
+
}
|
|
1214
|
+
if (labels && shown.label) {
|
|
1215
|
+
ctx.font = "500 11px system-ui, -apple-system, sans-serif";
|
|
1216
|
+
ctx.textAlign = "center";
|
|
1217
|
+
ctx.fillStyle = color;
|
|
1218
|
+
ctx.fillText(shown.label, circle.x, circle.y - circle.r - 4);
|
|
1219
|
+
ctx.textAlign = "left";
|
|
1220
|
+
}
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1168
1224
|
function drawOverlay() {
|
|
1169
1225
|
const ctx = overlay.getContext("2d");
|
|
1170
1226
|
if (!ctx) return;
|
|
1171
1227
|
const dpr = window.devicePixelRatio || 1;
|
|
1172
1228
|
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
1173
1229
|
ctx.clearRect(0, 0, overlay.width / dpr, overlay.height / dpr);
|
|
1230
|
+
drawLoops(ctx);
|
|
1174
1231
|
if (!laneState.lanes.length) return;
|
|
1175
1232
|
// The widget's own colours: its light or dark defaults, or the host theme (applyHostTheme sets these variables)
|
|
1176
1233
|
const css = getComputedStyle(wrapper);
|
|
@@ -1388,6 +1445,17 @@ function render({ model: host, el }) {
|
|
|
1388
1445
|
requestAnimationFrame(animate);
|
|
1389
1446
|
}
|
|
1390
1447
|
|
|
1448
|
+
// The nodes a selection keeps lit (highlight_neighbors, one selected node): worked out once per selection, not per node
|
|
1449
|
+
const NOTHING_LIT = new Set();
|
|
1450
|
+
let lit = { selected: null, edges: null, nodes: NOTHING_LIT };
|
|
1451
|
+
function litNodes(selectedNodes) {
|
|
1452
|
+
if (!model.get("highlight_neighbors") || selectedNodes.length !== 1) return NOTHING_LIT;
|
|
1453
|
+
if (lit.selected !== selectedNodes[0] || lit.edges !== drawn.edges) {
|
|
1454
|
+
lit = { selected: selectedNodes[0], edges: drawn.edges, nodes: neighbourhood(drawn.edges, selectedNodes[0]) };
|
|
1455
|
+
}
|
|
1456
|
+
return lit.nodes;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1391
1459
|
// Node reducer for type filtering, search filtering, selection, and pinned indicator
|
|
1392
1460
|
renderer.setSetting("nodeReducer", (node, data) => {
|
|
1393
1461
|
const selectedNodes = model.get("selected_nodes") || [];
|
|
@@ -1411,9 +1479,9 @@ function render({ model: host, el }) {
|
|
|
1411
1479
|
res.color = data.color + "80";
|
|
1412
1480
|
}
|
|
1413
1481
|
|
|
1414
|
-
// Dim unselected nodes when there is an active selection
|
|
1415
|
-
if (selectedNodes.length > 0 && !selectedNodes.includes(node)) {
|
|
1416
|
-
res.color = (res.color || data.color)
|
|
1482
|
+
// Dim unselected nodes when there is an active selection (with highlight_neighbors not its neighbours)
|
|
1483
|
+
if (selectedNodes.length > 0 && !selectedNodes.includes(node) && !litNodes(selectedNodes).has(node)) {
|
|
1484
|
+
res.color = dimColor(res.color || data.color, canvasBackground);
|
|
1417
1485
|
res.label = "";
|
|
1418
1486
|
}
|
|
1419
1487
|
|
|
@@ -1513,6 +1581,19 @@ function render({ model: host, el }) {
|
|
|
1513
1581
|
}
|
|
1514
1582
|
}
|
|
1515
1583
|
|
|
1584
|
+
// With highlight_neighbors a selected node's own edges stay lit, the others dim and lose their labels (as dimmed nodes do)
|
|
1585
|
+
const selected = model.get("selected_nodes") || [];
|
|
1586
|
+
const [from, to] = graph.extremities(edge);
|
|
1587
|
+
if (!res.hidden && model.get("highlight_neighbors") && selected.length === 1 && from !== selected[0] && to !== selected[0]) {
|
|
1588
|
+
res.color = dimColor(res.color || data.color, canvasBackground);
|
|
1589
|
+
res.label = "";
|
|
1590
|
+
}
|
|
1591
|
+
// Sigma draws an edge from a node to itself as nothing: the overlay draws it as a loop (drawLoops)
|
|
1592
|
+
if (!res.hidden && from === to) {
|
|
1593
|
+
res.hidden = true;
|
|
1594
|
+
res.loop = true;
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1516
1597
|
return res;
|
|
1517
1598
|
});
|
|
1518
1599
|
|
|
@@ -1786,7 +1867,9 @@ function render({ model: host, el }) {
|
|
|
1786
1867
|
const layoutSelect = document.createElement("select");
|
|
1787
1868
|
layoutSelect.className = "awg-layout-select";
|
|
1788
1869
|
layoutSelect.title = "Layout algorithm";
|
|
1789
|
-
|
|
1870
|
+
// The host's own positions (layout "preset") stay one choice away after trying another layout
|
|
1871
|
+
const presetChoice = model.get("layout") === "preset" ? [["preset", "Preset"]] : [];
|
|
1872
|
+
[...presetChoice, ["spring", "Default"], ["force", "Force"], ["cluster", "Cluster"], ["circular", "Circular"], ["random", "Random"]].forEach(([val, text]) => {
|
|
1790
1873
|
const opt = document.createElement("option");
|
|
1791
1874
|
opt.value = val;
|
|
1792
1875
|
opt.textContent = text;
|
|
@@ -2239,6 +2322,9 @@ function render({ model: host, el }) {
|
|
|
2239
2322
|
|
|
2240
2323
|
// Layout change handler
|
|
2241
2324
|
model.on("change:layout", refreshLayout);
|
|
2325
|
+
model.on("change:edge_arrows", () => renderer.setSetting("defaultEdgeType", model.get("edge_arrows") ? "arrow" : "line"));
|
|
2326
|
+
model.on("change:show_edge_labels", () => renderer.setSetting("renderEdgeLabels", model.get("show_edge_labels")));
|
|
2327
|
+
model.on("change:highlight_neighbors", () => renderer.refresh());
|
|
2242
2328
|
|
|
2243
2329
|
// === Demo Mode: auto-init WASM and populate data ===
|
|
2244
2330
|
if (model.get("_demo_mode")) {
|
|
@@ -586,3 +586,51 @@ export function withAlpha(hex, alpha) {
|
|
|
586
586
|
const [r, g, b] = match.slice(1).map((part) => parseInt(part, 16));
|
|
587
587
|
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
588
588
|
}
|
|
589
|
+
|
|
590
|
+
// A node and every node it shares an edge with (either direction); empty without a node
|
|
591
|
+
export function neighbourhood(edges, id) {
|
|
592
|
+
if (id === null || id === undefined) return new Set();
|
|
593
|
+
const near = new Set([id]);
|
|
594
|
+
for (const edge of edges) {
|
|
595
|
+
if (edge.source === id) near.add(edge.target);
|
|
596
|
+
if (edge.target === id) near.add(edge.source);
|
|
597
|
+
}
|
|
598
|
+
return near;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// The circle a self-loop is drawn as (viewport pixels): over the node's upper right edge, each further loop of the
|
|
602
|
+
// node a little wider, so they nest instead of overlapping
|
|
603
|
+
export function loopCircle(center, radius, index) {
|
|
604
|
+
const r = Math.max(7, radius * 0.7) + index * 5;
|
|
605
|
+
const reach = (radius + r * 0.4) * Math.SQRT1_2;
|
|
606
|
+
return { x: center.x + reach, y: center.y - reach, r };
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// The `preset` layout: the positions the nodes bring (numeric x and y); the others keep theirs
|
|
610
|
+
export function presetPositions(nodes) {
|
|
611
|
+
const positions = new Map();
|
|
612
|
+
for (const node of nodes) {
|
|
613
|
+
if (typeof node.x === "number" && typeof node.y === "number" && Number.isFinite(node.x) && Number.isFinite(node.y)) {
|
|
614
|
+
positions.set(node.id, { x: node.x, y: node.y });
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
return positions;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// A colour as [r, g, b]: #rrggbb (an #rrggbbaa's alpha is dropped) or rgb()/rgba(); null for anything else
|
|
621
|
+
function rgbOf(color) {
|
|
622
|
+
const hex = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i.exec(color || "");
|
|
623
|
+
if (hex) return hex.slice(1, 4).map((part) => parseInt(part, 16));
|
|
624
|
+
const rgb = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i.exec(color || "");
|
|
625
|
+
return rgb ? rgb.slice(1, 4).map(Number) : null;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// A dimmed node or edge (an active selection): its colour mixed most of the way towards the canvas, opaque. Sigma's
|
|
629
|
+
// blending does not treat a colour's alpha as transparency (a translucent colour stays bright on a dark canvas and
|
|
630
|
+
// all but vanishes on a light one), so an opaque mix is what reads the same on both.
|
|
631
|
+
const DIM_MIX = 0.65;
|
|
632
|
+
export function dimColor(color, background) {
|
|
633
|
+
const [from, to] = [rgbOf(color), rgbOf(background)];
|
|
634
|
+
if (!from || !to) return color;
|
|
635
|
+
return `#${from.map((v, i) => Math.round(v + (to[i] - v) * DIM_MIX).toString(16).padStart(2, "0")).join("")}`;
|
|
636
|
+
}
|
|
@@ -12,7 +12,7 @@ from traitlets import observe
|
|
|
12
12
|
|
|
13
13
|
from anywidget_graph.backends import DatabaseBackend
|
|
14
14
|
from anywidget_graph.backends.grafeo import GrafeoBackend
|
|
15
|
-
from anywidget_graph.ui import get_css, get_esm
|
|
15
|
+
from anywidget_graph.ui import get_css, get_esm, get_vendor_js
|
|
16
16
|
|
|
17
17
|
if TYPE_CHECKING:
|
|
18
18
|
from collections.abc import Callable
|
|
@@ -63,6 +63,10 @@ class Graph(anywidget.AnyWidget):
|
|
|
63
63
|
background = traitlets.Unicode(default_value="#fafafa").tag(sync=True)
|
|
64
64
|
show_labels = traitlets.Bool(default_value=True).tag(sync=True)
|
|
65
65
|
show_edge_labels = traitlets.Bool(default_value=False).tag(sync=True)
|
|
66
|
+
# Draw edges as arrows (source to target); self-loops are drawn as loops either way
|
|
67
|
+
edge_arrows = traitlets.Bool(default_value=False).tag(sync=True)
|
|
68
|
+
# A selected node keeps its neighbours and their edges lit; everything else dims
|
|
69
|
+
highlight_neighbors = traitlets.Bool(default_value=False).tag(sync=True)
|
|
66
70
|
|
|
67
71
|
# === Property-Based Styling (node) ===
|
|
68
72
|
color_field = traitlets.Unicode(allow_none=True, default_value=None).tag(sync=True)
|
|
@@ -78,6 +82,7 @@ class Graph(anywidget.AnyWidget):
|
|
|
78
82
|
edge_size_range = traitlets.List(default_value=[1, 8]).tag(sync=True)
|
|
79
83
|
|
|
80
84
|
# === Layout ===
|
|
85
|
+
# spring, force, cluster, circular, random, or preset (the nodes' own x and y)
|
|
81
86
|
layout = traitlets.Unicode(default_value="spring").tag(sync=True)
|
|
82
87
|
|
|
83
88
|
# === Hover / Tooltip ===
|
|
@@ -859,11 +864,9 @@ body {{ margin: 0; background: {background}; font-family: sans-serif; }}
|
|
|
859
864
|
<div id="container"></div>
|
|
860
865
|
<div id="tooltip" class="tooltip"></div>
|
|
861
866
|
<script type="module">
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
import random from "https://esm.sh/graphology-layout@0.6.1/random.js";
|
|
866
|
-
import forceAtlas2 from "https://esm.sh/graphology-layout-forceatlas2@0.10.1";
|
|
867
|
+
// graphology, sigma and the layouts are inlined (the widget's bundled libraries): the page needs no CDN
|
|
868
|
+
{vendor_js}
|
|
869
|
+
const {{ Graph, Sigma, circular, random, forceAtlas2 }} = anywidgetGraphVendor;
|
|
867
870
|
|
|
868
871
|
const DATA = {json_data};
|
|
869
872
|
const OPTIONS = {json_options};
|
|
@@ -1047,6 +1050,7 @@ const renderer = new Sigma(graph, container, {{
|
|
|
1047
1050
|
labelColor: {{ color: OPTIONS.dark_mode ? "#ccc" : "#333" }},
|
|
1048
1051
|
labelSize: 12,
|
|
1049
1052
|
labelWeight: "500",
|
|
1053
|
+
defaultEdgeType: OPTIONS.edge_arrows ? "arrow" : "line",
|
|
1050
1054
|
}});
|
|
1051
1055
|
|
|
1052
1056
|
// --- Tooltip ---
|
|
@@ -1108,7 +1112,7 @@ renderer.on("leaveEdge", () => {{
|
|
|
1108
1112
|
) -> str:
|
|
1109
1113
|
"""Export the current graph as a self-contained HTML string.
|
|
1110
1114
|
|
|
1111
|
-
The resulting HTML
|
|
1115
|
+
The resulting HTML carries Graphology and Sigma.js itself (no CDN, so it opens offline),
|
|
1112
1116
|
embeds all current node/edge data plus visual settings, and renders the
|
|
1113
1117
|
graph with layout, color/size mapping, labels, zoom/pan, and tooltips.
|
|
1114
1118
|
|
|
@@ -1131,6 +1135,7 @@ renderer.on("leaveEdge", () => {{
|
|
|
1131
1135
|
"background": self.background,
|
|
1132
1136
|
"show_labels": self.show_labels,
|
|
1133
1137
|
"show_edge_labels": self.show_edge_labels,
|
|
1138
|
+
"edge_arrows": self.edge_arrows,
|
|
1134
1139
|
"dark_mode": self.dark_mode,
|
|
1135
1140
|
"color_field": self.color_field,
|
|
1136
1141
|
"color_scale": self.color_scale,
|
|
@@ -1150,6 +1155,7 @@ renderer.on("leaveEdge", () => {{
|
|
|
1150
1155
|
height=height,
|
|
1151
1156
|
json_data=json.dumps(data),
|
|
1152
1157
|
json_options=json.dumps(options),
|
|
1158
|
+
vendor_js=get_vendor_js(),
|
|
1153
1159
|
)
|
|
1154
1160
|
|
|
1155
1161
|
def save_html(self, path: str, **kwargs: Any) -> None:
|
|
@@ -9,9 +9,32 @@ import {
|
|
|
9
9
|
sameItems, extentBand, crossNeighbours, laneIcon, removeItems, edgeMatches, applyBatchItems,
|
|
10
10
|
withTotals, shownOf, totalShown, nodeType, edgeType, insetBand,
|
|
11
11
|
seededRandom, clampInto, partnerHeights, laneSpacing, labelClear, laneSizeScale, rowOf, rowBands, bigBatch,
|
|
12
|
-
colorFor, labelsThatFit, shortenLabel,
|
|
12
|
+
colorFor, labelsThatFit, shortenLabel, neighbourhood, loopCircle, presetPositions, dimColor,
|
|
13
13
|
} from "../../src/anywidget_graph/ui/lanes.js";
|
|
14
14
|
|
|
15
|
+
test("a node's neighbourhood holds the node and every node it shares an edge with, either way", () => {
|
|
16
|
+
const edges = [{ source: "a", target: "b" }, { source: "c", target: "a" }, { source: "b", target: "d" }, { source: "a", target: "a" }];
|
|
17
|
+
assert.deepEqual([...neighbourhood(edges, "a")].sort(), ["a", "b", "c"]);
|
|
18
|
+
assert.deepEqual([...neighbourhood(edges, "d")].sort(), ["b", "d"]);
|
|
19
|
+
assert.deepEqual([...neighbourhood(edges, "z")], ["z"]);
|
|
20
|
+
assert.equal(neighbourhood(edges, null).size, 0);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("a self-loop is a circle over the node's upper right edge; a node's next loop is wider", () => {
|
|
24
|
+
const center = { x: 100, y: 100 }, radius = 10;
|
|
25
|
+
const first = loopCircle(center, radius, 0), second = loopCircle(center, radius, 1);
|
|
26
|
+
const distance = Math.hypot(first.x - center.x, first.y - center.y);
|
|
27
|
+
assert.ok(first.x > center.x && first.y < center.y, "up and to the right");
|
|
28
|
+
assert.ok(distance < radius + first.r && distance > radius - first.r, "the loop crosses the node's edge");
|
|
29
|
+
assert.ok(second.r > first.r);
|
|
30
|
+
assert.ok(loopCircle(center, 1, 0).r >= 7, "a tiny node still gets a visible loop");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("preset positions are the nodes' own numeric x and y", () => {
|
|
34
|
+
const positions = presetPositions([{ id: "a", x: 1, y: 2 }, { id: "b", x: "3", y: 4 }, { id: "c" }, { id: "d", x: 0, y: Number.NaN }, { id: "e", x: 0, y: 0 }]);
|
|
35
|
+
assert.deepEqual([...positions], [["a", { x: 1, y: 2 }], ["e", { x: 0, y: 0 }]]);
|
|
36
|
+
});
|
|
37
|
+
|
|
15
38
|
const LANES = [{ id: "intermediate", title: "Intermediate graph" }, { id: "output", title: "Output graph" }];
|
|
16
39
|
|
|
17
40
|
test("a node without a known lane goes to the first lane", () => {
|
|
@@ -466,3 +489,14 @@ test("an empty canvas keeps sigma's stage padding, so the lanes don't move when
|
|
|
466
489
|
// A container without a size yet maps everything to its corner instead of NaN
|
|
467
490
|
assert.deepEqual(fitBox({ x: [0, 2000], y: [0, 1000] }, 0, 0, 30)({ x: 1000, y: 500 }), { x: 0, y: 0 });
|
|
468
491
|
});
|
|
492
|
+
|
|
493
|
+
test("a dimmed item is its colour mixed towards the canvas, opaque, so it reads the same on a light and a dark canvas", () => {
|
|
494
|
+
// Sigma's blending does not treat a colour's alpha as transparency: an opaque mix looks alike on every background
|
|
495
|
+
assert.equal(dimColor("#7d6be0", "#ffffff"), "#d2cbf4");
|
|
496
|
+
assert.equal(dimColor("#7d6be0", "#15171c"), "#393461");
|
|
497
|
+
assert.equal(dimColor("#8c93a0", "rgb(255, 255, 255)"), "#d7d9de");
|
|
498
|
+
// A colour with an alpha is mixed from its base colour; a colour or canvas that is not hex or rgb stays as it is
|
|
499
|
+
assert.equal(dimColor("#7d6be080", "#ffffff"), "#d2cbf4");
|
|
500
|
+
assert.equal(dimColor("steelblue", "#ffffff"), "steelblue");
|
|
501
|
+
assert.equal(dimColor("#7d6be0", "var(--x)"), "#7d6be0");
|
|
502
|
+
});
|
|
@@ -404,10 +404,32 @@ def test_to_html_contains_expected_structure():
|
|
|
404
404
|
assert "<title>Graph Visualization</title>" in html
|
|
405
405
|
assert 'id="container"' in html
|
|
406
406
|
assert 'id="tooltip"' in html
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
def test_graph_arrows_and_neighbour_highlight_are_off_by_default():
|
|
410
|
+
"""Edges stay plain lines and a selection dims everything else, as before, until a host asks."""
|
|
411
|
+
graph = Graph()
|
|
412
|
+
assert graph.edge_arrows is False
|
|
413
|
+
assert graph.highlight_neighbors is False
|
|
414
|
+
assert Graph(edge_arrows=True, highlight_neighbors=True, layout="preset").edge_arrows is True
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
def test_to_html_draws_arrows_when_asked():
|
|
418
|
+
"""The exported page draws arrowheads for a graph with edge_arrows, and plain lines otherwise."""
|
|
419
|
+
edges = [{"source": "a", "target": "b"}]
|
|
420
|
+
nodes = [{"id": "a"}, {"id": "b"}]
|
|
421
|
+
assert '"edge_arrows": true' in Graph(nodes=nodes, edges=edges, edge_arrows=True).to_html()
|
|
422
|
+
assert '"edge_arrows": false' in Graph(nodes=nodes, edges=edges).to_html()
|
|
423
|
+
assert 'OPTIONS.edge_arrows ? "arrow" : "line"' in Graph(nodes=nodes, edges=edges).to_html()
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
def test_to_html_needs_no_cdn():
|
|
427
|
+
"""The exported page carries the graph libraries itself, so it opens offline."""
|
|
428
|
+
html = Graph(nodes=[{"id": "n1"}], edges=[]).to_html()
|
|
429
|
+
assert "https://" not in html.split("<script", 1)[1]
|
|
430
|
+
assert "anywidgetGraphVendor" in html
|
|
431
|
+
# The inlined libraries do not end the script early
|
|
432
|
+
assert html.count("<script") == html.count("</script>") == 1
|
|
411
433
|
|
|
412
434
|
|
|
413
435
|
def test_to_html_embeds_node_data():
|
|
@@ -499,7 +521,7 @@ def test_save_html(tmp_path):
|
|
|
499
521
|
assert out.exists()
|
|
500
522
|
content = out.read_text(encoding="utf-8")
|
|
501
523
|
assert "<title>Saved Graph</title>" in content
|
|
502
|
-
assert "
|
|
524
|
+
assert "anywidgetGraphVendor" in content # the graph libraries are inlined
|
|
503
525
|
|
|
504
526
|
|
|
505
527
|
# ------------------------------------------------------------------ #
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{anywidget_graph-0.4.4 → anywidget_graph-0.4.6}/src/anywidget_graph/ui/vendor/graph-libs.min.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|