hopglass/lib/gui.js

126 lines
3.4 KiB
JavaScript
Raw Permalink Normal View History

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