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

dev data javascript improvement

parent ed30c99e
...@@ -104,19 +104,12 @@ ...@@ -104,19 +104,12 @@
{% if data %} {% if data %}
<script type="text/javascript"> <script type="text/javascript">
google.charts.load('current', {'packages':['corechart']}); google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart(dname, ddata) {
{% for k in data[0][2] %} var data = google.visualization.arrayToDataTable(ddata);
function drawChart_{{ k }} () {
var data_{{ k }} = google.visualization.arrayToDataTable([ var options = {
['Time', '{{ k }}'], title: '{{ devname }} > '+dname,
{% for d in data|reverse %}
[new Date({{ d[0] }}*1000), {{ d[2][k] }}],
{% endfor %}
]);
var options_{{ k }} = {
title: '{{ devname}} > {{ k }}',
curveType: 'function', curveType: 'function',
hAxis: { hAxis: {
format: 'dd/MM/yy hh:mm:ss', format: 'dd/MM/yy hh:mm:ss',
...@@ -133,12 +126,10 @@ ...@@ -133,12 +126,10 @@
chartArea: { left: 0, top: 10, width: '100%' } chartArea: { left: 0, top: 10, width: '100%' }
}; };
var container_{{ k }} = document.getElementById('curve_chart_{{ k }}'); var container = document.getElementById('curve_chart_'+dname);
var chart_{{ k }} = new google.visualization.LineChart(container_{{ k }}); var chart = new google.visualization.LineChart(container);
//google.visualization.events.addListener(chart_{{ k }}, 'ready', function () { container_{{ k }}.className = ''; }); chart.draw(data, options);
chart_{{ k }}.draw(data_{{ k }}, options_{{ k }});
} }
{% endfor %}
function display_data(evt, dname) { function display_data(evt, dname) {
// Declare all variables // Declare all variables
...@@ -159,8 +150,9 @@ ...@@ -159,8 +150,9 @@
// Show the current tab, and add an "active" class to the button that opened the tab // Show the current tab, and add an "active" class to the button that opened the tab
document.getElementById(dname).style.display = "block"; document.getElementById(dname).style.display = "block";
evt.currentTarget.className += " active"; 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(); document.getElementById("tab_{{ data[0][2] | first }}").click();
......
...@@ -470,5 +470,21 @@ def settings(): ...@@ -470,5 +470,21 @@ def settings():
return redirect(request.url) 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(): def pend_delete_all_ack():
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