refactor main.js

This commit is contained in:
Nils Schneider 2015-03-25 21:11:15 +01:00
parent c79dff9111
commit 5b352d7a32

View File

@ -1,48 +1,40 @@
require(["router", "map", "sidebar", "meshstats", "linklist", "simplenodelist", "infobox/main"],
function (Router, Map, Sidebar, Meshstats, Linklist, SimpleNodelist, Infobox) {
main()
getJSON("config.json").then(main)
function main() {
getJSON("config.json").then( function (config) {
moment.locale("de")
function main(config) {
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 router = new Router(config)
var sidebar = new Sidebar(document.body)
var map = new Map(linkScale, sidebar, router)
document.body.insertBefore(map.div, document.body.firstChild)
var router = new Router(config)
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)
var infobox = new Infobox(config, sidebar, router)
router.addTarget(infobox)
sidebar.add(meshstats)
sidebar.add(newnodeslist)
sidebar.add(lostnodeslist)
sidebar.add(linklist)
var map = new Map(linkScale, sidebar, router)
document.body.insertBefore(map.div, document.body.firstChild)
router.addTarget(map)
router.addTarget(infobox)
router.addTarget(map)
var meshstats = new Meshstats()
sidebar.add(meshstats)
var urls = [ config.dataPath + 'nodes.json',
config.dataPath + 'graph.json'
]
var newnodeslist = new SimpleNodelist(config, "firstseen", router, "Neue Knoten")
sidebar.add(newnodeslist)
Promise.all(urls.map(getJSON))
.then(handle_data)
.then(function () { router.loadState(window.location.hash) })
var lostnodeslist = new SimpleNodelist(config, "lastseen", router, "Verschwundene Knoten")
sidebar.add(lostnodeslist)
var linklist = new Linklist(linkScale, router)
sidebar.add(linklist)
var urls = [ config.dataPath + 'nodes.json',
config.dataPath + 'graph.json'
]
var p = Promise.all(urls.map(getJSON))
p.then(handle_data(sidebar, meshstats, linklist, newnodeslist, lostnodeslist, infobox, map, router))
.then(function () { router.loadState(window.location.hash) })
})
}
function handle_data(sidebar, meshstats, linklist, newnodeslist, lostnodeslist, infobox, map, router) {
return function (data) {
function handle_data(data) {
var nodedict = data[0]
var nodes = Object.keys(nodedict.nodes).map(function (key) { return nodedict.nodes[key] })