graph_widget 0.1.7__tar.gz → 0.1.9__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.7
3
+ Version: 0.1.9
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.7"
7
+ version = "0.1.9"
8
8
  dependencies = ["anywidget","marimo"]
9
9
  readme = "README.md"
10
10
 
@@ -126,6 +126,10 @@ function render({ model, el }) {
126
126
  ctx.lineWidth = radius/5;
127
127
  ctx.strokeStyle = 'red';
128
128
  ctx.stroke();
129
+ } else {
130
+ ctx.lineWidth = 1;
131
+ ctx.strokeStyle = 'white';
132
+ ctx.stroke();
129
133
  }
130
134
  });
131
135
 
@@ -147,21 +151,66 @@ function render({ model, el }) {
147
151
  let feature_type = get_feature_type(feature_values[0])
148
152
  if ( feature_type == "numeric" ) {
149
153
  if ( colour_scale_type == "diverging" ) {
150
- 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"])
151
155
  } else {
152
156
  colour_scale = scaleLinear().domain(extent(feature_values)).range(["#FFFF0080", "#0000FF80"])
153
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
154
164
  }
155
- plot.nodeColor((d) => {
156
- return global_selected_ids.includes(d.id)
157
- ? "yellow"
158
- : local_selected_ids.includes(d.id)
159
- ? "rgba(255,0,0,0.5)" // Red for local_selected_ids nodes
160
- : feature_type === undefined
161
- ? "#4682B480" // Default colour
162
- : feature_type === 'hash_string'
163
- ? d[colour_feature] // Use the hash string directly
164
- : 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 = 1;
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])})
165
214
  })
166
215
  model.on("change:selected_ids", () => {
167
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
File without changes