This commit is contained in:
Nils Schneider 2012-02-17 03:10:46 +01:00
parent 1e6302680c
commit c8567b1062
3 changed files with 7 additions and 15 deletions

View file

@ -29,7 +29,7 @@ nodes = []
class Node(): class Node():
def __init__(self): def __init__(self):
self.name = None self.name = ""
self.macs = set() self.macs = set()
self.group = 0 self.group = 0
# groups: # groups:
@ -39,9 +39,6 @@ class Node():
# 3 TT # 3 TT
def add_mac(self, mac): def add_mac(self, mac):
if len(self.macs) == 0 and not self.name:
self.name = mac
self.macs.add(mac) self.macs.add(mac)
def __repr__(self): def __repr__(self):
@ -103,13 +100,6 @@ for line in lines:
for line in lines: for line in lines:
x = json.loads(line) x = json.loads(line)
if 'primary' in x:
try:
node = maybe_node_by_mac(nodes, (x['primary'], ))
node.name = x['primary']
except:
pass
if 'router' in x: if 'router' in x:
try: try:
if 'gateway' in x: if 'gateway' in x:
@ -163,7 +153,9 @@ links = map(lambda x: map_link(nodes, x), links)
output = dict() output = dict()
output['nodes'] = map(lambda x: {'group': x.group, 'name': x.name}, nodes) output['nodes'] = map(lambda x: {'group': x.group, 'name': x.name,
'macs': ', '.join(x.macs)
}, nodes)
output['links'] = map(lambda x: {'source': x.pair[0], 'target': x.pair[1], output['links'] = map(lambda x: {'source': x.pair[0], 'target': x.pair[1],
'distance': x.distance, 'distance': x.distance,
'strength': x.strength 'strength': x.strength

View file

@ -36,7 +36,7 @@ d3.json("nodes.json", function(json) {
.call(force.drag); .call(force.drag);
node.append("ellipse") node.append("ellipse")
.attr("rx", function(d) { if (d.group == 3) return 4; else return d.name.length * 5; }) .attr("rx", function(d) { if (d.group == 3) return 4; else return Math.max(14, d.name.length * 5); })
.attr("ry", function(d) { if (d.group == 3) return 4; else return 14; }) .attr("ry", function(d) { if (d.group == 3) return 4; else return 14; })
.style("fill", function(d) { if (d.group == 3) return fill(d.group); else return ""; }) .style("fill", function(d) { if (d.group == 3) return fill(d.group); else return ""; })
.style("stroke", function(d) { return fill(d.group); }); .style("stroke", function(d) { return fill(d.group); });
@ -48,7 +48,7 @@ d3.json("nodes.json", function(json) {
.text(function(d) { if (d.group == 3) return ""; else return d.name; }); .text(function(d) { if (d.group == 3) return ""; else return d.name; });
node.append("title") node.append("title")
.text(function(d) { return d.name; }); .text(function(d) { return d.macs; });
force.on("tick", function() { force.on("tick", function() {
link.attr("x1", function(d) { return d.source.x; }) link.attr("x1", function(d) { return d.source.x; })

View file

@ -8,4 +8,4 @@ mkdir $DEST
cp html/* $DEST/ cp html/* $DEST/
batctl vd json|python ./bat2nodes.py -a aliases.json $GWS - > $DEST/nodes.json ssh 188.138.99.158 batctl vd json|python ./bat2nodes.py -a aliases.json $GWS - > $DEST/nodes.json