graph_widget 0.1.11__tar.gz → 0.1.13__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.11 → graph_widget-0.1.13}/PKG-INFO +1 -1
- {graph_widget-0.1.11 → graph_widget-0.1.13}/example_2.py +11 -20
- {graph_widget-0.1.11 → graph_widget-0.1.13}/pyproject.toml +1 -1
- {graph_widget-0.1.11 → graph_widget-0.1.13}/src/graph_widget/__init__.py +2 -0
- {graph_widget-0.1.11 → graph_widget-0.1.13}/src/graph_widget/static/widget.js +15 -9
- {graph_widget-0.1.11 → graph_widget-0.1.13}/uv.lock +1 -1
- {graph_widget-0.1.11 → graph_widget-0.1.13}/.gitignore +0 -0
- {graph_widget-0.1.11 → graph_widget-0.1.13}/.python-version +0 -0
- {graph_widget-0.1.11 → graph_widget-0.1.13}/README.md +0 -0
- {graph_widget-0.1.11 → graph_widget-0.1.13}/README_DEV.md +0 -0
- {graph_widget-0.1.11 → graph_widget-0.1.13}/bug_test.py +0 -0
- {graph_widget-0.1.11 → graph_widget-0.1.13}/data.json +0 -0
- {graph_widget-0.1.11 → graph_widget-0.1.13}/dev.py +0 -0
- {graph_widget-0.1.11 → graph_widget-0.1.13}/graph_3d_example.py +0 -0
- {graph_widget-0.1.11 → graph_widget-0.1.13}/multi_mst.json +0 -0
- {graph_widget-0.1.11 → graph_widget-0.1.13}/src/graph_widget/dev.py +0 -0
- {graph_widget-0.1.11 → graph_widget-0.1.13}/src/graph_widget/static/widget.css +0 -0
- {graph_widget-0.1.11 → graph_widget-0.1.13}/vis-forge-marimo.py +0 -0
|
@@ -14,10 +14,10 @@ def _():
|
|
|
14
14
|
@app.cell
|
|
15
15
|
def _():
|
|
16
16
|
data = {'nodes':
|
|
17
|
-
[{"id": 1, "kind": "sample", "value": -15},
|
|
18
|
-
{"id": 2, "kind": "sample", "value": 0},
|
|
19
|
-
{"id": 3, "kind": "OTU", "degree": 3, "value": 23},
|
|
20
|
-
{"id": 4, "kind": "OTU", "degree": 2, "value": 1},
|
|
17
|
+
[{"id": 1, "kind": "sample", "value": -15, "label": "node 1"},
|
|
18
|
+
{"id": 2, "kind": "sample", "value": 0, "label": "node 2"},
|
|
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
21
|
{"id": 5, "kind": "OTU", "degree": 3, "value": 17}],
|
|
22
22
|
"links": [
|
|
23
23
|
{"source": 1, "target": 3},
|
|
@@ -60,7 +60,9 @@ def _(data, graph_widget, mo):
|
|
|
60
60
|
repulsion=2,
|
|
61
61
|
node_scale=2,
|
|
62
62
|
colour_feature="",
|
|
63
|
-
colour_scale_type=""
|
|
63
|
+
colour_scale_type="",
|
|
64
|
+
height=600,
|
|
65
|
+
width=600
|
|
64
66
|
)
|
|
65
67
|
)
|
|
66
68
|
return (data_graph,)
|
|
@@ -74,10 +76,10 @@ def _(
|
|
|
74
76
|
node_scale_slider,
|
|
75
77
|
repulsion_slider,
|
|
76
78
|
):
|
|
77
|
-
data_graph.repulsion = repulsion_slider.value
|
|
78
|
-
data_graph.node_scale = node_scale_slider.value
|
|
79
|
-
data_graph.colour_feature = colour_feature_dropdown.value
|
|
80
|
-
data_graph.colour_scale_type= colour_scale_type_radio.value
|
|
79
|
+
data_graph.widget.repulsion = repulsion_slider.value
|
|
80
|
+
data_graph.widget.node_scale = node_scale_slider.value
|
|
81
|
+
data_graph.widget.colour_feature = colour_feature_dropdown.value
|
|
82
|
+
data_graph.widget.colour_scale_type= colour_scale_type_radio.value
|
|
81
83
|
return
|
|
82
84
|
|
|
83
85
|
|
|
@@ -124,16 +126,5 @@ def _(data, selected):
|
|
|
124
126
|
return (filtered_nodes,)
|
|
125
127
|
|
|
126
128
|
|
|
127
|
-
@app.cell
|
|
128
|
-
def _(data):
|
|
129
|
-
type(data)
|
|
130
|
-
return
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
@app.cell
|
|
134
|
-
def _():
|
|
135
|
-
return
|
|
136
|
-
|
|
137
|
-
|
|
138
129
|
if __name__ == "__main__":
|
|
139
130
|
app.run()
|
|
@@ -20,3 +20,5 @@ class ForceGraphWidget(anywidget.AnyWidget):
|
|
|
20
20
|
colour_feature = traitlets.Unicode().tag(sync=True)
|
|
21
21
|
colour_scale_type = traitlets.Unicode().tag(sync=True)
|
|
22
22
|
selected_ids = traitlets.List([]).tag(sync=True)
|
|
23
|
+
width = traitlets.Int().tag(sync=True)
|
|
24
|
+
height = traitlets.Int().tag(sync=True)
|
|
@@ -7,8 +7,8 @@ import { scaleLinear, scaleOrdinal, scaleIdentity } from "https://esm.sh/d3-scal
|
|
|
7
7
|
import { schemeCategory10 } from "https://esm.sh/d3-scale-chromatic";
|
|
8
8
|
import RBush from 'https://cdn.jsdelivr.net/npm/rbush/+esm';
|
|
9
9
|
|
|
10
|
-
let
|
|
11
|
-
let
|
|
10
|
+
let default_width = 800;
|
|
11
|
+
let default_height = 500;
|
|
12
12
|
|
|
13
13
|
class MyRBush extends RBush {
|
|
14
14
|
toBBox(node) { return { id: node.id, minX: node.x, minY: node.y, maxX: node.x, maxY: node.y }; }
|
|
@@ -17,7 +17,8 @@ class MyRBush extends RBush {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
let local_selected_ids = []
|
|
20
|
-
let
|
|
20
|
+
let default_repulsion = 1;
|
|
21
|
+
let default_node_scale = 1;
|
|
21
22
|
let node_scale = 1;
|
|
22
23
|
let colour_scale_type = "";
|
|
23
24
|
let plot;
|
|
@@ -54,7 +55,7 @@ const isLinux = ua.includes('linux');
|
|
|
54
55
|
function render({ model, el }) {
|
|
55
56
|
const debouncedSaveChanges = debounce(() => model.save_changes(), 300);
|
|
56
57
|
|
|
57
|
-
const create_plot = (
|
|
58
|
+
const create_plot = (data) => {
|
|
58
59
|
return ForceGraph()(el)
|
|
59
60
|
.width(width)
|
|
60
61
|
.height(height)
|
|
@@ -65,6 +66,7 @@ function render({ model, el }) {
|
|
|
65
66
|
.d3AlphaDecay(0.001)
|
|
66
67
|
.minZoom(0.001)
|
|
67
68
|
.nodeCanvasObjectMode(() => 'replace')
|
|
69
|
+
.nodeLabel('label')
|
|
68
70
|
.onEngineStop(() => {
|
|
69
71
|
plot.zoomToFit(400);
|
|
70
72
|
create_rtree(data["nodes"]);
|
|
@@ -72,13 +74,15 @@ function render({ model, el }) {
|
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
const data = model.get("data");
|
|
75
|
-
repulsion = model.get("repulsion");
|
|
76
|
-
node_size = model.get("node_scale");
|
|
77
|
+
let repulsion = model.get("repulsion") || default_repulsion;
|
|
78
|
+
let node_size = model.get("node_scale") || default_node_scale;
|
|
79
|
+
let width = model.get("width") || default_width;
|
|
80
|
+
let height = model.get("height") || default_height;
|
|
77
81
|
colour_scale_type = model.get("colour_scale_type");
|
|
78
82
|
colour_feature = model.get("colour_feature");
|
|
79
83
|
let global_selected_ids = model.get("selected_ids")
|
|
80
84
|
|
|
81
|
-
plot = create_plot(
|
|
85
|
+
plot = create_plot(data);
|
|
82
86
|
model.on("change:repulsion", () => {
|
|
83
87
|
repulsion = model.get("repulsion");
|
|
84
88
|
plot.d3Force('charge', forceManyBody().strength(-repulsion));
|
|
@@ -218,6 +222,7 @@ function render({ model, el }) {
|
|
|
218
222
|
// ? d[colour_feature] // Use the hash string directly
|
|
219
223
|
// : colour_scale(d[colour_feature])})
|
|
220
224
|
})
|
|
225
|
+
|
|
221
226
|
model.on("change:selected_ids", () => {
|
|
222
227
|
global_selected_ids = model.get("selected_ids");
|
|
223
228
|
plot.nodeColor((d) =>
|
|
@@ -287,9 +292,10 @@ function render({ model, el }) {
|
|
|
287
292
|
let my_brush = brush()
|
|
288
293
|
.filter((event) => {
|
|
289
294
|
const modifierKey = isMac ? event.metaKey : event.ctrlKey;
|
|
295
|
+
console.log(modifierKey, event.button, event.target.__data__.type, event);
|
|
290
296
|
return (
|
|
291
|
-
|
|
292
|
-
(modifierKey || event.target.__data__.type
|
|
297
|
+
event.button == 0 && // Ignore mouse buttons other than left-click
|
|
298
|
+
(modifierKey || ["selection", "s", "e", "n", "w"].includes(event.target.__data__.type))
|
|
293
299
|
)
|
|
294
300
|
})
|
|
295
301
|
.extent([[0, 0], [width, height]])
|
|
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
|