Subject: [PATCH] Graphing of negative numbers

From: Malcolm Smith <[email-masked]>
Date: 08 Jan 2004 22:18:11 +0000

Hi,

While fiddling about with Argus I decided to monitor my clock's offset
from the real time relative to NTP, but found that Argus can't graph
negative numbers. The attached patch adds this capability. It has the
side-effect of allowing the two numbers in the gr_range parameter to be
specified in either order, but this does not affect the interpretation
of existing (correct) config files.

	Malcolm

--- src/Image.pm.original	Tue Jul 15 17:45:23 2003
+++ src/Image.pm	Sat Dec  6 01:48:12 2003
@@ -67,12 +67,17 @@
 sub axii {
     my $me = shift;
     my $im = $me->{img};
-    # draw axii
     
+    # Draw Y axis
     $im->line( $me->xpt(-1), $me->ypt(-1), $me->xpt(-1), $me->ypt($me->{ymax}), $me->{color}{black});
-    $im->line( $me->xpt(-1), $me->ypt(-1), $me->xpt($me->{xmax}), $me->ypt(-1), $me->{color}{black});
+    
+    my $xoffset = $me->ydatapt(0);
+    if (($xoffset >= $me->{ymin}) && ($xoffset <= $me->{ymax})) {
+	# Draw X axis
+	$im->line( $me->xpt(-1), $xoffset, $me->xpt($me->{xmax}), $xoffset, $me->{color}{black});
+    }
     # 'Talking of axes,' said the Duchess, 'chop off her head!'
-    #   -- Aliced in Wonderland
+    #   -- Alice in Wonderland
 }
 
 sub border {
@@ -178,7 +183,20 @@
 sub setrange {
     my $me = shift;
     my $r  = shift;
-    my( $l, $h ) = split /\s*-\s*/, $r;
+    my @limits = split /\s*-\s*/, $r;
+
+    if ($limits[0] eq '') {     	# first limit is negative
+	shift @limits;
+	$limits[0] = "-$limits[0]";
+    }
+    
+    if ($limits[1] eq '') { 	# second limit is negative
+	$limits[1] = "-$limits[2]";
+	pop @limits;
+    }
+
+    ($l, $h) = ($limits[0] <= $limits[1]) ? ($limits[0], $limits[1]) : ($limits[1], $limits[0]);
+
 
     $me->{yd_min} = $l if defined($l) && $l ne '';
     $me->{yd_max} = $h if defined($h) && $h;
@@ -596,13 +614,13 @@
 	    my $y = $s->{valu} || $s->{ave};
 	    if( $me->xdatapt($x) - $me->xdatapt($px) > 1 ){
 		my $poly = GD::Polygon->new;
-		$poly->addPt($me->xdatapt($px), $me->ypt(0));
+		$poly->addPt($me->xdatapt($px), $me->ydatapt(0));
 		$poly->addPt($me->xdatapt($px), $me->ydatapt($py));
 		$poly->addPt($me->xdatapt($x),  $me->ydatapt($y));
-		$poly->addPt($me->xdatapt($x),  $me->ypt(0));
+		$poly->addPt($me->xdatapt($x),  $me->ydatapt(0));
 		$me->{img}->filledPolygon($poly, $me->color($s->{flag}));
 	    }else{
-		$me->{img}->line( $me->xdatapt($x), $me->ypt(0),
+		$me->{img}->line( $me->xdatapt($x), $me->ydatapt(0),
 				  $me->xdatapt($x), $me->ydatapt($y),
 				  $me->color($s->{flag}) );
 	    }

---

From: Jeff Weisberg <[email-masked]>
Date: Fri, 9 Jan 2004 14:40:22 -0500 (EST)

| While fiddling about with Argus I decided to monitor my clock's offset
| from the real time relative to NTP, but found that Argus can't graph
| negative numbers. The attached patch adds this capability. It has the
| side-effect of allowing the two numbers in the gr_range parameter to be
| specified in either order, but this does not affect the interpretation
| of existing (correct) config files.

negative numbers, hmmmm.

thanks

	--jeff