home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / m / m242 / 1.ddi / SOURCE.ZIP / LINE_GRA.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-16  |  2.7 KB  |  81 lines

  1. #include "eg_grafx.h"
  2.  
  3. /* function to draw a line graph */
  4.   
  5. eg_line_graph(num_pts,pts,g_info,x_axis,y_axis)
  6. int num_pts;                    /* number of points to draw   */
  7. int *pts;                               /* array of points    */
  8. GRAPH_INFO g_info;      /* graph description        */
  9. EG_AXIS           x_axis;       /* X axis info       */
  10. EG_AXIS           y_axis;       /* Y axis info       */
  11. {
  12.   
  13.     int i,symbol_size;
  14.     struct egstatus s;              /* EG status structure */
  15.     int x0,x1,y0,y1;
  16.      int k,l;
  17.   
  18.     eg_status(&s);                          /* get EG status */
  19.   
  20. /* switch Y coordinates */
  21.     i = y_axis.high; y_axis.high = y_axis.low;   y_axis.low = i;
  22.   
  23.     if (g_info.symbol_size == -1){
  24.             worldpts(x_axis.low,y_axis.low,&x0,&y0);
  25.         worldpts(x_axis.high,y_axis.high,&x1,&y1);
  26.   
  27.         if ( (y1 - y0) > (x1 - x0) )
  28.             symbol_size = ((x1 - x0 + 1) - (num_pts*5) )/ (num_pts+5);
  29.         else
  30.             symbol_size = ((y1 - y0 + 1) - (num_pts*5) )/ (num_pts+5);
  31.   
  32.         symbol_size /= 2;
  33.     }
  34.     else
  35.         symbol_size = g_info.symbol_size;
  36.   
  37. /* minimum symbol size is 5 */
  38.     if (symbol_size < 5)
  39.         symbol_size = 5;
  40.   
  41. /* draw the line and or symbol points */
  42.     if (g_info.adjust_edges)
  43.         set_base(1,pts[0]);                        /* set the starting base position */
  44.     else
  45.         set_base(0,pts[0]);                        /* set the starting base position */
  46.   
  47. /* if not symbol only, draw line */
  48.     if (g_info.line_graph_type != SYMBOL_ONLY){
  49.         set_line_width(g_info.line_width);   /* set the line width */
  50.         set_line_style(g_info.line_style);      /* set the line style */
  51. /* loop thru the number of lines to plot */
  52.         if (g_info.adjust_edges){
  53.             for (i = 0; i < num_pts; i++)
  54.                 eg_lineto(i+1,pts[i],g_info.item_color,0);
  55.         }
  56.         else
  57.             for (i = 1; i < num_pts; i++)
  58.                 eg_lineto(i,pts[i],g_info.item_color,0);
  59.     }
  60. /* reset the line width */
  61.     set_line_width(s.line_width);
  62. /* reset the line style */
  63.     set_line_style(s.line_style);
  64.   
  65. /* if not line only, draw symbols at points */
  66.     if (g_info.line_graph_type != LINE_ONLY)
  67. /* loop thru the number of points to plot */
  68.         if (g_info.adjust_edges){
  69.             for (i = 0; i < num_pts; i++)
  70.                 (*act_lg_symbol)(i+1,pts[i],symbol_size,g_info.symbol_color,g_info.symbol_fill);
  71.         }
  72.         else{
  73.             for (i = 0; i < num_pts; i++){
  74.                 (*act_lg_symbol)(i,pts[i],symbol_size,g_info.symbol_color,g_info.symbol_fill);
  75.                    worldpts(i,pts[i],&k,&l);
  76.                 }
  77.         }
  78.     return(0);
  79. }
  80.  
  81.