[BACK]Return to tkcanvas.trm CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gnuplot / term

Annotation of OpenXM_contrib/gnuplot/term/tkcanvas.trm, Revision 1.1.1.3

1.1       maekawa     1: /*
1.1.1.3 ! ohara       2:  * $Id: tkcanvas.trm,v 1.6.2.5 2002/04/16 09:44:24 broeker Exp $
1.1       maekawa     3:  *
                      4:  */
                      5:
                      6: /* GNUPLOT - tkcanvas.trm */
                      7:
                      8: /*[
                      9:  * Copyright 1990 - 1993, 1998
                     10:  *
                     11:  * Permission to use, copy, and distribute this software and its
                     12:  * documentation for any purpose with or without fee is hereby granted,
                     13:  * provided that the above copyright notice appear in all copies and
                     14:  * that both that copyright notice and this permission notice appear
                     15:  * in supporting documentation.
                     16:  *
                     17:  * Permission to modify the software is granted, but not the right to
                     18:  * distribute the complete modified source code.  Modifications are to
                     19:  * be distributed as patches to the released version.  Permission to
                     20:  * distribute binaries produced by compiling modified sources is granted,
                     21:  * provided you
                     22:  *   1. distribute the corresponding source modifications from the
                     23:  *    released version in the form of a patch file along with the binaries,
                     24:  *   2. add special version identification to distinguish your version
                     25:  *    in addition to the base release version number,
                     26:  *   3. provide your name and address as the primary contact for the
                     27:  *    support of your modified version, and
                     28:  *   4. retain our contact information in regard to use of the base
                     29:  *    software.
                     30:  * Permission to distribute the released version of the source code along
                     31:  * with corresponding source modifications in the form of a patch file is
                     32:  * granted with same provisions 2 through 4 for binary distributions.
                     33:  *
                     34:  * This software is provided "as is" without express or implied warranty
                     35:  * to the extent permitted by applicable law.
                     36: ]*/
                     37:
                     38: /*
                     39:  * This file is included by ../term.c.
                     40:  *
                     41:  * This terminal driver supports:
                     42:  *  Tk/Tcl canvas widgets
                     43:  *
                     44:  * AUTHORS - original dxy.trm
                     45:  *  Martin Yii, eln557h@monu3.OZ
                     46:  *  Further modified Jan 1990 by Russell Lang, rjl@monu1.cc.monash.oz
                     47:  *
                     48:  * Port to the Tk/Tcl canvas widget
                     49:  *  D. Jeff Dionne, July 1995 jeff@ryeham.ee.ryerson.ca
                     50:  *  Alex Woo, woo@playfair.stanford.edu
                     51:  *
                     52:  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
                     53:  *
                     54:  */
                     55:
                     56: /*
                     57:  * adapted to the new terminal layout by Alex Woo (Sept. 1996)
                     58:  */
                     59:
1.1.1.2   maekawa    60: /*
                     61:  * extended interactive Tk/Tcl capabilities
                     62:  * Thomas Sefzick, March 1999, t.sefzick@fz-juelich.de
                     63:  *
                     64:  * added the perltk.trm code written by Slaven Rezic <eserte@cs.tu-berlin.de>,
                     65:  * the variable 'tk_perl' switches between tcl/tk and perltk code.
                     66:  * 'linewidth' and 'justify text' added, ends of plotted lines are now rounded.
                     67:  * if 'perltk' is chosen, perl code is produced, otherwise tcl code.
                     68:  * Thomas Sefzick, May 1999, t.sefzick@fz-juelich.de
                     69:  *
                     70:  * scale plot to fit into the actual size of the canvas as reported by
                     71:  * the window manager (the canvas itself doesn't report its real size).
                     72:  * Matt Willis, October 1999, mattbwillis@my-deja.com
                     73:  */
                     74:
1.1       maekawa    75: #include "driver.h"
                     76:
                     77: #ifdef TERM_REGISTER
                     78: register_term(tkcanvas)
                     79: #endif
                     80:
                     81: #ifdef TERM_PROTO
1.1.1.2   maekawa    82: TERM_PUBLIC void TK_options __PROTO((void));
1.1       maekawa    83: TERM_PUBLIC void TK_init __PROTO((void));
                     84: TERM_PUBLIC void TK_graphics __PROTO((void));
                     85: TERM_PUBLIC void TK_text __PROTO((void));
                     86: TERM_PUBLIC void TK_linetype __PROTO((int linetype));
                     87: TERM_PUBLIC void TK_move __PROTO((unsigned int x, unsigned int y));
                     88: TERM_PUBLIC void TK_vector __PROTO((unsigned int x, unsigned int y));
                     89: TERM_PUBLIC void TK_put_text __PROTO((unsigned int x, unsigned int y, char *str));
                     90: TERM_PUBLIC void TK_reset __PROTO((void));
1.1.1.2   maekawa    91: TERM_PUBLIC int TK_justify_text __PROTO((enum JUSTIFY));
                     92: TERM_PUBLIC int TK_set_font __PROTO((char *font));
                     93: TERM_PUBLIC void TK_linewidth __PROTO((double linewidth));
1.1       maekawa    94:
                     95: #define TK_XMAX 1000
                     96: #define TK_YMAX 1000
                     97:
                     98: #define TK_XLAST (TK_XMAX - 1)
                     99: #define TK_YLAST (TK_XMAX - 1)
                    100:
                    101: #define TK_VCHAR       (25)    /* double actual height of characters */
                    102: #define TK_HCHAR       (16)    /* actual width including spacing */
                    103: #define TK_VTIC        (18)
                    104: #define TK_HTIC        (18)
                    105: #endif /* TERM_PROTO */
                    106:
                    107: #ifndef TERM_PROTO_ONLY
                    108: #ifdef TERM_BODY
                    109:
1.1.1.2   maekawa   110: /* plot2d.c */
                    111: extern double min_array[], max_array[], base_array[], log_base_array[];
                    112: extern TBOOLEAN log_array[];
                    113: /* graphics.c */
                    114: extern int xleft, xright, ybot, ytop;
                    115: extern TBOOLEAN is_3d_plot;
                    116:
                    117: /* static int tk_angle = 0; unused, for now */
1.1       maekawa   118: static int tk_lastx;
                    119: static int tk_lasty;
                    120: static int tk_color = 0;
1.1.1.2   maekawa   121: static char tk_anchor[7] = "w";
                    122: static double tk_linewidth = 1.0;
                    123: static int tk_perl = 0;
                    124: static int tk_interactive = 0;
                    125: static char *tk_colors[] = {
                    126:     "black", "gray", "red", "blue", "green", "brown", "magenta", "cyan"
                    127: };
1.1       maekawa   128:
1.1.1.2   maekawa   129: TERM_PUBLIC void
                    130: TK_options()
1.1       maekawa   131: {
1.1.1.2   maekawa   132:     tk_perl = 0;
                    133:     tk_interactive = 0;
1.1       maekawa   134:
1.1.1.2   maekawa   135:     if (!END_OF_COMMAND) {
                    136:        if (almost_equals(c_token, "p$erltk")) {
                    137:            tk_perl = 1;
                    138:            c_token++;
                    139:        }
                    140:        if (almost_equals(c_token, "i$nteractive")) {
                    141:            tk_interactive = 1;
                    142:            c_token++;
                    143:        }
                    144:     }
                    145:
                    146:     sprintf(term_options, "%s %s",
                    147:            tk_perl ? "perltk" : "",
                    148:            tk_interactive ? "interactive" : "");
1.1       maekawa   149: }
                    150:
1.1.1.2   maekawa   151: TERM_PUBLIC void
                    152: TK_init()
1.1       maekawa   153: {
                    154: }
                    155:
1.1.1.2   maekawa   156: TERM_PUBLIC void
                    157: TK_graphics()
                    158: {
                    159:        /*
                    160:        * the resulting tcl or perl code takes the actual width and height
                    161:        * of the defined canvas and scales the plot to fit.
                    162:        * => NOTE: this makes 'set size' useless !!!
                    163:        * unless the original width and height is taken into account
                    164:        * by some tcl or perl code, that's why the 'gnuplot_plotarea' and
                    165:        * 'gnuplot_axisranges' procedures are supplied.
                    166:        */
                    167:     if (tk_perl) {
                    168:        fputs("\
1.1.1.3 ! ohara     169: sub {\n\
1.1.1.2   maekawa   170: my($can) = @_;\n\
                    171: $can->delete('all');\n\
1.1.1.3 ! ohara     172: my $cmx = $can->width - 2 * $can->cget(-border) - 2 * $can->cget(-highlightthickness);\n\
1.1.1.2   maekawa   173: if ($cmx <= 1) {\n$cmx = ($can->cget(-width));\n}\n\
1.1.1.3 ! ohara     174: my $cmy = $can->height - 2 * $can->cget(-border) - 2 * $can->cget(-highlightthickness);\n\
1.1.1.2   maekawa   175: if ($cmy <= 1) {\n$cmy = ($can->cget(-height));\n}\n",
                    176:              gpoutfile);
                    177:     } else {
                    178:        fputs("\
                    179: proc gnuplot can {\n\
                    180: $can delete all\n\
1.1.1.3 ! ohara     181: set cmx [expr [winfo width $can]-2*[$can cget -border]-2*[$can cget -highlightthickness]]\n\
1.1.1.2   maekawa   182: if {$cmx <= 1} {set cmx [$can cget -width]}\n\
1.1.1.3 ! ohara     183: set cmy [expr [winfo height $can]-2*[$can cget -border]-2*[$can cget -highlightthickness]]\n\
1.1.1.2   maekawa   184: if {$cmy <= 1} {set cmy [$can cget -height]}\n",
                    185:              gpoutfile);
                    186:     }
                    187:     tk_lastx = tk_lasty = tk_color = 0;
                    188: }
1.1       maekawa   189:
1.1.1.2   maekawa   190: TERM_PUBLIC void
                    191: TK_reset()
1.1       maekawa   192: {
                    193: }
                    194:
1.1.1.2   maekawa   195: TERM_PUBLIC void
                    196: TK_linetype(linetype)
1.1       maekawa   197: int linetype;
                    198: {
                    199:     tk_color = (linetype + 2) & 7;
                    200: }
                    201:
1.1.1.2   maekawa   202: TERM_PUBLIC void
                    203: TK_linewidth(linewidth)
                    204: double linewidth;
                    205: {
                    206:     tk_linewidth = linewidth;
                    207: }
                    208:
                    209: TERM_PUBLIC void
                    210: TK_move(x, y)
1.1       maekawa   211: unsigned int x, y;
                    212: {
                    213:     tk_lastx = x;
                    214:     tk_lasty = 1000 - y;
                    215: }
                    216:
1.1.1.2   maekawa   217: #define TK_REAL_VALUE(value,axis) \
                    218:  (log_array[axis])\
                    219:  ?pow(base_array[axis],min_array[axis]+value*(max_array[axis]-min_array[axis]))\
                    220:  :min_array[axis]+value*(max_array[axis]-min_array[axis])
                    221:
                    222: #define TK_X_VALUE(value) \
                    223:  (double)(value-xleft)/(double)(xright-xleft)
1.1       maekawa   224:
1.1.1.2   maekawa   225: #define TK_Y_VALUE(value) \
                    226:  (double)((TK_YMAX-value)-ybot)/(double)(ytop-ybot)
                    227:
                    228: TERM_PUBLIC void
                    229: TK_vector(x, y)
1.1       maekawa   230: unsigned int x, y;
                    231: {
1.1.1.2   maekawa   232:        /*
                    233:        * this is the 1st part of the wrapper around the 'create line' command
                    234:        * used to bind some actions to a line segment:
                    235:        * bind {
                    236:        *      normal create line command
                    237:        *      } gnuplot_xy(some coordinates)
                    238:        */
                    239:     if (tk_interactive && !is_3d_plot) {
                    240:        if (tk_perl)
                    241:            fprintf(gpoutfile, "$can->bind(");
                    242:        else
                    243:            fprintf(gpoutfile, "$can bind [\n");
                    244:     }
                    245:        /*
                    246:         * end of 1st part of wrapper
                    247:         */
1.1       maekawa   248:     y = 1000 - y;
1.1.1.2   maekawa   249:        /*
                    250:         * here is the basic well-known command for plotting a line segment
                    251:         */
                    252:     if (tk_perl) {
                    253:        fprintf(gpoutfile,"\
                    254: $can->createLine(\
                    255: $cmx * %d / 1000, \
                    256: $cmy * %d / 1000, \
                    257: $cmx * %d / 1000, \
                    258: $cmy * %d / 1000, -fill => q{%s}, -width => %f, -capstyle => q{round})",
                    259:                tk_lastx, tk_lasty, x, y, tk_colors[tk_color], tk_linewidth);
                    260:     } else {
                    261:        fprintf(gpoutfile,"\
                    262: $can create line \
                    263: [expr $cmx * %d /1000] \
                    264: [expr $cmy * %d /1000] \
                    265: [expr $cmx * %d /1000] \
                    266: [expr $cmy * %d /1000] -fill %s -width %f -capstyle round\n",
                    267:                tk_lastx, tk_lasty, x, y, tk_colors[tk_color], tk_linewidth);
                    268:     }
                    269:
                    270:        /*
                    271:         * this is the 2nd part of the wrapper around the 'create line'
                    272:         * command, it generates a mechanism which calls 'gnuplot_xy' for
                    273:         * the line segment pointed to by the mouse cursor when a mouse
                    274:         * button is pressed
                    275:         */
                    276:     if (tk_interactive && !is_3d_plot) {
                    277:        if (tk_perl) {
                    278:            /* Ev('W') not needed here, supplied anyhow, WHY ??? */
                    279:            fprintf(gpoutfile,"\
                    280: , '<Button>' => \
                    281: [\\&gnuplot_xy, %f, %f, %f, %f, %f, %f, %f, %f,",
                    282:                    TK_REAL_VALUE(TK_X_VALUE(tk_lastx), FIRST_X_AXIS),
                    283:                    TK_REAL_VALUE(TK_Y_VALUE(tk_lasty), FIRST_Y_AXIS),
                    284:                    TK_REAL_VALUE(TK_X_VALUE(tk_lastx), SECOND_X_AXIS),
                    285:                    TK_REAL_VALUE(TK_Y_VALUE(tk_lasty), SECOND_Y_AXIS),
                    286:                    TK_REAL_VALUE(TK_X_VALUE(x), FIRST_X_AXIS),
                    287:                    TK_REAL_VALUE(TK_Y_VALUE(y), FIRST_Y_AXIS),
                    288:                    TK_REAL_VALUE(TK_X_VALUE(x), SECOND_X_AXIS),
                    289:                    TK_REAL_VALUE(TK_Y_VALUE(y), SECOND_Y_AXIS));
                    290:            if (log_array[FIRST_X_AXIS]) {
                    291:                fprintf(gpoutfile, " %f,",
                    292:                        TK_REAL_VALUE(TK_X_VALUE(0.5 * (x + tk_lastx)), FIRST_X_AXIS));
                    293:            } else {
                    294:                fprintf(gpoutfile, " \"\",");
                    295:            }
                    296:            if (log_array[FIRST_Y_AXIS]) {
                    297:                fprintf(gpoutfile, " %f,",
                    298:                        TK_REAL_VALUE(TK_Y_VALUE(0.5 * (y + tk_lasty)), FIRST_Y_AXIS));
                    299:            } else {
                    300:                fprintf(gpoutfile, " \"\",");
                    301:            }
                    302:            if (log_array[SECOND_X_AXIS]) {
                    303:                fprintf(gpoutfile, " %f,",
                    304:                        TK_REAL_VALUE(TK_X_VALUE(0.5 * (x + tk_lastx)), SECOND_X_AXIS));
                    305:            } else {
                    306:                fprintf(gpoutfile, " \"\",");
                    307:            }
                    308:            if (log_array[SECOND_Y_AXIS]) {
                    309:                fprintf(gpoutfile, " %f",
                    310:                        TK_REAL_VALUE(TK_Y_VALUE(0.5 * (y + tk_lasty)), SECOND_Y_AXIS));
                    311:            } else {
                    312:                fprintf(gpoutfile, " \"\"");
                    313:            }
                    314:            fprintf(gpoutfile, "]);\n");
                    315:        } else {
                    316:            fprintf(gpoutfile,"\
                    317: ] <Button> \
                    318: \"gnuplot_xy %%W %f %f %f %f %f %f %f %f",
                    319:                    TK_REAL_VALUE(TK_X_VALUE(tk_lastx), FIRST_X_AXIS),
                    320:                    TK_REAL_VALUE(TK_Y_VALUE(tk_lasty), FIRST_Y_AXIS),
                    321:                    TK_REAL_VALUE(TK_X_VALUE(tk_lastx), SECOND_X_AXIS),
                    322:                    TK_REAL_VALUE(TK_Y_VALUE(tk_lasty), SECOND_Y_AXIS),
                    323:                    TK_REAL_VALUE(TK_X_VALUE(x), FIRST_X_AXIS),
                    324:                    TK_REAL_VALUE(TK_Y_VALUE(y), FIRST_Y_AXIS),
                    325:                    TK_REAL_VALUE(TK_X_VALUE(x), SECOND_X_AXIS),
                    326:                    TK_REAL_VALUE(TK_Y_VALUE(y), SECOND_Y_AXIS));
                    327:            if (log_array[FIRST_X_AXIS]) {
                    328:                fprintf(gpoutfile, " %f",
                    329:                        TK_REAL_VALUE(TK_X_VALUE(0.5 * (x + tk_lastx)), FIRST_X_AXIS));
                    330:            } else {
                    331:                fprintf(gpoutfile, " {}");
                    332:            }
                    333:            if (log_array[FIRST_Y_AXIS]) {
                    334:                fprintf(gpoutfile, " %f",
                    335:                        TK_REAL_VALUE(TK_Y_VALUE(0.5 * (y + tk_lasty)), FIRST_Y_AXIS));
                    336:            } else {
                    337:                fprintf(gpoutfile, " {}");
                    338:            }
                    339:            if (log_array[SECOND_X_AXIS]) {
                    340:                fprintf(gpoutfile, " %f",
                    341:                        TK_REAL_VALUE(TK_X_VALUE(0.5 * (x + tk_lastx)), SECOND_X_AXIS));
                    342:            } else {
                    343:                fprintf(gpoutfile, " {}");
                    344:            }
                    345:            if (log_array[SECOND_Y_AXIS]) {
                    346:                fprintf(gpoutfile, " %f",
                    347:                        TK_REAL_VALUE(TK_Y_VALUE(0.5 * (y + tk_lasty)), SECOND_Y_AXIS));
                    348:            } else {
                    349:                fprintf(gpoutfile, " {}");
                    350:            }
                    351:            fprintf(gpoutfile, "\"\n");
                    352:        }
                    353:     } else {
                    354:        if (tk_perl) {
                    355:            fprintf(gpoutfile, ";\n");
                    356:        }
                    357:     }
                    358:        /*
                    359:         * end of the wrapper
                    360:         */
1.1       maekawa   361:     tk_lastx = x;
                    362:     tk_lasty = y;
                    363: }
                    364:
1.1.1.2   maekawa   365: #undef TK_REAL_VALUE
                    366: #undef TK_X_VALUE
                    367: #undef TK_Y_VALUE
1.1       maekawa   368:
1.1.1.2   maekawa   369: TERM_PUBLIC void
                    370: TK_put_text(x, y, str)
1.1.1.3 ! ohara     371:     unsigned int x, y;
        !           372:     char *str;
1.1       maekawa   373: {
                    374:     y = 1000 - y;
1.1.1.2   maekawa   375:     if (tk_perl) {
                    376:        fprintf(gpoutfile,"\
                    377: $can->createText(\
                    378: $cmx * %d / 1000, \
                    379: $cmy * %d / 1000, \
                    380: -text => q{%s}, -fill => q{%s}, -anchor => '%s', \
                    381: (defined $font ? (-font => $font) : ()));\n",
                    382:                x, y, str, tk_colors[tk_color], tk_anchor);
                    383:     } else {
1.1.1.3 ! ohara     384:         /* Have to quote-protect '[' and ']' characters */
        !           385:         int i, newsize = 0;
        !           386:         char *quoted_str;
        !           387:
        !           388:         for (i=0; str[i] != '\0'; i++) {
        !           389:             if ((str[i] == '[') || (str[i] == ']'))
        !           390:                 newsize++;
        !           391:             newsize++;
        !           392:         }
        !           393:         quoted_str = gp_alloc(newsize + 1, "TK_put_text: quoted string");
        !           394:
        !           395:         for (i=0, newsize = 0; str[i] != '\0'; i++) {
        !           396:             if ((str[i] == '[') || (str[i] == ']'))
        !           397:                 quoted_str[newsize++] = '\\';
        !           398:             quoted_str[newsize++] = str[i];
        !           399:         }
        !           400:         quoted_str[newsize] = '\0';
1.1.1.2   maekawa   401:        fprintf(gpoutfile,"\
                    402: eval $can create text \
                    403: [expr $cmx * %d /1000] \
                    404: [expr $cmy * %d /1000] \
                    405: -text \\{%s\\} -fill %s -anchor %s\
                    406:  [expr [info exists font]?\"-font \\$font\":{}]\n",
1.1.1.3 ! ohara     407:                x, y, quoted_str, tk_colors[tk_color], tk_anchor);
        !           408:        free(quoted_str);
1.1.1.2   maekawa   409:     }
1.1       maekawa   410: }
                    411:
1.1.1.2   maekawa   412: TERM_PUBLIC int
                    413: TK_justify_text(anchor)
                    414: enum JUSTIFY anchor;
1.1       maekawa   415: {
1.1.1.2   maekawa   416:     int return_value;
                    417:
                    418:     switch (anchor) {
                    419:     case RIGHT:
                    420:        strcpy(tk_anchor, "e");
                    421:        return_value = TRUE;
                    422:        break;
                    423:     case CENTRE:
                    424:        strcpy(tk_anchor, "center");
                    425:        return_value = TRUE;
                    426:        break;
                    427:     case LEFT:
                    428:        strcpy(tk_anchor, "w");
                    429:        return_value = TRUE;
                    430:        break;
                    431:     default:
                    432:        strcpy(tk_anchor, "w");
                    433:        return_value = FALSE;
                    434:     }
                    435:     return return_value;
                    436: }
                    437:
                    438: TERM_PUBLIC int
                    439: TK_set_font(font)
                    440: char *font;
                    441: {
                    442:     if (!font || *font == NUL) {
                    443:        if (tk_perl)
                    444:            fputs("undef $font;\n", gpoutfile);
                    445:        else
                    446:            fputs("catch {unset $font}\n", gpoutfile);
                    447:     } else {
                    448:        char *name;
                    449:        int size = 0;
                    450:        size_t sep = strcspn(font, ",");
                    451:
                    452:        name = malloc(sep + 1);
                    453:        if (!name)
                    454:            return FALSE;
                    455:        strncpy(name, font, sep);
                    456:        name[sep] = NUL;
                    457:        if (sep < strlen(font))
                    458:            sscanf(&(font[sep + 1]), "%d", &size);
                    459:        if (tk_perl) {
                    460:            fprintf(gpoutfile,"\
                    461: if ($can->can('fontCreate')) {\n\
                    462: $font = $can->fontCreate(-family => q{%s}",
                    463:                    name);
                    464:            if (size)
                    465:                fprintf(gpoutfile, ", -size => %d", size);
                    466:            fputs(");\n}\n", gpoutfile);
                    467:        } else {
                    468:            fprintf(gpoutfile, "set font [font create -family %s", name);
                    469:            if (size)
                    470:                fprintf(gpoutfile, " -size %d", size);
                    471:            fputs("]\n", gpoutfile);
                    472:        }
                    473:        free(name);
                    474:     }
                    475:     return TRUE;
1.1       maekawa   476: }
                    477:
1.1.1.2   maekawa   478: TERM_PUBLIC void
                    479: TK_text()
                    480: {
                    481:        /*
                    482:        * when switching back to text mode some procedures are generated which
                    483:        * return important information about plotarea size and axis ranges:
                    484:        * 'gnuplot_plotarea' returns the plotarea size in tkcanvas units
                    485:        * 'gnuplot_axisranges' returns the min. and max. values of the axis
                    486:        * these are essentially needed to set the size of the canvas when the
                    487:        * axis scaling is important.
                    488:        * moreover, a procedure 'gnuplot_xy' is created which contains the
                    489:        * actions bound to line segments (see the above 'TK_vector' code):
                    490:        * if the user has defined a procedure named 'user_gnuplot_coordinates'
                    491:        * then 'gnuplot_xy' calls this procedure, otherwise is writes the
                    492:        * coordinates of the line segment the mouse cursor is pointing to
                    493:        * to standard output.
                    494:        */
                    495:     if (tk_perl) {
                    496:        fputs("};\n", gpoutfile);
                    497:        if (!is_3d_plot) {
                    498:            fputs("sub gnuplot_plotarea {\n", gpoutfile);
                    499:            fprintf(gpoutfile,
                    500:                    "return (%d, %d, %d, %d);\n",
                    501:                    xleft, xright, 1000 - ytop, 1000 - ybot);
                    502:            fputs("};\n", gpoutfile);
                    503:            fputs("sub gnuplot_axisranges {\n", gpoutfile);
                    504:            fprintf(gpoutfile,
                    505:                    "return (%f, %f, %f, %f, %f, %f, %f, %f);\n",
                    506:                    min_array[FIRST_X_AXIS], max_array[FIRST_X_AXIS],
                    507:                    min_array[FIRST_Y_AXIS], max_array[FIRST_Y_AXIS],
                    508:                    min_array[SECOND_X_AXIS], max_array[SECOND_X_AXIS],
                    509:                    min_array[SECOND_Y_AXIS], max_array[SECOND_Y_AXIS]);
                    510:            fputs("};\n", gpoutfile);
                    511:            if (tk_interactive) {
                    512:                fputs("sub gnuplot_xy {\n",
                    513:                      gpoutfile);
                    514:                fputs("my ($win, $x1s, $y1s, $x2s, $y2s, $x1e, $y1e, $x2e, $y2e, $x1m, $y1m, $x2m, $y2m) = @_;\n",
                    515:                      gpoutfile);
                    516:                fputs("if (defined &user_gnuplot_coordinates) {\n",
                    517:                      gpoutfile);
                    518:                fputs("my $id = $win->find('withtag', 'current');\n",
                    519:                      gpoutfile);
                    520:                fputs("user_gnuplot_coordinates $win, $id, $x1s, $y1s, $x2s, $y2s, $x1e, $y1e, $x2e, $y2e, $x1m, $y1m, $x2m, $y2m\n",
                    521:                      gpoutfile);
                    522:                fputs("} else {\n",
                    523:                      gpoutfile);
                    524:                fputs("if (length($x1m)>0) {print \" $x1m\";} else {print \" \", 0.5*($x1s+$x1e);}\n",
                    525:                      gpoutfile);
                    526:                fputs("if (length($y1m)>0) {print \" $y1m\";} else {print \" \", 0.5*($y1s+$y1e);}\n",
                    527:                      gpoutfile);
                    528:                fputs("if (length($x2m)>0) {print \" $x2m\";} else {print \" \", 0.5*($x2s+$x2e);}\n",
                    529:                      gpoutfile);
                    530:                fputs("if (length($y2m)>0) {print \" $y2m\";} else {print \" \", 0.5*($y2s+$y2e);}\n",
                    531:                      gpoutfile);
                    532:                fputs("print \"\\n\"\n",
                    533:                      gpoutfile);
                    534:                fputs("}\n",
                    535:                      gpoutfile);
                    536:                fputs("};\n", gpoutfile);
                    537:            }
                    538:        }
                    539:     } else {
                    540:        fputs("}\n", gpoutfile);
                    541:        if (!is_3d_plot) {
                    542:            fputs("proc gnuplot_plotarea {} {\n", gpoutfile);
                    543:            fprintf(gpoutfile,
                    544:                    "return {%d %d %d %d}\n",
                    545:                    xleft, xright, 1000 - ytop, 1000 - ybot);
                    546:            fputs("}\n", gpoutfile);
                    547:            fputs("proc gnuplot_axisranges {} {\n", gpoutfile);
                    548:            fprintf(gpoutfile,
                    549:                    "return {%f %f %f %f %f %f %f %f}\n",
                    550:                    min_array[FIRST_X_AXIS], max_array[FIRST_X_AXIS],
                    551:                    min_array[FIRST_Y_AXIS], max_array[FIRST_Y_AXIS],
                    552:                    min_array[SECOND_X_AXIS], max_array[SECOND_X_AXIS],
                    553:                    min_array[SECOND_Y_AXIS], max_array[SECOND_Y_AXIS]);
                    554:            fputs("}\n", gpoutfile);
                    555:            if (tk_interactive) {
                    556:                fputs("proc gnuplot_xy {win x1s y1s x2s y2s x1e y1e x2e y2e x1m y1m x2m y2m} {\n",
                    557:                      gpoutfile);
                    558:                fputs("if {([llength [info commands user_gnuplot_coordinates]])} {\n",
                    559:                      gpoutfile);
                    560:                fputs("set id [$win find withtag current]\n",
                    561:                      gpoutfile);
                    562:                fputs("user_gnuplot_coordinates $win $id $x1s $y1s $x2s $y2s $x1e $y1e $x2e $y2e $x1m $y1m $x2m $y2m\n",
                    563:                      gpoutfile);
                    564:                fputs("} else {\n", gpoutfile);
                    565:                fputs("if {[string length $x1m]>0} {puts -nonewline \" $x1m\"} else {puts -nonewline \" [expr 0.5*($x1s+$x1e)]\"}\n",
                    566:                      gpoutfile);
                    567:                fputs("if {[string length $y1m]>0} {puts -nonewline \" $y1m\"} else {puts -nonewline \" [expr 0.5*($y1s+$y1e)]\"}\n",
                    568:                      gpoutfile);
                    569:                fputs("if {[string length $x2m]>0} {puts -nonewline \" $x2m\"} else {puts -nonewline \" [expr 0.5*($x2s+$x2e)]\"}\n",
                    570:                      gpoutfile);
                    571:                fputs("if {[string length $y2m]>0} {puts \" $y2m\"} else {puts \" [expr 0.5*($y2s+$y2e)]\"}\n",
                    572:                      gpoutfile);
                    573:                fputs("}\n", gpoutfile);
                    574:                fputs("}\n", gpoutfile);
                    575:            }
                    576:        }
                    577:     }
                    578:     fflush(gpoutfile);
                    579: }
1.1       maekawa   580:
                    581: #endif /* TERM_BODY */
                    582:
                    583: #ifdef TERM_TABLE
1.1.1.2   maekawa   584:
1.1       maekawa   585: TERM_TABLE_START(tkcanvas)
1.1.1.2   maekawa   586:     "tkcanvas", "Tk/Tcl canvas widget [perltk] [interactive]",
1.1       maekawa   587:     TK_XMAX, TK_YMAX, TK_VCHAR, TK_HCHAR,
1.1.1.2   maekawa   588:     TK_VTIC, TK_HTIC, TK_options, TK_init, TK_reset,
1.1       maekawa   589:     TK_text, null_scale, TK_graphics, TK_move, TK_vector,
                    590:     TK_linetype, TK_put_text, null_text_angle,
1.1.1.2   maekawa   591:     TK_justify_text, do_point, do_arrow, TK_set_font,
                    592:     NULL, 0, NULL, NULL, NULL, TK_linewidth
1.1       maekawa   593: TERM_TABLE_END(tkcanvas)
                    594: #undef LAST_TERM
                    595: #define LAST_TERM tkcanvas
                    596:
                    597: #endif /* TERM_TABLE */
                    598: #endif /* TERM_PROTO_ONLY */
                    599:
                    600: #ifdef TERM_HELP
                    601: START_HELP(tkcanvas)
                    602: "1 tkcanvas",
                    603: "?commands set terminal tkcanvas",
                    604: "?set terminal tkcanvas",
                    605: "?set term tkcanvas",
                    606: "?terminal tkcanvas",
                    607: "?term tkcanvas",
                    608: "?tkcanvas",
1.1.1.2   maekawa   609: " This terminal driver generates Tk canvas widget commands based on Tcl/Tk",
                    610: " (default) or Perl.  To use it, rebuild `gnuplot` (after uncommenting or",
                    611: " inserting the appropriate line in \"term.h\"), then",
1.1       maekawa   612: "",
1.1.1.2   maekawa   613: "  gnuplot> set term tkcanvas {perltk} {interactive}",
1.1       maekawa   614: "  gnuplot> set output 'plot.file'",
                    615: "",
1.1.1.2   maekawa   616: " After invoking \"wish\", execute the following sequence of Tcl/Tk commands:",
1.1       maekawa   617: "",
                    618: "  % source plot.file",
                    619: "  % canvas .c",
                    620: "  % pack .c",
                    621: "  % gnuplot .c",
                    622: "",
1.1.1.2   maekawa   623: " Or, for Perl/Tk use a program like this:",
                    624: "",
                    625: "  use Tk;",
                    626: "  my $top = MainWindow->new;",
1.1.1.3 ! ohara     627: "  my $c = $top->Canvas->pack;",
        !           628: "  my $gnuplot = do \"plot.pl\";",
        !           629: "  $gnuplot->($c);",
1.1.1.2   maekawa   630: "  MainLoop;",
                    631: "",
                    632: " The code generated by `gnuplot` creates a procedure called \"gnuplot\"",
                    633: " that takes the name of a canvas as its argument.  When the procedure is",
1.1       maekawa   634: " called, it clears the canvas, finds the size of the canvas and draws the plot",
                    635: " in it, scaled to fit.",
1.1.1.2   maekawa   636: "",
                    637: " For 2-dimensional plotting (`plot`) two additional procedures are defined:",
                    638: " \"gnuplot_plotarea\" will return a list containing the borders of the plotting",
                    639: " area \"xleft, xright, ytop, ybot\" in canvas screen coordinates, while the ranges",
                    640: " of the two axes \"x1min, x1max, y1min, y1max, x2min, x2max, y2min, y2max\" in plot",
                    641: " coordinates can be obtained calling \"gnuplot_axisranges\".",
                    642: " If the \"interactive\" option is specified, mouse clicking on a line segment",
                    643: " will print the coordinates of its midpoint to stdout. Advanced actions",
                    644: " can happen instead if the user supplies a procedure named",
                    645: " \"user_gnuplot_coordinates\", which takes the following arguments:",
                    646: " \"win id x1s y1s x2s y2s x1e y1e x2e y2e x1m y1m x2m y2m\",",
                    647: " the name of the canvas and the id of the line segment followed by the",
                    648: " coordinates of its start and end point in the two possible axis ranges; the",
                    649: " coordinates of the midpoint are only filled for logarithmic axes.",
1.1       maekawa   650: "",
                    651: " The current version of `tkcanvas` supports neither `multiplot` nor `replot`."
                    652: END_HELP(tkcanvas)
                    653: #endif

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