Index: trunk/tools/czartool/Plotter.pm
===================================================================
--- trunk/tools/czartool/Plotter.pm	(revision 30918)
+++ trunk/tools/czartool/Plotter.pm	(revision 30955)
@@ -146,6 +146,6 @@
 #
 ###########################################################################
-sub createRateTimeSeries {
-    my ($self, $label, $selectedStage, $beginTime, $endTime, $interval) = @_;
+sub createRatePlot {
+    my ($self, $label, $selectedStage, $beginTime, $endTime, $interval, $histogram, $timeSeries) = @_;
 
     # stages
@@ -164,5 +164,49 @@
     my $stage = undef;
     my $gnuplotFile = undef;
-    my $outputFile = createImageFileName($self, $label, $selectedStage, "r", 0);
+    my $minX = 999999999;      
+    my $maxX = -9999999999;
+    my $timeDiff = 0;
+
+    foreach $stage (@{$stages}) {
+
+        if ($self->{_czarDb}->createProcessingRateData(
+                    $stage, 
+                    $label, 
+                    $beginTime, 
+                    $endTime, 
+                    $interval,
+                    \$gnuplotFile,
+                    \$minX, \$maxX, \$timeDiff)) {
+
+            $gnuplotFiles{$stage} = $gnuplotFile;
+            #print "$minX, $maxX, $timeDiff\n";
+        }
+    }
+
+    if ($histogram) {
+
+        my $outputFile = createImageFileName($self, $label, $selectedStage, "rh", 0);
+        $self->plotRateStackedHistogram(\%gnuplotFiles, $outputFile, $label, $selectedStage, $beginTime, $endTime, $interval);
+    }
+    if ($timeSeries) {
+
+        my $outputFile = createImageFileName($self, $label, $selectedStage, "rt", 0);
+        $self->plotTimeSeries(\%gnuplotFiles, $outputFile, $label, $beginTime, $endTime, $maxX, $minX, $timeDiff, "", "Exposures processed per $interval");
+    }
+
+    # now delete temp dat files
+    foreach my $stage (keys %gnuplotFiles) {unlink($gnuplotFiles{$stage});}
+
+    return 1;
+}
+
+###########################################################################
+#
+# Plots a stacked histogram of rate data for one or more stages
+#
+###########################################################################
+sub plotRateStackedHistogram {
+    my ($self, $gnuplotFiles, $outputFile, $label, $selectedStage, $beginTime, $endTime, $interval) = @_;
+
     open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
     use FileHandle;
@@ -173,5 +217,5 @@
     print GP
         "set term $self->{_outputFormat};" .
-        "set title \"'$label', '$selectedStage'\\nFrom '$beginTime' to '$endTime' HST\";" .
+        "set title \"'$label' for '$selectedStage'\\nFrom '$beginTime' to '$endTime' HST\";" .
         "set boxwidth;" .
         "set xtic rotate by -90 scale 0;" .
@@ -184,27 +228,16 @@
 
     my $first = 1;
-    foreach $stage (@{$stages}) {
-
-        if ($self->{_czarDb}->createProcessingRateData(
-                    $stage, 
-                    $label, 
-                    $beginTime, 
-                    $endTime, 
-                    $interval,
-                    \$gnuplotFile)) {
-
-            $gnuplotFiles{$stage} = $gnuplotFile;
-
-            if (!$first) { print GP ","; }
-            print GP "'$gnuplotFile' using 2:xtic(1) title \"$stage\" ";
-            $first = 0;
-        }
+    foreach my $stage (@allStages) {
+
+
+        if(!$gnuplotFiles->{$stage}) {next;}
+
+        if (!$first) { print GP ","; }
+        print GP "'" . $gnuplotFiles->{$stage}. "' using 4:xtic(1) title \"$stage\" ";
+        $first = 0;
     }
 
     print GP ";\n";
     close GP;
-
-    # now delete temp dat files
-    foreach my $stage (keys %gnuplotFiles) {unlink($gnuplotFiles{$stage});}
 
     return 1;
@@ -265,4 +298,8 @@
 
     my $outputFile = createImageFileName($self, $label, $selectedStage, "t", $isLog);
+    my $yTitle;
+    if ($isLog) {$yTitle = "Log(Exposures)";}
+    elsif ($deriv) {$yTitle = "dExposures/dTime(secs)";}
+    else {$yTitle = "Exposures";}
     $self->plotTimeSeries(
             \%gnuplotFiles, 
@@ -274,6 +311,6 @@
             $minX, 
             $timeDiff, 
-            $isLog,
-            $deriv);
+            "",
+            $yTitle);
 }                                                    
 
@@ -365,5 +402,5 @@
 ###########################################################################
 #
-# Figures out suitable spacing for time tics on time-series pliots
+# Figures out suitable spacing for time tics on time-series plots
 #
 ###########################################################################
@@ -427,12 +464,12 @@
 ###########################################################################
 sub plotTimeSeries {
-    my ($self, $gnuplotFiles, $outputFile, $label, $fromTime, $toTime, $maxX, $minX, $timeDiff, $isLog, $isDeriv) = @_;
+    my ($self, $gnuplotFiles, $outputFile, $label, $fromTime, $toTime, $maxX, $minX, $timeDiff, $title, $yTitle) = @_;
 
     my $timeFormat = undef;
     my $divX = undef;
-    my $yTitle = undef;
-    if ($isLog) {$yTitle = "Log( Exposures )";}
-    elsif ($isDeriv) {$yTitle = "dExposures/dTime(secs)";}
-    else {$yTitle = "Exposures";}
+    #my $yTitle = undef;
+    #if ($isLog) {$yTitle = "Log( Exposures )";}
+    #elsif ($isDeriv) {$yTitle = "dExposures/dTime(secs)";}
+    #else {$yTitle = "Exposures";}
 
     $self->getTimeSpacing($timeDiff, \$divX, \$timeFormat);
@@ -441,6 +478,6 @@
 
     # sort out plot title
-    my $title = "";
-    if ($isDeriv) {$title .= "First derivatives of "}
+    #my $title = "";
+    #if ($isDeriv) {$title .= "First derivatives of "}
     if ($numOfPlots == 1) {foreach my $stage (keys %$gnuplotFiles) {$title .= "'".$stage."'";}}
     else {$title .= "'all stages'"}
@@ -462,4 +499,5 @@
         "set xtics \"$minX\", $divX, \"$maxX\";" .
         "set grid xtics;" .
+        "set grid ytics;" .
         "set xlabel \"Time\";" .
         "set ylabel \"$yTitle\";" .
