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

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

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