hourly test
authorDan Vanderkam <danvdk@gmail.com>
Thu, 27 Aug 2009 05:22:18 +0000 (05:22 +0000)
committerDan Vanderkam <danvdk@gmail.com>
Thu, 27 Aug 2009 05:22:18 +0000 (05:22 +0000)
dygraph.js
tests/data.js
tests/hourly.html [new file with mode: 0644]
tests/noise.html

index 87a28ad..41145e1 100644 (file)
@@ -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);
 };
 
 /**
index 8bd1210..c843d13 100644 (file)
@@ -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 (file)
index 0000000..62d4cac
--- /dev/null
@@ -0,0 +1,22 @@
+<html>
+  <head>
+    <title>noise</title>
+    <!--[if IE]>
+    <script type="text/javascript" src="excanvas.js"></script>
+    <![endif]-->
+    <script type="text/javascript" src="../dygraph-combined.js"></script>
+    <script type="text/javascript" src="../dygraph.js"></script>
+    <script type="text/javascript" src="data.js"></script>
+  </head>
+  <body>
+    <p>Hourly data:</p>
+    <div id="g" style="width:600px; height:300px;"></div>
+
+    <script type="text/javascript">
+      g = new DateGraph(
+            document.getElementById("g"),
+            HourlyData, null, {}
+          );
+    </script>
+  </body>
+</html>
index 3918e0e..ed46844 100644 (file)
@@ -5,6 +5,7 @@
     <script type="text/javascript" src="excanvas.js"></script>
     <![endif]-->
     <script type="text/javascript" src="../dygraph-combined.js"></script>
+    <script type="text/javascript" src="../dygraph.js"></script>
     <script type="text/javascript" src="data.js"></script>
   </head>
   <body>