graph_widget 0.1.12__tar.gz → 0.1.14__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.12 → graph_widget-0.1.14}/PKG-INFO +1 -1
- {graph_widget-0.1.12 → graph_widget-0.1.14}/example_2.py +24 -9
- {graph_widget-0.1.12 → graph_widget-0.1.14}/pyproject.toml +1 -1
- {graph_widget-0.1.12 → graph_widget-0.1.14}/src/graph_widget/__init__.py +2 -1
- {graph_widget-0.1.12 → graph_widget-0.1.14}/src/graph_widget/static/widget.js +72 -88
- {graph_widget-0.1.12 → graph_widget-0.1.14}/uv.lock +1 -1
- graph_widget-0.1.12/vis-forge-marimo.py +0 -0
- {graph_widget-0.1.12 → graph_widget-0.1.14}/.gitignore +0 -0
- {graph_widget-0.1.12 → graph_widget-0.1.14}/.python-version +0 -0
- {graph_widget-0.1.12 → graph_widget-0.1.14}/README.md +0 -0
- {graph_widget-0.1.12 → graph_widget-0.1.14}/README_DEV.md +0 -0
- {graph_widget-0.1.12 → graph_widget-0.1.14}/bug_test.py +0 -0
- {graph_widget-0.1.12 → graph_widget-0.1.14}/data.json +0 -0
- {graph_widget-0.1.12 → graph_widget-0.1.14}/dev.py +0 -0
- {graph_widget-0.1.12 → graph_widget-0.1.14}/graph_3d_example.py +0 -0
- {graph_widget-0.1.12 → graph_widget-0.1.14}/multi_mst.json +0 -0
- {graph_widget-0.1.12 → graph_widget-0.1.14}/src/graph_widget/dev.py +0 -0
- {graph_widget-0.1.12 → graph_widget-0.1.14}/src/graph_widget/static/widget.css +0 -0
|
@@ -14,11 +14,11 @@ def _():
|
|
|
14
14
|
@app.cell
|
|
15
15
|
def _():
|
|
16
16
|
data = {'nodes':
|
|
17
|
-
[{"id": 1, "kind": "sample", "value":
|
|
18
|
-
{"id": 2, "kind": "sample", "value":
|
|
19
|
-
{"id": 3, "kind": "OTU", "degree": 3, "value": 23},
|
|
20
|
-
{"id": 4, "kind": "OTU", "degree": 2, "value": 1},
|
|
21
|
-
{"id": 5, "kind": "OTU", "degree": 3, "value": 17}],
|
|
17
|
+
[{"id": 1, "kind": "sample", "value": 15, "label": "node 1", "size_value": 4},
|
|
18
|
+
{"id": 2, "kind": "sample", "value": 1, "label": "node 2", "size_value": 6},
|
|
19
|
+
{"id": 3, "kind": "OTU", "degree": 3, "value": 23, "label": "node 3", "size_value": 2},
|
|
20
|
+
{"id": 4, "kind": "OTU", "degree": 2, "value": 1, "label": "node 4", "size_value": 8},
|
|
21
|
+
{"id": 5, "kind": "OTU", "degree": 3, "value": 17, "size_value": 6}],
|
|
22
22
|
"links": [
|
|
23
23
|
{"source": 1, "target": 3},
|
|
24
24
|
{"source": 1, "target": 4},
|
|
@@ -32,22 +32,32 @@ def _():
|
|
|
32
32
|
return (data,)
|
|
33
33
|
|
|
34
34
|
|
|
35
|
+
@app.cell
|
|
36
|
+
def _(data):
|
|
37
|
+
data["nodes"][3].keys()
|
|
38
|
+
return
|
|
39
|
+
|
|
40
|
+
|
|
35
41
|
@app.cell
|
|
36
42
|
def _(data, mo):
|
|
37
43
|
repulsion_slider = mo.ui.slider(
|
|
38
44
|
start=-100, stop=500, step=10, value=1, debounce=False, label="Repulsion"
|
|
39
45
|
)
|
|
40
46
|
node_scale_slider = mo.ui.slider(
|
|
41
|
-
start=1, stop=
|
|
47
|
+
start=0.1, stop=5, step=0.1, value=3, debounce=True, label="Node scale"
|
|
42
48
|
)
|
|
43
49
|
colour_feature_dropdown = mo.ui.dropdown(
|
|
44
|
-
options=list(data["nodes"][3].keys()), label="Colour by"
|
|
50
|
+
options=list(data["nodes"][3].keys()), value="kind", label="Colour by"
|
|
51
|
+
)
|
|
52
|
+
node_size_feature_dropdown = mo.ui.dropdown(
|
|
53
|
+
options=["","value","size_value"], value="", label="Node size feature"
|
|
45
54
|
)
|
|
46
55
|
colour_scale_type_radio = mo.ui.radio(options=["diverging", "sequential"], value="diverging", label="Colour scale type")
|
|
47
56
|
return (
|
|
48
57
|
colour_feature_dropdown,
|
|
49
58
|
colour_scale_type_radio,
|
|
50
59
|
node_scale_slider,
|
|
60
|
+
node_size_feature_dropdown,
|
|
51
61
|
repulsion_slider,
|
|
52
62
|
)
|
|
53
63
|
|
|
@@ -59,9 +69,10 @@ def _(data, graph_widget, mo):
|
|
|
59
69
|
data=data,
|
|
60
70
|
repulsion=2,
|
|
61
71
|
node_scale=2,
|
|
72
|
+
# node_size_feature="size_value",
|
|
62
73
|
colour_feature="",
|
|
63
74
|
colour_scale_type="",
|
|
64
|
-
height=
|
|
75
|
+
height=400,
|
|
65
76
|
width=600
|
|
66
77
|
)
|
|
67
78
|
)
|
|
@@ -74,12 +85,14 @@ def _(
|
|
|
74
85
|
colour_scale_type_radio,
|
|
75
86
|
data_graph,
|
|
76
87
|
node_scale_slider,
|
|
88
|
+
node_size_feature_dropdown,
|
|
77
89
|
repulsion_slider,
|
|
78
90
|
):
|
|
79
91
|
data_graph.widget.repulsion = repulsion_slider.value
|
|
80
92
|
data_graph.widget.node_scale = node_scale_slider.value
|
|
81
93
|
data_graph.widget.colour_feature = colour_feature_dropdown.value
|
|
82
94
|
data_graph.widget.colour_scale_type= colour_scale_type_radio.value
|
|
95
|
+
data_graph.widget.node_size_feature = node_size_feature_dropdown.value
|
|
83
96
|
return
|
|
84
97
|
|
|
85
98
|
|
|
@@ -90,6 +103,7 @@ def _(
|
|
|
90
103
|
data_graph,
|
|
91
104
|
mo,
|
|
92
105
|
node_scale_slider,
|
|
106
|
+
node_size_feature_dropdown,
|
|
93
107
|
repulsion_slider,
|
|
94
108
|
):
|
|
95
109
|
plot = mo.hstack([data_graph,
|
|
@@ -97,7 +111,8 @@ def _(
|
|
|
97
111
|
repulsion_slider,
|
|
98
112
|
node_scale_slider,
|
|
99
113
|
colour_feature_dropdown,
|
|
100
|
-
colour_scale_type_radio
|
|
114
|
+
colour_scale_type_radio,
|
|
115
|
+
node_size_feature_dropdown])], justify="start")
|
|
101
116
|
return (plot,)
|
|
102
117
|
|
|
103
118
|
|
|
@@ -16,7 +16,8 @@ class ForceGraphWidget(anywidget.AnyWidget):
|
|
|
16
16
|
_css = files("graph_widget").joinpath("static/widget.css")
|
|
17
17
|
data = traitlets.Dict().tag(sync=True)
|
|
18
18
|
repulsion = traitlets.Int().tag(sync=True)
|
|
19
|
-
node_scale = traitlets.
|
|
19
|
+
node_scale = traitlets.Float().tag(sync=True)
|
|
20
|
+
node_size_feature = traitlets.Unicode().tag(sync=True)
|
|
20
21
|
colour_feature = traitlets.Unicode().tag(sync=True)
|
|
21
22
|
colour_scale_type = traitlets.Unicode().tag(sync=True)
|
|
22
23
|
selected_ids = traitlets.List([]).tag(sync=True)
|
|
@@ -19,12 +19,12 @@ class MyRBush extends RBush {
|
|
|
19
19
|
let local_selected_ids = []
|
|
20
20
|
let default_repulsion = 1;
|
|
21
21
|
let default_node_scale = 1;
|
|
22
|
-
let node_scale = 1;
|
|
23
22
|
let colour_scale_type = "";
|
|
24
23
|
let plot;
|
|
25
24
|
let tree;
|
|
26
|
-
let
|
|
25
|
+
let default_node_size = 5;
|
|
27
26
|
let colour_feature = undefined;
|
|
27
|
+
let node_size_feature = undefined;
|
|
28
28
|
let colour_scale;
|
|
29
29
|
|
|
30
30
|
function debounce(func, wait) {
|
|
@@ -52,6 +52,39 @@ const isMac = ua.includes('macintosh');
|
|
|
52
52
|
const isWindows = ua.includes('windows');
|
|
53
53
|
const isLinux = ua.includes('linux');
|
|
54
54
|
|
|
55
|
+
const create_node_canvas_object = (plot, node_scale, node_size_feature) => {
|
|
56
|
+
return plot.nodeCanvasObject((node, ctx) => {
|
|
57
|
+
console.log(node_size_feature)
|
|
58
|
+
let radius;
|
|
59
|
+
|
|
60
|
+
if ( node_size_feature == undefined || node_size_feature == "") {
|
|
61
|
+
radius = default_node_size * node_scale
|
|
62
|
+
} else {
|
|
63
|
+
radius = node[node_size_feature] * node_scale
|
|
64
|
+
}
|
|
65
|
+
const isLocalSelected = local_selected_ids.includes(node.id);
|
|
66
|
+
const fillColour = colour_scale(node[colour_feature]);
|
|
67
|
+
// const radius = node[node_size_feature] * node_scale;
|
|
68
|
+
|
|
69
|
+
// Draw filled circle
|
|
70
|
+
ctx.beginPath();
|
|
71
|
+
ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, false);
|
|
72
|
+
ctx.fillStyle = fillColour;
|
|
73
|
+
ctx.fill();
|
|
74
|
+
|
|
75
|
+
// Draw red stroke if node is locally selected
|
|
76
|
+
if (isLocalSelected) {
|
|
77
|
+
ctx.lineWidth = radius/5;
|
|
78
|
+
ctx.strokeStyle = 'red';
|
|
79
|
+
ctx.stroke();
|
|
80
|
+
} else {
|
|
81
|
+
ctx.lineWidth = radius/10;
|
|
82
|
+
ctx.strokeStyle = 'lightgrey';
|
|
83
|
+
ctx.stroke();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
|
|
55
88
|
function render({ model, el }) {
|
|
56
89
|
const debouncedSaveChanges = debounce(() => model.save_changes(), 300);
|
|
57
90
|
|
|
@@ -63,6 +96,7 @@ function render({ model, el }) {
|
|
|
63
96
|
// .d3Force('charge',forceManyBody().strength(-repulsion))
|
|
64
97
|
.cooldownTime(5000)
|
|
65
98
|
.warmupTicks(10)
|
|
99
|
+
.nodeLabel('label')
|
|
66
100
|
.d3AlphaDecay(0.001)
|
|
67
101
|
.minZoom(0.001)
|
|
68
102
|
.nodeCanvasObjectMode(() => 'replace')
|
|
@@ -74,25 +108,37 @@ function render({ model, el }) {
|
|
|
74
108
|
|
|
75
109
|
const data = model.get("data");
|
|
76
110
|
let repulsion = model.get("repulsion") || default_repulsion;
|
|
77
|
-
let
|
|
111
|
+
let node_scale = model.get("node_scale") || default_node_scale;
|
|
78
112
|
let width = model.get("width") || default_width;
|
|
79
113
|
let height = model.get("height") || default_height;
|
|
80
114
|
colour_scale_type = model.get("colour_scale_type");
|
|
81
115
|
colour_feature = model.get("colour_feature");
|
|
82
|
-
|
|
83
|
-
|
|
116
|
+
node_size_feature = model.get("node_size_feature");
|
|
117
|
+
let global_selected_ids = model.get("selected_ids");
|
|
118
|
+
|
|
84
119
|
plot = create_plot(data);
|
|
85
|
-
|
|
120
|
+
|
|
121
|
+
const update_repulsion = () => {
|
|
86
122
|
repulsion = model.get("repulsion");
|
|
87
123
|
plot.d3Force('charge', forceManyBody().strength(-repulsion));
|
|
88
124
|
plot.d3ReheatSimulation();
|
|
89
|
-
}
|
|
90
|
-
model.on("change:
|
|
91
|
-
|
|
92
|
-
|
|
125
|
+
}
|
|
126
|
+
model.on("change:repulsion", update_repulsion)
|
|
127
|
+
|
|
128
|
+
const update_node_scale = () => {
|
|
129
|
+
node_scale = model.get("node_scale");
|
|
130
|
+
create_node_canvas_object(plot, node_scale, node_size_feature);
|
|
93
131
|
plot.d3ReheatSimulation();
|
|
94
|
-
}
|
|
95
|
-
model.on("change:
|
|
132
|
+
}
|
|
133
|
+
model.on("change:node_scale", update_node_scale)
|
|
134
|
+
|
|
135
|
+
const update_node_size_feature = () => {
|
|
136
|
+
node_size_feature = model.get("node_size_feature");
|
|
137
|
+
create_node_canvas_object(plot, node_scale, node_size_feature);
|
|
138
|
+
}
|
|
139
|
+
model.on("change:node_size_feature", update_node_size_feature);
|
|
140
|
+
|
|
141
|
+
const update_colour_feature = () => {
|
|
96
142
|
colour_feature = model.get("colour_feature");
|
|
97
143
|
let feature_values = data.nodes.map(node => node[colour_feature])
|
|
98
144
|
let feature_type = get_feature_type(feature_values[0])
|
|
@@ -119,41 +165,11 @@ function render({ model, el }) {
|
|
|
119
165
|
});
|
|
120
166
|
}
|
|
121
167
|
|
|
122
|
-
plot
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
// Draw filled circle
|
|
128
|
-
ctx.beginPath();
|
|
129
|
-
ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, false);
|
|
130
|
-
ctx.fillStyle = fillColour;
|
|
131
|
-
ctx.fill();
|
|
132
|
-
|
|
133
|
-
// Draw red stroke if node is locally selected
|
|
134
|
-
if (isLocalSelected) {
|
|
135
|
-
ctx.lineWidth = radius/5;
|
|
136
|
-
ctx.strokeStyle = 'red';
|
|
137
|
-
ctx.stroke();
|
|
138
|
-
} else {
|
|
139
|
-
ctx.lineWidth = radius/10;
|
|
140
|
-
ctx.strokeStyle = 'lightgrey';
|
|
141
|
-
ctx.stroke();
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
// plot.nodeColor((d) => {
|
|
146
|
-
// return global_selected_ids.includes(d.id)
|
|
147
|
-
// ? "yellow"
|
|
148
|
-
// : local_selected_ids.includes(d.id)
|
|
149
|
-
// ? "rgba(255,0,0,0.5)" // Red for local_selected_ids nodes
|
|
150
|
-
// : feature_type === undefined
|
|
151
|
-
// ? "#4682B480" // Default colour
|
|
152
|
-
// : feature_type === 'hash_string'
|
|
153
|
-
// ? d[colour_feature] // Use the hash string directly
|
|
154
|
-
// : colour_scale(d[colour_feature])})
|
|
155
|
-
});
|
|
156
|
-
model.on("change:colour_scale_type", () => {
|
|
168
|
+
create_node_canvas_object(plot, node_scale, node_size_feature);
|
|
169
|
+
}
|
|
170
|
+
model.on("change:colour_feature", update_colour_feature)
|
|
171
|
+
|
|
172
|
+
const update_colour_scale_type = () => {
|
|
157
173
|
colour_feature = model.get("colour_feature");
|
|
158
174
|
colour_scale_type = model.get("colour_scale_type")
|
|
159
175
|
let feature_values = data.nodes.map(node => node[colour_feature])
|
|
@@ -181,46 +197,10 @@ function render({ model, el }) {
|
|
|
181
197
|
});
|
|
182
198
|
}
|
|
183
199
|
|
|
184
|
-
plot
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
// Draw filled circle
|
|
190
|
-
ctx.beginPath();
|
|
191
|
-
ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, false);
|
|
192
|
-
ctx.fillStyle = fillColour;
|
|
193
|
-
ctx.fill();
|
|
194
|
-
|
|
195
|
-
// Draw red stroke if node is locally selected
|
|
196
|
-
if (isLocalSelected) {
|
|
197
|
-
ctx.lineWidth = radius/5;
|
|
198
|
-
ctx.strokeStyle = 'red';
|
|
199
|
-
ctx.stroke();
|
|
200
|
-
} else {
|
|
201
|
-
ctx.lineWidth = radius/10;
|
|
202
|
-
ctx.strokeStyle = 'lightgrey';
|
|
203
|
-
ctx.stroke();
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
// if ( feature_type == "numeric" ) {
|
|
207
|
-
// if ( colour_scale_type == "diverging" ) {
|
|
208
|
-
// colour_scale = scaleLinear().domain([min(feature_values), 0, max(feature_values)]).range(["#0000FF80","#EEEEEE80","#FF000080"])
|
|
209
|
-
// } else {
|
|
210
|
-
// colour_scale = scaleLinear().domain(extent(feature_values)).range(["#FFFF0080", "#0000FF80"])
|
|
211
|
-
// }
|
|
212
|
-
// }
|
|
213
|
-
// plot.nodeColor((d) => {
|
|
214
|
-
// return global_selected_ids.includes(d.id)
|
|
215
|
-
// ? "yellow"
|
|
216
|
-
// : local_selected_ids.includes(d.id)
|
|
217
|
-
// ? "rgba(255,0,0,0.5)" // Red for local_selected_ids nodes
|
|
218
|
-
// : feature_type === undefined
|
|
219
|
-
// ? "#4682B480" // Default colour
|
|
220
|
-
// : feature_type === 'hash_string'
|
|
221
|
-
// ? d[colour_feature] // Use the hash string directly
|
|
222
|
-
// : colour_scale(d[colour_feature])})
|
|
223
|
-
})
|
|
200
|
+
create_node_canvas_object(plot, node_scale, node_size_feature);
|
|
201
|
+
}
|
|
202
|
+
model.on("change:colour_scale_type", update_colour_scale_type)
|
|
203
|
+
|
|
224
204
|
model.on("change:selected_ids", () => {
|
|
225
205
|
global_selected_ids = model.get("selected_ids");
|
|
226
206
|
plot.nodeColor((d) =>
|
|
@@ -232,6 +212,10 @@ function render({ model, el }) {
|
|
|
232
212
|
);
|
|
233
213
|
});
|
|
234
214
|
|
|
215
|
+
update_node_scale();
|
|
216
|
+
update_colour_feature();
|
|
217
|
+
update_node_size_feature();
|
|
218
|
+
|
|
235
219
|
let brush_active = false;
|
|
236
220
|
|
|
237
221
|
let container = el.querySelector(".force-graph-container")
|
|
@@ -282,7 +266,6 @@ function render({ model, el }) {
|
|
|
282
266
|
let selectedNodes = tree.search(bbox)
|
|
283
267
|
local_selected_ids = selectedNodes.map(node => node.id);
|
|
284
268
|
model.set("selected_ids", local_selected_ids);
|
|
285
|
-
// console.log(local_selected_ids)
|
|
286
269
|
debouncedSaveChanges();
|
|
287
270
|
}
|
|
288
271
|
};
|
|
@@ -305,6 +288,7 @@ function render({ model, el }) {
|
|
|
305
288
|
window.addEventListener("dblclick", (e) => {
|
|
306
289
|
if (brush_active) { disactivate_brush() }
|
|
307
290
|
})
|
|
291
|
+
|
|
308
292
|
}
|
|
309
293
|
|
|
310
294
|
export default { render };
|
|
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
|