/[pspp]/pspp/src/piechart.c
ViewVC logotype

Diff of /pspp/src/piechart.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by jmd, Fri Jan 7 00:17:20 2005 UTC revision 1.6 by jmd, Fri Jan 14 04:05:47 2005 UTC
# Line 47  draw_segment(struct chart *ch, Line 47  draw_segment(struct chart *ch,
47    
48    
49    
 #ifndef NO_CHARTS  
   
50  /* Draw a piechart */  /* Draw a piechart */
51  void  void
52  piechart_plot(const char *title, const struct slice *slices, int n_slices)  piechart_plot(const char *title, const struct slice *slices, int n_slices)
# Line 56  piechart_plot(const char *title, const s Line 54  piechart_plot(const char *title, const s
54    int i;    int i;
55    double total_magnetude=0;    double total_magnetude=0;
56    
57    struct chart ch;    struct chart *ch;
58    
59    chart_initialise(&ch);    ch = chart_create();
60    
61    const double left_label = ch.data_left +    const double left_label = ch->data_left +
62      (ch.data_right - ch.data_left)/10.0;      (ch->data_right - ch->data_left)/10.0;
63    
64    const double right_label = ch.data_right -    const double right_label = ch->data_right -
65      (ch.data_right - ch.data_left)/10.0;      (ch->data_right - ch->data_left)/10.0;
66    
67    const double centre_x = (ch.data_right + ch.data_left ) / 2.0 ;    const double centre_x = (ch->data_right + ch->data_left ) / 2.0 ;
68    const double centre_y = (ch.data_top + ch.data_bottom ) / 2.0 ;    const double centre_y = (ch->data_top + ch->data_bottom ) / 2.0 ;
69    
70    const double radius = min(    const double radius = min(
71                              5.0 / 12.0 * (ch.data_top - ch.data_bottom),                              5.0 / 12.0 * (ch->data_top - ch->data_bottom),
72                              1.0 / 4.0 * (ch.data_right - ch.data_left)                              1.0 / 4.0 * (ch->data_right - ch->data_left)
73                              );                              );
74    
75    
76    chart_write_title(&ch, title);    chart_write_title(ch, title);
77    
78    for (i = 0 ; i < n_slices ; ++i )    for (i = 0 ; i < n_slices ; ++i )
79      total_magnetude += slices[i].magnetude;      total_magnetude += slices[i].magnetude;
# Line 94  piechart_plot(const char *title, const s Line 92  piechart_plot(const char *title, const s
92          radius * cos(angle + segment_angle/2.0);          radius * cos(angle + segment_angle/2.0);
93    
94        /* Fill the segment */        /* Fill the segment */
95        draw_segment(&ch,        draw_segment(ch,
96                     centre_x, centre_y, radius,                     centre_x, centre_y, radius,
97                     angle, segment_angle,                     angle, segment_angle,
98                     data_colour[i]);                     data_colour[i]);
# Line 102  piechart_plot(const char *title, const s Line 100  piechart_plot(const char *title, const s
100        /* Now add the labels */        /* Now add the labels */
101        if ( label_x < centre_x )        if ( label_x < centre_x )
102          {          {
103            pl_line_r(ch.lp, label_x, label_y,            pl_line_r(ch->lp, label_x, label_y,
104                      left_label, label_y );                      left_label, label_y );
105            pl_moverel_r(ch.lp,0,5);            pl_moverel_r(ch->lp,0,5);
106            pl_alabel_r(ch.lp,0,0,slices[i].label);            pl_alabel_r(ch->lp,0,0,slices[i].label);
107          }          }
108        else        else
109          {          {
110            pl_line_r(ch.lp,            pl_line_r(ch->lp,
111                      label_x, label_y,                      label_x, label_y,
112                      right_label, label_y                      right_label, label_y
113                      );                      );
114            pl_moverel_r(ch.lp,0,5);            pl_moverel_r(ch->lp,0,5);
115            pl_alabel_r(ch.lp,'r',0,slices[i].label);            pl_alabel_r(ch->lp,'r',0,slices[i].label);
116          }          }
117    
118        angle += segment_angle;        angle += segment_angle;
# Line 122  piechart_plot(const char *title, const s Line 120  piechart_plot(const char *title, const s
120      }      }
121    
122    /* Draw an outline to the pie */    /* Draw an outline to the pie */
123    pl_filltype_r(ch.lp,0);    pl_filltype_r(ch->lp,0);
124    pl_fcircle_r (ch.lp, centre_x, centre_y, radius);    pl_fcircle_r (ch->lp, centre_x, centre_y, radius);
125    
126    chart_finalise(&ch);    chart_submit(ch);
127  }  }
128    
129  static void  static void
# Line 211  draw_segment(struct chart *ch, Line 209  draw_segment(struct chart *ch,
209    pl_restorestate_r(ch->lp);    pl_restorestate_r(ch->lp);
210  }  }
211    
 #else  
   
   
 void  
 piechart_plot(const char *title, const struct slice *slices, int n_slices)  
 {  
 }  
   
 #endif  

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26