[TASK] Refactor legend/meshstats

This commit is contained in:
Xaver Maierhofer 2017-01-26 23:52:34 +01:00
parent f01851efa3
commit 430889c07d
No known key found for this signature in database
GPG Key ID: 7FDCE23FD2EC9FE8
3 changed files with 36 additions and 65 deletions

View File

@ -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);

View File

@ -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 = '<span class="legend-new"><span class="symbol"></span> Neuer Knoten</span>' +
'<span class="legend-online"><span class="symbol"></span> Knoten ist online</span>' +
'<span class="legend-offline"><span class="symbol"></span> Knoten ist offline</span>';
el.appendChild(p);
p.appendChild(document.createElement("br"));
p.appendChild(stats);
p.appendChild(document.createElement("br"));
p.appendChild(timestamp);
};
return self;
};
});

View File

@ -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;
};
});