X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=testing%2FMCTXWeb%2Fpublic_html%2Fstatic%2Fmctx.graph.js;h=4bb3e0632a904ea47908b54bf512fdc5a8213e8b;hb=fc0dc3b827eeff91373db42a78a098200cbf8fa6;hp=f71b52acdca05b861e5216dc610e66110eb51439;hpb=c0191ef4c04fca7d2ede7d9f417e2ec829477896;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..4bb3e06 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 @@ -21,13 +23,21 @@ mctx.graph.timer = null; * Appends each value pair to the result * @returns result */ +/** + * Helper - Calculate pairs of (dependent, independent) values + * Given input as (time, value) pairs for dependent and independent + * Appends each value pair to the result + * @param {array[][]} dependent Dependent data to be correlated with independent + * @param {array[][]} independent Independent data + * @param {array[][]} result Storage location + * @returns {dataMerge.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 +49,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 = $("