From e4ea98aa21bb73b72df3a5fa1ebf6d464cf9c2ce Mon Sep 17 00:00:00 2001 From: Brian Flowers Date: Wed, 9 Nov 2016 22:13:26 -0500 Subject: [PATCH] Added timestamps --- graph.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/graph.php b/graph.php index 0d4e2c9..4e72757 100644 --- 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; } ?> -- 1.8.3.1