From 386607fc4b470b7493a8ea46556f43effe0ca79a Mon Sep 17 00:00:00 2001 From: Wesley Moore Date: Sat, 16 Oct 2010 19:52:38 +1100 Subject: [PATCH] Add rain charts to weather page --- content/screen.sass | 8 ++-- content/weather.html | 30 +++++++++----- output/js/weather.js | 98 +++++++++++++++++++++++--------------------- 3 files changed, 75 insertions(+), 61 deletions(-) diff --git a/content/screen.sass b/content/screen.sass index c6e2bfe..808c28a 100644 --- a/content/screen.sass +++ b/content/screen.sass @@ -422,7 +422,6 @@ table body.weather #current > .temperature - //margin-left: 1em .temperature font-family: "Helvetica Neue", Helvetica, "Liberation Sans", "Bitstream Vera Sans", Tahoma, Geneva, Arial, sans-serif @@ -438,10 +437,11 @@ body.weather .chart clear: both + width: 100% + height: 320px - .canvas - width: 100% - height: 320px + section.rain + margin-top: 2em small display: block diff --git a/content/weather.html b/content/weather.html index 1d75d3c..967ba10 100644 --- a/content/weather.html +++ b/content/weather.html @@ -1,15 +1,25 @@ -

Temperature

+

Note: The times on this page are currently wrong.

-
Loading Loading
+
+

Temperature

-
- - - --> -
-
+
Loading Loading
- +
+
+ +
+

Rainfall

+ +

Today

+ +

Total: -- mm

+ +
+ +

Last 7 Days

+ +
+
Forecast icons by LavAna \ No newline at end of file diff --git a/output/js/weather.js b/output/js/weather.js index 63a60db..3d5d1d5 100644 --- a/output/js/weather.js +++ b/output/js/weather.js @@ -68,13 +68,11 @@ function timeString(date) { ].join(':') } -jQuery(function() { - jQuery.getJSON("/weather.json", function(data, status) { - var count = data.history.length; - for(var i = 0; i < count; i++) { - data.history[i][0] = new Date(data.history[i][0]); - } +//function newUTCDate() +jQuery(function() { + var now = new Date(); + jQuery.getJSON("/weather.json", function(data, status) { // Populate the current conditions var current = { temperature: data.current.temperature_out, @@ -105,50 +103,56 @@ jQuery(function() { $('.loading').replaceWith(current_div) // Populate the charts - $('.temperature.chart .canvas').each(function() { - var self = this; + var count = data.history.length; + for(var i = 0; i < count; i++) { + data.history[i][0] = new Date(data.history[i][0] - (now.getTimezoneOffset() * 60 * 1000)); + } + jQuery.plot('.temperature.chart', data.history, { + xaxis: { + mode: "time" + } + }); - var options = { - xaxis: { - mode: "time" + // Rain + var total_rain_today = 0; + jQuery.each(data.rain.today, function(idx, reading) { + total_rain_today += reading[1]; + reading[0] = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), reading[0])); + }); + $("section.rain .total").html(Math.round(total_rain_today * 10) / 10) + + jQuery.each(data.rain.history, function(idx, reading) { + var date = reading[0].split("-") + reading[0] = new Date(Date.UTC(date[0], date[1] - 1, date[2])); + }); + + jQuery.plot(".rainfall.today.chart", [data.rain.today], { + series: { + bars: { + show: true, + barWidth: 1000 * 60 * 60 // 1 hour } - }; + }, + xaxis: { + mode: "time", + min: new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate())), + max: new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 23, 59, 59)), + } + }); - jQuery.plot(self, data.history, options); - - /* - $("#year").click(function () { - $.plot(self, data.history, { - xaxis: { - mode: "time", - minTickSize: [1, "month"] //, - // min: (new Date("1990/01/01")).getTime(), - // max: (new Date()).getTime() - } - - }); - }); - - $("#month").click(function () { - $.plot(self, data.history, { - xaxis: { - mode: "time", - min: (new Date("2010/08/21")).getTime(), - max: (new Date()).getTime() - } - }); - }); - - $("#day").click(function () { - $.plot(self, data.history, { - xaxis: { - mode: "time", - min: (new Date("2010/09/21 00:00")).getTime(), - max: (new Date()).getTime() - } - }); - }); - */ + jQuery.plot(".rainfall.week.chart", [data.rain.history], { + series: { + bars: { + show: true, + barWidth: 1000 * 60 * 60 * 24 // 1 day + } + }, + xaxis: { + // min: 0, + // max: 24 + mode: "time", + minTickSize: [1, "day"] + } }); }); });