graph_widget 0.1.8__tar.gz → 0.1.10__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.8
3
+ Version: 0.1.10
4
4
  Requires-Dist: anywidget
5
5
  Requires-Dist: marimo
6
6
  Description-Content-Type: text/markdown
@@ -41,7 +41,7 @@ def _(data, mo):
41
41
  start=1, stop=20, step=1, value=3, debounce=True, label="Node scale"
42
42
  )
43
43
  colour_feature_dropdown = mo.ui.dropdown(
44
- options=list(data["nodes"][3].keys()), value="kind", label="Colour by"
44
+ options=list(data["nodes"][3].keys()), label="Colour by"
45
45
  )
46
46
  colour_scale_type_radio = mo.ui.radio(options=["diverging", "sequential"], value="diverging", label="Colour scale type")
47
47
  return (
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "graph_widget"
7
- version = "0.1.8"
7
+ version = "0.1.10"
8
8
  dependencies = ["anywidget","marimo"]
9
9
  readme = "README.md"
10
10
 
@@ -89,7 +89,7 @@ function render({ model, el }) {
89
89
  let feature_type = get_feature_type(feature_values[0])
90
90
  if ( feature_type == "numeric" ) {
91
91
  if ( colour_scale_type == "diverging" ) {
92
- colour_scale = scaleLinear().domain([min(feature_values), 0, max(feature_values)]).range(["#0000FFBF","#EEEEEE33","#FF0000BF"])
92
+ colour_scale = scaleLinear().domain([min(feature_values), 0, max(feature_values)]).range(["#0000FFBF","white","#FF0000BF"])
93
93
  } else {
94
94
  colour_scale = scaleLinear().domain(extent(feature_values)).range(["#FFFF0080", "#0000FF80"])
95
95
  }
@@ -127,8 +127,8 @@ function render({ model, el }) {
127
127
  ctx.strokeStyle = 'red';
128
128
  ctx.stroke();
129
129
  } else {
130
- ctx.lineWidth = 1;
131
- ctx.strokeStyle = 'white';
130
+ ctx.lineWidth = radius/10;
131
+ ctx.strokeStyle = 'lightgrey';
132
132
  ctx.stroke();
133
133
  }
134
134
  });
@@ -151,21 +151,66 @@ function render({ model, el }) {
151
151
  let feature_type = get_feature_type(feature_values[0])
152
152
  if ( feature_type == "numeric" ) {
153
153
  if ( colour_scale_type == "diverging" ) {
154
- colour_scale = scaleLinear().domain([min(feature_values), 0, max(feature_values)]).range(["#0000FF80","#EEEEEE80","#FF000080"])
154
+ colour_scale = scaleLinear().domain([min(feature_values), 0, max(feature_values)]).range(["#0000FFBF","white","#FF0000BF"])
155
155
  } else {
156
156
  colour_scale = scaleLinear().domain(extent(feature_values)).range(["#FFFF0080", "#0000FF80"])
157
157
  }
158
+ } else if ( feature_type == "categorical" ) {
159
+ colour_scale = scaleOrdinal().domain(extent(feature_values)).range(schemeCategory10)
160
+ } else if ( feature_type == "hash_string" ) {
161
+ colour_scale = scaleIdentity()
162
+ } else {
163
+ colour_scale = () => "#4682B480"; // Default colour
158
164
  }
159
- plot.nodeColor((d) => {
160
- return global_selected_ids.includes(d.id)
161
- ? "yellow"
162
- : local_selected_ids.includes(d.id)
163
- ? "rgba(255,0,0,0.5)" // Red for local_selected_ids nodes
164
- : feature_type === undefined
165
- ? "#4682B480" // Default colour
166
- : feature_type === 'hash_string'
167
- ? d[colour_feature] // Use the hash string directly
168
- : colour_scale(d[colour_feature])})
165
+
166
+ if (colour_scale_type === "diverging") {
167
+ // Sort nodes by absolute distance from zero
168
+ data.nodes.sort((a, b) => {
169
+ const aVal = Math.abs(a[colour_feature]);
170
+ const bVal = Math.abs(b[colour_feature]);
171
+ return aVal - bVal;
172
+ });
173
+ }
174
+
175
+ plot.nodeCanvasObject((node, ctx) => {
176
+ const radius = node_size * node_scale;
177
+ const isLocalSelected = local_selected_ids.includes(node.id);
178
+ const fillColour = colour_scale(node[colour_feature]);
179
+
180
+ // Draw filled circle
181
+ ctx.beginPath();
182
+ ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI, false);
183
+ ctx.fillStyle = fillColour;
184
+ ctx.fill();
185
+
186
+ // Draw red stroke if node is locally selected
187
+ if (isLocalSelected) {
188
+ ctx.lineWidth = radius/5;
189
+ ctx.strokeStyle = 'red';
190
+ ctx.stroke();
191
+ } else {
192
+ ctx.lineWidth = radius/10;
193
+ ctx.strokeStyle = 'lightgrey';
194
+ ctx.stroke();
195
+ }
196
+ });
197
+ // if ( feature_type == "numeric" ) {
198
+ // if ( colour_scale_type == "diverging" ) {
199
+ // colour_scale = scaleLinear().domain([min(feature_values), 0, max(feature_values)]).range(["#0000FF80","#EEEEEE80","#FF000080"])
200
+ // } else {
201
+ // colour_scale = scaleLinear().domain(extent(feature_values)).range(["#FFFF0080", "#0000FF80"])
202
+ // }
203
+ // }
204
+ // plot.nodeColor((d) => {
205
+ // return global_selected_ids.includes(d.id)
206
+ // ? "yellow"
207
+ // : local_selected_ids.includes(d.id)
208
+ // ? "rgba(255,0,0,0.5)" // Red for local_selected_ids nodes
209
+ // : feature_type === undefined
210
+ // ? "#4682B480" // Default colour
211
+ // : feature_type === 'hash_string'
212
+ // ? d[colour_feature] // Use the hash string directly
213
+ // : colour_scale(d[colour_feature])})
169
214
  })
170
215
  model.on("change:selected_ids", () => {
171
216
  global_selected_ids = model.get("selected_ids");
@@ -99,7 +99,7 @@ wheels = [
99
99
 
100
100
  [[package]]
101
101
  name = "graph-widget"
102
- version = "0.1.6"
102
+ version = "0.1.8"
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