--- loncom/homework/functionplotresponse.pm 2010/11/13 03:22:58 1.37 +++ loncom/homework/functionplotresponse.pm 2010/11/19 17:20:44 1.40 @@ -1,7 +1,7 @@ # LearningOnline Network with CAPA # option list style responses # -# $Id: functionplotresponse.pm,v 1.37 2010/11/13 03:22:58 www Exp $ +# $Id: functionplotresponse.pm,v 1.40 2010/11/19 17:20:44 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -47,7 +47,7 @@ sub geogebra_startcode { my ($id)=@_; return (< + codebase="/adm/geogebra/" width="722" height="447" MAYSCRIPT> ENDSTARTCODE } @@ -74,9 +74,8 @@ sub geogebra_default_parameters { - - - + + @@ -159,16 +158,40 @@ sub update_register { } # -# Set a coordinate variable +# Set a point coordinate variable # -sub set_coordinate { +sub set_point_coordinate { my ($id,$variable,$x,$y)=@_; return (<'. - &Apache::edit::select_arg(&mt('Relationship:'),'relationship', + &Apache::edit::select_or_text_arg(&mt('Relationship:'),'relationship', [['eq','equal'], ['ne','not equal'], ['ge','greater than or equal'], @@ -595,7 +649,11 @@ sub d2dt2_cubic_hermite { # sub array_index { my ($xmin,$xmax,$x)=@_; - return int(($x-$xmin)/($xmax-$xmin)*400.+0.5); + if ($x ne '') { + return int(($x-$xmin)/($xmax-$xmin)*400.+0.5); + } else { + return undef; + } } # @@ -886,7 +944,7 @@ sub functionplotrulecheck { # Basic sanity checks if ($li<0) { $li=0; } if ($lh>400) { $lh=400; } - if ($li>$lh) { + if (($li>$lh) || (!defined($lh))) { $lh=$li; } @@ -1064,8 +1122,22 @@ sub end_functionplotelements { $result=&Apache::edit::end_table(); } elsif ($target eq 'web') { # Now is the time to render all of the stored splines + my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval,-2); + $xmin=(defined($xmin)?$xmin:-10); + my $xmax=&Apache::lonxml::get_param('xmax',$parstack,$safeeval,-2); + $xmax=(defined($xmax)?$xmax:10); + my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval,-2); + $ymin=(defined($ymin)?$ymin:-10); + my $ymax=&Apache::lonxml::get_param('ymax',$parstack,$safeeval,-2); + $ymax=(defined($ymax)?$ymax:10); + if ($xmax<=$xmin) { + $xmax=$xmin+20; + } + if ($ymax<=$ymin) { + $ymax=$ymin+20; + } foreach my $label (keys(%Apache::functionplotresponse::splineorder)) { - $result.=&generate_spline($internalid,$label); + $result.=&generate_spline($internalid,$label,$xmin,$xmax,$ymin,$ymax); } # close the init script $result.=&end_init_script();