hopglass/lib/gui.js

126 lines
3.2 KiB
JavaScript
Raw Normal View History

2015-03-29 19:54:43 +02:00
define([ "chroma-js", "map", "sidebar", "tabs", "container", "meshstats",
2015-03-30 02:58:47 +02:00
"linklist", "nodelist", "simplenodelist", "infobox/main",
2015-04-07 22:06:12 +02:00
"proportions", "forcegraph", "title", "about" ],
2015-03-29 19:54:43 +02:00
function (chroma, Map, Sidebar, Tabs, Container, Meshstats, Linklist,
2015-04-07 22:06:12 +02:00
Nodelist, SimpleNodelist, Infobox, Proportions, ForceGraph,
Title, About) {
2015-03-29 19:54:43 +02:00
return function (config, router) {
var self = this
var dataTargets = []
2015-04-01 03:55:45 +02:00
var latestData
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")
function dataTargetRemove(d) {
dataTargets = dataTargets.filter( function (e) { return d !== e })
}
2015-04-01 03:55:45 +02:00
function removeContent() {
if (!content)
return
router.removeTarget(content)
dataTargetRemove(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
if (latestData)
content.setData(latestData)
dataTargets.push(content)
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
}
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")
2015-07-07 12:51:12 +02:00
buttonToggle.textContent = ""
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)
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)
var statistics = new Proportions(config)
2015-04-07 22:06:12 +02:00
var about = new About()
2015-03-29 19:54:43 +02:00
dataTargets.push(meshstats)
dataTargets.push(newnodeslist)
dataTargets.push(lostnodeslist)
dataTargets.push(nodelist)
dataTargets.push(linklist)
2015-03-30 02:58:47 +02:00
dataTargets.push(statistics)
2015-03-29 19:54:43 +02:00
2015-07-08 21:28:26 +02:00
sidebar.add(header)
header.add(meshstats)
2015-03-29 19:54:43 +02:00
overview.add(newnodeslist)
overview.add(lostnodeslist)
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 = function (data) {
2015-04-01 03:55:45 +02:00
latestData = data
2015-03-29 19:54:43 +02:00
dataTargets.forEach(function (d) {
d.setData(data)
})
}
return self
}
})