[LON-CAPA-cvs] cvs: loncom /cgi graph.png

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 08 Jan 2004 15:50:17 -0000


matthew		Thu Jan  8 10:50:17 2004 EDT

  Modified files:              
    /loncom/cgi	graph.png 
  Log:
  Added support for graph legends/keys
  
  
Index: loncom/cgi/graph.png
diff -u loncom/cgi/graph.png:1.32 loncom/cgi/graph.png:1.33
--- loncom/cgi/graph.png:1.32	Thu Dec 18 11:33:02 2003
+++ loncom/cgi/graph.png	Thu Jan  8 10:50:17 2004
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 #
-# $Id: graph.png,v 1.32 2003/12/18 16:33:02 matthew Exp $
+# $Id: graph.png,v 1.33 2004/01/08 15:50:17 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -198,11 +198,13 @@
 ##
 ## Build the @Data array
 my $NumSets = &get_env('NumSets');
-my @Data;  # stores the data for the graph
+my @Data;        # stores the data for the graph
+my @Legend;      # one entry per data set
 my @xlabels  = split(',',&get_env('labels'));
 push(@Data,\@xlabels);
 for (my $i=1;$i<=$NumSets;$i++) {
     push(@Data,[split(',',&get_env('data.'.$i))]);
+    push(@Legend,&get_env('data.'.$i.'.label',undef));
 }
 
 my $error = '';
@@ -210,6 +212,11 @@
     print &error($MyGraph->error);
     return;
 }
+
+if (join('',@Legend) ne '') {
+    $MyGraph->set_legend(@Legend);
+}
+
 
 my $plot = $MyGraph->plot(\@Data);
 if (! defined($plot)) {