From 80c2cd394b263e5f0cc119c57e65f1938105fbc7 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Thu, 7 Jun 2012 22:58:45 +0200 Subject: [PATCH] remove link.distance/strength, tweak parameters --- d3mapbuilder.py | 3 +-- html/force.js | 16 ++++++++++++++-- link.py | 3 +-- nodedb.py | 12 ++++++------ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/d3mapbuilder.py b/d3mapbuilder.py index 3993710..f7b125c 100644 --- a/d3mapbuilder.py +++ b/d3mapbuilder.py @@ -15,9 +15,8 @@ class D3MapBuilder: 'flags': x.flags } for x in nodes if x.flags['online']] output['links'] = [{'source': x.pair[0], 'target': x.pair[1], - 'distance': x.distance, - 'strength': x.strength, 'quality': x.quality, + 'type': x.type, 'id': "-".join(nodes[i].id for i in x.pair) } for x in self._db.get_links()] diff --git a/html/force.js b/html/force.js index 8d67a65..5381d35 100644 --- a/html/force.js +++ b/html/force.js @@ -160,8 +160,20 @@ var force = d3.layout.force() .friction(0.75) .theta(0.1) .size([w, h]) - .linkDistance(function (d) { return d.distance; }) - .linkStrength(function (d) { return d.strength; }) + .linkDistance(function (d) { + switch (d.type) { + case "vpn": return 150 + case "client": return 20 + default: return 70 + } + }) + .linkStrength(function (d) { + switch (d.type) { + case "vpn": return 0.15 + case "client": return 1 + default: return 0.5 + } + }) force.on("tick", function() { var size = force.size() diff --git a/link.py b/link.py index 301d813..ab9693b 100644 --- a/link.py +++ b/link.py @@ -1,7 +1,6 @@ class Link(): def __init__(self): self.pair = None - self.distance = None - self.strength = None self.quality = None + self.type = None diff --git a/nodedb.py b/nodedb.py index 7ae8f7b..b991322 100644 --- a/nodedb.py +++ b/nodedb.py @@ -157,16 +157,16 @@ class NodeDB: node.flags['vpn'] = True def map_link(self, pair): - distance = 80 - strength = 0.2 + type = None + if any(filter(lambda x: self._nodes[x].flags['vpn'], pair[0])): + type = "vpn" + if any(filter(lambda x: self._nodes[x].flags['client'], pair[0])): - distance = 10 - strength = 1 + type = "client" link = Link() link.pair = pair[0] - link.distance = distance - link.strength = strength + link.type = type link.quality = pair[1] return link