File:  [LON-CAPA] / loncom / xml / lonplot.pm
Revision 1.171: download - view: text, annotated - select for diffs
Mon Jan 21 02:25:38 2013 UTC (11 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Modify change in rev. 1.162.
  - Helvetica font is only available when target is tex
    (get "gdImageStringFT: Could not find/open font" errors if target is web).

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

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