Annotation of loncom/xml/lonplot.pm, revision 1.141

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

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