#result th {text-align:left;background-color:#eee;}
#result tbody td {vertical-align:top;font-family:fixed;font-size:11pt;background-color:#fff;padding:6px 4px 6px 4px;}
#tooltip {position:absolute;display:none;border:1px solid #fdd;padding:2px;background-color:#fee;opacity:0.80;}
+span.func {cursor: pointer; color: blue; text-decoration:underline;}
+span.func:hover {text-decoration:none; text-shadow: 1px 1px 1px #555; }
div.loading { background: rgba(255,255,255,.8) url('loading.gif') 50% 50% no-repeat; }
</style>
</head>
<div id="content">
<div id="overview" style="height:80px;"></div>
<div id="graph" style="height:400px;"></div>
-<p>Download view data as <a href="#" onclick="on_download('text')">ASCII</a> or <a href="#" onclick="on_download('json')">JSON</a></p>
-<p><a href="#" onclick="fetch_more_days(7)">Fetch another week</a>: update with an additional weeks historical data.</p>
-<p><a href="#" onclick="fetch_more_days(30)">Fetch another 30 days</a>: update with an additional month historical data.</p>
-<p id="result"/>
+<div id="pressure" style="height:120px;"></div>
+<div id="humidity" style="height:120px;"></div>
+<p>Download view data as <span class="func" onclick="on_download('text')">ASCII</span>
+or <span class="func" onclick="on_download('json')">JSON</span></p>
+<p><span class="func" onclick="fetch_more_days(7)">Fetch another week</span>:
+ update with an additional weeks historical data.</p>
+<p><span class="func" onclick="fetch_more_days(30)">Fetch another 30 days</span>:
+ update with an additional month historical data.</p>
+<p id="result"></p>
<div id="tooltip"></div>
</div><!-- /content -->
<div id="footer">
<span id="timestamp"></span>
</div>
<!-- <script type="text/javascript" src="/static/jquery.min.js"></script> -->
-<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.time.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.selection.min.js"></script>
<script type="text/javascript">
+'use strict';
function displayTime(ts) {
var d = new Date(ts);
return d.toLocaleTimeString() + " " + d.toLocaleDateString();
function graph_init() {
document.custom.graph_main = {plot: {}, options: {}};
document.custom.graph_overview = {plot: {}, options: {}};
+ document.custom.graph_pressure = {plot: {}, options: {}};
+ document.custom.graph_humidity = {plot: {}, options: {}};
document.custom.graph_main.options = {
series: {
shadowSize: 0,
yaxis: { ticks: [], autoscaleMargin: 0.1 },
selection: { mode: "x" }
};
+ document.custom.graph_pressure.options = {
+ series: { lines: { show: true, lineWidth: 1 }, shadowSize: 0 },
+ legend: { show: true },
+ grid: { markings: weekend_markings },
+ xaxis: { mode: "time", timezone: "browser", timeformat: "%d-%b" },
+ yaxis: { autoscaleMargin: 0.1 }
+ //selection: { mode: "x" }
+ };
$("#graph").bind("plotselected", function (event, ranges) {
var plot = document.custom.graph_main.plot;
$.each(plot.getXAxes(), function (_, axis) {
plot.clearSelection();
document.custom.graph_overview.plot.setSelection(ranges, true); // avoid event loop
});
+ $("#pressure").bind("plotselected", function (event, ranges) {
+ var plot = document.custom.graph_pressure.plot;
+ $.each(plot.getXAxes(), function (_, axis) {
+ var opts = axis.options;
+ opts.min = ranges.xaxis.from;
+ opts.max = ranges.xaxis.to;
+ });
+ plot.setupGrid();
+ plot.draw();
+ plot.clearSelection();
+ document.custom.graph_overview.plot.setSelection(ranges, true); // avoid event loop
+ });
$("#overview").bind("plotselected", function (event, ranges) {
var plot = document.custom.graph_overview.plot;
+ var dataLength = plot.getData()[0].data.length;
var mainPlot = document.custom.graph_main.plot;
- if (mainPlot.getData()[0].data.length != plot.getData()[0].data.length) {
+ if (mainPlot.getData()[0].data.length != dataLength) {
mainPlot.setData(document.custom.plotdata);
}
+ //var pressurePlot = document.custom.graph_pressure.plot;
+ //if (pressurePlot.getData()[0].data.length != document.custom.pressure.data.length) {
+ // pressurePlot.setData([document.custom.pressure]);
+ //}
$.each(plot.getXAxes(), function (_, axis) {
var opts = axis.options;
opts.min = ranges.xaxis.from;
opts.max = ranges.xaxis.to;
});
mainPlot.setSelection(ranges);
+ //pressurePlot.setSelection(ranges);
});
}
function replot(both) {
var ovplot = $.plot("#overview", document.custom.plotdata, document.custom.graph_overview.options);
document.custom.graph_overview.plot = ovplot;
+ var pressurePlot = $.plot("#pressure", [document.custom.pressure], document.custom.graph_pressure.options);
+ document.custom.graph_pressure.plot = pressurePlot;
+ var humidityPlot = $.plot("#humidity", [document.custom.humidity], document.custom.graph_pressure.options);
+ document.custom.graph_humidity.plot = humidityPlot;
if (both) {
var plot = $.plot($('#graph'), document.custom.plotdata, document.custom.graph_main.options);
document.custom.graph_main.plot = plot;
$.each(data.response, function(n, sensorName) {
document.custom.plotdata.push({data: [], label: sensorName, color: document.custom.colors[n]});
});
- fetch_initial_data();
+ document.custom.pressure = {data:[], label: "Pressure (hPa)", color: "#990000"}
+ document.custom.humidity = {data:[], label: "Humidity (% RH)", color: "#000099"}
+ fetch_initial_data();
}
function add_data(data) {
var plotdata = []; // one element per sensor
$.each(document.custom.plotdata, function(n,plot) {
- plotdata.push([]);
+ plotdata.push([]);
});
var oldest = document.custom.oldest;
var newest = document.custom.newest;
+ var pressure = []
+ var humidity = []
// update each sensor in plotdata adding new values
$.each(data.result, function(i,item) {
var t = item.timestamp*1000;
+ if (!(typeof(item.pressure) == "undefined")) {
+ if (item.pressure > 1)
+ pressure.push([t,item.pressure]);
+ }
+ if (!(typeof(item.humidity) == "undefined")) {
+ if (item.humidity > 1)
+ humidity.push([t,item.humidity]);
+ }
if (newest < t) newest = t;
if (oldest > t) oldest = t;
$.each(item.sensors, function(n, sensor) {
});
});
$.each(document.custom.plotdata, function(n,plot) {
- document.custom.plotdata[n].data = plotdata[n].concat(plot.data);
+ document.custom.plotdata[n].data = plotdata[n].concat(plot.data);
});
+ document.custom.pressure.data = pressure.concat(document.custom.pressure.data)
+ document.custom.humidity.data = humidity.concat(document.custom.humidity.data)
window.setTimeout(function() {replot(false);}, 20);
if (oldest < document.custom.oldest) {
if (((newest - oldest) / 1000 / (60*60*24)) < document.custom.days) {
window.setTimeout(function() {fetch_more((oldest - one_day)/1000, oldest/1000);}, 50);
}
function fetch_more(from_unixtime, until_unixtime) {
- when_from = (new Date(from_unixtime * 1000)).toISOString();
- when_until = (new Date(until_unixtime * 1000)).toISOString();
+ var when_from = (new Date(from_unixtime * 1000)).toISOString();
+ var when_until = (new Date(until_unixtime * 1000)).toISOString();
$.ajax({
url: 'since',
dataType: 'json',
});
}
function main() {
- document.custom = {plotdata: [], data: [], recent: {}, oldest: Infinity, newest: 0, days: 7};
+ document.custom = {plotdata: [], data: [], recent: {}, oldest: Infinity, newest: 0, days: 7, pressure: []};
document.custom.colors = ["#a040b0","#00a040","#0040a0"];
$.ajax({
url: 'recent',