⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graph.cc

📁 早期freebsd实现
💻 CC
📖 第 1 页 / 共 2 页
字号:
	    cerr nl;	  };        if (transpose_axes_flag)	{	  String tmp;	  tmp = y_label;	  y_label = x_label;	  x_label = tmp;	  double t;	  for (i = point.low (); i < point.fence (); point.next (i))	    {	      t = point[i].y;	      point[i].y = point[i].x;	      point[i].x = point[i].y;	    }	}      // find the upper and lower limits      // of the x any y coordinates.      for (i = point.low (); i < point.fence (); point.next (i))	{	  if (xmin > point[i].x) xmin = point[i].x;	  if (ymin > point[i].y) ymin = point[i].y;	  if (xmax < point[i].x) xmax = point[i].x;	  if (ymax < point[i].y) ymax = point[i].y;	}      // add margins beteen edges of the data and box if range is nonzero and      // the scale is not logarithmic.      if (!y_log_scale)	{	  double tmp = (ymax - ymin);	  ymax += y_margin * tmp;	  ymin -= y_margin * tmp;	}      if (!x_log_scale)	{	  double tmp = (xmax - xmin);	  xmax += x_margin * tmp;	  xmin -= x_margin * tmp;	}    }    // use limits specified on the command line if present.  if (x_lower_limit != HUGE) xmin = x_lower_limit;  if (y_lower_limit != HUGE) ymin = y_lower_limit;  if (x_upper_limit != HUGE) xmax = x_upper_limit;  if (y_upper_limit != HUGE) ymax = y_upper_limit;    // make sure that 0 is not in range if we are using a log scale.  if (   (x_log_scale	  && (xmin <= 0.)	  && (xmax >= 0.))      || (y_log_scale	  && (ymin <= 0.)	  && (ymax >= 0.)))    {      cerr << "the lower bound on x is" sp xmin nl;      cerr << "the upper bound on x is" sp xmax nl;      cerr << "the lower bound on y is" sp ymin nl;      cerr << "the upper bound on y is" sp ymax nl;      cerr << "Zero cannot lie between an upper and lower bound" nl	"if you use a log scale." nl;      exit (-1);    }  if (x_log_scale)    {      log_xmin = log (xmin);      log_xmax = log (xmax);    }  if (y_log_scale)    {      log_ymin = log (ymin);      log_ymax = log (ymax);    }  			// We have the limits, Now plot.  plot_file.space (0, 0, plot_size, plot_size);  // draw a box around the data.  plot_file.linemod ("solid");  if (grid_style)    plot_file.box (px (0.), py (0.), px (1.), py (1.));    char tick_label[32];	// tick lables are less than 16 digits long.#ifdef _OLD_STREAMS#define SET_TICK_LABEL(x) strcpy(tick_label, dtoa(x))#else  ostrstream tick_stream(tick_label, 32);#define SET_TICK_LABEL(x) tick_stream.seekp(0), tick_stream << (x) << ends#endif  // draw x tick marks.  if (grid_style)    {      // draw labels and ticks on x axis.      double x_tick = x_log_scale	? tick_interval (no_of_ticks, log10 (xmin), log10 (xmax))	  : tick_interval (no_of_ticks, xmin, xmax);      double x_tick_value;      if (x_log_scale)	x_tick_value = pow (10., x_tick			    * (x_tick > 0.			       ? ceil (log10 (xmin) * A_HAIR_MORE / x_tick)			       : floor  (log10 (xmin) * A_HAIR_MORE / x_tick)));      else	x_tick_value = x_tick	* (x_tick > 0. ? ceil (xmin * A_HAIR_MORE / x_tick)	   : floor (xmin * A_HAIR_MORE / x_tick));      while (x_tick_value <= xmax * A_HAIR_MORE)	{			// tick marks on axes.	  plot_file.line	    (px (fx (x_tick_value)), py (0.),	     px (fx (x_tick_value)), py (-1. * size_of_ticks));	  plot_file.line	    (px (fx (x_tick_value)), py (1.),	     px (fx (x_tick_value)), py (1. + size_of_ticks));	  SET_TICK_LABEL(x_tick_value);	  plot_file.move	    (px (fx (x_tick_value) - (extended_plot_format ? 0 :				      .5 * char_width * strlen (tick_label))),	     py ((x_label_on_top ? 1. : (extended_plot_format ? 0 : -1.					 * char_height))		 + (x_label_on_top ? 1. : -1.) * (0. >? size_of_ticks)));	  if (extended_plot_format)	    plot_file.alabel (CENTER_JUSTIFY, x_label_on_top ? BOTTOM_FLUSH			      : TOP_FLUSH, tick_label);	  else	    plot_file.label (tick_label);	  if (grid_style == 2)	    {			// grid across box.	      plot_file.linemod ("shortdashed");	      plot_file.line		(px (fx (x_tick_value)), py (0.),		 px (fx (x_tick_value)), py (1.));	      plot_file.linemod ("solid");	    }	  if ((.5 < fx (x_log_scale ? pow (10., log10 (x_tick_value) + x_tick)			: x_tick_value + x_tick))	      && x_label.length ())	    {			// put the label between tick marks	      plot_file.move		(px (fx ((x_log_scale ? pow (10., log10 (x_tick_value)+x_tick/2.)			  : x_tick_value + x_tick / 2.)			 - (extended_plot_format ? 0 : 			    .5 * char_width * x_label.length ()))),		 py ((x_label_on_top ? 1. : (extended_plot_format ? 0 : -1.					     * char_height)		      + (x_label_on_top ? 1. : -1.) * (0. >? size_of_ticks))));	      if (extended_plot_format)		plot_file.alabel (CENTER_JUSTIFY, x_label_on_top ? BOTTOM_FLUSH				  : TOP_FLUSH, x_label);	      else		plot_file.label (x_label);	      x_label = "";	    }	  if (x_log_scale)	    x_tick_value *= pow (10., x_tick);	  else	  x_tick_value += x_tick;	  if (!x_log_scale && fabs (x_tick_value / x_tick) < 1e-7)	    x_tick_value = 0.;	}      			// draw labels and ticks on y axis.      double y_tick = tick_interval (no_of_ticks, ymin, ymax);      double y_tick_value = y_tick	* (y_tick > 0. ? ceil (ymin * A_HAIR_MORE / y_tick)	   : floor (ymin * A_HAIR_MORE / y_tick));      while (y_tick_value <= ymax * A_HAIR_MORE)	{			// draw tick marks on axes	  plot_file.line	    (px (0.), py (fy (y_tick_value)),	     px (-1. * size_of_ticks), py (fy (y_tick_value)));	  plot_file.line	    (px (1.), py (fy (y_tick_value)),	     px (1. + size_of_ticks), py (fy (y_tick_value)));	  SET_TICK_LABEL(y_tick_value);	  plot_file.move	    (px ((y_label_on_right ? 1. : (extended_plot_format ? 0 : -1.					   * char_width * strlen(tick_label)))		 + (y_label_on_right ? 1. : -1.) * (0. >? size_of_ticks)),	     py (fy (y_tick_value) - .5		 * (extended_plot_format ? 0 : char_height)));	  if (extended_plot_format)	    plot_file.alabel (y_label_on_right ? LEFT_JUSTIFY : RIGHT_JUSTIFY,			      CENTER_FLUSH, tick_label);	  else	    {	      SET_TICK_LABEL(y_tick_value);	      plot_file.label (tick_label);	    }	  if (grid_style == 2)	    {			// draw grid within box.	      plot_file.linemod ("shortdashed");	      plot_file.line		(px (0.), py (fy (y_tick_value)),		 px (1.), py (fy (y_tick_value)));	      plot_file.linemod ("solid");	    }	  if ((.5 < fy (y_tick_value + y_tick))	      && y_label.length ())	    {			// put the label between tick marks	      plot_file.move		(px ((y_label_on_right ? 1. : (extended_plot_format ? 0 : -1.					       * char_width * strlen (y_label)))		     + (y_label_on_right ? 1. : -1.) * (0. >? size_of_ticks)),		 py (fy (y_tick_value + y_tick / 2.)));	      if (extended_plot_format)		plot_file.alabel (y_label_on_right ? LEFT_JUSTIFY				  : RIGHT_JUSTIFY, CENTER_FLUSH, y_label);	      else		plot_file.label (y_label);	      y_label = "";	    }	  y_tick_value += y_tick;	  if (fabs (y_tick_value / y_tick) < 1e-7) y_tick_value = 0.;	}      if (top_label.length ())	// put label above plot.	{	  plot_file.move	    (px (.5 - (extended_plot_format ? 0 :		       .5 * char_width * top_label.length ())),	     py (1. + size_of_ticks));	  if (extended_plot_format)	    plot_file.alabel (CENTER_JUSTIFY, BOTTOM_FLUSH, top_label);	  else	    plot_file.label (top_label);	}    }    if (line_style >= 0)		// set style of lines connecting data points.    plot_file.linemod (line_style_name[line_style % no_of_line_styles]);    				// draw all the points  if (point.length () <= 0)      return 0;			// exit if there is no data.  i = point.low ();  int move = 1;		// 1 means move to first point  double prev_x = point[i].x;  int clipped = 0;		// 1 means we were outside the box.  if (line_style >= 0)		// line_style == -1 means omit lines between points  while (i < point.fence ())    {				// break line if flag set and x < last x      if (point[i].x <  prev_x)	{	  if (switch_style)	    {		line_style = line_style++;		plot_file.linemod (line_style_name[line_style % no_of_line_styles]);	    }	  if (break_flag)	    move = 1;	}      if (in_box (point[i].x, point[i].y)) // clip out points outside the box	{	  if (move)	    {	      move = 0;			// only move once for the first point		plot_file.move (px (fx (point[i].x)), py (fy (point[i].y)));	    }	  else	      if (clipped)		{		  clipped = 0;		  plot_file.move (px (clip (fx (point[i-1].x))),				  py (clip (fy (point[i-1].y))));	    plot_file.cont (px (fx (point[i].x)), py (fy (point[i].y)));	}	      else		plot_file.cont (px (fx (point[i].x)), py (fy (point[i].y)));	  }	else	  {	    if (!clipped)	      {		clipped = 1;		if (move)		  {		    move = 0;		    plot_file.move (px (clip (fx (point[i].x))),				    py (clip (fy (point[i].y))));		  }		else		  plot_file.cont (px (clip (fx (point[i].x))),				  py (clip (fy (point[i].y))));	      }	  }	prev_x = point[i].x;      point.next (i);    }  			// now draw all the symbols and data labels  plot_file.linemod ("solid");  for (i = point.low (); i < point.fence (); point.next (i))    {      if (in_box (point[i].x, point[i].y))	{	  if (point[i].label)	    {	      plot_file.move		(px (fx (point[i].x)), py (fy (point[i].y)));	      if (extended_plot_format)		plot_file.alabel (CENTER_JUSTIFY, CENTER_FLUSH, point[i].label);	      else		plot_file.label (point[i].label);	    }	  else if (default_label.length ())	    {	      plot_file.move		(px (fx (point[i].x)), py (fy (point[i].y)));	      if (extended_plot_format)		plot_file.alabel (CENTER_JUSTIFY, CENTER_FLUSH, default_label);	      else		plot_file.label (default_label);	    }	  if (point[i].symbol >= 0)	    {	      point[i].symbol %= no_of_symbols;	      for (int j=0; (END != symbol[point[i].symbol][j].operation); j++)		switch (symbol[point[i].symbol][j].operation)		  {		  case CONT:		    plot_file.cont		      (px (fx (point[i].x) 			   + symbol_size * symbol[point[i].symbol][j].x),		       py (fy (point[i].y)			   + symbol_size * symbol[point[i].symbol][j].y));		    break;		  case MOVE:		    plot_file.move		      (px (fx (point[i].x)			   + symbol_size * symbol[point[i].symbol][j].x),		       py (fy (point[i].y)			   + symbol_size * symbol[point[i].symbol][j].y));		    break;		  case CIRCLE:		    plot_file.circle		      (px (fx (point[i].x)), py (fy (point[i].y)),		       (int) (plot_size * width * symbol_size			      * symbol[point[i].symbol][j].x));		    break;		  case END:		    ;		  }	    }	}    }  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -