refactor main.js
This commit is contained in:
parent
c79dff9111
commit
5b352d7a32
34
lib/main.js
34
lib/main.js
|
@ -1,48 +1,40 @@
|
||||||
require(["router", "map", "sidebar", "meshstats", "linklist", "simplenodelist", "infobox/main"],
|
require(["router", "map", "sidebar", "meshstats", "linklist", "simplenodelist", "infobox/main"],
|
||||||
function (Router, Map, Sidebar, Meshstats, Linklist, SimpleNodelist, Infobox) {
|
function (Router, Map, Sidebar, Meshstats, Linklist, SimpleNodelist, Infobox) {
|
||||||
main()
|
getJSON("config.json").then(main)
|
||||||
|
|
||||||
function main() {
|
function main(config) {
|
||||||
getJSON("config.json").then( function (config) {
|
|
||||||
moment.locale("de")
|
moment.locale("de")
|
||||||
|
|
||||||
var linkScale = chroma.scale(chroma.interpolate.bezier(['green', 'yellow', 'red'])).domain([1, 5])
|
var linkScale = chroma.scale(chroma.interpolate.bezier(['green', 'yellow', 'red'])).domain([1, 5])
|
||||||
|
|
||||||
var sidebar = new Sidebar(document.body)
|
var sidebar = new Sidebar(document.body)
|
||||||
|
|
||||||
var router = new Router(config)
|
var router = new Router(config)
|
||||||
|
|
||||||
var infobox = new Infobox(config, sidebar, router)
|
|
||||||
router.addTarget(infobox)
|
|
||||||
|
|
||||||
var map = new Map(linkScale, sidebar, router)
|
var map = new Map(linkScale, sidebar, router)
|
||||||
document.body.insertBefore(map.div, document.body.firstChild)
|
document.body.insertBefore(map.div, document.body.firstChild)
|
||||||
router.addTarget(map)
|
|
||||||
|
|
||||||
|
var infobox = new Infobox(config, sidebar, router)
|
||||||
var meshstats = new Meshstats()
|
var meshstats = new Meshstats()
|
||||||
sidebar.add(meshstats)
|
|
||||||
|
|
||||||
var newnodeslist = new SimpleNodelist(config, "firstseen", router, "Neue Knoten")
|
var newnodeslist = new SimpleNodelist(config, "firstseen", router, "Neue Knoten")
|
||||||
sidebar.add(newnodeslist)
|
|
||||||
|
|
||||||
var lostnodeslist = new SimpleNodelist(config, "lastseen", router, "Verschwundene Knoten")
|
var lostnodeslist = new SimpleNodelist(config, "lastseen", router, "Verschwundene Knoten")
|
||||||
sidebar.add(lostnodeslist)
|
|
||||||
|
|
||||||
var linklist = new Linklist(linkScale, router)
|
var linklist = new Linklist(linkScale, router)
|
||||||
|
|
||||||
|
sidebar.add(meshstats)
|
||||||
|
sidebar.add(newnodeslist)
|
||||||
|
sidebar.add(lostnodeslist)
|
||||||
sidebar.add(linklist)
|
sidebar.add(linklist)
|
||||||
|
|
||||||
|
router.addTarget(infobox)
|
||||||
|
router.addTarget(map)
|
||||||
|
|
||||||
var urls = [ config.dataPath + 'nodes.json',
|
var urls = [ config.dataPath + 'nodes.json',
|
||||||
config.dataPath + 'graph.json'
|
config.dataPath + 'graph.json'
|
||||||
]
|
]
|
||||||
|
|
||||||
var p = Promise.all(urls.map(getJSON))
|
Promise.all(urls.map(getJSON))
|
||||||
p.then(handle_data(sidebar, meshstats, linklist, newnodeslist, lostnodeslist, infobox, map, router))
|
.then(handle_data)
|
||||||
.then(function () { router.loadState(window.location.hash) })
|
.then(function () { router.loadState(window.location.hash) })
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function handle_data(sidebar, meshstats, linklist, newnodeslist, lostnodeslist, infobox, map, router) {
|
function handle_data(data) {
|
||||||
return function (data) {
|
|
||||||
var nodedict = data[0]
|
var nodedict = data[0]
|
||||||
var nodes = Object.keys(nodedict.nodes).map(function (key) { return nodedict.nodes[key] })
|
var nodes = Object.keys(nodedict.nodes).map(function (key) { return nodedict.nodes[key] })
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue