meshviewer/lib/gui.js

122 lines
3.3 KiB
JavaScript
Raw Normal View History

2015-03-29 17:54:43 +00:00
define([ "chroma-js", "map", "sidebar", "tabs", "container", "meshstats",
2015-03-30 00:58:47 +00:00
"linklist", "nodelist", "simplenodelist", "infobox/main",
2015-04-07 20:06:12 +00:00
"proportions", "forcegraph", "title", "about" ],
2015-03-29 17:54:43 +00:00
function (chroma, Map, Sidebar, Tabs, Container, Meshstats, Linklist,
2015-04-07 20:06:12 +00:00
Nodelist, SimpleNodelist, Infobox, Proportions, ForceGraph,
Title, About) {
2015-03-29 17:54:43 +00:00
return function (config, router) {
var self = this
var dataTargets = []
2015-04-01 01:55:45 +00:00
var latestData
var content
var contentDiv
2015-03-29 17:54:43 +00:00
var linkScale = chroma.scale(chroma.interpolate.bezier(["green", "yellow", "red"])).domain([1, 5])
var sidebar
2015-04-01 01:55:45 +00:00
function dataTargetRemove(d) {
dataTargets = dataTargets.filter( function (e) { return d !== e })
}
2015-04-01 01:55:45 +00:00
function removeContent() {
if (!content)
return
router.removeTarget(content)
dataTargetRemove(content)
2015-04-01 01:55:45 +00:00
content.destroy()
contentDiv.removeChild(content.div)
2015-04-01 01:55:45 +00:00
content = null
}
function addContent(K) {
removeContent()
content = new K(config, linkScale, sidebar, router)
contentDiv.appendChild(content.div)
2015-04-01 01:55:45 +00:00
if (latestData)
content.setData(latestData)
dataTargets.push(content)
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)
2015-04-01 01:55:45 +00: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")
2015-07-06 22:06:38 +00:00
router.view("g")
2015-04-01 01:55:45 +00:00
} else {
buttonToggle.classList.remove("next-map")
buttonToggle.classList.add("next-graph")
2015-07-06 22:06:38 +00:00
router.view("m")
2015-04-01 01:55:45 +00:00
}
}
contentDiv.appendChild(buttonToggle)
2015-04-01 01:55:45 +00:00
2015-04-05 21:44:43 +00:00
var title = new Title(config)
2015-03-29 17:54:43 +00:00
var infobox = new Infobox(config, sidebar, router)
var tabs = new Tabs()
var overview = new Container()
var meshstats = new Meshstats()
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)
var statistics = new Proportions(config)
2015-04-07 20:06:12 +00:00
var about = new About()
2015-03-29 17:54:43 +00:00
dataTargets.push(meshstats)
dataTargets.push(newnodeslist)
dataTargets.push(lostnodeslist)
dataTargets.push(nodelist)
dataTargets.push(linklist)
2015-03-30 00:58:47 +00:00
dataTargets.push(statistics)
2015-03-29 17:54:43 +00:00
overview.add(meshstats)
overview.add(newnodeslist)
overview.add(lostnodeslist)
sidebar.add(tabs)
tabs.add("Übersicht", 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
self.setData = function (data) {
2015-04-01 01:55:45 +00:00
latestData = data
2015-03-29 17:54:43 +00:00
dataTargets.forEach(function (d) {
d.setData(data)
})
}
return self
}
})