diff --git a/README.md b/README.md index 1f81a78..f82e006 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ Setting this to `false` will hide contact information for nodes. ## maxAge (integer) Nodes being online for less than maxAge days are considered "new". Likewise, -nodes being offline for less than than maxAge days are considered "lost". +nodes being offline for more than than maxAge days are considered "lost". ## mapLayers (List) diff --git a/lib/about.js b/lib/about.js index b88ecfa..d6161ce 100644 --- a/lib/about.js +++ b/lib/about.js @@ -28,8 +28,8 @@ define(function () { s += "https://www.gnu.org/licenses/.

" s += "

You may find the source code at " - s += "" - s += "http://draic.info/meshviewer." + s += "" + s += "https://github.com/ffnord/meshviewer." el.innerHTML = s } diff --git a/lib/main.js b/lib/main.js index c517768..4f2aab4 100644 --- a/lib/main.js +++ b/lib/main.js @@ -5,14 +5,12 @@ function (moment, Router, L, GUI, numeral) { var dataNodes = data[0] var dataGraph = data[1] - if (dataNodes.version !== 1 || dataGraph.version !== 1) { + if (dataNodes.version !== 2 || dataGraph.version !== 1) { var err = "Unsupported nodes or graph version: " + dataNodes.version + " " + dataGraph.version throw err } - var nodes = Object.keys(dataNodes.nodes).map(function (key) { return dataNodes.nodes[key] }) - - nodes = nodes.filter( function (d) { + var nodes = dataNodes.nodes.filter( function (d) { return "firstseen" in d && "lastseen" in d }) @@ -27,7 +25,12 @@ function (moment, Router, L, GUI, numeral) { var newnodes = limit("firstseen", age, sortByKey("firstseen", nodes).filter(online)) var lostnodes = limit("lastseen", age, sortByKey("lastseen", nodes).filter(offline)) - var graphnodes = dataNodes.nodes + var graphnodes = {} + + dataNodes.nodes.forEach( function (d) { + graphnodes[d.nodeinfo.node_id] = d + }) + var graph = dataGraph.batadv graph.nodes.forEach( function (d) { @@ -75,7 +78,7 @@ function (moment, Router, L, GUI, numeral) { }) return { now: now, - timestamp: moment.utc(data[0].timestamp).local(), + timestamp: moment.utc(dataNodes.timestamp).local(), nodes: { all: nodes, new: newnodes, diff --git a/lib/proportions.js b/lib/proportions.js index 29267af..b615ac1 100644 --- a/lib/proportions.js +++ b/lib/proportions.js @@ -1,5 +1,5 @@ -define(["chroma-js", "virtual-dom", "numeral-intl"], - function (Chroma, V, numeral) { +define(["chroma-js", "virtual-dom", "numeral-intl", "vercomp" ], + function (Chroma, V, numeral, vercomp) { return function (config) { var self = this @@ -128,7 +128,7 @@ define(["chroma-js", "virtual-dom", "numeral-intl"], }) fillTable(statusTable, statusDict.sort(function (a, b) { return b[1] - a[1] })) - fillTable(fwTable, fwDict.sort(function (a, b) { return b[1] - a[1] })) + fillTable(fwTable, fwDict.sort(function (a, b) { return vercomp(b[0], a[0]) })) fillTable(hwTable, hwDict.sort(function (a, b) { return b[1] - a[1] })) fillTable(geoTable, geoDict.sort(function (a, b) { return b[1] - a[1] })) fillTable(autoTable, autoDict.sort(function (a, b) { return b[1] - a[1] })) diff --git a/lib/vercomp.js b/lib/vercomp.js new file mode 100644 index 0000000..428f258 --- /dev/null +++ b/lib/vercomp.js @@ -0,0 +1,60 @@ +define([], function () { + function order(c) { + if (/^\d$/.test(c)) + return 0 + else if (/^[a-z]$/i.test(c)) + return c.charCodeAt(0) + else if (c === "~") + return -1 + else if (c) + return c.charCodeAt(0) + 256 + else + return 0 + } + + // Based on dpkg code + function vercomp(a, b) { + var apos = 0, bpos = 0 + while (apos < a.length || bpos < b.length) { + var firstDiff = 0 + + while ((apos < a.length && !/^\d$/.test(a[apos])) || (bpos < b.length && !/^\d$/.test(b[bpos]))) { + var ac = order(a[apos]) + var bc = order(b[bpos]) + + if (ac !== bc) + return ac - bc + + apos++ + bpos++ + } + + while (a[apos] === "0") + apos++ + + while (b[bpos] === "0") + bpos++ + + while (/^\d$/.test(a[apos]) && /^\d$/.test(b[bpos])) { + if (firstDiff === 0) + firstDiff = a.charCodeAt(apos) - b.charCodeAt(bpos) + + apos++ + bpos++ + } + + if (/^\d$/.test(a[apos])) + return 1 + + if (/^\d$/.test(b[bpos])) + return -1 + + if (firstDiff !== 0) + return firstDiff + } + + return 0 + } + + return vercomp +})