work on forcegraph reload

This commit is contained in:
Nils Schneider 2015-04-03 02:32:32 +02:00
commit d6e0587c55
4 changed files with 105 additions and 61 deletions

View file

@ -1,8 +1,8 @@
define(["tablesort", "virtual-dom", "tablesort.numeric"],
function (Tablesort, V) {
define(["virtual-dom"],
function (V) {
return function(linkScale, router) {
var self = this
var el, tbody, sort
var el, tbody
self.render = function (d) {
el = document.createElement("div")
@ -34,7 +34,6 @@ define(["tablesort", "virtual-dom", "tablesort.numeric"],
var th3 = document.createElement("th")
th3.textContent = "Entfernung"
th3.classList.add("sort-default")
tr.appendChild(th3)
thead.appendChild(tr)
@ -43,11 +42,16 @@ define(["tablesort", "virtual-dom", "tablesort.numeric"],
tbody = document.createElement("tbody")
tbody.last = V.h("tbody")
table.appendChild(tbody)
sort = new Tablesort(table)
}
var items = data.graph.links.map( function (d) {
var links = data.graph.links.slice(0).sort( function (a, b) {
a = a.distance === undefined ? -1 : a.distance
b = b.distance === undefined ? -1 : b.distance
return b - a
})
var items = links.map( function (d) {
var name = d.source.node.nodeinfo.hostname + " " + d.target.node.nodeinfo.hostname
var td1Content = [V.h("a", {href: "#", onclick: router.link(d)}, name)]
@ -55,10 +59,8 @@ define(["tablesort", "virtual-dom", "tablesort.numeric"],
td1Content.push(" (VPN)")
var td1 = V.h("td", td1Content)
var td2 = V.h("td", {style: {color: linkScale(d.tq)}}, showTq(d))
var td3 = V.h("td", {attributes: {
"data-sort": d.distance !== undefined ? -d.distance : 1
}}, showDistance(d))
var td2 = V.h("td", {style: {color: linkScale(d.tq).hex()}}, showTq(d))
var td3 = V.h("td", showDistance(d))
return V.h("tr", [td1, td2, td3])
})
@ -66,7 +68,6 @@ define(["tablesort", "virtual-dom", "tablesort.numeric"],
var tbodyNew = V.h("tbody", items)
tbody = V.patch(tbody, V.diff(tbody.last, tbodyNew))
tbody.last = tbodyNew
sort.refresh()
}
}
})