diff options
author | Karel Kočí <cynerd@email.cz> | 2017-06-17 10:54:20 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2017-06-17 10:54:20 +0200 |
commit | cfc9a152f42366d6e8fecf3134a9824840c80acc (patch) | |
tree | 99da8bbf5c24a07a94600c08b3ae0923ed99ee3f /foris/templates/javascript | |
download | turris-ups-pfc8591-cfc9a152f42366d6e8fecf3134a9824840c80acc.tar.gz turris-ups-pfc8591-cfc9a152f42366d6e8fecf3134a9824840c80acc.tar.bz2 turris-ups-pfc8591-cfc9a152f42366d6e8fecf3134a9824840c80acc.zip |
Initial commit
Diffstat (limited to 'foris/templates/javascript')
-rw-r--r-- | foris/templates/javascript/i2c_collect/i2c_collect.js.tpl | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/foris/templates/javascript/i2c_collect/i2c_collect.js.tpl b/foris/templates/javascript/i2c_collect/i2c_collect.js.tpl new file mode 100644 index 0000000..0ca8108 --- /dev/null +++ b/foris/templates/javascript/i2c_collect/i2c_collect.js.tpl @@ -0,0 +1,78 @@ +function graph_init(field) { + var graph_config = { + type: 'line', + data: { + labels: graph_labels[field], + datasets: [ + { + label: field, + data: graph_data[field], + }, + ], + fill: false, + steppedLine: false, + }, + options: { + responsive: true, + title: { + display:true, + text:'{{ trans("Sample") }}' + }, + tooltips: { + mode: 'index', + intersect: false, + }, + hover: { + mode: 'nearest', + intersect: true + }, + scales: { + xAxes: [{ + display: true, + scaleLabel: { + display: true, + labelString: '{{ trans("Time") }}' + } + }], + yAxes: [{ + display: true, + scaleLabel: { + display: true, + labelString: '{{ trans("Value") }}' + } + }], + }, + }, + }; + if (field == "voltage") { + graph_config.options.scales.yAxes[0].ticks = { min: 10, max: 15 } + } else if (field == "light" || field == "temperature") { + graph_config.options.scales.yAxes[0].ticks = { min: 0, max: 250 } + } else if (field == "light" || field == "temperature") { + graph_config.options.scales.yAxes[0].ticks = { min: 0, max: 100 } + } + var graph_ctx = document.getElementById("canvas-" + field).getContext("2d"); + Foris.lineChart[field] = new Chart(graph_ctx, graph_config); + Foris.lineChartData[field] = graph_config.data; +} + +$(document).ready(function() { + Foris.lineChart = []; + Foris.lineChartData = []; + graph_init("voltage"); + graph_init("light"); + graph_init("temperature"); + graph_init("trimmer"); +}); + +/* +Foris.WS["i2c-collect"] = function (data) { + for (d in data) { + Foris.lineChartData[d].datasets[0].data.push(data[d][0]); + Foris.lineChartData[d].datasets[0].data.shift(); + Foris.lineChartData[d].labels.push(data[d][1]); + Foris.lineChartData[d].labels.shift(); + Foris.lineChart[d].update(); + } +}; +*/ |