Added timestamps
authorBrian Flowers <git-admn@bsflowers.net>
Thu, 10 Nov 2016 03:13:26 +0000 (22:13 -0500)
committerBrian Flowers <git-admn@bsflowers.net>
Thu, 10 Nov 2016 03:13:26 +0000 (22:13 -0500)
graph.php

index 0d4e2c9..4e72757 100644 (file)
--- a/graph.php
+++ b/graph.php
@@ -84,9 +84,20 @@ if( !in_array($host, $hosts) )
     $result = $db->query($query);
     echo "      context.strokeStyle = '$colors[$i]';\n";
     $record = $result->fetch();
-    $final = $record['timestamp'];
+    $timediff = time() - $final;
+
+    $timestamp = ($timediff % 60)."s";
+    if( $timediff > 60 )
+      $timestamp = (($timediff / 60) % 60)."m ".$timestamp;
+    
+
+    echo "      context.strokeStyle = '#000000';\n";
+    echo "      context.strokeText('-$timestamp', 350, 10);\n";
+
+    echo "      context.strokeStyle = '$colors[$i]';\n";
     echo "      context.moveTo(0, ".sprintf("%d", $record['value']).");\n";
     echo "      context.beginPath();\n";
+
     while( $record = $result->fetch() )
       {
       echo "      context.lineTo(".sprintf("%d", $final - $record['timestamp']).", ".(400-$record['value']*4).");\n";
@@ -94,7 +105,7 @@ if( !in_array($host, $hosts) )
     echo "      context.stroke();\n";
 
     $name = $attributes[$attribute];
-    echo "      context.strokeText('$name', ".(40*$i).", 415);";
+    echo "      context.strokeText('$name', ".(100*($i%5)).", ".(425+(10*($i/5))).");";
     $i+=1;
     }
 ?>