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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graph_widget
3
- Version: 0.1.11
3
+ Version: 0.1.13
4
4
  Requires-Dist: anywidget
5
5
  Requires-Dist: marimo
6
6
  Description-Content-Type: text/markdown
@@ -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()
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "graph_widget"
7
- version = "0.1.11"
7
+ version = "0.1.13"
8
8
  dependencies = ["anywidget","marimo"]
9
9
  readme = "README.md"
10
10
 
@@ -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 width = "800";
11
- let height = "500";
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 repulsion = 1;
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 = (width, height, data) => {
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(width, height, data);
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
- !event.button && // Ignore mouse buttons other than left-click
292
- (modifierKey || event.target.__data__.type !== "overlay")
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]])
@@ -99,7 +99,7 @@ wheels = [
99
99
 
100
100
  [[package]]
101
101
  name = "graph-widget"
102
- version = "0.1.10"
102
+ version = "0.1.12"
103
103
  source = { editable = "." }
104
104
  dependencies = [
105
105
  { name = "anywidget" },
File without changes
File without changes
File without changes
File without changes
File without changes