Button to hide all datasets

resolves #46
This commit is contained in:
Danielv123 committed 2017-03-17 09:20:09 +01:00
1 parent dc2c04741a
commit 3f699e7ab5
1 file changed
+16 -3
+16 -3
View File
@@ -20,8 +20,9 @@ setTimeout(function() {
} }
HTML += "<div class='slaveBox'>"; HTML += "<div class='slaveBox'>";
HTML += '<div id="' + slaveData[key].unique + '" class="productionGraph" style="width: calc(100% - 200px);"></div>'; HTML += '<div id="' + slaveData[key].unique + '" class="productionGraph" style="width: calc(100% - 200px);"></div>';
HTML += "<h2>ID: " + slaveData[key].unique + "</h2><p>Last seen: "+seenDate+"</p><p>Port: "+slaveData[key].serverPort+"</p><p>Host: "+slaveData[key].mac+"</p>"; HTML += "<h2>ID: " + slaveData[key].unique + "</h2><p>Last seen: "+seenDate+"</p><p>IP: "+slaveData[key].publicIP +":"+ slaveData[key].serverPort+"</p>"
HTML += "<p>Host: "+slaveData[key].mac+"</p>";
HTML += "<button onclick='hideAllDatasets(\"" + slaveData[key].unique + "\")\'>Hide all</button>";
HTML += "</div>"; HTML += "</div>";
} }
} }
@@ -97,7 +98,7 @@ function generateLineChartArray(data, nameKey) {
} }
} }
} }
chartData = sortByKey(chartData, "x") chartData = sortByKey(chartData, "x");
let xyz = {}; let xyz = {};
xyz.name = nameKey; xyz.name = nameKey;
xyz.type = "line"; xyz.type = "line";
@@ -141,6 +142,18 @@ function drawChart(selector, chartData) {
chart.render(); chart.render();
} }
function hideAllDatasets(chartID) {
if(chartsByID[chartID]) {
let chart = chartsByID[chartID];
for(let i = 0; i < chart.options.data.length; i++) {
chart.options.data[i].visible = false;
}
chart.render();
} else {
return false;
}
}
// function to sort arrays of objects after a keys value // function to sort arrays of objects after a keys value
function sortByKey(array, key) { function sortByKey(array, key) {
return array.sort(function(a, b) { return array.sort(function(a, b) {