'.
- &Apache::edit::editfield('',$text,'',20,1);
+ $result .= &Apache::edit::end_row().
+ &Apache::edit::start_spanning_row().
+ &Apache::edit::editfield('',$text,'',60,1);
} elsif ($target eq 'modified') {
- # Why do I do this?
+ $result.=&Apache::edit::rebuild_tag($token);
my $text=$$parser[-1]->get_text("/function");
$result.=&Apache::edit::modifiedfield($token);
}
@@ -567,12 +611,17 @@ sub start_data {
delete($curves[-1]->{'function'});
}
my $datatext = &Apache::lonxml::get_all_text("/data",$$parser[-1]);
+ # Deal with cases where we're given an array...
+ if ($datatext =~ /^\@/) {
+ $datatext = &Apache::run::run('return "'.$datatext.'"',
+ $safeeval,1);
+ }
$datatext =~ s/\s+/ /g;
# 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;
- if ($datatext =~ /,/) {
+ if ($datatext =~ /,/) { # comma deliminated
@data = split /,/,$datatext;
} else { # Assume it's space seperated.
@data = split / /,$datatext;
@@ -593,13 +642,22 @@ sub start_data {
$data[$i] = 1.15572734979092;
}
}
+ # complain if the number of data points is not the same as
+ # in previous sets of data.
+ if (($curves[-1]->{'data'}) && ($#data != $#{@{$curves[-1]->{'data'}->[0]}})){
+ &Apache::lonxml::warning
+ ('Number of data points is not consistent with previous '.
+ 'number of data points');
+ }
push @{$curves[-1]->{'data'}},\@data;
} elsif ($target eq 'edit') {
- $result .= &Apache::edit::tag_start($target,$token,'Curve Data');
+ $result .= &Apache::edit::tag_start($target,$token,'Comma or space deliminated curve data');
my $text = &Apache::lonxml::get_all_text("/data",$$parser[-1]);
- $result .= '
'.
- &Apache::edit::editfield('',$text,'',20,1);
+ $result .= &Apache::edit::end_row().
+ &Apache::edit::start_spanning_row().
+ &Apache::edit::editfield('',$text,'',60,1);
} elsif ($target eq 'modified') {
+ $result.=&Apache::edit::rebuild_tag($token);
my $text=$$parser[-1]->get_text("/data");
$result.=&Apache::edit::modifiedfield($token);
}
@@ -627,6 +685,11 @@ sub start_axis {
$result .= &Apache::edit::tag_start($target,$token,'Plot Axes');
$result .= &edit_attributes($target,$token,\%axis_defaults);
} elsif ($target eq 'modified') {
+ my $constructtag=&Apache::edit::get_new_args
+ ($token,$parstack,$safeeval,keys(%axis_defaults));
+ if ($constructtag) {
+ $result = &Apache::edit::rebuild_tag($token);
+ }
}
return $result;
}
@@ -638,12 +701,6 @@ sub end_axis {
} elsif ($target eq 'edit') {
$result.=&Apache::edit::tag_end($target,$token);
} elsif ($target eq 'modified') {
- my $constructtag=&Apache::edit::get_new_args
- ($token,$parstack,$safeeval,keys(%axis_defaults));
- if ($constructtag) {
- $result = &Apache::edit::rebuild_tag($token);
- $result.= &Apache::edit::handle_insert();
- }
}
return $result;
}
@@ -683,8 +740,10 @@ sub get_attributes{
}
return ;
}
+
##------------------------------------------------------- write_gnuplot_file
sub write_gnuplot_file {
+ my ($tmpdir,$filename)= @_;
my $gnuplot_input = '';
my $curve;
# Collect all the colors
@@ -735,7 +794,6 @@ sub write_gnuplot_file {
}
# curves
$gnuplot_input .= 'plot ';
- my $datatext = '';
for (my $i = 0;$i<=$#curves;$i++) {
$curve = $curves[$i];
$gnuplot_input.= ', ' if ($i > 0);
@@ -745,9 +803,12 @@ sub write_gnuplot_file {
$curve->{'name'}.'" with '.
$curve->{'linestyle'};
} elsif (exists($curve->{'data'})) {
- $gnuplot_input.= '\'-\' title "'.
- $curve->{'name'}.'" with '.
- $curve->{'linestyle'};
+ # Store data values in $datatext
+ my $datatext = '';
+ # get new filename
+ my $datafilename = "$tmpdir/$filename.$i";
+ my $fh=Apache::File->new(">$datafilename");
+ # Compile data
my @Data = @{$curve->{'data'}};
my @Data0 = @{$Data[0]};
for (my $i =0; $i<=$#Data0; $i++) {
@@ -757,11 +818,21 @@ sub write_gnuplot_file {
}
$datatext .= $/;
}
- $datatext .=$/;
+ # write file
+ print $fh $datatext;
+ close ($fh);
+ # generate gnuplot text
+ $gnuplot_input.= '"'.$datafilename.'" title "'.
+ $curve->{'name'}.'" with '.
+ $curve->{'linestyle'};
}
}
- $gnuplot_input .= $/.$datatext;
- return $gnuplot_input;
+ # Write the output to a file.
+ my $fh=Apache::File->new(">$tmpdir$filename");
+ print $fh $gnuplot_input;
+ close($fh);
+ # That's all folks.
+ return ;
}
#---------------------------------------------- check_inputs
@@ -770,7 +841,7 @@ sub check_inputs {
## Make sure we have all the input we need:
if (! %plot) { &set_defaults(\%plot,\%plot_defaults); }
if (! %key ) {} # No key for this plot, thats okay
- if (! %axis) { &set_defaults(\%axis,\%axis_defaults); }
+# if (! %axis) { &set_defaults(\%axis,\%axis_defaults); }
if (! defined($title )) {} # No title for this plot, thats okay
if (! defined($xlabel)) {} # No xlabel for this plot, thats okay
if (! defined($ylabel)) {} # No ylabel for this plot, thats okay
@@ -790,20 +861,27 @@ sub check_inputs {
#------------------------------------------------ make_edit
sub edit_attributes {
- my ($target,$token,$defaults) = @_;
- my $result;
- foreach my $attr (sort keys(%$defaults)) {
+ my ($target,$token,$defaults,$keys) = @_;
+ my ($result,@keys);
+ if ($keys && ref($keys) eq 'ARRAY') {
+ @keys = @$keys;
+ } else {
+ @keys = sort(keys(%$defaults));
+ }
+ foreach my $attr (@keys) {
+ # append a ' ' to the description if it doesn't have one already.
+ my $description = $defaults->{$attr}->{'description'};
+ $description .= ' ' if ($description !~ / $/);
if ($defaults->{$attr}->{'edit_type'} eq 'entry') {
- $result .= &Apache::edit::text_arg(
- $defaults->{$attr}->{'description'},
- $attr,
- $token);
+ $result .= &Apache::edit::text_arg
+ ($description,$attr,$token,
+ $defaults->{$attr}->{'size'});
} elsif ($defaults->{$attr}->{'edit_type'} eq 'choice') {
- $result .= &Apache::edit::select_arg(
- $defaults->{$attr}->{'description'},
- $attr,
- $defaults->{$attr}->{'choices'},
- $token);
+ $result .= &Apache::edit::select_arg
+ ($description,$attr,$defaults->{$attr}->{'choices'},$token);
+ } elsif ($defaults->{$attr}->{'edit_type'} eq 'on_off') {
+ $result .= &Apache::edit::select_arg
+ ($description,$attr,['on','off'],$token);
}
$result .= ' ';
}
@@ -819,24 +897,20 @@ sub edit_attributes {
#------------------------------------------------ insert_xxxxxxx
sub insert_plot {
- my $result;
+ my $result = '';
# plot attributes
- $result .= '{'default'}.
- "\"\n";
+ $result .= "{'default'}\"\n";
}
$result .= ">\n";
# Add the components
$result .= &insert_key();
$result .= &insert_axis();
- $result .= &insert_label();
+ $result .= &insert_title();
+ $result .= &insert_xlabel();
+ $result .= &insert_ylabel();
$result .= &insert_curve();
- $result .= &insert_function();
- $result .= "\n";
- $result .= &insert_curve();
- $result .= &insert_data();
- $result .= "\n";
# close up the
$result .= "\n";
return $result;
@@ -844,10 +918,9 @@ sub insert_plot {
sub insert_key {
my $result;
- $result .= ' {'default'}.
- "\"\n";
+ $result .= " {'default'}\"\n";
}
$result .= " />\n";
return $result;
@@ -856,19 +929,22 @@ sub insert_key {
sub insert_axis{
my $result;
$result .= ' {'default'}.
- "\"\n";
+ foreach my $attr (keys(%axis_defaults)) {
+ $result .= " $attr=\"$axis_defaults{$attr}->{'default'}\"\n";
}
$result .= " />\n";
return $result;
}
+sub insert_title { return " \n"; }
+sub insert_xlabel { return " \n"; }
+sub insert_ylabel { return " \n"; }
+
sub insert_label {
my $result;
$result .= ' \n";
@@ -877,12 +953,13 @@ sub insert_label {
sub insert_curve {
my $result;
- $result .= ' {'default'}."\"\n";
}
$result .= " >\n";
+ $result .= &insert_data().&insert_data()."\n";
}
sub insert_function {
@@ -894,7 +971,6 @@ sub insert_function {
sub insert_data {
my $result;
$result .= " \n";
- $result .= " \n";
return $result;
}