From f1512a6ed7c5752b5b7312a8c1eccbc8d1f6aa62 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Sun, 29 Mar 2015 17:54:43 +0200 Subject: [PATCH] generalize setData/dataTargets --- lib/main.js | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/main.js b/lib/main.js index 9d8a23f..6b612f6 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,27 +1,33 @@ define(["config", "moment", "chroma-js", "router", "map", "sidebar", "tabs", "container", "meshstats", "linklist", "nodelist", "simplenodelist", "infobox/main", "leaflet"], function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshstats, Linklist, Nodelist, SimpleNodelist, Infobox, L) { return function () { - var linklist, lostnodeslist, map, meshstats, newnodeslist, nodelist, router + var dataTargets = [] + var router function createGUI() { moment.locale("de") - router = new Router() - var linkScale = chroma.scale(chroma.interpolate.bezier(["green", "yellow", "red"])).domain([1, 5]) var sidebar = new Sidebar(document.body) var infobox = new Infobox(config, sidebar, router) var tabs = new Tabs() var overview = new Container() - map = new Map(linkScale, sidebar, router) + var map = new Map(linkScale, sidebar, router) document.body.insertBefore(map.div, document.body.firstChild) - meshstats = new Meshstats() - newnodeslist = new SimpleNodelist(config, "new", "firstseen", router, "Neue Knoten") - lostnodeslist = new SimpleNodelist(config, "lost", "lastseen", router, "Verschwundene Knoten") - nodelist = new Nodelist(router) - linklist = new Linklist(linkScale, router) + var meshstats = new Meshstats() + var newnodeslist = new SimpleNodelist(config, "new", "firstseen", router, "Neue Knoten") + var lostnodeslist = new SimpleNodelist(config, "lost", "lastseen", router, "Verschwundene Knoten") + var nodelist = new Nodelist(router) + var linklist = new Linklist(linkScale, router) + + dataTargets.push(map) + dataTargets.push(meshstats) + dataTargets.push(newnodeslist) + dataTargets.push(lostnodeslist) + dataTargets.push(nodelist) + dataTargets.push(linklist) overview.add(meshstats) overview.add(newnodeslist) @@ -109,6 +115,8 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta } } + router = new Router() + var urls = [ config.dataPath + "nodes.json", config.dataPath + "graph.json" ] @@ -120,13 +128,9 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta }) .then(handleData) .then(function (d) { - map.setData(d) - meshstats.setData(d) - nodelist.setData(d) - linklist.setData(d) - newnodeslist.setData(d) - lostnodeslist.setData(d) - router.setData(d) + dataTargets.forEach(function (t) { + t.setData(d) + }) }) .then(function () { router.start() })