From 7046ba58d3831eb76993035770c100508b9e374c Mon Sep 17 00:00:00 2001 From: Danielv123 Date: Sun, 5 Nov 2017 21:11:12 +0100 Subject: [PATCH] Import/export line on same graph on storage page to save space --- static/storage.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/static/storage.js b/static/storage.js index dac98649..ad585c33 100644 --- a/static/storage.js +++ b/static/storage.js @@ -100,8 +100,6 @@ function getItemStatData(item, callback){ }); xhr.send(data); } -////// drawChart("contentGraph", /api/getStats) - function makeItemGraphs(itemName){ getJSON("/api/slaves", function(err, slaves){ @@ -115,9 +113,9 @@ function makeItemGraphs(itemName){ slaveIDs.unshift("unknown"); slaveIDs.forEach(function(slaveID){ if(slaveID == "unknown" || Date.now() - slaves[slaveID].time < 120000 || JSON.parse(localStorage.settings)["Display offline slaves"]){ + HTML += '
'; ["place", "remove"].forEach(statistic => { console.log("Making chart for "+slaveID+"'s "+statistic+" statistic"); - HTML += '
'; setTimeout(function(){ let xmlhttp = new XMLHttpRequest(); // new HttpRequest instance @@ -133,8 +131,19 @@ function makeItemGraphs(itemName){ slaveDisplayName = slaves[slaveID].instanceName; } catch(e) {} let whatGraphIsIt = "Items sent to cluster from"; - if(statistic == "remove") whatGraphIsIt = "Items taken from cluster by" - drawChart(statistic+"contentGraph"+slaveID, [JSON.parse(xmlhttp.response).data], `${whatGraphIsIt} ${slaveDisplayName} (${slaveID}) ${itemName}`); + if(statistic == "remove") whatGraphIsIt = "Items taken from cluster by"; + + let chartData = JSON.parse(xmlhttp.response).data; + switch(statistic){ + case "place": + chartData.name = "Items exported:"; + break; + case "remove": + chartData.name = "Items imported:"; + break; + } + drawChartWhenCalledTwice(chartData, whatGraphIsIt + " " + slaveDisplayName); + //drawChart(statistic+"contentGraph"+slaveID, [JSON.parse(xmlhttp.response).data], `${whatGraphIsIt} ${slaveDisplayName} (${slaveID}) ${itemName}`); // console.log(JSON.parse(xmlhttp.response).data); } } @@ -142,6 +151,13 @@ function makeItemGraphs(itemName){ xmlhttp.send(JSON.stringify({statistic:statistic, itemName:itemName, slaveID:slaveID})); },1); }); + let chartLines = []; + function drawChartWhenCalledTwice(data, slaveDisplayName){ + chartLines.push(data); + if(chartLines.length >= 2){ + drawChart("contentGraph"+slaveID, chartLines, `${slaveDisplayName} (${slaveID}) ${itemName}`); + } + } } }); document.querySelector("#graphDisplay > #storageGraphContainer").innerHTML = HTML; @@ -155,8 +171,9 @@ function drawChart(selector, chartData, title) { title:{ text: title || "Production graph" }, - toolTip:{ - content: "{name}: {y}" + toolTip:{ + shared: true, + // content: "{name}: {y}", }, zoomEnabled: true, axisY:{