Annotation of loncom/homework/functionplotresponse.pm, revision 1.96
1.1 www 1: # LearningOnline Network with CAPA
1.70 www 2: # Functionplot responses
1.1 www 3: #
1.96 ! www 4: # $Id: functionplotresponse.pm,v 1.95 2012/02/29 01:46:52 www Exp $
1.1 www 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;
1.65 www 34: use Apache::run;
1.85 www 35: use LONCAPA;
1.36 www 36:
1.1 www 37: BEGIN {
1.37 www 38: &Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline',
1.85 www 39: 'plotobject','plotvector',
40: 'functionplotvectorrule','functionplotvectorsumrule',
1.93 www 41: 'drawvectorsum',
1.85 www 42: 'functionplotcustomrule',
1.37 www 43: 'functionplotrule','functionplotruleset',
44: 'functionplotelements'));
1.1 www 45: }
46:
1.5 www 47: #
1.96 ! www 48: # Use old Java or HTML5/Javascript for GeoGebra? Depends on browser!
! 49: # Return a true value if HTML5 should be used.
! 50:
! 51: sub useHTML5 {
! 52: return 0;
! 53: }
! 54:
! 55: # Routines to start the applet (Java) or the HTML5/JavaScript
! 56: #
1.5 www 57: # There can be a number of applets on a page, each called ggbApplet_$id,
58: # where $id is the "_"-concatenated part and responseid
59: #
60:
1.1 www 61: sub geogebra_startcode {
1.88 www 62: my ($id,$width,$height)=@_;
1.96 ! www 63: if (&useHTML5()) {
! 64: return &html5_geogebra_startcode(@_);
! 65: } else {
! 66: return &java_geogebra_startcode(@_).
! 67: &java_geogebra_code_param();
! 68: }
! 69: }
! 70:
! 71: sub geogebra_endcode {
! 72: unless (&useHTML5()) {
! 73: return &java_geogebra_endcode();
! 74: }
! 75: }
! 76:
! 77: sub geogebra_default_parameters {
! 78: my ($id)=@_;
! 79: unless (&useHTML5()) {
! 80: return &java_geogebra_default_parameters($id);
! 81: }
! 82: }
! 83: # === Java code
! 84:
! 85: sub java_geogebra_startcode {
! 86: my ($id,$width,$height)=@_;
1.88 www 87: $width=int(1.*$width);
88: $height=int(1.*$height);
89: unless ($width) { $width=700; }
90: unless ($height) { $height=400; }
1.1 www 91: return (<<ENDSTARTCODE);
1.3 www 92: <applet name="ggbApplet_$id" code="geogebra.GeoGebraApplet" archive="geogebra.jar"
1.88 www 93: codebase="/adm/geogebra/" width="$width" height="$height" MAYSCRIPT>
1.1 www 94: <param name="java_arguments" value="-Xmx512m -Djnlp.packEnabled=true"/>
95: ENDSTARTCODE
96: }
97:
1.96 ! www 98: sub java_geogebra_endcode {
1.2 www 99: return &Apache::lonhtmlcommon::java_not_enabled()."</applet>\n";
100: }
101:
1.96 ! www 102: sub java_geogebra_code_param {
! 103: return '<param name="ggbBase64" value="'.&geogebra_internal_program().'" />';
! 104: }
! 105:
! 106: # === HTML5 code
! 107:
! 108: sub html5_geogebra_startcode {
! 109: my ($id,$width,$height)=@_;
! 110: my $code=&geogebra_internal_program();
! 111: return (<<ENDSTARTCODE);
! 112: <article class="geogebraweb" data-param-enableLabelDrags="false" data-param-enableShiftDragZoom="false"
! 113: data-param-width="$width" data-param-height="$height" data-param-id="ggbApplet_$id"
! 114: data-param-ggbbase64="$code"></article>
! 115: ENDSTARTCODE
! 116: }
! 117:
1.5 www 118: #
119: # This is the internal GeoGebra bytecode which defines the spline functions
120: #
1.96 ! www 121: sub geogebra_internal_program {
! 122: return
! 123: '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';
1.2 www 124: }
125:
1.5 www 126: #
127: # The standard set of parameters inside <applet>
128: #
1.96 ! www 129: sub java_geogebra_default_parameters {
1.3 www 130: my ($id)=@_;
1.2 www 131: return(<<ENDDEFAULTPARAMETERS);
132: <param name="image" value="/adm/lonIcons/lonanim.gif" />
133: <param name="boxborder" value="false" />
134: <param name="centerimage" value="true" />
1.62 www 135: <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" />
1.69 www 136: <param name="cache_version" value="4.0.1.0,4.0.1.0,4.0.1.0,4.0.1.0,4.0.1.0,4.0.1.0,4.0.1.0,4.0.1.0,4.0.1.0,4.0.1.0,4.0.1.0" />
1.2 www 137: <param name="framePossible" value="false" />
138:
139: <param name="showResetIcon" value="false" />
140: <param name="showAnimationButton" value="false" />
141: <param name="enableRightClick" value="false" />
142: <param name="errorDialogsActive" value="true" />
143: <param name="enableLabelDrags" value="false" />
144: <param name="showMenuBar" value="false" />
145: <param name="showToolBar" value="false" />
146: <param name="showToolBarHelp" value="false" />
147: <param name="showAlgebraInput" value="false" />
148: <param name="enableShiftDragZoom" value="false" />
149: <param name="allowRescaling" value="false" />
150: <param name="enableLabelDrags" value="false" />
1.3 www 151: <param name="ggbOnInitParam" value="applet_$id" />
1.2 www 152: ENDDEFAULTPARAMETERS
1.1 www 153: }
154:
1.5 www 155: #
156: # This subroutine is called by LON-CAPA at </problem>
157: # Each applet on the page will call function ggbOnInit when it is done loading
158: # This function in turn will call the respective function registered by start_init_script
159: # Which one of the registered functions is called is determined by ggbOnInitParam, which GeoGebra passes to ggbOnInit
160: #
161:
1.3 www 162: sub init_script {
1.16 www 163: if ($#Apache::functionplotresponse::callscripts>=0) {
164: my $script='';
165: foreach my $id (@Apache::functionplotresponse::callscripts) {
166: $script.="if (param=='applet_$id') { loaded_$id=true; }\n";
167: }
168: $script.="if (".join(' && ',map { "loaded_$_" } (@Apache::functionplotresponse::callscripts)).
1.52 www 169: ") { setTimeout('ggbInitAll()',200) }";
1.16 www 170: my $calls=join("\n",map { "ggbInit_$_();" } (@Apache::functionplotresponse::callscripts));
1.96 ! www 171: my $html5init='';
! 172: if (&useHTML5()) {
! 173: $html5init=
! 174: '<script type="text/javascript" language="javascript" src="/adm/geogebra/html5/web/test42/web/web.nocache.js"></script>';
! 175: }
1.3 www 176: return (<<ENDGGBINIT);
177: <script type="text/javascript">
178: // <![CDATA[
1.16 www 179: // Function that each applet will call when loaded
180: // It will pass "its" parameter
181: // Set flags for when an applet is loaded, wait till all are loaded, and then some
1.3 www 182: function ggbOnInit(param) {
1.16 www 183: $script
184: }
185: function ggbInitAll() {
1.17 www 186: $calls
1.3 www 187: }
188: // ]]>
189: </script>
190: ENDGGBINIT
191: }
192: }
193:
1.5 www 194: #
195: # Each Geogebra applet is supposed to call this when parameters change
1.10 www 196: # Changes the hidden fields on the web page
1.5 www 197: #
198: sub update_script {
199: my ($id)=@_;
200: return (<<ENDUPDATESCRIPT);
201: <script type="text/javascript">
202: // <![CDATA[
203: function updatePointCoordinates_$id(coordinateName) {
204: var x = document.ggbApplet_$id.getXcoord(coordinateName);
205: var y = document.ggbApplet_$id.getYcoord(coordinateName);
1.9 www 206: document.lonhomework.elements["HWVAL_$id\_" + coordinateName + "_x"].value = x;
207: document.lonhomework.elements["HWVAL_$id\_" + coordinateName + "_y"].value = y;
1.5 www 208: }
209: // ]]>
210: </script>
211: ENDUPDATESCRIPT
212: }
213:
214: #
215: # Register the above update-handler for a variable
216: #
217:
218: sub update_register {
219: my ($id,$variable)=@_;
1.6 www 220: return "document.ggbApplet_$id.registerObjectUpdateListener('$variable','updatePointCoordinates_$id');\n";
221: }
222:
223: #
1.40 www 224: # Set a point coordinate variable
1.6 www 225: #
1.40 www 226: sub set_point_coordinate {
1.48 www 227: my ($id,$variable,$x,$y,$fixed)=@_;
228: my $mult=($fixed?'a*':'');
1.68 www 229: # Get rid of wild exponents, make sure it's a number
230: $x=1.*$x;
231: $y=1.*$y;
232: # GeoGebra does not understand "E"
233: $x=~s/[e|E]/\*10\^/;
234: $x=~s/\+//;
235: $y=~s/[e|E]/\*10\^/;
236: $y=~s/\+//;
1.6 www 237: return (<<ENDSETVARIABLE);
1.48 www 238: document.ggbApplet_$id.evalCommand("a=1");
239: document.ggbApplet_$id.evalCommand("$variable=$mult($x,$y)");
1.40 www 240: document.ggbApplet_$id.setLabelVisible("$variable",false);
1.6 www 241: ENDSETVARIABLE
242: }
243:
244: #
1.40 www 245: # Set a slope coordinate variable
246: #
247: sub set_slope_coordinate {
1.48 www 248: my ($id,$variable,$xrel,$yrel,$xmin,$xmax,$ymin,$ymax,$pointname,$fixed)=@_;
1.40 www 249: my $xvariable=$variable.'x';
250: my $yvariable=$variable.'y';
251: my $domain=$xmax-$xmin;
252: my $range=$ymax-$ymin;
253: my $xinterval=$domain/100.;
254: my $yinterval=$range/200.;
1.48 www 255: my $mult=($fixed?'a*':'');
1.40 www 256: return (<<ENDSETSVARIABLE);
1.48 www 257: document.ggbApplet_$id.evalCommand("a=1");
1.51 www 258: document.ggbApplet_$id.evalCommand("$xvariable=Slider[$xinterval,$domain,$xinterval]");
1.40 www 259: document.ggbApplet_$id.setVisible("$xvariable", false);
260: document.ggbApplet_$id.evalCommand("$xvariable=$xrel");
261: document.ggbApplet_$id.evalCommand("$yvariable=Slider[-$range,$range,$yinterval]");
262: document.ggbApplet_$id.setVisible("$yvariable", false);
263: document.ggbApplet_$id.evalCommand("$yvariable=$yrel");
1.48 www 264: document.ggbApplet_$id.evalCommand("$variable=$mult($xvariable+x($pointname),$yvariable+y($pointname))");
1.40 www 265: document.ggbApplet_$id.setLabelVisible("$variable", false);
266: ENDSETSVARIABLE
267: }
268:
269: #
1.9 www 270: # Input field name for a coordinate variable
271: #
272:
273: sub field_name {
274: my ($id,$variable,$name)=@_;
275: return "HWVAL_$id\_$variable\_$name";
276: }
277:
278: #
279: # Generate an input field for a coordinate variable
280: #
281:
282: sub generate_input_field {
283: my ($id,$variable,$x,$y)=@_;
284: $Apache::functionplotresponse::inputfields.=
285: "<input type='hidden' name='".&field_name($id,$variable,'x')."' value='$x' />\n".
286: "<input type='hidden' name='".&field_name($id,$variable,'y')."' value='$y' />\n";
287: }
288:
289: #
1.40 www 290: # Initialize a new point coordinate variable at set a listener on it
1.6 www 291: #
1.40 www 292: sub new_point_coordinate {
1.48 www 293: my ($id,$variable,$x,$y,$fixed)=@_;
1.11 www 294: if (defined($Apache::functionplotresponse::previous{&field_name($id,$variable,'x')})) {
1.10 www 295: $x=$Apache::functionplotresponse::previous{&field_name($id,$variable,'x')};
296: }
1.11 www 297: if (defined($Apache::functionplotresponse::previous{&field_name($id,$variable,'y')})) {
1.10 www 298: $y=$Apache::functionplotresponse::previous{&field_name($id,$variable,'y')};
299: }
1.9 www 300: &generate_input_field($id,$variable,$x,$y);
1.48 www 301: return &set_point_coordinate($id,$variable,$x,$y,$fixed).&update_register($id,$variable);
1.40 www 302: }
303:
304: #
305: # Initialize a new slope coordinate variable at set a listener on it
306: #
307: sub new_slope_coordinate {
1.48 www 308: my ($id,$variable,$x,$y,$pointname,$xp,$yp,$xmin,$xmax,$ymin,$ymax,$fixed)=@_;
1.40 www 309: #
310: # $variable: name of the slope point
311: # $x, $y: coordinates of the slope point
312: # $pointname: name of the associated point point
313: # $xp $yp: coordinates of the point point
314: #
315: if (defined($Apache::functionplotresponse::previous{&field_name($id,$variable,'x')})) {
316: $x=$Apache::functionplotresponse::previous{&field_name($id,$variable,'x')};
317: }
318: if (defined($Apache::functionplotresponse::previous{&field_name($id,$variable,'y')})) {
319: $y=$Apache::functionplotresponse::previous{&field_name($id,$variable,'y')};
320: }
321: if (defined($Apache::functionplotresponse::previous{&field_name($id,$pointname,'x')})) {
322: $xp=$Apache::functionplotresponse::previous{&field_name($id,$pointname,'x')};
323: }
324: if (defined($Apache::functionplotresponse::previous{&field_name($id,$pointname,'y')})) {
325: $yp=$Apache::functionplotresponse::previous{&field_name($id,$pointname,'y')};
326: }
327:
328: &generate_input_field($id,$variable,$x,$y);
329: my $xrel=$x-$xp;
330: my $yrel=$y-$yp;
1.48 www 331: return &set_slope_coordinate($id,$variable,$xrel,$yrel,$xmin,$xmax,$ymin,$ymax,$pointname,$fixed).&update_register($id,$variable);
1.5 www 332: }
333:
334: #
335: # This registers the init-function call for ggbOnInit, which LON-CAPA will place at </problem>
336: # It then starts the right headers
337: #
1.3 www 338: sub start_init_script {
339: my ($id)=@_;
1.16 www 340: # Add id to the list of ggbInit_$id functions that need to be called
341: push(@Apache::functionplotresponse::callscripts,$id);
1.5 www 342: # ... and open this function
1.3 www 343: return (<<ENDSTARTINIT);
344: <script type="text/javascript">
345: // <![CDATA[
1.5 www 346: // variable that will eventually be passed back to the server
347: var coordinateMap_$id = [];
1.16 www 348: // flag for not loaded yet
349: var loaded_$id=false;
1.5 www 350: // Init-function for applet
1.3 www 351: function ggbInit_$id() {
352: ENDSTARTINIT
353: }
354:
1.5 www 355: #
356: # This sets the axes inside ggbInit_$id
357: #
358:
1.4 www 359: sub axes_script {
360: my ($id,$xmin,$xmax,$ymin,$ymax,$xvisible,$yvisible,$gvisible)=@_;
361: return (<<ENDAXESSCRIPT);
362: // changes (xmin, xmax, ymin, ymax)
363: document.ggbApplet_$id.setCoordSystem($xmin,$xmax,$ymin,$ymax);
364:
365: // makes the (x,y) axis (in)visible
366: document.ggbApplet_$id.setAxesVisible($xvisible,$yvisible);
367: // makes the grid (in)visible
368: document.ggbApplet_$id.setGridVisible($gvisible);
369: ENDAXESSCRIPT
370: }
371:
1.14 www 372: sub axes_label {
1.45 www 373: my ($id,$xmin,$xmax,$ymin,$ymax,$xlabel,$ylabel)=@_;
1.14 www 374: unless ($xlabel || $ylabel) { return ''; }
375: my $return='document.ggbApplet_'.$id.'.evalCommand("topRight=Corner[3]");';
376: if ($xlabel) {
1.45 www 377: if (($ymin<0) && ($ymax>0)) {
1.14 www 378: $return.=(<<ENDXAXISLABELSCRIPT);
379: document.ggbApplet_$id.evalCommand("Xlabel=(x(topRight)-AxisStepX[],AxisStepY[]/6)");
380: document.ggbApplet_$id.setVisible("Xlabel",false);
381: document.ggbApplet_$id.evalCommand("Text[\\"$xlabel\\", Xlabel]");
382: ENDXAXISLABELSCRIPT
1.45 www 383: } else {
384: $return.=(<<ENDXOFFAXISLABEL);
385: document.ggbApplet_$id.evalCommand("LowerRight=Corner[2]");
386: document.ggbApplet_$id.evalCommand("Text[\\"$xlabel\\", (x(LowerRight) - AxisStepX[], y(LowerRight) + AxisStepY[] / 2)]");
387: ENDXOFFAXISLABEL
388: }
1.14 www 389: }
390: if ($ylabel) {
1.45 www 391: if (($xmin<0) && ($xmax>0)) {
1.14 www 392: $return.=(<<ENDYAXISLABELSCRIPT);
393: document.ggbApplet_$id.evalCommand("Ylabel=(AxisStepX[]/6,y(topRight)-AxisStepY[]/3)");
394: document.ggbApplet_$id.setVisible("Ylabel",false);
395: document.ggbApplet_$id.evalCommand("Text[\\"$ylabel\\", Ylabel]");
396: ENDYAXISLABELSCRIPT
1.45 www 397: } else {
398: $return.=(<<ENDYOFFAXISLABEL);
399: document.ggbApplet_$id.evalCommand("UpperLeft=Corner[4]");
400: document.ggbApplet_$id.evalCommand("Text[\\"$ylabel\\", (x(UpperLeft) + AxisStepX[] / 5, y(UpperLeft) - AxisStepY[] / 1.8)]");
401: ENDYOFFAXISLABEL
402: }
1.14 www 403: }
404: return $return;
405: }
406:
1.58 www 407: #
408: # Subroutine to produce background and answer plots
409: #
410:
1.4 www 411: sub plot_script {
1.47 www 412: my ($id,$function,$fixed,$label,$color,$xmin,$xmax,$thickness)=@_;
1.41 www 413: $label=~s/\W//g;
414: if (($label) && ($label!~/^[A-Za-z]/)) {
415: $label='C'.$label;
416: }
417: my $visible=0;
418: if ($label) {
419: $visible="1";
420: } else {
421: $Apache::functionplotresponse::counter++;
422: $label='C'.$Apache::functionplotresponse::counter;
423: }
1.46 www 424: my $rc=0;
425: my $gc=0;
426: my $bc=0;
427: if ($color) {
428: my ($rh,$gh,$bh)=($color=~/(..)(..)(..)/);
429: $rc=hex($rh);
430: $gc=hex($gh);
431: $bc=hex($bh);
432: }
1.6 www 433: if ($fixed) {
1.43 www 434: return "document.ggbApplet_$id.evalCommand('$label=Function[$function,$xmin,$xmax]');\n".
1.46 www 435: ($visible?'':"document.ggbApplet_$id.setLabelVisible('$label', false);\n").
1.47 www 436: ($color?"document.ggbApplet_$id.setColor('$label',$rc,$gc,$bc);\n":'').
437: ($thickness?"document.ggbApplet_$id.setLineThickness('$label',$thickness);\n":'');
1.6 www 438: } else {
1.46 www 439: return "document.ggbApplet_$id.evalCommand('y=$function');\n";
1.6 www 440: }
1.4 www 441: }
442:
1.5 www 443: #
1.70 www 444: # Subroutine to produce objects
445: #
446:
447: sub plotobject_script {
448: my ($id,$label,$x,$y)=@_;
449: unless ($label) {
450: $Apache::functionplotresponse::counter++;
451: $label='O'.$Apache::functionplotresponse::counter;
452: }
1.77 www 453: &generate_input_field($id,$label,$x,$y);
1.70 www 454: return "document.ggbApplet_$id.evalCommand('a=1');\n".
455: "document.ggbApplet_$id.setVisible('a', false);\n".
456: "document.ggbApplet_$id.setLabelVisible('a', false);\n".
457: "document.ggbApplet_$id.evalCommand('$label=a*($x,$y)');\n".
458: "document.ggbApplet_$id.setVisible('$label', true);\n".
459: "document.ggbApplet_$id.setLabelVisible('$label', true);\n";
460: }
461:
462: #
463: # Subroutine to produce vectors
464: #
465:
466: sub plotvector_script {
1.92 www 467: my ($id,$label,$xs,$ys,$xe,$ye,$xmin,$xmax,$fixed)=@_;
1.70 www 468: unless ($label) {
469: $Apache::functionplotresponse::counter++;
470: $label='V'.$Apache::functionplotresponse::counter;
471: }
1.71 www 472: my $startlabel=$label.'Start';
473: my $endlabel=$label.'End';
474: my $pointlabel=$label.'Point';
1.72 www 475: my $pointx=2.*($xmax-$xmin)+$xmax;
1.71 www 476: my $anglelabel=$label.'Angle';
1.74 www 477: return
1.92 www 478: &new_point_coordinate($id,$startlabel,$xs,$ys,$fixed).
479: &new_point_coordinate($id,$endlabel,$xe,$ye,$fixed).
1.74 www 480: (<<ENDVECTOR);
1.71 www 481: document.ggbApplet_$id.evalCommand("$label=Vector[$startlabel,$endlabel]");
482: document.ggbApplet_$id.setLabelVisible("$label",true);
483: document.ggbApplet_$id.setLineThickness("$label",8);
1.72 www 484: document.ggbApplet_$id.evalCommand("$pointlabel=($pointx,y($startlabel))");
485: document.ggbApplet_$id.evalCommand("$anglelabel=Angle[$pointlabel,$startlabel,$endlabel]");
486: document.ggbApplet_$id.setLabelVisible("$anglelabel",true);
487: document.ggbApplet_$id.setLabelStyle("$anglelabel",VALUE=2);
1.70 www 488: ENDVECTOR
489: }
490:
491: #
1.58 www 492: # Answer spline display
493: #
494: # points: x,y,slope_x,slope_y
495:
496: sub answer_spline_script {
497: my ($id,@points)=@_;
498: my $order=int(($#points+1)/4);
499: if ($order<2) { $order=2; }
500: if ($order>8) { $order=8; }
501: $Apache::functionplotresponse::counter++;
1.60 www 502: my $label='CSpline'.$Apache::functionplotresponse::counter;
1.59 www 503: my $output='document.ggbApplet_'.$id.'.evalCommand("'.$label.'=Spline'.$order.'[';
504: for (my $i=0;$i<=$#points;$i+=4) {
505: $output.="($points[$i],$points[$i+1]),($points[$i+2],$points[$i+3]),";
506: }
507: $output=~s/\,$//;
508: $output.=']");'."\n";
509: for (my $i=2; $i<2*$order; $i+=2) {
1.61 www 510: $output.='document.ggbApplet_'.$id.'.setColor("'.$label.'_'.($i>=10?'{':'').$i.($i>=10?'}':'').'",0,170,0);'."\n";
1.59 www 511: }
1.60 www 512: for (my $i=1; $i<2*$order; $i+=2) {
1.61 www 513: $output.='document.ggbApplet_'.$id.'.setVisible("'.$label.'_'.($i>=10?'{':'').$i.($i>=10?'}':'').'",false);'."\n";
1.60 www 514: }
515:
1.59 www 516: return $output;
1.58 www 517: }
518:
519: #
1.7 www 520: # Subroutine that generates code for spline $label based on stored information
1.6 www 521: #
522:
523: sub generate_spline {
1.48 www 524: my ($id,$label,$xmin,$xmax,$ymin,$ymax,$fixed)=@_;
1.6 www 525: my $result='';
1.7 www 526: my $order=$Apache::functionplotresponse::splineorder{$label};
527: my $x=$Apache::functionplotresponse::splineinitx{$label};
528: my $y=$Apache::functionplotresponse::splineinity{$label};
529: my $sx=$Apache::functionplotresponse::splinescalex{$label};
530: my $sy=$Apache::functionplotresponse::splinescaley{$label};
531: my @coords=();
532: foreach my $i (1..$order) {
1.48 www 533: $result.=&new_point_coordinate($id,$label.'P'.$i,$x,$y,$fixed);
1.40 www 534: my $xp=$x;
1.8 www 535: $x+=$sx/(2.*($order-1));
1.7 www 536: push(@coords,$label.'P'.$i);
1.48 www 537: $result.=&new_slope_coordinate($id,$label.'S'.$i,$x,$y+$sy,$label.'P'.$i,$xp,$y,$xmin,$xmax,$ymin,$ymax,$fixed);
1.8 www 538: $x+=$sx/(2.*($order-1));
1.7 www 539: push(@coords,$label.'S'.$i);
540: }
541: $result.='document.ggbApplet_'.$id.'.evalCommand("Spline'.$order.'['.join(',',@coords).']");'."\n";
1.6 www 542: return $result;
543: }
1.70 www 544:
545: #
546: # Object
547: #
548:
549: sub start_plotobject {
550: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
551: my $result='';
552: my $internalid = $Apache::inputtags::part.'_'.$Apache::inputtags::response[-1];
553: my $x=&Apache::lonxml::get_param('x',$parstack,$safeeval);
554: my $y=&Apache::lonxml::get_param('y',$parstack,$safeeval);
555: my $label=&Apache::lonxml::get_param('label',$parstack,$safeeval);
556: $label=~s/\W//gs;
557: $label=ucfirst($label);
558: unless ($label) { $label="NewObject"; }
559: if ($target eq 'web') {
560: my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-3);
561: unless (defined($x)) { $x=$xmin; }
562: unless (defined($y)) { $y=$ymin; }
563: $result.=&plotobject_script($internalid,$label,$x,$y);
564: } elsif ($target eq 'edit') {
565: $result=&Apache::edit::tag_start($target,$token,'Plot Object').
566: &Apache::edit::text_arg('Label on Plot:','label',
567: $token,'16').
568: &Apache::edit::text_arg('x:','x',
569: $token,'8').
570: &Apache::edit::text_arg('y:','y',
571: $token,'8').
572: &Apache::edit::end_row();
573: } elsif ($target eq 'modified') {
1.76 www 574: $env{'form.'.&Apache::edit::html_element_name('label')}=ucfirst($env{'form.'.&Apache::edit::html_element_name('label')});
1.70 www 575: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'label','x','y');
576: if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
577: }
578: return $result;
579: }
580:
581: sub end_plotobject {
582: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
583: my $result='';
584: if ($target eq 'edit') {
585: $result=&Apache::edit::end_table();
586: }
587: return $result;
588: }
589:
1.71 www 590: #
591: # Vector
592: #
593:
594: sub start_plotvector {
595: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
596: my $result='';
597: my $internalid = $Apache::inputtags::part.'_'.$Apache::inputtags::response[-1];
598: my $tailx=&Apache::lonxml::get_param('tailx',$parstack,$safeeval);
599: my $taily=&Apache::lonxml::get_param('taily',$parstack,$safeeval);
600: my $tipx=&Apache::lonxml::get_param('tipx',$parstack,$safeeval);
601: my $tipy=&Apache::lonxml::get_param('tipy',$parstack,$safeeval);
602:
603: my $label=&Apache::lonxml::get_param('label',$parstack,$safeeval);
604: $label=~s/\W//gs;
605: $label=ucfirst($label);
606: unless ($label) { $label="NewVector"; }
1.95 www 607: if ($Apache::functionplotresponse::vectorlabels{$label}) {
608: &Apache::lonxml::warning(&mt('Vector labels must be unique: [_1]',$label));
609: }
610: $Apache::functionplotresponse::vectorlabels{$label}=1;
1.71 www 611: if ($target eq 'web') {
612: my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-3);
613: unless (defined($tailx)) { $tailx=$xmin; }
614: unless (defined($taily)) { $taily=$ymin; }
615: unless (defined($tipx)) { $tipx=$xmin; }
616: unless (defined($tipy)) { $tipy=$ymin; }
1.92 www 617: my $fixed=0;
618: if ((&Apache::response::show_answer()) || (&Apache::response::check_status()>=2)) { $fixed=1; }
619: $result.=&plotvector_script($internalid,$label,$tailx,$taily,$tipx,$tipy,$xmin,$xmax,$fixed);
1.71 www 620: } elsif ($target eq 'edit') {
621: $result=&Apache::edit::tag_start($target,$token,'Plot Vector').
622: &Apache::edit::text_arg('Label on Plot:','label',
623: $token,'16').
624: &Apache::edit::text_arg('Tail x:','tailx',
625: $token,'8').
626: &Apache::edit::text_arg('Tail y:','taily',
627: $token,'8').
628: &Apache::edit::text_arg('Tip x:','tipx',
629: $token,'8').
630: &Apache::edit::text_arg('Tip y:','tipy',
631: $token,'8').
632:
633: &Apache::edit::end_row();
634: } elsif ($target eq 'modified') {
1.76 www 635: $env{'form.'.&Apache::edit::html_element_name('label')}=ucfirst($env{'form.'.&Apache::edit::html_element_name('label')});
1.71 www 636: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'label','tailx','taily','tipx','tipy');
637: if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
638: }
639: return $result;
640: }
641:
642: sub end_plotvector {
643: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
644: my $result='';
645: if ($target eq 'edit') {
646: $result=&Apache::edit::end_table();
647: }
648: return $result;
649: }
650:
651:
1.93 www 652: #
653: # Vector sum - have GeoGebra draw a sum of specified vectors to help students draw
654: #
655:
656: sub start_drawvectorsum {
657: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
658: my $result='';
659: my $internalid = $Apache::inputtags::part.'_'.$Apache::inputtags::response[-1];
660: my $tailx=&Apache::lonxml::get_param('tailx',$parstack,$safeeval);
661: my $taily=&Apache::lonxml::get_param('taily',$parstack,$safeeval);
1.94 www 662: my $showvalue=&Apache::lonxml::get_param('showvalue',$parstack,$safeeval);
1.93 www 663: my $vectorlist=&Apache::lonxml::get_param('vectorlist',$parstack,$safeeval);
664: my $label=&Apache::lonxml::get_param('label',$parstack,$safeeval);
665: $label=~s/\W//gs;
666: $label=ucfirst($label);
667: unless ($label) { $label="NewVector"; }
668: if ($target eq 'web') {
669: my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-3);
670: unless (defined($tailx)) { $tailx=$xmin; }
671: unless (defined($taily)) { $taily=$ymin; }
672: unless (defined($vectorlist)) { $vectorlist=''; }
673: my @vectors=split(/\,/,$vectorlist);
674: if ($#vectors>0) {
675: my @sumx=();
676: my @sumy=();
677: foreach my $thisvector (@vectors) {
678: $thisvector=~s/\W//gs;
679: $thisvector=ucfirst($thisvector);
680: unless ($thisvector) { next; }
1.95 www 681: unless ($Apache::functionplotresponse::vectorlabels{$thisvector}) {
682: &Apache::lonxml::warning(&mt('Vectors must be defined before using them for drawing vector sums: [_1]',$thisvector));
683: next;
684: }
1.93 www 685: my $vectorx=$thisvector.'X';
686: my $vectory=$thisvector.'Y';
687: $result.=(<<ENDADDVEC);
688: document.ggbApplet_$internalid.evalCommand("$vectorx=x($thisvector)");
689: document.ggbApplet_$internalid.evalCommand("$vectory=y($thisvector)");
690: document.ggbApplet_$internalid.evalCommand("Include$thisvector$label=Checkbox[]");
691: ENDADDVEC
692: push(@sumx,"If[Include$thisvector$label,$vectorx,0]");
693: push(@sumy,"If[Include$thisvector$label,$vectory,0]");
694: }
695: $result.="document.ggbApplet_$internalid.evalCommand(".'"'."xTot$label=".join('+',@sumx).'");'."\n";
696: $result.="document.ggbApplet_$internalid.evalCommand(".'"'."yTot$label=".join('+',@sumy).'");'."\n";
1.94 www 697: my $show=0;
698: if ($showvalue=~/yes/i) {
699: $show=1;
700: }
1.93 www 701: $result.=(<<ENDMAKEVECTOR);
702: document.ggbApplet_$internalid.evalCommand("$label=Vector[($tailx,$taily),($tailx+xTot$label,$taily+yTot$label)]");
703: document.ggbApplet_$internalid.setLabelVisible("$label",true);
704: document.ggbApplet_$internalid.setLineThickness("$label",8);
705: document.ggbApplet_$internalid.setColor("$label",255,0,0);
1.94 www 706: document.ggbApplet_$internalid.setLabelStyle("$label",VALUE=$show);
1.93 www 707: ENDMAKEVECTOR
708: }
709: } elsif ($target eq 'edit') {
710: $result=&Apache::edit::tag_start($target,$token,'Draw Vector Sum').
711: &Apache::edit::text_arg('Label on Plot:','label',
712: $token,'16').
713: &Apache::edit::text_arg('Tail x:','tailx',
714: $token,'8').
715: &Apache::edit::text_arg('Tail y:','taily',
1.94 www 716: $token,'8').
717: &Apache::edit::select_arg('Show Value:','showvalue',
718: ['yes','no'],$token).'<br />'.
1.93 www 719: &Apache::edit::text_arg('Vector List:','vectorlist',
720: $token,'40').
721: &Apache::edit::end_row();
722: } elsif ($target eq 'modified') {
723: $env{'form.'.&Apache::edit::html_element_name('label')}=ucfirst($env{'form.'.&Apache::edit::html_element_name('label')});
1.94 www 724: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'label','tailx','taily','showvalue','vectorlist');
1.93 www 725: if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
726: }
727: return $result;
728: }
729:
730:
731: sub end_drawvectorsum {
732: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
733: my $result='';
734: if ($target eq 'edit') {
735: $result=&Apache::edit::end_table();
736: }
737: return $result;
738: }
739:
740:
1.70 www 741:
1.6 www 742: #
743: # <backgroundplot function="..." fixed="yes/no" />
1.5 www 744: #
1.4 www 745: sub start_backgroundplot {
746: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
747: my $result='';
748: my $internalid = $Apache::inputtags::part.'_'.$Apache::inputtags::response[-1];
749: my $function=&Apache::lonxml::get_param('function',$parstack,$safeeval);
1.47 www 750: my $xinitial=&Apache::lonxml::get_param('xinitial',$parstack,$safeeval);
751: my $xfinal=&Apache::lonxml::get_param('xfinal',$parstack,$safeeval);
1.41 www 752: my $label=&Apache::lonxml::get_param('label',$parstack,$safeeval);
1.46 www 753: my $color=&Apache::lonxml::get_param('color',$parstack,$safeeval);
754: $color=~s/[^a-fA-F0-9]//gs;
755: unless (length($color)==6) { $color=''; }
1.6 www 756: my $fixed=(&Apache::lonxml::get_param('fixed',$parstack,$safeeval)=~/on|true|yes|1/i?1:0);
757:
1.4 www 758: unless ($function) { $function="0"; }
759: if ($target eq 'web') {
1.41 www 760: my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-3);
1.47 www 761: unless (defined($xinitial)) { $xinitial=$xmin; }
762: unless (defined($xfinal)) { $xfinal=$xmax; }
763: $result.=&plot_script($internalid,$function,$fixed,$label,$color,$xinitial,$xfinal);
1.13 www 764: } elsif ($target eq 'edit') {
765: $result=&Apache::edit::tag_start($target,$token,'Background Function Plot').
766: &Apache::edit::text_arg('Function:','function',
767: $token,'16').
1.47 www 768: &Apache::edit::text_arg('Initial x-value (optional):','xinitial',
769: $token,'8').
770: &Apache::edit::text_arg('Final x-value (optional):','xfinal',
771: $token,'8').
1.41 www 772: &Apache::edit::text_arg('Label on Plot:','label',
773: $token,'8').
1.46 www 774: &Apache::edit::text_arg('Color (hex code):','color',
775: $token,'8').
1.13 www 776: &Apache::edit::select_arg('Fixed location:','fixed',
777: ['yes','no'],$token).
778: &Apache::edit::end_row();
779: } elsif ($target eq 'modified') {
780: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.47 www 781: $safeeval,'function','label','xinitial','xfinal','color','fixed');
1.13 www 782: if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
783: }
784: return $result;
1.4 www 785: }
786:
787: sub end_backgroundplot {
1.13 www 788: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
789: my $result='';
790: if ($target eq 'edit') {
791: $result=&Apache::edit::end_table();
792: }
793: return $result;
1.6 www 794: }
795:
796: #
1.25 www 797: # <functionplotrule ... />
1.12 www 798: #
1.25 www 799: sub start_functionplotrule {
1.12 www 800: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
801: my $result='';
1.24 www 802: my $label=&Apache::lonxml::get_param('index',$parstack,$safeeval);
803: $Apache::functionplotresponse::counter++;
804: if ($label=~/\W/) {
1.25 www 805: &Apache::lonxml::warning(&mt('Rule indices should only contain alphanumeric characters.'));
1.24 www 806: }
807: $label=~s/\W//gs;
808: unless ($label) {
809: $label='R'.$Apache::functionplotresponse::counter;
810: } else {
811: $label='R'.$label;
812: }
813:
814: if ($target eq 'grade') {
815: # Simply remember - in order - for later
1.25 www 816: my $beginninglabel=&Apache::lonxml::get_param('xinitiallabel',$parstack,$safeeval);
817: my $endinglabel=&Apache::lonxml::get_param('xfinallabel',$parstack,$safeeval);
1.24 www 818: if (($beginninglabel=~/\W/) || ($endinglabel=~/W/)) {
1.25 www 819: &Apache::lonxml::warning(&mt('Rule labels must be alphanumeric.'));
1.24 www 820: }
821: $beginninglabel=~s/\W//gs;
822: $endinglabel=~s/\W//gs;
823: my $relationship=&Apache::lonxml::get_param('relationship',$parstack,$safeeval);
824: $relationship=~s/\W//gs;
825: $relationship=lc($relationship);
826: unless ($relationship=~/^(eq|ge|gt|le|lt|ne)$/) {
1.25 www 827: &Apache::lonxml::warning(&mt('Rule relationship not defined.'));
1.24 www 828: $relationship='eq';
829: }
1.35 www 830: my $derivative=&Apache::lonxml::get_param('derivativeorder',$parstack,$safeeval);
1.42 www 831: unless (($derivative==-1) || ($derivative==0) || ($derivative==1) || ($derivative==2)) {
1.25 www 832: &Apache::lonxml::warning(&mt('Rule derivative not defined.'));
1.24 www 833: $derivative=0;
834: }
1.25 www 835: push(@Apache::functionplotresponse::functionplotrules,join(':',(
1.24 www 836: $label,
837: $derivative,
1.25 www 838: &Apache::lonxml::get_param('xinitial',$parstack,$safeeval),
1.24 www 839: $beginninglabel,
1.25 www 840: &Apache::lonxml::get_param('xfinal',$parstack,$safeeval),
1.24 www 841: $endinglabel,
1.35 www 842: &Apache::lonxml::get_param('minimumlength',$parstack,$safeeval),
843: &Apache::lonxml::get_param('maximumlength',$parstack,$safeeval),
1.24 www 844: $relationship,
1.33 www 845: &Apache::lonxml::get_param('value',$parstack,$safeeval),
846: &Apache::lonxml::get_param('percenterror',$parstack,$safeeval)
1.24 www 847: )));
848: } elsif ($target eq 'edit') {
1.75 www 849: $result=&Apache::edit::tag_start($target,$token,'Function Plot Graph Rule').
1.36 www 850: &Apache::edit::text_arg('Index/Name:','index',
851: $token,'10').' '.
1.35 www 852: &Apache::edit::select_arg(&mt('Function:'),'derivativeorder',
1.29 www 853: [['0','Function itself'],
854: ['1','First derivative'],
1.42 www 855: ['2','Second derivative'],
856: ['-1','Integral']],$token).'<br />'.
1.44 www 857: &Apache::edit::text_arg('Initial x-value:','xinitial',
1.35 www 858: $token,'8').
1.44 www 859: &Apache::edit::select_or_text_arg('Initial x-value label:','xinitiallabel',
860: [['start','Start of Plot'],
861: ['end','End of Plot']],$token,'8').'<br />'.
1.30 www 862:
1.44 www 863: &Apache::edit::text_arg('Final x-value (optional):','xfinal',
1.35 www 864: $token,'8').
1.44 www 865: &Apache::edit::select_or_text_arg('Final x-value label (optional):','xfinallabel',
1.32 www 866: [['end','End of Plot']],$token,'8').'<br />'.
1.44 www 867: &Apache::edit::text_arg('Minimum length for range (optional):','minimumlength',
1.35 www 868: $token,'8').
1.44 www 869: &Apache::edit::text_arg('Maximum length for range (optional):','maximumlength',
1.35 www 870: $token,'8').'<br />'.
1.38 www 871: &Apache::edit::select_or_text_arg(&mt('Relationship:'),'relationship',
1.29 www 872: [['eq','equal'],
873: ['ne','not equal'],
874: ['ge','greater than or equal'],
875: ['gt','greater than'],
876: ['lt','less than'],
877: ['le','less than or equal']],$token).
878: $result.= &Apache::edit::select_or_text_arg('Value:','value',
1.65 www 879: [['undef','not defined']],$token,'30').
1.29 www 880: &Apache::edit::text_arg('Percent error:','percenterror',
1.35 www 881: $token,'8').
1.29 www 882: &Apache::edit::end_row();
883: } elsif ($target eq 'modified') {
1.54 www 884: if (($env{'form.'.&Apache::edit::html_element_name('xinitial')} ne '') && ($env{'form.'.&Apache::edit::html_element_name('xinitiallabel')} eq 'start')) {
1.53 www 885: $env{'form.'.&Apache::edit::html_element_name('xinitiallabel')}='';
886: }
1.54 www 887: if (($env{'form.'.&Apache::edit::html_element_name('xfinal')} ne '') && ($env{'form.'.&Apache::edit::html_element_name('xfinallabel')} eq 'end')) {
1.53 www 888: $env{'form.'.&Apache::edit::html_element_name('xfinallabel')}='';
889: }
1.29 www 890: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.35 www 891: $safeeval,'index','derivativeorder',
892: 'xinitial','xinitiallabel','xfinal','xfinallabel',
893: 'minimumlength','maximumlength',
894: 'relationship','value','percenterror');
1.29 www 895: if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
1.13 www 896: }
1.12 www 897: return $result;
898: }
899:
1.25 www 900: sub end_functionplotrule {
1.13 www 901: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
902: my $result='';
903: if ($target eq 'edit') {
904: $result=&Apache::edit::end_table();
905: }
906: return $result;
1.12 www 907: }
908:
909:
910: #
1.75 www 911: # <functionplotvectorrule ... />
912: #
913: sub start_functionplotvectorrule {
914: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
915: my $result='';
916: my $label=&Apache::lonxml::get_param('index',$parstack,$safeeval);
917: $Apache::functionplotresponse::counter++;
918: if ($label=~/\W/) {
919: &Apache::lonxml::warning(&mt('Rule indices should only contain alphanumeric characters.'));
920: }
921: $label=~s/\W//gs;
922: unless ($label) {
1.79 www 923: $label='R'.$Apache::functionplotresponse::counter;
1.75 www 924: } else {
1.79 www 925: $label='R'.$label;
1.75 www 926: }
927:
928: if ($target eq 'grade') {
929: # Simply remember - in order - for later
1.77 www 930:
931: my $id=$Apache::inputtags::response[-1];
932: my $partid=$Apache::inputtags::part;
933: my $internalid = $partid.'_'.$id;
934:
1.75 www 935: my $vector=&Apache::lonxml::get_param('vector',$parstack,$safeeval);
936: $vector=~s/\W//gs;
937: $vector=ucfirst($vector);
1.76 www 938:
1.75 www 939: push(@Apache::functionplotresponse::functionplotvectorrules,join(':',(
940: $label,
1.76 www 941: 'vector',
1.77 www 942: $internalid,
1.75 www 943: $vector,
1.87 www 944: &Apache::lonxml::get_param('attachpoint',$parstack,$safeeval),
945: &Apache::lonxml::get_param('notattachpoint',$parstack,$safeeval),
946: &Apache::lonxml::get_param('tailpoint',$parstack,$safeeval),
947: &Apache::lonxml::get_param('tippoint',$parstack,$safeeval),
948: &Apache::lonxml::get_param('nottailpoint',$parstack,$safeeval),
949: &Apache::lonxml::get_param('nottippoint',$parstack,$safeeval),
1.75 www 950: &Apache::lonxml::get_param('length',$parstack,$safeeval),
951: &Apache::lonxml::get_param('angle',$parstack,$safeeval),
1.79 www 952: &Apache::lonxml::get_param('lengtherror',$parstack,$safeeval),
953: &Apache::lonxml::get_param('angleerror',$parstack,$safeeval),
1.75 www 954: )));
955: } elsif ($target eq 'edit') {
956: $result=&Apache::edit::tag_start($target,$token,'Function Plot Vector Rule').
957: &Apache::edit::text_arg('Index/Name:','index',
958: $token,'10').' '.
959: &Apache::edit::text_arg('Vector:','vector',
960: $token,'16').'<br />'.
1.76 www 961: &Apache::edit::text_arg('Attached to object:','attachpoint',
962: $token,'16').
963: &Apache::edit::text_arg('Not attached to object:','notattachpoint',
964: $token,'16').'<br />'.
1.75 www 965: &Apache::edit::text_arg('Tail attached to object:','tailpoint',
966: $token,'16').
967: &Apache::edit::text_arg('Tip attached to object:','tippoint',
968: $token,'16').
969: &Apache::edit::text_arg('Tail not attached to object:','nottailpoint',
970: $token,'16').
971: &Apache::edit::text_arg('Tip not attached to object:','nottippoint',
972: $token,'16').'<br />'.
973: &Apache::edit::text_arg('Length:','length',
1.84 www 974: $token,'30').
975: &Apache::edit::text_arg('Absolute error length:','lengtherror',
976: $token,'8').'<br />'.
1.75 www 977: &Apache::edit::text_arg('Angle:','angle',
1.84 www 978: $token,'30').
1.79 www 979: &Apache::edit::text_arg('Absolute error angle:','angleerror',
1.75 www 980: $token,'8').
981: &Apache::edit::end_row();
982: } elsif ($target eq 'modified') {
1.76 www 983: $env{'form.'.&Apache::edit::html_element_name('vector')}=ucfirst($env{'form.'.&Apache::edit::html_element_name('vector')});
1.75 www 984: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.76 www 985: $safeeval,'index','vector','attachpoint','notattachpoint',
1.75 www 986: 'tailpoint','tippoint','nottailpoint','nottipoint',
987: 'length','angle',
1.79 www 988: 'lengtherror','angleerror');
1.75 www 989: if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
990: }
991: return $result;
992: }
993:
994: sub end_functionplotvectorrule {
995: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
996: my $result='';
997: if ($target eq 'edit') {
998: $result=&Apache::edit::end_table();
999: }
1000: return $result;
1001: }
1002:
1.76 www 1003: #
1004: # <functionplotvectorsumrule ... />
1005: #
1006: sub start_functionplotvectorsumrule {
1007: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1008: my $result='';
1009: my $label=&Apache::lonxml::get_param('index',$parstack,$safeeval);
1010: $Apache::functionplotresponse::counter++;
1011: if ($label=~/\W/) {
1012: &Apache::lonxml::warning(&mt('Rule indices should only contain alphanumeric characters.'));
1013: }
1014: $label=~s/\W//gs;
1015: unless ($label) {
1.79 www 1016: $label='R'.$Apache::functionplotresponse::counter;
1.76 www 1017: } else {
1.79 www 1018: $label='R'.$label;
1.76 www 1019: }
1020: if ($target eq 'grade') {
1021: # Simply remember - in order - for later
1.77 www 1022: my $id=$Apache::inputtags::response[-1];
1023: my $partid=$Apache::inputtags::part;
1024: my $internalid = $partid.'_'.$id;
1.82 www 1025: my $vectors=&Apache::lonxml::get_param('vectors',$parstack,$safeeval);
1.76 www 1026: push(@Apache::functionplotresponse::functionplotvectorrules,join(':',(
1027: $label,
1028: 'sum',
1.77 www 1029: $internalid,
1.82 www 1030: $vectors,
1.76 www 1031: &Apache::lonxml::get_param('length',$parstack,$safeeval),
1032: &Apache::lonxml::get_param('angle',$parstack,$safeeval),
1.80 www 1033: &Apache::lonxml::get_param('lengtherror',$parstack,$safeeval),
1.79 www 1034: &Apache::lonxml::get_param('angleerror',$parstack,$safeeval),
1.76 www 1035: )));
1036: } elsif ($target eq 'edit') {
1037: $result=&Apache::edit::tag_start($target,$token,'Function Plot Vector Sum Rule').
1038: &Apache::edit::text_arg('Index/Name:','index',
1039: $token,'10').' '.
1.82 www 1040: &Apache::edit::text_arg('Comma-separated list of vectors:','vectors',
1041: $token,'30').'<br />'.
1.76 www 1042: &Apache::edit::text_arg('Sum vector length:','length',
1.84 www 1043: $token,'30').
1044: &Apache::edit::text_arg('Absolute error length:','lengtherror',
1045: $token,'8').'<br />'.
1.76 www 1046: &Apache::edit::text_arg('Sum vector angle:','angle',
1.84 www 1047: $token,'30').
1048: &Apache::edit::text_arg('Absolute error angle:','angleerror',
1.76 www 1049: $token,'8').
1050: &Apache::edit::end_row();
1.85 www 1051: } elsif ($target eq 'modified') {
1052: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1053: $safeeval,'index','vectors',
1054: 'length','angle',
1055: 'lengtherror','angleerror');
1056: if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
1.76 www 1057: }
1058: return $result;
1059: }
1.75 www 1060:
1.76 www 1061: sub end_functionplotvectorsumrule {
1062: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1063: my $result='';
1064: if ($target eq 'edit') {
1065: $result=&Apache::edit::end_table();
1066: }
1067: return $result;
1068: }
1.75 www 1069:
1070: #
1.85 www 1071: # <functionplotcustom ... />
1072: #
1073: sub start_functionplotcustomrule {
1074: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1075: my $result='';
1076: my $label=&Apache::lonxml::get_param('index',$parstack,$safeeval);
1077: $Apache::functionplotresponse::counter++;
1078: if ($label=~/\W/) {
1079: &Apache::lonxml::warning(&mt('Rule indices should only contain alphanumeric characters.'));
1080: }
1081: $label=~s/\W//gs;
1082: unless ($label) {
1083: $label='R'.$Apache::functionplotresponse::counter;
1084: } else {
1085: $label='R'.$label;
1086: }
1087: &Apache::lonxml::register('Apache::response',('answer'));
1088: if ($target eq 'edit') {
1089: $result=&Apache::edit::tag_start($target,$token,'Function Plot Custom Rule').
1090: &Apache::edit::text_arg('Index/Name:','index',$token,'10').
1091: &Apache::edit::end_row();
1092: } elsif ($target eq 'modified') {
1093: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'index');
1094: if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
1095: }
1096: return $result;
1097: }
1098:
1099: sub end_functionplotcustomrule {
1100: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1101: my $result='';
1102: if ($target eq 'edit') {
1103: $result=&Apache::edit::end_table();
1104: } elsif ($target eq 'grade') {
1105: # Simply remember - in order - for later
1106: my $label=&Apache::lonxml::get_param('index',$parstack,$safeeval);
1107: $Apache::functionplotresponse::counter++;
1108: if ($label=~/\W/) {
1109: &Apache::lonxml::warning(&mt('Rule indices should only contain alphanumeric characters.'));
1110: }
1111: $label=~s/\W//gs;
1112: unless ($label) {
1113: $label='R'.$Apache::functionplotresponse::counter;
1114: } else {
1115: $label='R'.$label;
1116: }
1117: push(@Apache::functionplotresponse::functionplotvectorrules,join(':',(
1118: $label,
1119: 'custom',
1120: &escape($Apache::response::custom_answer[-1])
1121: )));
1122: }
1123: &Apache::lonxml::deregister('Apache::response',('answer'));
1124: return $result;
1125: }
1126:
1127:
1128:
1129: #
1.23 www 1130: # <spline index="..." order="1,2,3,4" initx="..." inity="..." scalex="..." scaley="..." />
1.6 www 1131: #
1132: # Unfortunately, GeoGebra seems to want all splines after everything else, so we need to store them
1133: #
1134: sub start_spline {
1135: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.13 www 1136: my $result='';
1137: if ($target eq 'web') {
1.23 www 1138: my $label=&Apache::lonxml::get_param('index',$parstack,$safeeval);
1.13 www 1139: $Apache::functionplotresponse::counter++;
1140: if ($label=~/\W/) {
1.23 www 1141: &Apache::lonxml::warning(&mt('Spline indices should only contain alphanumeric characters.'));
1.13 www 1142: }
1143: $label=~s/\W//gs;
1.23 www 1144: unless ($label) {
1145: $label='S'.$Apache::functionplotresponse::counter;
1146: } else {
1147: $label='S'.$label;
1148: }
1.13 www 1149: if ($Apache::functionplotresponse::splineorder{$label}) {
1.23 www 1150: &Apache::lonxml::error(&mt('Spline indices must be unique.'));
1.13 www 1151: }
1152:
1153: my $order=&Apache::lonxml::get_param('order',$parstack,$safeeval);
1154: if ($order<2) { $order=2; }
1155: if ($order>8) { $order=8; }
1156: $Apache::functionplotresponse::splineorder{$label}=$order;
1157:
1158: my $x=&Apache::lonxml::get_param('initx',$parstack,$safeeval);
1159: unless ($x) { $x=0; }
1160: $Apache::functionplotresponse::splineinitx{$label}=$x;
1161:
1162: my $y=&Apache::lonxml::get_param('inity',$parstack,$safeeval);
1163: unless ($y) { $y=0; }
1164: $Apache::functionplotresponse::splineinity{$label}=$y;
1165:
1166: my $sx=&Apache::lonxml::get_param('scalex',$parstack,$safeeval);
1167: unless ($sx) { $sx=$order; }
1168: $Apache::functionplotresponse::splinescalex{$label}=$sx;
1169:
1170: my $sy=&Apache::lonxml::get_param('scaley',$parstack,$safeeval);
1171: unless ($sy) { $sy=2; }
1172: $Apache::functionplotresponse::splinescaley{$label}=$sy;
1173: } elsif ($target eq 'edit') {
1174: $result=&Apache::edit::tag_start($target,$token,'Spline').
1.23 www 1175: &Apache::edit::text_arg('Index:','index',
1.14 www 1176: $token,'4').' '.
1.13 www 1177: &Apache::edit::select_arg('Order:','order',
1.44 www 1178: ['2','3','4','5','6','7','8'],$token).' '.
1.13 www 1179: &Apache::edit::text_arg('Initial x-value:','initx',
1.14 www 1180: $token,'4').' '.
1.13 www 1181: &Apache::edit::text_arg('Initial y-value:','inity',
1.14 www 1182: $token,'4').' '.
1.13 www 1183: &Apache::edit::text_arg('Scale x:','scalex',
1.14 www 1184: $token,'4').' '.
1.13 www 1185: &Apache::edit::text_arg('Scale y:','scaley',
1186: $token,'4').
1187: &Apache::edit::end_row();
1188: } elsif ($target eq 'modified') {
1189: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.23 www 1190: $safeeval,'index','order','initx','inity',
1.13 www 1191: 'scalex','scaley');
1192: if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
1193: }
1194: return $result;
1.6 www 1195: }
1196:
1197: sub end_spline {
1.13 www 1198: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1199: my $result='';
1200: if ($target eq 'edit') {
1201: $result=&Apache::edit::end_table();
1202: }
1203: return $result;
1.4 www 1204: }
1205:
1.3 www 1206: sub end_init_script {
1207: return (<<ENDENDINIT);
1208: }
1209: // ]]>
1210: </script>
1211: ENDENDINIT
1212: }
1213:
1.10 www 1214: #
1215: # Storing and restoring spline coordinates from part answers
1216: #
1217: sub decode_previous_answer {
1218: my ($answer)=@_;
1219: foreach my $coordinate (split(/\,/,$answer)) {
1220: my ($key,$value)=split(/\=/,$coordinate);
1221: $Apache::functionplotresponse::previous{$key}=$value;
1222: }
1223: }
1224:
1225: sub get_answer_from_form_fields {
1226: my ($id)=@_;
1227: my $answer='';
1228: my %coords=();
1229: foreach my $field (keys(%env)) {
1230: if ($field=~/^form\.HWVAL\_$id/) {
1231: $field=~/^form\.(.*)$/;
1232: $coords{$1}=$env{$field};
1233: }
1234: }
1235: $answer=join(',',map { $_.'='.$coords{$_} } (sort(keys(%coords))));
1236: return ($answer,%coords);
1237: }
1238:
1.15 www 1239: #
1240: # The following functions calculate the cubic-hermite splines server-side
1241: #
1242:
1243: sub cubic_hermite {
1244: my ($t,$p1,$s1,$p2,$s2)=@_;
1.42 www 1245: return (2.*$t*$t*$t-3.*$t*$t+1.)*$p1 + 3.*($t*$t*$t-2.*$t*$t+$t)*($s1-$p1)+
1246: (-2.*$t*$t*$t+3.*$t*$t) *$p2 + 3.*($t*$t*$t-$t*$t) *($s2-$p2);
1.15 www 1247: }
1248:
1249: #
1250: # d/dt(...)
1251: #
1252:
1253: sub ddt_cubic_hermite {
1254: my ($t,$p1,$s1,$p2,$s2)=@_;
1.42 www 1255: return (6.*$t*$t-6.*$t) *$p1 + 3.*(3.*$t*$t-4.*$t+1.)*($s1-$p1)+
1256: (-6.*$t*$t+6.*$t)*$p2 + 3.*(3.*$t*$t-2.*$t) *($s2-$p2);
1.15 www 1257: }
1258:
1259: #
1260: # d^2/dt^2(...)
1261: #
1262:
1263: sub d2dt2_cubic_hermite {
1264: my ($t,$p1,$s1,$p2,$s2)=@_;
1.42 www 1265: return (12.*$t-6.) *$p1 + 3.*(6.*$t-4.)*($s1-$p1)+
1266: (-12.*$t+6.)*$p2 + 3.*(6.*$t-2.)*($s2-$p2);
1.15 www 1267: }
1268:
1269: #
1.18 www 1270: # Array index calculation
1271: #
1272: sub array_index {
1273: my ($xmin,$xmax,$x)=@_;
1.38 www 1274: if ($x ne '') {
1275: return int(($x-$xmin)/($xmax-$xmin)*400.+0.5);
1276: } else {
1277: return undef;
1278: }
1.20 www 1279: }
1280:
1281: #
1.18 www 1282: # Populate the arrays
1283: #
1284:
1285: sub populate_arrays {
1.64 www 1286: my ($id,$xmin,$xmax,$ymin,$ymax)=@_;
1.26 www 1287: for (my $i=0; $i<=400; $i++) {
1.35 www 1288: $Apache::functionplotresponse::actualxval[$i]=undef;
1.19 www 1289: $Apache::functionplotresponse::func[$i]=undef;
1.22 www 1290: $Apache::functionplotresponse::dfuncdx[$i]=undef;
1.19 www 1291: $Apache::functionplotresponse::d2funcd2x[$i]=undef;
1.18 www 1292: }
1.19 www 1293: unless ($xmax>$xmin) { return 'no_func'; }
1.18 www 1294: # Run over all splines in response
1295: foreach my $label (split(/\,/,$env{"form.HWVAL_AllSplines_$id"})) {
1.19 www 1296: my $xiold=-1;
1.18 www 1297: # Run over all points in spline
1.19 www 1298: for (my $i=1; $i<$env{"form.HWVAL_SplineOrder_".$id."_".$label}; $i++) {
1.18 www 1299: my $ni=$i+1;
1300: my @xparms=($env{'form.HWVAL_'.$id.'_'.$label.'P'.$i.'_x'},
1301: $env{'form.HWVAL_'.$id.'_'.$label.'S'.$i.'_x'},
1302: $env{'form.HWVAL_'.$id.'_'.$label.'P'.$ni.'_x'},
1303: $env{'form.HWVAL_'.$id.'_'.$label.'S'.$ni.'_x'});
1304: my @yparms=($env{'form.HWVAL_'.$id.'_'.$label.'P'.$i.'_y'},
1305: $env{'form.HWVAL_'.$id.'_'.$label.'S'.$i.'_y'},
1306: $env{'form.HWVAL_'.$id.'_'.$label.'P'.$ni.'_y'},
1307: $env{'form.HWVAL_'.$id.'_'.$label.'S'.$ni.'_y'});
1308: # Run in small steps over spline parameter
1.26 www 1309: for (my $t=0; $t<=1; $t+=0.0001) {
1.35 www 1310: my $xreal=&cubic_hermite($t,@xparms);
1311: my $xi=&array_index($xmin,$xmax,$xreal);
1.19 www 1312: if ($xi<$xiold) { return 'no_func'; }
1.26 www 1313: if (($xi>$xiold) && ($xi>=0) && ($xi<=400)) {
1.18 www 1314: $xiold=$xi;
1.35 www 1315: $Apache::functionplotresponse::actualxval[$xi]=$xreal;
1.22 www 1316: # Function value
1.30 www 1317: my $funcval=&cubic_hermite($t,@yparms);
1.64 www 1318:
1319: # Do we already have a value for this point, and is it different from the new one?
1320: if ((defined($Apache::functionplotresponse::func[$xi])) &&
1321: (abs($Apache::functionplotresponse::func[$xi]-$funcval)>($ymax-$ymin)/100.)) {
1322: return 'no_func';
1323: }
1324: # Okay, remember the new point
1.30 www 1325: $Apache::functionplotresponse::func[$xi]=$funcval;
1.64 www 1326:
1.30 www 1327: if (defined($funcval)) {
1328: if ($xi<$Apache::functionplotresponse::functionplotrulelabels{'start'}) {
1329: $Apache::functionplotresponse::functionplotrulelabels{'start'}=$xi;
1330: }
1331: if ($xi>$Apache::functionplotresponse::functionplotrulelabels{'end'}) {
1332: $Apache::functionplotresponse::functionplotrulelabels{'end'}=$xi;
1333: }
1334: }
1.28 www 1335: # Chain rule
1.22 www 1336: # dy/dx=dy/dt/(dx/dt)
1337: my $dxdt=&ddt_cubic_hermite($t,@xparms);
1338: if ($dxdt) {
1339: $Apache::functionplotresponse::dfuncdx[$xi]=&ddt_cubic_hermite($t,@yparms)/$dxdt;
1.34 www 1340: # Second derivative
1.28 www 1341: $Apache::functionplotresponse::d2funcdx2[$xi]=
1.34 www 1342: ($dxdt*&d2dt2_cubic_hermite($t,@yparms)-&ddt_cubic_hermite($t,@yparms)*&d2dt2_cubic_hermite($t,@xparms))/
1343: ($dxdt*$dxdt*$dxdt);
1.22 www 1344: }
1.18 www 1345: }
1346: }
1347: }
1348: }
1349: }
1350:
1351: #
1.37 www 1352: # Implementation of <functionplotresponse>
1.15 www 1353: #
1354:
1.1 www 1355: sub start_functionplotresponse {
1356: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1357: my $result='';
1.6 www 1358: # To remember the splines - somehow, they need to come last
1359: undef %Apache::functionplotresponse::splineorder;
1360: undef %Apache::functionplotresponse::splineinitx;
1361: undef %Apache::functionplotresponse::splineinity;
1362: undef %Apache::functionplotresponse::splinescalex;
1363: undef %Apache::functionplotresponse::splinescaley;
1.10 www 1364: # Remember input fields, etc
1365: undef %Apache::functionplotresponse::previous;
1.9 www 1366: $Apache::functionplotresponse::inputfields='';
1.6 www 1367: $Apache::functionplotresponse::counter=0;
1.95 www 1368: # Remember vectors
1369: undef %Apache::functionplotresponse::vectorlabels;
1.24 www 1370: # Remember rules
1.25 www 1371: undef @Apache::functionplotresponse::functionplotrules;
1.75 www 1372: undef @Apache::functionplotresponse::functionplotvectorrules;
1.37 www 1373: # Remember failed rules
1374: if ($target eq 'grade') {
1375: undef @Apache::functionplotresponse::failedrules;
1376: }
1377: # Delete previous awards
1378: undef $Apache::functionplotresponse::awarddetail;
1.10 www 1379: # Part and ID
1380: my $partid=$Apache::inputtags::part;
1381: my $id=&Apache::response::start_response($parstack,$safeeval);
1.6 www 1382: # Internal ID to mark the applet and its coordinates
1.10 www 1383: my $internalid = $partid.'_'.$id;
1384: # Previous answer
1385: &decode_previous_answer($Apache::lonhomework::history{"resource.$partid.$id.submission"});
1386:
1.6 www 1387: # Parameters of <functionplotresponse>
1.41 www 1388: my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval);
1.6 www 1389: my $xaxisvisible=(&Apache::lonxml::get_param('xaxisvisible',$parstack,$safeeval)=~/on|true|yes|1/i?'true':'false');
1390: my $yaxisvisible=(&Apache::lonxml::get_param('yaxisvisible',$parstack,$safeeval)=~/on|true|yes|1/i?'true':'false');
1391: my $gridvisible=(&Apache::lonxml::get_param('gridvisible',$parstack,$safeeval)=~/on|true|yes|1/i?'true':'false');
1.14 www 1392: my $xlabel=&Apache::lonxml::get_param('xlabel',$parstack,$safeeval);
1393: my $ylabel=&Apache::lonxml::get_param('ylabel',$parstack,$safeeval);
1.12 www 1394: if ($target eq 'edit') {
1395: $result.=&Apache::edit::start_table($token)
1396: .'<tr><td><span class="LC_nobreak">'.&mt('Function Plot Question').'</span></td>'
1397: .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
1.37 www 1398: .&Apache::edit::deletelist($target,$token).' '
1.50 www 1399: .&Apache::edit::insertlist($target,$token).' '
1400: .&Apache::loncommon::help_open_topic('Function_Plot_Response_Question','Function Plot Responses')
1.12 www 1401: .'</span></td>'
1402: ."<td> "
1403: .&Apache::edit::end_row()
1404: .&Apache::edit::start_spanning_row()
1405: ."\n";
1.88 www 1406: $result.=&Apache::edit::text_arg('Width (pixels):','width',
1407: $token,'6').' '.
1408: &Apache::edit::text_arg('Height (pixels):','height',
1409: $token,'6').'<br />'.
1410: &Apache::edit::text_arg('Label x-axis:','xlabel',
1.14 www 1411: $token,'6').' '.
1412: &Apache::edit::text_arg('Minimum x-value:','xmin',
1413: $token,'4').' '.
1.12 www 1414: &Apache::edit::text_arg('Maximum x-value:','xmax',
1.14 www 1415: $token,'4').' '.
1.12 www 1416: &Apache::edit::select_arg('x-axis visible:','xaxisvisible',
1.32 www 1417: ['yes','no'],$token).'<br />'.
1.14 www 1418: &Apache::edit::text_arg('Label y-axis:','ylabel',
1419: $token,'6').' '.
1.12 www 1420: &Apache::edit::text_arg('Minimum y-value:','ymin',
1.14 www 1421: $token,'4').' '.
1.12 www 1422: &Apache::edit::text_arg('Maximum y-value:','ymax',
1.14 www 1423: $token,'4').' '.
1.12 www 1424: &Apache::edit::select_arg('y-axis visible:','yaxisvisible',
1.32 www 1425: ['yes','no'],$token).'<br />'.
1.12 www 1426: &Apache::edit::select_arg('Grid visible:','gridvisible',
1.47 www 1427: ['yes','no'],$token).'<br />'.
1.58 www 1428: &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,...):',
1.63 raeburn 1429: 'answerdisplay',$token,'50').
1.12 www 1430: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
1431: } elsif ($target eq 'modified') {
1432: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.88 www 1433: $safeeval,'width','height','xlabel','xmin','xmax','ylabel','ymin','ymax',
1.47 www 1434: 'xaxisvisible','yaxisvisible','gridvisible','answerdisplay');
1.12 www 1435: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.3 www 1436:
1.12 www 1437: } elsif ($target eq 'meta') {
1.10 www 1438: $result=&Apache::response::meta_package_write('functionplotresponse');
1.35 www 1439: } elsif (($target eq 'answer') &&
1440: ($env{'form.answer_output_mode'} ne 'tex') &&
1441: ($Apache::lonhomework::viewgrades == 'F')) {
1442: my (undef,undef,$udom,$uname)=&Apache::lonnet::whichuser();
1443: $uname =~s/\W//g;
1444: $udom =~s/\W//g;
1445: my $function_name =
1446: join('_','LONCAPA_scriptvars',$uname,$udom,
1447: $env{'form.counter'},$Apache::lonxml::curdepth);
1.89 www 1448: &Apache::lonxml::add_script_result(
1.90 www 1449: &Apache::loncommon::modal_adhoc_window($function_name,700,500,
1450: '<pre>'.$Apache::functionplotresponse::ruleslog.'</pre>',
1451: &mt('Rules Log'))."<br />");
1452: }
1.1 www 1453: return $result;
1454: }
1455:
1.25 www 1456: sub compare_rel {
1.26 www 1457: my ($relationship,$value,$realval,$tol)=@_;
1.36 www 1458: # is the real value undefined?
1.26 www 1459: unless (defined($realval)) {
1.36 www 1460: # the real value is not defined
1.26 www 1461: if ($relationship eq 'eq') {
1462: if ($value eq 'undef') {
1463: return 1;
1464: } else {
1465: return 0;
1466: }
1467: } elsif ($relationship eq 'ne') {
1468: if ($value eq 'undef') {
1469: return 0;
1470: } else {
1471: return 1;
1472: }
1473: } else {
1474: return 0;
1475: }
1476: }
1477:
1.36 www 1478: # is the expected value undefined?
1479: if ($value eq 'undef') {
1480: # but by now we know that the real value is defined
1481: return 0;
1482: }
1483:
1484: # both are defined.
1.26 www 1485: if ($relationship eq 'gt') {
1486: return ($realval>$value);
1487: } elsif ($relationship eq 'ge') {
1488: return ($realval>$value-$tol);
1489: } elsif ($relationship eq 'lt') {
1490: return ($realval<$value);
1491: } elsif ($relationship eq 'le') {
1492: return ($realval<$value+$tol);
1493: } elsif ($relationship eq 'ne') {
1494: return (abs($value-$realval)>$tol);
1495: } else {
1496: return (abs($value-$realval)<$tol);
1497: }
1.25 www 1498: return 0;
1499: }
1500:
1.35 www 1501: sub addlog {
1502: my ($text)=@_;
1.67 www 1503: $text=~s/\'/\\\'/g;
1.35 www 1504: $Apache::functionplotresponse::ruleslog.=$text.'<br />';
1505: }
1506:
1507: sub actualval {
1508: my ($i,$xmin,$xmax)=@_;
1509: return $xmin+$i/400.*($xmax-$xmin);
1510: }
1.65 www 1511:
1.66 www 1512: sub fpr_val {
1513: my ($arg)=@_;
1514: return &actualval($Apache::functionplotresponse::functionplotrulelabels{$arg},
1515: $Apache::functionplotresponse::fpr_xmin,
1516: $Apache::functionplotresponse::fpr_xmax);
1517: }
1518:
1.65 www 1519: sub fpr_f {
1520: my ($arg)=@_;
1521: return $Apache::functionplotresponse::func[&array_index($Apache::functionplotresponse::fpr_xmin,
1522: $Apache::functionplotresponse::fpr_xmax,
1523: $arg)];
1524: }
1525:
1526: sub fpr_dfdx {
1527: my ($arg)=@_;
1528: return $Apache::functionplotresponse::dfuncdx[&array_index($Apache::functionplotresponse::fpr_xmin,
1529: $Apache::functionplotresponse::fpr_xmax,
1530: $arg)];
1531: }
1532:
1533: sub fpr_d2fdx2 {
1534: my ($arg)=@_;
1535: return $Apache::functionplotresponse::d2funcdx2[&array_index($Apache::functionplotresponse::fpr_xmin,
1536: $Apache::functionplotresponse::fpr_xmax,
1537: $arg)];
1538: }
1.77 www 1539:
1.84 www 1540: sub fpr_vectorcoords {
1541: my ($arg)=@_;
1542: $arg=~s/\W//gs;
1543: $arg=ucfirst($arg);
1544: my $id=$Apache::inputtags::response[-1];
1545: my $partid=$Apache::inputtags::part;
1546: my $internalid = $partid.'_'.$id;
1547: return ($env{'form.HWVAL_'.$internalid.'_'.$arg.'Start_x'},
1548: $env{'form.HWVAL_'.$internalid.'_'.$arg.'End_x'},
1549: $env{'form.HWVAL_'.$internalid.'_'.$arg.'Start_y'},
1550: $env{'form.HWVAL_'.$internalid.'_'.$arg.'End_y'});
1551: }
1552:
1553: sub fpr_objectcoords {
1554: my ($arg)=@_;
1555: $arg=~s/\W//gs;
1556: $arg=ucfirst($arg);
1557: my $id=$Apache::inputtags::response[-1];
1558: my $partid=$Apache::inputtags::part;
1559: my $internalid = $partid.'_'.$id;
1560: return ($env{'form.HWVAL_'.$internalid.'_'.$arg.'_x'},
1561: $env{'form.HWVAL_'.$internalid.'_'.$arg.'_y'});
1562: }
1563:
1564: sub fpr_vectorlength {
1565: my ($arg)=@_;
1566: my ($xs,$xe,$ys,$ye)=&fpr_vectorcoords($arg);
1567: return sqrt(($xe-$xs)*($xe-$xs)+($ye-$ys)*($ye-$ys));
1568: }
1569:
1570: sub fpr_vectorangle {
1571: my ($arg)=@_;
1572: my ($xs,$xe,$ys,$ye)=&fpr_vectorcoords($arg);
1573: my $angle=57.2957795*atan2(($ye-$ys),($xe-$xs));
1574: if ($angle<0) { $angle=360+$angle; }
1575: return $angle;
1576: }
1.77 www 1577:
1578: sub vectorcoords {
1579: my ($id,$label)=@_;
1580: return ($env{'form.HWVAL_'.$id.'_'.$label.'Start_x'},
1581: $env{'form.HWVAL_'.$id.'_'.$label.'End_x'},
1582: $env{'form.HWVAL_'.$id.'_'.$label.'Start_y'},
1583: $env{'form.HWVAL_'.$id.'_'.$label.'End_y'});
1584: }
1585:
1586: sub objectcoords {
1587: my ($id,$label)=@_;
1588: return ($env{'form.HWVAL_'.$id.'_'.$label.'_x'},
1589: $env{'form.HWVAL_'.$id.'_'.$label.'_y'});
1590: }
1.81 www 1591:
1592: sub attached {
1.87 www 1593: my ($id,$vector,$objects,$xmin,$xmax,$ymin,$ymax)=@_;
1.81 www 1594: my ($xs,$xe,$ys,$ye)=&vectorcoords($id,$vector);
1595: my $tolx=($xmax-$xmin)/100.;
1596: my $toly=($ymax-$ymin)/100.;
1597: my $tail=0;
1598: my $tip=0;
1.87 www 1599: foreach my $obj (split(/\s*\,\s*/,$objects)) {
1600: $obj=~s/\W//g;
1601: unless ($obj) { next; }
1602: $obj=ucfirst($obj);
1603: my ($xo,$yo)=&objectcoords($id,$obj);
1604: &addlog("Proximity $vector ($xs,$ys)-($xe,$ye) to $obj ($xo,$yo)");
1605: if ((abs($xs-$xo)<$tolx) && (abs($ys-$yo)<$toly)) {
1606: $tail=1;
1607: &addlog("Attached tail: $obj");
1608: }
1609: if ((abs($xe-$xo)<$tolx) && (abs($ye-$yo)<$toly)) {
1610: $tip=1;
1611: &addlog("Attached tip: $obj");
1612: }
1613: }
1.81 www 1614: &addlog("Result tail:$tail tip:$tip");
1615: return($tail,$tip);
1616: }
1617:
1.77 www 1618:
1619: sub vectorangle {
1620: my ($x,$y)=@_;
1.78 www 1621: my $angle=57.2957795*atan2($y,$x);
1622: if ($angle<0) { $angle=360+$angle; }
1623: return $angle;
1.77 www 1624: }
1625:
1626: sub vectorlength {
1627: my ($x,$y)=@_;
1628: return sqrt($x*$x+$y*$y);
1629: }
1630:
1.78 www 1631: sub relvector {
1632: my ($xs,$xe,$ys,$ye)=@_;
1633: return ($xe-$xs,$ye-$ys);
1634: }
1635:
1636: sub plotvectorlength {
1637: return &vectorlength(&relvector(&vectorcoords(@_)));
1638: }
1639:
1640: sub plotvectorangle {
1641: return &vectorangle(&relvector(&vectorcoords(@_)));
1642: }
1643:
1.77 www 1644:
1645: #
1646: # Evaluate a functionplotvectorrule
1647: #
1648:
1649: sub functionplotvectorrulecheck {
1650: my ($rule,$xmin,$xmax,$ymin,$ymax,$safeeval)=@_;
1.78 www 1651: &addlog("=================");
1.77 www 1652: my ($label,$type)=split(/\:/,$rule);
1653: if ($type eq 'vector') {
1654: return &vectorcheck($rule,$xmin,$xmax,$ymin,$ymax,$safeeval);
1655: } elsif ($type eq 'sum') {
1656: return &sumcheck($rule,$xmin,$xmax,$ymin,$ymax,$safeeval);
1.85 www 1657: } elsif ($type eq 'custom') {
1658: return &customcheck($rule,$safeeval);
1.77 www 1659: }
1660: }
1661:
1662: sub vectorcheck {
1663: my ($rule,$xmin,$xmax,$ymin,$ymax,$safeeval)=@_;
1664: my ($label,$type,$id,$vector,
1665: $attachpoint,$notattachpoint,
1666: $tailpoint,$tippoint,$nottailpoint,$nottippoint,
1.79 www 1667: $length,$angle,$lengtherror,$angleerror)=split(/\:/,$rule);
1.78 www 1668: &addlog("Vector Rule $label for vector ".$vector);
1.79 www 1669: if ($length ne '') {
1670: &addlog("Checking for length $length with error $lengtherror");
1671: $length=&Apache::run::run($length,$safeeval);
1672: &addlog("Length evaluated to $length");
1673: my $thislength=&plotvectorlength($id,$vector);
1674: &addlog("Found length $thislength");
1675: if (abs($thislength-$length)>$lengtherror) {
1676: &setfailed($label);
1677: return 0;
1678: }
1679: }
1.80 www 1680: if ($angle ne '') {
1681: &addlog("Checking for angle $angle with error $angleerror");
1682: $angle=&Apache::run::run($angle,$safeeval);
1683: &addlog("Angle evaluated to $angle");
1684: my $thisangle=&plotvectorangle($id,$vector);
1685: &addlog("Found angle $thisangle");
1686: my $anglediff=abs($thisangle-$angle);
1687: &addlog("Angle difference: $anglediff");
1688: if ($anglediff>360.-$anglediff) {
1689: $anglediff=360.-$anglediff;
1690: }
1691: &addlog("Smallest angle difference: $anglediff");
1692: if ($anglediff>$angleerror) {
1693: &setfailed($label);
1694: return 0;
1695: }
1696: }
1.81 www 1697: if ($attachpoint ne '') {
1698: &addlog("Checking attached: ".$attachpoint);
1699: my ($tail,$tip)=&attached($id,$vector,$attachpoint,$xmin,$xmax,$ymin,$ymax);
1700: unless ($tail || $tip) {
1701: &setfailed($label);
1702: return 0;
1703: }
1704: }
1705: if ($notattachpoint ne '') {
1706: &addlog("Checking not attached: ".$notattachpoint);
1707: my ($tail,$tip)=&attached($id,$vector,$notattachpoint,$xmin,$xmax,$ymin,$ymax);
1708: if ($tail || $tip) {
1709: &setfailed($label);
1710: return 0;
1711: }
1712: }
1713: if ($tailpoint ne '') {
1714: &addlog("Checking tail: ".$tailpoint);
1715: my ($tail,$tip)=&attached($id,$vector,$tailpoint,$xmin,$xmax,$ymin,$ymax);
1716: unless ($tail) {
1717: &setfailed($label);
1718: return 0;
1719: }
1720: }
1721: if ($nottailpoint ne '') {
1722: &addlog("Checking not tail: ".$nottailpoint);
1723: my ($tail,$tip)=&attached($id,$vector,$nottailpoint,$xmin,$xmax,$ymin,$ymax);
1724: if ($tail) {
1725: &setfailed($label);
1726: return 0;
1727: }
1728: }
1729: if ($tippoint ne '') {
1730: &addlog("Checking tip: ".$tippoint);
1731: my ($tail,$tip)=&attached($id,$vector,$tippoint,$xmin,$xmax,$ymin,$ymax);
1732: unless ($tip) {
1733: &setfailed($label);
1734: return 0;
1735: }
1736: }
1737: if ($nottippoint ne '') {
1738: &addlog("Checking not tip: ".$nottippoint);
1739: my ($tail,$tip)=&attached($id,$vector,$nottippoint,$xmin,$xmax,$ymin,$ymax);
1740: if ($tip) {
1741: &setfailed($label);
1742: return 0;
1743: }
1744: }
1745:
1.79 www 1746: &addlog("Rule $label passed.");
1747: return 1;
1.77 www 1748: }
1749:
1750: sub sumcheck {
1751: my ($rule,$xmin,$xmax,$ymin,$ymax,$safeeval)=@_;
1.82 www 1752: my ($label,$type,$id,$vectors,$length,$angle,$lengtherror,$angleerror)=split(/\:/,$rule);
1753: &addlog("Vector Sum Rule $label for vectors ".$vectors);
1754: my $sumx=0;
1755: my $sumy=0;
1756: foreach my $sv (split(/\s*\,\s*/,$vectors)) {
1757: my ($rx,$ry)=&relvector(&vectorcoords($id,$sv));
1758: $sumx+=$rx;
1759: $sumy+=$ry;
1760: }
1761: &addlog("Sum vector ($sumx,$sumy)");
1.83 www 1762: if ($length ne '') {
1763: &addlog("Checking length $length with error $lengtherror");
1764: $length=&Apache::run::run($length,$safeeval);
1765: &addlog("Evaluated to $length");
1766: my $thislength=&vectorlength($sumx,$sumy);
1767: &addlog("Actual length $thislength");
1768: if (abs($length-$thislength)>$lengtherror) {
1769: &setfailed($label);
1770: return 0;
1771: }
1772: }
1773: if ($angle ne '') {
1774: &addlog("Checking angle $angle with error $angleerror");
1775: $angle=&Apache::run::run($angle,$safeeval);
1776: &addlog("Evaluated to $angle");
1777: my $thisangle=&vectorangle($sumx,$sumy);
1778: &addlog("Actual angle $thisangle");
1779: my $anglediff=abs($thisangle-$angle);
1780: &addlog("Angle difference: $anglediff");
1781: if ($anglediff>360.-$anglediff) {
1782: $anglediff=360.-$anglediff;
1783: }
1784: &addlog("Smallest angle difference: $anglediff");
1785: if ($anglediff>$angleerror) {
1786: &setfailed($label);
1787: return 0;
1788: }
1789: }
1.79 www 1790: &addlog("Rule $label passed.");
1791: return 1;
1.77 www 1792: }
1793:
1.85 www 1794: sub customcheck {
1795: my ($rule,$safeeval)=@_;
1796: my ($label,$type,$prg)=split(/\:/,$rule);
1797: &addlog("Custom Rule ".$label);
1798: my $result=&Apache::run::run(&unescape($prg),$safeeval);
1799: &addlog("Algorithm returned $result");
1800: unless ($result) {
1801: &setfailed($label);
1802: return 0;
1803: }
1804: &addlog("Rule $label passed.");
1805: return 1;
1806: }
1807:
1.77 www 1808: #
1809: # Evaluate a functionplotrule
1810: #
1.35 www 1811:
1.25 www 1812: sub functionplotrulecheck {
1.65 www 1813: my ($rule,$xmin,$xmax,$ymin,$ymax,$safeeval)=@_;
1.33 www 1814:
1.35 www 1815: my ($label,$derivative,$xinitial,$xinitiallabel,$xfinal,$xfinallabel,$minimumlength,$maximumlength,$relationship,$value,$percent)
1.25 www 1816: =split(/\:/,$rule);
1.33 www 1817: $percent=($percent>0?$percent:5);
1.35 www 1818: &addlog("=================");
1.42 www 1819: &addlog("Rule $label for ".($derivative<0?'integral':('function itself','first derivative','second derivative')[$derivative])." $relationship $value");
1.65 www 1820: #
1821: # Evaluate the value
1822: #
1.91 www 1823: if (($value=~/\D/) && ($value ne 'undef')) {
1.65 www 1824: $Apache::functionplotresponse::fpr_xmin=$xmin;
1825: $Apache::functionplotresponse::fpr_xmax=$xmax;
1826: $value=&Apache::run::run($value,$safeeval);
1827: &addlog("Value evaluated to $value");
1828: }
1829:
1830: #
1831: # Minimum and maximum lengths of the interval
1832: #
1.49 www 1833: if ((defined($minimumlength)) || (defined($maximumlength))) {
1834: &addlog("Minimumlength $minimumlength Maximumlength $maximumlength");
1835: }
1.30 www 1836: my $li=0;
1837: my $lh=400;
1838:
1.31 www 1839: # Special case: the upper boundary was not defined
1840: # and needs to be set to the value where
1841: # the condition is not true anymore => set flag
1842:
1843: my $findupper=0;
1844: if (($xfinal eq '')
1845: && (!defined($Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}))
1846: && ($xfinallabel)) {
1847: $findupper=1;
1848: }
1849:
1.25 www 1850: # if a hard value is set for the boundaries, it overrides the label
1.30 www 1851: if (($xinitial ne '') && ($xinitiallabel ne '') && ($xinitiallabel ne 'start')) {
1852: $li=&array_index($xmin,$xmax,$xinitial);
1853: $Apache::functionplotresponse::functionplotrulelabels{$xinitiallabel}=$li;
1854: }
1855: if (($xfinal ne '') && ($xfinallabel ne '') && ($xfinallabel ne 'end')) {
1856: $lh=&array_index($xmin,$xmax,$xfinal);
1857: $Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}=$lh;
1.25 www 1858: }
1.31 www 1859: # if the label is defined, use it
1.25 www 1860: if (defined($Apache::functionplotresponse::functionplotrulelabels{$xinitiallabel})) {
1.35 www 1861: &addlog("Using lower label $xinitiallabel");
1.30 www 1862: $li=$Apache::functionplotresponse::functionplotrulelabels{$xinitiallabel};
1863: } else {
1864: $li=&array_index($xmin,$xmax,$xinitial);
1.25 www 1865: }
1.31 www 1866: unless ($findupper) {
1867: if (defined($Apache::functionplotresponse::functionplotrulelabels{$xfinallabel})) {
1.35 www 1868: &addlog("Using upper label $xfinallabel");
1.33 www 1869: $lh=$Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}-1;
1.31 www 1870: } else {
1871: $lh=&array_index($xmin,$xmax,$xfinal);
1872: }
1.25 www 1873: }
1874: # Basic sanity checks
1.30 www 1875: if ($li<0) { $li=0; }
1876: if ($lh>400) { $lh=400; }
1.38 www 1877: if (($li>$lh) || (!defined($lh))) {
1.30 www 1878: $lh=$li;
1.25 www 1879: }
1.31 www 1880:
1.35 www 1881: &addlog("Boundaries: x=".&actualval($li,$xmin,$xmax)." (".$Apache::functionplotresponse::actualxval[$li]."; index $li)) to x=".
1882: &actualval($lh,$xmin,$xmax)." (".$Apache::functionplotresponse::actualxval[$lh]."; index $lh))");
1883: if ($findupper) {
1884: &addlog("Looking for label $xfinallabel");
1885: }
1.33 www 1886: my $tol=$percent*($ymax-$ymin)/100;
1887: if ($xmax>$xmin) {
1888: if ($derivative==2) {
1889: $tol=4.*$tol/($xmax-$xmin);
1890: } elsif ($derivative==1) {
1891: $tol=2.*$tol/($xmax-$xmin);
1.42 www 1892: } elsif ($derivative==-1) {
1893: $tol=$tol*($xmax-$xmin)/2.;
1.33 www 1894: }
1.27 www 1895: }
1.42 www 1896: my $integral=0;
1897: my $binwidth=($xmax-$xmin)/400.;
1898: if (($derivative<0) && (!$findupper)) {
1899: # definite integral, calculate over whole length
1900: &addlog("Calculating definite integral");
1901: for (my $i=$li; $i<=$lh; $i++) {
1902: $integral+=$Apache::functionplotresponse::func[$i]*$binwidth;
1903: }
1904: unless (&compare_rel($relationship,$value,$integral,$tol)) {
1905: &addlog("Actual integral ".(defined($integral)?$integral:'undef').", expected $value, tolerance $tol");
1906: &addlog("Rule $label failed.");
1.79 www 1907: &setfailed($label);
1.42 www 1908: return 0;
1909: }
1910: } else {
1911: for (my $i=$li; $i<=$lh; $i++) {
1.25 www 1912: my $val;
1913: if ($derivative==2) {
1.27 www 1914: $val=$Apache::functionplotresponse::d2funcdx2[$i];
1.25 www 1915: } elsif ($derivative==1) {
1.27 www 1916: $val=$Apache::functionplotresponse::dfuncdx[$i];
1.42 www 1917: } elsif ($derivative==-1) {
1918: $integral+=$Apache::functionplotresponse::func[$i]*$binwidth;
1919: $val=$integral;
1.25 www 1920: } else {
1.27 www 1921: $val=$Apache::functionplotresponse::func[$i];
1.25 www 1922: }
1.31 www 1923: unless (&compare_rel($relationship,$value,$val,$tol)) {
1.37 www 1924: &addlog("Actual value ".(defined($val)?$val:'undef').", expected $value, tolerance $tol");
1.35 www 1925: &addlog("Condition not fulfilled at x=".&actualval($i,$xmin,$xmax)." (".$Apache::functionplotresponse::actualxval[$i]."; index $i)");
1.31 www 1926: if (($findupper) && ($i>$li)) {
1.49 www 1927: # Check lengths
1928: unless (&checklength($i,$li,$minimumlength,$maximumlength,$xmin,$xmax,$label)) { return 0; }
1929: # Successfully found a new label, set it
1.31 www 1930: $Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}=$i;
1.35 www 1931: &addlog("Rule $label passed, setting label $xfinallabel");
1.31 www 1932: return 1;
1933: } else {
1.35 www 1934: &addlog("Rule $label failed.");
1.49 www 1935: &setfailed($label);
1.31 www 1936: return 0;
1937: }
1938: }
1.42 www 1939: }
1.25 www 1940: }
1.49 www 1941: # Corner case where this makes sense: using start or stop as defined labels
1942: unless (&checklength($lh,$li,$minimumlength,$maximumlength,$xmin,$xmax,$label)) { return 0; }
1.35 www 1943: &addlog("Rule $label passed.");
1.27 www 1944: return 1;
1.24 www 1945: }
1946:
1.49 www 1947: #
1948: # check for minimum and maximum lengths
1949: #
1950:
1951: sub checklength {
1952: my ($i,$li,$minimumlength,$maximumlength,$xmin,$xmax,$label)=@_;
1953: unless (($minimumlength) || ($maximumlength)) { return 1; }
1954: my $length=&actualval($i,$xmin,$xmax)-&actualval($li,$xmin,$xmax);
1955: if ($minimumlength) {
1956: if ($length<$minimumlength) {
1957: &addlog("Rule $label failed, actual length $length, minimum length $minimumlength");
1958: &setfailed($label);
1959: return 0;
1960: }
1961: }
1962: if ($maximumlength) {
1963: if ($length>$maximumlength) {
1964: &addlog("Rule $label failed, actual length $length, maximum length $maximumlength");
1965: &setfailed($label);
1966: return 0;
1967: }
1968: }
1969: return 1;
1970: }
1971:
1972: sub setfailed {
1.79 www 1973: my ($hintlabel)=@_;
1.49 www 1974: $hintlabel=~s/^R//;
1975: push(@Apache::functionplotresponse::failedrules,$hintlabel);
1976: &addlog("Set hint condition $hintlabel");
1977: }
1978:
1.37 www 1979: sub start_functionplotruleset {
1980: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1981: if ($target eq 'edit') {
1982: return &Apache::edit::start_table($token).
1983: '<tr><td><span class="LC_nobreak">'.&mt('Function Plot Rule Set').'</span></td>'
1984: .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
1985: .&Apache::edit::deletelist($target,$token).' '.
1.50 www 1986: &Apache::edit::insertlist($target,$token).' '
1987: .&Apache::loncommon::help_open_topic('Function_Plot_Response_Rule_Set','Function Plot Rules')
1.37 www 1988: .'</span></td>'
1989: ."<td> "
1990: .&Apache::edit::end_row()
1991: .&Apache::edit::start_spanning_row()
1992: ."\n";
1993: }
1994: }
1.3 www 1995:
1.37 www 1996: sub end_functionplotruleset {
1997: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1998: my $id=$Apache::inputtags::response[-1];
1999: my $partid=$Apache::inputtags::part;
2000: my $internalid = $partid.'_'.$id;
2001:
2002: if ($target eq 'edit' ) {
2003: return &Apache::edit::end_table();
2004: } elsif ($target eq 'grade'
1.10 www 2005: && &Apache::response::submitted()
2006: && $Apache::lonhomework::type ne 'exam') {
1.12 www 2007: #
2008: # Actually grade
2009: #
1.41 www 2010: my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-2);
1.27 www 2011:
1.24 www 2012: my $ad='';
1.30 www 2013: undef %Apache::functionplotresponse::functionplotrulelabels;
1.35 www 2014: $Apache::functionplotresponse::ruleslog='';
1.30 www 2015: $Apache::functionplotresponse::functionplotrulelabels{'start'}=400;
2016: $Apache::functionplotresponse::functionplotrulelabels{'end'}=0;
1.64 www 2017: if (&populate_arrays($internalid,$xmin,$xmax,$ymin,$ymax) eq 'no_func') {
1.21 www 2018: $ad='NOT_FUNCTION';
1.18 www 2019: } else {
1.35 www 2020: &addlog("Start of function ".&actualval($Apache::functionplotresponse::functionplotrulelabels{'start'},$xmin,$xmax)." (index ".
2021: $Apache::functionplotresponse::functionplotrulelabels{'start'}.")");
2022: &addlog("End of function ".&actualval($Apache::functionplotresponse::functionplotrulelabels{'end'},$xmin,$xmax)." (index ".
2023: $Apache::functionplotresponse::functionplotrulelabels{'end'}.")");
2024:
1.24 www 2025: # We have a function that we can actually grade, go through the spline rules.
1.25 www 2026: foreach my $rule (@Apache::functionplotresponse::functionplotrules) {
1.65 www 2027: unless (&functionplotrulecheck($rule,$xmin,$xmax,$ymin,$ymax,$safeeval)) {
1.24 www 2028: $ad='INCORRECT';
2029: last;
2030: }
2031: }
1.77 www 2032: # And now go through the vector rules
2033: foreach my $rule (@Apache::functionplotresponse::functionplotvectorrules) {
2034: unless (&functionplotvectorrulecheck($rule,$xmin,$xmax,$ymin,$ymax,$safeeval)) {
2035: $ad='INCORRECT';
2036: last;
2037: }
2038: }
1.24 www 2039: # If it's not wrong, it's correct
2040: unless ($ad) { $ad='EXACT_ANS' };
1.18 www 2041: }
1.37 www 2042: &addlog("Set hint conditions: ".join(",",@Apache::functionplotresponse::failedrules));
2043: &addlog("Assigned award detail: $ad");
2044: # Store for later to be assigned at end_functionplotresponse
2045: $Apache::functionplotresponse::awarddetail=$ad;
2046: }
2047: }
2048:
2049:
2050: sub end_functionplotresponse {
2051: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2052: &Apache::response::end_response;
2053:
2054: my $result;
2055: my $id=$Apache::inputtags::response[-1];
2056: my $partid=$Apache::inputtags::part;
2057: my $internalid = $partid.'_'.$id;
1.20 www 2058:
1.37 www 2059: if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
2060: if ($target eq 'grade'
2061: && &Apache::response::submitted()
2062: && $Apache::lonhomework::type eq 'exam') {
2063:
2064: &Apache::response::scored_response($partid,$id);
2065:
2066: } elsif ($target eq 'grade'
2067: && &Apache::response::submitted()
2068: && $Apache::lonhomework::type ne 'exam') {
2069: my ($response,%coords)=&get_answer_from_form_fields($internalid);
2070: $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
2071: my %previous=&Apache::response::check_for_previous($response,$partid,$id);
2072: #
2073: # Assign grade
2074: #
2075: my $ad=$Apache::functionplotresponse::awarddetail;
1.12 www 2076: #
2077: # Store grading info
2078: #
2079: $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
2080: &Apache::response::handle_previous(\%previous,$ad);
1.10 www 2081: } elsif ($target eq 'web') {
1.37 www 2082: undef @Apache::functionplotresponse::failedrules;
2083: }
2084: return $result;
2085: }
2086:
2087: sub end_functionplotelements {
2088: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2089: my $result='';
2090: my $id=$Apache::inputtags::response[-1];
2091: my $partid=$Apache::inputtags::part;
2092: my $internalid = $partid.'_'.$id;
2093: if ($target eq 'edit' ) {
2094: $result=&Apache::edit::end_table();
2095: } elsif ($target eq 'web') {
1.47 www 2096: my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-2);
2097:
2098: # Are we in show answer mode?
2099: my $showanswer=&Apache::response::show_answer();
2100: if ($showanswer) {
2101: # Render answerdisplay
2102: my $answerdisplay=&Apache::lonxml::get_param('answerdisplay',$parstack,$safeeval,-2);
2103: if ($answerdisplay=~/\S/s) {
2104: foreach my $plot (split(/\s*\,\s*/,$answerdisplay)) {
1.58 www 2105: my @components=split(/\s*\:\s*/,$plot);
2106: if ($#components<3) {
2107: # Just a simple plot
2108: my ($func,$xl,$xh)=@components;
2109: if ((!defined($xl)) || ($xl eq '')) { $xl=$xmin; }
2110: if ((!defined($xh)) || ($xh eq '')) { $xh=$xmax; }
2111: $result.=&plot_script($internalid,$func,1,'','00aa00',$xl,$xh,6);
2112: } else {
2113: # This is a spline
1.59 www 2114: $result.=&answer_spline_script($internalid,@components);
1.58 www 2115: }
1.47 www 2116: }
2117: }
2118: }
1.48 www 2119: my $fixed=0;
2120: if (($showanswer) || (&Apache::response::check_status()>=2)) { $fixed=1; }
1.6 www 2121: # Now is the time to render all of the stored splines
2122: foreach my $label (keys(%Apache::functionplotresponse::splineorder)) {
1.48 www 2123: $result.=&generate_spline($internalid,$label,$xmin,$xmax,$ymin,$ymax,$fixed);
1.6 www 2124: }
1.5 www 2125: # close the init script
1.3 www 2126: $result.=&end_init_script();
1.17 www 2127: # register all splines in this response
2128: $result.='<input type="hidden" name="HWVAL_AllSplines_'.$internalid.'" value="'.
2129: join(',',keys(%Apache::functionplotresponse::splineorder)).'" />'."\n";
2130: foreach my $label (keys(%Apache::functionplotresponse::splineorder)) {
2131: $result.='<input type="hidden" name="HWVAL_SplineOrder_'.$internalid.'_'.$label.'" value="'.
2132: $Apache::functionplotresponse::splineorder{$label}.'" />'."\n";
2133: }
1.9 www 2134: # generate the input fields
2135: $result.=$Apache::functionplotresponse::inputfields;
1.5 www 2136: # actually start the <applet>-tag
1.88 www 2137: $result.=&geogebra_startcode($internalid,
2138: &Apache::lonxml::get_param('width',$parstack,$safeeval,-2),
2139: &Apache::lonxml::get_param('height',$parstack,$safeeval,-2));
1.5 www 2140: # set default parameters
1.3 www 2141: $result.=&geogebra_default_parameters($internalid);
1.5 www 2142: # close the <applet>-tag
1.1 www 2143: $result.=&geogebra_endcode();
2144: }
2145: return $result;
2146: }
2147:
1.41 www 2148: sub boundaries {
2149: my ($parstack,$safeeval,$level)=@_;
2150: my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval,$level);
2151: $xmin=(defined($xmin)?$xmin:-10);
2152: my $xmax=&Apache::lonxml::get_param('xmax',$parstack,$safeeval,$level);
2153: $xmax=(defined($xmax)?$xmax:10);
2154: my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval,$level);
2155: $ymin=(defined($ymin)?$ymin:-10);
2156: my $ymax=&Apache::lonxml::get_param('ymax',$parstack,$safeeval,$level);
2157: $ymax=(defined($ymax)?$ymax:10);
2158: if ($xmax<=$xmin) {
2159: $xmax=$xmin+20;
2160: }
2161: if ($ymax<=$ymin) {
2162: $ymax=$ymin+20;
2163: }
2164: return ($xmin,$xmax,$ymin,$ymax);
2165: }
2166:
1.37 www 2167: sub start_functionplotelements {
2168: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2169: my $result='';
2170: my $id=$Apache::inputtags::response[-1];
2171: my $partid=$Apache::inputtags::part;
2172: my $internalid = $partid.'_'.$id;
2173:
2174: if ($target eq 'edit') {
2175: return &Apache::edit::start_table($token).
2176: '<tr><td><span class="LC_nobreak">'.&mt('Function Plot Elements').'</span></td>'
2177: .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
2178: .&Apache::edit::deletelist($target,$token).' '.
1.50 www 2179: &Apache::edit::insertlist($target,$token).' '
2180: .&Apache::loncommon::help_open_topic('Function_Plot_Response_Elements','Function Plot Elements')
1.37 www 2181: .'</span></td>'
2182: ."<td> "
2183: .&Apache::edit::end_row()
2184: .&Apache::edit::start_spanning_row()
2185: ."\n";
2186: } elsif ($target eq 'web') {
1.41 www 2187: my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-2);
1.37 www 2188: my $xaxisvisible=(&Apache::lonxml::get_param('xaxisvisible',$parstack,$safeeval,-2)=~/on|true|yes|1/i?'true':'false');
2189: my $yaxisvisible=(&Apache::lonxml::get_param('yaxisvisible',$parstack,$safeeval,-2)=~/on|true|yes|1/i?'true':'false');
2190: my $gridvisible=(&Apache::lonxml::get_param('gridvisible',$parstack,$safeeval,-2)=~/on|true|yes|1/i?'true':'false');
2191: my $xlabel=&Apache::lonxml::get_param('xlabel',$parstack,$safeeval,-2);
2192: my $ylabel=&Apache::lonxml::get_param('ylabel',$parstack,$safeeval,-2);
2193:
2194:
2195: # paste in the update routine to receive stuff back from the applet
2196: $result.=&update_script($internalid);
2197: # start the initscript for this applet
2198: $result.=&start_init_script($internalid);
2199: # put the axis commands inside
2200: $result.=&axes_script($internalid,$xmin,$xmax,$ymin,$ymax,$xaxisvisible,$yaxisvisible,$gridvisible);
1.45 www 2201: $result.=&axes_label($internalid,$xmin,$xmax,$ymin,$ymax,$xlabel,$ylabel);
1.37 www 2202: # init script is left open
2203: }
2204: return $result;
2205: }
2206:
1.1 www 2207: 1;
2208:
2209: __END__
2210:
2211: =head1 NAME
2212:
2213: Apache::functionplotresponse.pm;
2214:
2215: =head1 SYNOPSIS
2216:
2217: Handles tags associated with accepting function plots.
2218:
2219: This is part of the LearningOnline Network with CAPA project
2220: described at http://www.lon-capa.org.
2221:
2222: =head1 HANDLER SUBROUTINE
2223:
2224: start_functionplotresponse()
2225:
2226: =head1 OTHER SUBROUTINES
2227:
2228: =over
2229:
2230: =item end_functionplotresponse()
2231:
2232: =back
2233:
2234: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>