From 90d2c3e444c13b52c4a320c1bffb6ebf3b42e7a3 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 | 7 +++---- 7 files changed, 15 insertions(+), 26 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 e63962c..ef1fd19 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 1237021..a97b38f 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 659c596..421a60d 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)) { @@ -297,7 +297,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 bfb3637..aa4163a 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 = {}; @@ -197,8 +197,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 b81ec59..950bdd3 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); @@ -75,7 +75,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 : 0).toFixed(0)); return V.h("tr", [td1, td2, td3, td4]); } diff --git a/lib/proportions.js b/lib/proportions.js index 9d9b2e7..e7b6e56 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; @@ -80,7 +80,6 @@ define(["chroma-js", "virtual-dom", "numeral.de", "filters/genericnode", "vercom }); } - function addFilter(filter) { return function () { filterManager.addFilter(filter); @@ -117,7 +116,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]); });