X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=testing%2FMCTXWeb%2Fpublic_html%2Fstatic%2Fmctx.graph.js;h=e79b6a88b703ba69d79e41ed52b4827d32c3d270;hb=e0132025a1df98f88b2415e9e5f75ce7304efb33;hp=f71b52acdca05b861e5216dc610e66110eb51439;hpb=3bef37b168e451dc56932d03a9150d21eab4ffc9;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 f71b52a..e79b6a8 100644 --- a/testing/MCTXWeb/public_html/static/mctx.graph.js +++ b/testing/MCTXWeb/public_html/static/mctx.graph.js @@ -14,6 +14,8 @@ mctx.actuators = {}; mctx.graph.dependent = null; mctx.graph.independent = null; mctx.graph.timer = null; +mctx.graph.running = false; +mctx.graph.chart = null; /** * Helper - Calculate pairs of (dependent, independent) values @@ -22,12 +24,11 @@ mctx.graph.timer = null; * @returns result */ function dataMerge(dependent, independent, result) { - var j = 0; for (var i = 0; i < dependent.length-1; ++i) { var start = dependent[i][0]; var end = dependent[i+1][0]; - var average = 0; var n = 0; + var average = 0, n = 0; for (; j < independent.length; ++j) { if (independent[j][0] < start) continue; @@ -39,31 +40,36 @@ function dataMerge(dependent, independent, result) { if (n > 0) { average /= n; result.push([dependent[i][1], average]); - } + } } return result; } /** * Helper function adds the sensors and actuators to a form + * @param input_type is it a radio? or is it a checkbox? + * @param check_first determines whether the first item is checked or not + * @param group which group this input belongs to (name field) */ -$.fn.deployDevices = function(input_type, check_first) { - var formhtml = $(this).html(); - var formname = $(this).attr("id"); - // formhtml += " Sensors " - var checked = "checked"; - if (!check_first) - checked = ""; - $.each(mctx.sensors, function(key, val) { - formhtml += "" + val + ""; - checked = ""; - }); - // formhtml += " Actuators " - $.each(mctx.actuators, function(key, val) { - formhtml += "" + val + ""; - checked = ""; - }); - $(this).html(formhtml); +$.fn.deployDevices = function(input_type, check_first, group) { + var container = this; + var apply = function(dict, prefix) { + $.each(dict, function(key, val) { + var attributes = { + 'type' : input_type, 'value' : key, 'alt' : val, + 'class' : prefix, 'name' : group, + 'id' : prefix + '_' + val //Unique id (name mangling) + }; + var entry = $("", attributes); + var label = $("