main.js: create only after data is ready

This commit is contained in:
Nils Schneider 2015-03-25 21:19:52 +01:00
parent 64c9e42eb4
commit 090254c781

View File

@ -3,34 +3,40 @@ function (Router, Map, Sidebar, Meshstats, Linklist, SimpleNodelist, Infobox) {
getJSON("config.json").then(main) getJSON("config.json").then(main)
function main(config) { function main(config) {
moment.locale("de") var linklist, lostnodeslist, map, meshstats, newnodeslist, router
var linkScale = chroma.scale(chroma.interpolate.bezier(['green', 'yellow', 'red'])).domain([1, 5]) function createGUI() {
var sidebar = new Sidebar(document.body) moment.locale("de")
var router = new Router(config)
var map = new Map(linkScale, sidebar, router) router = new Router(config)
document.body.insertBefore(map.div, document.body.firstChild)
var infobox = new Infobox(config, sidebar, router) var linkScale = chroma.scale(chroma.interpolate.bezier(['green', 'yellow', 'red'])).domain([1, 5])
var meshstats = new Meshstats() var sidebar = new Sidebar(document.body)
var newnodeslist = new SimpleNodelist(config, "firstseen", router, "Neue Knoten") var infobox = new Infobox(config, sidebar, router)
var lostnodeslist = new SimpleNodelist(config, "lastseen", router, "Verschwundene Knoten")
var linklist = new Linklist(linkScale, router)
sidebar.add(meshstats) map = new Map(linkScale, sidebar, router)
sidebar.add(newnodeslist) document.body.insertBefore(map.div, document.body.firstChild)
sidebar.add(lostnodeslist)
sidebar.add(linklist)
router.addTarget(infobox) meshstats = new Meshstats()
router.addTarget(map) newnodeslist = new SimpleNodelist(config, "firstseen", router, "Neue Knoten")
lostnodeslist = new SimpleNodelist(config, "lastseen", router, "Verschwundene Knoten")
linklist = new Linklist(linkScale, router)
sidebar.add(meshstats)
sidebar.add(newnodeslist)
sidebar.add(lostnodeslist)
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'
] ]
Promise.all(urls.map(getJSON)) Promise.all(urls.map(getJSON))
.then(function (d) { createGUI(); return d })
.then(handle_data) .then(handle_data)
.then(function () { router.loadState(window.location.hash) }) .then(function () { router.loadState(window.location.hash) })