--- loncom/homework/functionplotresponse.pm	2011/04/04 21:06:46	1.59
+++ loncom/homework/functionplotresponse.pm	2011/09/28 23:33:52	1.64
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: functionplotresponse.pm,v 1.59 2011/04/04 21:06:46 www Exp $
+# $Id: functionplotresponse.pm,v 1.64 2011/09/28 23:33:52 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -74,8 +74,8 @@ sub geogebra_default_parameters {
         <param name="image" value="/adm/lonIcons/lonanim.gif"  />
         <param name="boxborder" value="false"  />
         <param name="centerimage" value="true"  />
-	<param name="cache_archive" value="geogebra.jar, geogebra_main.jar, geogebra_gui.jar, geogebra_cas.jar, geogebra_algos.jar, geogebra_export.jar, geogebra_javascript.jar, jlatexmath.jar, jlm_greek.jar, jlm_cyrillic.jar, geogebra_properties.jar" />
-	<param name="cache_version" value="3.9.214.0, 3.9.214.0, 3.9.214.0, 3.9.214.0, 3.9.214.0, 3.9.214.0, 3.9.214.0, 3.9.214.0, 3.9.214.0, 3.9.214.0, 3.9.214.0" />
+	<param name="cache_archive" value="geogebra.jar, geogebra_main.jar, geogebra_gui.jar, geogebra_cas.jar, geogebra_export.jar, geogebra_algos.jar, geogebra_javascript.jar, geogebra_properties.jar, jlatexmath.jar, jlm_cyrillic.jar, jlm_greek.jar" />
+	<param name="cache_version" value="3.9.219.0, 3.9.219.0, 3.9.219.0, 3.9.219.0, 3.9.219.0, 3.9.219.0, 3.9.219.0, 3.9.219.0, 3.9.219.0, 3.9.219.0, 3.9.219.0" />
         <param name="framePossible" value="false" />
 
         <param name="showResetIcon" value="false" />
@@ -380,7 +380,7 @@ sub answer_spline_script {
    if ($order<2) { $order=2; }
    if ($order>8) { $order=8; }
    $Apache::functionplotresponse::counter++;
-   my $label='C'.$Apache::functionplotresponse::counter;
+   my $label='CSpline'.$Apache::functionplotresponse::counter;
    my $output='document.ggbApplet_'.$id.'.evalCommand("'.$label.'=Spline'.$order.'[';
    for (my $i=0;$i<=$#points;$i+=4) {
       $output.="($points[$i],$points[$i+1]),($points[$i+2],$points[$i+3]),";
@@ -388,8 +388,12 @@ sub answer_spline_script {
    $output=~s/\,$//;
    $output.=']");'."\n";
    for (my $i=2; $i<2*$order; $i+=2) {
-       $output.='document.ggbApplet_'.$id.'.setColor("'.$label.'_'.$i.'",0,170,0);'."\n";
+       $output.='document.ggbApplet_'.$id.'.setColor("'.$label.'_'.($i>=10?'{':'').$i.($i>=10?'}':'').'",0,170,0);'."\n";
    }
+   for (my $i=1; $i<2*$order; $i+=2) {
+       $output.='document.ggbApplet_'.$id.'.setVisible("'.$label.'_'.($i>=10?'{':'').$i.($i>=10?'}':'').'",false);'."\n";
+   }
+
    return $output;
 }
 
@@ -747,7 +751,7 @@ sub array_index {
 #
 
 sub populate_arrays {
-    my ($id,$xmin,$xmax)=@_;
+    my ($id,$xmin,$xmax,$ymin,$ymax)=@_;
     for (my $i=0; $i<=400; $i++) {
        $Apache::functionplotresponse::actualxval[$i]=undef;
        $Apache::functionplotresponse::func[$i]=undef;
@@ -775,12 +779,19 @@ sub populate_arrays {
                 my $xi=&array_index($xmin,$xmax,$xreal);
                 if ($xi<$xiold) { return 'no_func'; }
                 if (($xi>$xiold) && ($xi>=0) && ($xi<=400)) {
-                   if (defined($Apache::functionplotresponse::func[$xi])) { return 'no_func'; }
                    $xiold=$xi;
                    $Apache::functionplotresponse::actualxval[$xi]=$xreal;
 # Function value
                    my $funcval=&cubic_hermite($t,@yparms);
+
+# Do we already have a value for this point, and is it different from the new one?
+                   if ((defined($Apache::functionplotresponse::func[$xi])) &&
+                       (abs($Apache::functionplotresponse::func[$xi]-$funcval)>($ymax-$ymin)/100.)) { 
+                       return 'no_func'; 
+                   }
+# Okay, remember the new point
                    $Apache::functionplotresponse::func[$xi]=$funcval;
+
                    if (defined($funcval)) {
                       if ($xi<$Apache::functionplotresponse::functionplotrulelabels{'start'}) {
                          $Apache::functionplotresponse::functionplotrulelabels{'start'}=$xi;
@@ -876,8 +887,7 @@ sub start_functionplotresponse {
              &Apache::edit::select_arg('Grid visible:','gridvisible',
                                   ['yes','no'],$token).'<br />'.
              &Apache::edit::text_arg('Background plot(s) for answer (function(x):xmin:xmax,function(x):xmin:xmax,x1:y1:sx1:sy1:x2:y2:sx2:sy2,...):',
-                                         'answerdisplay',$token,'50');
-
+                                         'answerdisplay',$token,'50').
              &Apache::edit::end_row().&Apache::edit::start_spanning_row();
   } elsif ($target eq 'modified') {
     my $constructtag=&Apache::edit::get_new_args($token,$parstack,
@@ -1166,7 +1176,7 @@ sub end_functionplotruleset {
         $Apache::functionplotresponse::ruleslog='';
         $Apache::functionplotresponse::functionplotrulelabels{'start'}=400;
         $Apache::functionplotresponse::functionplotrulelabels{'end'}=0;
-        if (&populate_arrays($internalid,$xmin,$xmax) eq 'no_func') {
+        if (&populate_arrays($internalid,$xmin,$xmax,$ymin,$ymax) eq 'no_func') {
            $ad='NOT_FUNCTION';
         } else {
            &addlog("Start of function ".&actualval($Apache::functionplotresponse::functionplotrulelabels{'start'},$xmin,$xmax)." (index ".