graph_widget 0.1.5__tar.gz → 0.1.7__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.
- {graph_widget-0.1.5 → graph_widget-0.1.7}/PKG-INFO +1 -1
- {graph_widget-0.1.5 → graph_widget-0.1.7}/pyproject.toml +2 -2
- {graph_widget-0.1.5 → graph_widget-0.1.7}/src/graph_widget/static/widget.js +56 -27
- {graph_widget-0.1.5 → graph_widget-0.1.7}/uv.lock +1 -1
- {graph_widget-0.1.5 → graph_widget-0.1.7}/.gitignore +0 -0
- {graph_widget-0.1.5 → graph_widget-0.1.7}/.python-version +0 -0
- {graph_widget-0.1.5 → graph_widget-0.1.7}/README.md +0 -0
- {graph_widget-0.1.5 → graph_widget-0.1.7}/README_DEV.md +0 -0
- {graph_widget-0.1.5 → graph_widget-0.1.7}/bug_test.py +0 -0
- {graph_widget-0.1.5 → graph_widget-0.1.7}/data.json +0 -0
- {graph_widget-0.1.5 → graph_widget-0.1.7}/dev.py +0 -0
- {graph_widget-0.1.5 → graph_widget-0.1.7}/example_2.py +0 -0
- {graph_widget-0.1.5 → graph_widget-0.1.7}/multi_mst.json +0 -0
- {graph_widget-0.1.5 → graph_widget-0.1.7}/src/graph_widget/__init__.py +0 -0
- {graph_widget-0.1.5 → graph_widget-0.1.7}/src/graph_widget/dev.py +0 -0
- {graph_widget-0.1.5 → graph_widget-0.1.7}/src/graph_widget/static/widget.css +0 -0
- {graph_widget-0.1.5 → graph_widget-0.1.7}/vis-forge-marimo.py +0 -0
|
@@ -4,11 +4,11 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "graph_widget"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.7"
|
|
8
8
|
dependencies = ["anywidget","marimo"]
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
|
|
11
11
|
# Dependency groups (recognized by `uv`). For more details, visit:
|
|
12
12
|
# https://peps.python.org/pep-0735/
|
|
13
13
|
[dependency-groups]
|
|
14
|
-
dev = ["watchfiles"]
|
|
14
|
+
dev = ["watchfiles"]
|
|
@@ -39,22 +39,6 @@ const create_rtree = (data) => {
|
|
|
39
39
|
tree.load(data)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
function create_plot(el, width, height, data) {
|
|
43
|
-
return ForceGraph()(el)
|
|
44
|
-
.width(width)
|
|
45
|
-
.height(height)
|
|
46
|
-
.graphData(data)
|
|
47
|
-
// .d3Force('charge',forceManyBody().strength(-repulsion))
|
|
48
|
-
.cooldownTime(5000)
|
|
49
|
-
.warmupTicks(10)
|
|
50
|
-
.d3AlphaDecay(0.001)
|
|
51
|
-
.minZoom(0.001)
|
|
52
|
-
.onEngineStop(() => {
|
|
53
|
-
plot.zoomToFit(400);
|
|
54
|
-
create_rtree(data["nodes"]);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
42
|
const get_feature_type = (value) => {
|
|
59
43
|
if (typeof value === 'number') return 'numeric'; // Check for numeric
|
|
60
44
|
if (typeof value === 'string' && value.startsWith('#')) return 'hash_string'; // Check for strings starting with #
|
|
@@ -64,6 +48,23 @@ const get_feature_type = (value) => {
|
|
|
64
48
|
function render({ model, el }) {
|
|
65
49
|
const debouncedSaveChanges = debounce(() => model.save_changes(), 300);
|
|
66
50
|
|
|
51
|
+
const create_plot = (width, height, data) => {
|
|
52
|
+
return ForceGraph()(el)
|
|
53
|
+
.width(width)
|
|
54
|
+
.height(height)
|
|
55
|
+
.graphData(data)
|
|
56
|
+
// .d3Force('charge',forceManyBody().strength(-repulsion))
|
|
57
|
+
.cooldownTime(5000)
|
|
58
|
+
.warmupTicks(10)
|
|
59
|
+
.d3AlphaDecay(0.001)
|
|
60
|
+
.minZoom(0.001)
|
|
61
|
+
.nodeCanvasObjectMode(() => 'replace')
|
|
62
|
+
.onEngineStop(() => {
|
|
63
|
+
plot.zoomToFit(400);
|
|
64
|
+
create_rtree(data["nodes"]);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
67
68
|
const data = model.get("data");
|
|
68
69
|
repulsion = model.get("repulsion");
|
|
69
70
|
node_size = model.get("node_scale");
|
|
@@ -71,7 +72,7 @@ function render({ model, el }) {
|
|
|
71
72
|
colour_feature = model.get("colour_feature");
|
|
72
73
|
let global_selected_ids = model.get("selected_ids")
|
|
73
74
|
|
|
74
|
-
plot = create_plot(
|
|
75
|
+
plot = create_plot(width, height, data);
|
|
75
76
|
model.on("change:repulsion", () => {
|
|
76
77
|
repulsion = model.get("repulsion");
|
|
77
78
|
plot.d3Force('charge', forceManyBody().strength(-repulsion));
|
|
@@ -100,16 +101,44 @@ function render({ model, el }) {
|
|
|
100
101
|
colour_scale = undefined
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
if (colour_scale_type === "diverging") {
|
|
105
|
+
// Sort nodes by absolute distance from zero
|
|
106
|
+
data.nodes.sort((a, b) => {
|
|
107
|
+
const aVal = Math.abs(a[colour_feature]);
|
|
108
|
+
const bVal = Math.abs(b[colour_feature]);
|
|
109
|
+
return aVal - bVal;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
plot.nodeCanvasObject((node, ctx) => {
|
|
114
|
+
const radius = node_size * node_scale;
|
|
115
|
+
const isLocalSelected = local_selected_ids.includes(node.id);
|
|
116
|
+
const fillColour = colour_scale(node[colour_feature]);
|
|
117
|
+
|
|
118
|
+
// Draw filled circle
|
|
119
|
+
ctx.beginPath();
|
|
120
|
+
ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, false);
|
|
121
|
+
ctx.fillStyle = fillColour;
|
|
122
|
+
ctx.fill();
|
|
123
|
+
|
|
124
|
+
// Draw red stroke if node is locally selected
|
|
125
|
+
if (isLocalSelected) {
|
|
126
|
+
ctx.lineWidth = radius/5;
|
|
127
|
+
ctx.strokeStyle = 'red';
|
|
128
|
+
ctx.stroke();
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// plot.nodeColor((d) => {
|
|
133
|
+
// return global_selected_ids.includes(d.id)
|
|
134
|
+
// ? "yellow"
|
|
135
|
+
// : local_selected_ids.includes(d.id)
|
|
136
|
+
// ? "rgba(255,0,0,0.5)" // Red for local_selected_ids nodes
|
|
137
|
+
// : feature_type === undefined
|
|
138
|
+
// ? "#4682B480" // Default colour
|
|
139
|
+
// : feature_type === 'hash_string'
|
|
140
|
+
// ? d[colour_feature] // Use the hash string directly
|
|
141
|
+
// : colour_scale(d[colour_feature])})
|
|
113
142
|
});
|
|
114
143
|
model.on("change:colour_scale_type", () => {
|
|
115
144
|
colour_feature = model.get("colour_feature");
|
|
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
|