File:  [LON-CAPA] / loncom / homework / functionplotresponse.pm
Revision 1.44: download - view: text, annotated - select for diffs
Tue Nov 23 17:01:28 2010 UTC (13 years, 6 months ago) by www
Branches: MAIN
CVS tags: HEAD
Improvements to colorful editor

    1: # LearningOnline Network with CAPA
    2: # option list style responses
    3: #
    4: # $Id: functionplotresponse.pm,v 1.44 2010/11/23 17:01:28 www Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::functionplotresponse;
   30: use strict;
   31: use Apache::response();
   32: use Apache::lonlocal;
   33: use Apache::lonnet;
   34:  
   35: BEGIN {
   36:   &Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline',
   37:                                                             'functionplotrule','functionplotruleset',
   38:                                                             'functionplotelements'));
   39: }
   40: 
   41: #
   42: # There can be a number of applets on a page, each called ggbApplet_$id, 
   43: # where $id is the "_"-concatenated part and responseid
   44: #
   45: 
   46: sub geogebra_startcode {
   47:     my ($id)=@_;
   48:     return (<<ENDSTARTCODE);
   49: <applet name="ggbApplet_$id" code="geogebra.GeoGebraApplet" archive="geogebra.jar"
   50:          codebase="/adm/geogebra/"  width="722" height="447" MAYSCRIPT>
   51:        <param name="java_arguments" value="-Xmx512m -Djnlp.packEnabled=true"/>
   52: ENDSTARTCODE
   53: }
   54: 
   55: sub geogebra_endcode {
   56:     return &Apache::lonhtmlcommon::java_not_enabled()."</applet>\n";
   57: }
   58: 
   59: #
   60: # This is the internal GeoGebra bytecode which defines the spline functions
   61: #
   62: sub geogebra_spline_program {
   63:     return (<<ENDSPLINEPROGRAM);
   64: <param name="ggbBase64" value="UEsDBBQACAAIANOAcz0AAAAAAAAAAAAAAAASAAAAZ2VvZ2VicmFfbWFjcm8ueG1s7Vxtb6tGGv3c/grEh1Vuu4njlzje2/hW5b1Sb3ulu1qttGorYhPHrQ0WJomnv74zA9hxgGuGNfYYnw/JYDwM8ByYM545z7n7fjWfKc9euJwG/lBtX12riuePgvHUnwzVp+jhcqB+/+Hru4kXTLz70FUegnDuRkO1e9VVldVy+t4Pfnbn3nLhjrzPo0dv7v4UjNyIt/YYRYv3rdbLy8tVevxVEE5ak0l0tVqO6fHzmb8cqsnGe9rc1kEvXV69c33dbv33409x85dTfxm5/shTFXpdc3cUBspoPmYXMVQ/L2ZT3+uoShQEs5xdjjdbrHf971P7n8pn+vepQ8vOr6oyHQW+NZ157JKWj8HLj/6/6UGaGw7VKHzy1PSEP/qLp0hxr4fqD6ritmnh0rIzVDVadGnhqq207i9P0bryc1JbS2o/82r0pEva/IgFTYmmUXx+9yl6DEK2NXYjtofW9Gbe3PMjJSILumcRTP1IVWbuvTdjV/Lh66/u2FUrwf0f3ihKrjn9/sGdLT12vq/u6Pd6MAtChTZP8Z7w//f8vztbPLp0iz4HvOrMJV6oPLsz9m2yhzb3MRh7W3tdfzrnqCvLyFuwBto0hAvPGycPVXzJdGNBm+QP16sLGgVBOF4qq/jEChmqPVb+FR/Lq/Cb/Tz9Kzlt9/XeiMxeX81dK4nTjohpjYhY54ARo4/5/x2yzs2NPEHrH+Ixa0rQevsO2moRektGPGkk3PvfV5R/Vot482L1ThkqFxQs5Rtl9dtF9+r6nXKpdNPPHfb5W6XNCrrj4g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/Z16mn3Y/f3L1Dplr0P+MbffP0yooHXvH3aIe4IvgF+btNuNTTplGnDfZ5WTbf1dKo/qp6z5wxCgOoxUM5NGbk4IrtV8V19Un0qJTv/i124EENGo5lc8W9RrEHXPqDsZOVtsv+hk3B79Zi14uplzTui833OXcaz98wvtheLSclrA4atfXRMtLY/oK2D2Zv7f3Rfi3CfYnfnOaM31SlsceWwZzOvQON34y3fwFQSwcI3KfwzsQEAAClDgAAUEsBAhQAFAAIAAgA04BzPTOjqPpOCgAAU0wBABIAAAAAAAAAAAAAAAAAAAAAAGdlb2dlYnJhX21hY3JvLnhtbFBLAQIUABQACAAIANOAcz1FzN5dGgAAABgAAAAWAAAAAAAAAAAAAAAAAI4KAABnZW9nZWJyYV9qYXZhc2NyaXB0LmpzUEsBAhQAFAAIAAgA04BzPdyn8M7EBAAApQ4AAAwAAAAAAAAAAAAAAAAA7AoAAGdlb2dlYnJhLnhtbFBLBQYAAAAAAwADAL4AAADqDwAAAAA=" />
   65: ENDSPLINEPROGRAM
   66: }
   67: 
   68: #
   69: # The standard set of parameters inside <applet>
   70: #
   71: sub geogebra_default_parameters {
   72:    my ($id)=@_;
   73:    return(<<ENDDEFAULTPARAMETERS);
   74:         <param name="image" value="/adm/lonIcons/lonanim.gif"  />
   75:         <param name="boxborder" value="false"  />
   76:         <param name="centerimage" value="true"  />
   77: 	<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" />
   78: 	<param name="cache_version" value="3.9.115.0, 3.9.115.0, 3.9.115.0, 3.9.115.0, 3.9.115.0, 3.9.115.0, 3.9.115.0, 3.9.115.0, 3.9.115.0, 3.9.115.0, 3.9.115.0" />
   79:         <param name="framePossible" value="false" />
   80: 
   81:         <param name="showResetIcon" value="false" />
   82:         <param name="showAnimationButton" value="false" />
   83:         <param name="enableRightClick" value="false" />
   84:         <param name="errorDialogsActive" value="true" />
   85:         <param name="enableLabelDrags" value="false" />
   86:         <param name="showMenuBar" value="false" />
   87:         <param name="showToolBar" value="false" />
   88:         <param name="showToolBarHelp" value="false" />
   89:         <param name="showAlgebraInput" value="false" />
   90:         <param name="enableShiftDragZoom" value="false" />
   91:         <param name="allowRescaling" value="false" />
   92:         <param name="enableLabelDrags" value="false" />
   93:         <param name="ggbOnInitParam" value="applet_$id" />
   94: ENDDEFAULTPARAMETERS
   95: }
   96: 
   97: #
   98: # This subroutine is called by LON-CAPA at </problem>
   99: # Each applet on the page will call function ggbOnInit when it is done loading
  100: # This function in turn will call the respective function registered by start_init_script
  101: # Which one of the registered functions is called is determined by ggbOnInitParam, which GeoGebra passes to ggbOnInit
  102: #
  103: 
  104: sub init_script {
  105:    if ($#Apache::functionplotresponse::callscripts>=0) {
  106:       my $script='';
  107:       foreach my $id (@Apache::functionplotresponse::callscripts) {
  108:           $script.="if (param=='applet_$id') { loaded_$id=true; }\n";
  109:       }
  110:       $script.="if (".join(' && ',map { "loaded_$_" } (@Apache::functionplotresponse::callscripts)).
  111:                ") { setTimeout('ggbInitAll()',20) }";
  112:       my $calls=join("\n",map { "ggbInit_$_();" } (@Apache::functionplotresponse::callscripts)); 
  113:       return (<<ENDGGBINIT);
  114: <script type="text/javascript">
  115: // <![CDATA[
  116: // Function that each applet will call when loaded
  117: // It will pass "its" parameter
  118: // Set flags for when an applet is loaded, wait till all are loaded, and then some
  119: function ggbOnInit(param) {
  120: $script
  121: }
  122: function ggbInitAll() {
  123: $calls
  124: }
  125: // ]]>
  126: </script>
  127: ENDGGBINIT
  128:    }
  129: }
  130: 
  131: #
  132: # Each Geogebra applet is supposed to call this when parameters change
  133: # Changes the hidden fields on the web page
  134: #
  135: sub update_script {
  136:     my ($id)=@_;
  137:     return (<<ENDUPDATESCRIPT);
  138: <script type="text/javascript">
  139: // <![CDATA[
  140: function updatePointCoordinates_$id(coordinateName) {
  141:             var x = document.ggbApplet_$id.getXcoord(coordinateName);
  142:             var y = document.ggbApplet_$id.getYcoord(coordinateName);
  143:             document.lonhomework.elements["HWVAL_$id\_" + coordinateName + "_x"].value = x;
  144:             document.lonhomework.elements["HWVAL_$id\_" + coordinateName + "_y"].value = y;
  145:         }
  146: // ]]>
  147: </script>
  148: ENDUPDATESCRIPT
  149: }
  150: 
  151: #
  152: # Register the above update-handler for a variable
  153: #
  154: 
  155: sub update_register {
  156:    my ($id,$variable)=@_;
  157:    return "document.ggbApplet_$id.registerObjectUpdateListener('$variable','updatePointCoordinates_$id');\n";
  158: }
  159: 
  160: #
  161: # Set a point coordinate variable
  162: #
  163: sub set_point_coordinate {
  164:    my ($id,$variable,$x,$y)=@_;
  165:    return (<<ENDSETVARIABLE);
  166: document.ggbApplet_$id.evalCommand("$variable=($x,$y)");
  167: document.ggbApplet_$id.setLabelVisible("$variable",false);
  168: ENDSETVARIABLE
  169: }
  170: 
  171: #
  172: # Set a slope coordinate variable
  173: #
  174: sub set_slope_coordinate {
  175:    my ($id,$variable,$xrel,$yrel,$xmin,$xmax,$ymin,$ymax,$pointname)=@_;
  176:    my $xvariable=$variable.'x';
  177:    my $yvariable=$variable.'y';
  178:    my $domain=$xmax-$xmin;
  179:    my $range=$ymax-$ymin;
  180:    my $xinterval=$domain/100.;
  181:    my $yinterval=$range/200.;
  182:    return (<<ENDSETSVARIABLE);
  183: document.ggbApplet_$id.evalCommand("$xvariable=Slider[0,$domain,$xinterval]");
  184: document.ggbApplet_$id.setVisible("$xvariable", false);
  185: document.ggbApplet_$id.evalCommand("$xvariable=$xrel");
  186: document.ggbApplet_$id.evalCommand("$yvariable=Slider[-$range,$range,$yinterval]");
  187: document.ggbApplet_$id.setVisible("$yvariable", false);
  188: document.ggbApplet_$id.evalCommand("$yvariable=$yrel");
  189: document.ggbApplet_$id.evalCommand("$variable=($xvariable+x($pointname),$yvariable+y($pointname))");
  190: document.ggbApplet_$id.setLabelVisible("$variable", false);
  191: ENDSETSVARIABLE
  192: }
  193: 
  194: #
  195: # Input field name for a coordinate variable
  196: #
  197: 
  198: sub field_name {
  199:     my ($id,$variable,$name)=@_;
  200:     return "HWVAL_$id\_$variable\_$name";
  201: }
  202: 
  203: #
  204: # Generate an input field for a coordinate variable
  205: #
  206: 
  207: sub generate_input_field {
  208:     my ($id,$variable,$x,$y)=@_;
  209:     $Apache::functionplotresponse::inputfields.=
  210:        "<input type='hidden' name='".&field_name($id,$variable,'x')."' value='$x' />\n".
  211:        "<input type='hidden' name='".&field_name($id,$variable,'y')."' value='$y' />\n";
  212: }
  213: 
  214: #
  215: # Initialize a new point coordinate variable at set a listener on it
  216: #
  217: sub new_point_coordinate {
  218:     my ($id,$variable,$x,$y)=@_;
  219:     if (defined($Apache::functionplotresponse::previous{&field_name($id,$variable,'x')})) {
  220:        $x=$Apache::functionplotresponse::previous{&field_name($id,$variable,'x')};
  221:     }
  222:     if (defined($Apache::functionplotresponse::previous{&field_name($id,$variable,'y')})) {
  223:        $y=$Apache::functionplotresponse::previous{&field_name($id,$variable,'y')};
  224:     }
  225:     &generate_input_field($id,$variable,$x,$y);
  226:     return &set_point_coordinate($id,$variable,$x,$y).&update_register($id,$variable);
  227: }
  228: 
  229: #
  230: # Initialize a new slope coordinate variable at set a listener on it
  231: #
  232: sub new_slope_coordinate {
  233:     my ($id,$variable,$x,$y,$pointname,$xp,$yp,$xmin,$xmax,$ymin,$ymax)=@_;
  234: #
  235: # $variable: name of the slope point
  236: # $x, $y: coordinates of the slope point
  237: # $pointname: name of the associated point point
  238: # $xp $yp: coordinates of the point point
  239: #
  240:     if (defined($Apache::functionplotresponse::previous{&field_name($id,$variable,'x')})) {
  241:        $x=$Apache::functionplotresponse::previous{&field_name($id,$variable,'x')};
  242:     }
  243:     if (defined($Apache::functionplotresponse::previous{&field_name($id,$variable,'y')})) {
  244:        $y=$Apache::functionplotresponse::previous{&field_name($id,$variable,'y')};
  245:     }
  246:     if (defined($Apache::functionplotresponse::previous{&field_name($id,$pointname,'x')})) {
  247:        $xp=$Apache::functionplotresponse::previous{&field_name($id,$pointname,'x')};
  248:     }
  249:     if (defined($Apache::functionplotresponse::previous{&field_name($id,$pointname,'y')})) {
  250:        $yp=$Apache::functionplotresponse::previous{&field_name($id,$pointname,'y')};
  251:     }
  252: 
  253:     &generate_input_field($id,$variable,$x,$y);
  254:     my $xrel=$x-$xp;
  255:     my $yrel=$y-$yp;
  256:     return &set_slope_coordinate($id,$variable,$xrel,$yrel,$xmin,$xmax,$ymin,$ymax,$pointname).&update_register($id,$variable);
  257: }
  258: 
  259: #
  260: # This registers the init-function call for ggbOnInit, which LON-CAPA will place at </problem>
  261: # It then starts the right headers
  262: #
  263: sub start_init_script {
  264:     my ($id)=@_;
  265: # Add id to the list of ggbInit_$id functions that need to be called
  266:     push(@Apache::functionplotresponse::callscripts,$id);
  267: # ... and open this function
  268:     return (<<ENDSTARTINIT);
  269: <script type="text/javascript">
  270: // <![CDATA[
  271: // variable that will eventually be passed back to the server
  272: var coordinateMap_$id = [];
  273: // flag for not loaded yet
  274: var loaded_$id=false;
  275: // Init-function for applet
  276: function ggbInit_$id() {
  277: ENDSTARTINIT
  278: }
  279: 
  280: #
  281: # This sets the axes inside ggbInit_$id
  282: #
  283: 
  284: sub axes_script {
  285:     my ($id,$xmin,$xmax,$ymin,$ymax,$xvisible,$yvisible,$gvisible)=@_;
  286:     return (<<ENDAXESSCRIPT);
  287:             // changes (xmin, xmax, ymin, ymax)
  288:             document.ggbApplet_$id.setCoordSystem($xmin,$xmax,$ymin,$ymax);
  289: 
  290:             // makes the (x,y) axis (in)visible
  291:             document.ggbApplet_$id.setAxesVisible($xvisible,$yvisible);
  292:             // makes the grid (in)visible
  293:             document.ggbApplet_$id.setGridVisible($gvisible);
  294: ENDAXESSCRIPT
  295: }
  296: 
  297: sub axes_label {
  298:     my ($id,$xlabel,$ylabel)=@_;
  299:     unless ($xlabel || $ylabel) { return ''; }
  300:     my $return='document.ggbApplet_'.$id.'.evalCommand("topRight=Corner[3]");';
  301:     if ($xlabel) {
  302:        $return.=(<<ENDXAXISLABELSCRIPT);
  303: document.ggbApplet_$id.evalCommand("Xlabel=(x(topRight)-AxisStepX[],AxisStepY[]/6)");
  304: document.ggbApplet_$id.setVisible("Xlabel",false);
  305: document.ggbApplet_$id.evalCommand("Text[\\"$xlabel\\", Xlabel]");
  306: ENDXAXISLABELSCRIPT
  307:     }
  308:     if ($ylabel) {
  309:        $return.=(<<ENDYAXISLABELSCRIPT);
  310: document.ggbApplet_$id.evalCommand("Ylabel=(AxisStepX[]/6,y(topRight)-AxisStepY[]/3)");
  311: document.ggbApplet_$id.setVisible("Ylabel",false);
  312: document.ggbApplet_$id.evalCommand("Text[\\"$ylabel\\", Ylabel]");
  313: ENDYAXISLABELSCRIPT
  314:     }
  315:     return $return;
  316: }
  317: 
  318: sub plot_script {
  319:    my ($id,$function,$fixed,$label,$xmin,$xmax)=@_;
  320:    $label=~s/\W//g;
  321:    if (($label) && ($label!~/^[A-Za-z]/)) {
  322:       $label='C'.$label;
  323:    }
  324:    my $visible=0;
  325:    if ($label) {
  326:       $visible="1";
  327:    } else {
  328:       $Apache::functionplotresponse::counter++;
  329:       $label='C'.$Apache::functionplotresponse::counter;
  330:    }
  331:    if ($fixed) {
  332:       return "document.ggbApplet_$id.evalCommand('$label=Function[$function,$xmin,$xmax]');\n".
  333:              ($visible?'':"document.ggbApplet_$id.setLabelVisible('$label', false);\n");
  334:    } else {
  335:        return "document.ggbApplet_$id.evalCommand('y=$function')";
  336:    }
  337: }
  338: 
  339: #
  340: # Subroutine that generates code for spline $label based on stored information
  341: #
  342: 
  343: sub generate_spline {
  344:    my ($id,$label,$xmin,$xmax,$ymin,$ymax)=@_;
  345:    my $result='';
  346:    my $order=$Apache::functionplotresponse::splineorder{$label};
  347:    my $x=$Apache::functionplotresponse::splineinitx{$label};
  348:    my $y=$Apache::functionplotresponse::splineinity{$label};
  349:    my $sx=$Apache::functionplotresponse::splinescalex{$label};
  350:    my $sy=$Apache::functionplotresponse::splinescaley{$label};
  351:    my @coords=();
  352:    foreach my $i (1..$order) {
  353:        $result.=&new_point_coordinate($id,$label.'P'.$i,$x,$y);
  354:        my $xp=$x;
  355:        $x+=$sx/(2.*($order-1));
  356:        push(@coords,$label.'P'.$i);
  357:        $result.=&new_slope_coordinate($id,$label.'S'.$i,$x,$y+$sy,$label.'P'.$i,$xp,$y,$xmin,$xmax,$ymin,$ymax);
  358:        $x+=$sx/(2.*($order-1));
  359:        push(@coords,$label.'S'.$i);
  360:    }
  361:    $result.='document.ggbApplet_'.$id.'.evalCommand("Spline'.$order.'['.join(',',@coords).']");'."\n";
  362:    return $result;
  363: }
  364: #
  365: # <backgroundplot function="..." fixed="yes/no" />
  366: #
  367: sub start_backgroundplot {
  368:    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  369:    my $result='';
  370:    my $internalid = $Apache::inputtags::part.'_'.$Apache::inputtags::response[-1];
  371:    my $function=&Apache::lonxml::get_param('function',$parstack,$safeeval);
  372:    my $label=&Apache::lonxml::get_param('label',$parstack,$safeeval);
  373:    my $fixed=(&Apache::lonxml::get_param('fixed',$parstack,$safeeval)=~/on|true|yes|1/i?1:0);
  374:  
  375:    unless ($function) { $function="0"; }
  376:    if ($target eq 'web') {
  377:       my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-3);
  378:       $result.=&plot_script($internalid,$function,$fixed,$label,$xmin,$xmax);
  379:    } elsif ($target eq 'edit') {
  380:         $result=&Apache::edit::tag_start($target,$token,'Background Function Plot').
  381:              &Apache::edit::text_arg('Function:','function',
  382:                                      $token,'16').
  383:              &Apache::edit::text_arg('Label on Plot:','label',
  384:                                      $token,'8').
  385:              &Apache::edit::select_arg('Fixed location:','fixed',
  386:                                   ['yes','no'],$token).
  387:              &Apache::edit::end_row();
  388:   } elsif ($target eq 'modified') {
  389:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  390:                                                  $safeeval,'function','label','fixed');
  391:     if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
  392:   }
  393:   return $result;
  394: }
  395: 
  396: sub end_backgroundplot {
  397:    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  398:    my $result='';
  399:    if ($target eq 'edit') {
  400:        $result=&Apache::edit::end_table();
  401:    }
  402:    return $result;
  403: }
  404: 
  405: #
  406: # <functionplotrule ... />
  407: #
  408: sub start_functionplotrule {
  409:    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  410:    my $result='';
  411:    my $label=&Apache::lonxml::get_param('index',$parstack,$safeeval);
  412:    $Apache::functionplotresponse::counter++;
  413:    if ($label=~/\W/) {
  414:       &Apache::lonxml::warning(&mt('Rule indices should only contain alphanumeric characters.'));
  415:    }
  416:    $label=~s/\W//gs;
  417:    unless ($label) {
  418:       $label='R'.$Apache::functionplotresponse::counter;
  419:    } else {
  420:       $label='R'.$label;
  421:    }
  422:    if ($Apache::functionplotresponse::splineorder{$label}) {
  423:        &Apache::lonxml::error(&mt('Rule indices must be unique.'));
  424:    }
  425: 
  426: 
  427:    if ($target eq 'grade') {
  428: # Simply remember - in order - for later
  429:       my $beginninglabel=&Apache::lonxml::get_param('xinitiallabel',$parstack,$safeeval);
  430:       my $endinglabel=&Apache::lonxml::get_param('xfinallabel',$parstack,$safeeval);
  431:       if (($beginninglabel=~/\W/) || ($endinglabel=~/W/)) {
  432:           &Apache::lonxml::warning(&mt('Rule labels must be alphanumeric.'));
  433:       }
  434:       $beginninglabel=~s/\W//gs;
  435:       $endinglabel=~s/\W//gs;
  436:       my $relationship=&Apache::lonxml::get_param('relationship',$parstack,$safeeval);
  437:       $relationship=~s/\W//gs;
  438:       $relationship=lc($relationship);
  439:       unless ($relationship=~/^(eq|ge|gt|le|lt|ne)$/) {
  440:           &Apache::lonxml::warning(&mt('Rule relationship not defined.'));
  441:           $relationship='eq';
  442:       }
  443:       my $derivative=&Apache::lonxml::get_param('derivativeorder',$parstack,$safeeval);
  444:       unless (($derivative==-1) || ($derivative==0) || ($derivative==1) || ($derivative==2)) {
  445:          &Apache::lonxml::warning(&mt('Rule derivative not defined.'));
  446:          $derivative=0;
  447:       }
  448:       push(@Apache::functionplotresponse::functionplotrules,join(':',(
  449:            $label,
  450:            $derivative,
  451:            &Apache::lonxml::get_param('xinitial',$parstack,$safeeval),
  452:            $beginninglabel,
  453:            &Apache::lonxml::get_param('xfinal',$parstack,$safeeval),
  454:            $endinglabel,
  455:            &Apache::lonxml::get_param('minimumlength',$parstack,$safeeval),
  456:            &Apache::lonxml::get_param('maximumlength',$parstack,$safeeval),
  457:            $relationship,
  458:            &Apache::lonxml::get_param('value',$parstack,$safeeval),
  459:            &Apache::lonxml::get_param('percenterror',$parstack,$safeeval)
  460:           )));
  461:    } elsif ($target eq 'edit') {
  462:         $result=&Apache::edit::tag_start($target,$token,'Function Plot Evaluation Rule').
  463:              &Apache::edit::text_arg('Index/Name:','index',
  464:                                      $token,'10').'&nbsp;'.
  465:              &Apache::edit::select_arg(&mt('Function:'),'derivativeorder',
  466:                                   [['0','Function itself'],
  467:                                    ['1','First derivative'],
  468:                                    ['2','Second derivative'],
  469:                                    ['-1','Integral']],$token).'<br />'.
  470:              &Apache::edit::text_arg('Initial x-value:','xinitial',
  471:                                       $token,'8').
  472:              &Apache::edit::select_or_text_arg('Initial x-value label:','xinitiallabel',
  473:                                                [['start','Start of Plot'],
  474:                                                 ['end','End of Plot']],$token,'8').'<br />'.
  475: 
  476:              &Apache::edit::text_arg('Final x-value (optional):','xfinal',
  477:                                       $token,'8').
  478:              &Apache::edit::select_or_text_arg('Final x-value label (optional):','xfinallabel',
  479:                                                [['end','End of Plot']],$token,'8').'<br />'.
  480:              &Apache::edit::text_arg('Minimum length for range (optional):','minimumlength',
  481:                                      $token,'8').
  482:              &Apache::edit::text_arg('Maximum length for range (optional):','maximumlength',
  483:                                      $token,'8').'<br />'.
  484:              &Apache::edit::select_or_text_arg(&mt('Relationship:'),'relationship',
  485:                                   [['eq','equal'],
  486:                                    ['ne','not equal'],
  487:                                    ['ge','greater than or equal'],
  488:                                    ['gt','greater than'],
  489:                                    ['lt','less than'],
  490:                                    ['le','less than or equal']],$token).
  491:              $result.= &Apache::edit::select_or_text_arg('Value:','value',
  492:                                                [['undef','not defined']],$token,'8').
  493:              &Apache::edit::text_arg('Percent error:','percenterror',
  494:                                      $token,'8').
  495:              &Apache::edit::end_row();
  496:   } elsif ($target eq 'modified') {
  497:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  498:                                                  $safeeval,'index','derivativeorder',
  499:                                                            'xinitial','xinitiallabel','xfinal','xfinallabel',
  500:                                                            'minimumlength','maximumlength',
  501:                                                            'relationship','value','percenterror');
  502:     if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
  503:    }
  504:    return $result;
  505: }
  506: 
  507: sub end_functionplotrule {
  508:    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  509:    my $result='';
  510:    if ($target eq 'edit') {
  511:        $result=&Apache::edit::end_table();
  512:    }
  513:    return $result;
  514: }
  515: 
  516: 
  517: #
  518: # <spline index="..." order="1,2,3,4" initx="..." inity="..." scalex="..." scaley="..." />
  519: #
  520: # Unfortunately, GeoGebra seems to want all splines after everything else, so we need to store them
  521: #
  522: sub start_spline {
  523:    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  524:    my $result='';
  525:    if ($target eq 'web') {
  526:       my $label=&Apache::lonxml::get_param('index',$parstack,$safeeval);
  527:       $Apache::functionplotresponse::counter++;
  528:       if ($label=~/\W/) {
  529:          &Apache::lonxml::warning(&mt('Spline indices should only contain alphanumeric characters.'));
  530:       }
  531:       $label=~s/\W//gs;
  532:       unless ($label) { 
  533:          $label='S'.$Apache::functionplotresponse::counter; 
  534:       } else {
  535:          $label='S'.$label;
  536:       }
  537:       if ($Apache::functionplotresponse::splineorder{$label}) {
  538:          &Apache::lonxml::error(&mt('Spline indices must be unique.'));
  539:       }
  540: 
  541:       my $order=&Apache::lonxml::get_param('order',$parstack,$safeeval);
  542:       if ($order<2) { $order=2; }
  543:       if ($order>8) { $order=8; }
  544:       $Apache::functionplotresponse::splineorder{$label}=$order;
  545: 
  546:       my $x=&Apache::lonxml::get_param('initx',$parstack,$safeeval);
  547:       unless ($x) { $x=0; }
  548:       $Apache::functionplotresponse::splineinitx{$label}=$x;
  549: 
  550:       my $y=&Apache::lonxml::get_param('inity',$parstack,$safeeval);
  551:       unless ($y) { $y=0; }
  552:       $Apache::functionplotresponse::splineinity{$label}=$y;
  553: 
  554:       my $sx=&Apache::lonxml::get_param('scalex',$parstack,$safeeval);
  555:       unless ($sx) { $sx=$order; }
  556:       $Apache::functionplotresponse::splinescalex{$label}=$sx;
  557: 
  558:       my $sy=&Apache::lonxml::get_param('scaley',$parstack,$safeeval);
  559:       unless ($sy) { $sy=2; }
  560:       $Apache::functionplotresponse::splinescaley{$label}=$sy;
  561:    } elsif ($target eq 'edit') {
  562:         $result=&Apache::edit::tag_start($target,$token,'Spline').
  563:              &Apache::edit::text_arg('Index:','index',
  564:                                      $token,'4').'&nbsp;'.
  565:              &Apache::edit::select_arg('Order:','order',
  566:                                   ['2','3','4','5','6','7','8'],$token).'&nbsp;'.
  567:              &Apache::edit::text_arg('Initial x-value:','initx',
  568:                                      $token,'4').'&nbsp;'.
  569:              &Apache::edit::text_arg('Initial y-value:','inity',
  570:                                      $token,'4').'&nbsp;'.
  571:              &Apache::edit::text_arg('Scale x:','scalex',
  572:                                      $token,'4').'&nbsp;'.
  573:              &Apache::edit::text_arg('Scale y:','scaley',
  574:                                      $token,'4').
  575:              &Apache::edit::end_row();
  576:   } elsif ($target eq 'modified') {
  577:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  578:                                                  $safeeval,'index','order','initx','inity',
  579:                                                            'scalex','scaley');
  580:     if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
  581:   }
  582:   return $result;
  583: }
  584: 
  585: sub end_spline {
  586:    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  587:    my $result='';
  588:    if ($target eq 'edit') {
  589:        $result=&Apache::edit::end_table();
  590:    }
  591:    return $result;
  592: }
  593:  
  594: sub end_init_script {
  595:     return (<<ENDENDINIT);
  596: }
  597: // ]]>
  598: </script>
  599: ENDENDINIT
  600: }
  601: 
  602: #
  603: # Storing and restoring spline coordinates from part answers
  604: #
  605: sub decode_previous_answer {
  606:    my ($answer)=@_;
  607:    foreach my $coordinate (split(/\,/,$answer)) {
  608:       my ($key,$value)=split(/\=/,$coordinate);
  609:       $Apache::functionplotresponse::previous{$key}=$value;
  610:    }
  611: }
  612: 
  613: sub get_answer_from_form_fields {
  614:    my ($id)=@_;
  615:    my $answer='';
  616:    my %coords=();
  617:    foreach my $field (keys(%env)) {
  618:       if ($field=~/^form\.HWVAL\_$id/) {
  619:          $field=~/^form\.(.*)$/;
  620:          $coords{$1}=$env{$field};
  621:       }
  622:    }
  623:    $answer=join(',',map { $_.'='.$coords{$_} } (sort(keys(%coords))));
  624:    return ($answer,%coords);
  625: }
  626: 
  627: #
  628: # The following functions calculate the cubic-hermite splines server-side
  629: #
  630: 
  631: sub cubic_hermite {
  632:    my ($t,$p1,$s1,$p2,$s2)=@_;
  633:    return (2.*$t*$t*$t-3.*$t*$t+1.)*$p1 + 3.*($t*$t*$t-2.*$t*$t+$t)*($s1-$p1)+
  634:           (-2.*$t*$t*$t+3.*$t*$t)  *$p2 + 3.*($t*$t*$t-$t*$t)      *($s2-$p2);
  635: }
  636: 
  637: #
  638: # d/dt(...)
  639: # 
  640: 
  641: sub ddt_cubic_hermite {
  642:    my ($t,$p1,$s1,$p2,$s2)=@_;
  643:    return (6.*$t*$t-6.*$t) *$p1 + 3.*(3.*$t*$t-4.*$t+1.)*($s1-$p1)+
  644:           (-6.*$t*$t+6.*$t)*$p2 + 3.*(3.*$t*$t-2.*$t)   *($s2-$p2);
  645: }
  646: 
  647: #
  648: # d^2/dt^2(...)
  649: #
  650: 
  651: sub d2dt2_cubic_hermite {
  652:    my ($t,$p1,$s1,$p2,$s2)=@_;
  653:    return (12.*$t-6.) *$p1 + 3.*(6.*$t-4.)*($s1-$p1)+
  654:           (-12.*$t+6.)*$p2 + 3.*(6.*$t-2.)*($s2-$p2);
  655: }
  656: 
  657: #
  658: # Array index calculation
  659: #
  660: sub array_index {
  661:    my ($xmin,$xmax,$x)=@_;
  662:    if ($x ne '') {
  663:       return int(($x-$xmin)/($xmax-$xmin)*400.+0.5);
  664:    } else {
  665:       return undef;
  666:    }
  667: }
  668: 
  669: #
  670: # Populate the arrays
  671: #
  672: 
  673: sub populate_arrays {
  674:     my ($id,$xmin,$xmax)=@_;
  675:     for (my $i=0; $i<=400; $i++) {
  676:        $Apache::functionplotresponse::actualxval[$i]=undef;
  677:        $Apache::functionplotresponse::func[$i]=undef;
  678:        $Apache::functionplotresponse::dfuncdx[$i]=undef;
  679:        $Apache::functionplotresponse::d2funcd2x[$i]=undef;
  680:     }
  681:     unless ($xmax>$xmin) { return 'no_func'; }
  682: # Run over all splines in response
  683:     foreach my $label (split(/\,/,$env{"form.HWVAL_AllSplines_$id"})) {
  684:         my $xiold=-1;
  685: # Run over all points in spline
  686:         for (my $i=1; $i<$env{"form.HWVAL_SplineOrder_".$id."_".$label}; $i++) {
  687:             my $ni=$i+1;
  688:             my @xparms=($env{'form.HWVAL_'.$id.'_'.$label.'P'.$i.'_x'},
  689:                         $env{'form.HWVAL_'.$id.'_'.$label.'S'.$i.'_x'},
  690:                         $env{'form.HWVAL_'.$id.'_'.$label.'P'.$ni.'_x'},
  691:                         $env{'form.HWVAL_'.$id.'_'.$label.'S'.$ni.'_x'});
  692:             my @yparms=($env{'form.HWVAL_'.$id.'_'.$label.'P'.$i.'_y'},
  693:                         $env{'form.HWVAL_'.$id.'_'.$label.'S'.$i.'_y'},
  694:                         $env{'form.HWVAL_'.$id.'_'.$label.'P'.$ni.'_y'},
  695:                         $env{'form.HWVAL_'.$id.'_'.$label.'S'.$ni.'_y'});
  696: # Run in small steps over spline parameter
  697:             for (my $t=0; $t<=1; $t+=0.0001) {
  698:                 my $xreal=&cubic_hermite($t,@xparms);
  699:                 my $xi=&array_index($xmin,$xmax,$xreal);
  700:                 if ($xi<$xiold) { return 'no_func'; }
  701:                 if (($xi>$xiold) && ($xi>=0) && ($xi<=400)) {
  702:                    if (defined($Apache::functionplotresponse::func[$xi])) { return 'no_func'; }
  703:                    $xiold=$xi;
  704:                    $Apache::functionplotresponse::actualxval[$xi]=$xreal;
  705: # Function value
  706:                    my $funcval=&cubic_hermite($t,@yparms);
  707:                    $Apache::functionplotresponse::func[$xi]=$funcval;
  708:                    if (defined($funcval)) {
  709:                       if ($xi<$Apache::functionplotresponse::functionplotrulelabels{'start'}) {
  710:                          $Apache::functionplotresponse::functionplotrulelabels{'start'}=$xi;
  711:                       }
  712:                       if ($xi>$Apache::functionplotresponse::functionplotrulelabels{'end'}) {
  713:                          $Apache::functionplotresponse::functionplotrulelabels{'end'}=$xi;
  714:                       }
  715:                    }
  716: # Chain rule
  717: # dy/dx=dy/dt/(dx/dt)
  718:                    my $dxdt=&ddt_cubic_hermite($t,@xparms);
  719:                    if ($dxdt) {
  720:                       $Apache::functionplotresponse::dfuncdx[$xi]=&ddt_cubic_hermite($t,@yparms)/$dxdt;
  721: # Second derivative
  722:                       $Apache::functionplotresponse::d2funcdx2[$xi]=
  723:                          ($dxdt*&d2dt2_cubic_hermite($t,@yparms)-&ddt_cubic_hermite($t,@yparms)*&d2dt2_cubic_hermite($t,@xparms))/
  724:                          ($dxdt*$dxdt*$dxdt);
  725:                    }
  726:                 }
  727:             }
  728:         }
  729:     }
  730: }
  731: 
  732: #
  733: # Implementation of <functionplotresponse>
  734: #
  735: 
  736: sub start_functionplotresponse {
  737:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  738:   my $result='';
  739: # To remember the splines - somehow, they need to come last
  740:   undef %Apache::functionplotresponse::splineorder;
  741:   undef %Apache::functionplotresponse::splineinitx;
  742:   undef %Apache::functionplotresponse::splineinity;
  743:   undef %Apache::functionplotresponse::splinescalex;
  744:   undef %Apache::functionplotresponse::splinescaley;
  745: # Remember input fields, etc
  746:   undef %Apache::functionplotresponse::previous;
  747:   $Apache::functionplotresponse::inputfields='';
  748:   $Apache::functionplotresponse::counter=0;
  749: # Remember rules
  750:   undef @Apache::functionplotresponse::functionplotrules;
  751: # Remember failed rules
  752:   if ($target eq 'grade') {
  753:      undef @Apache::functionplotresponse::failedrules;
  754:   }
  755: # Delete previous awards
  756:   undef $Apache::functionplotresponse::awarddetail;
  757: # Part and ID
  758:   my $partid=$Apache::inputtags::part;
  759:   my $id=&Apache::response::start_response($parstack,$safeeval);
  760: # Internal ID to mark the applet and its coordinates
  761:   my $internalid = $partid.'_'.$id;
  762: # Previous answer
  763:   &decode_previous_answer($Apache::lonhomework::history{"resource.$partid.$id.submission"});
  764: 
  765: # Parameters of <functionplotresponse>
  766:   my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval);
  767:   my $xaxisvisible=(&Apache::lonxml::get_param('xaxisvisible',$parstack,$safeeval)=~/on|true|yes|1/i?'true':'false');
  768:   my $yaxisvisible=(&Apache::lonxml::get_param('yaxisvisible',$parstack,$safeeval)=~/on|true|yes|1/i?'true':'false');
  769:   my $gridvisible=(&Apache::lonxml::get_param('gridvisible',$parstack,$safeeval)=~/on|true|yes|1/i?'true':'false');
  770:   my $xlabel=&Apache::lonxml::get_param('xlabel',$parstack,$safeeval);
  771:   my $ylabel=&Apache::lonxml::get_param('ylabel',$parstack,$safeeval);
  772:   if ($target eq 'edit') {
  773:     $result.=&Apache::edit::start_table($token)
  774:        .'<tr><td><span class="LC_nobreak">'.&mt('Function Plot Question').'</span></td>'
  775:        .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
  776:        .&Apache::edit::deletelist($target,$token).'&nbsp;&nbsp;&nbsp;'
  777:        .&Apache::edit::insertlist($target,$token)
  778:        .'</span></td>'
  779:        ."<td>&nbsp;"
  780:        .&Apache::edit::end_row()
  781:        .&Apache::edit::start_spanning_row()
  782:        ."\n";
  783:     $result.=&Apache::edit::text_arg('Label x-axis:','xlabel',
  784:                                      $token,'6').'&nbsp;'.
  785:              &Apache::edit::text_arg('Minimum x-value:','xmin',
  786:                                      $token,'4').'&nbsp;'.
  787:              &Apache::edit::text_arg('Maximum x-value:','xmax',
  788:                                      $token,'4').'&nbsp;'.
  789:              &Apache::edit::select_arg('x-axis visible:','xaxisvisible',
  790:                                   ['yes','no'],$token).'<br />'.
  791:              &Apache::edit::text_arg('Label y-axis:','ylabel',
  792:                                      $token,'6').'&nbsp;'.
  793:              &Apache::edit::text_arg('Minimum y-value:','ymin',
  794:                                      $token,'4').'&nbsp;'.
  795:              &Apache::edit::text_arg('Maximum y-value:','ymax',
  796:                                      $token,'4').'&nbsp;'.
  797:              &Apache::edit::select_arg('y-axis visible:','yaxisvisible',
  798:                                   ['yes','no'],$token).'<br />'.
  799:              &Apache::edit::select_arg('Grid visible:','gridvisible',
  800:                                   ['yes','no'],$token).
  801:              &Apache::edit::end_row().&Apache::edit::start_spanning_row();
  802:   } elsif ($target eq 'modified') {
  803:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  804:                                                  $safeeval,'xlabel','xmin','xmax','ylabel','ymin','ymax',
  805:                                                            'xaxisvisible','yaxisvisible','gridvisible');
  806:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  807: 
  808:   } elsif ($target eq 'meta') {
  809:        $result=&Apache::response::meta_package_write('functionplotresponse');
  810:   } elsif (($target eq 'answer') &&
  811:             ($env{'form.answer_output_mode'} ne 'tex') &&
  812:             ($Apache::lonhomework::viewgrades == 'F')) {
  813:       my (undef,undef,$udom,$uname)=&Apache::lonnet::whichuser();
  814:       my $windowopen=&Apache::lonhtmlcommon::javascript_docopen();
  815:       my $start_page = &Apache::loncommon::start_page('Rules Log', undef,
  816:                                                {'only_body' => 1,
  817:                                                 'bgcolor'   => '#FFFFFF',
  818:                                                 'js_ready'  => 1,});
  819:       my $end_page = &Apache::loncommon::end_page({'js_ready' => 1,});
  820:       $uname =~s/\W//g;
  821:       $udom  =~s/\W//g;
  822:       my $function_name =
  823:                 join('_','LONCAPA_scriptvars',$uname,$udom,
  824:                      $env{'form.counter'},$Apache::lonxml::curdepth);
  825:       my $rules_var ="<script type=\"text/javascript\">
  826: // <![CDATA[
  827:     function $function_name() {newWindow=open('','new_W','width=500,height=500,scrollbars=1,resizable=yes');newWindow.$windowopen;newWindow.document.writeln('$start_page<pre>".
  828:     $Apache::functionplotresponse::ruleslog.
  829:     "<\\/pre>$end_page');newWindow.document.close();newWindow.focus()}
  830: // ]]>
  831: </script><a href=\"javascript:$function_name();void(0);\">".&mt('Rules Log')."</a><br />";
  832:             &Apache::lonxml::add_script_result($rules_var);
  833:         }
  834: 
  835:   return $result;
  836: }
  837: 
  838: sub compare_rel {
  839:    my ($relationship,$value,$realval,$tol)=@_;
  840: # is the real value undefined?
  841:    unless (defined($realval)) {
  842: # the real value is not defined
  843:       if ($relationship eq 'eq') {
  844:          if ($value eq 'undef') {
  845:             return 1;
  846:          } else {
  847:             return 0;
  848:          }
  849:       } elsif ($relationship eq 'ne') {
  850:          if ($value eq 'undef') {
  851:             return 0;
  852:          } else {
  853:             return 1;
  854:          }
  855:       } else {
  856:          return 0;
  857:       }
  858:    }
  859: 
  860: # is the expected value undefined?
  861:    if ($value eq 'undef') {
  862: # but by now we know that the real value is defined
  863:       return 0;
  864:    }
  865: 
  866: # both are defined.
  867:    if ($relationship eq 'gt') {
  868:       return ($realval>$value);
  869:    } elsif ($relationship eq 'ge') {
  870:       return ($realval>$value-$tol);
  871:    } elsif ($relationship eq 'lt') {
  872:       return ($realval<$value);
  873:    } elsif ($relationship eq 'le') {
  874:       return ($realval<$value+$tol);
  875:    } elsif ($relationship eq 'ne') {
  876:       return (abs($value-$realval)>$tol);
  877:    } else {
  878:       return (abs($value-$realval)<$tol);
  879:    }
  880:    return 0;
  881: }
  882: 
  883: sub addlog {
  884:    my ($text)=@_;
  885:    $Apache::functionplotresponse::ruleslog.=$text.'<br />';
  886: }
  887: 
  888: sub actualval {
  889:    my ($i,$xmin,$xmax)=@_;
  890:    return $xmin+$i/400.*($xmax-$xmin);
  891: }
  892:  
  893: sub functionplotrulecheck {
  894:    my ($rule,$xmin,$xmax,$ymin,$ymax)=@_;
  895: 
  896:    my ($label,$derivative,$xinitial,$xinitiallabel,$xfinal,$xfinallabel,$minimumlength,$maximumlength,$relationship,$value,$percent)
  897:       =split(/\:/,$rule);
  898:    $percent=($percent>0?$percent:5);
  899:    &addlog("=================");
  900:    &addlog("Rule $label for ".($derivative<0?'integral':('function itself','first derivative','second derivative')[$derivative])." $relationship $value");
  901:    my $li=0;
  902:    my $lh=400;
  903: 
  904: # Special case: the upper boundary was not defined
  905: # and needs to be set to the value where
  906: # the condition is not true anymore => set flag
  907: 
  908:    my $findupper=0;
  909:    if (($xfinal eq '')
  910:     && (!defined($Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}))
  911:     && ($xfinallabel)) {
  912:        $findupper=1;
  913:    }
  914: 
  915: # if a hard value is set for the boundaries, it overrides the label
  916:    if (($xinitial ne '') && ($xinitiallabel ne '') && ($xinitiallabel ne 'start')) {
  917:       $li=&array_index($xmin,$xmax,$xinitial);
  918:       $Apache::functionplotresponse::functionplotrulelabels{$xinitiallabel}=$li;
  919:    }
  920:    if (($xfinal ne '') && ($xfinallabel ne '') && ($xfinallabel ne 'end')) {
  921:       $lh=&array_index($xmin,$xmax,$xfinal);
  922:       $Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}=$lh;
  923:    }
  924: # if the label is defined, use it
  925:    if (defined($Apache::functionplotresponse::functionplotrulelabels{$xinitiallabel})) {
  926:       &addlog("Using lower label $xinitiallabel");
  927:       $li=$Apache::functionplotresponse::functionplotrulelabels{$xinitiallabel};
  928:    } else {
  929:       $li=&array_index($xmin,$xmax,$xinitial);
  930:    }
  931:    unless ($findupper) {
  932:       if (defined($Apache::functionplotresponse::functionplotrulelabels{$xfinallabel})) {
  933:          &addlog("Using upper label $xfinallabel");
  934:          $lh=$Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}-1;
  935:       } else {
  936:          $lh=&array_index($xmin,$xmax,$xfinal);
  937:       }
  938:    }
  939: # Basic sanity checks
  940:    if ($li<0) { $li=0; }
  941:    if ($lh>400) { $lh=400; }
  942:    if (($li>$lh) || (!defined($lh))) {
  943:        $lh=$li;
  944:    }
  945: 
  946:    &addlog("Boundaries: x=".&actualval($li,$xmin,$xmax)." (".$Apache::functionplotresponse::actualxval[$li]."; index $li)) to x=".
  947:                             &actualval($lh,$xmin,$xmax)." (".$Apache::functionplotresponse::actualxval[$lh]."; index $lh))");
  948:    if ($findupper) {
  949:       &addlog("Looking for label $xfinallabel");
  950:    }
  951:    my $tol=$percent*($ymax-$ymin)/100;
  952:    if ($xmax>$xmin) {
  953:       if ($derivative==2) {
  954:          $tol=4.*$tol/($xmax-$xmin);
  955:       } elsif ($derivative==1) {
  956:          $tol=2.*$tol/($xmax-$xmin);
  957:       } elsif ($derivative==-1) {
  958:          $tol=$tol*($xmax-$xmin)/2.;
  959:       }
  960:    }
  961:    my $integral=0;
  962:    my $binwidth=($xmax-$xmin)/400.;
  963:    if (($derivative<0) && (!$findupper)) {
  964: # definite integral, calculate over whole length
  965:      &addlog("Calculating definite integral");
  966:      for (my $i=$li; $i<=$lh; $i++) {
  967:         $integral+=$Apache::functionplotresponse::func[$i]*$binwidth;
  968:      }
  969:      unless (&compare_rel($relationship,$value,$integral,$tol)) {
  970:         &addlog("Actual integral ".(defined($integral)?$integral:'undef').", expected $value, tolerance $tol");
  971:         &addlog("Rule $label failed.");
  972:         my $hintlabel=$label;
  973:         $hintlabel=~s/^R//;
  974:         push(@Apache::functionplotresponse::failedrules,$hintlabel);
  975:         &addlog("Set hint condition $hintlabel");
  976:         return 0;
  977:      } 
  978:    } else {
  979:      for (my $i=$li; $i<=$lh; $i++) {
  980:         my $val;
  981:         if ($derivative==2) {
  982:            $val=$Apache::functionplotresponse::d2funcdx2[$i];
  983:         } elsif ($derivative==1) {
  984:            $val=$Apache::functionplotresponse::dfuncdx[$i];
  985:         } elsif ($derivative==-1) {
  986:            $integral+=$Apache::functionplotresponse::func[$i]*$binwidth;
  987:            $val=$integral;      
  988:         } else {
  989:            $val=$Apache::functionplotresponse::func[$i];
  990:         }
  991:         unless (&compare_rel($relationship,$value,$val,$tol)) { 
  992:            &addlog("Actual value ".(defined($val)?$val:'undef').", expected $value, tolerance $tol");
  993:            &addlog("Condition not fulfilled at x=".&actualval($i,$xmin,$xmax)." (".$Apache::functionplotresponse::actualxval[$i]."; index $i)");
  994:            if (($findupper) && ($i>$li)) {
  995: # check for minimum and maximum lengths
  996:               my $length=&actualval($i,$xmin,$xmax)-&actualval($li,$xmin,$xmax);
  997:               if ($minimumlength) {
  998:                  if ($length<$minimumlength) {
  999:                     &addlog("Rule $label failed, actual length $length, minimum length $minimumlength");
 1000:                     return 0;
 1001:                  }
 1002:               }
 1003:               if ($maximumlength) {
 1004:                  if ($length>$maximumlength) {
 1005:                     &addlog("Rule $label failed, actual length $length, maximum length $maximumlength");
 1006:                     return 0;
 1007:                  }
 1008:               }
 1009:               $Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}=$i;
 1010:               &addlog("Rule $label passed, setting label $xfinallabel");
 1011:               return 1;
 1012:            } else {
 1013:               &addlog("Rule $label failed.");
 1014:               my $hintlabel=$label;
 1015:               $hintlabel=~s/^R//;
 1016:               push(@Apache::functionplotresponse::failedrules,$hintlabel);
 1017:               &addlog("Set hint condition $hintlabel");
 1018:               return 0; 
 1019:            }
 1020:         }
 1021:      }
 1022:    }
 1023:    &addlog("Rule $label passed.");
 1024:    return 1;
 1025: }
 1026: 
 1027: sub start_functionplotruleset {
 1028:    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1029:    if ($target eq 'edit') {
 1030:       return &Apache::edit::start_table($token).
 1031:         '<tr><td><span class="LC_nobreak">'.&mt('Function Plot Rule Set').'</span></td>'
 1032:        .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
 1033:        .&Apache::edit::deletelist($target,$token).'&nbsp;&nbsp;&nbsp;'.
 1034:         &Apache::edit::insertlist($target,$token)
 1035:        .'</span></td>'
 1036:        ."<td>&nbsp;"
 1037:        .&Apache::edit::end_row()
 1038:        .&Apache::edit::start_spanning_row()
 1039:        ."\n";
 1040:    }
 1041: }
 1042: 
 1043: sub end_functionplotruleset {
 1044:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1045:     my $id=$Apache::inputtags::response[-1];
 1046:     my $partid=$Apache::inputtags::part;
 1047:     my $internalid = $partid.'_'.$id;
 1048: 
 1049:     if ($target eq 'edit' ) {
 1050:         return &Apache::edit::end_table();
 1051:     }  elsif ($target eq 'grade'
 1052:          && &Apache::response::submitted()
 1053:          && $Apache::lonhomework::type ne 'exam') {
 1054: #
 1055: # Actually grade
 1056: #
 1057:     my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-2);
 1058: 
 1059:         my $ad='';
 1060:         undef  %Apache::functionplotresponse::functionplotrulelabels;
 1061:         $Apache::functionplotresponse::ruleslog='';
 1062:         $Apache::functionplotresponse::functionplotrulelabels{'start'}=400;
 1063:         $Apache::functionplotresponse::functionplotrulelabels{'end'}=0;
 1064:         if (&populate_arrays($internalid,$xmin,$xmax) eq 'no_func') {
 1065:            $ad='NOT_FUNCTION';
 1066:         } else {
 1067:            &addlog("Start of function ".&actualval($Apache::functionplotresponse::functionplotrulelabels{'start'},$xmin,$xmax)." (index ".
 1068:                                         $Apache::functionplotresponse::functionplotrulelabels{'start'}.")");
 1069:            &addlog("End of function ".&actualval($Apache::functionplotresponse::functionplotrulelabels{'end'},$xmin,$xmax)." (index ".
 1070:                                         $Apache::functionplotresponse::functionplotrulelabels{'end'}.")");
 1071: 
 1072: # We have a function that we can actually grade, go through the spline rules.
 1073:            foreach my $rule (@Apache::functionplotresponse::functionplotrules) {
 1074:               unless (&functionplotrulecheck($rule,$xmin,$xmax,$ymin,$ymax)) {
 1075:                  $ad='INCORRECT';
 1076:                  last;
 1077:               }
 1078:            }
 1079: # If it's not wrong, it's correct 
 1080:            unless ($ad) { $ad='EXACT_ANS' };
 1081:         }
 1082:         &addlog("Set hint conditions: ".join(",",@Apache::functionplotresponse::failedrules));
 1083:         &addlog("Assigned award detail: $ad");
 1084: # Store for later to be assigned at end_functionplotresponse
 1085:         $Apache::functionplotresponse::awarddetail=$ad;
 1086:      }
 1087: }
 1088: 
 1089: 
 1090: sub end_functionplotresponse {
 1091:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1092:   &Apache::response::end_response;
 1093: 
 1094:   my $result;
 1095:   my $id=$Apache::inputtags::response[-1];
 1096:   my $partid=$Apache::inputtags::part;
 1097:   my $internalid = $partid.'_'.$id;
 1098: 
 1099:     if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
 1100:     if ($target eq 'grade'
 1101:          && &Apache::response::submitted()
 1102:          && $Apache::lonhomework::type eq 'exam') {
 1103: 
 1104:         &Apache::response::scored_response($partid,$id);
 1105: 
 1106:     } elsif ($target eq 'grade'
 1107:          && &Apache::response::submitted()
 1108:          && $Apache::lonhomework::type ne 'exam') {
 1109:         my ($response,%coords)=&get_answer_from_form_fields($internalid);
 1110:         $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
 1111:         my %previous=&Apache::response::check_for_previous($response,$partid,$id);
 1112: #
 1113: # Assign grade
 1114: #
 1115:         my $ad=$Apache::functionplotresponse::awarddetail;
 1116: #
 1117: # Store grading info
 1118: #
 1119:         $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
 1120:         &Apache::response::handle_previous(\%previous,$ad);
 1121:    } elsif ($target eq 'web') {
 1122:         undef @Apache::functionplotresponse::failedrules;
 1123:    }
 1124:    return $result;
 1125: }
 1126: 
 1127: sub end_functionplotelements {
 1128:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1129:   my $result='';
 1130:   my $id=$Apache::inputtags::response[-1];
 1131:   my $partid=$Apache::inputtags::part;
 1132:   my $internalid = $partid.'_'.$id;
 1133:   if ($target eq 'edit' ) {
 1134:      $result=&Apache::edit::end_table();
 1135:   } elsif ($target eq 'web') {
 1136: # Now is the time to render all of the stored splines
 1137:      my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-2);
 1138:      foreach my $label (keys(%Apache::functionplotresponse::splineorder)) {
 1139:         $result.=&generate_spline($internalid,$label,$xmin,$xmax,$ymin,$ymax);
 1140:      }
 1141: # close the init script
 1142:      $result.=&end_init_script();
 1143: # register all splines in this response 
 1144:      $result.='<input type="hidden" name="HWVAL_AllSplines_'.$internalid.'" value="'.
 1145:                  join(',',keys(%Apache::functionplotresponse::splineorder)).'" />'."\n";
 1146:      foreach my $label (keys(%Apache::functionplotresponse::splineorder)) {
 1147:         $result.='<input type="hidden" name="HWVAL_SplineOrder_'.$internalid.'_'.$label.'" value="'.
 1148:                  $Apache::functionplotresponse::splineorder{$label}.'" />'."\n";
 1149:      }
 1150: # generate the input fields
 1151:      $result.=$Apache::functionplotresponse::inputfields;
 1152: # actually start the <applet>-tag
 1153:      $result.=&geogebra_startcode($internalid);
 1154: # load the spline bytecode
 1155:      $result.=&geogebra_spline_program();
 1156: # set default parameters
 1157:      $result.=&geogebra_default_parameters($internalid);
 1158: # close the <applet>-tag
 1159:      $result.=&geogebra_endcode();
 1160:   }
 1161:   return $result;
 1162: }
 1163: 
 1164: sub boundaries {
 1165:    my ($parstack,$safeeval,$level)=@_;
 1166:    my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval,$level);
 1167:    $xmin=(defined($xmin)?$xmin:-10);
 1168:    my $xmax=&Apache::lonxml::get_param('xmax',$parstack,$safeeval,$level);
 1169:    $xmax=(defined($xmax)?$xmax:10);
 1170:    my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval,$level);
 1171:    $ymin=(defined($ymin)?$ymin:-10);
 1172:    my $ymax=&Apache::lonxml::get_param('ymax',$parstack,$safeeval,$level);
 1173:    $ymax=(defined($ymax)?$ymax:10);
 1174:    if ($xmax<=$xmin) {
 1175:       $xmax=$xmin+20;
 1176:    }
 1177:    if ($ymax<=$ymin) {
 1178:       $ymax=$ymin+20;
 1179:    }
 1180:    return ($xmin,$xmax,$ymin,$ymax);
 1181: }
 1182: 
 1183: sub start_functionplotelements {
 1184:    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1185:    my $result='';
 1186:    my $id=$Apache::inputtags::response[-1];
 1187:    my $partid=$Apache::inputtags::part;
 1188:    my $internalid = $partid.'_'.$id;
 1189: 
 1190:    if ($target eq 'edit') {
 1191:       return &Apache::edit::start_table($token).
 1192:         '<tr><td><span class="LC_nobreak">'.&mt('Function Plot Elements').'</span></td>'
 1193:        .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
 1194:        .&Apache::edit::deletelist($target,$token).'&nbsp;&nbsp;&nbsp;'.
 1195:         &Apache::edit::insertlist($target,$token)
 1196:        .'</span></td>'
 1197:        ."<td>&nbsp;"
 1198:        .&Apache::edit::end_row()
 1199:        .&Apache::edit::start_spanning_row()
 1200:        ."\n";
 1201:    } elsif ($target eq 'web') {
 1202:       my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-2);
 1203:       my $xaxisvisible=(&Apache::lonxml::get_param('xaxisvisible',$parstack,$safeeval,-2)=~/on|true|yes|1/i?'true':'false');
 1204:       my $yaxisvisible=(&Apache::lonxml::get_param('yaxisvisible',$parstack,$safeeval,-2)=~/on|true|yes|1/i?'true':'false');
 1205:       my $gridvisible=(&Apache::lonxml::get_param('gridvisible',$parstack,$safeeval,-2)=~/on|true|yes|1/i?'true':'false');
 1206:       my $xlabel=&Apache::lonxml::get_param('xlabel',$parstack,$safeeval,-2);
 1207:       my $ylabel=&Apache::lonxml::get_param('ylabel',$parstack,$safeeval,-2);
 1208: 
 1209: 
 1210: # paste in the update routine to receive stuff back from the applet
 1211:      $result.=&update_script($internalid);
 1212: # start the initscript for this applet
 1213:      $result.=&start_init_script($internalid);
 1214: # put the axis commands inside
 1215:      $result.=&axes_script($internalid,$xmin,$xmax,$ymin,$ymax,$xaxisvisible,$yaxisvisible,$gridvisible);
 1216:      $result.=&axes_label($internalid,$xlabel,$ylabel);
 1217: # init script is left open
 1218:   }
 1219:   return $result;
 1220: }
 1221: 
 1222: 1;
 1223: 
 1224: __END__
 1225:  
 1226: =head1 NAME
 1227: 
 1228: Apache::functionplotresponse.pm;
 1229: 
 1230: =head1 SYNOPSIS
 1231: 
 1232: Handles tags associated with accepting function plots.
 1233: 
 1234: This is part of the LearningOnline Network with CAPA project
 1235: described at http://www.lon-capa.org.
 1236: 
 1237: =head1 HANDLER SUBROUTINE
 1238: 
 1239: start_functionplotresponse()
 1240: 
 1241: =head1 OTHER SUBROUTINES
 1242: 
 1243: =over
 1244: 
 1245: =item end_functionplotresponse()
 1246: 
 1247: =back
 1248: 
 1249: =cut

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