graph_widget 0.1.13__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.13 → graph_widget-0.1.14}/PKG-INFO +1 -1
- {graph_widget-0.1.13 → graph_widget-0.1.14}/example_2.py +35 -9
- {graph_widget-0.1.13 → graph_widget-0.1.14}/pyproject.toml +1 -1
- {graph_widget-0.1.13 → graph_widget-0.1.14}/src/graph_widget/__init__.py +2 -1
- {graph_widget-0.1.13 → graph_widget-0.1.14}/src/graph_widget/static/widget.js +71 -89
- {graph_widget-0.1.13 → graph_widget-0.1.14}/uv.lock +1 -1
- graph_widget-0.1.13/vis-forge-marimo.py +0 -0
- {graph_widget-0.1.13 → graph_widget-0.1.14}/.gitignore +0 -0
- {graph_widget-0.1.13 → graph_widget-0.1.14}/.python-version +0 -0
- {graph_widget-0.1.13 → graph_widget-0.1.14}/README.md +0 -0
- {graph_widget-0.1.13 → graph_widget-0.1.14}/README_DEV.md +0 -0
- {graph_widget-0.1.13 → graph_widget-0.1.14}/bug_test.py +0 -0
- {graph_widget-0.1.13 → graph_widget-0.1.14}/data.json +0 -0
- {graph_widget-0.1.13 → graph_widget-0.1.14}/dev.py +0 -0
- {graph_widget-0.1.13 → graph_widget-0.1.14}/graph_3d_example.py +0 -0
- {graph_widget-0.1.13 → graph_widget-0.1.14}/multi_mst.json +0 -0
- {graph_widget-0.1.13 → graph_widget-0.1.14}/src/graph_widget/dev.py +0 -0
- {graph_widget-0.1.13 → 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, "label": "node 3"},
|
|
20
|
-
{"id": 4, "kind": "OTU", "degree": 2, "value": 1, "label": "node 4"},
|
|
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
|
|
|
@@ -126,5 +141,16 @@ def _(data, selected):
|
|
|
126
141
|
return (filtered_nodes,)
|
|
127
142
|
|
|
128
143
|
|
|
144
|
+
@app.cell
|
|
145
|
+
def _(data):
|
|
146
|
+
type(data)
|
|
147
|
+
return
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
@app.cell
|
|
151
|
+
def _():
|
|
152
|
+
return
|
|
153
|
+
|
|
154
|
+
|
|
129
155
|
if __name__ == "__main__":
|
|
130
156
|
app.run()
|
|
@@ -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,10 +96,10 @@ 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')
|
|
69
|
-
.nodeLabel('label')
|
|
70
103
|
.onEngineStop(() => {
|
|
71
104
|
plot.zoomToFit(400);
|
|
72
105
|
create_rtree(data["nodes"]);
|
|
@@ -75,25 +108,37 @@ function render({ model, el }) {
|
|
|
75
108
|
|
|
76
109
|
const data = model.get("data");
|
|
77
110
|
let repulsion = model.get("repulsion") || default_repulsion;
|
|
78
|
-
let
|
|
111
|
+
let node_scale = model.get("node_scale") || default_node_scale;
|
|
79
112
|
let width = model.get("width") || default_width;
|
|
80
113
|
let height = model.get("height") || default_height;
|
|
81
114
|
colour_scale_type = model.get("colour_scale_type");
|
|
82
115
|
colour_feature = model.get("colour_feature");
|
|
83
|
-
|
|
84
|
-
|
|
116
|
+
node_size_feature = model.get("node_size_feature");
|
|
117
|
+
let global_selected_ids = model.get("selected_ids");
|
|
118
|
+
|
|
85
119
|
plot = create_plot(data);
|
|
86
|
-
|
|
120
|
+
|
|
121
|
+
const update_repulsion = () => {
|
|
87
122
|
repulsion = model.get("repulsion");
|
|
88
123
|
plot.d3Force('charge', forceManyBody().strength(-repulsion));
|
|
89
124
|
plot.d3ReheatSimulation();
|
|
90
|
-
}
|
|
91
|
-
model.on("change:
|
|
92
|
-
|
|
93
|
-
|
|
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);
|
|
94
131
|
plot.d3ReheatSimulation();
|
|
95
|
-
}
|
|
96
|
-
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 = () => {
|
|
97
142
|
colour_feature = model.get("colour_feature");
|
|
98
143
|
let feature_values = data.nodes.map(node => node[colour_feature])
|
|
99
144
|
let feature_type = get_feature_type(feature_values[0])
|
|
@@ -120,41 +165,11 @@ function render({ model, el }) {
|
|
|
120
165
|
});
|
|
121
166
|
}
|
|
122
167
|
|
|
123
|
-
plot
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
// Draw filled circle
|
|
129
|
-
ctx.beginPath();
|
|
130
|
-
ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, false);
|
|
131
|
-
ctx.fillStyle = fillColour;
|
|
132
|
-
ctx.fill();
|
|
133
|
-
|
|
134
|
-
// Draw red stroke if node is locally selected
|
|
135
|
-
if (isLocalSelected) {
|
|
136
|
-
ctx.lineWidth = radius/5;
|
|
137
|
-
ctx.strokeStyle = 'red';
|
|
138
|
-
ctx.stroke();
|
|
139
|
-
} else {
|
|
140
|
-
ctx.lineWidth = radius/10;
|
|
141
|
-
ctx.strokeStyle = 'lightgrey';
|
|
142
|
-
ctx.stroke();
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
// plot.nodeColor((d) => {
|
|
147
|
-
// return global_selected_ids.includes(d.id)
|
|
148
|
-
// ? "yellow"
|
|
149
|
-
// : local_selected_ids.includes(d.id)
|
|
150
|
-
// ? "rgba(255,0,0,0.5)" // Red for local_selected_ids nodes
|
|
151
|
-
// : feature_type === undefined
|
|
152
|
-
// ? "#4682B480" // Default colour
|
|
153
|
-
// : feature_type === 'hash_string'
|
|
154
|
-
// ? d[colour_feature] // Use the hash string directly
|
|
155
|
-
// : colour_scale(d[colour_feature])})
|
|
156
|
-
});
|
|
157
|
-
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 = () => {
|
|
158
173
|
colour_feature = model.get("colour_feature");
|
|
159
174
|
colour_scale_type = model.get("colour_scale_type")
|
|
160
175
|
let feature_values = data.nodes.map(node => node[colour_feature])
|
|
@@ -182,46 +197,9 @@ function render({ model, el }) {
|
|
|
182
197
|
});
|
|
183
198
|
}
|
|
184
199
|
|
|
185
|
-
plot
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const fillColour = colour_scale(node[colour_feature]);
|
|
189
|
-
|
|
190
|
-
// Draw filled circle
|
|
191
|
-
ctx.beginPath();
|
|
192
|
-
ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, false);
|
|
193
|
-
ctx.fillStyle = fillColour;
|
|
194
|
-
ctx.fill();
|
|
195
|
-
|
|
196
|
-
// Draw red stroke if node is locally selected
|
|
197
|
-
if (isLocalSelected) {
|
|
198
|
-
ctx.lineWidth = radius/5;
|
|
199
|
-
ctx.strokeStyle = 'red';
|
|
200
|
-
ctx.stroke();
|
|
201
|
-
} else {
|
|
202
|
-
ctx.lineWidth = radius/10;
|
|
203
|
-
ctx.strokeStyle = 'lightgrey';
|
|
204
|
-
ctx.stroke();
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
// if ( feature_type == "numeric" ) {
|
|
208
|
-
// if ( colour_scale_type == "diverging" ) {
|
|
209
|
-
// colour_scale = scaleLinear().domain([min(feature_values), 0, max(feature_values)]).range(["#0000FF80","#EEEEEE80","#FF000080"])
|
|
210
|
-
// } else {
|
|
211
|
-
// colour_scale = scaleLinear().domain(extent(feature_values)).range(["#FFFF0080", "#0000FF80"])
|
|
212
|
-
// }
|
|
213
|
-
// }
|
|
214
|
-
// plot.nodeColor((d) => {
|
|
215
|
-
// return global_selected_ids.includes(d.id)
|
|
216
|
-
// ? "yellow"
|
|
217
|
-
// : local_selected_ids.includes(d.id)
|
|
218
|
-
// ? "rgba(255,0,0,0.5)" // Red for local_selected_ids nodes
|
|
219
|
-
// : feature_type === undefined
|
|
220
|
-
// ? "#4682B480" // Default colour
|
|
221
|
-
// : feature_type === 'hash_string'
|
|
222
|
-
// ? d[colour_feature] // Use the hash string directly
|
|
223
|
-
// : colour_scale(d[colour_feature])})
|
|
224
|
-
})
|
|
200
|
+
create_node_canvas_object(plot, node_scale, node_size_feature);
|
|
201
|
+
}
|
|
202
|
+
model.on("change:colour_scale_type", update_colour_scale_type)
|
|
225
203
|
|
|
226
204
|
model.on("change:selected_ids", () => {
|
|
227
205
|
global_selected_ids = model.get("selected_ids");
|
|
@@ -234,6 +212,10 @@ function render({ model, el }) {
|
|
|
234
212
|
);
|
|
235
213
|
});
|
|
236
214
|
|
|
215
|
+
update_node_scale();
|
|
216
|
+
update_colour_feature();
|
|
217
|
+
update_node_size_feature();
|
|
218
|
+
|
|
237
219
|
let brush_active = false;
|
|
238
220
|
|
|
239
221
|
let container = el.querySelector(".force-graph-container")
|
|
@@ -284,7 +266,6 @@ function render({ model, el }) {
|
|
|
284
266
|
let selectedNodes = tree.search(bbox)
|
|
285
267
|
local_selected_ids = selectedNodes.map(node => node.id);
|
|
286
268
|
model.set("selected_ids", local_selected_ids);
|
|
287
|
-
// console.log(local_selected_ids)
|
|
288
269
|
debouncedSaveChanges();
|
|
289
270
|
}
|
|
290
271
|
};
|
|
@@ -307,6 +288,7 @@ function render({ model, el }) {
|
|
|
307
288
|
window.addEventListener("dblclick", (e) => {
|
|
308
289
|
if (brush_active) { disactivate_brush() }
|
|
309
290
|
})
|
|
291
|
+
|
|
310
292
|
}
|
|
311
293
|
|
|
312
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
|