gui.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. define([ "chroma-js", "map", "sidebar", "tabs", "container", "meshstats",
  2. "legend", "linklist", "nodelist", "simplenodelist", "infobox/main",
  3. "proportions", "forcegraph", "title", "about", "datadistributor",
  4. "filters/filtergui", "filters/hostname" ],
  5. function (chroma, Map, Sidebar, Tabs, Container, Meshstats, Legend, Linklist,
  6. Nodelist, SimpleNodelist, Infobox, Proportions, ForceGraph,
  7. Title, About, DataDistributor, FilterGUI, HostnameFilter) {
  8. return function (config, router) {
  9. var self = this
  10. var content
  11. var contentDiv
  12. var linkScale = chroma.scale(chroma.interpolate.bezier(["#04C714", "#FF5500", "#F02311"])).domain([1, 5])
  13. var sidebar
  14. var buttons = document.createElement("div")
  15. buttons.classList.add("buttons")
  16. var fanout = new DataDistributor()
  17. var fanoutUnfiltered = new DataDistributor()
  18. fanoutUnfiltered.add(fanout)
  19. function removeContent() {
  20. if (!content)
  21. return
  22. router.removeTarget(content)
  23. fanout.remove(content)
  24. content.destroy()
  25. content = null
  26. }
  27. function addContent(K) {
  28. removeContent()
  29. content = new K(config, linkScale, sidebar.getWidth, router, buttons)
  30. content.render(contentDiv)
  31. fanout.add(content)
  32. router.addTarget(content)
  33. }
  34. function mkView(K) {
  35. return function () {
  36. addContent(K)
  37. }
  38. }
  39. contentDiv = document.createElement("div")
  40. contentDiv.classList.add("content")
  41. document.body.appendChild(contentDiv)
  42. sidebar = new Sidebar(document.body)
  43. contentDiv.appendChild(buttons)
  44. var buttonToggle = document.createElement("button")
  45. buttonToggle.textContent = ""
  46. buttonToggle.onclick = function () {
  47. if (content.constructor === Map)
  48. router.view("g")
  49. else
  50. router.view("m")
  51. }
  52. buttons.appendChild(buttonToggle)
  53. var title = new Title(config)
  54. var header = new Container("header")
  55. var infobox = new Infobox(config, sidebar, router)
  56. var tabs = new Tabs()
  57. var overview = new Container()
  58. var meshstats = new Meshstats(config)
  59. var legend = new Legend()
  60. var newnodeslist = new SimpleNodelist("new", "firstseen", router, "Neue Knoten")
  61. var lostnodeslist = new SimpleNodelist("lost", "lastseen", router, "Verschwundene Knoten")
  62. var nodelist = new Nodelist(router)
  63. var linklist = new Linklist(linkScale, router)
  64. var statistics = new Proportions(config, fanout)
  65. var about = new About()
  66. fanoutUnfiltered.add(meshstats)
  67. fanoutUnfiltered.add(newnodeslist)
  68. fanoutUnfiltered.add(lostnodeslist)
  69. fanout.add(nodelist)
  70. fanout.add(linklist)
  71. fanout.add(statistics)
  72. sidebar.add(header)
  73. header.add(meshstats)
  74. header.add(legend)
  75. overview.add(newnodeslist)
  76. overview.add(lostnodeslist)
  77. var filterGUI = new FilterGUI(fanout)
  78. fanout.watchFilters(filterGUI)
  79. header.add(filterGUI)
  80. var hostnameFilter = new HostnameFilter()
  81. fanout.addFilter(hostnameFilter)
  82. sidebar.add(tabs)
  83. tabs.add("Aktuelles", overview)
  84. tabs.add("Knoten", nodelist)
  85. tabs.add("Verbindungen", linklist)
  86. tabs.add("Statistiken", statistics)
  87. tabs.add("Über", about)
  88. router.addTarget(title)
  89. router.addTarget(infobox)
  90. router.addView("m", mkView(Map))
  91. router.addView("g", mkView(ForceGraph))
  92. router.view("m")
  93. self.setData = fanoutUnfiltered.setData
  94. return self
  95. }
  96. })