Diff for /loncom/cgi/graph.png between versions 1.29 and 1.33

version 1.29, 2003/10/27 21:21:08 version 1.33, 2004/01/08 15:50:17
Line 38  graph.png Line 38  graph.png
   
 =head1 SYNOPSIS  =head1 SYNOPSIS
   
 produces plots based on input  produces plots from data stored in users environment.
   
 =head1 DESCRIPTION  =head1 DESCRIPTION
   
 graph.png is a cgi-bin script which produces plots based on input data.  graph.png is a cgi-bin script which produces plots based on data stored
   in the users environment.  The users cookie is checked prior to producing
 The query string is expected to be as follows (without whitespace):  a plot.  The query string is expected to be an identifier, $id.  
   The parameters defining the plot must be stored in the environment as 
 escape(Plot title) & escape(X label)& escape(Y label) & Maximum Y value &  $ENV{'cgi.'.$id.'.'.$dataname}.  Two types of plots can be produced, 'bar'
 Number of bars & $data1 & $data2  and 'xy'.  The 'xy' graph can will 1 or 2 y-axes if the parameter
   'two_axes' is set to false or true respectively.  See perldoc GD::Graph and
 $data1 and $data2 are expected to be comma seperated lists of numbers.  loncommon::DrawBarGraph, loncommon::DrawXYGraph, and loncommon::DrawXYYGraph.
 escape( value ) means the values must be run through lonnet::escape.  
   
 =cut  =cut
   
Line 90  END Line 89  END
 my $id = $ENV{'QUERY_STRING'};  my $id = $ENV{'QUERY_STRING'};
   
 #  #
 # &get_env($name,$default)  # usage: &get_env($name,$default)
 sub get_env {  sub get_env {
     my $key = 'cgi.'.$id.'.'.(shift());      my $key = 'cgi.'.$id.'.'.(shift());
     return shift if (! exists($ENV{$key}));      return shift if (! exists($ENV{$key}));
Line 113  END Line 112  END
   
 $|=1;   # Autoflush after each print/write  $|=1;   # Autoflush after each print/write
   
   ##
   ## Set up the plot
   ##
 my $colordefaults = join(',',  my $colordefaults = join(',',
                          ('#33ff00',                            ('#33ff00', 
                           '#0033cc','#990000','#aaaa66','#663399','#ff9933',                            '#0033cc','#990000','#aaaa66','#663399','#ff9933',
Line 143  my %GraphSettings = ( Line 145  my %GraphSettings = (
   
 $GraphSettings{'x_label_skip'}  = &get_env('xskip',1);  $GraphSettings{'x_label_skip'}  = &get_env('xskip',1);
 $GraphSettings{'x_tick_offset'} = &get_env('x_tick_offset',0);  $GraphSettings{'x_tick_offset'} = &get_env('x_tick_offset',0);
 $GraphSettings{'y_max_value'}   = &get_env('Max',undef);  $GraphSettings{'y_max_value'}   = &get_env('y_max_value',1);
   
 my $MyGraph;  my $MyGraph;
 if ($PlotType eq 'bar') {  if ($PlotType eq 'bar') {
Line 168  if ($PlotType eq 'bar') { Line 170  if ($PlotType eq 'bar') {
     $GraphSettings{'x_label_skip'}  = $skip_x;      $GraphSettings{'x_label_skip'}  = $skip_x;
     $GraphSettings{'x_tick_offset'} = $x_tick_offset;      $GraphSettings{'x_tick_offset'} = $x_tick_offset;
     $GraphSettings{'zero_axis'}     = 1;      $GraphSettings{'zero_axis'}     = 1;
       if (&get_env('two_axes',0)) {
           $GraphSettings{'two_axes'}     = 1;
           $GraphSettings{'y1_label'}     = &get_env('y1_label',
                                                     $GraphSettings{'y_label'});
           $GraphSettings{'y2_label'}     = &get_env('y2_label','');
           $GraphSettings{'y1_max_value'} = &get_env('y1_max_value',0);
           $GraphSettings{'y1_min_value'} = &get_env('y1_min_value',1);
           $GraphSettings{'y2_max_value'} = &get_env('y2_max_value',1);
           $GraphSettings{'y2_min_value'} = &get_env('y2_min_value',1);
       }
 }  }
 #  #
 # Pick up miscellanious values passed in by the user  # Pick up miscellanious values passed in by the user
Line 186  if (! defined($MyGraph)) { Line 198  if (! defined($MyGraph)) {
 ##  ##
 ## Build the @Data array  ## Build the @Data array
 my $NumSets = &get_env('NumSets');  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'));  my @xlabels  = split(',',&get_env('labels'));
 push(@Data,\@xlabels);  push(@Data,\@xlabels);
 for (my $i=1;$i<=$NumSets;$i++) {  for (my $i=1;$i<=$NumSets;$i++) {
     push(@Data,[split(',',&get_env('data.'.$i))]);      push(@Data,[split(',',&get_env('data.'.$i))]);
       push(@Legend,&get_env('data.'.$i.'.label',undef));
 }  }
   
 my $error = '';  my $error = '';
Line 199  if (! $MyGraph->set(%GraphSettings)) { Line 213  if (! $MyGraph->set(%GraphSettings)) {
     return;      return;
 }  }
   
   if (join('',@Legend) ne '') {
       $MyGraph->set_legend(@Legend);
   }
   
   
 my $plot = $MyGraph->plot(\@Data);  my $plot = $MyGraph->plot(\@Data);
 if (! defined($plot)) {  if (! defined($plot)) {
     my $error = 'Unable to plot the data provided.';      my $error = 'Unable to plot the data provided.';
     $error .= '<pre>'.join(',',@{$Data[0]}).'</pre>';  # Debugging code:    
     $error .= '<pre>'.join(',',@{$Data[1]}).'</pre>';  #    $error .= '<pre>'.join(',',@{$Data[0]}).'</pre>';
     $error .= '<pre>'.join(',',@{$Data[2]}).'</pre>';  #    $error .= '<pre>'.join(',',@{$Data[1]}).'</pre>';
   #    $error .= '<pre>'.join(',',@{$Data[2]}).'</pre>' if (ref($Data[2]));
   #    $error .= '<pre>'.join(',',@{$Data[3]}).'</pre>' if (ref($Data[3]));
     print &error($error);      print &error($error);
     exit;      exit;
 }  }

Removed from v.1.29  
changed lines
  Added in v.1.33


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>