From 2769de626609e47b4137ce89eeb95391cf08c8e7 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Thu, 27 Aug 2009 05:22:18 +0000 Subject: [PATCH] hourly test --- dygraph.js | 21 +++++++++++++++------ tests/data.js | 12 ++++++++++++ tests/hourly.html | 22 ++++++++++++++++++++++ tests/noise.html | 1 + 4 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 tests/hourly.html diff --git a/dygraph.js b/dygraph.js index 87a28ad..41145e1 100644 --- a/dygraph.js +++ b/dygraph.js @@ -631,10 +631,15 @@ DateGraph.prototype.dateTicker = function(startDate, endDate) { for (var week = startDate - 14; week < endDate + 14; week += 7) { scale.push(week * ONE_DAY); } - } else { // daily + } else if (dateSpan > 1) { // daily for (var day = startDate - 14; day < endDate + 14; day += 1) { scale.push(day * ONE_DAY); } + } else { // hourly + for (var hour = (startDate - 1) * 24; + hour < (endDate + 1) * 24; hour += 1) { + scale.push(hour * 60*60*1000); + } } var xTicks = []; @@ -876,6 +881,7 @@ DateGraph.prototype.rollingAverage = function(originalData, rollPeriod) { rollingData[i] = [originalData[i][0], [ 1.0 * mid / count, 1.0 * (mid - low) / count, 1.0 * (high - mid) / count ]]; + } } else { // Calculate the rolling average for the first rollPeriod - 1 points where // there is not enough data to roll over the full number of days @@ -937,18 +943,21 @@ DateGraph.prototype.rollingAverage = function(originalData, rollPeriod) { */ DateGraph.prototype.dateParser = function(dateStr) { var dateStrSlashed; - if (dateStr.search("-") != -1) { + if (dateStr.length == 10 && dateStr.search("-") != -1) { // e.g. '2009-07-12' dateStrSlashed = dateStr.replace("-", "/", "g"); while (dateStrSlashed.search("-") != -1) { dateStrSlashed = dateStrSlashed.replace("-", "/"); } - } else if (dateStr.search("/") != -1) { - return Date.parse(dateStr); - } else { + return Date.parse(dateStrSlashed); + } else if (dateStr.length == 8) { // e.g. '20090712' dateStrSlashed = dateStr.substr(0,4) + "/" + dateStr.substr(4,2) + "/" + dateStr.substr(6,2); + return Date.parse(dateStrSlashed); + } else { + // Any format that Date.parse will accept, e.g. "2009/07/12" or + // "2009/07/12 12:34:56" + return Date.parse(dateStr); } - return Date.parse(dateStrSlashed); }; /** diff --git a/tests/data.js b/tests/data.js index 8bd1210..c843d13 100644 --- a/tests/data.js +++ b/tests/data.js @@ -431,3 +431,15 @@ return "" + "20061128,2.97723292469,0.711254751484,2.54237288136,0.648039583782\n" + "20061129,1.41093474427,0.495309102312,3.02013422819,0.701020603129"; } + +function HourlyData() { +return "" + +"Date,A,B\n" + +"2009/07/12 00:00:00,3,4\n" + +"2009/07/12 01:00:00,5,6\n" + +"2009/07/12 02:00:00,7,6\n" + +"2009/07/12 03:00:00,6,5\n" + +"2009/07/12 04:00:00,4,7\n" + +"2009/07/12 05:00:00,3,6\n" + +"2009/07/12 06:00:00,4,6" +} diff --git a/tests/hourly.html b/tests/hourly.html new file mode 100644 index 0000000..62d4cac --- /dev/null +++ b/tests/hourly.html @@ -0,0 +1,22 @@ + + + noise + + + + + + +

Hourly data:

+
+ + + + diff --git a/tests/noise.html b/tests/noise.html index 3918e0e..ed46844 100644 --- a/tests/noise.html +++ b/tests/noise.html @@ -5,6 +5,7 @@ + -- 2.7.4