From 1768e8279361b147b279715f4afbdf8bbcb27cbd Mon Sep 17 00:00:00 2001 From: Xaver Maierhofer Date: Wed, 25 May 2016 23:38:18 +0200 Subject: [PATCH] [TASK] Replace numeraljs with toFixed vanilla js --- app.js | 9 +-------- bower.json | 1 - helper.js | 4 ++-- lib/infobox/node.js | 10 +++++----- lib/main.js | 6 ++---- lib/nodelist.js | 4 ++-- lib/proportions.js | 10 +++++----- 7 files changed, 17 insertions(+), 27 deletions(-) diff --git a/app.js b/app.js index f08f023..53b3a4b 100644 --- a/app.js +++ b/app.js @@ -10,8 +10,6 @@ require.config({ "tablesort": "../bower_components/tablesort/tablesort.min", "tablesort.number": "../bower_components/tablesort/src/sorts/tablesort.number", "d3": "../bower_components/d3/d3.min", - "numeral": "../bower_components/numeraljs/min/numeral.min", - "numeral.de": "../bower_components/numeraljs/min/languages/de.min", "virtual-dom": "../bower_components/virtual-dom/dist/virtual-dom", "rbush": "../bower_components/rbush/rbush", "helper": "../helper", @@ -24,12 +22,7 @@ require.config({ "tablesort": { exports: "Tablesort" }, - "numeral.de": { - deps: ["numeral"], - exports: "numeral" - }, - "tablesort.number": ["tablesort"], - "helper": ["numeral.de"] + "tablesort.number": ["tablesort"] } }); diff --git a/bower.json b/bower.json index eb54dfc..a582b93 100644 --- a/bower.json +++ b/bower.json @@ -18,7 +18,6 @@ "es6-shim": "~0.35.1", "almond": "~0.3.2", "d3": "~3.5.17", - "numeraljs": "~1.5.3", "roboto-fontface": "~0.3.0", "virtual-dom": "~2.1.1", "leaflet-providers": "~1.1.10", diff --git a/helper.js b/helper.js index d95ddb3..5ded2f7 100644 --- a/helper.js +++ b/helper.js @@ -118,11 +118,11 @@ function showDistance(d) { return; } - return numeral(d.distance).format("0,0") + " m" + return d.distance.toFixed(0) + " m" } function showTq(d) { - return numeral(1 / d.tq).format("0%") + return (1 / d.tq * 100).toFixed(0) + "%" } /* Infobox stuff (XXX: move to module) */ diff --git a/lib/infobox/node.js b/lib/infobox/node.js index c432183..99e3385 100644 --- a/lib/infobox/node.js +++ b/lib/infobox/node.js @@ -1,5 +1,5 @@ -define(["moment", "numeral", "tablesort", "tablesort.number", "moment.de"], - function (moment, numeral, Tablesort) { +define(["moment", "tablesort", "tablesort.number", "moment.de"], + function (moment, Tablesort) { function showGeoURI(d) { function showLatitude(d) { var suffix = Math.sign(d) > -1 ? "' N" : "' S"; @@ -8,7 +8,7 @@ define(["moment", "numeral", "tablesort", "tablesort.number", "moment.de"], var min = (d * 60) % 60; a = (a < 10 ? "0" : "") + a; - return a + "° " + numeral(min).format("0.000") + suffix; + return a + "° " + min.toFixed(3) + suffix; } function showLongitude(d) { @@ -18,7 +18,7 @@ define(["moment", "numeral", "tablesort", "tablesort.number", "moment.de"], var min = (d * 60) % 60; a = (a < 100 ? "0" + (a < 10 ? "0" : "") : "") + a; - return a + "° " + numeral(min).format("0.000") + suffix; + return a + "° " + min.toFixed(3) + suffix; } if (!has_location(d)) { @@ -178,7 +178,7 @@ define(["moment", "numeral", "tablesort", "tablesort.number", "moment.de"], } return function (el) { - el.appendChild(showLoadBar("load-avg", numeral(d.statistics.loadavg).format("0.00"))); + el.appendChild(showLoadBar("load-avg", d.statistics.loadavg.toFixed(2))); }; } diff --git a/lib/main.js b/lib/main.js index 4f2a9fd..14cd1a1 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,5 +1,5 @@ -define(["moment", "router", "leaflet", "gui", "numeral", "moment.de"], - function (moment, Router, L, GUI, numeral) { +define(["moment", "router", "leaflet", "gui", "moment.de"], + function (moment, Router, L, GUI) { return function (config) { function handleData(data) { var dataNodes = {}; @@ -154,8 +154,6 @@ define(["moment", "router", "leaflet", "gui", "numeral", "moment.de"], } }; } - - numeral.language("de"); moment.locale("de"); var router = new Router(); diff --git a/lib/nodelist.js b/lib/nodelist.js index 1c9c6be..cd55254 100644 --- a/lib/nodelist.js +++ b/lib/nodelist.js @@ -1,4 +1,4 @@ -define(["sorttable", "virtual-dom", "numeral"], function (SortTable, V, numeral) { +define(["sorttable", "virtual-dom"], function (SortTable, V) { function getUptime(now, d) { if (d.flags.online && "uptime" in d.statistics) { return Math.round(d.statistics.uptime); @@ -70,7 +70,7 @@ define(["sorttable", "virtual-dom", "numeral"], function (SortTable, V, numeral) var td1 = V.h("td", td1Content); var td2 = V.h("td", showUptime(d.uptime)); var td3 = V.h("td", d.meshlinks.toString()); - var td4 = V.h("td", numeral("clients" in d.statistics ? d.statistics.clients : "").format("0,0")); + var td4 = V.h("td", ("clients" in d.statistics ? d.statistics.clients : "").toFixed(0)); return V.h("tr", [td1, td2, td3, td4]); } diff --git a/lib/proportions.js b/lib/proportions.js index 3a27ac6..92ac066 100644 --- a/lib/proportions.js +++ b/lib/proportions.js @@ -1,5 +1,5 @@ -define(["chroma-js", "virtual-dom", "numeral.de", "filters/genericnode", "vercomp"], - function (Chroma, V, numeral, Filter, vercomp) { +define(["chroma-js", "virtual-dom", "filters/genericnode", "vercomp"], + function (Chroma, V, Filter, vercomp) { return function (config, filterManager) { var self = this; @@ -49,7 +49,7 @@ define(["chroma-js", "virtual-dom", "numeral.de", "filters/genericnode", "vercom }); } - function addFilter(filter) { + function addFilter(filter) { return function () { filterManager.addFilter(filter); @@ -85,7 +85,7 @@ define(["chroma-js", "virtual-dom", "numeral.de", "filters/genericnode", "vercom backgroundColor: scale(v).hex(), color: c1 > c2 ? "white" : "black" } - }, numeral(d[1]).format("0,0"))); + }, d[1].toFixed(0))); return V.h("tr", [th, td]); }); @@ -150,7 +150,7 @@ define(["chroma-js", "virtual-dom", "numeral.de", "filters/genericnode", "vercom fillTable("Autom. Updates", autoTable, autoDict.sort(function (a, b) { return b[1] - a[1]; })); - fillTable("Site", siteTable, siteDict.sort(function (a, b) { + fillTable("Site", siteTable, siteDict.sort(function (a, b) { return b[1] - a[1]; })); };