Spaces:
Running
Running
Fixes for airlines demo.
Browse files
lynxkite-graph-analytics/src/lynxkite_plugins/graph_analytics/lynxkite_ops.py
CHANGED
@@ -201,8 +201,7 @@ def import_graphml(*, filename: str):
|
|
201 |
else:
|
202 |
raise ValueError("No GraphML file found in the ZIP archive.")
|
203 |
else:
|
204 |
-
|
205 |
-
G = nx.read_graphml(f)
|
206 |
return G
|
207 |
|
208 |
|
@@ -317,7 +316,9 @@ def _map_color(value):
|
|
317 |
colors = cmap.colors[: len(categories)]
|
318 |
return [
|
319 |
"#{:02x}{:02x}{:02x}".format(int(r * 255), int(g * 255), int(b * 255))
|
320 |
-
for r, g, b in [
|
|
|
|
|
321 |
]
|
322 |
|
323 |
|
@@ -326,17 +327,27 @@ def visualize_graph(graph: Bundle, *, color_nodes_by: ops.NodeAttribute = None):
|
|
326 |
nodes = graph.dfs["nodes"].copy()
|
327 |
if color_nodes_by:
|
328 |
nodes["color"] = _map_color(nodes[color_nodes_by])
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
else:
|
341 |
pos = nx.spring_layout(
|
342 |
graph.to_nx(), iterations=max(1, int(10000 / len(nodes)))
|
|
|
201 |
else:
|
202 |
raise ValueError("No GraphML file found in the ZIP archive.")
|
203 |
else:
|
204 |
+
G = nx.read_graphml(filename)
|
|
|
205 |
return G
|
206 |
|
207 |
|
|
|
316 |
colors = cmap.colors[: len(categories)]
|
317 |
return [
|
318 |
"#{:02x}{:02x}{:02x}".format(int(r * 255), int(g * 255), int(b * 255))
|
319 |
+
for r, g, b in [
|
320 |
+
colors[min(len(colors) - 1, categories.get_loc(v))] for v in value
|
321 |
+
]
|
322 |
]
|
323 |
|
324 |
|
|
|
327 |
nodes = graph.dfs["nodes"].copy()
|
328 |
if color_nodes_by:
|
329 |
nodes["color"] = _map_color(nodes[color_nodes_by])
|
330 |
+
for cols in ["x y", "long lat"]:
|
331 |
+
x, y = cols.split()
|
332 |
+
if (
|
333 |
+
x in nodes.columns
|
334 |
+
and nodes[x].dtype == "float64"
|
335 |
+
and y in nodes.columns
|
336 |
+
and nodes[y].dtype == "float64"
|
337 |
+
):
|
338 |
+
cx, cy = nodes[x].mean(), nodes[y].mean()
|
339 |
+
dx, dy = nodes[x].std(), nodes[y].std()
|
340 |
+
# Scale up to avoid float precision issues and because eCharts omits short edges.
|
341 |
+
scale_x = 100 / max(dx, dy)
|
342 |
+
scale_y = scale_x
|
343 |
+
if y == "lat":
|
344 |
+
scale_y *= -1
|
345 |
+
pos = {
|
346 |
+
node_id: ((row[x] - cx) * scale_x, (row[y] - cy) * scale_y)
|
347 |
+
for node_id, row in nodes.iterrows()
|
348 |
+
}
|
349 |
+
curveness = 0 # Street maps are better with straight streets.
|
350 |
+
break
|
351 |
else:
|
352 |
pos = nx.spring_layout(
|
353 |
graph.to_nx(), iterations=max(1, int(10000 / len(nodes)))
|