From 912ea821e9eb4cac8ba17f60e3956709ad4bc326 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Wed, 6 Jun 2012 06:03:30 +0200 Subject: [PATCH] fix update mechanism --- html/force.js | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/html/force.js b/html/force.js index 6143c4e..9ea139e 100644 --- a/html/force.js +++ b/html/force.js @@ -187,12 +187,35 @@ var visible = {clients: true, vpn: true} function reload() { d3.json("nodes.json", function(json) { + // update existing nodes with new info + // XXX inefficient data structure + json.nodes.forEach(function(d, i) { + var n + force.nodes().forEach(function(x) {if (x.id == d.id) n = x}) + if (n) { + for (var key in d) + if (d.hasOwnProperty(key)) + n[key] = d[key] + json.nodes[i] = n + } + }) + + json.links.forEach(function(d, i) { + var n + force.links().forEach(function(x) {if (x.id == d.id) n = x}) + if (n) { + json.links[i] = n + } + }) + + // replace indices with real objects json.links.forEach( function(d) { if (typeof d.source == "number") d.source = json.nodes[d.source]; if (typeof d.target == "number") d.target = json.nodes[d.target]; }) + // count uplinks json.links.forEach(function(d) { var node, other @@ -214,28 +237,6 @@ function reload() { } }) - // update existing nodes with new info - json.nodes.forEach(function(d, i) { - var n - force.nodes().forEach(function(x) {if (x.id == d.id) n = x}) - if (n) { - for (var key in d) - if (d.hasOwnProperty(key)) - n[key] = d[key] - - json.nodes[i] = n - } - }) - - json.links.forEach(function(d) { - var n - force.links().forEach(function(x) {if (x.id == d.id) n = x}) - if (n) { - d.source = n.source - d.target = n.target - } - }) - data = json update()