added date selector
authorAndrew Tridgell <tridge@samba.org>
Sun, 10 Oct 2010 03:38:01 +0000 (14:38 +1100)
committerAndrew Tridgell <tridge@samba.org>
Sun, 10 Oct 2010 03:38:01 +0000 (14:38 +1100)
live/graphs.js
live/index.html

index 21aee3ed4f78338b6d6f5884de2dced5de21e49d..5cd2a41f33daa621f3f09a9ad1575cc5c0bfa3ff 100644 (file)
@@ -8,18 +8,22 @@ midnight.setMinutes(0);
 midnight.setSeconds(0);
 midnight.setMilliseconds(0);
 
+pvdate = new Date(midnight);
+
 /*
   show a HTML heading
  */
 function heading(level, h) {
-  document.write("<h" + level + ">" + h + "</h" + level + ">\n");
+  if (!in_redraw) {
+    document.write("<h" + level + ">" + h + "</h" + level + ">\n");
+  }
 }
 
 /*
   create a div for a graph
  */
 function graph_div(divname) {
-  if (document.getElementById(divname) == null) {
+  if (!in_redraw) {
     document.write('<div id="' + divname + '" style="width:700px; height:350px;"></div>');
   }
 }
@@ -144,17 +148,17 @@ function intLength(v, N) {
 }
 
 /*
-  return the list of CSV files for my 6 inverters for today
+  return the list of CSV files for my 6 inverters for date pvdate
  */
 function todays_csv_files() {
   var serialnums = [ 2001511859, 2001511912, 2001512099, 2001551093, 2001551109, 2001559615 ];
   var list = new Array();
-  var today = new Date(midnight);
+  writeDebug(pvdate);
   for (var i=0; i<serialnums.length; i++) {
     list[i] = "../CSV/" + 
-      today.getFullYear() + "-" + 
-      intLength(today.getMonth()+1,2) + "-" + 
-      intLength(today.getDate(),2) + "-WR5KA-08:" +
+      pvdate.getFullYear() + "-" + 
+      intLength(pvdate.getMonth()+1,2) + "-" + 
+      intLength(pvdate.getDate(),2) + "-WR5KA-08:" + 
       serialnums[i] + ".csv";
   }
   return list;
@@ -269,6 +273,9 @@ function apply_function(d, func, label) {
 }
 
 
+/* currently displayed graphs, indexed by divname */
+global_graphs = new Array();
+
 /*
   graph results from a set of CSV files:
     - apply func1 to the name columns within each file
@@ -360,8 +367,18 @@ function graph_csv_files_func(divname, filenames, columns, func1, func2, attrs)
        caller.attrs[a] = defaultAttrs[a];
       }
     }
-    
-    var g = new Dygraph(document.getElementById(divname), d2.data, caller.attrs);
+
+    if (global_graphs[divname] !== undefined) {
+      /* just update the data */
+      var g = global_graphs[divname];
+      for (var i=0; i<d2.data.length; i++) {
+       d2.data[i][0] = d2.data[i][0].valueOf();
+      }
+      g.rawData_ = d2.data;
+      g.drawGraph_(g.rawData_);
+    } else {
+      global_graphs[divname] = new Dygraph(document.getElementById(divname), d2.data, caller.attrs);
+    }
   }
 
   caller.loaded_callback = loaded_callback;
@@ -403,14 +420,14 @@ function graph_sum_csv_files(divname, filenames, column, attrs) {
   return graph_csv_files_func(divname, filenames, [column], null, sum, attrs);
 }
 
+/* marker for whether we are in a redraw with new data */
+in_redraw = false;
 
 /*
   show all the live data graphs
  */
 function show_graphs() {
 
-  enableDebug(false);
-
   heading(3, "Total AC Power (W)");
 
   graph_sum_csv_files("Total AC Power", 
@@ -504,17 +521,22 @@ function show_graphs() {
                    avoidMinZero: true,
                    valueRange: [0, 12] });
 
+  in_redraw = true;
+}
+
+function redraw_graphs() {
+  return false;
 }
 
-function set_date() {
+function set_date(e) {
+  var dp = datePickerController.getDatePicker("pvdate");
+  pvdate = dp.date;
+  writeDebug("redrawing for: " + pvdate);
   show_graphs();
 }
 
 function setup_datepicker() {
-  
-  document.getElementById("sd").value = 
-    midnight.getFullYear() + "-" + intLength(midnight.getMonth()+1, 2) + "-" + intLength(midnight.getDate(),2);
-
-  // Add the onchange event handler to the start date input
-  datePickerController.addEvent(document.getElementById("sd"), "change", set_date);
+    document.getElementById("pvdate").value = 
+      intLength(pvdate.getDate(),2) + "/" + intLength(pvdate.getMonth()+1, 2) + "/" + pvdate.getFullYear();
+    datePickerController.addEvent(document.getElementById("pvdate"), "change", set_date);
 }
index 3b24cd3ab99524aa605e7c8af3ba89625220af96..91f5e8ed7f3d3a57e05f5142fbd54247f1f8d275 100755 (executable)
 <script type="text/javascript" src="lib/dygraph.js"></script>
 <script type="text/javascript" src="lib/debug.js"></script>
 <script type="text/javascript" src="graphs.js"></script>
-<!--
 <script type="text/javascript" src="lib/date-picker/js/datepicker.js"></script>
-<link href="lib/date-picker/css/datepicker.css" rel="stylesheet" --
-  --type="text/css" />
--->
+<link href="lib/date-picker/css/datepicker.css" rel="stylesheet" type="text/css" />
 <!-- meta http-equiv="Refresh" content="300" -->
 </head>
 <body>
 <h1>Daily Inverter Data</h1>
 
-<!--
-<form id="date" method="post" action="">
+<form id="dateForm" method="get" onsubmit="return redraw_graphs();" action="">
     <fieldset>
-      <label for="sd">Start Date : </label>
       <p><input type="text" class="w8em format-d-m-y highlight-days-67
-      range-high-today range-low-2010-10-08" name="sd" id="sd" value="" maxlength="10" /></p>
+      range-high-today range-low-2010-10-09" name="pvdate" id="pvdate" value="" maxlength="10" /></p>
     </fieldset>
 </form>
--->
 
 <script type="text/javascript">
-/* setup_datepicker(); */
+enableDebug(false);
+setup_datepicker();
 show_graphs();
 </script>