diff --git a/master.js b/master.js index 49b46cd7..6e1bdaf7 100644 --- a/master.js +++ b/master.js @@ -93,6 +93,13 @@ app.get("/inventory", function(req, res) { res.send(docs); }); }); +// endpoint for getting the chartjs library +app.get("/chart.js", function(req, res) { + res.header("Access-Control-Allow-Origin", "*"); + res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); + // Check it and send it + res.end(fs.readFileSync("node_modules/chartjs/chart.js")); +}); var server = app.listen(config.masterPort || 8080, function () { console.log("Listening on port %s...", server.address().port); diff --git a/static/index.html b/static/index.html index 084b2e68..ae504e47 100644 --- a/static/index.html +++ b/static/index.html @@ -2,6 +2,7 @@ Clusterio + @@ -25,6 +26,13 @@

Storage

+ + +
+

Production

+
+ +
\ No newline at end of file diff --git a/static/main.js b/static/main.js index d56bb0dc..21f4256c 100644 --- a/static/main.js +++ b/static/main.js @@ -1,10 +1,25 @@ - contents = { "iron-plate":100, "copper-plate":7312, } +function djb2(str){ + var hash = 5381; + for (var i = 0; i < str.length; i++) { + hash = ((hash << 5) + hash) + str.charCodeAt(i); /* hash * 33 + c */ + } + return hash; +} + +function hashColor(str) { + var hash = djb2(str); + var r = (hash & 0xFF0000) >> 16; + var g = (hash & 0x00FF00) >> 8; + var b = hash & 0x0000FF; + return "#" + ("0" + r.toString(16)).substr(-2) + ("0" + g.toString(16)).substr(-2) + ("0" + b.toString(16)).substr(-2); +} + function drawcontents(data) { keys = Object.keys(data); result = ""; @@ -14,14 +29,43 @@ function drawcontents(data) { result = result + "
" document.getElementById("contents").innerHTML = result; } + setInterval(function() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { data = JSON.parse(xmlhttp.responseText); drawcontents(data); + // render our piechart with up to date information + piedata = []; + for(i=0;i