int PLP_annotate() { char attr[NAMEMAXLEN], val[256]; char *line, *lineval; int nt, lvp; int first; int align; double adjx, adjy; double x, y; char textdetails[256]; char fromfile[256]; int fromfilemode; int nlines, maxlen; char box[256]; char backcolor[COLORLEN]; int verttext; double bm; char mapurl[MAXPATH]; double bevelsize, shadowsize; char lowbevelcolor[COLORLEN], hibevelcolor[COLORLEN], shadowcolor[COLORLEN]; int ioutline; char maplabel[MAXTT]; int clickmap_on; int do_ellipse; double bd_1, bd_2, bd_3, bd_4; int backdim; double cx, cy, px, py; int clip; TDH_errprog( "pl proc annotate" ); /* initialize */ strcpy( PL_bigbuf, "" ); strcpy( textdetails, "" ); strcpy( fromfile, "" ); fromfilemode = 0; x = 3.0; y = 3.0; arrowh = arrowt = 0; arrow2h = arrow2t = 0; strcpy( arrowdet, "" ); ahsize = 0.1; strcpy( box, "" ); strcpy( backcolor, "" ); verttext = 0; bm = 0.0; strcpy( mapurl, "" ); bevelsize = 0.0; shadowsize = 0.0; strcpy( lowbevelcolor, "0.6" ); strcpy( hibevelcolor, "0.8" ); strcpy( shadowcolor, "black" ); strcpy( maplabel, "" ); clickmap_on = 0; do_ellipse = 0; backdim = 0; clip = 0; /* get attributes.. */ first = 1; while( 1 ) { line = getnextattr( first, attr, val, &lvp, &nt ); if( line == NULL ) break; first = 0; lineval = &line[lvp]; if( stricmp( attr, "location" )==0 ) { getcoords( "location", lineval, &x, &y ); } else if( stricmp( attr, "text" )==0 ) getmultiline( "text", lineval, MAXBIGBUF, PL_bigbuf ); else if( stricmp( attr, "textdetails" )==0 ) strcpy( textdetails, lineval ); else if( stricmp( attr, "fromfile" )==0 ) { strcpy( fromfile, lineval ); fromfilemode = 1; } else if( stricmp( attr, "fromcommand" )==0 ) { strcpy( fromfile, lineval ); fromfilemode = 2; } else if( stricmp( attr, "arrowhead" )==0 ) { getcoords( "arrowhead", lineval, &ahx, &ahy ); arrowh = 1; } else if( stricmp( attr, "arrowtail" )==0 ) { getcoords( "arrowtail", lineval, &atx, &aty ); arrowt = 1; } else if( stricmp( attr, "arrowhead2" )==0 ) { getcoords( "arrowhead2", lineval, &ah2x, &ah2y ); arrow2h = 1; } else if( stricmp( attr, "arrowtail2" )==0 ) { getcoords( "arrowtail2", lineval, &at2x, &at2y ); arrow2t = 1; } else if( stricmp( attr, "arrowdetails" )==0 ) strcpy( arrowdet, lineval ); else if( stricmp( attr, "arrowheadsize" )==0 ) { ahsize = atof( val ); if( ahsize <= 0.0 ) ahsize = 0.0; /* no arrow */ if( PLS.usingcm ) ahsize /= 2.54; } else if( stricmp( attr, "box" )==0 || stricmp( attr, "outline" )==0 ) strcpy( box, lineval ); else if( stricmp( attr, "ellipse" )==0 ) { if( strnicmp( val, YESANS, 1 )==0 ) do_ellipse = 1; else do_ellipse = 0; } else if( stricmp( attr, "clickmapurl" )==0 ) { if( PLS.clickmap ) { strcpy( mapurl, val ); clickmap_on = 1; } } else if( stricmp( attr, "clickmaplabel" )==0 ) { if( PLS.clickmap ) { strcpy( maplabel, lineval ); clickmap_on = 1; } } else if( stricmp( attr, "clickmaplabeltext" )==0 ) { if( PLS.clickmap ) { getmultiline( "clickmaplabeltext", lineval, MAXTT, maplabel ); clickmap_on = 1; } } else if( stricmp( attr, "boxmargin" )==0 ) { bm = atof( val ); if( PLS.usingcm ) bm /= 2.54; } else if( stricmp( attr, "verttext" )==0 ) { if( strnicmp( val, YESANS, 1 )==0 ) verttext = 1; else verttext = 0; } else if( stricmp( attr, "backcolor" )==0 ) strcpy( backcolor, val ); else if( stricmp( attr, "bevelsize" )==0 ) bevelsize = atof( val ); else if( stricmp( attr, "shadowsize" )==0 ) shadowsize = atof( val ); else if( stricmp( attr, "lowbevelcolor" )==0 ) strcpy( lowbevelcolor, val ); else if( stricmp( attr, "hibevelcolor" )==0 ) strcpy( hibevelcolor, val ); else if( stricmp( attr, "shadowcolor" )==0 ) strcpy( shadowcolor, val ); else if( stricmp( attr, "backdim" )==0 ) { PL_getbox( "backdim", lineval, &bd_1, &bd_2, &bd_3, &bd_4 ); backdim = 1; } else if( stricmp( attr, "clip" )==0 ) { if( strnicmp( val, YESANS, 1 )==0 ) clip = 1; else clip = 0; } else Eerr( 1, "attribute not recognized", attr ); } if( fromfilemode > 0 ) file_to_buf( fromfile, fromfilemode, PL_bigbuf, MAXBIGBUF ); textdet( "textdetails", textdetails, &align, &adjx, &adjy, 0, "R", 1.0 ); if( align == '?' ) align = 'C'; px = x + adjx; py = y + adjy; /* figure backing box */ measuretext( PL_bigbuf, &nlines, &maxlen ); boxw = (maxlen+2) * Ecurtextwidth; boxh = (nlines*1.2) * Ecurtextheight; uly = py + Ecurtextheight; if( align == 'C' ) ulx = px - (boxw/2.0); else if( align == 'L' ) ulx = px; else if( align == 'R' ) ulx = px - boxw; if( bm != 0.0 ) { ulx -= bm; uly += bm; boxw += (bm*2); boxh += (bm*2); } if( clip ) PLG_pcodeboundingbox( 0 ); /* clip the annotation to the cropped size (by turning off bb) */ if( backcolor[0] != '\0' || ( box[0] != '\0' && strnicmp( box, "no", 2 )!= 0 ) ) { if( box[0] != '\0' && strnicmp( box, "no", 2 )!= 0 ) { ioutline = 1; linedet( "box", box, 0.5 ); } else ioutline = 0; if( do_ellipse ) { cx = ulx+(boxw/2.0); cy = uly-(boxh/2.0); if( backdim ) { cx = bd_1; cy = bd_2; boxw = bd_3; boxh = bd_4; } do_arrows(); /* do this before ellipse to get abutting edge */ PLG_ellipse( cx, cy, ((boxw/2.0)*1.3), ((boxh/2.0)*1.3), backcolor, ioutline ); } else { if( backdim ) { ulx = bd_1; uly = bd_2; boxw = bd_3; boxh = bd_4; } do_arrows(); /* do this before fill to get abutting edge */ Ecblock( ulx, (uly-boxh), ulx+boxw, uly, backcolor, ioutline ); if( bevelsize > 0.0 || shadowsize > 0.0 ) Ecblockdress( ulx, (uly-boxh), ulx+boxw, uly, bevelsize, lowbevelcolor, hibevelcolor, shadowsize, shadowcolor); } } else do_arrows(); if( clickmap_on ) { if( backdim && do_ellipse ) { /* need to solve back to ulx,uly in this case.. */ ulx = (((boxw/2.0)-cx)*-1.0); uly = (((boxw/2.0)-cy)*-1.0) + boxh; } clickmap_entry( 'r', mapurl, 0, ulx, (uly-boxh), ulx+boxw, uly, 1, 0, maplabel ); } /* now render the text.. */ textdet( "textdetails", textdetails, &align, &adjx, &adjy, 0, "R", 1.0 ); /* need to do again */ if( align == '?' ) align = 'C'; Emov( x + adjx, y + adjy ); if( verttext ) Etextdir( 90 ); Edotext( PL_bigbuf, align ); if( verttext ) Etextdir( 0 ); if( clip ) PLG_pcodeboundingbox( 1 ); /* restore */ return( 0 ); }
int PLP_pie() { char attr[NAMEMAXLEN], *line, *lineval; int lvp, first; char *labels, *outlinedetails, *lablinedetails, *labelmode, *mapurl, *maplabel, *textdetails; char *pctfmt, *labelback, *lblfmtstring, *expandedurl, *expandedlabel, *color1; char buf[256], color[MAXSLICE][40], lbl[256], pctstr[80]; int j, align, df, lblfld, ncolors, nexpl, ibb, colorfield, nlines; int maxlen, irow, ilabmode, labelbackoutline, exactcolorfield, wraplen; double expl[MAXSLICE]; double adjx, adjy, cx, cy, radius, theta, total, ux, uy, stop, starttheta, sin(), cos(); double fval, x, y, oldx, oldy, stheta, lblfarout, boxwid, boxhi, labx, laby, dval; TDH_errprog( "pl proc pie" ); /* initialize */ labels = ""; outlinedetails = ""; lablinedetails = ""; textdetails = ""; mapurl = ""; maplabel = ""; labelback = ""; lblfmtstring = ""; ncolors = 0; labelbackoutline = 0; wraplen = 0; nexpl = 0; theta = 0.0; cx = cy = -1.0; radius = -1.0; labelmode = "legend"; starttheta = 90.0 * TORAD; total = 0.0; lblfarout = 0.0; pctfmt = "%.1f"; lblfld = -1; colorfield = -1; exactcolorfield = -1; /* get attributes.. */ first = 1; while( 1 ) { line = getnextattr( first, attr, &lvp ); if( line == NULL ) break; first = 0; lineval = &line[lvp]; if( strcmp( attr, "datafield" )==0 ) df = fref( lineval ) -1 ; else if( strcmp( attr, "center" )==0 ) getcoords( "center", lineval, &cx, &cy ); else if( strcmp( attr, "radius" )==0 ) Elenex( lineval, X, &radius ); else if( strcmp( attr, "firstslice" )==0 ) starttheta = ((360-ftokncpy( lineval )) * TORAD ) + 90.0 * TORAD; else if( strcmp( attr, "total" )==0 ) total = ftokncpy( lineval ); else if( strcmp( attr, "clickmapurl" )==0 ) mapurl = lineval; else if( strcmp( attr, "clickmaplabel" )==0 ) maplabel = lineval; else if( strcmp( attr, "clickmaplabeltext" )==0 ) maplabel = getmultiline( lineval, "get" ); else if( strcmp( attr, "colors" )==0 ) { int i, ix; for( i = 0, ix = 0; i < MAXSLICE; i++ ) { strcpy( color[i], GL_getok( lineval, &ix ) ); if( color[i][0] == '\0' ) break; } ncolors = i; } else if( strcmp( attr, "labels" )==0 ) labels = getmultiline( lineval, "get" ); else if( strcmp( attr, "labelfield" )==0 ) lblfld = fref( lineval ) - 1; else if( strcmp( attr, "labelfmtstring" )==0 ) lblfmtstring = lineval; else if( strcmp( attr, "colorfield" )==0 ) colorfield = fref( lineval ) - 1; else if( strcmp( attr, "exactcolorfield" )==0 ) exactcolorfield = fref( lineval ) - 1; else if( strcmp( attr, "outlinedetails" )==0 ) outlinedetails = lineval; else if( strcmp( attr, "lablinedetails" )==0 ) lablinedetails = lineval; else if( strcmp( attr, "textdetails" )==0 ) textdetails = lineval; else if( strcmp( attr, "labelmode" )==0 ) labelmode = lineval; else if( strcmp( attr, "labelfarout" )==0 ) lblfarout = ftokncpy( lineval ); else if( strcmp( attr, "labelback" )==0 ) labelback = lineval; else if( strcmp( attr, "labelbackoutline" )==0 ) labelbackoutline = getyn( lineval ); else if( strcmp( attr, "pctformat" )==0 ) pctfmt = lineval; else if( strcmp( attr, "explode" )==0 ) { int i, ix; for( i = 0, ix = 0; i < MAXSLICE; i++ ) { strcpy( buf, GL_getok( lineval, &ix )); if( buf[0] == '\0' ) break; else expl[i] = atof( buf ); } nexpl = i; } else if( strcmp( attr, "wraplen" )==0 ) wraplen = itokncpy( lineval ); else Eerr( 1, "attribute not recognized", attr ); } /* overrides and degenerate cases */ /* -------------------------- */ if( Nrecords < 1 ) return( Eerr( 17, "No data has been read yet w/ proc getdata", "" ) ); if( df < 0 || df >= Nfields ) return( Eerr( 2840, "invalid datafield", "" ) ); if( cx < 0.0 || cy < 0.0 ) return( Eerr( 2841, "invalid center", "" ) ); if( radius < 0.0 || radius > 5.0 ) return( Eerr( 2842, "invalid radius", "" ) ); if( lblfarout < 0.001 && strncmp( labelmode, "label", 5 )==0 ) lblfarout = 0.67; if( lblfarout < 0.001 && strncmp( labelmode, "line", 4 )==0 ) lblfarout = 1.3; if( labelbackoutline && labelback[0] == '\0' ) labelback = Ecurbkcolor; /* now do the plotting work.. */ /* -------------------------- */ /* compute total.. */ if( total <= 0.0 ) { total = 0.0; for( irow = 0; irow < Nrecords; irow++ ) { total += atof( da( irow, df ) ); } } ibb = 0; if( strncmp( labelmode, "legend", 6 )==0 ) ilabmode = LEGEND; else if( strncmp( labelmode, "labelonly", 5 ) ==0 ) ilabmode = LABEL; else if( strncmp( labelmode, "line+label", 4 ) ==0 ) ilabmode = LINELABEL; else ilabmode = 0; for( j = 0; j < 2; j++ ) { /* first time - colors; 2nd time, lines */ theta = starttheta + 6.28319; if( j == 1 ) { /* set line details for outline.. */ linedet( "outlinedetails", outlinedetails, 0.5 ); } for( irow = 0; irow < Nrecords; irow++ ) { /* take val as % of total and convert to rads */ dval = atof( da( irow, df ) ); if( dval == 0.0 ) continue; /* prevent slice attempt on degenerate case - scg 7/21/03 */ fval = ( dval / total ) * 6.28319; stop = theta - fval; /* find (ux,uy), the point at the wedge of the slice, normalized to 0,0 center.. */ if( nexpl <= 0 ) { /* don't explode any slices */ ux = 0.0; uy = 0.0; } else if( irow >= nexpl ) { /* explode slice according to last explode value */ ux = (expl[nexpl-1]*radius) * cos( theta+(fval/-2.0) ); uy = (expl[nexpl-1]*radius) * sin( theta+(fval/-2.0) ); } else if( irow < nexpl ) { /* explode slice according to explode value [i] */ ux = (expl[irow]*radius) * cos( theta+(fval/-2.0) ); uy = (expl[irow]*radius) * sin( theta+(fval/-2.0) ); } first = 1; stheta = theta; if( j == 1 && strncmp( outlinedetails, "no", 2 )==0 ) /* break; */ goto DOLAB; /* changed again, scg 4/29/05 */ for( ; theta > stop; theta -= 0.03 ) { if( theta - stop < 0.03 ) theta = stop; x = cx + (radius * cos( theta )); y = cy + (radius * sin( theta )); if( j == 0 ) { if( first ) { first = 0; oldx = x; oldy = y; Emov( cx+ux, cy+uy ); Epath( x+ux, y+uy ); continue; } Epath( x+ux, y+uy ); oldx = x; oldy = y; } else if( j == 1 ) { if( first ) { Emov( cx+ux, cy+uy ); Elin( x+ux, y+uy ); first = 0; } Elin( x+ux, y+uy ); } } if( j == 1 ) Elin( cx+ux, cy+uy ); color1 = ""; if( j == 0 ) { Epath( cx+ux, cy+uy ); if( colorfield >=0 ) { color1 = PL_get_legent( da( irow, colorfield ) ); Ecolorfill( color1 ); } else if( exactcolorfield >= 0 ) { color1 = da( irow, exactcolorfield ); Ecolorfill( color1 ); } else if( strcmp( color[0], "auto" )==0 ) { color1 = Eicolor( irow ); Ecolorfill( color1 ); } else if( irow < ncolors ) Ecolorfill( color[irow] ); else if( ncolors > 0 ) Ecolorfill( color[ncolors-1] ); else Ecolorfill( "0.8" ); } /* labeling */ /* if doing legend, handle this during j == 0 because color is available; otherwise do labeling during j == 1 to avoid color fill obliterating labels.. */ DOLAB: if( ( j == 0 && ilabmode == LEGEND ) || ( j == 1 && ilabmode != 0 ) ) { strcpy( lbl, ""); sprintf( pctstr, pctfmt, (atof( da( irow, df ) ) / total)*100.0 ); if( PLS.bignumspacer ) rewritenums( pctstr ); /* added 4/5/03 */ if( lblfld >= 0 ) strcpy( lbl, da( irow, lblfld ) ); else if( labels != "" ) GL_getseg( lbl, labels, &ibb, "\n" ); else if( lblfmtstring[0] != '\0' ) { /* added scg 8/20/04 */ strcpy( buf, lblfmtstring ); GL_varsub( buf, "@PCT", pctstr ); do_subst( lbl, buf, irow, NORMAL ); } GL_varsub( lbl, "@PCT", pctstr ); convertnl( lbl ); /* allow @field substitutions into url */ if( PLS.clickmap && ( mapurl != "" || maplabel != "" )) { expandedurl = PL_bigbuf; expandedlabel = &PL_bigbuf[2000]; do_subst( expandedurl, mapurl, irow, URL_ENCODED ); do_subst( expandedlabel, maplabel, irow, NORMAL ); } /* if( ilabmode == LEGEND ) */ /* changed 7/14/03 scg */ if( j == 0 && ilabmode == LEGEND ) { if( color1[0] != '\0' ) PL_add_legent( LEGEND_COLOR, lbl, "", color1, "", "" ); else PL_add_legent( LEGEND_COLOR, lbl, "", color[irow], "", "" ); } else if( j == 1 && ilabmode == LABEL ) { double htheta; double x1, y1, x2, y2; int centerit = 0; htheta = stop + ((stheta - stop) / 2.0 ); x = cx + ( (radius * lblfarout) * cos( htheta ) ); y = cy + ( (radius * lblfarout) * sin( htheta ) ); if( wraplen ) GL_wraptext( lbl, wraplen ); /* added scg 8/16/05 */ measuretext( lbl, &nlines, &maxlen ); labx = x+ux; laby = y+uy; boxhi = nlines * Ecurtextheight; boxwid = (maxlen * Ecurtextwidth); if( (htheta >= 7.7 && htheta <= 8.2 ) || (htheta >= 4.5 && htheta <= 5.0 )) centerit = 1; if( centerit ) { x1 = labx-(boxwid/2.0); x2 = labx+(boxwid/2.0); } else if( x < cx ) { x1 = labx - boxwid; x2 = labx; } else { x1 = labx; x2 = labx + boxwid; } y1 = laby-boxhi; y2 = laby; if( labelback != "" ) Ecblock( x1-0.1, y1+(Ecurtextheight*0.6), x2+0.1, y2+Ecurtextheight, labelback, labelbackoutline ); textdet( "textdetails", textdetails, &align, &adjx, &adjy, -2,"R", 1.0 ); Emov( labx, laby ); if( !centerit && x < cx ) Erightjust( lbl ); else if( !centerit && x >= cx ) Etext( lbl ); else Ecentext( lbl ); if( PLS.clickmap && ( mapurl != "" || maplabel != "" )) clickmap_entry( 'r', expandedurl, 0, x1, y1+Ecurtextheight, x2, y2+Ecurtextheight, 1, 0, expandedlabel ); linedet( "linedetails", outlinedetails, 0.5 ); /* restore */ } /* else if( ilabmode == LINELABEL ) */ /* changed 7/14/03 scg */ else if( j == 1 && ilabmode == LINELABEL ) { double htheta, px, py, w, z; if( wraplen ) GL_wraptext( lbl, wraplen ); /* added scg 8/16/05 */ measuretext( lbl, &nlines, &maxlen ); boxwid = maxlen * Ecurtextwidth; boxhi = nlines * Ecurtextheight; w = radius * lblfarout; if( w < (1.1 * radius) ) z = lblfarout; else z = 1.1; htheta = stop + ((stheta - stop) / 2.0 ); px = cx + ( (radius * 0.9 ) * cos( htheta ) ); py = cy + ( (radius * 0.9 ) * sin( htheta ) ); x = cx + ( (radius * z ) * cos( htheta ) ); y = cy + ( (radius * z ) * sin( htheta ) ); linedet( "lablinedetails", lablinedetails, 0.5 ); Emov( px+ux, py+uy ); Elin( x+ux, y+uy ); if( x+ux < cx ) { Elin( (cx+ux)-w, y+uy ); textdet( "textdetails", textdetails, &align, &adjx, &adjy, -2,"R", 1.0 ); labx = ((cx+ux)-w)-0.1; laby = y+uy; if( labelback[0] != '\0' ) Ecblock( labx-boxwid-0.1, laby-boxhi+(Ecurtextheight*0.6), labx+0.1, laby+Ecurtextheight, labelback, labelbackoutline ); Emov( labx, laby ); Erightjust( lbl ); if( PLS.clickmap && ( mapurl != "" || maplabel != "" )) clickmap_entry( 'r', expandedurl, 0, labx-boxwid, laby-boxhi+Ecurtextheight, labx, laby+Ecurtextheight, 1, 0, expandedlabel ); } else { Elin( (cx+ux)+w, y+uy ); textdet( "textdetails", textdetails, &align, &adjx, &adjy, -2,"R", 1.0 ); labx = cx+ux+w+0.1; laby = y+uy; if( labelback[0] != '\0' ) Ecblock( labx-0.1, laby-boxhi+(Ecurtextheight*0.6), labx+boxwid+0.1, laby+Ecurtextheight, labelback, labelbackoutline ); Emov( labx, laby ); Etext( lbl ); if( PLS.clickmap && ( mapurl != "" || maplabel != "" )) clickmap_entry( 'r', expandedurl, 0, labx, laby-boxhi+Ecurtextheight, labx+boxwid, laby+Ecurtextheight, 1, 0, expandedlabel ); } linedet( "outlinedetails", outlinedetails, 0.5 ); /* restore */ } } theta = stop; } } return( 0 ); }
int PLP_page( ) { int lvp, first; char attr[NAMEMAXLEN], *line, *lineval; char buf[512], devval[20]; char *outfilename, *mapfilename, *titledet, *pagetitle, *url; int stat, nt, align, nlines, maxlen, landscapemode, dobackground, dopagebox, pagesizegiven, clickmap_enabled_here, tight, map; double adjx, adjy, scalex, scaley, sx, sy; TDH_errprog( "pl proc page" ); /* initialize */ landscapemode = PLS.landscape; /* from command line */ titledet = ""; outfilename = ""; mapfilename = ""; pagetitle = ""; dobackground = 1; dopagebox = 1; if( GL_member( PLS.device, "gesf" )) dopagebox = 0; /* bounding box shouldn't include entire page for gif , eps */ if( PLS.device == 'e' ) dobackground = 0; pagesizegiven = 0; strcpy( devval, "" ); scalex = scaley = 1.0; clickmap_enabled_here = 0; /* get attributes.. */ first = 1; while( 1 ) { line = getnextattr( first, attr, &lvp ); if( line == NULL ) break; first = 0; lineval = &line[lvp]; /* if an attribute is given on command line, it overrides anything here.. */ if( GL_slmember( attr, PLS.cmdlineparms )) continue; if( strcmp( attr, "landscape" )==0 && GL_slmember( "portrait", PLS.cmdlineparms )) continue; if( strcmp( attr, "outfilename" )==0 && GL_slmember( "o", PLS.cmdlineparms )) continue; if( strcmp( attr, "landscape" )==0 ) landscapemode = getyn( lineval ); else if( strcmp( attr, "title" )==0 ) pagetitle = getmultiline( lineval, "get" ); else if( strcmp( attr, "titledetails" )==0 ) titledet = lineval; else if( strcmp( attr, "color" )==0 ) tokncpy( Estandard_color, lineval, COLORLEN ); else if( strcmp( attr, "scale" )==0 ) { nt = sscanf( lineval, "%lf %lf", &scalex, &scaley ); if( nt == 1 ) scaley = scalex; } else if( strcmp( attr, "backgroundcolor" )==0 ) { tokncpy( Estandard_bkcolor, lineval, COLORLEN ); Ebackcolor( Estandard_bkcolor ); dobackground = 1; /* added scg 9/27/99 */ } else if( strcmp( attr, "linewidth" )==0 ) Estandard_lwscale = ftokncpy( lineval ); else if( strcmp( attr, "textsize" )==0 ) Estandard_textsize = itokncpy( lineval ); else if( strcmp( attr, "font" )==0 ) tokncpy( Estandard_font, lineval, FONTLEN ); else if( strcmp( attr, "dobackground" )==0 ) dobackground = getyn( lineval ); else if( strcmp( attr, "dopagebox" )==0 ) dopagebox = getyn( lineval ); else if( strcmp( attr, "tightcrop" )==0 ) { tight = getyn( lineval ); Etightbb( tight ); } else if( strncmp( attr, "crop", 4 )==0 ) { double cropx1, cropy1, cropx2, cropy2; nt = sscanf( lineval, "%lf %lf %lf %lf", &cropx1, &cropy1, &cropx2, &cropy2 ); if( nt != 4 ) Eerr( 2707, "usage: crop x1 y1 x2 y2 OR croprel left bottom right top", "" ); else { if( PLS.usingcm ) { cropx1 /= 2.54; cropy1 /= 2.54; cropx2 /= 2.54; cropy2 /= 2.54; } if( strcmp( attr, "croprel" )==0 ) Especifycrop( 2, cropx1, cropy1, cropx2, cropy2 ); /* relative to tight */ else Especifycrop( 1, cropx1, cropy1, cropx2, cropy2 ); /* absolute */ } } else if( strcmp( attr, "pixsize" ) ==0 ) { /* added scg 1/9/08 */ int reqwidth, reqheight; nt = sscanf( lineval, "%d %d", &reqwidth, &reqheight ); if( nt != 2 ) Eerr( 57233, "pixsize ignored.. it requires width and height (in pixels)", "" ); #ifndef NOGD PLGG_setimpixsize( reqwidth, reqheight ); #endif if( PLS.device != 'g' ) Eerr( 24795, "pixsize ignored.. it's only applicable when generating png/gif/jpeg images", "" ); } else if( strcmp( attr, "pagesize" )==0 ) { getcoords( "pagesize", lineval, &(PLS.winw), &(PLS.winh) ); pagesizegiven = 1; } else if( strcmp( attr, "outfilename" )==0 ) { outfilename = lineval; if( strlen( outfilename ) > MAXPATH-1 ) { PLS.skipout = 1; return( Eerr( 57932, "outfilename too long", "" ) ); } } else if( strncmp( attr, "mapfile", 7 )==0 ) { mapfilename = lineval; if( strlen( mapfilename ) > MAXPATH-1 ) { Eerr( 57932, "mapfile name too long", "" ); mapfilename = ""; } } else if( strcmp( attr, "clickmapdefault" )==0 ) { url = lineval; if( strlen( url ) > MAXURL-1 ) Eerr( 57933, "clickmapdefault url too long", "" ); else clickmap_setdefaulturl( url ); } else if( strcmp( attr, "map" )==0 ) { map = getyn( lineval ); if( map ) { PLS.clickmap = 1; clickmap_enabled_here = 1; }} else if( strcmp( attr, "csmap" )==0 ){ map = getyn( lineval ); if( map ) { PLS.clickmap = 2; clickmap_enabled_here = 1; }} else if( strcmp( attr, "outlabel" )==0 ) Esetoutlabel( lineval ); else Eerr( 1, "page attribute not recognized", attr ); } /* -------------------------- */ /* Page break logic.. */ /* -------------------------- */ if( PLS.npages == 0 ) { /* following 3 lines moved here from above - also replicated below. scg 10/31/00 */ if( scalex != 1.0 || scaley != 1.0 ) Esetglobalscale( scalex, scaley ); Egetglobalscale( &sx, &sy ); if( pagesizegiven ) Esetsize( PLS.winw * sx, PLS.winh * sy, PLS.winx, PLS.winy ); else if( landscapemode && !PLS.winsizegiven ) Esetsize( 11.0, 8.5, PLS.winx, PLS.winy ); /* landscape */ /* clickmap (must come before init for eg. svg - scg 2/7/05) */ if( clickmap_enabled_here ) { if( mapfilename[0] == '\0' ) { if( PLS.clickmap == 2 ) strcpy( PLS.mapfile, "stdout" ); /* csmap defaults to stdout.. scg 8/26/04 */ else if( PLS.outfile[0] != '\0' ) makeoutfilename( PLS.outfile, PLS.mapfile, 'm', 1); else strcpy( PLS.mapfile, "unnamed.map" ); } PL_clickmap_init(); #ifndef NOSVG /* must update this now too.. scg 2/7/05 */ if( PLS.device == 's' ) PLGS_setparms( PLS.debug, PLS.tmpname, PLS.clickmap ); #endif } else if( mapfilename[0] != '\0' ) strcpy( PLS.mapfile, mapfilename ); /* PPP */ /* initialize and give specified output file name .. */ if( outfilename[0] != '\0' ) Esetoutfilename( outfilename ); stat = Einit( PLS.device ); if( stat ) { PLS.skipout = 1; return( stat ); } /* set paper orientation */ if( landscapemode ) Epaper( 1 ); } else if( PLS.npages > 0 ) { if( GL_member( PLS.device, "gesf" )) { /* finish up current page before moving on to next one.. */ Eshow(); stat = Eendoffile(); if( stat ) return( stat ); /* now set file name for next page.. */ if( outfilename[0] != '\0' ) Esetoutfilename( outfilename ); else { makeoutfilename( PLS.outfile, buf, PLS.device, (PLS.npages)+1 ); if( PLS.debug ) fprintf( PLS.diagfp, "Setting output file name to %s\n", PLS.outfile ); Esetoutfilename( buf ); } if( PLS.clickmap ) { /* initialize a new click map file.. */ if( mapfilename[0] != '\0' ) strcpy( PLS.mapfile, mapfilename ); else makeoutfilename( PLS.outfile, PLS.mapfile, 'm', (PLS.npages)+1 ); PL_clickmap_init(); } /* perhaps set global scaling and/or page size for next page.. */ /* following 3 lines copied here from above - scg 10/31/00 */ if( scalex != 1.0 || scaley != 1.0 ) Esetglobalscale( scalex, scaley ); Egetglobalscale( &sx, &sy ); if( pagesizegiven ) Esetsize( PLS.winw * sx, PLS.winh * sy, PLS.winx, PLS.winy ); else if( landscapemode && !PLS.winsizegiven ) Esetsize( 11.0, 8.5, PLS.winx, PLS.winy ); /* landscape */ /* initialize next page.. */ stat = Einit( PLS.device ); if( stat ) return( stat ); } else if ( PLS.device == 'x' ) PL_do_x_button( "More.." ); else if ( GL_member( PLS.device, "pc" ) ) { Eprint(); if( landscapemode ) Epaper( 1 ); /* added scg 2/29/00 */ Elinetype( 0, 0.6, 1.0 ); /* added scg 9/20/99 */ } } (PLS.npages)++; /* -------------------------- */ /* now do other work.. */ /* -------------------------- */ /* do background.. */ /* if( dopagebox ) Ecblock( 0.0, 0.0, EWinx, EWiny, Ecurbkcolor, 0 ); */ /* does update bb */ if( dopagebox ) Ecblock( 0.0, 0.0, PLS.winw, PLS.winh, Ecurbkcolor, 0 ); /* does update bb */ else if( dobackground ) { /* EPS color=transparent - best to do nothing.. */ if( PLS.device == 'e' && strcmp( Ecurbkcolor, "transparent" )==0 ) ; else Eclr(); /* doesn't update bb */ } if( pagetitle[0] != '\0' ) { textdet( "titledetails", titledet, &align, &adjx, &adjy, 3, "B", 1.0 ); if( align == '?' ) align = 'C'; measuretext( pagetitle, &nlines, &maxlen ); if( align == 'L' ) Emov( 1.0 + adjx, (PLS.winh-0.8) + adjy ); else if ( align == 'C' ) Emov( (PLS.winw / 2.0 ) + adjx, (PLS.winh-0.8) + adjy ); else if( align == 'R' ) Emov( (PLS.winw-1.0) + adjx, (PLS.winh-0.8) + adjy ); Edotext( pagetitle, align ); } return( 0 ); }
int PLP_areadef() { int i; char attr[NAMEMAXLEN], val[256]; char *line, *lineval; int nt, lvp; int first; int stat; double xlo, xhi, ylo, yhi; char areaname[NAMEMAXLEN]; char xscaletype[50], yscaletype[50]; char title[256]; char title2[256]; char titledet[256]; char title2det[256]; char frame[256]; int nlines, maxlen; int doframe; int namedarea; int align; double adjx, adjy; int gotarea, gotxrange, gotyrange; int doxaxis, doyaxis; char areacolor[COLORLEN]; char xminstr[256], xmaxstr[120]; /* was xminstr[120] - needs bigger if big autorange datafield list given - scg 10/25/04 */ char yminstr[256], ymaxstr[120]; /* was yminstr[120] - '' - scg 10/25/04 */ double height, width; int locspec; char linebottom[256]; char lineside[256]; double autowf, autowmin, autowmax; double autohf, autohmin, autohmax; char mapurl[MAXPATH]; double cmadj; int docats; char maplabel[MAXTT]; int clickmap_on; TDH_errprog( "pl proc areadef" ); /* initialize */ strcpy( xscaletype, "linear" ); strcpy( yscaletype, "linear" ); strcpy( areaname, "standard" ); gotxrange = gotyrange = 0; if( PLS.device == 'c' || PLS.device == 'p' ) strcpy( areaname, "standardp" ); /* for sheet of paper */ strcpy( title, "" ); strcpy( title2, "" ); doframe = 0; strcpy( frame, "" ); strcpy( titledet, "" ); strcpy( title2det, "" ); namedarea = 1; /* doxaxis = doyaxis = 1; */ doxaxis = doyaxis = 0; strcpy( areacolor, "" ); strcpy( PL_bigbuf, "" ); height = 4.0; width = 6.0; xlo = 1.5; ylo = 5.0; locspec = 0; strcpy( xminstr, "" ); strcpy( xmaxstr, "" ); strcpy( yminstr, "" ); strcpy( ymaxstr, "" ); strcpy( linebottom, "" ); strcpy( lineside, "" ); gotarea = 1; autowf = 0.0; autowmin = 0.0; autowmax = 20.0; autohf = 0.0; autohmin = 0.0; autohmax = 20.0; strcpy( mapurl, "" ); strcpy( maplabel, "" ); docats = 0; clickmap_on = 0; /* get attributes.. */ first = 1; while( 1 ) { line = getnextattr( first, attr, val, &lvp, &nt ); if( line == NULL ) break; first = 0; lineval = &line[lvp]; if( stricmp( attr, "areaname" )==0 ) { strcpy( areaname, val ); gotarea = 1; } else if( stricmp( attr, "rectangle" )==0 ) { stat = getbox( "rectangle", lineval, &xlo, &ylo, &xhi, &yhi ); if( stat ) { PLS.skipout = 1; return( 1 ); } namedarea = 0; gotarea = 1; } else if( stricmp( attr, "box" )==0 ) { sscanf( lineval, "%lf %lf", &width, &height ); if( PLS.usingcm ) { width /= 2.54; height /= 2.54; } namedarea = 0; gotarea = 1; } else if( stricmp( attr, "location" )==0 ) { sscanf( lineval, "%lf %lf", &xlo, &ylo ); if( PLS.usingcm ) { xlo /= 2.54; ylo /= 2.54; } locspec = 1; } else if( stricmp( attr, "autowidth" )==0 ) { nt = sscanf( lineval, "%lf %lf %lf", &autowf, &autowmin, &autowmax ); } else if( stricmp( attr, "autoheight" )==0 ) { nt = sscanf( lineval, "%lf %lf %lf", &autohf, &autohmin, &autohmax ); } else if( stricmp( attr, "xrange" )==0 || stricmp( attr, "xautorange" )==0 ) { if( strnicmp( val, "datafield", 9 )==0 ) strcpy( xminstr, lineval ); else if( stricmp( val, "categories" )==0 ) { strcpy( xscaletype, val ); continue; } else { nt = sscanf( lineval, "%s %s", xminstr, xmaxstr ); if( nt != 2 ) { PLS.skipout = 1; return( Eerr( 105, "both min and max expected", "xrange" )); } } gotxrange = 1; } else if( stricmp( attr, "yrange" )==0 || stricmp( attr, "yautorange" )==0 ) { if( strnicmp( val, "datafield", 9 )==0 ) strcpy( yminstr, lineval ); else if( stricmp( val, "categories" )==0 ) { strcpy( yscaletype, val ); continue; } else { nt = sscanf( lineval, "%s %s", yminstr, ymaxstr ); if( nt != 2 ) { PLS.skipout = 1; return( Eerr( 105, "both min and max expected", "yrange" )); } } gotyrange = 1; } else if( stricmp( attr, "xscaletype" )==0 ) strcpy( xscaletype, lineval ); else if( stricmp( attr, "yscaletype" )==0 ) strcpy( yscaletype, lineval ); else if( stricmp( attr, "frame" )==0 ) { if( strnicmp( val, "no", 2 )==0 ) doframe = 0; else { strcpy( frame, lineval ); doframe = 1; } } else if( stricmp( attr, "title" )==0 ) { strcpy( title, lineval ); convertnl( title ); } else if( stricmp( attr, "title2" )==0 ) { strcpy( title2, lineval ); convertnl( title2 ); } else if( stricmp( attr, "titledetails" )==0 ) strcpy( titledet, lineval ); else if( stricmp( attr, "title2details" )==0 ) strcpy( title2det, lineval ); else if( stricmp( attr, "areacolor" )==0 ) strcpy( areacolor, val ); else if( stricmp( attr, "linebottom" )==0 ) { if( strnicmp( val, "no", 2 )!=0 ) strcpy( linebottom, lineval ); } else if( stricmp( attr, "lineside" )==0 ) { if( strnicmp( val, "no", 2 )!= 0 ) strcpy( lineside, lineval ); } else if( stricmp( attr, "clickmapurl" )==0 ) { if( PLS.clickmap ) { strcpy( mapurl, val ); clickmap_on = 1 ; } } else if( stricmp( attr, "clickmaplabel" )==0 ) { if( PLS.clickmap ) { strcpy( maplabel, lineval ); clickmap_on = 1 ; } } else if( stricmp( attr, "clickmaplabeltext" )==0 ) { if( PLS.clickmap ) { getmultiline( "clickmaplabeltext", lineval, MAXTT, maplabel ); clickmap_on = 1; } } else if( stricmp( attr, "axes" )==0 ) { if( stricmp( val, "none" )==0 ) { doxaxis = 0; doyaxis = 0; } else if( stricmp( val, "x" )==0 ) doxaxis = 1; else if( stricmp( val, "y" )==0 ) doyaxis = 1; else if( stricmp( val, "both" )==0 ) { doxaxis = 1; doyaxis = 1; } } else if( GL_slmember( attr, "?axis.stubs ?axis.selflocatingstubs" )) { if( strnicmp( attr, "xaxis.", 6 )==0 ) doxaxis = 1; if( strnicmp( attr, "yaxis.", 6 )==0 ) doyaxis = 1; if( GL_slmember( val, "none inc* dat*matic file datafield* list categories usecategories" )) ; else getmultiline( "stubtext", lineval, MAXBIGBUF-5, PL_bigbuf ); /* just to skip past it..*/ } else if( strnicmp( attr, "xaxis.", 6 )==0 ) { doxaxis = 1; continue; } else if( strnicmp( attr, "yaxis.", 6 )==0 ) { doyaxis = 1; continue; } else if( GL_slmember( attr, "axisline tic* minortic*" )) continue; else if( GL_slmember( attr, "?categories ?extracategory catcompmethod" )) { docats = 1; if( GL_slmember( attr, "?categories" ) && strnicmp( val, "datafield", 9 )!=0 ) getmultiline( "categories", lineval, MAXBIGBUF-5, PL_bigbuf ); /* skip over it.. */ if( attr[0] == 'x' ) strcpy( xscaletype, "categories" ); if( attr[0] == 'y' ) strcpy( yscaletype, "categories" ); } else Eerr( 1, "areadef attribute not recognized", attr ); } /* now do the plotting work.. */ PL_resetstacklist(); /* (obscure) - reset the bar graph list that tries to keep track of fields for automatic stacking */ /* go set up category sets if needed.. */ if( docats ) { PLP_categories(); TDH_errprog( "pl proc areadef" ); } if( stricmp( xscaletype, "categories" )==0 ) { if( PL_ncats('x') < 1 ) { PLS.skipout = 1; return( Eerr( 5972, "no x categories exist", "" ) ); } gotxrange = 1; /* note- categories could have been filled from a previous data set */ strcpy( xminstr, "0" ); sprintf( xmaxstr, "%d", PL_ncats('x')+1 ); } if( stricmp( yscaletype, "categories" )==0 ) { if( PL_ncats('y') < 1 ) { PLS.skipout = 1; return( Eerr( 5973, "no y categories exist", "" ) ); } gotyrange = 1; /* note- categories could have been filled from a previous data set */ strcpy( yminstr, "0" ); sprintf( ymaxstr, "%d", PL_ncats('y')+1 ); } if( locspec ) { /* location and box specified, calculate xhi and yhi.. */ xhi = xlo + width; yhi = ylo + height; } /* determine area.. */ if( namedarea ) { RETRY: strcat( areaname, " " ); for( i = 0; i < nareas; i++ ) { if( strnicmp( areas[i], areaname, strlen( areaname ) )==0 ) { if( Ecurpaper == 0 ) sscanf( areas[i], "%*s %lf %lf %lf %lf", &xlo, &ylo, &xhi, &yhi ); else if( Ecurpaper == 1 ) sscanf( areas[i], "%*s %*s %*s %*s %*s %lf %lf %lf %lf", &xlo, &ylo, &xhi, &yhi ); break; } } if( i == nareas ) { areaname[ strlen( areaname ) -1 ] = '\0'; Eerr( 110, "warning, areaname not recognized, using 'standard'..", areaname ); strcpy( areaname, "standard" ); goto RETRY; } } if( !gotarea && !locspec ) { /* && !locspec added scg 11/21/00 */ PLS.skipout = 1; return( Eerr( 130, "No plotting area has been specified", "" ) ); } if( !gotxrange ) { PLS.skipout = 1; return( Eerr( 130, "No xrange has been specified", "" ) ); } if( !gotyrange ) { PLS.skipout = 1; return( Eerr( 130, "No yrange has been specified", "" ) ); } /* set scaling type and special units if any.. */ stat = Escaletype( xscaletype, 'x' ); if( stat != 0 ) Escaletype( "linear", 'x' ); if( strnicmp( xscaletype, "log", 3 )==0 ) Esetunits( 'x', "linear" ); else Esetunits( 'x', xscaletype ); stat = Escaletype( yscaletype, 'y' ); if( stat != 0 ) Escaletype( "linear", 'y' ); if( strnicmp( yscaletype, "log", 3 )==0 ) Esetunits( 'y', "linear" ); else Esetunits( 'y', yscaletype ); /* if autoranging is specified, do it now.. */ if( strnicmp( xminstr, "datafield", 9 ) == 0 ) PLP_autorange( 'x', xminstr, xminstr, xmaxstr ); if( strnicmp( yminstr, "datafield", 9 ) == 0 ) PLP_autorange( 'y', yminstr, yminstr, ymaxstr ); /* if scaletype is log but there are data values = 0.0, go to log+1 scaling.. */ if( stricmp( xscaletype, "log" )==0 && atof( xminstr ) <= 0.0 ) Escaletype( "log+1", 'x' ); if( stricmp( yscaletype, "log" )==0 && atof( yminstr ) <= 0.0 ) Escaletype( "log+1", 'y' ); /* if using autowidth or autoheight, revise plotting area now.. */ if( autowf != 0.0 ) { double xmin, xmax; if( stricmp( xscaletype, "categories" )== 0 ) { xmin = atof( xminstr ); xmax = atof( xmaxstr ); } else { xmin = Econv( 'x', xminstr ); xmax = Econv( 'x', xmaxstr ); } xhi = xlo + ((xmax-xmin) * autowf); if( xhi - xlo < autowmin ) xhi = xlo + autowmin; else if( xhi - xlo > autowmax ) xhi = xlo + autowmax; } if( autohf != 0.0 ) { double ymin, ymax; if( stricmp( yscaletype, "categories" )== 0 ) { ymin = atof( yminstr ); ymax = atof( ymaxstr ); } else { ymin = Econv( 'y', yminstr ); ymax = Econv( 'y', ymaxstr ); } yhi = ylo + ((ymax-ymin) * autohf); if( yhi - ylo < autohmin ) yhi = ylo + autohmin; else if( yhi - ylo > autohmax ) yhi = ylo + autohmax; } /* set the scaling for the plot area.. */ stat = Esetscale( 'x', xlo, xhi, xminstr, xmaxstr ); stat += Esetscale( 'y', ylo, yhi, yminstr, ymaxstr ); if( PLS.debug ) fprintf( PLS.diagfp, "areadef: lowerleft: %g,%g upperright: %g,%g\n", xlo, ylo, xhi, yhi ); if( PLS.debug ) fprintf( PLS.diagfp, "areadef: xrange is %s to %s. yrange is %s to %s.\n", xminstr, xmaxstr, yminstr, ymaxstr ); if( stat != 0 ) return( stat ); DT_suppress_twin_warn( 0 ); /* set variables to hold plot area bounds and scale min/max.. */ if( PLS.usingcm ) cmadj = 2.54; else cmadj = 1.0; setfloatvar( "AREATOP", EYhi * cmadj ); setfloatvar( "AREABOTTOM", EYlo * cmadj ); setfloatvar( "AREALEFT", EXlo * cmadj ); setfloatvar( "AREARIGHT", EXhi * cmadj ); setcharvar( "XMIN", xminstr ); setcharvar( "XMAX", xmaxstr ); setcharvar( "YMIN", yminstr ); setcharvar( "YMAX", ymaxstr ); if( areacolor[0] != '\0' ) Ecblock( EXlo, EYlo, EXhi, EYhi, areacolor, 0 ); if( clickmap_on ) { if( GL_slmember( mapurl, "*@XVAL*" ) || GL_slmember( mapurl, "*@YVAL*" )) clickmap_seturlt( mapurl ); else clickmap_entry( 'r', mapurl, 0, EXlo, EYlo, EXhi, EYhi, 0, 0, maplabel ); } /* draw a frame of the graphics area */ if( doframe ) { if( stricmp( frame, "bevel" )==0 ) { Ecblockdress( EXlo, EYlo, EXhi, EYhi, 0.1, "0.6", "0.8", 0.0, "" ); } else { linedet( "frame", frame, 1.0 ); Ecblock( EXlo, EYlo, EXhi, EYhi, "", 1 ); } } /* draw bottom line */ if( linebottom[0] != '\0' ) { linedet( "linebottom", linebottom, 1.0 ); Emov( EXlo, EYlo ); Elin( EXhi, EYlo ); } /* draw side line */ if( lineside[0] != '\0' ) { linedet( "lineside", lineside, 1.0 ); Emov( EXlo, EYlo ); Elin( EXlo, EYhi ); } /* title */ if( title[0] != '\0' ) { textdet( "titledetails", titledet, &align, &adjx, &adjy, 0, "R", 1.0 ); measuretext( title, &nlines, &maxlen ); if( align == '?' ) align = 'L'; if( align == 'L' ) Emov( EXlo + adjx, EYhi + ((nlines-1) * Ecurtextheight ) + adjy + 0.02 ); else if( align == 'C' ) Emov( EXlo+((EXhi-EXlo) / 2.0 ) + adjx, EYhi + ((nlines-1) * Ecurtextheight ) +adjy + 0.02 ); else if( align == 'R' ) Emov( EXhi + adjx, EYhi + ((nlines-1) * Ecurtextheight ) +adjy + 0.02); Edotext( title, align ); } /* title 2 */ if( title2[0] != '\0' ) { textdet( "title2details", title2det, &align, &adjx, &adjy, 0, "R", 1.0 ); measuretext( title2, &nlines, &maxlen ); if( align == '?' ) align = 'L'; if( align == 'L' ) Emov( EXlo + adjx, EYhi + ((nlines-1) * Ecurtextheight ) + adjy + 0.02 ); else if( align == 'C' ) Emov( EXlo+((EXhi-EXlo) / 2.0 ) + adjx, EYhi + ((nlines-1) * Ecurtextheight ) +adjy + 0.02 ); else if( align == 'R' ) Emov( EXhi + adjx, EYhi + ((nlines-1) * Ecurtextheight ) +adjy + 0.02 ); Edotext( title2, align ); } if( doxaxis ) PLP_axis( 'x', 6 ); if( doyaxis ) PLP_axis( 'y', 6 ); return( 0 ); }