--- loncom/xml/lonplot.pm 2001/12/21 16:59:01 1.14
+++ loncom/xml/lonplot.pm 2001/12/21 21:39:51 1.16
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Dynamic plot
#
-# $Id: lonplot.pm,v 1.14 2001/12/21 16:59:01 matthew Exp $
+# $Id: lonplot.pm,v 1.16 2001/12/21 21:39:51 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -71,10 +71,10 @@ my $int_test = sub {$_[0]=~s/\s+//
my $real_test = sub {$_[0]=~s/\s+//g;$_[0]=~/^[+-]?\d*\.?\d*$/};
my $color_test = sub {$_[0]=~s/\s+//g;$_[0]=~/^x[\da-f]{6}$/};
my $onoff_test = sub {$_[0]=~/^(on|off)$/};
-my $key_pos_test = sub {$_[0]=~/^(top|bottom|right|left|outside|below)+$/};
+my $key_pos_test = sub {$_[0]=~/^(top|bottom|right|left|outside|below| )+$/};
my $sml_test = sub {$_[0]=~/^(small|medium|large)$/};
my $linestyle_test = sub {$_[0]=~/^(lines|linespoints|dots|points|steps)$/};
-my $words_test = sub {$_[0]=~s/\s+/ /g;$_[0]=~/^(\w+ ?)+$/};
+my $words_test = sub {$_[0]=~s/\s+/ /g;$_[0]=~/^([\w\(\)]+ ?)+$/};
##
## Default values for attributes of elements
##
@@ -87,7 +87,8 @@ my %plot_defaults =
transparent => {default => 'off', test => $onoff_test },
grid => {default => 'off', test => $onoff_test },
border => {default => 'on', test => $onoff_test },
- font => {default => 'medium', test => $sml_test }
+ font => {default => 'medium', test => $sml_test },
+ align => {default => 'left', test => $words_test }
);
my %key_defaults =
@@ -111,7 +112,8 @@ my %axis_defaults =
xmin => {default => '-10.0', test => $real_test },
xmax => {default => ' 10.0', test => $real_test },
ymin => {default => '-10.0', test => $real_test },
- ymax => {default => ' 10.0', test => $real_test }
+ ymax => {default => ' 10.0', test => $real_test },
+ linestyle => {default => 'points', test => $linestyle_test}
);
my %curve_defaults =
@@ -186,8 +188,11 @@ sub end_plot {
close($fh);
## return image tag for the plot
$result .= <<"ENDIMAGE";
-
+
ENDIMAGE
}
return $result;
@@ -359,7 +364,7 @@ sub start_data {
delete($curves[-1]->{'function'});
}
my $datatext = &Apache::lonxml::get_all_text("/data",$$parser[-1]);
- $datatext =~ s/\s+//g; # No whitespace, numbers must be seperated
+ $datatext =~ s/\s+/ /g; # No whitespace, numbers must be seperated
# by commas
if ($datatext !~ /^(([+-]?\d*\.?\d*)[, ]?)+$/) {
&Apache::lonxml::warning('Malformed data: '.$datatext);
@@ -368,7 +373,12 @@ sub start_data {
# Need to do some error checking on the @data array -
# make sure it's all numbers and make sure each array
# is of the same length.
- my @data = split /,/,$datatext;
+ my @data;
+ if ($datatext =~ /,/) {
+ @data = split /,/,$datatext;
+ } else { # Assume it's space seperated.
+ @data = split / /,$datatext;
+ }
for (my $i=0;$i<=$#data;$i++) {
# Check that it's non-empty
# Check that it's a number
@@ -432,7 +442,7 @@ sub get_attributes{
my $attr;
foreach $attr (keys %{$defaults}) {
$values->{$attr} =
- &Apache::lonxml::get_param($attr,$parstack,$safeeval);
+ &Apache::lonxml::get_param($attr,$parstack,$safeeval);
if ($values->{$attr} eq '' | !defined($values->{$attr})) {
$values->{$attr} = $defaults->{$attr}->{'default'};
next;
@@ -447,7 +457,7 @@ sub get_attributes{
}
return ;
}
-
+##------------------------------------------------------- write_gnuplot_file
sub write_gnuplot_file {
my $gnuplot_input = '';
my $curve;
@@ -456,7 +466,6 @@ sub write_gnuplot_file {
push @Colors, $plot{'bgcolor'};
push @Colors, $plot{'fgcolor'};
push @Colors, (defined($axis{'color'})?$axis{'color'}:$plot{'fgcolor'});
- push @Colors, $Colors[-1]; # Redundancy
foreach $curve (@curves) {
push @Colors, ($curve->{'color'} ne '' ?
$curve->{'color'} :