📄 psaxesbox.c
字号:
/* Copyright (c) Colorado School of Mines, 2006.*//* All rights reserved. *//*********************** self documentation **********************//*****************************************************************************PSAXESBOX - Functions to draw PostScript axes and estimate bounding boxpsAxesBox Draw an axes box via PostScriptpsAxesBBox estimate bounding box for an axes box drawn via psAxesBox******************************************************************************Function Prototypes:void psAxesBox( float x, float y, float width, float height, float x1Beg, float x1End, float p1Beg, float p1End, float d1Num, float f1Num, int n1Tic, int grid1, char *label1, float x2Beg, float x2End, float p2Beg, float p2End, float d2Num, float f2Num, int n2Tic, int grid2, char *label2, char *labelFont, float labelSize, char *title, char *titleFont, float titleSize, char *titleColor, char *axesColor, char *gridColor, float ticwidth, float axeswidth, float gridwidth, int style);void psAxesBBox( float x, float y, float width, float height, char *labelFont, float labelSize, char *titleFont, float titleSize, int style, int bbox[]);******************************************************************************psAxesBox:Input:x x coordinate of lower left corner of boxy y coordinate of lower left corner of boxwidth width of boxheight height of boxx1Beg axis value at beginning of axis 1x1End axis value at end of axis 1p1Beg pad value at beginning of axis 1p1End pad value at end of axis 1d1Num numbered tic increment for axis 1 (0.0 for automatic)f1Num first numbered tic for axis 1n1Tic number of horizontal tics per numbered tic for axis 1grid1 grid code for axis 1: NONE, DOT, DASH, or SOLIDlabel1 label for axis 1x2Beg axis value at beginning of axis 2x2End axis value at end of axis 2p2Beg pad value at beginning of axis 2p2End pad value at end of axis 2d2Num vertical numbered tic increment (0.0 for automatic)f2Num first numbered vertical ticn2Tic number of vertical tics per numbered ticgrid2 grid code for vertical axis: NONE, DOT, DASH, or SOLIDlabel2 vertical axis labellabelFont name of font to use for axes labelslabelSize size of font to use for axes labelstitle axes box titletitleFont name of font to use for titletitleSize size of font to use for titletitleColor color to use for titleaxesColor color to use for axes and axes labelsgridColor color to use for grid linesaxeswidth width (in points) of axesticwidth width (in points) of tic marksgridwidth width (in points) of grid linesstyle NORMAL (axis 1 on bottom, axis 2 on left) SEISMIC (axis 1 on left, axis 2 on top)*****************************************************************************psAxesBBox:Input:x x coordinate of lower left corner of boxy y coordinate of lower left corner of boxwidth width of boxheight height of boxlabelFont name of font to use for axes labelslabelSize size of font to use for axes labelstitleFont name of font to use for titletitleSize size of font to use for titlestyle NORMAL (axis 1 on bottom, axis 2 on left) SEISMIC (axis 1 on left, axis 2 on top)Output:bbox bounding box (bbox[0:3] = llx, lly, ulx, uly)******************************************************************************Notes:psAxesBox:psAxesBox will determine the numbered tic increment and first numberedtic automatically, if the specified increment is zero. Axis numberingis in scientific notation, if necessary and is plotted to foursignificant digits.Pad values must be specified in the same units as the correspondingaxes values. These pads are useful when the contents of the axes boxrequires more space than implied by the axes values. For example, thefirst and last seismic wiggle traces plotted inside an axes box willtypically extend beyond the axes values corresponding to the first andlast traces. However, all tics will lie with the limits specified inthe axes values (x1Beg, x1End, x2Beg, x2End).psAxesBBox:psAxesBBox uses font sizes to estimate the bounding box foran axes box drawn with psAxesBox. To be on the safe side, psAxesBBox overestimates.psAxesBBox assumes that the axes labels and titles do not extendbeyond the corresponding edges of the axes box.******************************************************************************References:(see References for basic.c)******************************************************************************Author: Dave Hale, Colorado School of Mines, 06/27/89Modified: Ken Larner, Colorado School of Mines, 08/30/90Modified: Dave Hale, Advance Geophysical, 10/18/92Added color parameters for title, axes, and grid.Modified: Morten Wendell Pedersen, Aarhus University, 23/3-97Added ticwidth,axeswidth, gridwidth parameters *****************************************************************************//**************** end self doc ********************************/#include "cwp.h"#include "psplot.h"void psAxesBox( float x, float y, float width, float height, float x1Beg, float x1End, float p1Beg, float p1End, float d1Num, float f1Num, int n1Tic, int grid1, char *label1, float x2Beg, float x2End, float p2Beg, float p2End, float d2Num, float f2Num, int n2Tic, int grid2, char *label2, char *labelFont, float labelSize, char *title, char *titleFont, float titleSize, char *titleColor, char *axesColor, char *gridColor, float ticwidth, float axeswidth, float gridwidth, int style)/*****************************************************************************Draw an axes box via PostScript******************************************************************************Input:x x coordinate of lower left corner of boxy y coordinate of lower left corner of boxwidth width of boxheight height of boxx1Beg axis value at beginning of axis 1x1End axis value at end of axis 1p1Beg pad value at beginning of axis 1p1End pad value at end of axis 1d1Num numbered tic increment for axis 1 (0.0 for automatic)f1Num first numbered tic for axis 1n1Tic number of horizontal tics per numbered tic for axis 1grid1 grid code for axis 1: NONE, DOT, DASH, or SOLIDlabel1 label for axis 1x2Beg axis value at beginning of axis 2x2End axis value at end of axis 2p2Beg pad value at beginning of axis 2p2End pad value at end of axis 2d2Num vertical numbered tic increment (0.0 for automatic)f2Num first numbered vertical ticn2Tic number of vertical tics per numbered ticgrid2 grid code for vertical axis: NONE, DOT, DASH, or SOLIDlabel2 vertical axis labellabelFont name of font to use for axes labelslabelSize size of font to use for axes labelstitle axes box titletitleFont name of font to use for titletitleSize size of font to use for titletitleColor color to use for titleaxesColor color to use for axes and axes labelsgridColor color to use for grid linesstyle NORMAL (axis 1 on bottom, axis 2 on left) SEISMIC (axis 1 on left, axis 2 on top)******************************************************************************Notes:psAxesBox will determine the numbered tic increment and first numberedtic automatically, if the specified increment is zero. Axis numberingis in scientific notation, if necessary and is plotted to foursignificant digits.Pad values must be specified in the same units as the correspondingaxes values. These pads are useful when the contents of the axes boxrequires more space than implied by the axes values. For example, thefirst and last seismic wiggle traces plotted inside an axes box willtypically extend beyond the axes values corresponding to the first andlast traces. However, all tics will lie with the limits specified inthe axes values (x1Beg, x1End, x2Beg, x2End).******************************************************************************Author: Dave Hale, Colorado School of Mines, 06/27/89Modified: Ken Larner, Colorado School of Mines, 08/30/90Modified: Dave Hale, Colorado School of Mines, 10/18/92 Added color parameters for title, axes, and grid.*****************************************************************************/{ int n1num,n2num,ntic,ndash=0,grided; int ndig,ndigits,nexp,nexpmax=0,nexplot1,nexplot2, nplaces,nplacesmax,nformat; float xa,xas,ya,yas,xb,ticsize,dnum,fnum,dtic,amin,amax,azero, base,scale,anum,anumnorm,atic,fnexp, size1,size2,ticb,numb,numb2,labelb,dash[2], labelCH,labelCW,labelCA,labelCD, titleCH,titleCA,titleCD, pnorm,fdexp,azeronorm; char str[256],str2[256],sformat[256]; /* determine font dimensions */ labelCH = fontheight(labelFont,labelSize); labelCW = fontwidth(labelFont,labelSize); labelCA = fontascender(labelFont,labelSize); labelCD = fontdescender(labelFont,labelSize); titleCH = fontheight(titleFont,titleSize); titleCA = fontascender(titleFont,titleSize); titleCD = fontdescender(titleFont,titleSize); /* determine sizes of axes 1 and 2 */ if (style==NORMAL) { size1 = width; size2 = height; } else { size1 = height; size2 = width; } /* determine numbered tic intervals */ if (d1Num==0.0) { n1num = size1/(4*labelCW); scaxis(x1Beg,x1End,&n1num,&d1Num,&f1Num); } if (d2Num==0.0) { n2num = size2/(4*labelCW); scaxis(x2Beg,x2End,&n2num,&d2Num,&f2Num); } /* save graphics state */ gsave(); /* translate coordinate system, so that origin is at x,y */ translate(x,y); /* if style is not NORMAL, rotate coordinate system */ if (style!=NORMAL) { rotate(-90.0); translate(-height,0.0); } /* start a new path (just to be safe) */ newpath(); /* set font and character size */ setfont(labelFont,labelSize); /* determine tic size */ ticsize = 0.3*labelCH; /* draw axis 1 */ setcolor(axesColor); setlinewidth(ticwidth); amin = (x1Beg<x1End)?x1Beg:x1End; amax = (x1Beg>x1End)?x1Beg:x1End; azero = 0.0001*(amax-amin); dnum = d1Num; fnum = f1Num; ntic = n1Tic; scale = size1/(x1End+p1End-x1Beg-p1Beg); base = -scale*(x1Beg+p1Beg); ticb = -ticsize; numb = 1.2*ticb-labelCA; if(style!=NORMAL) numb = 1.2*ticb; labelb = numb-labelCH; /* determine axis1 exponent for scientific notation */ ndigits = 0; ndig = 0; fdexp = log10(1.001*ABS(dnum)); if(fdexp<0.) fdexp -=1.0; for (anum=fnum; anum<=amax; anum+=dnum) { if(anum==fnum && anum==0.) nexpmax = 0; nexp = 0; if(anum!=0.) { fnexp = log10(1.001*ABS(anum)); if(fnexp>0.) nexp = (int)fnexp; else nexp = (int)fnexp-1; if(anum==fnum) nexpmax = nexp; if(nexpmax<nexp || nexpmax==0) nexpmax = nexp; ndig = 1+nexp-(int)fdexp; } if(ndigits<ndig) ndigits = ndig; } nexplot1 = 0; if(ABS(nexpmax)>3) nexplot1 = nexpmax; if((nexpmax<0) && (ndigits+ABS(nexpmax))>4) nexplot1 = nexpmax; /* loop for axis1 numbering */ nplacesmax = 0; pnorm = pow(10.0,(double)nexplot1); azeronorm = azero/pnorm; fdexp = log10(1.001*ABS(dnum/pnorm)); if(fdexp<0.) fdexp -=1.0; for (anum=fnum; anum<=amax; anum+=dnum) { if (anum<amin) continue; xa = base+scale*anum; xas = xa+0.25*labelCH; moveto(xa,0.0); lineto(xa,ticb); anumnorm = anum/pnorm; /* find the number of places in axis1 numbers */ nplaces = 1; nexp = 1; nexp = 0; if (anumnorm<-azeronorm || anumnorm>azeronorm) { fnexp = log10(1.001*ABS(anumnorm)); if(fnexp>0.) { nexp = (int)fnexp; nplaces = nexp+2; } else { nexp = (int)fnexp-1; nplaces = -nexp+2; } } /* numbers limited to four significant digits */ ndigits = 1+nexp-(int)fdexp; if(ndigits>4) ndigits = 4; if((nexp>=0) && ((ndigits+1)>nplaces)) nplaces = ndigits+1; if(anum<0. ) nplaces +=1; if(nexp<0) nplaces = nplaces+ndigits-1; if(nplacesmax<nplaces) nplacesmax = nplaces; nformat = ndigits-(nexp+1); if(nformat<0) nformat = 0; if (anumnorm>-azeronorm && anumnorm<azeronorm) sprintf(str,"%.4g",0.0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -