Commit 5b12e9a8 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

dev data javascript improvement

parent ed30c99e
......@@ -104,19 +104,12 @@
{% if data %}
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
{% for k in data[0][2] %}
function drawChart_{{ k }} () {
var data_{{ k }} = google.visualization.arrayToDataTable([
['Time', '{{ k }}'],
{% for d in data|reverse %}
[new Date({{ d[0] }}*1000), {{ d[2][k] }}],
{% endfor %}
]);
function drawChart(dname, ddata) {
var data = google.visualization.arrayToDataTable(ddata);
var options_{{ k }} = {
title: '{{ devname}} > {{ k }}',
var options = {
title: '{{ devname }} > '+dname,
curveType: 'function',
hAxis: {
format: 'dd/MM/yy hh:mm:ss',
......@@ -133,12 +126,10 @@
chartArea: { left: 0, top: 10, width: '100%' }
};
var container_{{ k }} = document.getElementById('curve_chart_{{ k }}');
var chart_{{ k }} = new google.visualization.LineChart(container_{{ k }});
//google.visualization.events.addListener(chart_{{ k }}, 'ready', function () { container_{{ k }}.className = ''; });
chart_{{ k }}.draw(data_{{ k }}, options_{{ k }});
var container = document.getElementById('curve_chart_'+dname);
var chart = new google.visualization.LineChart(container);
chart.draw(data, options);
}
{% endfor %}
function display_data(evt, dname) {
// Declare all variables
......@@ -160,7 +151,8 @@
document.getElementById(dname).style.display = "block";
evt.currentTarget.className += " active";
eval('drawChart_'+dname+'()');
fetch(window.origin+'/dev-data/'+dname+'/graph/200/1').then(res => res.text()).then(data => drawChart(dname, eval(data)));
}
document.getElementById("tab_{{ data[0][2] | first }}").click();
......
......@@ -470,5 +470,21 @@ def settings():
return redirect(request.url)
@app.route('/dev-data/<var>/<dest>/<cnt>/<page>')
def dev_data(var, dest, cnt, page):
if dest == 'graph':
# for graph <cnt> is in hours
last = data.get_last_range(session['appkey'], session['devid'], [int(cnt), (int(page)-1)*int(cnt)])
arr = '[["Time", "{}"],'.format(var)
if last[0]:
for d in last[1]:
arr += '[new Date('+str(d[0])+'*1000),'+str(d[2][var])+'],'
arr += ']'
return arr
elif dest == 'table':
# for table <cnt> is in items
pass
def pend_delete_all_ack():
pend.delete_all_ack()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment