graph_widget 0.1.11__tar.gz → 0.1.12__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.12
4
4
  Requires-Dist: anywidget
5
5
  Requires-Dist: marimo
6
6
  Description-Content-Type: text/markdown
@@ -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=200,
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
 
@@ -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.12"
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)
@@ -72,13 +73,15 @@ function render({ model, el }) {
72
73
  }
73
74
 
74
75
  const data = model.get("data");
75
- repulsion = model.get("repulsion");
76
- node_size = model.get("node_scale");
76
+ let repulsion = model.get("repulsion") || default_repulsion;
77
+ let node_size = model.get("node_scale") || default_node_scale;
78
+ let width = model.get("width") || default_width;
79
+ let height = model.get("height") || default_height;
77
80
  colour_scale_type = model.get("colour_scale_type");
78
81
  colour_feature = model.get("colour_feature");
79
82
  let global_selected_ids = model.get("selected_ids")
80
83
 
81
- plot = create_plot(width, height, data);
84
+ plot = create_plot(data);
82
85
  model.on("change:repulsion", () => {
83
86
  repulsion = model.get("repulsion");
84
87
  plot.d3Force('charge', forceManyBody().strength(-repulsion));
@@ -287,9 +290,10 @@ function render({ model, el }) {
287
290
  let my_brush = brush()
288
291
  .filter((event) => {
289
292
  const modifierKey = isMac ? event.metaKey : event.ctrlKey;
293
+ console.log(modifierKey, event.button, event.target.__data__.type, event);
290
294
  return (
291
- !event.button && // Ignore mouse buttons other than left-click
292
- (modifierKey || event.target.__data__.type !== "overlay")
295
+ event.button == 0 && // Ignore mouse buttons other than left-click
296
+ (modifierKey || ["selection", "s", "e", "n", "w"].includes(event.target.__data__.type))
293
297
  )
294
298
  })
295
299
  .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.11"
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