Index: trunk/tools/czartool/Czarplot.pm
===================================================================
--- trunk/tools/czartool/Czarplot.pm	(revision 28804)
+++ trunk/tools/czartool/Czarplot.pm	(revision 28845)
@@ -154,10 +154,49 @@
     my ($self, $minY, $maxY) = @_;
 
-    ${$maxY} = ${$maxY} + (${$maxY}/10);
-    ${$minY} = ${$minY} - (${$minY}/10);
+    my $border = (${$maxY} - ${$minY})/10;
+
+    ${$maxY} += $border;
+    ${$minY} -= $border ;
     if (${$maxY} == 0) {${$maxY} = 1;}
     if (${$minY} == 0) {${$minY} = -1;}
 }
 
+
+###########################################################################
+#
+# Figures out suitable spacing for time tics on time-series pliots
+#
+###########################################################################
+sub getTimeSpacing {
+    my ($self, $timeDiff, $divX, $timeFormat) = @_;
+
+    # if less than a couple of hour's data plotted, show 30 mins tics
+    if ($timeDiff < 7200) {
+        ${$timeFormat} = "%H:%M";
+        ${$divX} = 1800;
+    }
+    # if less than half a day's data plotted, show hourly tics
+    elsif ($timeDiff < 43200) {
+        ${$timeFormat} = "%H:%M";
+        ${$divX} = 3600;
+    }
+    # if less than one day's data plotted, show 2 hourly tics
+    elsif ($timeDiff < 86400) {
+        ${$timeFormat} = "%H:%M";
+        ${$divX} = 7200;
+    }
+    # if less than 1 week's data is data plotted, show daily tics
+    elsif ($timeDiff < 604800) {
+
+        ${$timeFormat} = "%m/%d";
+        ${$divX} = 86400;
+    }
+    else {
+
+        ${$timeFormat} = "%m/%d";
+        ${$divX} = 172800;
+    }
+}
+
 ###########################################################################
 #
@@ -171,34 +210,7 @@
 
     my $timeFormat = undef;
-
-    my $divX = $timeDiff/4;
-
-    # if less than a couple of hour's data plotted, show 30 mins tics
-    if ($timeDiff < 7200) {
-        $timeFormat = "%H:%M";
-        $divX = 1800;
-    }
-    # if less than half a day's data plotted, show hourly tics
-    elsif ($timeDiff < 43200) {
-        $timeFormat = "%H:%M";
-        $divX = 3600;
-    }
-    # if less than one day's data plotted, show 2 hourly tics
-    elsif ($timeDiff < 86400) {
-        $timeFormat = "%H:%M";
-        $divX = 7200;
-    }
-    # if less than 1 week's data is data plotted, show daily tics
-    elsif ($timeDiff < 604800) {
-        
-        $timeFormat = "%m/%d";
-        $divX = 86400;
-    }
-    else {
-
-        $timeFormat = "%m/%d";
-        $divX = 172800;
-    }
-
+    my $divX = undef;
+
+    $self->getTimeSpacing($timeDiff, \$divX, \$timeFormat);
 
     my $numOfPlots = keys %$gnuplotFiles;
@@ -237,7 +249,7 @@
         if ($numOfPlots == 1) {
 
-            print GP "'" . $gnuplotFiles->{$stage} . "' using 1:4 title \"processed\" with lines lt 2,";
-            print GP "'" . $gnuplotFiles->{$stage} . "' using 1:2 title \"pending\" with lines lt 3,";
-            print GP "'" . $gnuplotFiles->{$stage} . "' using 1:3 title \"faults\" with lines lt 1";
+            print GP "'" . $gnuplotFiles->{$stage} . "' using 1:4 title \"Processed\" with lines lt 2,";
+            print GP "'" . $gnuplotFiles->{$stage} . "' using 1:2 title \"Pending\" with lines lt 4,";
+            print GP "'" . $gnuplotFiles->{$stage} . "' using 1:3 title \"Faults\" with lines lt 7";
         }
         # when plotting multiple stages, show only processed
@@ -249,4 +261,50 @@
 
     print GP "\n";
+    close GP;
+}
+
+###########################################################################
+#
+# Plots a time-series of cluster storage
+#
+###########################################################################
+sub plotStorageTimeSeries {
+    my ($self, $fromTime, $toTime) = @_;
+
+    my $outputFile = "/tmp/czarplot_cluster.png";
+    my ($minX, $maxX, $minY, $maxY, $timeDiff);
+
+    my $gnuplotFile = $self->{_czarDb}->createStorageTimeSeriesData($fromTime, $toTime, \$minX, \$maxX, \$minY, \$maxY, \$timeDiff);
+
+    $self->sortOutMaxMinY(\$minY, \$maxY);
+
+    my $timeFormat = undef;
+    my $divX = undef;
+
+    $self->getTimeSpacing($timeDiff, \$divX, \$timeFormat);
+
+    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
+    use FileHandle;
+    GP->autoflush(1);
+
+    print GP
+        "set term $self->{_outputFormat};" .
+        "set output \"$outputFile\";" .
+        "set title \"hmjhhjhj\";" .
+        "set key left top;" .
+        "set xdata time;" .
+        "set timefmt \"$self->{_dateFormat}\";" .
+        "set xrange [\"$minX\":\"$maxX\"];" .
+        "set yrange [\"$minY\":\"$maxY\"];" .
+        "set format x \"$timeFormat\";" .
+        "set xtics \"$minX\", $divX, \"$maxX\";" .
+        "set grid xtics;" .
+        "set xlabel \"Time\";" .
+        "set ylabel \"Available (TB)\";" .
+        "plot " . 
+#        "'$gnuplotFile' using 1:2 title \"Total\" with lines lt 1," .
+        "'$gnuplotFile' using 1:2 title \"Available\" with lines lt 2\n";
+
+        print GP "\n";
     close GP;
 }
@@ -275,8 +333,40 @@
         "set bmargin 5;" .
         "set ylabel \"Exposures\";" .
-        "plot '$inputFile' using 2:xtic(1) title \"Processed\" lt 2, '' using 3 title \"Pending\" lt 3, '' using 4 title \"Faults\" lt 1\n";
+        "plot '$inputFile' using 2:xtic(1) title \"Processed\" lt 2, '' using 3 title \"Pending\" lt 4, '' using 4 title \"Faults\" lt 7;" . 
+        "\n";
 
     close GP;
 }
 
+###########################################################################
+#
+# Plots disk usage across cluster as a stacked histogram
+#
+###########################################################################
+sub plotDiskUsageHistogram {
+    my ($self) = @_;
+
+    my $outputFile = "/tmp/czarplot_hosts.png";
+
+    my $inputFile = $self->{_czarDb}->createHostsData();
+
+    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
+    use FileHandle;
+    GP->autoflush(1);
+
+    print GP
+        "set term $self->{_outputFormat};" .
+        "set output \"$outputFile\";" .
+        "set title \"Nebulous disk use across IPP cluster\";" .
+        "set style fill solid 1.00 border -1;" .
+        "set style histogram rowstacked;" .
+        "set style data histograms;" .
+        "set ylabel \"Space (TB)\";" .
+        "set xtic rotate by -90 scale 0;" .
+        "plot '$inputFile' using 2:xtic(1) t \"Used\" , '' using 3 t \"Available\";" .
+
+        "\n";
+
+    close GP;
+}
 1;
