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

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

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