Mercurial > ~darius > hgwebdir.cgi > iwws
view static/iwws.js @ 5:f859bcb451ca
Give a little horizontal border around the graphs and centre them.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 15 Aug 2011 22:56:27 +0930 |
parents | 2d9ee2b3ae82 |
children | 24e9b717722d |
line wrap: on
line source
/* * Copyright 2011 Daniel O'Connor <darius@dons.net.au> * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of Daniel O'Connor. */ $.jQTouch({ icon: 'icon.png', startupScreen: 'img/startup.png' }); function draw_graph(data, status) { if (status != "success") { $.log("Couldn't load data. status = %s", status); return; } var temp_out = []; var hum_out = []; var wavg = []; var wgust = []; var rain = []; var i, mint = 5, maxt = 35; var l = data['idx'].length - 1; var d = new Date(); var tzofs = d.getTimezoneOffset() * 60; for (i = 0; i < l; i++) { // Convert time from UTC to browser LT t = data['idx'][i] - tzofs; if (data['temp_out'] < mint) mint = data['temp_out'] if (data['temp_out'] < maxt) maxt = data['temp_out'] temp_out.push([t * 1000.0, data['temp_out'][i]]); hum_out.push([t * 1000.0, data['hum_out'][i]]); wavg.push([t * 1000.0, data['wind_ave'][i], wind2angle(data['wind_dir'][i])]); wgust.push([t * 1000.0, data['wind_gust'][i], wind2angle(data['wind_dir'][i])]); if (data['rain'][i] > 0) rain.push([t * 1000.0, data['rain'][i]]); } $.plot($("#graph1"), [ { data : temp_out, label: "Temp.", yaxis : 1, points : { show : true }, lines : { show : true } }, { data : hum_out, label: "RH", yaxis : 2, points : { show : true }, lines : { show : true } } ], { xaxis : { mode : 'time' }, legend : { backgroundOpacity : 0, position : 'nw' }, yaxis : { min : mint, max : maxt, tickFormatter : degCFormatter }, y2axis : { min : 0, max : 100, tickFormatter : pctFormatter } }); $.plot($("#graph2"), [ { data : wavg, label: "Wind (Avg)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true }, { data : wgust, label: "Wind (Gust)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true }, { data : rain, label: "Rain", yaxis : 2, bars : { show : true, barWidth : 0.5 * 60 * 60 * 1000, align : "centre" } } ], { xaxis : { mode : 'time' }, legend : { backgroundOpacity : 0, position : 'nw' }, yaxis : { tickFormatter : spdFormatter }, y2axis : { min : 0, tickFormatter : mmFormatter } }); } function wind2angle(dir) { var a = dir * (360.0 / 16.0); return a; } function degCFormatter(v, axis) { return v.toFixed(axis.tickDecimals) +"°C"; } function pctFormatter(v, axis) { return v.toFixed(axis.tickDecimals) +"%"; } function spdFormatter(v, axis) { return v.toFixed(axis.tickDecimals) + "kph"; } function mmFormatter(v, axis) { return v.toFixed(axis.tickDecimals) + "mm"; } function update_data() { jQuery.getJSON('iwws/getdata.json', draw_graph); } $(document).ready(function(){ update_data(); });