Пример #1
0
void wheel2(const char *fn, int nres, char *resnm[], real rot0, char *title)
{
    const real fontsize  = 14;
    const real gray      = 0.9;
    const real fontasp   = 0.45;
    const int  angle     = 9;
    const real fontwidth = fontsize*fontasp;

    t_psdata   out;
    int        i, slen;
    real       ring, inner, outer;
    real       xc, yc, box;

    inner = 60.0;
    slen  = 0;
    for (i = 0; (i < nres); i++)
    {
        slen = std::max(slen, static_cast<int>(strlen(resnm[i])));
    }
    fprintf(stderr, "slen = %d\n", slen);
    ring  = slen*fontwidth;
    outer = inner+ring;
    box   = (1+(nres / (2*angle)))*outer;

    out = ps_open(fn, 0, 0, 2.0*box, 2.0*box);
    xc  = box;
    yc  = box;

    ps_font(out, efontHELV, 1.5*fontsize);
    ps_translate(out, xc, yc);
    ps_color(out, 0, 0, 0);
    if (title)
    {
        ps_ctext(out, 0, -fontsize*1.5/2.0, title, eXCenter);
    }
    ps_font(out, efontHELV, fontsize);

    ps_rotate(out, rot0);
    for (i = 0; (i < nres); )
    {
        if ((i % 5) == 4)
        {
            ps_color(out, gray, gray, 1.0);
            ps_fillarcslice(out, 0, 0, inner, outer, -angle, angle);
            ps_color(out, 0, 0, 0);
        }
        ps_arcslice(out, 0, 0, inner, outer, -angle, angle);

        ps_ctext(out, inner+fontwidth, -fontsize/2.0, resnm[i], eXLeft);
        ps_rotate(out, -2*angle);
        i++;

        if ((i % (2*angle)) == 0)
        {
            inner  = outer;
            outer += ring;
        }
    }
    ps_close(out);
}
Пример #2
0
void leg_continuous(t_psdata ps,real x0,real x,real y0,char *label,
		    real fontsize,char *font,
		    int nmap,t_mapping map[],
		    int mapoffset)
{
  int   i;
  real  xx0;
  real  yhh,boxxh,boxyh;
  
  boxyh=fontsize;
  if (x<8*fontsize)
    x=8*fontsize;
  boxxh=(real)x/(real)(nmap-mapoffset);
  if (boxxh>fontsize)
    boxxh=fontsize;
  
  /* LANDSCAPE */
  xx0=x0-((nmap-mapoffset)*boxxh)/2.0;
  
  for(i=0; (i<nmap-mapoffset); i++) {
    ps_rgb(ps,&(map[i+mapoffset].rgb));
    ps_fillbox(ps,xx0+i*boxxh,y0,xx0+(i+1)*boxxh,y0+boxyh);
  }
  ps_strfont(ps,font,fontsize);
  ps_rgb(ps,BLACK);
  ps_box(ps,xx0,y0,xx0+(nmap-mapoffset)*boxxh,y0+boxyh);
  
  yhh=y0+boxyh+3*DDD;
  ps_ctext(ps,xx0+boxxh/2,yhh,map[0].desc,eXCenter);
  if ((int)strlen(label) > 0)
    ps_ctext(ps,x0,yhh,label,eXCenter);
  ps_ctext(ps,xx0+((nmap-mapoffset)*boxxh)
	   - boxxh/2,yhh,map[nmap-1].desc,eXCenter);
}
Пример #3
0
void leg_discrete(t_psdata ps,real x0,real y0,char *label,
		  real fontsize,char *font,int nmap,t_mapping map[])
{
  int   i;
  real  yhh;
  real  boxhh;
  
  boxhh=fontsize+DDD;
  /* LANDSCAPE */
  ps_rgb(ps,BLACK);
  ps_strfont(ps,font,fontsize);
  yhh=y0+fontsize+3*DDD;
  if ((int)strlen(label) > 0)
    ps_ctext(ps,x0,yhh,label,eXLeft);
  ps_moveto(ps,x0,y0);
  for(i=0; (i<nmap); i++) {
    ps_setorigin(ps);
    ps_rgb(ps,&(map[i].rgb));
    ps_fillbox(ps,DDD,DDD,DDD+fontsize,boxhh-DDD);
    ps_rgb(ps,BLACK);
    ps_box(ps,DDD,DDD,DDD+fontsize,boxhh-DDD);
    ps_ctext(ps,boxhh+2*DDD,fontsize/3,map[i].desc,eXLeft);
    ps_unsetorigin(ps);
    ps_moverel(ps,DDD,-fontsize/3);
  }
}
Пример #4
0
void wheel(const char *fn, int nres, char *resnm[], int r0, real rot0, char *title)
{
    const real fontsize  = 16;
    const real gray      = 0.9;
    const real fontasp   = 0.6;
    const real fontwidth = fontsize*fontasp;

    t_psdata   out;
    int        i, sl, slen;
    real       ring, inner, outer;
    real       xc, yc, box;
    gmx_bool  *bPh;
    char     **rnms;
    char       sign;

    inner = 75.0;
    slen  = 0;
    snew(rnms, nres);
    for (i = 0; (i < nres); i++)
    {
        snew(rnms[i], 256);
        sl   = std::strlen(resnm[i]);
        sign = resnm[i][sl-1];
        if ((sign == '+') || (sign == '-'))
        {
            resnm[i][sl-1] = '\0';
        }
        sprintf(rnms[i], "%s-%d", resnm[i], i+r0);
        if ((sign == '+') || (sign == '-'))
        {
            sl            = std::strlen(rnms[i]);
            rnms[i][sl]   = sign;
            rnms[i][sl+1] = '\0';
        }

        slen = std::max(slen, static_cast<int>(std::strlen(rnms[i])));
    }
    ring  = (2+slen)*fontwidth;
    outer = inner+ring;
    box   = inner*1.5+(1+(nres / 18))*ring;

    bPh = bPhobics(nres, resnm);

    out = ps_open(fn, 0, 0, 2.0*box, 2.0*box);
    xc  = box;
    yc  = box;

    ps_font(out, efontHELV, 1.5*fontsize);
    ps_translate(out, xc, yc);
    if (title)
    {
        ps_ctext(out, 0, -fontsize*1.5/2.0, title, eXCenter);
    }
    ps_font(out, efontHELV, fontsize);
    ps_rotate(out, rot0);
    for (i = 0; (i < nres); )
    {
        if (bPh[i])
        {
            ps_color(out, gray, gray, gray);
            ps_fillarcslice(out, 0, 0, inner, outer, -10, 10);
            ps_color(out, 0, 0, 0);
        }
        ps_arcslice(out, 0, 0, inner, outer, -10, 10);

        ps_ctext(out, inner+fontwidth, -fontsize/2.0, rnms[i], eXLeft);
        ps_rotate(out, -100);
        i++;

        if ((i % 18) == 0)
        {
            inner  = outer;
            outer += ring;
        }
    }
    ps_close(out);
}
Пример #5
0
void ps_mat(char *outf,int nmat,t_matrix mat[],t_matrix mat2[],
	    bool bFrame,bool bDiag,bool bFirstDiag,
	    bool bTitle,bool bTitleOnce,bool bYonce,int elegend,
	    real size,real boxx,real boxy,char *m2p,char *m2pout,
	    int mapoffset)
{
  char   *libm2p;
  char buf[256],*legend;
  t_psdata out;
  t_psrec  psrec,*psr;
  int    W,H;
  int    i,j,x,y,col,leg=0;
  real   x0,y0,xx;
  real   w,h,dw,dh;
  int       nmap1=0,nmap2=0,leg_nmap;
  t_mapping *map1=NULL,*map2=NULL,*leg_map;
  bool   bMap1,bNextMap1,bDiscrete;
  
  libm2p = m2p ? strdup(libfn(m2p)) : m2p;
  get_params(libm2p,m2pout,&psrec);

  psr=&psrec;

  if (psr->X.major <= 0 )
    tick_spacing((mat[0].flags & MAT_SPATIAL_X) ? mat[0].nx + 1 : mat[0].nx,
		 mat[0].axis_x, psr->X.offset, 'X', 
		 &(psr->X.major), &(psr->X.minor) );
  if (psr->X.minor <= 0 )
    psr->X.minor = psr->X.major / 2;
  if (psr->Y.major <= 0)
    tick_spacing((mat[0].flags & MAT_SPATIAL_Y) ? mat[0].ny + 1 : mat[0].ny,
		 mat[0].axis_y, psr->Y.offset, 'Y',
		 &(psr->Y.major), &(psr->Y.minor) );
  if (psr->Y.minor <= 0)
    psr->Y.minor = psr->Y.major / 2;

  if (boxx>0) {
    psr->xboxsize=boxx;
    psr->yboxsize=boxx;
  }
  if (boxy>0)
    psr->yboxsize=boxy;  

  if (psr->xboxsize==0) {
    psr->xboxsize = size/mat[0].nx;
    printf("Set the x-size of the box to %.3f\n",psr->xboxsize);
  }
  if (psr->yboxsize==0) {
    psr->yboxsize = size/mat[0].nx;
    printf("Set the y-size of the box to %.3f\n",psr->yboxsize);
  }

  nmap1=0;
  for (i=0; (i<nmat); i++)
    if (mat[i].nmap>nmap1) {
      nmap1=mat[i].nmap;
      map1=mat[i].map;
      leg=i+1;
    }
  if (leg!=1)
    printf("Selected legend of matrix # %d for display\n",leg);
  if (mat2) {
    nmap2=0;
    for (i=0; (i<nmat); i++)
      if (mat2[i].nmap>nmap2) {
	nmap2=mat2[i].nmap;
	map2=mat2[i].map;
	leg=i+1;
  }
    if (leg!=1)
      printf("Selected legend of matrix # %d for second display\n",leg);
  }
  if ( (mat[0].legend[0]==0) && psr->legend )
    strcpy(mat[0].legend, psr->leglabel);

  bTitle     = bTitle     && mat[nmat-1].title[0];
  bTitleOnce = bTitleOnce && mat[nmat-1].title[0];
  psr->bTitle     = bTitle;
  psr->bTitleOnce = bTitleOnce;
  psr->bYonce     = bYonce;

  /* Set up size of box for nice colors */
  box_dim(nmat,mat,mat2,psr,elegend,bFrame,&w,&h,&dw,&dh);
  
  /* Set up bounding box */
  W=w+dw;
  H=h+dh;
  
  /* Start box at */
  x0=dw;
  y0=dh;
  x = W+psr->xoffs;
  y = H+psr->yoffs;
  if (bFrame) {
    x += 5*DDD;
    y += 4*DDD;
  }
  out=ps_open(outf,0,0,x,y);
  ps_linewidth(out,psr->linewidth);
  ps_init_rgb_box(out,psr->xboxsize,psr->yboxsize);
  ps_init_rgb_nbox(out,psr->xboxsize,psr->yboxsize);
  ps_translate(out,psr->xoffs,psr->yoffs);

  if (bFrame) {
    ps_comment(out,"Here starts the BOX drawing");  
    draw_boxes(out,x0,y0,w,nmat,mat,psr);
  }

  for(i=0; (i<nmat); i++) {
    if (bTitle || (bTitleOnce && i==nmat-1) ) {
      /* Print title, if any */
      ps_rgb(out,BLACK);
      ps_strfont(out,psr->titfont,psr->titfontsize); 
      if (!mat2 || (strcmp(mat[i].title,mat2[i].title) == 0))
	strcpy(buf,mat[i].title);
      else
	sprintf(buf,"%s / %s",mat[i].title,mat2[i].title);
      ps_ctext(out,x0+w/2,y0+box_height(&(mat[i]),psr)+psr->titfontsize,
	       buf,eXCenter);
    }
    sprintf(buf,"Here starts the filling of box #%d",i);
    ps_comment(out,buf);
    for(x=0; (x<mat[i].nx); x++) {
      int nexty;
      int nextcol;
      
      xx=x0+x*psr->xboxsize;
      ps_moveto(out,xx,y0);
      y=0;
      bMap1 = (!mat2 || (x<y || (x==y && bFirstDiag)));
      if ((bDiag) || (x!=y))
	col = mat[i].matrix[x][y];
      else
	col = -1;
      for(nexty=1; (nexty<=mat[i].ny); nexty++) {
	bNextMap1 = (!mat2 || (x<nexty || (x==nexty && bFirstDiag)));
	  /* TRUE:  upper left  -> map1 */
	  /* FALSE: lower right -> map2 */
	if ((nexty==mat[i].ny) || (!bDiag && (x==nexty)))
	  nextcol = -1;
	else
	  nextcol=mat[i].matrix[x][nexty];
	if ( (nexty==mat[i].ny) || (col!=nextcol) || (bMap1!=bNextMap1) ) {
	  if (col >= 0)
	    if (bMap1)
	      ps_rgb_nbox(out,&(mat[i].map[col].rgb),nexty-y);
	    else
	      ps_rgb_nbox(out,&(mat2[i].map[col].rgb),nexty-y);
	  else
	    ps_moverel(out,0,psr->yboxsize);
	  y=nexty;
	  bMap1=bNextMap1;
	  col=nextcol;
	  }
	}
    }
    y0+=box_height(&(mat[i]),psr)+box_dh(psr)+box_dh_top(IS_ONCE,psr);
  }
  
  if (psr->X.lineatzero || psr->Y.lineatzero) {
    /* reset y0 for first box */
    y0=dh;
    ps_comment(out,"Here starts the zero lines drawing");  
    draw_zerolines(out,x0,y0,w,nmat,mat,psr);
  }
  
  if (elegend!=elNone) {
    ps_comment(out,"Now it's legend time!");
    ps_linewidth(out,psr->linewidth);
    if ( mat2==NULL || elegend!=elSecond ) {
      bDiscrete = mat[0].bDiscrete;
      legend    = mat[0].legend;
      leg_nmap  = nmap1;
      leg_map   = map1;
    } else {
      bDiscrete = mat2[0].bDiscrete;
      legend    = mat2[0].legend;
      leg_nmap  = nmap2;
      leg_map   = map2;
    }
    if (bDiscrete)
      leg_discrete(out,psr->legfontsize,DDD,legend,
		   psr->legfontsize,psr->legfont,leg_nmap,leg_map);
    else {
      if ( elegend!=elBoth )
	leg_continuous(out,x0+w/2,w/2,DDD,legend,
		       psr->legfontsize,psr->legfont,leg_nmap,leg_map,
		       mapoffset);
      else
	leg_bicontinuous(out,x0+w/2,w,DDD,mat[0].legend,mat2[0].legend,
			 psr->legfontsize,psr->legfont,nmap1,map1,nmap2,map2);
    }
    ps_comment(out,"Were there, dude");
  }
  
  ps_close(out);
}
Пример #6
0
static void draw_boxes(t_psdata ps,real x0,real y0,real w,
		       int nmat,t_matrix mat[],t_psrec *psr)
{
  char   buf[12];
  char   *mylab;
  real   xxx;
  char   **xtick,**ytick;
  real   xx,yy,dy,xx00,yy00,offset_x,offset_y;
  int    i,j,x,y,ntx,nty,strlength;
  
  /* Only necessary when there will be no y-labels */ 
  strlength = 0;
  
  /* Draw the box */
  ps_rgb(ps,BLACK);
  ps_linewidth(ps,psr->boxlinewidth);
  yy00=y0;
  for(i=0; (i<nmat); i++) {
    dy=box_height(&(mat[i]),psr);
    ps_box(ps,x0-1,yy00-1,x0+w+1,yy00+dy+1);
    yy00+=dy+box_dh(psr)+box_dh_top(IS_ONCE,psr);
  }
  
  /* Draw the ticks on the axes */
  ps_linewidth(ps,psr->ticklinewidth);
  xx00=x0-1;
  yy00=y0-1;
  for (i=0; (i<nmat); i++) {
    if (mat[i].flags & MAT_SPATIAL_X) {
      ntx = mat[i].nx + 1;
      offset_x = 0.1;
    } else {
      ntx = mat[i].nx;
      offset_x = 0.6;
    }
    if (mat[i].flags & MAT_SPATIAL_Y) {
      nty = mat[i].ny + 1;
      offset_y = 0.1;
    } else {
      nty = mat[i].ny;
      offset_y = 0.6;
    }
    snew(xtick,ntx);
    for(j=0; (j<ntx); j++) {
      sprintf(buf,"%g",mat[i].axis_x[j]);
      xtick[j]=strdup(buf);
    }
    ps_strfont(ps,psr->X.tickfont,psr->X.tickfontsize);
    for(x=0; (x<ntx); x++) {
      xx = xx00 + (x + offset_x)*psr->xboxsize;
      if ( ( bRmod(mat[i].axis_x[x], psr->X.offset, psr->X.major) || 
	     (psr->X.first && (x==0))) &&
	   ( (i == 0) || box_do_all_x_maj_ticks(psr) ) ) {
	/* Longer tick marks */
	ps_line (ps,xx,yy00,xx,yy00-psr->X.majorticklen);
	/* Plot label on lowest graph only */
	if (i == 0)
	  ps_ctext(ps,xx,
		   yy00-DDD-psr->X.majorticklen-psr->X.tickfontsize*0.8,
		   xtick[x],eXCenter);
      } else if ( bRmod(mat[i].axis_x[x], psr->X.offset, psr->X.minor) &&
		( (i == 0) || box_do_all_x_min_ticks(psr) ) ){
	/* Shorter tick marks */
	ps_line(ps,xx,yy00,xx,yy00-psr->X.minorticklen);
      } else if ( bRmod(mat[i].axis_x[x], psr->X.offset, psr->X.major) ) {
	/* Even shorter marks, only each X.major */
	ps_line(ps,xx,yy00,xx,yy00-(psr->boxspacing/2));
      }
    }
    ps_strfont(ps,psr->Y.tickfont,psr->Y.tickfontsize);
    snew(ytick,nty);
    for(j=0; (j<nty); j++) {
      sprintf(buf,"%g",mat[i].axis_y[j]);
      ytick[j]=strdup(buf);
    }

    for(y=0; (y<nty); y++) {
      yy = yy00 + (y + offset_y)*psr->yboxsize;
      if ( bRmod(mat[i].axis_y[y], psr->Y.offset, psr->Y.major) || 
	   (psr->Y.first && (y==0))) {
	/* Major ticks */
	strlength=max(strlength,(int)strlen(ytick[y]));
	ps_line (ps,xx00,yy,xx00-psr->Y.majorticklen,yy);
	ps_ctext(ps,xx00-psr->Y.majorticklen-DDD,
		 yy-psr->Y.tickfontsize/3.0,ytick[y],eXRight);
      }
      else if ( bRmod(mat[i].axis_y[y], psr->Y.offset, psr->Y.minor) ) {
	/* Minor ticks */
	ps_line(ps,xx00,yy,xx00-psr->Y.minorticklen,yy);
      }
    }
    sfree(xtick);
    sfree(ytick);
    
    /* Label on Y-axis */
    if (!psr->bYonce || i==nmat/2) {
      if (strlen(psr->Y.label) > 0) 
	mylab = psr->Y.label;
      else
	mylab = mat[i].label_y;
      if (strlen(mylab) > 0) {
	ps_strfont(ps,psr->Y.font,psr->Y.fontsize);
	ps_flip(ps,TRUE);
	xxx=x0-psr->X.majorticklen-psr->X.tickfontsize*strlength-DDD;
	ps_ctext(ps,yy00+box_height(&mat[i],psr)/2.0,612.5-xxx,
		 mylab,eXCenter);
	ps_flip(ps,FALSE);
      }
    }
    
    yy00+=box_height(&(mat[i]),psr)+box_dh(psr)+box_dh_top(IS_ONCE,psr);
  }
  /* Label on X-axis */  
  if (strlen(psr->X.label) > 0) 
    mylab = psr->X.label;
  else
    mylab = mat[0].label_x;
  if (strlen(mylab) > 0) {
    ps_strfont(ps,psr->X.font,psr->X.fontsize);
    ps_ctext(ps,x0+w/2,y0-DDD-psr->X.majorticklen-psr->X.tickfontsize*FUDGE-
	     psr->X.fontsize,mylab,eXCenter);
  }
}