graph_widget 0.1.4__tar.gz → 0.1.6__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.4
3
+ Version: 0.1.6
4
4
  Requires-Dist: anywidget
5
5
  Requires-Dist: marimo
6
6
  Description-Content-Type: text/markdown
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "graph_widget"
7
- version = "0.1.4"
7
+ version = "0.1.6"
8
8
  dependencies = ["anywidget","marimo"]
9
9
  readme = "README.md"
10
10
 
@@ -39,22 +39,6 @@ const create_rtree = (data) => {
39
39
  tree.load(data)
40
40
  }
41
41
 
42
- function create_plot(el, width, height, data) {
43
- return ForceGraph()(el)
44
- .width(width)
45
- .height(height)
46
- .graphData(data)
47
- // .d3Force('charge',forceManyBody().strength(-repulsion))
48
- .cooldownTime(5000)
49
- .warmupTicks(10)
50
- .d3AlphaDecay(0.001)
51
- .minZoom(0.001)
52
- .onEngineStop(() => {
53
- plot.zoomToFit(400);
54
- create_rtree(data["nodes"]);
55
- });
56
- }
57
-
58
42
  const get_feature_type = (value) => {
59
43
  if (typeof value === 'number') return 'numeric'; // Check for numeric
60
44
  if (typeof value === 'string' && value.startsWith('#')) return 'hash_string'; // Check for strings starting with #
@@ -64,6 +48,23 @@ const get_feature_type = (value) => {
64
48
  function render({ model, el }) {
65
49
  const debouncedSaveChanges = debounce(() => model.save_changes(), 300);
66
50
 
51
+ const create_plot = (width, height, data) => {
52
+ return ForceGraph()(el)
53
+ .width(width)
54
+ .height(height)
55
+ .graphData(data)
56
+ // .d3Force('charge',forceManyBody().strength(-repulsion))
57
+ .cooldownTime(5000)
58
+ .warmupTicks(10)
59
+ .d3AlphaDecay(0.001)
60
+ .minZoom(0.001)
61
+ .nodeCanvasObjectMode(() => 'replace')
62
+ .onEngineStop(() => {
63
+ plot.zoomToFit(400);
64
+ create_rtree(data["nodes"]);
65
+ });
66
+ }
67
+
67
68
  const data = model.get("data");
68
69
  repulsion = model.get("repulsion");
69
70
  node_size = model.get("node_scale");
@@ -71,7 +72,7 @@ function render({ model, el }) {
71
72
  colour_feature = model.get("colour_feature");
72
73
  let global_selected_ids = model.get("selected_ids")
73
74
 
74
- plot = create_plot(el, width, height, data);
75
+ plot = create_plot(width, height, data);
75
76
  model.on("change:repulsion", () => {
76
77
  repulsion = model.get("repulsion");
77
78
  plot.d3Force('charge', forceManyBody().strength(-repulsion));
@@ -88,7 +89,7 @@ function render({ model, el }) {
88
89
  let feature_type = get_feature_type(feature_values[0])
89
90
  if ( feature_type == "numeric" ) {
90
91
  if ( colour_scale_type == "diverging" ) {
91
- colour_scale = scaleLinear().domain([min(feature_values), 0, max(feature_values)]).range(["#0000FF80","#EEEEEE80","#FF000080"])
92
+ colour_scale = scaleLinear().domain([min(feature_values), 0, max(feature_values)]).range(["#0000FFBF","#EEEEEE33","#FF0000BF"])
92
93
  } else {
93
94
  colour_scale = scaleLinear().domain(extent(feature_values)).range(["#FFFF0080", "#0000FF80"])
94
95
  }
@@ -100,16 +101,35 @@ function render({ model, el }) {
100
101
  colour_scale = undefined
101
102
  }
102
103
 
103
- plot.nodeColor((d) => {
104
- return global_selected_ids.includes(d.id)
105
- ? "yellow"
106
- : local_selected_ids.includes(d.id)
107
- ? "rgba(255,0,0,0.5)" // Red for local_selected_ids nodes
108
- : feature_type === undefined
109
- ? "#4682B480" // Default colour
110
- : feature_type === 'hash_string'
111
- ? d[colour_feature] // Use the hash string directly
112
- : colour_scale(d[colour_feature])})
104
+ plot.nodeCanvasObject((node, ctx) => {
105
+ const radius = node_size * node_scale;
106
+ const isLocalSelected = local_selected_ids.includes(node.id);
107
+ const fillColour = colour_scale(node[colour_feature]);
108
+
109
+ // Draw filled circle
110
+ ctx.beginPath();
111
+ ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, false);
112
+ ctx.fillStyle = fillColour;
113
+ ctx.fill();
114
+
115
+ // Draw red stroke if node is locally selected
116
+ if (isLocalSelected) {
117
+ ctx.lineWidth = radius/5;
118
+ ctx.strokeStyle = 'red';
119
+ ctx.stroke();
120
+ }
121
+ });
122
+
123
+ // plot.nodeColor((d) => {
124
+ // return global_selected_ids.includes(d.id)
125
+ // ? "yellow"
126
+ // : local_selected_ids.includes(d.id)
127
+ // ? "rgba(255,0,0,0.5)" // Red for local_selected_ids nodes
128
+ // : feature_type === undefined
129
+ // ? "#4682B480" // Default colour
130
+ // : feature_type === 'hash_string'
131
+ // ? d[colour_feature] // Use the hash string directly
132
+ // : colour_scale(d[colour_feature])})
113
133
  });
114
134
  model.on("change:colour_scale_type", () => {
115
135
  colour_feature = model.get("colour_feature");
@@ -99,7 +99,7 @@ wheels = [
99
99
 
100
100
  [[package]]
101
101
  name = "graph-widget"
102
- version = "0.1.3"
102
+ version = "0.1.5"
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
File without changes
File without changes