X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=testing%2FMCTXWeb%2Fpublic_html%2Fstatic%2Fmctx.graph.js;fp=testing%2FMCTXWeb%2Fpublic_html%2Fstatic%2Fmctx.graph.js;h=57c884122718ba101d2843ef9b90452fb0f61f7a;hb=8c9214a60db100a206496d1c417c08a20ea2693e;hp=4bb3e0632a904ea47908b54bf512fdc5a8213e8b;hpb=486cec839029052716fc88ad64b41e074d0ee1ab;p=matches%2FMCTX3420.git diff --git a/testing/MCTXWeb/public_html/static/mctx.graph.js b/testing/MCTXWeb/public_html/static/mctx.graph.js index 4bb3e06..57c8841 100644 --- a/testing/MCTXWeb/public_html/static/mctx.graph.js +++ b/testing/MCTXWeb/public_html/static/mctx.graph.js @@ -106,19 +106,19 @@ $.fn.setDevices = function() { }); }; -function setGraphStatus(on, failText) { +function setGraphStatus(on, failText, keep) { if (on) { mctx.graph.running = true; $("#status-text").html(" "); - $("#graph-run").text("Pause"); + $("#graph-run").prop("value", "Pause"); } else { mctx.graph.running = false; if (failText) { $("#status-text").text(failText).addClass("fail"); - } else { + } else if (!keep) { $("#status-text").text("Graph stopped").removeClass("fail"); } - $("#graph-run").text("Run"); + $("#graph-run").prop("value", "Run"); } } @@ -155,6 +155,11 @@ function graphUpdater() { responses.push($.ajax({url : urls[val.urltype], data : parameters}) .done(function(json) { //alert("Hi from " + json.name); + if (!$("#status-text").checkStatus(json)) { + setGraphStatus(false, null, true); + return; + } + var dev = val.data; for (var i = 0; i < json.data.length; ++i) { if (dev.length <= 0 || json.data[i][0] > dev[dev.length-1][0]) { @@ -169,29 +174,29 @@ function graphUpdater() { //... When the response is received, then() will happen (I think?) $.when.apply(this, responses).then(function () { - var plot_data = []; - yaxis.each(function() { - //alert("Add " + $(this).val() + " to plot"); - if (xaxis.attr("alt") === "time") { - //alert("Against time"); - plot_data.push(devices[$(this).attr("alt")].data); + if (mctx.graph.running) { + var plot_data = []; + + yaxis.each(function() { + //alert("Add " + $(this).val() + " to plot"); + if (xaxis.attr("alt") === "time") { + //alert("Against time"); + plot_data.push(devices[$(this).attr("alt")].data); + } else { + var result = [] + dataMerge(devices[xaxis.attr("alt")].data, + devices[$(this).attr("alt")].data, result); + plot_data.push(result); + } + }); + + if (mctx.graph.chart !== null) { + mctx.graph.chart.setData(plot_data); + mctx.graph.chart.setupGrid(); + mctx.graph.chart.draw(); } else { - var result = [] - dataMerge(devices[xaxis.attr("alt")].data, - devices[$(this).attr("alt")].data, result); - plot_data.push(result); + mctx.graph.chart = $.plot("#graph", plot_data); } - }); - - //$.plot("#graph", plot_data); - if (mctx.graph.chart !== null) { - mctx.graph.chart.setData(plot_data); - mctx.graph.chart.setupGrid(); - mctx.graph.chart.draw(); - } else { - mctx.graph.chart = $.plot("#graph", plot_data); - } - if (mctx.graph.running) { mctx.graph.timer = setTimeout(updater, 1000); } }, function () {