From 430889c07d71b78baca20c260aa1033011811750 Mon Sep 17 00:00:00 2001 From: Xaver Maierhofer Date: Thu, 26 Jan 2017 23:52:34 +0100 Subject: [PATCH] [TASK] Refactor legend/meshstats --- lib/gui.js | 12 +++++------ lib/legend.js | 34 +++++++++++++++++++++++++++--- lib/meshstats.js | 55 ------------------------------------------------ 3 files changed, 36 insertions(+), 65 deletions(-) delete mode 100644 lib/meshstats.js diff --git a/lib/gui.js b/lib/gui.js index 88640eb..a3d2609 100644 --- a/lib/gui.js +++ b/lib/gui.js @@ -1,8 +1,8 @@ -define(["chroma-js", "map", "sidebar", "tabs", "container", "meshstats", - "legend", "linklist", "nodelist", "simplenodelist", "infobox/main", +define(["chroma-js", "map", "sidebar", "tabs", "container", "legend", + "linklist", "nodelist", "simplenodelist", "infobox/main", "proportions", "forcegraph", "title", "about", "datadistributor", "filters/filtergui"], - function (chroma, Map, Sidebar, Tabs, Container, Meshstats, Legend, Linklist, + function (chroma, Map, Sidebar, Tabs, Container, Legend, Linklist, Nodelist, SimpleNodelist, Infobox, Proportions, ForceGraph, Title, About, DataDistributor, FilterGUI) { "use strict"; @@ -80,8 +80,7 @@ define(["chroma-js", "map", "sidebar", "tabs", "container", "meshstats", var infobox = new Infobox(config, sidebar, router); var tabs = new Tabs(); var overview = new Container(); - var meshstats = new Meshstats(config); - var legend = new Legend(); + var legend = new Legend(config); var newnodeslist = new SimpleNodelist("new", "firstseen", router, "Neue Knoten"); var lostnodeslist = new SimpleNodelist("lost", "lastseen", router, "Verschwundene Knoten"); var nodelist = new Nodelist(router); @@ -89,7 +88,7 @@ define(["chroma-js", "map", "sidebar", "tabs", "container", "meshstats", var statistics = new Proportions(config, fanout); var about = new About(); - fanoutUnfiltered.add(meshstats); + fanoutUnfiltered.add(legend); fanoutUnfiltered.add(newnodeslist); fanoutUnfiltered.add(lostnodeslist); fanout.add(nodelist); @@ -97,7 +96,6 @@ define(["chroma-js", "map", "sidebar", "tabs", "container", "meshstats", fanout.add(statistics); sidebar.add(header); - header.add(meshstats); header.add(legend); overview.add(newnodeslist); diff --git a/lib/legend.js b/lib/legend.js index 37c2b1b..edf8093 100644 --- a/lib/legend.js +++ b/lib/legend.js @@ -1,19 +1,47 @@ -define(function () { +define(["helper"], function (helper) { "use strict"; - return function () { + return function (config) { var self = this; + var stats = document.createTextNode(""); + var timestamp = document.createTextNode(""); + + self.setData = function (d) { + var totalNodes = helper.sum(d.nodes.all.map(helper.one)); + var totalOnlineNodes = helper.sum(d.nodes.all.filter(helper.online).map(helper.one)); + var totalClients = helper.sum(d.nodes.all.filter(helper.online).map(function (d) { + return d.statistics.clients ? d.statistics.clients : 0; + })); + var totalGateways = helper.sum(d.nodes.all.filter(helper.online).filter(function (d) { + return d.flags.gateway; + }).map(helper.one)); + + stats.textContent = totalNodes + " Knoten, " + + "davon " + totalOnlineNodes + " Knoten online " + + "mit " + totalClients + " Client" + ( totalClients === 1 ? " " : "s " ) + + "auf " + totalGateways + " Gateway" + ( totalGateways === 1 ? "" : "s" ); + + timestamp.textContent = "Stand: " + d.timestamp.format("DD.MM.Y HH:mm"); + }; self.render = function (el) { + var h2 = document.createElement("h2"); + h2.textContent = config.siteName; + el.appendChild(h2); + var p = document.createElement("p"); p.classList.add("legend"); p.innerHTML = ' Neuer Knoten' + ' Knoten ist online' + ' Knoten ist offline'; el.appendChild(p); + + p.appendChild(document.createElement("br")); + p.appendChild(stats); + p.appendChild(document.createElement("br")); + p.appendChild(timestamp); }; return self; }; }); - diff --git a/lib/meshstats.js b/lib/meshstats.js deleted file mode 100644 index 1acaf43..0000000 --- a/lib/meshstats.js +++ /dev/null @@ -1,55 +0,0 @@ -define(["helper"], function (helper) { - "use strict"; - - return function (config) { - var self = this; - var stats, timestamp; - - self.setData = function (d) { - var totalNodes = helper.sum(d.nodes.all.map(helper.one)); - var totalOnlineNodes = helper.sum(d.nodes.all.filter(helper.online).map(helper.one)); - var totalNewNodes = helper.sum(d.nodes.new.map(helper.one)); - var totalLostNodes = helper.sum(d.nodes.lost.map(helper.one)); - var totalClients = helper.sum(d.nodes.all.filter(helper.online).map(function (d) { - return d.statistics.clients ? d.statistics.clients : 0; - })); - var totalGateways = helper.sum(d.nodes.all.filter(helper.online).filter(function (d) { - return d.flags.gateway; - }).map(helper.one)); - - var nodetext = [{count: totalOnlineNodes, label: "online"}, - {count: totalNewNodes, label: "neu"}, - {count: totalLostNodes, label: "verschwunden"} - ].filter(function (d) { - return d.count > 0; - }) - .map(function (d) { - return [d.count, d.label].join(" "); - }) - .join(", "); - - stats.textContent = totalNodes + " Knoten " + - "(" + nodetext + "), " + - totalClients + " Client" + ( totalClients === 1 ? ", " : "s, " ) + - totalGateways + " Gateways"; - - timestamp.textContent = "Diese Daten sind von " + d.timestamp.format("LLLL") + "."; - }; - - self.render = function (el) { - var h2 = document.createElement("h2"); - h2.textContent = config.siteName; - el.appendChild(h2); - - var p = document.createElement("p"); - el.appendChild(p); - stats = document.createTextNode(""); - p.appendChild(stats); - p.appendChild(document.createElement("br")); - timestamp = document.createTextNode(""); - p.appendChild(timestamp); - }; - - return self; - }; -});