linklist.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. define(["sorttable", "virtual-dom"], function (SortTable, V) {
  2. function linkName(d) {
  3. return d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname
  4. }
  5. var headings = [{ name: "Knoten",
  6. sort: function (a, b) {
  7. return linkName(a).localeCompare(linkName(b))
  8. },
  9. reverse: false
  10. },
  11. { name: "TQ",
  12. sort: function (a, b) { return a.tq - b.tq},
  13. reverse: true
  14. },
  15. { name: "Entfernung",
  16. sort: function (a, b) {
  17. return (a.distance === undefined ? -1 : a.distance) -
  18. (b.distance === undefined ? -1 : b.distance)
  19. },
  20. reverse: true
  21. }]
  22. return function(linkScale, router) {
  23. var table = new SortTable(headings, 2, renderRow)
  24. function renderRow(d) {
  25. var td1Content = [V.h("a", {href: "#", onclick: router.link(d)}, linkName(d))]
  26. if (d.vpn)
  27. td1Content.push(" (VPN)")
  28. var td1 = V.h("td", td1Content)
  29. var td2 = V.h("td", {style: {color: linkScale(d.tq).hex()}}, showTq(d))
  30. var td3 = V.h("td", showDistance(d))
  31. return V.h("tr", [td1, td2, td3])
  32. }
  33. this.render = function (d) {
  34. var el = document.createElement("div")
  35. el.last = V.h("div")
  36. d.appendChild(el)
  37. var h2 = document.createElement("h2")
  38. h2.textContent = "Verbindungen"
  39. el.appendChild(h2)
  40. el.appendChild(table.el)
  41. }
  42. this.setData = function (d) {
  43. table.setData(d.graph.links)
  44. }
  45. }
  46. })