|
@@ -123,7 +123,7 @@ COLORS = [
|
|
|
]
|
|
|
|
|
|
def pick_color(index):
|
|
|
- index = min(index, 6) * 0.2
|
|
|
+ index = min(index, 10) * 0.1
|
|
|
n3 = 0
|
|
|
|
|
|
if index <= 0:
|
|
@@ -146,18 +146,38 @@ def pick_color(index):
|
|
|
|
|
|
return f'#{int(color[0]):02x}{int(color[1]):02x}{int(color[2]):02x}'
|
|
|
|
|
|
-def build_graph(graph, map, index=0):
|
|
|
+def distance(graph, start, end):
|
|
|
+ visited = []
|
|
|
+ queue = [[start]]
|
|
|
+
|
|
|
+ while queue:
|
|
|
+ path = queue.pop(0)
|
|
|
+ node = path[-1]
|
|
|
+
|
|
|
+ if node not in visited:
|
|
|
+ near = graph[node]
|
|
|
+
|
|
|
+ for near_node in near:
|
|
|
+ if near_node == end:
|
|
|
+ return len(path)
|
|
|
+
|
|
|
+ queue.append(path + [near_node])
|
|
|
+
|
|
|
+ visited.append(node)
|
|
|
+
|
|
|
+ return 10
|
|
|
+
|
|
|
+def build_graph(graph, map, first=False):
|
|
|
uid = yafn.encode_uid(map.uid)
|
|
|
|
|
|
graph.add_node(
|
|
|
uid,
|
|
|
- label=f'{uid[:6]}{" (this peer)" if index == 0 else ""}',
|
|
|
- title=uid,
|
|
|
- color=pick_color(index)
|
|
|
+ label=f'{uid[:6]}{" (this peer)" if first else ""}',
|
|
|
+ title=uid
|
|
|
)
|
|
|
|
|
|
for submap in map.submaps:
|
|
|
- subuid = build_graph(graph, submap, index + 1)
|
|
|
+ subuid = build_graph(graph, submap)
|
|
|
|
|
|
graph.add_edge(uid, subuid)
|
|
|
|
|
@@ -219,11 +239,12 @@ if args.crawl:
|
|
|
font_color='white'
|
|
|
)
|
|
|
|
|
|
- build_graph(network, map)
|
|
|
+ first_uid = build_graph(network, map, first=True)
|
|
|
|
|
|
adj_list = network.get_adj_list()
|
|
|
for node in network.nodes:
|
|
|
node['value'] = min(max(len(adj_list[node['id']]), 1), 10)
|
|
|
+ node['color'] = pick_color(distance(adj_list, first_uid, node['id']))
|
|
|
|
|
|
filename = f'map_{int(time.time())}.html'
|
|
|
network.save_graph(filename)
|