Annotation of loncom/xml/lonplot.pm, revision 1.151
1.1 matthew 1: # The LearningOnline Network with CAPA
2: # Dynamic plot
3: #
1.151 ! raeburn 4: # $Id: lonplot.pm,v 1.150 2008/12/02 01:49:48 raeburn Exp $
1.1 matthew 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: #
1.35 matthew 28:
1.149 jms 29:
30:
31:
1.1 matthew 32: package Apache::lonplot;
1.10 matthew 33:
1.1 matthew 34: use strict;
1.89 matthew 35: use warnings FATAL=>'all';
36: no warnings 'uninitialized';
1.10 matthew 37: use Apache::File;
1.1 matthew 38: use Apache::response;
1.2 matthew 39: use Apache::lonxml;
1.20 matthew 40: use Apache::edit;
1.106 albertel 41: use Apache::lonnet;
1.113 www 42: use LONCAPA;
43:
1.10 matthew 44:
1.129 albertel 45: use vars qw/$weboutputformat $version/;
1.97 matthew 46:
1.109 foxr 47:
1.108 foxr 48:
1.33 harris41 49: BEGIN {
1.97 matthew 50: &Apache::lonxml::register('Apache::lonplot',('gnuplot'));
51: #
52: # Determine the version of GNUPLOT
53: $weboutputformat = 'gif';
1.129 albertel 54: my $versionstring = `gnuplot --version 2>/dev/null`;
55: ($version) = ($versionstring =~ /^gnuplot ([\d.]+)/);
56: if ($version >= 4) {
1.97 matthew 57: $weboutputformat = 'png';
58: }
1.108 foxr 59:
60: }
61:
1.1 matthew 62:
1.149 jms 63: =pod
64:
1.10 matthew 65: ##
66: ## Description of data structures:
67: ##
68: ## %plot %key %axis
69: ## --------------------------
70: ## height title color
71: ## width box xmin
72: ## bgcolor pos xmax
73: ## fgcolor ymin
74: ## transparent ymax
75: ## grid
76: ## border
77: ## font
1.19 matthew 78: ## align
1.10 matthew 79: ##
80: ## @labels: $labels[$i] = \%label
81: ## %label: text, xpos, ypos, justify
1.14 matthew 82: ##
1.10 matthew 83: ## @curves: $curves[$i] = \%curve
1.14 matthew 84: ## %curve: name, linestyle, ( function | data )
1.10 matthew 85: ##
86: ## $curves[$i]->{'data'} = [ [x1,x2,x3,x4],
87: ## [y1,y2,y3,y4] ]
88: ##
1.21 matthew 89:
90: ###################################################################
91: ## ##
92: ## Tests used in checking the validitity of input ##
93: ## ##
94: ###################################################################
1.29 matthew 95:
1.149 jms 96: =cut
97:
1.32 matthew 98: my $max_str_len = 50; # if a label, title, xlabel, or ylabel text
99: # is longer than this, it will be truncated.
100:
1.135 faziophi 101: my %linetypes =
102: (
103: solid => 1,
104: dashed => 0
105: );
106:
1.29 matthew 107: my %linestyles =
108: (
109: lines => 2, # Maybe this will be used in the future
110: linespoints => 2, # to check on whether or not they have
111: dots => 2, # supplied enough <data></data> fields
112: points => 2, # to use the given line style. But for
113: steps => 2, # now there are more important things
114: fsteps => 2, # for me to deal with.
115: histeps => 2,
1.34 matthew 116: errorbars => 3,
117: xerrorbars => [3,4],
118: yerrorbars => [3,4],
1.35 matthew 119: xyerrorbars => [4,6],
1.34 matthew 120: boxes => 3,
1.110 albertel 121: filledcurves => 2,
1.35 matthew 122: vector => 4
1.29 matthew 123: );
124:
1.11 matthew 125: my $int_test = sub {$_[0]=~s/\s+//g;$_[0]=~/^\d+$/};
1.19 matthew 126: my $real_test =
127: sub {$_[0]=~s/\s+//g;$_[0]=~/^[+-]?\d*\.?\d*([eE][+-]\d+)?$/};
1.62 matthew 128: my $pos_real_test =
129: sub {$_[0]=~s/\s+//g;$_[0]=~/^[+]?\d*\.?\d*([eE][+-]\d+)?$/};
1.79 matthew 130: my $color_test = sub {$_[0]=~s/\s+//g;$_[0]=~/^x[\da-fA-F]{6}$/};
1.1 matthew 131: my $onoff_test = sub {$_[0]=~/^(on|off)$/};
1.15 matthew 132: my $key_pos_test = sub {$_[0]=~/^(top|bottom|right|left|outside|below| )+$/};
1.119 albertel 133: my $sml_test = sub {$_[0]=~/^(\d+|small|medium|large)$/};
1.29 matthew 134: my $linestyle_test = sub {exists($linestyles{$_[0]})};
1.67 matthew 135: my $words_test = sub {$_[0]=~s/\s+/ /g;$_[0]=~/^([\w~!\@\#\$\%^&\*\(\)-=_\+\[\]\{\}:\;\'<>,\.\/\?\\]+ ?)+$/};
1.21 matthew 136:
137: ###################################################################
138: ## ##
139: ## Attribute metadata ##
140: ## ##
141: ###################################################################
1.47 matthew 142: my @gnuplot_edit_order =
1.123 albertel 143: qw/alttag bgcolor fgcolor height width texwidth fontface font texfont
144: transparent grid samples
145: border align plotcolor plottype gridtype lmargin rmargin
1.115 albertel 146: tmargin bmargin major_ticscale minor_ticscale boxwidth gridlayer fillstyle
1.110 albertel 147: pattern solid/;
1.101 matthew 148:
1.105 matthew 149: my $margin_choices = ['default',0..20];
1.48 matthew 150:
1.47 matthew 151: my %gnuplot_defaults =
1.1 matthew 152: (
1.64 matthew 153: alttag => {
154: default => 'dynamically generated plot',
155: test => $words_test,
1.120 albertel 156: description => 'Brief description of the plot',
1.64 matthew 157: edit_type => 'entry',
158: size => '40'
159: },
1.20 matthew 160: height => {
1.65 matthew 161: default => 300,
1.20 matthew 162: test => $int_test,
1.120 albertel 163: description => 'Height of image (pixels)',
1.38 matthew 164: edit_type => 'entry',
165: size => '10'
1.20 matthew 166: },
167: width => {
1.65 matthew 168: default => 400,
1.20 matthew 169: test => $int_test,
1.120 albertel 170: description => 'Width of image (pixels)',
1.38 matthew 171: edit_type => 'entry',
172: size => '10'
1.20 matthew 173: },
174: bgcolor => {
175: default => 'xffffff',
176: test => $color_test,
1.120 albertel 177: description => 'Background color of image (xffffff)',
1.38 matthew 178: edit_type => 'entry',
179: size => '10'
1.20 matthew 180: },
181: fgcolor => {
182: default => 'x000000',
183: test => $color_test,
1.120 albertel 184: description => 'Foreground color of image (x000000)',
1.38 matthew 185: edit_type => 'entry',
186: size => '10'
1.20 matthew 187: },
188: transparent => {
189: default => 'off',
190: test => $onoff_test,
1.34 matthew 191: description => 'Transparent image',
1.45 matthew 192: edit_type => 'onoff'
1.20 matthew 193: },
194: grid => {
1.65 matthew 195: default => 'on',
1.20 matthew 196: test => $onoff_test,
1.34 matthew 197: description => 'Display grid',
1.45 matthew 198: edit_type => 'onoff'
1.20 matthew 199: },
1.110 albertel 200: gridlayer => {
201: default => 'off',
202: test => $onoff_test,
203: description => 'Display grid front layer over filled boxes or filled curves',
204: edit_type => 'onoff'
205: },
206: box_border => {
207: default => 'noborder',
208: test => sub {$_[0]=~/^(noborder|border)$/},
209: description => 'Draw border for boxes',
210: edit_type => 'choice',
211: choices => ['border','noborder']
212: },
1.20 matthew 213: border => {
214: default => 'on',
215: test => $onoff_test,
1.34 matthew 216: description => 'Draw border around plot',
1.45 matthew 217: edit_type => 'onoff'
1.20 matthew 218: },
219: font => {
1.119 albertel 220: default => '9',
1.20 matthew 221: test => $sml_test,
1.125 albertel 222: description => 'Font size to use in web output (pts)',
1.20 matthew 223: edit_type => 'choice',
1.126 albertel 224: choices => [['5','5 (small)'],'6','7','8',['9','9 (medium)'],'10',['11','11 (large)'],'12','15']
1.20 matthew 225: },
1.120 albertel 226: fontface => {
227: default => 'sans-serif',
228: test => sub {$_[0]=~/^(sans-serif|serif|classic)$/},
229: description => 'Type of font to use',
230: edit_type => 'choice',
231: choices => ['sans-serif','serif', 'classic']
232: },
1.110 albertel 233: samples => {
1.77 matthew 234: default => '100',
235: test => $int_test,
236: description => 'Number of samples for non-data plots',
237: edit_type => 'choice',
238: choices => ['100','200','500','1000','2000','5000']
239: },
1.20 matthew 240: align => {
1.116 albertel 241: default => 'middle',
242: test => sub {$_[0]=~/^(left|right|middle|center)$/},
1.120 albertel 243: description => 'Alignment for image in HTML',
1.20 matthew 244: edit_type => 'choice',
1.116 albertel 245: choices => ['left','right','middle']
1.82 matthew 246: },
247: texwidth => {
248: default => '93',
249: test => $int_test,
250: description => 'Width of plot when printed (mm)',
251: edit_type => 'entry',
252: size => '5'
253: },
1.110 albertel 254: texfont => {
1.92 matthew 255: default => '22',
256: test => $int_test,
257: description => 'Font size to use in TeX output (pts):',
258: edit_type => 'choice',
1.96 matthew 259: choices => [qw/8 10 12 14 16 18 20 22 24 26 28 30 32 34 36/],
1.92 matthew 260: },
1.110 albertel 261: plotcolor => {
1.105 matthew 262: default => 'monochrome',
263: test => sub {$_[0]=~/^(monochrome|color|colour)$/},
264: description => 'Color setting for printing:',
265: edit_type => 'choice',
266: choices => [qw/monochrome color colour/],
267: },
1.110 albertel 268: pattern => {
269: default => '',
270: test => $int_test,
1.120 albertel 271: description => 'Pattern value for boxes:',
1.110 albertel 272: edit_type => 'choice',
273: choices => [0,1,2,3,4,5,6]
274: },
275: solid => {
276: default => 0,
277: test => $real_test,
278: description => 'The density of fill style for boxes',
279: edit_type => 'entry',
280: size => '5'
281: },
282: fillstyle => {
283: default => 'empty',
284: test => sub {$_[0]=~/^(empty|solid|pattern)$/},
285: description => 'Filled style for boxes:',
286: edit_type => 'choice',
287: choices => ['empty','solid','pattern']
288: },
289: plottype => {
1.87 matthew 290: default => 'Cartesian',
291: test => sub {$_[0]=~/^(Polar|Cartesian)$/},
292: description => 'Plot type:',
293: edit_type => 'choice',
1.94 matthew 294: choices => ['Cartesian','Polar']
1.87 matthew 295: },
1.115 albertel 296: gridtype => {
297: default => 'Cartesian',
1.118 albertel 298: test => sub {$_[0]=~/^(Polar|Cartesian|Linear-Log|Log-Linear|Log-Log)$/},
1.115 albertel 299: description => 'Grid type:',
300: edit_type => 'choice',
1.118 albertel 301: choices => ['Cartesian','Polar','Linear-Log','Log-Linear','Log-Log']
1.115 albertel 302: },
1.110 albertel 303: lmargin => {
1.101 matthew 304: default => 'default',
305: test => sub {$_[0]=~/^(default|\d+)$/},
306: description => 'Left margin width (pts):',
307: edit_type => 'choice',
308: choices => $margin_choices,
309: },
1.110 albertel 310: rmargin => {
1.101 matthew 311: default => 'default',
312: test => sub {$_[0]=~/^(default|\d+)$/},
313: description => 'Right margin width (pts):',
314: edit_type => 'choice',
315: choices => $margin_choices,
316: },
1.110 albertel 317: tmargin => {
1.101 matthew 318: default => 'default',
319: test => sub {$_[0]=~/^(default|\d+)$/},
320: description => 'Top margin width (pts):',
321: edit_type => 'choice',
322: choices => $margin_choices,
323: },
1.110 albertel 324: bmargin => {
1.101 matthew 325: default => 'default',
326: test => sub {$_[0]=~/^(default|\d+)$/},
1.104 www 327: description => 'Bottom margin width (pts):',
1.101 matthew 328: edit_type => 'choice',
329: choices => $margin_choices,
330: },
1.110 albertel 331: boxwidth => {
332: default => '',
333: test => $real_test,
1.120 albertel 334: description => 'Width of boxes, default is auto',
1.110 albertel 335: edit_type => 'entry',
336: size => '5'
337: },
1.101 matthew 338: major_ticscale => {
339: default => '1',
340: test => $real_test,
341: description => 'Size of major tic marks (plot coordinates)',
342: edit_type => 'entry',
343: size => '5'
344: },
345: minor_ticscale => {
346: default => '0.5',
347: test => $real_test,
348: description => 'Size of minor tic mark (plot coordinates)',
349: edit_type => 'entry',
350: size => '5'
351: },
1.1 matthew 352: );
353:
354: my %key_defaults =
355: (
1.20 matthew 356: title => {
357: default => '',
358: test => $words_test,
359: description => 'Title of key',
1.38 matthew 360: edit_type => 'entry',
361: size => '40'
1.20 matthew 362: },
363: box => {
364: default => 'off',
365: test => $onoff_test,
366: description => 'Draw a box around the key?',
1.45 matthew 367: edit_type => 'onoff'
1.20 matthew 368: },
369: pos => {
370: default => 'top right',
371: test => $key_pos_test,
1.120 albertel 372: description => 'Position of the key on the plot',
1.20 matthew 373: edit_type => 'choice',
374: choices => ['top left','top right','bottom left','bottom right',
375: 'outside','below']
376: }
1.1 matthew 377: );
378:
379: my %label_defaults =
380: (
1.20 matthew 381: xpos => {
382: default => 0,
383: test => $real_test,
1.120 albertel 384: description => 'X position of label (graph coordinates)',
1.38 matthew 385: edit_type => 'entry',
386: size => '10'
1.20 matthew 387: },
388: ypos => {
389: default => 0,
390: test => $real_test,
1.120 albertel 391: description => 'Y position of label (graph coordinates)',
1.38 matthew 392: edit_type => 'entry',
393: size => '10'
1.20 matthew 394: },
395: justify => {
396: default => 'left',
397: test => sub {$_[0]=~/^(left|right|center)$/},
398: description => 'justification of the label text on the plot',
399: edit_type => 'choice',
400: choices => ['left','right','center']
1.134 raeburn 401: },
402: rotate => {
403: default => 0,
404: test => $real_test,
405: description => 'Rotation of label (degrees)',
406: edit_type => 'entry',
407: size => '10',
1.20 matthew 408: }
1.1 matthew 409: );
410:
1.89 matthew 411: my @tic_edit_order = ('location','mirror','start','increment','end',
412: 'minorfreq');
1.45 matthew 413: my %tic_defaults =
414: (
415: location => {
416: default => 'border',
417: test => sub {$_[0]=~/^(border|axis)$/},
1.90 matthew 418: description => 'Location of major tic marks',
1.45 matthew 419: edit_type => 'choice',
420: choices => ['border','axis']
421: },
422: mirror => {
423: default => 'on',
424: test => $onoff_test,
1.120 albertel 425: description => 'Mirror tics on opposite axis?',
1.45 matthew 426: edit_type => 'onoff'
427: },
428: start => {
429: default => '-10.0',
430: test => $real_test,
1.90 matthew 431: description => 'Start major tics at',
1.45 matthew 432: edit_type => 'entry',
433: size => '10'
434: },
435: increment => {
436: default => '1.0',
437: test => $real_test,
1.90 matthew 438: description => 'Place a major tic every',
1.45 matthew 439: edit_type => 'entry',
440: size => '10'
441: },
442: end => {
443: default => ' 10.0',
444: test => $real_test,
1.90 matthew 445: description => 'Stop major tics at ',
1.45 matthew 446: edit_type => 'entry',
447: size => '10'
448: },
1.89 matthew 449: minorfreq => {
450: default => '0',
451: test => $int_test,
1.98 matthew 452: description => 'Number of minor tics per major tic mark',
1.89 matthew 453: edit_type => 'entry',
454: size => '10'
455: },
1.45 matthew 456: );
457:
1.132 albertel 458: my @axis_edit_order = ('color','xmin','xmax','ymin','ymax','xformat', 'yformat');
1.1 matthew 459: my %axis_defaults =
460: (
1.28 matthew 461: color => {
1.20 matthew 462: default => 'x000000',
463: test => $color_test,
1.120 albertel 464: description => 'Color of grid lines (x000000)',
1.38 matthew 465: edit_type => 'entry',
466: size => '10'
1.20 matthew 467: },
468: xmin => {
469: default => '-10.0',
470: test => $real_test,
1.120 albertel 471: description => 'Minimum x-value shown in plot',
1.38 matthew 472: edit_type => 'entry',
473: size => '10'
1.20 matthew 474: },
475: xmax => {
476: default => ' 10.0',
477: test => $real_test,
1.120 albertel 478: description => 'Maximum x-value shown in plot',
1.38 matthew 479: edit_type => 'entry',
480: size => '10'
1.20 matthew 481: },
482: ymin => {
483: default => '-10.0',
484: test => $real_test,
1.120 albertel 485: description => 'Minimum y-value shown in plot',
1.38 matthew 486: edit_type => 'entry',
487: size => '10'
1.20 matthew 488: },
489: ymax => {
490: default => ' 10.0',
491: test => $real_test,
1.120 albertel 492: description => 'Maximum y-value shown in plot',
1.38 matthew 493: edit_type => 'entry',
494: size => '10'
1.132 albertel 495: },
496: xformat => {
497: default => 'on',
498: test => sub {$_[0]=~/^(on|off|\d+(f|F|e|E))$/},
499: description => 'X-axis number formatting',
500: edit_type => 'choice',
501: choices => ['on', 'off', '2e', '2f'],
502: },
503: yformat => {
504: default => 'on',
505: test => sub {$_[0]=~/^(on|off|\d+(f|F|e|E))$/},
1.151 ! raeburn 506: description => 'Y-axis number formatting',
1.132 albertel 507: edit_type => 'choice',
508: choices => ['on', 'off', '2e', '2f'],
509: },
510:
1.1 matthew 511: );
512:
1.135 faziophi 513: my @curve_edit_order = ('color','name','linestyle','linewidth','linetype','pointtype','pointsize','limit');
1.60 matthew 514:
1.1 matthew 515: my %curve_defaults =
516: (
1.20 matthew 517: color => {
518: default => 'x000000',
519: test => $color_test,
1.120 albertel 520: description => 'Color of curve (x000000)',
1.38 matthew 521: edit_type => 'entry',
522: size => '10'
1.20 matthew 523: },
524: name => {
525: default => '',
526: test => $words_test,
1.120 albertel 527: description => 'Name of curve to appear in key',
1.38 matthew 528: edit_type => 'entry',
529: size => '20'
1.20 matthew 530: },
531: linestyle => {
532: default => 'lines',
533: test => $linestyle_test,
1.135 faziophi 534: description => 'Plot with:',
1.20 matthew 535: edit_type => 'choice',
1.38 matthew 536: choices => [keys(%linestyles)]
1.60 matthew 537: },
1.119 albertel 538: linewidth => {
1.130 albertel 539: default => 1,
1.119 albertel 540: test => $int_test,
1.135 faziophi 541: description => 'Line width (may not apply to all plot styles)',
1.119 albertel 542: edit_type => 'choice',
543: choices => [1,2,3,4,5,6,7,8,9,10]
544: },
1.135 faziophi 545: linetype => {
546: default => 'solid',
547: test => sub {$_[0]=~/^(solid|dashed)$/},
548: description => 'Line type (may not apply to all plot styles)',
549: edit_type => 'choice',
550: choices => ['solid', 'dashed']
551: },
1.60 matthew 552: pointsize => {
553: default => 1,
1.62 matthew 554: test => $pos_real_test,
1.135 faziophi 555: description => 'Point size (may not apply to all plot styles)',
1.62 matthew 556: edit_type => 'entry',
557: size => '5'
558: },
559: pointtype => {
560: default => 1,
1.60 matthew 561: test => $int_test,
1.135 faziophi 562: description => 'Point type (may not apply to all plot styles)',
1.60 matthew 563: edit_type => 'choice',
1.62 matthew 564: choices => [0,1,2,3,4,5,6]
1.110 albertel 565: },
566: limit => {
567: default => 'closed',
1.135 faziophi 568: test => sub {$_[0]=~/^(above|below|closed|x1|x2|y1|y2)$/},
1.120 albertel 569: description => 'Point to fill -- for filledcurves',
1.110 albertel 570: edit_type => 'choice',
1.135 faziophi 571: choices => ['above', 'below', 'closed','x1','x2','y1','y2']
1.110 albertel 572: },
1.1 matthew 573: );
574:
1.21 matthew 575: ###################################################################
576: ## ##
577: ## parsing and edit rendering ##
578: ## ##
579: ###################################################################
1.107 foxr 580:
581: undef %Apache::lonplot::plot;
582: my (%key,%axis,$title,$xlabel,$ylabel,@labels,@curves,%xtics,%ytics);
1.1 matthew 583:
1.47 matthew 584: sub start_gnuplot {
1.107 foxr 585: undef(%Apache::lonplot::plot); undef(%key); undef(%axis);
1.89 matthew 586: undef($title); undef($xlabel); undef($ylabel);
587: undef(@labels); undef(@curves);
588: undef(%xtics); undef(%ytics);
1.6 matthew 589: #
1.1 matthew 590: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
591: my $result='';
1.25 matthew 592: &Apache::lonxml::register('Apache::lonplot',
1.45 matthew 593: ('title','xlabel','ylabel','key','axis','label','curve',
594: 'xtics','ytics'));
1.29 matthew 595: push (@Apache::lonxml::namespace,'lonplot');
1.51 matthew 596: if ($target eq 'web' || $target eq 'tex') {
1.107 foxr 597: &get_attributes(\%Apache::lonplot::plot,\%gnuplot_defaults,$parstack,$safeeval,
1.17 matthew 598: $tagstack->[-1]);
1.20 matthew 599: } elsif ($target eq 'edit') {
1.47 matthew 600: $result .= &Apache::edit::tag_start($target,$token,'GnuPlot');
601: $result .= &edit_attributes($target,$token,\%gnuplot_defaults,
1.116 albertel 602: \@gnuplot_edit_order)
603: .&Apache::edit::end_row()
604: .&Apache::edit::start_spanning_row();
1.20 matthew 605: } elsif ($target eq 'modified') {
606: my $constructtag=&Apache::edit::get_new_args
1.47 matthew 607: ($token,$parstack,$safeeval,keys(%gnuplot_defaults));
1.20 matthew 608: if ($constructtag) {
609: $result = &Apache::edit::rebuild_tag($token);
610: }
1.4 matthew 611: }
1.21 matthew 612: return $result;
1.1 matthew 613: }
614:
1.47 matthew 615: sub end_gnuplot {
1.1 matthew 616: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
617: pop @Apache::lonxml::namespace;
1.4 matthew 618: &Apache::lonxml::deregister('Apache::lonplot',
619: ('title','xlabel','ylabel','key','axis','label','curve'));
620: my $result = '';
1.56 albertel 621: my $randnumber;
622: # need to call rand everytime start_script would evaluate, as the
623: # safe space rand number generator and the global rand generator
1.95 www 624: # are not separate
1.56 albertel 625: if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
626: $target eq 'answer') {
627: $randnumber=int(rand(1000));
628: }
1.51 matthew 629: if ($target eq 'web' || $target eq 'tex') {
1.21 matthew 630: &check_inputs(); # Make sure we have all the data we need
1.13 matthew 631: ##
632: ## Determine filename
1.4 matthew 633: my $tmpdir = '/home/httpd/perl/tmp/';
1.106 albertel 634: my $filename = $env{'user.name'}.'_'.$env{'user.domain'}.
1.69 matthew 635: '_'.time.'_'.$$.$randnumber.'_plot';
1.4 matthew 636: ## Write the plot description to the file
1.51 matthew 637: &write_gnuplot_file($tmpdir,$filename,$target);
1.113 www 638: $filename = &escape($filename);
1.4 matthew 639: ## return image tag for the plot
1.51 matthew 640: if ($target eq 'web') {
641: $result .= <<"ENDIMAGE";
1.114 albertel 642: <img src = "/cgi-bin/plot.$weboutputformat?file=$filename.data"
1.107 foxr 643: width = "$Apache::lonplot::plot{'width'}"
644: height = "$Apache::lonplot::plot{'height'}"
645: align = "$Apache::lonplot::plot{'align'}"
646: alt = "$Apache::lonplot::plot{'alttag'}" />
1.12 matthew 647: ENDIMAGE
1.51 matthew 648: } elsif ($target eq 'tex') {
1.107 foxr 649: &Apache::lonxml::debug(" gnuplot wid = $Apache::lonplot::plot{'width'}");
650: &Apache::lonxml::debug(" gnuplot ht = $Apache::lonplot::plot{'height'}");
1.91 albertel 651: #might be inside the safe space, register the URL for later
652: &Apache::lonxml::register_ssi("/cgi-bin/plot.gif?file=$filename.data&output=eps");
1.111 albertel 653: $result = "%DYNAMICIMAGE:$Apache::lonplot::plot{'width'}:$Apache::lonplot::plot{'height'}:$Apache::lonplot::plot{'texwidth'}\n";
1.109 foxr 654: $result .= '\graphicspath{{/home/httpd/perl/tmp/}}'."\n";
1.113 www 655: $result .= '\includegraphics[width='.$Apache::lonplot::plot{'texwidth'}.' mm]{'.&unescape($filename).'.eps}';
1.51 matthew 656: }
1.20 matthew 657: } elsif ($target eq 'edit') {
1.21 matthew 658: $result.=&Apache::edit::tag_end($target,$token);
1.4 matthew 659: }
1.1 matthew 660: return $result;
661: }
1.2 matthew 662:
1.45 matthew 663:
664: ##--------------------------------------------------------------- xtics
665: sub start_xtics {
666: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
667: my $result='';
1.51 matthew 668: if ($target eq 'web' || $target eq 'tex') {
1.45 matthew 669: &get_attributes(\%xtics,\%tic_defaults,$parstack,$safeeval,
670: $tagstack->[-1]);
671: } elsif ($target eq 'edit') {
672: $result .= &Apache::edit::tag_start($target,$token,'xtics');
673: $result .= &edit_attributes($target,$token,\%tic_defaults,
674: \@tic_edit_order);
675: } elsif ($target eq 'modified') {
676: my $constructtag=&Apache::edit::get_new_args
677: ($token,$parstack,$safeeval,keys(%tic_defaults));
678: if ($constructtag) {
679: $result = &Apache::edit::rebuild_tag($token);
680: }
681: }
682: return $result;
683: }
684:
685: sub end_xtics {
686: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
687: my $result = '';
1.51 matthew 688: if ($target eq 'web' || $target eq 'tex') {
1.45 matthew 689: } elsif ($target eq 'edit') {
690: $result.=&Apache::edit::tag_end($target,$token);
691: }
692: return $result;
693: }
694:
695: ##--------------------------------------------------------------- ytics
696: sub start_ytics {
697: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
698: my $result='';
1.51 matthew 699: if ($target eq 'web' || $target eq 'tex') {
1.45 matthew 700: &get_attributes(\%ytics,\%tic_defaults,$parstack,$safeeval,
701: $tagstack->[-1]);
702: } elsif ($target eq 'edit') {
703: $result .= &Apache::edit::tag_start($target,$token,'ytics');
704: $result .= &edit_attributes($target,$token,\%tic_defaults,
705: \@tic_edit_order);
706: } elsif ($target eq 'modified') {
707: my $constructtag=&Apache::edit::get_new_args
708: ($token,$parstack,$safeeval,keys(%tic_defaults));
709: if ($constructtag) {
710: $result = &Apache::edit::rebuild_tag($token);
711: }
712: }
713: return $result;
714: }
715:
716: sub end_ytics {
717: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
718: my $result = '';
1.51 matthew 719: if ($target eq 'web' || $target eq 'tex') {
1.45 matthew 720: } elsif ($target eq 'edit') {
721: $result.=&Apache::edit::tag_end($target,$token);
722: }
723: return $result;
724: }
725:
1.119 albertel 726: ##-----------------------------------------------------------------font
1.120 albertel 727: my %font_properties =
728: (
729: 'classic' => {
730: face => 'classic',
731: file => 'DejaVuSansMono-Bold',
732: printname => 'Helvetica',
1.121 albertel 733: tex_no_file => 1,
1.120 albertel 734: },
735: 'sans-serif' => {
736: face => 'sans-serif',
737: file => 'DejaVuSans',
738: printname => 'DejaVuSans',
739: },
740: 'serif' => {
741: face => 'serif',
742: file => 'DejaVuSerif',
743: printname => 'DejaVuSerif',
744: },
745: );
746:
1.119 albertel 747: sub get_font {
1.124 albertel 748: my ($target) = @_;
1.120 albertel 749: my ($size, $selected_font);
750:
1.119 albertel 751: if ( $Apache::lonplot::plot{'font'} =~ /^(small|medium|large)/) {
1.120 albertel 752: $selected_font = $font_properties{'classic'};
1.119 albertel 753: if ( $Apache::lonplot::plot{'font'} eq 'small') {
754: $size = '5';
755: } elsif ( $Apache::lonplot::plot{'font'} eq 'medium') {
756: $size = '9';
757: } elsif ( $Apache::lonplot::plot{'font'} eq 'large') {
1.126 albertel 758: $size = '11';
1.119 albertel 759: } else {
760: $size = '9';
761: }
762: } else {
1.122 albertel 763: $size = $Apache::lonplot::plot{'font'};
1.120 albertel 764: $selected_font = $font_properties{$Apache::lonplot::plot{'fontface'}};
1.119 albertel 765: }
1.124 albertel 766: if ($target eq 'tex' && defined($Apache::lonplot::plot{'texfont'})) {
1.146 foxr 767: # $selected_font = $font_properties{'classic'};
1.124 albertel 768: $size = $Apache::lonplot::plot{'texfont'};
769: }
1.120 albertel 770: return ($size, $selected_font);
1.119 albertel 771: }
1.45 matthew 772:
1.1 matthew 773: ##----------------------------------------------------------------- key
774: sub start_key {
775: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
776: my $result='';
1.51 matthew 777: if ($target eq 'web' || $target eq 'tex') {
1.17 matthew 778: &get_attributes(\%key,\%key_defaults,$parstack,$safeeval,
1.11 matthew 779: $tagstack->[-1]);
1.20 matthew 780: } elsif ($target eq 'edit') {
1.25 matthew 781: $result .= &Apache::edit::tag_start($target,$token,'Plot Key');
1.21 matthew 782: $result .= &edit_attributes($target,$token,\%key_defaults);
1.20 matthew 783: } elsif ($target eq 'modified') {
784: my $constructtag=&Apache::edit::get_new_args
1.24 matthew 785: ($token,$parstack,$safeeval,keys(%key_defaults));
1.20 matthew 786: if ($constructtag) {
787: $result = &Apache::edit::rebuild_tag($token);
788: }
1.4 matthew 789: }
1.1 matthew 790: return $result;
791: }
792:
793: sub end_key {
794: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
795: my $result = '';
1.51 matthew 796: if ($target eq 'web' || $target eq 'tex') {
1.20 matthew 797: } elsif ($target eq 'edit') {
1.21 matthew 798: $result.=&Apache::edit::tag_end($target,$token);
1.4 matthew 799: }
1.1 matthew 800: return $result;
801: }
1.21 matthew 802:
1.128 albertel 803: sub parse_label {
804: my ($target,$text) = @_;
805: my $parser=HTML::LCParser->new(\$text);
806: my $result;
807: while (my $token=$parser->get_token) {
808: if ($token->[0] eq 'S') {
809: if ($token->[1] eq 'sub') {
810: $result .= '_{';
811: } elsif ($token->[1] eq 'sup') {
812: $result .= '^{';
813: } else {
814: $result .= $token->[4];
815: }
816: } elsif ($token->[0] eq 'E') {
817: if ($token->[1] eq 'sub'
818: || $token->[1] eq 'sup') {
819: $result .= '}';
820: } else {
821: $result .= $token->[2];
822: }
823: } elsif ($token->[0] eq 'T') {
824: $result .= &replace_entities($target,$token->[1]);
825: }
826: }
827: return $result;
828: }
829:
1.143 foxr 830: #
831: # Note that there are severe restrictions on font selection in the
832: # ps driver now. later in life Gnuplot is supposed to support
833: # utf-8 fonts in the posts script driver. When this happens,
834: # the tex entries with comments that include the word <FIX>
835: # should be changed to print the correct glyphs rather than some
836: # approximation or fallback of what is intended.
1.128 albertel 837:
838: my %lookup =
1.137 foxr 839: ( # Greek alphabet:
1.139 foxr 840:
841: '(Alpha|#913)' => {'tex' => '{/Symbol A}', 'web' => "\x{391}"},
842: '(Beta|#914)' => {'tex' => '{/Symbol B}', 'web' => "\x{392}"},
843: '(Chi|#935)' => {'tex' => '{/Symbol C}', 'web' => "\x{3A7}"},
844: '(Delta|#916)' => {'tex' => '{/Symbol D}', 'web' => "\x{394}"},
845: '(Epsilon|#917)' => {'tex' => '{/Symbol E}', 'web' => "\x{395}"},
846: '(Phi|#934)' => {'tex' => '{/Symbol F}', 'web' => "\x{3A6}"},
847: '(Gamma|#915)' => {'tex' => '{/Symbol G}', 'web' => "\x{393}"},
848: '(Eta|#919)' => {'tex' => '{/Symbol H}', 'web' => "\x{397}"},
849: '(Iota|#921)' => {'tex' => '{/Symbol I}', 'web' => "\x{399}"},
850: '(Kappa|#922)' => {'tex' => '{/Symbol K}', 'web' => "\x{39A}"},
851: '(Lambda|#923)' => {'tex' => '{/Symbol L}', 'web' => "\x{39B}"},
852: '(Mu|#924)' => {'tex' => '{/Symbol M}', 'web' => "\x{39C}"},
853: '(Nu|#925)' => {'tex' => '{/Symbol N}', 'web' => "\x{39D}"},
854: '(Omicron|#927)' => {'tex' => '{/Symbol O}', 'web' => "\x{39F}"},
855: '(Pi|#928)' => {'tex' => '{/Symbol P}', 'web' => "\x{3A0}"},
856: '(Theta|#920)' => {'tex' => '{/Symbol Q}', 'web' => "\x{398}"},
857: '(Rho|#929)' => {'tex' => '{/Symbol R}', 'web' => "\x{3A1}"},
858: '(Sigma|#931)' => {'tex' => '{/Symbol S}', 'web' => "\x{3A3}"},
859: '(Tau|#932)' => {'tex' => '{/Symbol T}', 'web' => "\x{3A4}"},
860: '(Upsilon|#933)' => {'tex' => '{/Symbol U}', 'web' => "\x{3A5}"},
861: '(Omega|#937)' => {'tex' => '{/Symbol W}', 'web' => "\x{3A9}"},
862: '(Xi|#926)' => {'tex' => '{/Symbol X}', 'web' => "\x{39E}"},
863: '(Psi|#936)' => {'tex' => '{/Symbol Y}', 'web' => "\x{3A8}"},
864: '(Zeta|#918)' => {'tex' => '{/Symbol Z}', 'web' => "\x{396}"},
865: '(alpha|#945)' => {'tex' => '{/Symbol a}', 'web' => "\x{3B1}"},
866: '(beta|#946)' => {'tex' => '{/Symbol b}', 'web' => "\x{3B2}"},
867: '(chi|#967)' => {'tex' => '{/Symbol c}', 'web' => "\x{3C7}"},
868: '(delta|#948)' => {'tex' => '{/Symbol d}', 'web' => "\x{3B4}"},
869: '(epsilon|#949)' => {'tex' => '{/Symbol e}', 'web' => "\x{3B5}"},
870: '(phi|#966)' => {'tex' => '{/Symbol f}', 'web' => "\x{3C6}"},
871: '(gamma|#947)' => {'tex' => '{/Symbol g}', 'web' => "\x{3B3}"},
872: '(eta|#951)' => {'tex' => '{/Symbol h}', 'web' => "\x{3B7}"},
873: '(iota|#953)' => {'tex' => '{/Symbol i}', 'web' => "\x{3B9}"},
874: '(kappa|#954)' => {'tex' => '{/Symbol k}', 'web' => "\x{3BA}"},
875: '(lambda|#955)' => {'tex' => '{/Symbol k}', 'web' => "\x{3BB}"},
876: '(mu|#956)' => {'tex' => '{/Symbol m}', 'web' => "\x{3BC}"},
877: '(nu|#957)' => {'tex' => '{/Symbol n}', 'web' => "\x{3BD}"},
878: '(omicron|#959)' => {'tex' => '{/Symbol o}', 'web' => "\x{3BF}"},
879: '(pi|#960)' => {'tex' => '{/Symbol p}', 'web' => "\x{3C0}"},
880: '(theta|#952)' => {'tex' => '{/Symbol q}', 'web' => "\x{3B8}"},
881: '(rho|#961)' => {'tex' => '{/Symbol r}', 'web' => "\x{3C1}"},
882: '(sigma|#963)' => {'tex' => '{/Symbol s}', 'web' => "\x{3C3}"},
883: '(tau|#964)' => {'tex' => '{/Symbol t}', 'web' => "\x{3C4}"},
884: '(upsilon|#965)' => {'tex' => '{/Symbol u}', 'web' => "\x{3C5}"},
885: '(omega|#969)' => {'tex' => '{/Symbol w}', 'web' => "\x{3C9}"},
886: '(xi|#958)' => {'tex' => '{/Symbol x}', 'web' => "\x{3BE}"},
887: '(psi|#968)' => {'tex' => '{/Symbol y}', 'web' => "\x{3C8}"},
888: '(zeta|#950)' => {'tex' => '{/Symbol z}', 'web' => "\x{3B6}"},
889: '(thetasym|#977)' => {'tex' => '{/Symbol \165}', 'web' => "\x{3d1}"},
890: '(upsih|#978)' => {'tex' => '{/Symbol \241}', 'web' => "\x{3d2}"},
891: '(piv|#982)' => {'tex' => '{/Symbol \166}', 'web' => "\x{3d6}"},
1.137 foxr 892:
893:
894: # Punctuation:
895:
1.138 foxr 896: '(quot|#034)' => {'tex' => '\42', 'web' => '\42'},
897: '(amp|#038)' => {'tex' => '\46', 'web' => '\46'},
898: '(lt|#060)' => {'tex' => '\74', 'web' => '\74'},
899: '(gt|#062)' => {'tex' => '\76', 'web' => '\76'},
1.137 foxr 900: '#131' => {'tex' => '{/Symbol \246}', 'web' => "\x{192}"},
1.138 foxr 901: '#132' => {'tex' => '{/Text \271}', 'web' => "\x{201e}"},
902: '#133' => {'tex' => '{/Symbol \274}', 'web'=> "\x{2026}"},
903: '#134' => {'tex' => '{/Text \262}', 'web' => "\x{2020}"},
904: '#135' => {'tex' => '{/Text \263}', 'web' => "\x{2021}"},
905: '#136' => {'tex' => '\\\\^', 'web' => '\\\\^'},
1.143 foxr 906: '#137' => {'tex' => '%o', 'web' => "\x{2030}"}, # Per Mille <FIX>
907: '#138' => {'tex' => 'S', 'web' => "\x{160}"}, # S-Caron <FIX>
1.138 foxr 908: '#139' => {'tex' => '<', 'web' => '<'},
1.143 foxr 909: '#140' => {'tex' => 'AE', 'web' => "\x{152}"}, # AE ligature <FIX>
1.138 foxr 910: '#145' => {'tex' => '\140', 'web' => "\x{2018}"},
911: '#146' => {'tex' => '\47', 'web' => "\x{2019}"},
1.143 foxr 912: '#147' => {'tex' => '\140\140', 'web' => "\x{201c}"}, # Left " <FIX>
913: '#148' => {'tex' => '\47\47', 'web' => '\\"'}, # Right " <FIX>
1.138 foxr 914: '#149' => {'tex' => '{/Symbol \267}', 'web' => "\x{2022}"},
1.143 foxr 915: '#150' => {'tex' => '{/Text \55}', 'web' => "\x{2013}"}, # en dash
1.138 foxr 916: '#151' => {'tex' => '{/Symbol \55}', 'web' => "\x{2014}"}, # em dash
1.143 foxr 917: '#152' => {'tex' => '\\\\~', 'web' => '\\\\~'},
918: '#153' => {'tex' => '{/Symbol \324}', 'web' => "\x{2122}"}, # trademark
1.139 foxr 919:
920: # Accented letters, and other furreign language glyphs.
921:
1.138 foxr 922: '#154' => {'tex' => 's', 'web' => "\x{161}"}, # small s-caron no ps.
923: '#155' => {'tex' => '>', 'web' => '\76'}, # >
1.143 foxr 924: '#156' => {'tex' => '{/Text \366}', 'web' => "\x{153}"}, # oe ligature.<FIX>
925: '#159', => {'tex' => 'Y', 'web' => "\x{178}"}, # Y-umlaut - can't print <FIX>
1.138 foxr 926: '(nbsp|#160)' => {'tex' => ' ', 'web' => ' '}, # non breaking space.
927: '(iexcl|#161)' => {'tex' => '{/Text \241}', 'web' => "\x{a1}"}, # inverted !
928: '(cent|#162)' => {'tex' => '{/Text \242}', 'web' => "\x{a2}"}, # Cent currency.
1.142 foxr 929: '(pound|#163)' => {'tex' => '{/Text \243}', 'web' => "\x{a3}"}, # GB Pound currency.
1.143 foxr 930: '(curren|#164)' => {'tex' => '{/ZapfDingbats \161}','web' => "\x{a4}"}, # Generic currency symb. <FIX>
1.138 foxr 931: '(yen|#165)' => {'tex' => '{/Text \245}', 'web' => "\x{a5}"}, # Yen currency.
932: '(brvbar|#166)' => {'tex' => '{/Symbol \174}', 'web' => "\x{a6}"}, # Broken vert bar no print.
933: '(sect|#167)' => {'tex' => '{\247}', 'web' => "\x{a7}"}, # Section symbol.
934: '(uml|#168)' => {'tex' => '{\250}', 'web' => "\x{a8}"}, # 'naked' umlaut.
935: '(copy|#169)' => {'tex' => '{/Symbol \343}', 'web' => "\x{a9}"}, # Copyright symbol.
936: '(ordf|#170)' => {'tex' => '{/Text \343}', 'web' => "\x{aa}"}, # Feminine ordinal.
937: '(laquo|#171)' => {'tex' => '{/Text \253}', 'web' => "\x{ab}"}, # << quotes.
938: '(not|#172)' => {'tex' => '\254', 'web' => "\x{ac}"}, # Logical not.
1.143 foxr 939: '(shy|#173)' => {'tex' => '\255', 'web' => "\x{ad}"}, # soft hyphen.
1.138 foxr 940: '(reg|#174)' => {'tex' => '{/Symbol \342}', 'web' => "\x{ae}"}, # Registered tm.
1.143 foxr 941: '(macr|#175)' => {'tex' => '^{\255}', 'web' => "\x{af}"}, # 'naked' macron (overbar).
942: '(deg|#176)' => {'tex' => '{/Text \260}', 'web' => "\x{b0}"}, # Degree symbo..`
1.138 foxr 943: '(plusmn|#177)' => {'tex' => '{/Symbol \261}', 'web' => "\x{b1}"}, # +/- symbol.
944: '(sup2|#178)' => {'tex' => '^2', 'web' => "\x{b2}"}, # Superscript 2.
945: '(sup3|#179)' => {'tex' => '^3', 'web' => "\x{b3}"}, # Superscript 3.
1.143 foxr 946: '(acute|#180)' => {'tex' => '{/Text \222}', 'web' => "\x{b4}"}, # 'naked' acute accent.
1.138 foxr 947: '(micro|#181)' => {'tex' => '{/Symbol \155}', 'web' => "\x{b5}"}, # Micro (small mu).
948: '(para|#182)' => {'tex' => '{/Text \266}', 'web' => "\x{b6}"}, # Paragraph symbol.
1.143 foxr 949: '(middot|#183)' => {'tex' => '\267', 'web' => "\x{b7}"}, # middle dot
1.138 foxr 950: '(cedil|#184)' => {'tex' => '\233', 'web' => "\x{b8}"}, # 'naked' cedilla.
951: '(sup1|#185)' => {'tex' => '^1', 'web' => "\x{b9}"}, # superscript 1.
1.143 foxr 952: '(ordm|#186)' => {'tex' => '{\260}', 'web' => "\x{ba}"}, # masculine ordinal.
1.138 foxr 953: '(raquo|#187)', => {'tex' => '\273', 'web' => "\x{bb}"}, # Right angle quotes.
954: '(frac14|#188)' => {'tex' => '\274', 'web' => "\x{bc}"}, # 1/4.
955: '(frac12|#189)' => {'tex' => '\275', 'web' => "\x{bd}"}, # 1/2.
956: '(frac34|#190)' => {'tex' => '\276', 'web' => "\x{be}"}, # 3/4
957: '(iquest|#191)' => {'tex' => '{/Text \277}', 'web' => "\x{bf}"}, # Inverted ?
958: '(Agrave|#192)' => {'tex' => '\300', 'web' => "\x{c0}"}, # A Grave.
959: '(Aacute|#193)' => {'tex' => '\301', 'web' => "\x{c1}"}, # A Acute.
960: '(Acirc|#194)' => {'tex' => '\302', 'web' => "\x{c2}"}, # A Circumflex.
961: '(Atilde|#195)' => {'tex' => '\303', 'web' => "\x{c3}"}, # A tilde.
962: '(Auml|#196)' => {'tex' => '\304', 'web' => "\x{c4}"}, # A umlaut.
963: '(Aring|#197)' => {'tex' => '\305', 'web' => "\x{c5}"}, # A ring.
1.139 foxr 964: '(AElig|#198)' => {'tex' => '\306', 'web' => "\x{c6}"}, # AE ligature.
965: '(Ccedil|#199)' => {'tex' => '\307', 'web' => "\x{c7}"}, # C cedilla
966: '(Egrave|#200)' => {'tex' => '\310', 'web' => "\x{c8}"}, # E Accent grave.
967: '(Eacute|#201)' => {'tex' => '\311', 'web' => "\x{c9}"}, # E acute accent.
968: '(Ecirc|#202)' => {'tex' => '\312', 'web' => "\x{ca}"}, # E Circumflex.
969: '(Euml|#203)' => {'tex' => '\313', 'web' => "\x{cb}"}, # E umlaut.
970: '(Igrave|#204)' => {'tex' => '\314', 'web' => "\x{cc}"}, # I grave accent.
971: '(Iacute|#205)' => {'tex' => '\315', 'web' => "\x{cd}"}, # I acute accent.
972: '(Icirc|#206)' => {'tex' => '\316', 'web' => "\x{ce}"}, # I circumflex.
973: '(Iuml|#207)' => {'tex' => '\317', 'web' => "\x{cf}"}, # I umlaut.
974: '(ETH|#208)' => {'tex' => '\320', 'web' => "\x{d0}"}, # Icelandic Cap eth.
975: '(Ntilde|#209)' => {'tex' => '\321', 'web' => "\x{d1}"}, # Ntilde (enyan).
976: '(Ograve|#210)' => {'tex' => '\322', 'web' => "\x{d2}"}, # O accent grave.
977: '(Oacute|#211)' => {'tex' => '\323', 'web' => "\x{d3}"}, # O accent acute.
978: '(Ocirc|#212)' => {'tex' => '\324', 'web' => "\x{d4}"}, # O circumflex.
979: '(Otilde|#213)' => {'tex' => '\325', 'web' => "\x{d5}"}, # O tilde.
980: '(Ouml|#214)' => {'tex' => '\326', 'web' => "\x{d6}"}, # O umlaut.
981: '(times|#215)' => {'tex' => '\327', 'web' => "\x{d7}"}, # Times symbol.
982: '(Oslash|#216)' => {'tex' => '\330', 'web' => "\x{d8}"}, # O slash.
983: '(Ugrave|#217)' => {'tex' => '\331', 'web' => "\x{d9}"}, # U accent grave.
984: '(Uacute|#218)' => {'tex' => '\332', 'web' => "\x{da}"}, # U accent acute.
985: '(Ucirc|#219)' => {'tex' => '\333', 'web' => "\x{db}"}, # U circumflex.
986: '(Uuml|#220)' => {'tex' => '\334', 'web' => "\x{dc}"}, # U umlaut.
987: '(Yacute|#221)' => {'tex' => '\335', 'web' => "\x{dd}"}, # Y accent acute.
988: '(THORN|#222)' => {'tex' => '\336', 'web' => "\x{de}"}, # Icelandic thorn.
989: '(szlig|#223)' => {'tex' => '\337', 'web' => "\x{df}"}, # German sharfes s.
990: '(agrave|#224)' => {'tex' => '\340', 'web' => "\x{e0}"}, # a accent grave.
991: '(aacute|#225)' => {'tex' => '\341', 'web' => "\x{e1}"}, # a grave.
992: '(acirc|#226)' => {'tex' => '\342', 'web' => "\x{e2}"}, # a circumflex.
993: '(atilde|#227)' => {'tex' => '\343', 'web' => "\x{e3}"}, # a tilde.
994: '(auml|#228)' => {'tex' => '\344', 'web' => "\x{e4}"}, # a umlaut
995: '(aring|#229)' => {'tex' => '\345', 'web' => "\x{e5}"}, # a ring on top.
996: '(aelig|#230)' => {'tex' => '\346', 'web' => "\x{e6}"}, # ae ligature.
1.142 foxr 997: '(ccedil|#231)' => {'tex' => '\347', 'web' => "\x{e7}"}, # C cedilla
1.139 foxr 998: '(egrave|#232)' => {'tex' => '\350', 'web' => "\x{e8}"}, # e accent grave.
999: '(eacute|#233)' => {'tex' => '\351', 'web' => "\x{e9}"}, # e accent acute.
1000: '(ecirc|#234)' => {'tex' => '\352', 'web' => "\x{ea}" }, # e circumflex.
1001: '(euml|#235)' => {'tex' => '\353', 'web' => "\x{eb}"}, # e umlaut.
1002: '(igrave|#236)' => {'tex' => '\354', 'web' => "\x{ec}"}, # i grave.
1.142 foxr 1003: '(iacute|#237)' => {'tex' => '\355', 'web' => "\x{ed}"}, # i acute.
1004: '(icirc|#238)' => {'tex' => '\356', 'web' => "\x{ee}"}, # i circumflex.
1.139 foxr 1005: '(iuml|#239)' => {'tex' => '\357', 'web' => "\x{ef}"}, # i umlaut.
1006: '(eth|#240)' => {'tex' => '\360', 'web' => "\x{f0}"}, # Icelandic eth.
1007: '(ntilde|#241)' => {'tex' => '\361', 'web' => "\x{f1}"}, # n tilde.
1008: '(ograve|#242)' => {'tex' => '\362', 'web' => "\x{f2}"}, # o grave.
1009: '(oacute|#243)' => {'tex' => '\363', 'web' => "\x{f3}"}, # o acute.
1.143 foxr 1010: '(ocirc|#244)' => {'tex' => '\364', 'web' => "\x{f4}"}, # o circumflex.
1.139 foxr 1011: '(otilde|#245)' => {'tex' => '\365', 'web' => "\x{f5}"}, # o tilde.
1012: '(ouml|#246)' => {'tex' => '\366', 'web' => "\x{f6}"}, # o umlaut.
1013: '(divide|#247)' => {'tex' => '\367', 'web' => "\x{f7}"}, # division symbol
1014: '(oslash|#248)' => {'tex' => '\370', 'web' => "\x{f8}"}, # o slashed.
1015: '(ugrave|#249)' => {'tex' => '\371', 'web' => "\x{f9}"}, # u accent grave.
1016: '(uacute|#250)' => {'tex' => '\372', 'web' => "\x{fa}"}, # u acute.
1017: '(ucirc|#251)' => {'tex' => '\373', 'web' => "\x{fb}"}, # u circumflex.
1018: '(uuml|#252)' => {'tex' => '\374', 'web' => "\x{fc}"}, # u umlaut.
1019: '(yacute|#253)' => {'tex' => '\375', 'web' => "\x{fd}"}, # y acute accent.
1020: '(thorn|#254)' => {'tex' => '\376', 'web' => "\x{fe}"}, # small thorn (icelandic).
1021: '(yuml|#255)' => {'tex' => '\377', 'web' => "\x{ff}"}, # y umlaut.
1022:
1023: # Latin extended A entities:
1024:
1.143 foxr 1025: '(OElig|#338)' => {'tex' => '{/Text \326}', 'web' => "\x{152}"}, # OE ligature.
1026: '(oelig|#339)' => {'tex' => '{/Text \366}', 'web' => "\x{153}"}, # oe ligature.
1.139 foxr 1027: '(Scaron|#352)' => {'tex' => 'S', 'web' => "\x{160}"}, # S caron no printable.
1028: '(scaron|#353)' => {'tex' => 's', 'web' => "\x{161}"}, # s caron no printable.
1029: '(Yuml|#376)' => {'tex' => 'Y', 'web' => "\x{178}"}, # Y umlaut - no printable.
1030:
1031: # Latin extended B.
1032:
1.143 foxr 1033: '(fnof|#402)' => {'tex' =>'{/Symbol \246}', 'web' => "\x{192}"}, # f with little hook.
1.139 foxr 1034:
1.140 foxr 1035: # Standalone accents:
1.139 foxr 1036:
1037: '(circ|#710)' => {'tex' => '^', 'web' => '^'}, # circumflex.
1038: '(tilde|#732)' => {'tex' => '~', 'web' => '~'}, # tilde.
1039:
1.140 foxr 1040: # General punctuation. We're not able to make a distinction between
1041: # the various length spacings in the print version. (e.g. en/em/thin).
1042: # the various joiners will be empty strings in the print version too.
1043:
1044:
1045: '(ensp|#8194)' => {'tex' => ' ', 'web' => "\x{2002}"}, # en space.
1046: '(emsp|#8195)' => {'tex' => ' ', 'web' => "\x{2003}"}, # em space.
1047: '(thinsp|#8201)' => {'tex' => ' ', 'web' => "\x{2009}"}, # thin space.
1.144 foxr 1048: '(zwnj|#8204)' => {'tex' => ' ', 'web' => "\x{200c}"}, # Zero width non joiner.
1049: '(zwj|#8205)' => {'tex' => ' ', 'web' => "\x{200d}"}, # Zero width joiner.
1050: '(lrm|#8206)' => {'tex' => ' ', 'web' => "\x{200e}"}, # Left to right mark
1051: '(rlm|#8207)' => {'tex' => ' ', 'web' => "\x{200f}"}, # right to left mark.
1.140 foxr 1052: '(ndash|#8211)' => {'tex' => '{/Text \55}', 'web' => "\x{2013}"}, # en dash.
1053: '(mdash|#8212)' => {'tex' => '{/Symbol \55}', 'web' => "\x{2014}"}, # em dash.
1054: '(lsquo|#8216)' => {'tex' => '{/Text \140}', 'web' => "\x{2018}"}, # Left single quote.
1.144 foxr 1055: '(rsquo|#8217)' => {'tex' => '\47', 'web' => "\x{2019}"}, # Right single quote.
1056: '(sbquo|#8218)' => {'tex' => '\54', 'web' => "\x{201a}"}, # Single low-9 quote.
1057: '(ldquo|#8220)' => {'tex' => '\42', 'web' => "\x{201c}"}, # Left double quote.
1058: '(rdquo|#8221)' => {'tex' => '\42', 'web' => "\x{201d}"}, # Right double quote.
1059: '(bdquo|#8222)' => {'tex' => ',', 'web' => "\x{201e}"}, # Double low-9 quote.
1060: '(dagger|#8224)' => {'tex' => '+', 'web' => "\x{2020}"}, # Is this a dagger I see before me now?
1.145 foxr 1061: '(Dagger|#8225)' => {'tex' => '\261', 'web' => "\x{2021}"}, # it's handle pointing towards my heart?
1.140 foxr 1062: '(bull|#8226)' => {'tex' => '\267', 'web' => "\x{2022}"}, # Bullet.
1.144 foxr 1063: '(hellep|#8230)' => {'tex' => '{/Symbol \274}', 'web' => "\x{2026}"}, # Ellipses.
1064: '(permil|#8240)' => {'tex' => '%_o', 'web' => "\x{2031}"}, # Per mille.
1.140 foxr 1065: '(prime|#8242)' => {'tex' => '\264', 'web' => "\x{2032}"}, # Prime.
1066: '(Prime|#8243)' => {'tex' => '{/Symbol \262}', 'web' => "\x{2033}"}, # double prime.
1.144 foxr 1067: '(lsaquo|#8249)' => {'tex' => '<', 'web' => "\x{2039}"}, # < quote.
1068: '(rsaquo|#8250)' => {'tex' => '\74', 'web' => "\x{203a}"}, # > quote.
1.140 foxr 1069: '(oline|#8254)' => {'tex' => '{/Symbol \140}', 'web' => "\x{203e}"}, # Overline.
1070: '(frasl|#8260)' => {'tex' => '/', 'web' => "\x{2044}"}, # Fraction slash.
1.144 foxr 1071: '(euro|#8364)' => {'tex' => '{/Symbol \240}', 'web' => "\x{20ac}"}, # Euro currency.
1.140 foxr 1072:
1073: # Letter like symbols.
1074:
1075: '(weierp|#8472)' => {'tex' => '{/Symbol \303}', 'web' => "\x{2118}"}, # Power set symbol
1076: '(image|#8465)' => {'tex' => '{/Symbol \301}', 'web' => "\x{2111}"}, # Imaginary part
1077: '(real|#8476)' => {'tex' => '{/Symbol \302}', 'web' => "\x{211c}"}, # Real part.
1078: '(trade|#8482)' => {'tex' => '{/Symbol \344}', 'web' => "\x{2122}"}, # trademark symbol.
1079: '(alefsym|#8501)' => {'tex' => '{/Symbol \300}', 'web' => "\x{2135}"}, # Hebrew alef.
1080:
1081: # Arrows of various types and directions.
1082: '(larr|#8592)' => {'tex' => '{/Symbol \254}', 'web' => "\x{2190}"}, # <--
1.142 foxr 1083: '(uarr|#8593)' => {'tex' => '{/Symbol \255}', 'web' => "\x{2191}"}, # up arrow.
1.140 foxr 1084: '(rarr|#8594)' => {'tex' => '{/Symbol \256}', 'web' => "\x{2192}"}, # -->
1085: '(darr|#8595)' => {'tex' => '{/Symbol \257}', 'web' => "\x{2193}"}, # down arrow.
1086: '(harr|#8596)' => {'tex' => '{/Symbol \253}', 'web' => "\x{2194}"}, # <-->
1087: '(crarr|#8629)' => {'tex' => '{/Symbol \277}', 'web' => "\x{21b5}"}, # corner arrow down and right.
1088: '(lArr|#8656)' => {'tex' => '{/Symbol \334}', 'web' => "\x{21d0}"}, # <==
1089: '(uArr|#8657)' => {'tex' => '{/Symbol \335}', 'web' => "\x{21d1}"}, # Up double arrow.
1090: '(rArr|#8658)' => {'tex' => '{/Symbol \336}', 'web' => "\x{21d2}"}, # ==>
1091: '(dArr|#8659)' => {'tex' => '{/Symbol \337}', 'web' => "\x{21d3}"}, # Down double arrow.
1092: '(hArr|#8660)' => {'tex' => '{/Symbol \333}', 'web' => "\x{21d4}"}, # <==>
1093:
1094: # Mathematical operators. For some of these we do the best we can in printing.
1095:
1096: '(forall|#8704)' => {'tex' => '{/Symbol \42}', 'web' => "\x{2200}"}, # For all.
1097: '(part|#8706)' => {'tex' => '{/Symbol d}', 'web' => "\x{2202}"}, # partial derivative
1098: '(exist|#8707)' => {'tex' => '{/Symbol \44}', 'web' => "\x{2203}"}, # There exists.
1099: '(empty|#8709)' => {'tex' => '{/Symbol \306}', 'web' => "\x{2205}"}, # Null set.
1100: '(nabla|#8711)' => {'tex' => '{/Symbol \321}', 'web' => "\x{2207}"}, # Gradient e.g.
1101: '(isin|#8712)' => {'tex' => '{/Symbol \316}', 'web' => "\x{2208}"}, # Element of the set.
1.145 foxr 1102: '(notin|#8713)' => {'tex' => '{/Symbol \317}', 'web' => "\x{2209}"}, # Not an element of
1.140 foxr 1103: '(ni|#8715)' => {'tex' => '{/Symbol \47}', 'web' => "\x{220b}"}, # Contains as a member
1104: '(prod|#8719)' => {'tex' => '{/Symbol \325}', 'web' => "\x{220f}"}, # Product
1105: '(sum|#8721)' => {'tex' => '{/Symbol \345}', 'web' => "\x{2211}"}, # Sum of.
1.145 foxr 1106: '(minus|#8722)' => {'tex' => '{/Symbol \55}', 'web' => "\x{2212}"}, # - sign.
1.140 foxr 1107: '(lowast|#8727)' => {'tex' => '*', 'web' => "\x{2217}"}, # *
1108: '(radic|#8730)' => {'tex' => '{/Symbol \326}', 'web' => "\x{221a}"}, # Square root.
1109: '(prop|#8733)' => {'tex' => '{/Symbol \265}', 'web' => "\x{221d}"}, # Proportional to.
1110: '(infin|#8734)' => {'tex' => '{/Symbol \245}', 'web' => "\x{221e}"}, # Infinity.
1111: '(ang|#8736)' => {'tex' => '{/Symbol \320}', 'web' => "\x{2220}"}, # Angle .
1112: '(and|#8743)' => {'tex' => '{/Symbol \331}', 'web' => "\x{2227}"}, # Logical and.
1113: '(or|#8744)' => {'tex' => '{/Symbol \332}', 'web' => "\x{2228}"}, # Logical or.
1114: '(cap|#8745)' => {'tex' => '{/Symbol \307}', 'web' => "\x{2229}"}, # Set intersection.
1115: '(cup|#8746)' => {'tex' => '{/Symbol \310}', 'web' => "\x{222a}"}, # Set union.
1116: '(int|8747)' => {'tex' => '{/Symbol \362}', 'web' => "\x{222b}"}, # Integral.
1.145 foxr 1117:
1118: # Some gnuplot guru will have to explain to me why the next three
1119: # require the extra slashes... else they print very funkily.
1120:
1121: '(there4|#8756)' => {'tex' => '{/Symbol \\\134}', 'web' => "\x{2234}"}, # Therefore triple dots.
1122: '(sim|#8764)' => {'tex' => '\\\176', 'web' => "\x{223c}"}, # Simlar to.
1123: '(cong|#8773)' => {'tex' => '{/Symbol \\\100}','web' => "\x{2245}"}, # Congruent to/with.
1124:
1125: '(asymp|#8776)' => {'tex' => '{/Symbol \273}', 'web' => "\x{2248}"}, # Asymptotic to.
1.141 foxr 1126: '(ne|#8800)' => {'tex' => '{/Symbol \271}', 'web' => "\x{2260}"}, # not equal to.
1127: '(equiv|#8801)' => {'tex' => '{/Symbol \272}', 'web' => "\x{2261}"}, # Equivalent to.
1128: '(le|8804)' => {'tex' => '{/Symbol \243}', 'web' => "\x{2264}"}, # Less than or equal to.
1129: '(ge|8805)' => {'tex' => '{/Symbol \263}', 'web' => "\x{2265}"}, # Greater than or equal to
1130: '(sub|8834)' => {'tex' => '{/Symbol \314}', 'web' => "\x{2282}"}, # Subset of.
1131: '(sup|8835)' => {'tex' => '{/Symbol \311}', 'web' => "\x{2283}"}, # Super set of.
1132: '(nsub|8836)' => {'tex' => '{/Symbol \313}', 'web' => "\x{2284}"}, # not subset of.
1133: '(sube|8838)' => {'tex' => '{/Symbol \315}', 'web' => "\x{2286}"}, # Subset or equal.
1134: '(supe|8839)' => {'tex' => '{/Symbol \312}', 'web' => "\x{2287}"}, # Superset or equal
1135: '(oplus|8853)' => {'tex' => '{/Symbol \305}', 'web' => "\x{2295}"}, # O with plus inside
1136: '(otimes|8855)' => {'tex' => '{/Symbol \304}', 'web' => "\x{2297}"}, # O with times.
1137: '(perp|8869)' => {'tex' => '{/Symbol \136}', 'web' => "\x{22a5}"}, # Perpendicular.
1138: '(sdot|8901)' => {'tex' => '{/Symbol \227}', 'web' => "\x{22c5}"}, # Dot operator.
1139:
1140: # Misc. technical symbols:
1141:
1142: '(lceil|8698)' => {'tex' => '{/Symbol \351}', 'web' => "\x{2308}"}, # Left ceiling.
1143: '(rceil|8969)' => {'tex' => '{/Symbol \371}', 'web' => "\x{2309}"}, # Right ceiling.
1144: '(lfloor|8970)' => {'tex' => '{/Symbol \353}', 'web' => "\x{230a}"}, # Left floor.
1145: '(rfloor|8971)' => {'tex' => '{/Symbol \373}', 'web' => "\x{230b}"}, # Right floor.
1.145 foxr 1146:
1147: # The gnuplot png font evidently does not have the big angle brackets at
1148: # positions 0x2329, 0x232a so use ordinary brackets.
1149:
1150: '(lang|9001)' => {'tex' => '{/Symbol \341}', 'web' => '<'}, # Left angle bracket.
1151: '(rang|9002)' => {'tex' => '{/Symbol \361}', 'web' => '>'}, # Right angle bracket.
1.141 foxr 1152:
1153: # Gemoetric shapes.
1154:
1155: '(loz|9674)' => {'tex' => '{/Symbol \340}', 'web' => "\x{25ca}"}, # Lozenge.
1156:
1157: # Misc. symbols
1158:
1159: '(spades|9824)' => {'tex' => '{/Symbol \252}', 'web' => "\x{2660}"},
1160: '(clubs|9827)' => {'tex' => '{/Symbol \247}', 'web' => "\x{2663}"},
1161: '(hearts|9829)' => {'tex' => '{/Symbol \251}', 'web' => "\x{2665}"},
1162: '(diams|9830)' => {'tex' => '{/Symbol \250}', 'web' => "\x{2666}"}
1.139 foxr 1163:
1.133 albertel 1164: );
1165:
1.128 albertel 1166:
1167: sub replace_entities {
1168: my ($target,$text) = @_;
1169: $text =~ s{([_^~\{\}]|\\\\)}{\\\\$1}g;
1170: while (my ($re, $replace) = each(%lookup)) {
1.137 foxr 1171: my $repl = $replace->{$target};
1.128 albertel 1172: $text =~ s/&$re;/$replace->{$target}/g;
1173: }
1174: $text =~ s{(&)}{\\\\$1}g;
1175: return $text;
1.127 albertel 1176: }
1177:
1.1 matthew 1178: ##------------------------------------------------------------------- title
1179: sub start_title {
1180: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1181: my $result='';
1.51 matthew 1182: if ($target eq 'web' || $target eq 'tex') {
1.112 albertel 1183: $title = &Apache::lonxml::get_all_text("/title",$parser,$style);
1.58 matthew 1184: $title=&Apache::run::evaluate($title,$safeeval,$$parstack[-1]);
1.49 matthew 1185: $title =~ s/\n/ /g;
1.32 matthew 1186: if (length($title) > $max_str_len) {
1187: $title = substr($title,0,$max_str_len);
1188: }
1.128 albertel 1189: $title = &parse_label($target,$title);
1.20 matthew 1190: } elsif ($target eq 'edit') {
1.25 matthew 1191: $result.=&Apache::edit::tag_start($target,$token,'Plot Title');
1.112 albertel 1192: my $text=&Apache::lonxml::get_all_text("/title",$parser,$style);
1.116 albertel 1193: $result.=&Apache::edit::editline('',$text,'',60);
1.20 matthew 1194: } elsif ($target eq 'modified') {
1.42 matthew 1195: $result.=&Apache::edit::rebuild_tag($token);
1.93 albertel 1196: $result.=&Apache::edit::modifiedfield("/title",$parser);
1.4 matthew 1197: }
1.1 matthew 1198: return $result;
1199: }
1200:
1201: sub end_title {
1202: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1203: my $result = '';
1.51 matthew 1204: if ($target eq 'web' || $target eq 'tex') {
1.20 matthew 1205: } elsif ($target eq 'edit') {
1.27 matthew 1206: $result.=&Apache::edit::tag_end($target,$token);
1.4 matthew 1207: }
1.1 matthew 1208: return $result;
1209: }
1210: ##------------------------------------------------------------------- xlabel
1211: sub start_xlabel {
1212: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1213: my $result='';
1.51 matthew 1214: if ($target eq 'web' || $target eq 'tex') {
1.112 albertel 1215: $xlabel = &Apache::lonxml::get_all_text("/xlabel",$parser,$style);
1.58 matthew 1216: $xlabel=&Apache::run::evaluate($xlabel,$safeeval,$$parstack[-1]);
1.49 matthew 1217: $xlabel =~ s/\n/ /g;
1.32 matthew 1218: if (length($xlabel) > $max_str_len) {
1219: $xlabel = substr($xlabel,0,$max_str_len);
1220: }
1.128 albertel 1221: $xlabel = &parse_label($target,$xlabel);
1.20 matthew 1222: } elsif ($target eq 'edit') {
1.25 matthew 1223: $result.=&Apache::edit::tag_start($target,$token,'Plot Xlabel');
1.112 albertel 1224: my $text=&Apache::lonxml::get_all_text("/xlabel",$parser,$style);
1.116 albertel 1225: $result.=&Apache::edit::editline('',$text,'',60);
1.20 matthew 1226: } elsif ($target eq 'modified') {
1.42 matthew 1227: $result.=&Apache::edit::rebuild_tag($token);
1.93 albertel 1228: $result.=&Apache::edit::modifiedfield("/xlabel",$parser);
1.4 matthew 1229: }
1.1 matthew 1230: return $result;
1231: }
1232:
1233: sub end_xlabel {
1234: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1235: my $result = '';
1.51 matthew 1236: if ($target eq 'web' || $target eq 'tex') {
1.20 matthew 1237: } elsif ($target eq 'edit') {
1.27 matthew 1238: $result.=&Apache::edit::tag_end($target,$token);
1.4 matthew 1239: }
1.1 matthew 1240: return $result;
1241: }
1.21 matthew 1242:
1.1 matthew 1243: ##------------------------------------------------------------------- ylabel
1244: sub start_ylabel {
1245: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1246: my $result='';
1.51 matthew 1247: if ($target eq 'web' || $target eq 'tex') {
1.112 albertel 1248: $ylabel = &Apache::lonxml::get_all_text("/ylabel",$parser,$style);
1.58 matthew 1249: $ylabel = &Apache::run::evaluate($ylabel,$safeeval,$$parstack[-1]);
1.49 matthew 1250: $ylabel =~ s/\n/ /g;
1.32 matthew 1251: if (length($ylabel) > $max_str_len) {
1252: $ylabel = substr($ylabel,0,$max_str_len);
1253: }
1.128 albertel 1254: $ylabel = &parse_label($target,$ylabel);
1.20 matthew 1255: } elsif ($target eq 'edit') {
1.25 matthew 1256: $result .= &Apache::edit::tag_start($target,$token,'Plot Ylabel');
1.112 albertel 1257: my $text = &Apache::lonxml::get_all_text("/ylabel",$parser,$style);
1.116 albertel 1258: $result .= &Apache::edit::editline('',$text,'',60);
1.20 matthew 1259: } elsif ($target eq 'modified') {
1.42 matthew 1260: $result.=&Apache::edit::rebuild_tag($token);
1.93 albertel 1261: $result.=&Apache::edit::modifiedfield("/ylabel",$parser);
1.4 matthew 1262: }
1.1 matthew 1263: return $result;
1264: }
1265:
1266: sub end_ylabel {
1267: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1268: my $result = '';
1.51 matthew 1269: if ($target eq 'web' || $target eq 'tex') {
1.20 matthew 1270: } elsif ($target eq 'edit') {
1.27 matthew 1271: $result.=&Apache::edit::tag_end($target,$token);
1.4 matthew 1272: }
1.1 matthew 1273: return $result;
1274: }
1.21 matthew 1275:
1.1 matthew 1276: ##------------------------------------------------------------------- label
1277: sub start_label {
1278: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1279: my $result='';
1.51 matthew 1280: if ($target eq 'web' || $target eq 'tex') {
1.17 matthew 1281: my %label;
1282: &get_attributes(\%label,\%label_defaults,$parstack,$safeeval,
1.11 matthew 1283: $tagstack->[-1]);
1.112 albertel 1284: my $text = &Apache::lonxml::get_all_text("/label",$parser,$style);
1.58 matthew 1285: $text = &Apache::run::evaluate($text,$safeeval,$$parstack[-1]);
1.49 matthew 1286: $text =~ s/\n/ /g;
1.32 matthew 1287: $text = substr($text,0,$max_str_len) if (length($text) > $max_str_len);
1.128 albertel 1288: $label{'text'} = &parse_label($target,$text);
1.17 matthew 1289: push(@labels,\%label);
1.20 matthew 1290: } elsif ($target eq 'edit') {
1.25 matthew 1291: $result .= &Apache::edit::tag_start($target,$token,'Plot Label');
1.21 matthew 1292: $result .= &edit_attributes($target,$token,\%label_defaults);
1.112 albertel 1293: my $text = &Apache::lonxml::get_all_text("/label",$parser,$style);
1.39 matthew 1294: $result .= &Apache::edit::end_row().
1295: &Apache::edit::start_spanning_row().
1.63 albertel 1296: &Apache::edit::editline('',$text,'',60);
1.20 matthew 1297: } elsif ($target eq 'modified') {
1.42 matthew 1298: &Apache::edit::get_new_args
1.24 matthew 1299: ($token,$parstack,$safeeval,keys(%label_defaults));
1.42 matthew 1300: $result.=&Apache::edit::rebuild_tag($token);
1.93 albertel 1301: $result.=&Apache::edit::modifiedfield("/label",$parser);
1.4 matthew 1302: }
1.1 matthew 1303: return $result;
1304: }
1305:
1306: sub end_label {
1307: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1308: my $result = '';
1.51 matthew 1309: if ($target eq 'web' || $target eq 'tex') {
1.20 matthew 1310: } elsif ($target eq 'edit') {
1.21 matthew 1311: $result.=&Apache::edit::tag_end($target,$token);
1.4 matthew 1312: }
1.1 matthew 1313: return $result;
1314: }
1315:
1316: ##------------------------------------------------------------------- curve
1317: sub start_curve {
1318: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1319: my $result='';
1.25 matthew 1320: &Apache::lonxml::register('Apache::lonplot',('function','data'));
1321: push (@Apache::lonxml::namespace,'curve');
1.51 matthew 1322: if ($target eq 'web' || $target eq 'tex') {
1.17 matthew 1323: my %curve;
1324: &get_attributes(\%curve,\%curve_defaults,$parstack,$safeeval,
1.11 matthew 1325: $tagstack->[-1]);
1.17 matthew 1326: push (@curves,\%curve);
1.20 matthew 1327: } elsif ($target eq 'edit') {
1.26 matthew 1328: $result .= &Apache::edit::tag_start($target,$token,'Curve');
1.60 matthew 1329: $result .= &edit_attributes($target,$token,\%curve_defaults,
1.116 albertel 1330: \@curve_edit_order)
1331: .&Apache::edit::end_row()
1332: .&Apache::edit::start_spanning_row();
1333:
1.20 matthew 1334: } elsif ($target eq 'modified') {
1335: my $constructtag=&Apache::edit::get_new_args
1.35 matthew 1336: ($token,$parstack,$safeeval,keys(%curve_defaults));
1.20 matthew 1337: if ($constructtag) {
1338: $result = &Apache::edit::rebuild_tag($token);
1339: }
1.4 matthew 1340: }
1.1 matthew 1341: return $result;
1342: }
1343:
1344: sub end_curve {
1345: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1346: my $result = '';
1.25 matthew 1347: pop @Apache::lonxml::namespace;
1348: &Apache::lonxml::deregister('Apache::lonplot',('function','data'));
1.51 matthew 1349: if ($target eq 'web' || $target eq 'tex') {
1.20 matthew 1350: } elsif ($target eq 'edit') {
1.21 matthew 1351: $result.=&Apache::edit::tag_end($target,$token);
1.4 matthew 1352: }
1.1 matthew 1353: return $result;
1354: }
1.21 matthew 1355:
1.1 matthew 1356: ##------------------------------------------------------------ curve function
1357: sub start_function {
1358: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1359: my $result='';
1.51 matthew 1360: if ($target eq 'web' || $target eq 'tex') {
1.17 matthew 1361: if (exists($curves[-1]->{'data'})) {
1.85 matthew 1362: &Apache::lonxml::warning
1363: ('Use of the <b>curve function</b> tag precludes use of '.
1364: ' the <b>curve data</b> tag. '.
1365: 'The curve data tag will be omitted in favor of the '.
1366: 'curve function declaration.');
1.17 matthew 1367: delete $curves[-1]->{'data'} ;
1368: }
1.112 albertel 1369: my $function = &Apache::lonxml::get_all_text("/function",$parser,
1370: $style);
1.58 matthew 1371: $function = &Apache::run::evaluate($function,$safeeval,$$parstack[-1]);
1.147 www 1372: $function=~s/\^/\*\*/gs;
1.58 matthew 1373: $curves[-1]->{'function'} = $function;
1.20 matthew 1374: } elsif ($target eq 'edit') {
1.37 matthew 1375: $result .= &Apache::edit::tag_start($target,$token,'Gnuplot compatible curve function');
1.112 albertel 1376: my $text = &Apache::lonxml::get_all_text("/function",$parser,$style);
1.116 albertel 1377: $result .= &Apache::edit::editline('',$text,'',60);
1.20 matthew 1378: } elsif ($target eq 'modified') {
1.42 matthew 1379: $result.=&Apache::edit::rebuild_tag($token);
1.93 albertel 1380: $result.=&Apache::edit::modifiedfield("/function",$parser);
1.4 matthew 1381: }
1.1 matthew 1382: return $result;
1383: }
1384:
1385: sub end_function {
1386: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1387: my $result = '';
1.51 matthew 1388: if ($target eq 'web' || $target eq 'tex') {
1.20 matthew 1389: } elsif ($target eq 'edit') {
1.26 matthew 1390: $result .= &Apache::edit::end_table();
1.4 matthew 1391: }
1.1 matthew 1392: return $result;
1393: }
1.21 matthew 1394:
1.1 matthew 1395: ##------------------------------------------------------------ curve data
1396: sub start_data {
1397: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1398: my $result='';
1.51 matthew 1399: if ($target eq 'web' || $target eq 'tex') {
1.17 matthew 1400: if (exists($curves[-1]->{'function'})) {
1.85 matthew 1401: &Apache::lonxml::warning
1402: ('Use of the <b>curve function</b> tag precludes use of '.
1403: ' the <b>curve data</b> tag. '.
1404: 'The curve function tag will be omitted in favor of the '.
1405: 'curve data declaration.');
1.17 matthew 1406: delete($curves[-1]->{'function'});
1407: }
1.112 albertel 1408: my $datatext = &Apache::lonxml::get_all_text("/data",$parser,$style);
1.58 matthew 1409: $datatext=&Apache::run::evaluate($datatext,$safeeval,$$parstack[-1]);
1.40 matthew 1410: # Deal with cases where we're given an array...
1411: if ($datatext =~ /^\@/) {
1412: $datatext = &Apache::run::run('return "'.$datatext.'"',
1413: $safeeval,1);
1414: }
1.49 matthew 1415: $datatext =~ s/\s+/ /g;
1.17 matthew 1416: # Need to do some error checking on the @data array -
1417: # make sure it's all numbers and make sure each array
1418: # is of the same length.
1419: my @data;
1.35 matthew 1420: if ($datatext =~ /,/) { # comma deliminated
1.17 matthew 1421: @data = split /,/,$datatext;
1.95 www 1422: } else { # Assume it's space separated.
1.17 matthew 1423: @data = split / /,$datatext;
1424: }
1425: for (my $i=0;$i<=$#data;$i++) {
1426: # Check that it's non-empty
1.19 matthew 1427: if (! defined($data[$i])) {
1428: &Apache::lonxml::warning(
1.85 matthew 1429: 'undefined curve data value. Replacing with '.
1.19 matthew 1430: ' pi/e = 1.15572734979092');
1431: $data[$i] = 1.15572734979092;
1432: }
1.17 matthew 1433: # Check that it's a number
1.19 matthew 1434: if (! &$real_test($data[$i]) & ! &$int_test($data[$i])) {
1435: &Apache::lonxml::warning(
1.85 matthew 1436: 'Bad curve data value of '.$data[$i].' Replacing with '.
1.19 matthew 1437: ' pi/e = 1.15572734979092');
1438: $data[$i] = 1.15572734979092;
1439: }
1.17 matthew 1440: }
1.35 matthew 1441: # complain if the number of data points is not the same as
1442: # in previous sets of data.
1.150 raeburn 1443: if (($curves[-1]->{'data'}) && ($#data != $#{$curves[-1]->{'data'}->[0]})){
1.35 matthew 1444: &Apache::lonxml::warning
1445: ('Number of data points is not consistent with previous '.
1446: 'number of data points');
1447: }
1.17 matthew 1448: push @{$curves[-1]->{'data'}},\@data;
1.20 matthew 1449: } elsif ($target eq 'edit') {
1.37 matthew 1450: $result .= &Apache::edit::tag_start($target,$token,'Comma or space deliminated curve data');
1.112 albertel 1451: my $text = &Apache::lonxml::get_all_text("/data",$parser,$style);
1.116 albertel 1452: $result .= &Apache::edit::editline('',$text,'',60);
1.20 matthew 1453: } elsif ($target eq 'modified') {
1.42 matthew 1454: $result.=&Apache::edit::rebuild_tag($token);
1.93 albertel 1455: $result.=&Apache::edit::modifiedfield("/data",$parser);
1.4 matthew 1456: }
1.1 matthew 1457: return $result;
1458: }
1459:
1460: sub end_data {
1461: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1462: my $result = '';
1.51 matthew 1463: if ($target eq 'web' || $target eq 'tex') {
1.20 matthew 1464: } elsif ($target eq 'edit') {
1.26 matthew 1465: $result .= &Apache::edit::end_table();
1.4 matthew 1466: }
1.1 matthew 1467: return $result;
1468: }
1469:
1470: ##------------------------------------------------------------------- axis
1471: sub start_axis {
1472: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1473: my $result='';
1.51 matthew 1474: if ($target eq 'web' || $target eq 'tex') {
1.17 matthew 1475: &get_attributes(\%axis,\%axis_defaults,$parstack,$safeeval,
1476: $tagstack->[-1]);
1.20 matthew 1477: } elsif ($target eq 'edit') {
1.25 matthew 1478: $result .= &Apache::edit::tag_start($target,$token,'Plot Axes');
1.65 matthew 1479: $result .= &edit_attributes($target,$token,\%axis_defaults,
1480: \@axis_edit_order);
1.20 matthew 1481: } elsif ($target eq 'modified') {
1.29 matthew 1482: my $constructtag=&Apache::edit::get_new_args
1483: ($token,$parstack,$safeeval,keys(%axis_defaults));
1484: if ($constructtag) {
1485: $result = &Apache::edit::rebuild_tag($token);
1486: }
1.4 matthew 1487: }
1.1 matthew 1488: return $result;
1489: }
1490:
1491: sub end_axis {
1492: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1493: my $result = '';
1.51 matthew 1494: if ($target eq 'web' || $target eq 'tex') {
1.20 matthew 1495: } elsif ($target eq 'edit') {
1.21 matthew 1496: $result.=&Apache::edit::tag_end($target,$token);
1.20 matthew 1497: } elsif ($target eq 'modified') {
1.4 matthew 1498: }
1.1 matthew 1499: return $result;
1500: }
1501:
1.21 matthew 1502: ###################################################################
1503: ## ##
1504: ## Utility Functions ##
1505: ## ##
1506: ###################################################################
1507:
1.13 matthew 1508: ##----------------------------------------------------------- set_defaults
1509: sub set_defaults {
1.21 matthew 1510: my ($var,$defaults) = @_;
1.13 matthew 1511: my $key;
1.24 matthew 1512: foreach $key (keys(%$defaults)) {
1.13 matthew 1513: $var->{$key} = $defaults->{$key}->{'default'};
1514: }
1515: }
1516:
1.1 matthew 1517: ##------------------------------------------------------------------- misc
1.2 matthew 1518: sub get_attributes{
1.21 matthew 1519: my ($values,$defaults,$parstack,$safeeval,$tag) = @_;
1.24 matthew 1520: foreach my $attr (keys(%{$defaults})) {
1.92 matthew 1521: if ($attr eq 'texwidth' || $attr eq 'texfont') {
1.86 albertel 1522: $values->{$attr} =
1523: &Apache::lonxml::get_param($attr,$parstack,$safeeval,undef,1);
1524: } else {
1525: $values->{$attr} =
1526: &Apache::lonxml::get_param($attr,$parstack,$safeeval);
1527: }
1.10 matthew 1528: if ($values->{$attr} eq '' | !defined($values->{$attr})) {
1.11 matthew 1529: $values->{$attr} = $defaults->{$attr}->{'default'};
1.6 matthew 1530: next;
1531: }
1.10 matthew 1532: my $test = $defaults->{$attr}->{'test'};
1533: if (! &$test($values->{$attr})) {
1.6 matthew 1534: &Apache::lonxml::warning
1535: ($tag.':'.$attr.': Bad value.'.'Replacing your value with : '
1.11 matthew 1536: .$defaults->{$attr}->{'default'} );
1537: $values->{$attr} = $defaults->{$attr}->{'default'};
1.10 matthew 1538: }
1.2 matthew 1539: }
1.11 matthew 1540: return ;
1.6 matthew 1541: }
1.40 matthew 1542:
1.15 matthew 1543: ##------------------------------------------------------- write_gnuplot_file
1.6 matthew 1544: sub write_gnuplot_file {
1.51 matthew 1545: my ($tmpdir,$filename,$target)= @_;
1.124 albertel 1546: my ($fontsize, $font_properties) = &get_font($target);
1.6 matthew 1547: my $gnuplot_input = '';
1.10 matthew 1548: my $curve;
1.100 matthew 1549: #
1550: # Check to be sure we do not have any empty curves
1551: my @curvescopy;
1552: foreach my $curve (@curves) {
1553: if (exists($curve->{'function'})) {
1554: if ($curve->{'function'} !~ /^\s*$/) {
1555: push(@curvescopy,$curve);
1556: }
1557: } elsif (exists($curve->{'data'})) {
1558: foreach my $data (@{$curve->{'data'}}) {
1559: if (scalar(@$data) > 0) {
1560: push(@curvescopy,$curve);
1561: last;
1562: }
1563: }
1564: }
1565: }
1566: @curves = @curvescopy;
1.6 matthew 1567: # Collect all the colors
1568: my @Colors;
1.107 foxr 1569: push @Colors, $Apache::lonplot::plot{'bgcolor'};
1570: push @Colors, $Apache::lonplot::plot{'fgcolor'};
1571: push @Colors, (defined($axis{'color'})?$axis{'color'}:$Apache::lonplot::plot{'fgcolor'});
1.9 matthew 1572: foreach $curve (@curves) {
1573: push @Colors, ($curve->{'color'} ne '' ?
1574: $curve->{'color'} :
1.107 foxr 1575: $Apache::lonplot::plot{'fgcolor'} );
1.6 matthew 1576: }
1577: # set term
1.51 matthew 1578: if ($target eq 'web') {
1.120 albertel 1579: $gnuplot_input .= 'set terminal png enhanced nocrop ';
1.107 foxr 1580: $gnuplot_input .= 'transparent ' if ($Apache::lonplot::plot{'transparent'} eq 'on');
1.120 albertel 1581: $gnuplot_input .= 'font "'.$Apache::lonnet::perlvar{'lonFontsDir'}.
1582: '/'.$font_properties->{'file'}.'.ttf" ';
1583: $gnuplot_input .= $fontsize;
1584: $gnuplot_input .= ' size '.$Apache::lonplot::plot{'width'}.','.$Apache::lonplot::plot{'height'}.' ';
1.51 matthew 1585: $gnuplot_input .= "@Colors\n";
1586: # set output
1587: $gnuplot_input .= "set output\n";
1588: } elsif ($target eq 'tex') {
1.120 albertel 1589: $gnuplot_input .= "set term postscript eps enhanced $Apache::lonplot::plot{'plotcolor'} solid ";
1.121 albertel 1590: if (!$font_properties->{'tex_no_file'}) {
1591: $gnuplot_input .=
1592: 'fontfile "'.$Apache::lonnet::perlvar{'lonFontsDir'}.
1593: '/'.$font_properties->{'file'}.'.pfb" ';
1594: }
1.120 albertel 1595: $gnuplot_input .= ' "'.$font_properties->{'printname'}.'" ';
1596: $gnuplot_input .= $fontsize;
1597: $gnuplot_input .= "\nset output \"/home/httpd/perl/tmp/".
1.113 www 1598: &unescape($filename).".eps\"\n";
1.143 foxr 1599: $gnuplot_input .= "set encoding iso_8859_1\n"; # Get access to extended font.
1600:
1.87 matthew 1601: }
1.115 albertel 1602: # cartesian or polar plot?
1.107 foxr 1603: if (lc($Apache::lonplot::plot{'plottype'}) eq 'polar') {
1.87 matthew 1604: $gnuplot_input .= 'set polar'.$/;
1605: } else {
1606: # Assume Cartesian
1.51 matthew 1607: }
1.115 albertel 1608: # cartesian or polar grid?
1609: if (lc($Apache::lonplot::plot{'gridtype'}) eq 'polar') {
1610: $gnuplot_input .= 'set grid polar'.$/;
1.118 albertel 1611: } elsif (lc($Apache::lonplot::plot{'gridtype'}) eq 'linear-log') {
1612: $gnuplot_input .= 'set logscale x'.$/;
1613: } elsif (lc($Apache::lonplot::plot{'gridtype'}) eq 'log-linear') {
1614: $gnuplot_input .= 'set logscale y'.$/;
1615: } elsif (lc($Apache::lonplot::plot{'gridtype'}) eq 'log-log') {
1616: $gnuplot_input .= 'set logscale x'.$/;
1617: $gnuplot_input .= 'set logscale y'.$/;
1.115 albertel 1618: } else {
1619: # Assume Cartesian
1620: }
1.110 albertel 1621: # solid or pattern for boxes?
1622: if (lc($Apache::lonplot::plot{'fillstyle'}) eq 'solid') {
1623: $gnuplot_input .= 'set style fill solid '.
1624: $Apache::lonplot::plot{'solid'}.$Apache::lonplot::plot{'box_border'}.$/;
1625: } elsif (lc($Apache::lonplot::plot{'fillstyle'}) eq 'pattern') {
1626: $gnuplot_input .= 'set style fill pattern '.$Apache::lonplot::plot{'pattern'}.$Apache::lonplot::plot{'box_border'}.$/;
1627: } elsif (lc($Apache::lonplot::plot{'fillstyle'}) eq 'empty') {
1628: }
1.101 matthew 1629: # margin
1.107 foxr 1630: if (lc($Apache::lonplot::plot{'lmargin'}) ne 'default') {
1631: $gnuplot_input .= 'set lmargin '.$Apache::lonplot::plot{'lmargin'}.$/;
1.101 matthew 1632: }
1.107 foxr 1633: if (lc($Apache::lonplot::plot{'rmargin'}) ne 'default') {
1634: $gnuplot_input .= 'set rmargin '.$Apache::lonplot::plot{'rmargin'}.$/;
1.101 matthew 1635: }
1.107 foxr 1636: if (lc($Apache::lonplot::plot{'tmargin'}) ne 'default') {
1637: $gnuplot_input .= 'set tmargin '.$Apache::lonplot::plot{'tmargin'}.$/;
1.101 matthew 1638: }
1.107 foxr 1639: if (lc($Apache::lonplot::plot{'bmargin'}) ne 'default') {
1640: $gnuplot_input .= 'set bmargin '.$Apache::lonplot::plot{'bmargin'}.$/;
1.101 matthew 1641: }
1.129 albertel 1642:
1.101 matthew 1643: # tic scales
1.129 albertel 1644: if ($version > 4) {
1645: $gnuplot_input .= 'set tics scale '.
1646: $Apache::lonplot::plot{'major_ticscale'}.', '.$Apache::lonplot::plot{'minor_ticscale'}.$/;
1647: } else {
1648: $gnuplot_input .= 'set ticscale '.
1649: $Apache::lonplot::plot{'major_ticscale'}.' '.$Apache::lonplot::plot{'minor_ticscale'}.$/;
1650: }
1.110 albertel 1651: #boxwidth
1652: if (lc($Apache::lonplot::plot{'boxwidth'}) ne '') {
1653: $gnuplot_input .= 'set boxwidth '.$Apache::lonplot::plot{'boxwidth'}.$/;
1654: }
1655: # gridlayer
1656: $gnuplot_input .= 'set grid noxtics noytics front '.$/
1657: if ($Apache::lonplot::plot{'gridlayer'} eq 'on');
1658:
1.7 matthew 1659: # grid
1.107 foxr 1660: $gnuplot_input .= 'set grid'.$/ if ($Apache::lonplot::plot{'grid'} eq 'on');
1.7 matthew 1661: # border
1.107 foxr 1662: $gnuplot_input .= ($Apache::lonplot::plot{'border'} eq 'on'?
1.9 matthew 1663: 'set border'.$/ :
1.67 matthew 1664: 'set noborder'.$/ );
1.77 matthew 1665: # sampling rate for non-data curves
1.107 foxr 1666: $gnuplot_input .= "set samples $Apache::lonplot::plot{'samples'}\n";
1.67 matthew 1667: # title, xlabel, ylabel
1.45 matthew 1668: # titles
1.125 albertel 1669: my $extra_space_x = ($xtics{'location'} eq 'axis') ? ' 0, -0.5 ' : '';
1670: my $extra_space_y = ($ytics{'location'} eq 'axis') ? ' -0.5, 0 ' : '';
1671:
1.89 matthew 1672: if ($target eq 'tex') {
1.125 albertel 1673: $gnuplot_input .= "set title \"$title\" font \"".$font_properties->{'printname'}.",".$fontsize."pt\"\n" if (defined($title)) ;
1674: $gnuplot_input .= "set xlabel \"$xlabel\" $extra_space_x font \"".$font_properties->{'printname'}.",".$fontsize."pt\"\n" if (defined($xlabel));
1675: $gnuplot_input .= "set ylabel \"$ylabel\" $extra_space_y font \"".$font_properties->{'printname'}.",".$fontsize."pt\"\n" if (defined($ylabel));
1.89 matthew 1676: } else {
1.125 albertel 1677: $gnuplot_input .= "set title \"$title\" \n" if (defined($title)) ;
1678: $gnuplot_input .= "set xlabel \"$xlabel\" $extra_space_x \n" if (defined($xlabel));
1679: $gnuplot_input .= "set ylabel \"$ylabel\" $extra_space_y \n" if (defined($ylabel));
1.89 matthew 1680: }
1.45 matthew 1681: # tics
1682: if (%xtics) {
1683: $gnuplot_input .= "set xtics $xtics{'location'} ";
1.46 matthew 1684: $gnuplot_input .= ( $xtics{'mirror'} eq 'on'?"mirror ":"nomirror ");
1.45 matthew 1685: $gnuplot_input .= "$xtics{'start'}, ";
1686: $gnuplot_input .= "$xtics{'increment'}, ";
1.146 foxr 1687: $gnuplot_input .= "$xtics{'end'} ";
1688: if ($target eq 'tex') {
1689: $gnuplot_input .= 'font "Helvetica,22"'; # Needed in iso 8859-1 enc.
1690: }
1691: $gnuplot_input .= "\n";
1.89 matthew 1692: if ($xtics{'minorfreq'} != 0) {
1693: $gnuplot_input .= "set mxtics ".$xtics{'minorfreq'}."\n";
1694: }
1.146 foxr 1695: } else {
1696: if ($target eq 'tex') {
1697: $gnuplot_input .= 'set xtics font "Helvetica,22"'."\n"; # needed in iso 8859-1 enc
1698: }
1.45 matthew 1699: }
1700: if (%ytics) {
1701: $gnuplot_input .= "set ytics $ytics{'location'} ";
1.46 matthew 1702: $gnuplot_input .= ( $ytics{'mirror'} eq 'on'?"mirror ":"nomirror ");
1.45 matthew 1703: $gnuplot_input .= "$ytics{'start'}, ";
1704: $gnuplot_input .= "$ytics{'increment'}, ";
1.146 foxr 1705: $gnuplot_input .= "$ytics{'end'} ";
1.148 raeburn 1706: if ($target eq 'tex') {
1707: $gnuplot_input .= 'font "Helvetica,22"'; # Needed in iso-8859-1 encoding.
1708: }
1709: $gnuplot_input .= "\n";
1.89 matthew 1710: if ($ytics{'minorfreq'} != 0) {
1711: $gnuplot_input .= "set mytics ".$ytics{'minorfreq'}."\n";
1712: }
1.146 foxr 1713: } else {
1714: if ($target eq 'tex') {
1715: $gnuplot_input .= 'set ytics font "Helvetica,22"'."\n"; # Needed for iso 8859-1 enc.
1716: }
1.45 matthew 1717: }
1718: # axis
1.23 matthew 1719: if (%axis) {
1.132 albertel 1720: if ($axis{'xformat'} ne 'on') {
1721: $gnuplot_input .= "set format x ";
1722: if ($axis{'xformat'} eq 'off') {
1723: $gnuplot_input .= "\"\"\n";
1724: } else {
1725: $gnuplot_input .= "\"\%.".$axis{'xformat'}."\"\n";
1726: }
1727: }
1728: if ($axis{'yformat'} ne 'on') {
1729: $gnuplot_input .= "set format y ";
1730: if ($axis{'yformat'} eq 'off') {
1731: $gnuplot_input .= "\"\"\n";
1732: } else {
1733: $gnuplot_input .= "\"\%.".$axis{'yformat'}."\"\n";
1734: }
1735: }
1.13 matthew 1736: $gnuplot_input .= "set xrange \[$axis{'xmin'}:$axis{'xmax'}\]\n";
1737: $gnuplot_input .= "set yrange \[$axis{'ymin'}:$axis{'ymax'}\]\n";
1.6 matthew 1738: }
1739: # Key
1.23 matthew 1740: if (%key) {
1.9 matthew 1741: $gnuplot_input .= 'set key '.$key{'pos'}.' ';
1742: if ($key{'title'} ne '') {
1.67 matthew 1743: $gnuplot_input .= 'title "'.$key{'title'}.'" ';
1.11 matthew 1744: }
1745: $gnuplot_input .= ($key{'box'} eq 'on' ? 'box ' : 'nobox ').$/;
1.6 matthew 1746: } else {
1.9 matthew 1747: $gnuplot_input .= 'set nokey'.$/;
1.13 matthew 1748: }
1.6 matthew 1749: # labels
1.10 matthew 1750: my $label;
1.6 matthew 1751: foreach $label (@labels) {
1752: $gnuplot_input .= 'set label "'.$label->{'text'}.'" at '.
1.134 raeburn 1753: $label->{'xpos'}.','.$label->{'ypos'};
1754: if ($label->{'rotate'} ne '') {
1755: $gnuplot_input .= ' rotate by '.$label->{'rotate'};
1756: }
1757: $gnuplot_input .= ' '.$label->{'justify'};
1758:
1.103 matthew 1759: if ($target eq 'tex') {
1.124 albertel 1760: $gnuplot_input .=' font "'.$font_properties->{'printname'}.','.$fontsize.'pt"' ;
1.103 matthew 1761: }
1762: $gnuplot_input .= $/;
1.6 matthew 1763: }
1.74 matthew 1764: if ($target eq 'tex') {
1.107 foxr 1765: $gnuplot_input .="set size 1,".$Apache::lonplot::plot{'height'}/$Apache::lonplot::plot{'width'}*1.38;
1.74 matthew 1766: $gnuplot_input .="\n";
1.120 albertel 1767: }
1.6 matthew 1768: # curves
1769: $gnuplot_input .= 'plot ';
1.9 matthew 1770: for (my $i = 0;$i<=$#curves;$i++) {
1771: $curve = $curves[$i];
1772: $gnuplot_input.= ', ' if ($i > 0);
1.119 albertel 1773: if ($target eq 'tex') {
1774: $curve->{'linewidth'} *= 2;
1775: }
1.6 matthew 1776: if (exists($curve->{'function'})) {
1.9 matthew 1777: $gnuplot_input.=
1778: $curve->{'function'}.' title "'.
1779: $curve->{'name'}.'" with '.
1.72 matthew 1780: $curve->{'linestyle'};
1.119 albertel 1781:
1.60 matthew 1782: if (($curve->{'linestyle'} eq 'points') ||
1783: ($curve->{'linestyle'} eq 'linespoints') ||
1784: ($curve->{'linestyle'} eq 'errorbars') ||
1785: ($curve->{'linestyle'} eq 'xerrorbars') ||
1786: ($curve->{'linestyle'} eq 'yerrorbars') ||
1787: ($curve->{'linestyle'} eq 'xyerrorbars')) {
1.62 matthew 1788: $gnuplot_input.=' pointtype '.$curve->{'pointtype'};
1.60 matthew 1789: $gnuplot_input.=' pointsize '.$curve->{'pointsize'};
1.110 albertel 1790: } elsif ($curve->{'linestyle'} eq 'filledcurves') {
1791: $gnuplot_input.= ' '.$curve->{'limit'};
1.135 faziophi 1792: } elsif ($curve->{'linetype'} ne '' &&
1793: $curve->{'linestyle'} eq 'lines') {
1794: $gnuplot_input.= ' linetype ';
1795: $gnuplot_input.= $linetypes{$curve->{'linetype'}};
1796: $gnuplot_input.= ' linecolor rgb "';
1797: # convert color from xaaaaaa to #aaaaaa
1.136 raeburn 1798: $curve->{'color'} =~ s/^x/#/;
1.135 faziophi 1799: $gnuplot_input.= $curve->{'color'}.'"';
1.60 matthew 1800: }
1.131 albertel 1801: $gnuplot_input.= ' linewidth '.$curve->{'linewidth'};
1802:
1.6 matthew 1803: } elsif (exists($curve->{'data'})) {
1.40 matthew 1804: # Store data values in $datatext
1805: my $datatext = '';
1806: # get new filename
1.70 matthew 1807: my $datafilename = "$tmpdir/$filename.data.$i";
1.40 matthew 1808: my $fh=Apache::File->new(">$datafilename");
1809: # Compile data
1.6 matthew 1810: my @Data = @{$curve->{'data'}};
1.9 matthew 1811: my @Data0 = @{$Data[0]};
1812: for (my $i =0; $i<=$#Data0; $i++) {
1.10 matthew 1813: my $dataset;
1.6 matthew 1814: foreach $dataset (@Data) {
1.9 matthew 1815: $datatext .= $dataset->[$i] . ' ';
1.6 matthew 1816: }
1.9 matthew 1817: $datatext .= $/;
1.6 matthew 1818: }
1.40 matthew 1819: # write file
1820: print $fh $datatext;
1.119 albertel 1821: close($fh);
1.40 matthew 1822: # generate gnuplot text
1823: $gnuplot_input.= '"'.$datafilename.'" title "'.
1824: $curve->{'name'}.'" with '.
1825: $curve->{'linestyle'};
1.62 matthew 1826: if (($curve->{'linestyle'} eq 'points') ||
1827: ($curve->{'linestyle'} eq 'linespoints') ||
1828: ($curve->{'linestyle'} eq 'errorbars') ||
1829: ($curve->{'linestyle'} eq 'xerrorbars') ||
1830: ($curve->{'linestyle'} eq 'yerrorbars') ||
1831: ($curve->{'linestyle'} eq 'xyerrorbars')) {
1832: $gnuplot_input.=' pointtype '.$curve->{'pointtype'};
1833: $gnuplot_input.=' pointsize '.$curve->{'pointsize'};
1.110 albertel 1834: } elsif ($curve->{'linestyle'} eq 'filledcurves') {
1835: $gnuplot_input.= ' '.$curve->{'limit'};
1.135 faziophi 1836: } elsif ($curve->{'linetype'} ne '' &&
1837: $curve->{'linestyle'} eq 'lines') {
1838: $gnuplot_input.= ' linetype ';
1839: $gnuplot_input.= $linetypes{$curve->{'linetype'}};
1840: $gnuplot_input.= ' linecolor rgb "';
1841: # convert color from xaaaaaa to #aaaaaa
1.136 raeburn 1842: $curve->{'color'} =~ s/^x/#/;
1.135 faziophi 1843: $gnuplot_input.= $curve->{'color'}.'"';
1.62 matthew 1844: }
1.135 faziophi 1845: $gnuplot_input.= ' linewidth '.$curve->{'linewidth'};
1.6 matthew 1846: }
1847: }
1.40 matthew 1848: # Write the output to a file.
1.128 albertel 1849: open (my $fh,">$tmpdir$filename.data");
1850: binmode($fh, ":utf8");
1.40 matthew 1851: print $fh $gnuplot_input;
1852: close($fh);
1853: # That's all folks.
1854: return ;
1.2 matthew 1855: }
1.21 matthew 1856:
1857: #---------------------------------------------- check_inputs
1858: sub check_inputs {
1859: ## Note: no inputs, no outputs - this acts only on global variables.
1860: ## Make sure we have all the input we need:
1.107 foxr 1861: if (! %Apache::lonplot::plot) { &set_defaults(\%Apache::lonplot::plot,\%gnuplot_defaults); }
1.23 matthew 1862: if (! %key ) {} # No key for this plot, thats okay
1.34 matthew 1863: # if (! %axis) { &set_defaults(\%axis,\%axis_defaults); }
1.21 matthew 1864: if (! defined($title )) {} # No title for this plot, thats okay
1865: if (! defined($xlabel)) {} # No xlabel for this plot, thats okay
1866: if (! defined($ylabel)) {} # No ylabel for this plot, thats okay
1867: if ($#labels < 0) { } # No labels for this plot, thats okay
1868: if ($#curves < 0) {
1869: &Apache::lonxml::warning("No curves specified for plot!!!!");
1870: return '';
1871: }
1872: my $curve;
1873: foreach $curve (@curves) {
1874: if (!defined($curve->{'function'})&&!defined($curve->{'data'})){
1.85 matthew 1875: &Apache::lonxml::warning("One of the curves specified did not contain any curve data or curve function declarations\n");
1.21 matthew 1876: return '';
1877: }
1878: }
1879: }
1880:
1.20 matthew 1881: #------------------------------------------------ make_edit
1882: sub edit_attributes {
1.34 matthew 1883: my ($target,$token,$defaults,$keys) = @_;
1884: my ($result,@keys);
1885: if ($keys && ref($keys) eq 'ARRAY') {
1886: @keys = @$keys;
1887: } else {
1888: @keys = sort(keys(%$defaults));
1889: }
1890: foreach my $attr (@keys) {
1.35 matthew 1891: # append a ' ' to the description if it doesn't have one already.
1892: my $description = $defaults->{$attr}->{'description'};
1893: $description .= ' ' if ($description !~ / $/);
1.20 matthew 1894: if ($defaults->{$attr}->{'edit_type'} eq 'entry') {
1.35 matthew 1895: $result .= &Apache::edit::text_arg
1.38 matthew 1896: ($description,$attr,$token,
1897: $defaults->{$attr}->{'size'});
1.20 matthew 1898: } elsif ($defaults->{$attr}->{'edit_type'} eq 'choice') {
1.102 albertel 1899: $result .= &Apache::edit::select_or_text_arg
1.35 matthew 1900: ($description,$attr,$defaults->{$attr}->{'choices'},$token);
1.45 matthew 1901: } elsif ($defaults->{$attr}->{'edit_type'} eq 'onoff') {
1.102 albertel 1902: $result .= &Apache::edit::select_or_text_arg
1.35 matthew 1903: ($description,$attr,['on','off'],$token);
1.20 matthew 1904: }
1.25 matthew 1905: $result .= '<br />';
1.20 matthew 1906: }
1907: return $result;
1908: }
1.1 matthew 1909:
1.21 matthew 1910:
1911: ###################################################################
1912: ## ##
1913: ## Insertion functions for editing plots ##
1914: ## ##
1915: ###################################################################
1916:
1.47 matthew 1917: sub insert_gnuplot {
1.29 matthew 1918: my $result = '';
1.20 matthew 1919: # plot attributes
1.61 matthew 1920: $result .= "\n<gnuplot ";
1.47 matthew 1921: foreach my $attr (keys(%gnuplot_defaults)) {
1.61 matthew 1922: $result .= "\n $attr=\"$gnuplot_defaults{$attr}->{'default'}\"";
1.20 matthew 1923: }
1.61 matthew 1924: $result .= ">";
1.47 matthew 1925: # Add the components (most are commented out for simplicity)
1.44 matthew 1926: # $result .= &insert_key();
1927: # $result .= &insert_axis();
1928: # $result .= &insert_title();
1929: # $result .= &insert_xlabel();
1930: # $result .= &insert_ylabel();
1.20 matthew 1931: $result .= &insert_curve();
1.50 matthew 1932: # close up the <gnuplot>
1.61 matthew 1933: $result .= "\n</gnuplot>";
1.45 matthew 1934: return $result;
1935: }
1936:
1.46 matthew 1937: sub insert_tics {
1938: my $result;
1939: $result .= &insert_xtics() . &insert_ytics;
1940: return $result;
1941: }
1942:
1.45 matthew 1943: sub insert_xtics {
1944: my $result;
1.46 matthew 1945: $result .= "\n <xtics ";
1.45 matthew 1946: foreach my $attr (keys(%tic_defaults)) {
1.61 matthew 1947: $result .= "\n $attr=\"$tic_defaults{$attr}->{'default'}\" ";
1.45 matthew 1948: }
1.61 matthew 1949: $result .= "/>";
1.45 matthew 1950: return $result;
1951: }
1952:
1953: sub insert_ytics {
1954: my $result;
1.46 matthew 1955: $result .= "\n <ytics ";
1.45 matthew 1956: foreach my $attr (keys(%tic_defaults)) {
1.61 matthew 1957: $result .= "\n $attr=\"$tic_defaults{$attr}->{'default'}\" ";
1.45 matthew 1958: }
1.61 matthew 1959: $result .= "/>";
1.20 matthew 1960: return $result;
1961: }
1962:
1963: sub insert_key {
1964: my $result;
1.61 matthew 1965: $result .= "\n <key ";
1.30 matthew 1966: foreach my $attr (keys(%key_defaults)) {
1.61 matthew 1967: $result .= "\n $attr=\"$key_defaults{$attr}->{'default'}\"";
1.20 matthew 1968: }
1.61 matthew 1969: $result .= " />";
1.20 matthew 1970: return $result;
1971: }
1972:
1973: sub insert_axis{
1974: my $result;
1.46 matthew 1975: $result .= "\n <axis ";
1.30 matthew 1976: foreach my $attr (keys(%axis_defaults)) {
1.61 matthew 1977: $result .= "\n $attr=\"$axis_defaults{$attr}->{'default'}\"";
1.20 matthew 1978: }
1.61 matthew 1979: $result .= " />";
1.20 matthew 1980: return $result;
1981: }
1.28 matthew 1982:
1.61 matthew 1983: sub insert_title { return "\n <title></title>"; }
1984: sub insert_xlabel { return "\n <xlabel></xlabel>"; }
1985: sub insert_ylabel { return "\n <ylabel></ylabel>"; }
1.20 matthew 1986:
1987: sub insert_label {
1988: my $result;
1.46 matthew 1989: $result .= "\n <label ";
1.30 matthew 1990: foreach my $attr (keys(%label_defaults)) {
1.61 matthew 1991: $result .= "\n $attr=\"".
1992: $label_defaults{$attr}->{'default'}."\"";
1.20 matthew 1993: }
1.61 matthew 1994: $result .= "></label>";
1.20 matthew 1995: return $result;
1996: }
1997:
1998: sub insert_curve {
1999: my $result;
1.41 matthew 2000: $result .= "\n <curve ";
1.30 matthew 2001: foreach my $attr (keys(%curve_defaults)) {
1.61 matthew 2002: $result .= "\n $attr=\"".
2003: $curve_defaults{$attr}->{'default'}."\"";
1.20 matthew 2004: }
1.61 matthew 2005: $result .= " >";
2006: $result .= &insert_data().&insert_data()."\n </curve>";
1.20 matthew 2007: }
1.4 matthew 2008:
1.20 matthew 2009: sub insert_function {
2010: my $result;
1.61 matthew 2011: $result .= "\n <function></function>";
1.20 matthew 2012: return $result;
2013: }
1.4 matthew 2014:
1.20 matthew 2015: sub insert_data {
2016: my $result;
1.61 matthew 2017: $result .= "\n <data></data>";
1.20 matthew 2018: return $result;
2019: }
1.4 matthew 2020:
1.48 matthew 2021: ##----------------------------------------------------------------------
1.20 matthew 2022: 1;
2023: __END__
1.4 matthew 2024:
2025:
1.149 jms 2026: =head1 NAME
2027:
2028: Apache::lonplot.pm
2029:
2030: =head1 SYNOPSIS
2031:
2032: XML-based plotter of graphs
2033:
2034: This is part of the LearningOnline Network with CAPA project
2035: described at http://www.lon-capa.org.
2036:
2037:
2038: =head1 SUBROUTINES (parsing and edit rendering)
2039:
2040: =over
2041:
2042: =item start_gnuplot()
2043:
2044: =item end_gnuplot()
2045:
2046: =item start_xtics()
2047:
2048: =item end_xtics()
2049:
2050: =item start_ytics()
2051:
2052: =item end_ytics()
2053:
2054: =item get_font()
2055:
2056: =item start_key()
2057:
2058: =item end_key()
2059:
2060: =item parse_label()
2061:
2062: =item replace_entities()
2063:
2064: =item start_title()
2065:
2066: =item end_title()
2067:
2068: =item start_xlabel()
2069:
2070: =item end_xlabel()
2071:
2072: =item start_ylabel()
2073:
2074: =item end_label()
2075:
2076: =item start_curve()
2077:
2078: =item end_curve()
2079:
2080: =item start_function()
2081:
2082: =item end_function()
2083:
2084: =item start_data()
2085:
2086: =item end_data()
2087:
2088: =item start_axis()
2089:
2090: =item end_axis
2091:
2092: =back
2093:
2094: =head1 SUBROUTINES (Utility)
2095:
2096: =over
2097:
2098: =item set_defaults()
2099:
2100: =item get_attributes()
2101:
2102: =item write_gnuplot_file()
2103:
2104: =item check_inputs()
2105:
2106: =item edit_attributes()
2107:
2108: =back
2109:
2110: =head1 SUBROUTINES (Insertion functions for editing plots)
2111:
2112: =over
2113:
2114: =item insert_gnuplot()
2115:
2116: =item insert_tics()
2117:
2118: =item insert_xtics()
2119:
2120: =item insert_key()
2121:
2122: =item insert_axis()
2123:
2124: =item insert_title()
2125:
2126: =item insert_xlabel()
2127:
2128: =item insert_ylabel()
2129:
2130: =item insert_label()
2131:
2132: =item insert_curve()
2133:
2134: =item insert_function()
2135:
2136: =item insert_data()
2137:
2138: =back
2139:
2140: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>