[TASK] Refactor legend/meshstats
This commit is contained in:
parent
f01851efa3
commit
430889c07d
12
lib/gui.js
12
lib/gui.js
@ -1,8 +1,8 @@
|
|||||||
define(["chroma-js", "map", "sidebar", "tabs", "container", "meshstats",
|
define(["chroma-js", "map", "sidebar", "tabs", "container", "legend",
|
||||||
"legend", "linklist", "nodelist", "simplenodelist", "infobox/main",
|
"linklist", "nodelist", "simplenodelist", "infobox/main",
|
||||||
"proportions", "forcegraph", "title", "about", "datadistributor",
|
"proportions", "forcegraph", "title", "about", "datadistributor",
|
||||||
"filters/filtergui"],
|
"filters/filtergui"],
|
||||||
function (chroma, Map, Sidebar, Tabs, Container, Meshstats, Legend, Linklist,
|
function (chroma, Map, Sidebar, Tabs, Container, Legend, Linklist,
|
||||||
Nodelist, SimpleNodelist, Infobox, Proportions, ForceGraph,
|
Nodelist, SimpleNodelist, Infobox, Proportions, ForceGraph,
|
||||||
Title, About, DataDistributor, FilterGUI) {
|
Title, About, DataDistributor, FilterGUI) {
|
||||||
"use strict";
|
"use strict";
|
||||||
@ -80,8 +80,7 @@ define(["chroma-js", "map", "sidebar", "tabs", "container", "meshstats",
|
|||||||
var infobox = new Infobox(config, sidebar, router);
|
var infobox = new Infobox(config, sidebar, router);
|
||||||
var tabs = new Tabs();
|
var tabs = new Tabs();
|
||||||
var overview = new Container();
|
var overview = new Container();
|
||||||
var meshstats = new Meshstats(config);
|
var legend = new Legend(config);
|
||||||
var legend = new Legend();
|
|
||||||
var newnodeslist = new SimpleNodelist("new", "firstseen", router, "Neue Knoten");
|
var newnodeslist = new SimpleNodelist("new", "firstseen", router, "Neue Knoten");
|
||||||
var lostnodeslist = new SimpleNodelist("lost", "lastseen", router, "Verschwundene Knoten");
|
var lostnodeslist = new SimpleNodelist("lost", "lastseen", router, "Verschwundene Knoten");
|
||||||
var nodelist = new Nodelist(router);
|
var nodelist = new Nodelist(router);
|
||||||
@ -89,7 +88,7 @@ define(["chroma-js", "map", "sidebar", "tabs", "container", "meshstats",
|
|||||||
var statistics = new Proportions(config, fanout);
|
var statistics = new Proportions(config, fanout);
|
||||||
var about = new About();
|
var about = new About();
|
||||||
|
|
||||||
fanoutUnfiltered.add(meshstats);
|
fanoutUnfiltered.add(legend);
|
||||||
fanoutUnfiltered.add(newnodeslist);
|
fanoutUnfiltered.add(newnodeslist);
|
||||||
fanoutUnfiltered.add(lostnodeslist);
|
fanoutUnfiltered.add(lostnodeslist);
|
||||||
fanout.add(nodelist);
|
fanout.add(nodelist);
|
||||||
@ -97,7 +96,6 @@ define(["chroma-js", "map", "sidebar", "tabs", "container", "meshstats",
|
|||||||
fanout.add(statistics);
|
fanout.add(statistics);
|
||||||
|
|
||||||
sidebar.add(header);
|
sidebar.add(header);
|
||||||
header.add(meshstats);
|
|
||||||
header.add(legend);
|
header.add(legend);
|
||||||
|
|
||||||
overview.add(newnodeslist);
|
overview.add(newnodeslist);
|
||||||
|
@ -1,19 +1,47 @@
|
|||||||
define(function () {
|
define(["helper"], function (helper) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
return function () {
|
return function (config) {
|
||||||
var self = this;
|
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) {
|
self.render = function (el) {
|
||||||
|
var h2 = document.createElement("h2");
|
||||||
|
h2.textContent = config.siteName;
|
||||||
|
el.appendChild(h2);
|
||||||
|
|
||||||
var p = document.createElement("p");
|
var p = document.createElement("p");
|
||||||
p.classList.add("legend");
|
p.classList.add("legend");
|
||||||
p.innerHTML = '<span class="legend-new"><span class="symbol"></span> Neuer Knoten</span>' +
|
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-online"><span class="symbol"></span> Knoten ist online</span>' +
|
||||||
'<span class="legend-offline"><span class="symbol"></span> Knoten ist offline</span>';
|
'<span class="legend-offline"><span class="symbol"></span> Knoten ist offline</span>';
|
||||||
el.appendChild(p);
|
el.appendChild(p);
|
||||||
|
|
||||||
|
p.appendChild(document.createElement("br"));
|
||||||
|
p.appendChild(stats);
|
||||||
|
p.appendChild(document.createElement("br"));
|
||||||
|
p.appendChild(timestamp);
|
||||||
};
|
};
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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;
|
|
||||||
};
|
|
||||||
});
|
|
Loading…
Reference in New Issue
Block a user