File:  [LON-CAPA] / loncom / xml / lonplot.pm
Revision 1.177: download - view: text, annotated - select for diffs
Sun Apr 2 21:38:15 2017 UTC (7 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, HEAD
- Coding style (indent is 4 spaces).

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

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