hopglass/lib/gui.js

106 lines
3 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-05 23:44:43 +02:00
"proportions", "forcegraph", "title" ],
2015-03-29 19:54:43 +02:00
function (chroma, Map, Sidebar, Tabs, Container, Meshstats, Linklist,
2015-04-05 23:44:43 +02:00
Nodelist, SimpleNodelist, Infobox, Proportions, ForceGraph, Title) {
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
var linkScale = chroma.scale(chroma.interpolate.bezier(["green", "yellow", "red"])).domain([1, 5])
var sidebar
2015-04-01 03:55:45 +02:00
function removeContent() {
if (!content)
return
router.removeTarget(content)
content.destroy()
contentDiv.removeChild(content.div)
2015-04-01 03:55:45 +02:00
content = null
}
function addContent(K) {
removeContent()
content = new K(config, linkScale, sidebar, router)
contentDiv.appendChild(content.div)
2015-04-01 03:55:45 +02:00
if (latestData)
content.setData(latestData)
dataTargets.push(content)
router.addTarget(content)
router.reload()
}
contentDiv = document.createElement("div")
contentDiv.classList.add("content")
document.body.appendChild(contentDiv)
sidebar = new Sidebar(document.body)
2015-04-01 03:55:45 +02:00
var buttonToggle = document.createElement("button")
buttonToggle.classList.add("contenttoggle")
buttonToggle.classList.add("next-graph")
buttonToggle.onclick = function () {
if (content.constructor === Map) {
buttonToggle.classList.remove("next-graph")
buttonToggle.classList.add("next-map")
addContent(ForceGraph)
} else {
buttonToggle.classList.remove("next-map")
buttonToggle.classList.add("next-graph")
addContent(Map)
}
}
contentDiv.appendChild(buttonToggle)
2015-04-01 03:55:45 +02:00
2015-04-05 23:44:43 +02:00
var title = new Title(config)
2015-03-29 19:54:43 +02:00
var infobox = new Infobox(config, sidebar, router)
var tabs = new Tabs()
var overview = new Container()
var meshstats = new Meshstats()
var newnodeslist = new SimpleNodelist(config, "new", "firstseen", router, "Neue Knoten")
var lostnodeslist = new SimpleNodelist(config, "lost", "lastseen", router, "Verschwundene Knoten")
var nodelist = new Nodelist(router)
var linklist = new Linklist(linkScale, router)
2015-03-30 02:58:47 +02:00
var statistics = new Proportions()
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
overview.add(meshstats)
overview.add(newnodeslist)
overview.add(lostnodeslist)
sidebar.add(tabs)
tabs.add("Übersicht", overview)
tabs.add("Alle Knoten", nodelist)
tabs.add("Verbindungen", linklist)
2015-03-30 02:58:47 +02:00
tabs.add("Statistiken", statistics)
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
addContent(Map)
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
}
})