meshviewer/lib/gui.js

120 lines
3.2 KiB
JavaScript
Raw Normal View History

2015-03-29 17:54:43 +00:00
define([ "chroma-js", "map", "sidebar", "tabs", "container", "meshstats",
2015-08-26 23:31:19 +00:00
"legend", "linklist", "nodelist", "simplenodelist", "infobox/main",
2015-07-07 22:36:57 +00:00
"proportions", "forcegraph", "title", "about", "datadistributor",
"filters/filtergui" ],
2015-08-26 23:31:19 +00:00
function (chroma, Map, Sidebar, Tabs, Container, Meshstats, Legend, Linklist,
2015-04-07 20:06:12 +00:00
Nodelist, SimpleNodelist, Infobox, Proportions, ForceGraph,
2015-07-07 22:36:57 +00:00
Title, About, DataDistributor, FilterGUI) {
2015-03-29 17:54:43 +00:00
return function (config, router) {
var self = this
2015-07-07 22:36:57 +00:00
var fanout = new DataDistributor()
2015-04-01 01:55:45 +00:00
var content
var contentDiv
2015-03-29 17:54:43 +00:00
2015-07-07 10:42:57 +00:00
var linkScale = chroma.scale(chroma.interpolate.bezier(["#04C714", "#FF5500", "#F02311"])).domain([1, 5])
var sidebar
2015-04-01 01:55:45 +00:00
var buttons = document.createElement("div")
buttons.classList.add("buttons")
2015-04-01 01:55:45 +00:00
function removeContent() {
if (!content)
return
router.removeTarget(content)
2015-07-07 22:36:57 +00:00
fanout.remove(content)
2015-04-01 01:55:45 +00:00
content.destroy()
2015-07-11 22:11:18 +00:00
2015-04-01 01:55:45 +00:00
content = null
}
function addContent(K) {
removeContent()
content = new K(config, linkScale, sidebar.getWidth, router, buttons)
2015-07-11 22:11:18 +00:00
content.render(contentDiv)
2015-04-01 01:55:45 +00:00
2015-07-07 22:36:57 +00:00
fanout.add(content)
2015-04-01 01:55:45 +00:00
router.addTarget(content)
2015-07-06 22:06:38 +00:00
}
function mkView(K) {
return function () {
addContent(K)
}
2015-04-01 01:55:45 +00:00
}
contentDiv = document.createElement("div")
contentDiv.classList.add("content")
document.body.appendChild(contentDiv)
sidebar = new Sidebar(document.body)
contentDiv.appendChild(buttons)
2015-04-01 01:55:45 +00:00
var buttonToggle = document.createElement("button")
2015-07-07 10:51:12 +00:00
buttonToggle.textContent = ""
2015-04-01 01:55:45 +00:00
buttonToggle.onclick = function () {
2015-07-07 10:51:12 +00:00
if (content.constructor === Map)
2015-07-06 22:06:38 +00:00
router.view("g")
2015-07-07 10:51:12 +00:00
else
2015-07-06 22:06:38 +00:00
router.view("m")
2015-04-01 01:55:45 +00:00
}
buttons.appendChild(buttonToggle)
2015-04-01 01:55:45 +00:00
2015-04-05 21:44:43 +00:00
var title = new Title(config)
2015-07-08 19:28:26 +00:00
var header = new Container("header")
2015-03-29 17:54:43 +00:00
var infobox = new Infobox(config, sidebar, router)
var tabs = new Tabs()
var overview = new Container()
2015-07-08 14:32:26 +00:00
var meshstats = new Meshstats(config)
2015-08-26 23:31:19 +00:00
var legend = new Legend()
var newnodeslist = new SimpleNodelist("new", "firstseen", router, "Neue Knoten")
var lostnodeslist = new SimpleNodelist("lost", "lastseen", router, "Verschwundene Knoten")
2015-03-29 17:54:43 +00:00
var nodelist = new Nodelist(router)
var linklist = new Linklist(linkScale, router)
2015-07-07 22:36:57 +00:00
var statistics = new Proportions(config, fanout)
2015-04-07 20:06:12 +00:00
var about = new About()
2015-03-29 17:54:43 +00:00
2015-07-07 22:36:57 +00:00
fanout.add(meshstats)
fanout.add(newnodeslist)
fanout.add(lostnodeslist)
fanout.add(nodelist)
fanout.add(linklist)
fanout.add(statistics)
2015-03-29 17:54:43 +00:00
2015-07-08 19:28:26 +00:00
sidebar.add(header)
header.add(meshstats)
2015-08-26 23:31:19 +00:00
header.add(legend)
2015-07-08 19:28:26 +00:00
2015-03-29 17:54:43 +00:00
overview.add(newnodeslist)
overview.add(lostnodeslist)
2015-07-07 22:36:57 +00:00
var filterGUI = new FilterGUI(fanout)
fanout.watchFilters(filterGUI)
header.add(filterGUI)
2015-03-29 17:54:43 +00:00
sidebar.add(tabs)
2015-07-08 19:28:26 +00:00
tabs.add("Aktuelles", overview)
2015-04-07 20:06:12 +00:00
tabs.add("Knoten", nodelist)
2015-03-29 17:54:43 +00:00
tabs.add("Verbindungen", linklist)
2015-03-30 00:58:47 +00:00
tabs.add("Statistiken", statistics)
2015-04-07 20:06:12 +00:00
tabs.add("Über", about)
2015-03-29 17:54:43 +00:00
2015-04-05 21:44:43 +00:00
router.addTarget(title)
2015-03-29 17:54:43 +00:00
router.addTarget(infobox)
2015-04-01 01:55:45 +00:00
2015-07-06 22:06:38 +00:00
router.addView("m", mkView(Map))
router.addView("g", mkView(ForceGraph))
router.view("m")
2015-03-29 17:54:43 +00:00
2015-07-07 22:36:57 +00:00
self.setData = fanout.setData
2015-03-29 17:54:43 +00:00
return self
}
})