gui.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. define([ "chroma-js", "map", "sidebar", "tabs", "container", "meshstats",
  2. "linklist", "nodelist", "simplenodelist", "infobox/main",
  3. "proportions", "forcegraph", "title", "about" ],
  4. function (chroma, Map, Sidebar, Tabs, Container, Meshstats, Linklist,
  5. Nodelist, SimpleNodelist, Infobox, Proportions, ForceGraph,
  6. Title, About) {
  7. return function (config, router) {
  8. var self = this
  9. var dataTargets = []
  10. var latestData
  11. var content
  12. var contentDiv
  13. var linkScale = chroma.scale(chroma.interpolate.bezier(["green", "yellow", "red"])).domain([1, 5])
  14. var sidebar
  15. function dataTargetRemove(d) {
  16. dataTargets = dataTargets.filter( function (e) { return d !== e })
  17. }
  18. function removeContent() {
  19. if (!content)
  20. return
  21. router.removeTarget(content)
  22. dataTargetRemove(content)
  23. content.destroy()
  24. contentDiv.removeChild(content.div)
  25. content = null
  26. }
  27. function addContent(K) {
  28. removeContent()
  29. content = new K(config, linkScale, sidebar, router)
  30. contentDiv.appendChild(content.div)
  31. if (latestData)
  32. content.setData(latestData)
  33. dataTargets.push(content)
  34. router.addTarget(content)
  35. router.reload()
  36. }
  37. contentDiv = document.createElement("div")
  38. contentDiv.classList.add("content")
  39. document.body.appendChild(contentDiv)
  40. sidebar = new Sidebar(document.body)
  41. var buttonToggle = document.createElement("button")
  42. buttonToggle.classList.add("contenttoggle")
  43. buttonToggle.classList.add("next-graph")
  44. buttonToggle.onclick = function () {
  45. if (content.constructor === Map) {
  46. buttonToggle.classList.remove("next-graph")
  47. buttonToggle.classList.add("next-map")
  48. addContent(ForceGraph)
  49. } else {
  50. buttonToggle.classList.remove("next-map")
  51. buttonToggle.classList.add("next-graph")
  52. addContent(Map)
  53. }
  54. }
  55. contentDiv.appendChild(buttonToggle)
  56. var title = new Title(config)
  57. var infobox = new Infobox(config, sidebar, router)
  58. var tabs = new Tabs()
  59. var overview = new Container()
  60. var meshstats = new Meshstats()
  61. var newnodeslist = new SimpleNodelist(config, "new", "firstseen", router, "Neue Knoten")
  62. var lostnodeslist = new SimpleNodelist(config, "lost", "lastseen", router, "Verschwundene Knoten")
  63. var nodelist = new Nodelist(router)
  64. var linklist = new Linklist(linkScale, router)
  65. var statistics = new Proportions()
  66. var about = new About()
  67. dataTargets.push(meshstats)
  68. dataTargets.push(newnodeslist)
  69. dataTargets.push(lostnodeslist)
  70. dataTargets.push(nodelist)
  71. dataTargets.push(linklist)
  72. dataTargets.push(statistics)
  73. overview.add(meshstats)
  74. overview.add(newnodeslist)
  75. overview.add(lostnodeslist)
  76. sidebar.add(tabs)
  77. tabs.add("Übersicht", overview)
  78. tabs.add("Knoten", nodelist)
  79. tabs.add("Verbindungen", linklist)
  80. tabs.add("Statistiken", statistics)
  81. tabs.add("Über", about)
  82. router.addTarget(title)
  83. router.addTarget(infobox)
  84. addContent(Map)
  85. self.setData = function (data) {
  86. latestData = data
  87. dataTargets.forEach(function (d) {
  88. d.setData(data)
  89. })
  90. }
  91. return self
  92. }
  93. })