graph_widget 0.1.10__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.10
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
 
@@ -0,0 +1,59 @@
1
+ import marimo
2
+
3
+ __generated_with = "0.11.6"
4
+ app = marimo.App(width="full")
5
+
6
+
7
+ @app.cell
8
+ def _():
9
+ import anywidget
10
+ import traitlets
11
+ return anywidget, traitlets
12
+
13
+
14
+ @app.cell
15
+ def _(anywidget, traitlets):
16
+ class CounterWidget(anywidget.AnyWidget):
17
+ _esm = """
18
+ import ForceGraph3D from "https://esm.sh/3d-force-graph";
19
+ const N = 300;
20
+ const gData = {
21
+ nodes: [...Array(N).keys()].map(i => ({ id: i })),
22
+ links: [...Array(N).keys()]
23
+ .filter(id => id)
24
+ .map(id => ({
25
+ source: id,
26
+ target: Math.round(Math.random() * (id-1))
27
+ }))
28
+ };
29
+
30
+ function render({ model, el }) {
31
+ const create_plot = () => {
32
+ return ForceGraph3D()(el)
33
+ .graphData(gData)
34
+ }
35
+ create_plot()
36
+ }
37
+ export default { render };
38
+ """
39
+ _css = """
40
+ .counter-widget button { color: white; font-size: 1.75rem; background-color: #ea580c; padding: 0.5rem 1rem; border: none; border-radius: 0.25rem; }
41
+ .counter-widget button:hover { background-color: #9a3412; }
42
+ """
43
+ value = traitlets.Int(0).tag(sync=True)
44
+ return (CounterWidget,)
45
+
46
+
47
+ @app.cell
48
+ def _(CounterWidget):
49
+ CounterWidget()
50
+ return
51
+
52
+
53
+ @app.cell
54
+ def _():
55
+ return
56
+
57
+
58
+ if __name__ == "__main__":
59
+ app.run()
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "graph_widget"
7
- version = "0.1.10"
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;
@@ -45,10 +46,16 @@ const get_feature_type = (value) => {
45
46
  return 'categorical'; // Default to categorical if not numeric or hash_string
46
47
  }
47
48
 
49
+ const ua = navigator.userAgent.toLowerCase();
50
+
51
+ const isMac = ua.includes('macintosh');
52
+ const isWindows = ua.includes('windows');
53
+ const isLinux = ua.includes('linux');
54
+
48
55
  function render({ model, el }) {
49
56
  const debouncedSaveChanges = debounce(() => model.save_changes(), 300);
50
57
 
51
- const create_plot = (width, height, data) => {
58
+ const create_plot = (data) => {
52
59
  return ForceGraph()(el)
53
60
  .width(width)
54
61
  .height(height)
@@ -66,13 +73,15 @@ function render({ model, el }) {
66
73
  }
67
74
 
68
75
  const data = model.get("data");
69
- repulsion = model.get("repulsion");
70
- 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;
71
80
  colour_scale_type = model.get("colour_scale_type");
72
81
  colour_feature = model.get("colour_feature");
73
82
  let global_selected_ids = model.get("selected_ids")
74
83
 
75
- plot = create_plot(width, height, data);
84
+ plot = create_plot(data);
76
85
  model.on("change:repulsion", () => {
77
86
  repulsion = model.get("repulsion");
78
87
  plot.d3Force('charge', forceManyBody().strength(-repulsion));
@@ -280,13 +289,11 @@ function render({ model, el }) {
280
289
 
281
290
  let my_brush = brush()
282
291
  .filter((event) => {
283
- // Prevent contextual menu on Ctrl-click (macOS)
284
- if (event.ctrlKey && event.button === 0) {
285
- event.preventDefault();
286
- }
292
+ const modifierKey = isMac ? event.metaKey : event.ctrlKey;
293
+ console.log(modifierKey, event.button, event.target.__data__.type, event);
287
294
  return (
288
- !event.button && // Ignore mouse buttons other than left-click
289
- (event.metaKey || event.ctrlKey || 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))
290
297
  )
291
298
  })
292
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.8"
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