Annotation of loncom/homework/functionplotresponse.pm, revision 1.4
1.1 www 1: # LearningOnline Network with CAPA
2: # option list style responses
3: #
1.4 ! www 4: # $Id: functionplotresponse.pm,v 1.3 2010/10/04 18:28:53 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;
34:
35: BEGIN {
1.4 ! www 36: &Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot'));
1.1 www 37: }
38:
39: sub geogebra_startcode {
1.3 www 40: my ($id)=@_;
1.1 www 41: return (<<ENDSTARTCODE);
1.3 www 42: <applet name="ggbApplet_$id" code="geogebra.GeoGebraApplet" archive="geogebra.jar"
1.1 www 43: codebase="/adm/geogebra/" width="714" height="447" MAYSCRIPT>
44: <param name="java_arguments" value="-Xmx512m -Djnlp.packEnabled=true"/>
45: ENDSTARTCODE
46: }
47:
48: sub geogebra_endcode {
1.2 www 49: return &Apache::lonhtmlcommon::java_not_enabled()."</applet>\n";
50: }
51:
52: sub geogebra_spline_program {
53: return (<<ENDSPLINEPROGRAM);
54: <param name="ggbBase64" value="UEsDBBQACAAIADhQET0AAAAAAAAAAAAAAAASA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2gGfSlFJXjrgvE60ImQk6jsPqfLhCEliHqPWpNoFthKpXS1vRgLDTn/Bq3w7iWbLJaLmMX4wz88dgkWlqSTZJGweTRny9UqWWIKUS8KYYtJzFJkZctZki5SluChf9v81XDcgrVYSkP4GcyYz1qL6ppwt3k2X5W8QZ0SrX3ine21b4N4gLb24m7DvGkX45e2ljBgEVZpD+WhUOdtyFscqF8unT/i9RT1k5JKE+0CRf31sBZh9T5O6NVr5n1m3mPgcKRXe7Ri3sOvRVi9lxRtkDYEHo1Rj1XhZ2GIA5Dcde+YG8kLwGagpG+F3YwbbJrDLVLn/6NvCpya921zpYz+E2U2veu37AC6BRm6qsXC9qo35Oi6N5TO66igFA1ug2FICHfF+oUCAlpBrWHUHUYupMtbP3TuHZxNRxFOg0GtpcW3A+OxLpZt51Kfugm3OF05/c4bMGTD8Y2xF0oqbtHLPR3T98f9iA1vzPovUEsHCEyILqxEAgAAlQQAAFBLAQIUABQACAAIADhQET1gj4YNdwsAAFgqAQASAAAAAAAAAAAAAAAAAAAAAABnZW9nZWJyYV9tYWNyby54bWxQSwECFAAUAAgACAA4UBE9TIgurEQCAACVBAAADAAAAAAAAAAAAAAAAAC3CwAAZ2VvZ2VicmEueG1sUEsFBgAAAAACAAIAegAAADUOAAAAAA=="/>
55: ENDSPLINEPROGRAM
56: }
57:
58: sub geogebra_default_parameters {
1.3 www 59: my ($id)=@_;
1.2 www 60: return(<<ENDDEFAULTPARAMETERS);
61: <param name="image" value="/adm/lonIcons/lonanim.gif" />
62: <param name="boxborder" value="false" />
63: <param name="centerimage" value="true" />
64: <param name="java_arguments" value="-Xmx512m" />
65: <param name="cache_archive" value="geogebra.jar, geogebra_main.jar, geogebra_gui.jar, geogebra_cas.jar, geogebra_export.jar, geogebra_properties.jar" />
66: <param name="cache_version" value="3.2.44.0, 3.2.44.0, 3.2.44.0, 3.2.44.0, 3.2.44.0, 3.2.44.0" />
67: <param name="framePossible" value="false" />
68:
69: <param name="showResetIcon" value="false" />
70: <param name="showAnimationButton" value="false" />
71: <param name="enableRightClick" value="false" />
72: <param name="errorDialogsActive" value="true" />
73: <param name="enableLabelDrags" value="false" />
74: <param name="showMenuBar" value="false" />
75: <param name="showToolBar" value="false" />
76: <param name="showToolBarHelp" value="false" />
77: <param name="showAlgebraInput" value="false" />
78: <param name="enableShiftDragZoom" value="false" />
79: <param name="allowRescaling" value="false" />
80: <param name="enableLabelDrags" value="false" />
1.3 www 81: <param name="ggbOnInitParam" value="applet_$id" />
1.2 www 82: ENDDEFAULTPARAMETERS
1.1 www 83: }
84:
1.3 www 85: sub init_script {
86: if ($Apache::functionplotresponse::callscripts) {
87: return (<<ENDGGBINIT);
88: <script type="text/javascript">
89: // <![CDATA[
90: function ggbOnInit(param) {
91: $Apache::functionplotresponse::callscripts
92: }
93: // ]]>
94: </script>
95: ENDGGBINIT
96: }
97: }
98:
99: sub start_init_script {
100: my ($id)=@_;
101: $Apache::functionplotresponse::callscripts.="if (param=='applet_$id') { ggbInit_$id(); }\n";
102: return (<<ENDSTARTINIT);
103: <script type="text/javascript">
104: // <![CDATA[
105: function ggbInit_$id() {
106: ENDSTARTINIT
107: }
108:
1.4 ! www 109: sub axes_script {
! 110: my ($id,$xmin,$xmax,$ymin,$ymax,$xvisible,$yvisible,$gvisible)=@_;
! 111: return (<<ENDAXESSCRIPT);
! 112: // changes (xmin, xmax, ymin, ymax)
! 113: document.ggbApplet_$id.setCoordSystem($xmin,$xmax,$ymin,$ymax);
! 114:
! 115: // makes the (x,y) axis (in)visible
! 116: document.ggbApplet_$id.setAxesVisible($xvisible,$yvisible);
! 117: // makes the grid (in)visible
! 118: document.ggbApplet_$id.setGridVisible($gvisible);
! 119: ENDAXESSCRIPT
! 120: }
! 121:
! 122: sub plot_script {
! 123: my ($id,$function)=@_;
! 124: return (<<ENDPLOTSCRIPT);
! 125: document.ggbApplet_$id.evalCommand("y=$function");
! 126: ENDPLOTSCRIPT
! 127: }
! 128:
! 129: sub start_backgroundplot {
! 130: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
! 131: my $result='';
! 132: my $internalid = $Apache::inputtags::part.'_'.$Apache::inputtags::response[-1];
! 133: my $function=&Apache::lonxml::get_param('function',$parstack,$safeeval);
! 134: unless ($function) { $function="0"; }
! 135: if ($target eq 'web') {
! 136: $result.=&plot_script($internalid,$function);
! 137: }
! 138: return $result;
! 139: }
! 140:
! 141: sub end_backgroundplot {
! 142: }
! 143:
1.3 www 144: sub end_init_script {
145: return (<<ENDENDINIT);
146: }
147: // ]]>
148: </script>
149: ENDENDINIT
150: }
151:
1.1 www 152: sub start_functionplotresponse {
153: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
154: my $result='';
1.3 www 155: my $internalid = $Apache::inputtags::part.'_'.&Apache::response::start_response($parstack,$safeeval);
156: my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval);
1.4 ! www 157: $xmin=($xmin?$xmin:-10);
1.3 www 158: my $xmax=&Apache::lonxml::get_param('xmax',$parstack,$safeeval);
1.4 ! www 159: $xmax=($xmax?$xmax:10);
1.3 www 160: my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval);
1.4 ! www 161: $ymin=($ymin?$ymin:-10);
1.3 www 162: my $ymax=&Apache::lonxml::get_param('ymax',$parstack,$safeeval);
1.4 ! www 163: $ymax=($ymax?$ymax:10);
! 164: my $xaxisvisible=(&Apache::lonxml::get_param('xaxisvisible',$parstack,$safeeval)=~/on|true|1/i?'true':'false');
! 165: my $yaxisvisible=(&Apache::lonxml::get_param('yaxisvisible',$parstack,$safeeval)=~/on|true|1/i?'true':'false');
! 166: my $gridvisible=(&Apache::lonxml::get_param('gridvisible',$parstack,$safeeval)=~/on|true|1/i?'true':'false');
1.3 www 167:
168:
1.1 www 169: if ($target eq 'web') {
1.3 www 170: $result.=&start_init_script($internalid);
1.4 ! www 171: $result.=&axes_script($internalid,$xmin,$xmax,$ymin,$ymax,$xaxisvisible,$yaxisvisible,$gridvisible);
1.1 www 172: }
173: return $result;
174: }
175:
176: sub end_functionplotresponse {
177: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
178: &Apache::response::end_response;
1.3 www 179:
1.1 www 180: my $result;
1.3 www 181: my $internalid = $Apache::inputtags::part.'_'.$Apache::inputtags::response[-1];
182:
1.1 www 183: # if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
184: if ($target eq 'web') {
1.3 www 185: $result.=&end_init_script();
186: $result.=&geogebra_startcode($internalid);
187: $result.=&geogebra_spline_program();
188: $result.=&geogebra_default_parameters($internalid);
1.1 www 189: $result.=&geogebra_endcode();
190: }
191: return $result;
192: }
193:
194: 1;
195:
196: __END__
197:
198: =head1 NAME
199:
200: Apache::functionplotresponse.pm;
201:
202: =head1 SYNOPSIS
203:
204: Handles tags associated with accepting function plots.
205:
206: This is part of the LearningOnline Network with CAPA project
207: described at http://www.lon-capa.org.
208:
209: =head1 HANDLER SUBROUTINE
210:
211: start_functionplotresponse()
212:
213: =head1 OTHER SUBROUTINES
214:
215: =over
216:
217: =item end_functionplotresponse()
218:
219: =back
220:
221: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>