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