File:
[LON-CAPA] /
loncom /
xml /
lonplot.pm
Revision
1.63:
download - view:
text,
annotated -
select for diffs
Fri Mar 22 20:05:19 2002 UTC (22 years, 1 month ago) by
albertel
Branches:
MAIN
CVS tags:
HEAD
- changed textfield to the more descriptive editline
- updated all references to textfield to use edit line
- update <import> <scriptlib> <parserlib> to use the new editline
- editline, and editfield now protect entities, should preserve and " much better
1: # The LearningOnline Network with CAPA
2: # Dynamic plot
3: #
4: # $Id: lonplot.pm,v 1.63 2002/03/22 20:05:19 albertel Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: # 12/15/01 Matthew
29: # 12/17 12/18 12/19 12/20 12/21 12/27 12/28 12/30 12/31 Matthew
30: # 01/01/02 Matthew
31: # 01/02 01/03 01/04 01/07 01/08 01/09 Matthew
32: # 01/21 02/05 02/06 2/28Matthew
33:
34: package Apache::lonplot;
35:
36: use strict;
37: use Apache::File;
38: use Apache::response;
39: use Apache::lonxml;
40: use Apache::edit;
41:
42: BEGIN {
43: &Apache::lonxml::register('Apache::lonplot',('gnuplot'));
44: }
45:
46: ##
47: ## Description of data structures:
48: ##
49: ## %plot %key %axis
50: ## --------------------------
51: ## height title color
52: ## width box xmin
53: ## bgcolor pos xmax
54: ## fgcolor ymin
55: ## transparent ymax
56: ## grid
57: ## border
58: ## font
59: ## align
60: ##
61: ## @labels: $labels[$i] = \%label
62: ## %label: text, xpos, ypos, justify
63: ##
64: ## @curves: $curves[$i] = \%curve
65: ## %curve: name, linestyle, ( function | data )
66: ##
67: ## $curves[$i]->{'data'} = [ [x1,x2,x3,x4],
68: ## [y1,y2,y3,y4] ]
69: ##
70:
71: ###################################################################
72: ## ##
73: ## Tests used in checking the validitity of input ##
74: ## ##
75: ###################################################################
76:
77: my $max_str_len = 50; # if a label, title, xlabel, or ylabel text
78: # is longer than this, it will be truncated.
79:
80: my %linestyles =
81: (
82: lines => 2, # Maybe this will be used in the future
83: linespoints => 2, # to check on whether or not they have
84: dots => 2, # supplied enough <data></data> fields
85: points => 2, # to use the given line style. But for
86: steps => 2, # now there are more important things
87: fsteps => 2, # for me to deal with.
88: histeps => 2,
89: errorbars => 3,
90: xerrorbars => [3,4],
91: yerrorbars => [3,4],
92: xyerrorbars => [4,6],
93: boxes => 3,
94: vector => 4
95: );
96:
97: my $int_test = sub {$_[0]=~s/\s+//g;$_[0]=~/^\d+$/};
98: my $real_test =
99: sub {$_[0]=~s/\s+//g;$_[0]=~/^[+-]?\d*\.?\d*([eE][+-]\d+)?$/};
100: my $pos_real_test =
101: sub {$_[0]=~s/\s+//g;$_[0]=~/^[+]?\d*\.?\d*([eE][+-]\d+)?$/};
102: my $color_test = sub {$_[0]=~s/\s+//g;$_[0]=~/^x[\da-f]{6}$/};
103: my $onoff_test = sub {$_[0]=~/^(on|off)$/};
104: my $key_pos_test = sub {$_[0]=~/^(top|bottom|right|left|outside|below| )+$/};
105: my $sml_test = sub {$_[0]=~/^(small|medium|large)$/};
106: my $linestyle_test = sub {exists($linestyles{$_[0]})};
107: my $words_test = sub {$_[0]=~s/\s+/ /g;$_[0]=~/^([\w\(\)]+ ?)+$/};
108:
109: ###################################################################
110: ## ##
111: ## Attribute metadata ##
112: ## ##
113: ###################################################################
114: my @gnuplot_edit_order =
115: qw/bgcolor fgcolor height width font transparent grid border align/;
116:
117: my $gnuplot_help_text = <<"ENDPLOTHELP";
118: <p>
119: The <b>gnuplot</b> tag allows an author to design a plot which can
120: be created on the fly. This is intended for use in homework problems
121: where each student needs to see a distinct plot. It can be used in
122: conjunction with a <b>script</b> tag to generate random plots.
123: </p><p>
124: A <b>gnuplot</b> tag can contain the following sub-tags:
125: </p>
126: <dl>
127: <dt> Plot Label
128: <dd> Allows you to place text at a given (x,y) coordinate on the plot.
129: <dt> Plot Title
130: <dd> The title of the plot
131: <dt> Plot Xlabel
132: <dd> The label on the horizontal axis of the plot
133: <dt> Plot Ylabel
134: <dd> The label on the vertical axis of the plot
135: <dt> Plot Axes
136: <dd> allows specification of the x and y ranges displayed in the plot
137: <dt> Plot Key
138: <dd> Lists the functions displayed in the plot.
139: <dt> Plot Curve
140: <dd> Sets the data used in the plot.
141: <dt> Plot Tics
142: <dd> Allows specification of the x and y coordinate 'tics' on the axes.
143: This is mostly used to adjust the grid lines when a grid is displayed.
144: </dl>
145: If you are having trouble with your plot, please read the help
146: available on Plot Curve.
147: ENDPLOTHELP
148:
149: my %gnuplot_defaults =
150: (
151: height => {
152: default => 200,
153: test => $int_test,
154: description => 'height of image (pixels)',
155: edit_type => 'entry',
156: size => '10'
157: },
158: width => {
159: default => 200,
160: test => $int_test,
161: description => 'width of image (pixels)',
162: edit_type => 'entry',
163: size => '10'
164: },
165: bgcolor => {
166: default => 'xffffff',
167: test => $color_test,
168: description => 'background color of image (xffffff)',
169: edit_type => 'entry',
170: size => '10'
171: },
172: fgcolor => {
173: default => 'x000000',
174: test => $color_test,
175: description => 'foreground color of image (x000000)',
176: edit_type => 'entry',
177: size => '10'
178: },
179: transparent => {
180: default => 'off',
181: test => $onoff_test,
182: description => 'Transparent image',
183: edit_type => 'onoff'
184: },
185: grid => {
186: default => 'off',
187: test => $onoff_test,
188: description => 'Display grid',
189: edit_type => 'onoff'
190: },
191: border => {
192: default => 'on',
193: test => $onoff_test,
194: description => 'Draw border around plot',
195: edit_type => 'onoff'
196: },
197: font => {
198: default => 'medium',
199: test => $sml_test,
200: description => 'Size of font to use',
201: edit_type => 'choice',
202: choices => ['small','medium','large']
203: },
204: align => {
205: default => 'left',
206: test => sub {$_[0]=~/^(left|right|center)$/},
207: description => 'alignment for image in html',
208: edit_type => 'choice',
209: choices => ['left','right','center']
210: }
211: );
212:
213: my %key_defaults =
214: (
215: title => {
216: default => '',
217: test => $words_test,
218: description => 'Title of key',
219: edit_type => 'entry',
220: size => '40'
221: },
222: box => {
223: default => 'off',
224: test => $onoff_test,
225: description => 'Draw a box around the key?',
226: edit_type => 'onoff'
227: },
228: pos => {
229: default => 'top right',
230: test => $key_pos_test,
231: description => 'position of the key on the plot',
232: edit_type => 'choice',
233: choices => ['top left','top right','bottom left','bottom right',
234: 'outside','below']
235: }
236: );
237:
238: my %label_defaults =
239: (
240: xpos => {
241: default => 0,
242: test => $real_test,
243: description => 'x position of label (graph coordinates)',
244: edit_type => 'entry',
245: size => '10'
246: },
247: ypos => {
248: default => 0,
249: test => $real_test,
250: description => 'y position of label (graph coordinates)',
251: edit_type => 'entry',
252: size => '10'
253: },
254: justify => {
255: default => 'left',
256: test => sub {$_[0]=~/^(left|right|center)$/},
257: description => 'justification of the label text on the plot',
258: edit_type => 'choice',
259: choices => ['left','right','center']
260: }
261: );
262:
263: my @tic_edit_order = ('location','mirror','start','increment','end');
264: my %tic_defaults =
265: (
266: location => {
267: default => 'border',
268: test => sub {$_[0]=~/^(border|axis)$/},
269: description => 'Location of tick marks',
270: edit_type => 'choice',
271: choices => ['border','axis']
272: },
273: mirror => {
274: default => 'on',
275: test => $onoff_test,
276: description => 'mirror ticks on opposite axis?',
277: edit_type => 'onoff'
278: },
279: start => {
280: default => '-10.0',
281: test => $real_test,
282: description => 'Start ticks at',
283: edit_type => 'entry',
284: size => '10'
285: },
286: increment => {
287: default => '1.0',
288: test => $real_test,
289: description => 'Place a tick every',
290: edit_type => 'entry',
291: size => '10'
292: },
293: end => {
294: default => ' 10.0',
295: test => $real_test,
296: description => 'Stop ticks at ',
297: edit_type => 'entry',
298: size => '10'
299: },
300: );
301:
302: my %axis_defaults =
303: (
304: color => {
305: default => 'x000000',
306: test => $color_test,
307: description => 'color of axes (x000000)',
308: edit_type => 'entry',
309: size => '10'
310: },
311: xmin => {
312: default => '-10.0',
313: test => $real_test,
314: description => 'minimum x-value shown in plot',
315: edit_type => 'entry',
316: size => '10'
317: },
318: xmax => {
319: default => ' 10.0',
320: test => $real_test,
321: description => 'maximum x-value shown in plot',
322: edit_type => 'entry',
323: size => '10'
324: },
325: ymin => {
326: default => '-10.0',
327: test => $real_test,
328: description => 'minimum y-value shown in plot',
329: edit_type => 'entry',
330: size => '10'
331: },
332: ymax => {
333: default => ' 10.0',
334: test => $real_test,
335: description => 'maximum y-value shown in plot',
336: edit_type => 'entry',
337: size => '10'
338: }
339: );
340:
341: my $curve_help_text = <<"ENDCURVEHELP";
342: The <b>curve</b> tag is where you set the data to be plotted by gnuplot.
343: There are two ways of entering the information:
344: <dl>
345: <dt> Curve Data
346: <dd> Using a <b>data</b> tag you can specify the numbers used to produce
347: the plot.
348: <p>
349: By default, two <b>data</b> tags will be available in a plot. The
350: first will specify X coordinates of the data and the second will
351: give the Y coordinates of the data. When working with a linestyle that
352: requires more than two data sets, inserting another <b>data</b> tag is
353: required. Unfortunately, you must make sure the <b>data</b> tags appear
354: in the order gnuplot expects the data.
355: </p><p>
356: Specifying the data should usually be done with a perl variable or array,
357: such as \@Xdata and \@Ydata. You may also specify numerical data seperated
358: by commas. Again, the order of the <b>data</b> tags is important. The
359: first tag will be the X data and the second will be the Y data.
360: </p>
361: <dt> Curve Function
362: <dd> The <b>function</b> tag allows you to specify the curve to be
363: plotted as a formula that gnuplot can understand. <b>Be careful using this
364: tag.</b> It is surprisingly easy to give gnuplot a function it cannot deal
365: with properly. Be explicit: 2*sin(2*3.141592*x/4) will work but
366: 2sin(2*3.141592x/4) will not. If you do not receive any errors in the
367: gnuplot data but still do not have an image produced, it is likely there
368: is an error in your <b>function</b> tag.
369: </dl>
370: ENDCURVEHELP
371:
372: my @curve_edit_order = ('color','name','linestyle','pointtype','pointsize');
373:
374: my %curve_defaults =
375: (
376: color => {
377: default => 'x000000',
378: test => $color_test,
379: description => 'color of curve (x000000)',
380: edit_type => 'entry',
381: size => '10'
382: },
383: name => {
384: default => '',
385: test => $words_test,
386: description => 'name of curve to appear in key',
387: edit_type => 'entry',
388: size => '20'
389: },
390: linestyle => {
391: default => 'lines',
392: test => $linestyle_test,
393: description => 'Line style',
394: edit_type => 'choice',
395: choices => [keys(%linestyles)]
396: },
397: # gnuplots term=gif driver does not handle linewidth :(
398: # linewidth => {
399: # default => 1,
400: # test => $int_test,
401: # description => 'Line width (may not apply to all line styles)',
402: # edit_type => 'choice',
403: # choices => [1,2,3,4,5,6,7,8,9,10]
404: # },
405: pointsize => {
406: default => 1,
407: test => $pos_real_test,
408: description => 'point size (may not apply to all line styles)',
409: edit_type => 'entry',
410: size => '5'
411: },
412: pointtype => {
413: default => 1,
414: test => $int_test,
415: description => 'point type (may not apply to all line styles)',
416: edit_type => 'choice',
417: choices => [0,1,2,3,4,5,6]
418: }
419: );
420:
421: ###################################################################
422: ## ##
423: ## parsing and edit rendering ##
424: ## ##
425: ###################################################################
426: my (%plot,%key,%axis,$title,$xlabel,$ylabel,@labels,@curves,%xtics,%ytics);
427:
428: sub start_gnuplot {
429: %plot = (); %key = (); %axis = ();
430: $title = undef; $xlabel = undef; $ylabel = undef;
431: $#labels = -1; $#curves = -1;
432: %xtics = (); %ytics = ();
433: #
434: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
435: my $result='';
436: &Apache::lonxml::register('Apache::lonplot',
437: ('title','xlabel','ylabel','key','axis','label','curve',
438: 'xtics','ytics'));
439: push (@Apache::lonxml::namespace,'lonplot');
440: if ($target eq 'web' || $target eq 'tex') {
441: &get_attributes(\%plot,\%gnuplot_defaults,$parstack,$safeeval,
442: $tagstack->[-1]);
443: } elsif ($target eq 'edit') {
444: $result .= &Apache::edit::tag_start($target,$token,'GnuPlot');
445: $result .= &make_javascript();
446: $result .= &help_win($gnuplot_help_text);
447: $result .= &edit_attributes($target,$token,\%gnuplot_defaults,
448: \@gnuplot_edit_order);
449: } elsif ($target eq 'modified') {
450: my $constructtag=&Apache::edit::get_new_args
451: ($token,$parstack,$safeeval,keys(%gnuplot_defaults));
452: if ($constructtag) {
453: $result = &Apache::edit::rebuild_tag($token);
454: }
455: }
456: return $result;
457: }
458:
459: sub end_gnuplot {
460: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
461: pop @Apache::lonxml::namespace;
462: &Apache::lonxml::deregister('Apache::lonplot',
463: ('title','xlabel','ylabel','key','axis','label','curve'));
464: my $result = '';
465: my $randnumber;
466: # need to call rand everytime start_script would evaluate, as the
467: # safe space rand number generator and the global rand generator
468: # are not seperate
469: if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
470: $target eq 'answer') {
471: $randnumber=int(rand(1000));
472: }
473: if ($target eq 'web' || $target eq 'tex') {
474: &check_inputs(); # Make sure we have all the data we need
475: ##
476: ## Determine filename
477: my $tmpdir = '/home/httpd/perl/tmp/';
478: my $filename = $ENV{'user.name'}.'_'.$ENV{'user.domain'}.
479: '_'.time.'_'.$$.$randnumber.'_plot.data';
480: ## Write the plot description to the file
481: &write_gnuplot_file($tmpdir,$filename,$target);
482: $filename = &Apache::lonnet::escape($filename);
483: ## return image tag for the plot
484: if ($target eq 'web') {
485: $result .= <<"ENDIMAGE";
486: <img src = "/cgi-bin/plot.gif?file=$filename&output=gif"
487: width = "$plot{'width'}"
488: height = "$plot{'height'}"
489: align = "$plot{'align'}"
490: alt = "image should be /cgi-bin/plot.gif?$filename" />
491: ENDIMAGE
492: } elsif ($target eq 'tex') {
493: &Apache::lonnet::ssi('cgi-bin/plot.gif?file=$filename'.
494: '&output=eps');
495: $result = "$filename.eps";
496: }
497: } elsif ($target eq 'edit') {
498: $result.=&Apache::edit::tag_end($target,$token);
499: }
500: return $result;
501: }
502:
503:
504: ##--------------------------------------------------------------- xtics
505: sub start_xtics {
506: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
507: my $result='';
508: if ($target eq 'web' || $target eq 'tex') {
509: &get_attributes(\%xtics,\%tic_defaults,$parstack,$safeeval,
510: $tagstack->[-1]);
511: } elsif ($target eq 'edit') {
512: $result .= &Apache::edit::tag_start($target,$token,'xtics');
513: $result .= &edit_attributes($target,$token,\%tic_defaults,
514: \@tic_edit_order);
515: } elsif ($target eq 'modified') {
516: my $constructtag=&Apache::edit::get_new_args
517: ($token,$parstack,$safeeval,keys(%tic_defaults));
518: if ($constructtag) {
519: $result = &Apache::edit::rebuild_tag($token);
520: }
521: }
522: return $result;
523: }
524:
525: sub end_xtics {
526: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
527: my $result = '';
528: if ($target eq 'web' || $target eq 'tex') {
529: } elsif ($target eq 'edit') {
530: $result.=&Apache::edit::tag_end($target,$token);
531: }
532: return $result;
533: }
534:
535: ##--------------------------------------------------------------- ytics
536: sub start_ytics {
537: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
538: my $result='';
539: if ($target eq 'web' || $target eq 'tex') {
540: &get_attributes(\%ytics,\%tic_defaults,$parstack,$safeeval,
541: $tagstack->[-1]);
542: } elsif ($target eq 'edit') {
543: $result .= &Apache::edit::tag_start($target,$token,'ytics');
544: $result .= &edit_attributes($target,$token,\%tic_defaults,
545: \@tic_edit_order);
546: } elsif ($target eq 'modified') {
547: my $constructtag=&Apache::edit::get_new_args
548: ($token,$parstack,$safeeval,keys(%tic_defaults));
549: if ($constructtag) {
550: $result = &Apache::edit::rebuild_tag($token);
551: }
552: }
553: return $result;
554: }
555:
556: sub end_ytics {
557: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
558: my $result = '';
559: if ($target eq 'web' || $target eq 'tex') {
560: } elsif ($target eq 'edit') {
561: $result.=&Apache::edit::tag_end($target,$token);
562: }
563: return $result;
564: }
565:
566:
567: ##----------------------------------------------------------------- key
568: sub start_key {
569: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
570: my $result='';
571: if ($target eq 'web' || $target eq 'tex') {
572: &get_attributes(\%key,\%key_defaults,$parstack,$safeeval,
573: $tagstack->[-1]);
574: } elsif ($target eq 'edit') {
575: $result .= &Apache::edit::tag_start($target,$token,'Plot Key');
576: $result .= &edit_attributes($target,$token,\%key_defaults);
577: } elsif ($target eq 'modified') {
578: my $constructtag=&Apache::edit::get_new_args
579: ($token,$parstack,$safeeval,keys(%key_defaults));
580: if ($constructtag) {
581: $result = &Apache::edit::rebuild_tag($token);
582: }
583: }
584: return $result;
585: }
586:
587: sub end_key {
588: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
589: my $result = '';
590: if ($target eq 'web' || $target eq 'tex') {
591: } elsif ($target eq 'edit') {
592: $result.=&Apache::edit::tag_end($target,$token);
593: }
594: return $result;
595: }
596:
597: ##------------------------------------------------------------------- title
598: sub start_title {
599: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
600: my $result='';
601: if ($target eq 'web' || $target eq 'tex') {
602: $title = &Apache::lonxml::get_all_text("/title",$$parser[-1]);
603: $title=&Apache::run::evaluate($title,$safeeval,$$parstack[-1]);
604: $title =~ s/\n/ /g;
605: if (length($title) > $max_str_len) {
606: $title = substr($title,0,$max_str_len);
607: }
608: } elsif ($target eq 'edit') {
609: $result.=&Apache::edit::tag_start($target,$token,'Plot Title');
610: my $text=&Apache::lonxml::get_all_text("/title",$$parser[-1]);
611: $result.=&Apache::edit::end_row().
612: &Apache::edit::start_spanning_row().
613: &Apache::edit::editline('',$text,'',60);
614: } elsif ($target eq 'modified') {
615: my $text=$$parser[-1]->get_text("/title");
616: $result.=&Apache::edit::rebuild_tag($token);
617: $result.=&Apache::edit::modifiedfield($token);
618: }
619: return $result;
620: }
621:
622: sub end_title {
623: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
624: my $result = '';
625: if ($target eq 'web' || $target eq 'tex') {
626: } elsif ($target eq 'edit') {
627: $result.=&Apache::edit::tag_end($target,$token);
628: }
629: return $result;
630: }
631: ##------------------------------------------------------------------- xlabel
632: sub start_xlabel {
633: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
634: my $result='';
635: if ($target eq 'web' || $target eq 'tex') {
636: $xlabel = &Apache::lonxml::get_all_text("/xlabel",$$parser[-1]);
637: $xlabel=&Apache::run::evaluate($xlabel,$safeeval,$$parstack[-1]);
638: $xlabel =~ s/\n/ /g;
639: if (length($xlabel) > $max_str_len) {
640: $xlabel = substr($xlabel,0,$max_str_len);
641: }
642: } elsif ($target eq 'edit') {
643: $result.=&Apache::edit::tag_start($target,$token,'Plot Xlabel');
644: my $text=&Apache::lonxml::get_all_text("/xlabel",$$parser[-1]);
645: $result.=&Apache::edit::end_row().
646: &Apache::edit::start_spanning_row().
647: &Apache::edit::editline('',$text,'',60);
648: } elsif ($target eq 'modified') {
649: my $text=$$parser[-1]->get_text("/xlabel");
650: $result.=&Apache::edit::rebuild_tag($token);
651: $result.=&Apache::edit::modifiedfield($token);
652: }
653: return $result;
654: }
655:
656: sub end_xlabel {
657: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
658: my $result = '';
659: if ($target eq 'web' || $target eq 'tex') {
660: } elsif ($target eq 'edit') {
661: $result.=&Apache::edit::tag_end($target,$token);
662: }
663: return $result;
664: }
665:
666: ##------------------------------------------------------------------- ylabel
667: sub start_ylabel {
668: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
669: my $result='';
670: if ($target eq 'web' || $target eq 'tex') {
671: $ylabel = &Apache::lonxml::get_all_text("/ylabel",$$parser[-1]);
672: $ylabel = &Apache::run::evaluate($ylabel,$safeeval,$$parstack[-1]);
673: $ylabel =~ s/\n/ /g;
674: if (length($ylabel) > $max_str_len) {
675: $ylabel = substr($ylabel,0,$max_str_len);
676: }
677: } elsif ($target eq 'edit') {
678: $result .= &Apache::edit::tag_start($target,$token,'Plot Ylabel');
679: my $text = &Apache::lonxml::get_all_text("/ylabel",$$parser[-1]);
680: $result .= &Apache::edit::end_row().
681: &Apache::edit::start_spanning_row().
682: &Apache::edit::editline('',$text,'',60);
683: } elsif ($target eq 'modified') {
684: my $text=$$parser[-1]->get_text("/ylabel");
685: $result.=&Apache::edit::rebuild_tag($token);
686: $result.=&Apache::edit::modifiedfield($token);
687: }
688: return $result;
689: }
690:
691: sub end_ylabel {
692: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
693: my $result = '';
694: if ($target eq 'web' || $target eq 'tex') {
695: } elsif ($target eq 'edit') {
696: $result.=&Apache::edit::tag_end($target,$token);
697: }
698: return $result;
699: }
700:
701: ##------------------------------------------------------------------- label
702: sub start_label {
703: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
704: my $result='';
705: if ($target eq 'web' || $target eq 'tex') {
706: my %label;
707: &get_attributes(\%label,\%label_defaults,$parstack,$safeeval,
708: $tagstack->[-1]);
709: my $text = &Apache::lonxml::get_all_text("/label",$$parser[-1]);
710: $text = &Apache::run::evaluate($text,$safeeval,$$parstack[-1]);
711: $text =~ s/\n/ /g;
712: $text = substr($text,0,$max_str_len) if (length($text) > $max_str_len);
713: $label{'text'} = $text;
714: push(@labels,\%label);
715: } elsif ($target eq 'edit') {
716: $result .= &Apache::edit::tag_start($target,$token,'Plot Label');
717: $result .= &edit_attributes($target,$token,\%label_defaults);
718: my $text = &Apache::lonxml::get_all_text("/label",$$parser[-1]);
719: $result .= &Apache::edit::end_row().
720: &Apache::edit::start_spanning_row().
721: &Apache::edit::editline('',$text,'',60);
722: } elsif ($target eq 'modified') {
723: &Apache::edit::get_new_args
724: ($token,$parstack,$safeeval,keys(%label_defaults));
725: $result.=&Apache::edit::rebuild_tag($token);
726: my $text=$$parser[-1]->get_text("/label");
727: $result.=&Apache::edit::modifiedfield($token);
728: }
729: return $result;
730: }
731:
732: sub end_label {
733: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
734: my $result = '';
735: if ($target eq 'web' || $target eq 'tex') {
736: } elsif ($target eq 'edit') {
737: $result.=&Apache::edit::tag_end($target,$token);
738: }
739: return $result;
740: }
741:
742: ##------------------------------------------------------------------- curve
743: sub start_curve {
744: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
745: my $result='';
746: &Apache::lonxml::register('Apache::lonplot',('function','data'));
747: push (@Apache::lonxml::namespace,'curve');
748: if ($target eq 'web' || $target eq 'tex') {
749: my %curve;
750: &get_attributes(\%curve,\%curve_defaults,$parstack,$safeeval,
751: $tagstack->[-1]);
752: push (@curves,\%curve);
753: } elsif ($target eq 'edit') {
754: $result .= &Apache::edit::tag_start($target,$token,'Curve');
755: $result .= &help_win($curve_help_text);
756: $result .= &edit_attributes($target,$token,\%curve_defaults,
757: \@curve_edit_order);
758: } elsif ($target eq 'modified') {
759: my $constructtag=&Apache::edit::get_new_args
760: ($token,$parstack,$safeeval,keys(%curve_defaults));
761: if ($constructtag) {
762: $result = &Apache::edit::rebuild_tag($token);
763: $result.= &Apache::edit::handle_insert();
764: }
765: }
766: return $result;
767: }
768:
769: sub end_curve {
770: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
771: my $result = '';
772: pop @Apache::lonxml::namespace;
773: &Apache::lonxml::deregister('Apache::lonplot',('function','data'));
774: if ($target eq 'web' || $target eq 'tex') {
775: } elsif ($target eq 'edit') {
776: $result.=&Apache::edit::tag_end($target,$token);
777: }
778: return $result;
779: }
780:
781: ##------------------------------------------------------------ curve function
782: sub start_function {
783: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
784: my $result='';
785: if ($target eq 'web' || $target eq 'tex') {
786: if (exists($curves[-1]->{'data'})) {
787: &Apache::lonxml::warning('Use of <function> precludes use of <data>. The <data> will be omitted in favor of the <function> declaration.');
788: delete $curves[-1]->{'data'} ;
789: }
790: my $function = &Apache::lonxml::get_all_text("/function",$$parser[-1]);
791: $function = &Apache::run::evaluate($function,$safeeval,$$parstack[-1]);
792: $curves[-1]->{'function'} = $function;
793: } elsif ($target eq 'edit') {
794: $result .= &Apache::edit::tag_start($target,$token,'Gnuplot compatible curve function');
795: my $text = &Apache::lonxml::get_all_text("/function",$$parser[-1]);
796: $result .= &Apache::edit::end_row().
797: &Apache::edit::start_spanning_row().
798: &Apache::edit::editline('',$text,'',60);
799: } elsif ($target eq 'modified') {
800: $result.=&Apache::edit::rebuild_tag($token);
801: my $text=$$parser[-1]->get_text("/function");
802: $result.=&Apache::edit::modifiedfield($token);
803: }
804: return $result;
805: }
806:
807: sub end_function {
808: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
809: my $result = '';
810: if ($target eq 'web' || $target eq 'tex') {
811: } elsif ($target eq 'edit') {
812: $result .= &Apache::edit::end_table();
813: }
814: return $result;
815: }
816:
817: ##------------------------------------------------------------ curve data
818: sub start_data {
819: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
820: my $result='';
821: if ($target eq 'web' || $target eq 'tex') {
822: if (exists($curves[-1]->{'function'})) {
823: &Apache::lonxml::warning('Use of <data> precludes use of .'.
824: '<function>. The <function> will be omitted in favor of '.
825: 'the <data> declaration.');
826: delete($curves[-1]->{'function'});
827: }
828: my $datatext = &Apache::lonxml::get_all_text("/data",$$parser[-1]);
829: $datatext=&Apache::run::evaluate($datatext,$safeeval,$$parstack[-1]);
830: # Deal with cases where we're given an array...
831: if ($datatext =~ /^\@/) {
832: $datatext = &Apache::run::run('return "'.$datatext.'"',
833: $safeeval,1);
834: }
835: $datatext =~ s/\s+/ /g;
836: # Need to do some error checking on the @data array -
837: # make sure it's all numbers and make sure each array
838: # is of the same length.
839: my @data;
840: if ($datatext =~ /,/) { # comma deliminated
841: @data = split /,/,$datatext;
842: } else { # Assume it's space seperated.
843: @data = split / /,$datatext;
844: }
845: for (my $i=0;$i<=$#data;$i++) {
846: # Check that it's non-empty
847: if (! defined($data[$i])) {
848: &Apache::lonxml::warning(
849: 'undefined <data> value. Replacing with '.
850: ' pi/e = 1.15572734979092');
851: $data[$i] = 1.15572734979092;
852: }
853: # Check that it's a number
854: if (! &$real_test($data[$i]) & ! &$int_test($data[$i])) {
855: &Apache::lonxml::warning(
856: 'Bad <data> value of '.$data[$i].' Replacing with '.
857: ' pi/e = 1.15572734979092');
858: $data[$i] = 1.15572734979092;
859: }
860: }
861: # complain if the number of data points is not the same as
862: # in previous sets of data.
863: if (($curves[-1]->{'data'}) && ($#data != $#{@{$curves[-1]->{'data'}->[0]}})){
864: &Apache::lonxml::warning
865: ('Number of data points is not consistent with previous '.
866: 'number of data points');
867: }
868: push @{$curves[-1]->{'data'}},\@data;
869: } elsif ($target eq 'edit') {
870: $result .= &Apache::edit::tag_start($target,$token,'Comma or space deliminated curve data');
871: my $text = &Apache::lonxml::get_all_text("/data",$$parser[-1]);
872: $result .= &Apache::edit::end_row().
873: &Apache::edit::start_spanning_row().
874: &Apache::edit::editline('',$text,'',60);
875: } elsif ($target eq 'modified') {
876: $result.=&Apache::edit::rebuild_tag($token);
877: my $text=$$parser[-1]->get_text("/data");
878: $result.=&Apache::edit::modifiedfield($token);
879: }
880: return $result;
881: }
882:
883: sub end_data {
884: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
885: my $result = '';
886: if ($target eq 'web' || $target eq 'tex') {
887: } elsif ($target eq 'edit') {
888: $result .= &Apache::edit::end_table();
889: }
890: return $result;
891: }
892:
893: ##------------------------------------------------------------------- axis
894: sub start_axis {
895: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
896: my $result='';
897: if ($target eq 'web' || $target eq 'tex') {
898: &get_attributes(\%axis,\%axis_defaults,$parstack,$safeeval,
899: $tagstack->[-1]);
900: } elsif ($target eq 'edit') {
901: $result .= &Apache::edit::tag_start($target,$token,'Plot Axes');
902: $result .= &edit_attributes($target,$token,\%axis_defaults);
903: } elsif ($target eq 'modified') {
904: my $constructtag=&Apache::edit::get_new_args
905: ($token,$parstack,$safeeval,keys(%axis_defaults));
906: if ($constructtag) {
907: $result = &Apache::edit::rebuild_tag($token);
908: }
909: }
910: return $result;
911: }
912:
913: sub end_axis {
914: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
915: my $result = '';
916: if ($target eq 'web' || $target eq 'tex') {
917: } elsif ($target eq 'edit') {
918: $result.=&Apache::edit::tag_end($target,$token);
919: } elsif ($target eq 'modified') {
920: }
921: return $result;
922: }
923:
924: ###################################################################
925: ## ##
926: ## Utility Functions ##
927: ## ##
928: ###################################################################
929:
930: ##----------------------------------------------------------- set_defaults
931: sub set_defaults {
932: my ($var,$defaults) = @_;
933: my $key;
934: foreach $key (keys(%$defaults)) {
935: $var->{$key} = $defaults->{$key}->{'default'};
936: }
937: }
938:
939: ##------------------------------------------------------------------- misc
940: sub get_attributes{
941: my ($values,$defaults,$parstack,$safeeval,$tag) = @_;
942: foreach my $attr (keys(%{$defaults})) {
943: $values->{$attr} =
944: &Apache::lonxml::get_param($attr,$parstack,$safeeval);
945: if ($values->{$attr} eq '' | !defined($values->{$attr})) {
946: $values->{$attr} = $defaults->{$attr}->{'default'};
947: next;
948: }
949: my $test = $defaults->{$attr}->{'test'};
950: if (! &$test($values->{$attr})) {
951: &Apache::lonxml::warning
952: ($tag.':'.$attr.': Bad value.'.'Replacing your value with : '
953: .$defaults->{$attr}->{'default'} );
954: $values->{$attr} = $defaults->{$attr}->{'default'};
955: }
956: }
957: return ;
958: }
959:
960: ##------------------------------------------------------- write_gnuplot_file
961: sub write_gnuplot_file {
962: my ($tmpdir,$filename,$target)= @_;
963: my $gnuplot_input = '';
964: my $curve;
965: # Collect all the colors
966: my @Colors;
967: push @Colors, $plot{'bgcolor'};
968: push @Colors, $plot{'fgcolor'};
969: push @Colors, (defined($axis{'color'})?$axis{'color'}:$plot{'fgcolor'});
970: foreach $curve (@curves) {
971: push @Colors, ($curve->{'color'} ne '' ?
972: $curve->{'color'} :
973: $plot{'fgcolor'} );
974: }
975: # set term
976: if ($target eq 'web') {
977: $gnuplot_input .= 'set term gif ';
978: $gnuplot_input .= 'transparent ' if ($plot{'transparent'} eq 'on');
979: $gnuplot_input .= $plot{'font'} . ' ';
980: $gnuplot_input .= 'size '.$plot{'width'}.','.$plot{'height'}.' ';
981: $gnuplot_input .= "@Colors\n";
982: # set output
983: $gnuplot_input .= "set output\n";
984: } elsif ($target eq 'tex') {
985: $gnuplot_input .= "set term postscript eps monochrome\n";
986: $gnuplot_input .= "set output \"$filename.eps\"\n";
987: }
988: # grid
989: $gnuplot_input .= 'set grid'.$/ if ($plot{'grid'} eq 'on');
990: # border
991: $gnuplot_input .= ($plot{'border'} eq 'on'?
992: 'set border'.$/ :
993: 'set noborder'.$/ ); # title, xlabel, ylabel
994: # titles
995: $gnuplot_input .= "set title \"$title\"\n" if (defined($title)) ;
996: $gnuplot_input .= "set xlabel \"$xlabel\"\n" if (defined($xlabel));
997: $gnuplot_input .= "set ylabel \"$ylabel\"\n" if (defined($ylabel));
998: # tics
999: if (%xtics) {
1000: $gnuplot_input .= "set xtics $xtics{'location'} ";
1001: $gnuplot_input .= ( $xtics{'mirror'} eq 'on'?"mirror ":"nomirror ");
1002: $gnuplot_input .= "$xtics{'start'}, ";
1003: $gnuplot_input .= "$xtics{'increment'}, ";
1004: $gnuplot_input .= "$xtics{'end'}\n";
1005: }
1006: if (%ytics) {
1007: $gnuplot_input .= "set ytics $ytics{'location'} ";
1008: $gnuplot_input .= ( $ytics{'mirror'} eq 'on'?"mirror ":"nomirror ");
1009: $gnuplot_input .= "$ytics{'start'}, ";
1010: $gnuplot_input .= "$ytics{'increment'}, ";
1011: $gnuplot_input .= "$ytics{'end'}\n";
1012: }
1013: # axis
1014: if (%axis) {
1015: $gnuplot_input .= "set xrange \[$axis{'xmin'}:$axis{'xmax'}\]\n";
1016: $gnuplot_input .= "set yrange \[$axis{'ymin'}:$axis{'ymax'}\]\n";
1017: }
1018: # Key
1019: if (%key) {
1020: $gnuplot_input .= 'set key '.$key{'pos'}.' ';
1021: if ($key{'title'} ne '') {
1022: $gnuplot_input .= 'title " '.$key{'title'}.'" ';
1023: }
1024: $gnuplot_input .= ($key{'box'} eq 'on' ? 'box ' : 'nobox ').$/;
1025: } else {
1026: $gnuplot_input .= 'set nokey'.$/;
1027: }
1028: # labels
1029: my $label;
1030: foreach $label (@labels) {
1031: $gnuplot_input .= 'set label "'.$label->{'text'}.'" at '.
1032: $label->{'xpos'}.','.$label->{'ypos'}.' '.$label->{'justify'}.$/ ;
1033: }
1034: # curves
1035: $gnuplot_input .= 'plot ';
1036: for (my $i = 0;$i<=$#curves;$i++) {
1037: $curve = $curves[$i];
1038: $gnuplot_input.= ', ' if ($i > 0);
1039: if (exists($curve->{'function'})) {
1040: $gnuplot_input.=
1041: $curve->{'function'}.' title "'.
1042: $curve->{'name'}.'" with '.
1043: $curve->{'linestyle'};
1044: #
1045: # gnuplot's term=gif driver does not handle linewidths :(
1046: # . ' linewidth '. $curve->{'linewidth'};
1047: #
1048: if (($curve->{'linestyle'} eq 'points') ||
1049: ($curve->{'linestyle'} eq 'linespoints') ||
1050: ($curve->{'linestyle'} eq 'errorbars') ||
1051: ($curve->{'linestyle'} eq 'xerrorbars') ||
1052: ($curve->{'linestyle'} eq 'yerrorbars') ||
1053: ($curve->{'linestyle'} eq 'xyerrorbars')) {
1054: $gnuplot_input.=' pointtype '.$curve->{'pointtype'};
1055: $gnuplot_input.=' pointsize '.$curve->{'pointsize'};
1056: }
1057: } elsif (exists($curve->{'data'})) {
1058: # Store data values in $datatext
1059: my $datatext = '';
1060: # get new filename
1061: my $datafilename = "$tmpdir/$filename.$i";
1062: my $fh=Apache::File->new(">$datafilename");
1063: # Compile data
1064: my @Data = @{$curve->{'data'}};
1065: my @Data0 = @{$Data[0]};
1066: for (my $i =0; $i<=$#Data0; $i++) {
1067: my $dataset;
1068: foreach $dataset (@Data) {
1069: $datatext .= $dataset->[$i] . ' ';
1070: }
1071: $datatext .= $/;
1072: }
1073: # write file
1074: print $fh $datatext;
1075: close ($fh);
1076: # generate gnuplot text
1077: $gnuplot_input.= '"'.$datafilename.'" title "'.
1078: $curve->{'name'}.'" with '.
1079: $curve->{'linestyle'};
1080: if (($curve->{'linestyle'} eq 'points') ||
1081: ($curve->{'linestyle'} eq 'linespoints') ||
1082: ($curve->{'linestyle'} eq 'errorbars') ||
1083: ($curve->{'linestyle'} eq 'xerrorbars') ||
1084: ($curve->{'linestyle'} eq 'yerrorbars') ||
1085: ($curve->{'linestyle'} eq 'xyerrorbars')) {
1086: $gnuplot_input.=' pointtype '.$curve->{'pointtype'};
1087: $gnuplot_input.=' pointsize '.$curve->{'pointsize'};
1088: }
1089: }
1090: }
1091: # Write the output to a file.
1092: my $fh=Apache::File->new(">$tmpdir$filename");
1093: print $fh $gnuplot_input;
1094: close($fh);
1095: # That's all folks.
1096: return ;
1097: }
1098:
1099: #---------------------------------------------- check_inputs
1100: sub check_inputs {
1101: ## Note: no inputs, no outputs - this acts only on global variables.
1102: ## Make sure we have all the input we need:
1103: if (! %plot) { &set_defaults(\%plot,\%gnuplot_defaults); }
1104: if (! %key ) {} # No key for this plot, thats okay
1105: # if (! %axis) { &set_defaults(\%axis,\%axis_defaults); }
1106: if (! defined($title )) {} # No title for this plot, thats okay
1107: if (! defined($xlabel)) {} # No xlabel for this plot, thats okay
1108: if (! defined($ylabel)) {} # No ylabel for this plot, thats okay
1109: if ($#labels < 0) { } # No labels for this plot, thats okay
1110: if ($#curves < 0) {
1111: &Apache::lonxml::warning("No curves specified for plot!!!!");
1112: return '';
1113: }
1114: my $curve;
1115: foreach $curve (@curves) {
1116: if (!defined($curve->{'function'})&&!defined($curve->{'data'})){
1117: &Apache::lonxml::warning("One of the curves specified did not contain any <data> or <function> declarations\n");
1118: return '';
1119: }
1120: }
1121: }
1122:
1123: #------------------------------------------------ make_edit
1124: sub edit_attributes {
1125: my ($target,$token,$defaults,$keys) = @_;
1126: my ($result,@keys);
1127: if ($keys && ref($keys) eq 'ARRAY') {
1128: @keys = @$keys;
1129: } else {
1130: @keys = sort(keys(%$defaults));
1131: }
1132: foreach my $attr (@keys) {
1133: # append a ' ' to the description if it doesn't have one already.
1134: my $description = $defaults->{$attr}->{'description'};
1135: $description .= ' ' if ($description !~ / $/);
1136: if ($defaults->{$attr}->{'edit_type'} eq 'entry') {
1137: $result .= &Apache::edit::text_arg
1138: ($description,$attr,$token,
1139: $defaults->{$attr}->{'size'});
1140: } elsif ($defaults->{$attr}->{'edit_type'} eq 'choice') {
1141: $result .= &Apache::edit::select_arg
1142: ($description,$attr,$defaults->{$attr}->{'choices'},$token);
1143: } elsif ($defaults->{$attr}->{'edit_type'} eq 'onoff') {
1144: $result .= &Apache::edit::select_arg
1145: ($description,$attr,['on','off'],$token);
1146: }
1147: $result .= '<br />';
1148: }
1149: return $result;
1150: }
1151:
1152:
1153: ###################################################################
1154: ## ##
1155: ## Insertion functions for editing plots ##
1156: ## ##
1157: ###################################################################
1158:
1159: sub insert_gnuplot {
1160: my $result = '';
1161: # plot attributes
1162: $result .= "\n<gnuplot ";
1163: foreach my $attr (keys(%gnuplot_defaults)) {
1164: $result .= "\n $attr=\"$gnuplot_defaults{$attr}->{'default'}\"";
1165: }
1166: $result .= ">";
1167: # Add the components (most are commented out for simplicity)
1168: # $result .= &insert_key();
1169: # $result .= &insert_axis();
1170: # $result .= &insert_title();
1171: # $result .= &insert_xlabel();
1172: # $result .= &insert_ylabel();
1173: $result .= &insert_curve();
1174: # close up the <gnuplot>
1175: $result .= "\n</gnuplot>";
1176: return $result;
1177: }
1178:
1179: sub insert_tics {
1180: my $result;
1181: $result .= &insert_xtics() . &insert_ytics;
1182: return $result;
1183: }
1184:
1185: sub insert_xtics {
1186: my $result;
1187: $result .= "\n <xtics ";
1188: foreach my $attr (keys(%tic_defaults)) {
1189: $result .= "\n $attr=\"$tic_defaults{$attr}->{'default'}\" ";
1190: }
1191: $result .= "/>";
1192: return $result;
1193: }
1194:
1195: sub insert_ytics {
1196: my $result;
1197: $result .= "\n <ytics ";
1198: foreach my $attr (keys(%tic_defaults)) {
1199: $result .= "\n $attr=\"$tic_defaults{$attr}->{'default'}\" ";
1200: }
1201: $result .= "/>";
1202: return $result;
1203: }
1204:
1205: sub insert_key {
1206: my $result;
1207: $result .= "\n <key ";
1208: foreach my $attr (keys(%key_defaults)) {
1209: $result .= "\n $attr=\"$key_defaults{$attr}->{'default'}\"";
1210: }
1211: $result .= " />";
1212: return $result;
1213: }
1214:
1215: sub insert_axis{
1216: my $result;
1217: $result .= "\n <axis ";
1218: foreach my $attr (keys(%axis_defaults)) {
1219: $result .= "\n $attr=\"$axis_defaults{$attr}->{'default'}\"";
1220: }
1221: $result .= " />";
1222: return $result;
1223: }
1224:
1225: sub insert_title { return "\n <title></title>"; }
1226: sub insert_xlabel { return "\n <xlabel></xlabel>"; }
1227: sub insert_ylabel { return "\n <ylabel></ylabel>"; }
1228:
1229: sub insert_label {
1230: my $result;
1231: $result .= "\n <label ";
1232: foreach my $attr (keys(%label_defaults)) {
1233: $result .= "\n $attr=\"".
1234: $label_defaults{$attr}->{'default'}."\"";
1235: }
1236: $result .= "></label>";
1237: return $result;
1238: }
1239:
1240: sub insert_curve {
1241: my $result;
1242: $result .= "\n <curve ";
1243: foreach my $attr (keys(%curve_defaults)) {
1244: $result .= "\n $attr=\"".
1245: $curve_defaults{$attr}->{'default'}."\"";
1246: }
1247: $result .= " >";
1248: $result .= &insert_data().&insert_data()."\n </curve>";
1249: }
1250:
1251: sub insert_function {
1252: my $result;
1253: $result .= "\n <function></function>";
1254: return $result;
1255: }
1256:
1257: sub insert_data {
1258: my $result;
1259: $result .= "\n <data></data>";
1260: return $result;
1261: }
1262:
1263: ##----------------------------------------------------------------------
1264: # Javascript functions to display help for tags
1265:
1266: sub make_javascript {
1267: my $helpwindowwidth = 400;
1268: my $helpwindowheight = 400;
1269: my $result = '';
1270: $result.=<<"ENDFUNCTION";
1271: <script language="JavaScript">
1272: function openWin(text)
1273: {
1274: newWin = open("", "new_W", "width=$helpwindowwidth,height=$helpwindowheight,resizable=1,scrollbars=1");
1275: newWin.document.open("text/html", "replace");
1276: newWin.document.writeln(text);
1277: newWin.document.writeln('<center><a href=\"javascript:window.close()\">close this window</a></center>');
1278: newWin.document.close();
1279: }
1280: </script>
1281: ENDFUNCTION
1282: return $result;
1283: }
1284:
1285: sub help_win {
1286: my ($helptext)=@_;
1287: $helptext =~ s/\n/ /g;
1288: $helptext =~ s/\'/\\\'/g;
1289: my $result = '';
1290: $result.=<<"ENDWIN";
1291: <table width="100%"><tr><td align="right">
1292: <a href="javascript:openWin('$helptext')">help</a>
1293: </td></tr></table><hr />
1294: ENDWIN
1295: return $result;
1296: }
1297: ##----------------------------------------------------------------------
1298: 1;
1299: __END__
1300:
1301:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>