From cff596d42a09de543fe4e4a510952cf08687703e Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Fri, 16 Jan 2015 02:12:24 -0800 Subject: [PATCH] diag/net: more powerfil d3 vis --- diagnostics/d3/chord.html | 12 +++++++++--- diagnostics/vis.go | 8 +++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/diagnostics/d3/chord.html b/diagnostics/d3/chord.html index 333862b74..9f5b311d8 100644 --- a/diagnostics/d3/chord.html +++ b/diagnostics/d3/chord.html @@ -109,9 +109,12 @@ d3.json(hash, function(error, data) { .attr("dy", 3) // .attr("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; }) // .attr("transform", function(d) { return d.x < 180 ? null : "rotate(180)"; }) - .text(function(d) { return d.conns + " - " + d.name; }) + .text(function(d) { return d.conns + " - " + (d.rtkey || d.name); }) .attr("transform", function(d) { return "rotate(" + (d.x - 90 + rotate) + ")translate(" + d.y + ")"; }) + node.append("svg:title") + .text(function(d) { return d.name; }); + // var mid = svg.selectAll(".node-mid") // .data(graph.mids) // .enter().append("g") @@ -135,8 +138,11 @@ function parseGraph(graph2) { graph.mids = [] graph2.nodes.sort(function(a, b) { - if (a.name > b.name) return 1; - if (a.name < b.name) return -1; + var aname = a.rtkey || a.name + var bname = b.rtkey || b.name + + if (aname > bname) return 1; + if (aname < bname) return -1; return 0; }) diff --git a/diagnostics/vis.go b/diagnostics/vis.go index 77cf29dc5..bbf180cd5 100644 --- a/diagnostics/vis.go +++ b/diagnostics/vis.go @@ -4,11 +4,15 @@ import ( "encoding/json" "fmt" "io" + + peer "github.com/jbenet/go-ipfs/p2p/peer" + rtable "github.com/jbenet/go-ipfs/routing/kbucket" ) type node struct { Name string `json:"name"` Value uint64 `json:"value"` + RtKey string `json:"rtkey"` } type link struct { @@ -24,7 +28,9 @@ func GetGraphJson(dinfo []*DiagInfo) []byte { for _, di := range dinfo { names[di.ID] = len(nodes) val := di.BwIn + di.BwOut + 10 - nodes = append(nodes, &node{Name: di.ID, Value: val}) + // include the routing table key, for proper routing table display + rtk := peer.ID(rtable.ConvertPeerID(peer.ID(di.ID))).Pretty() + nodes = append(nodes, &node{Name: di.ID, Value: val, RtKey: rtk}) } var links []*link