示例#1
0
void PieChart::draw_series_double() {
    double *dataArray = (double *) data_array;
    double total=0;
    double theta1,theta2;

    for (int i = 0; i < data_num; i++)
	total+=(double)(dataArray[i]);

    if(total<1E-9)total=1;

    theta2=0.0;
    for (int i = 0; i < data_num; i++) {
	theta1=theta2;
	theta2+=6.2832*(double)dataArray[i]/total;
	draw_pie(theta1,theta2,i);
    }

    theta1=0.0;
    for (int i = 0; i <= data_num; i++) {
	vga_back.thick_line(
	    centerx, centery,
	    centerx+(int)(radius*cos(theta1)), centery+(int)(radius*sin(theta1)),
	    vga_back.translate_color(V_GRAY-5));
	theta1+=6.2832*(double)dataArray[i]/total;
    }

}
static gboolean
countdown_expose_cb(GtkWidget *pie, GdkEventExpose *event,
					WindowData *windata)
{
	cairo_t *context;
	cairo_surface_t *surface;
	cairo_t *cr;

	context = gdk_cairo_create(pie->window);

	cairo_set_operator(context, CAIRO_OPERATOR_SOURCE);
	surface = cairo_surface_create_similar(cairo_get_target(context),
										   CAIRO_CONTENT_COLOR_ALPHA,
										   pie->allocation.width,
										   pie->allocation.height);
	cr = cairo_create(surface);

	cairo_translate (cr, -pie->allocation.x, -pie->allocation.y);
	fill_background (pie, windata, cr);
	cairo_translate (cr, pie->allocation.x, pie->allocation.y);
	
	draw_pie (pie, windata, cr);

	cairo_destroy(cr);
	cairo_set_source_surface(context, surface, 0, 0);
	cairo_paint(context);
	cairo_surface_destroy(surface);
	cairo_destroy(context);
	return TRUE;
}
示例#3
0
//---------- Begin of function PieChart::draw_series_int ------------//
//!
void PieChart::draw_series_int() {
    int *dataArray = (int *) data_array;
    long total=0;
    double theta1,theta2;

    for (int i = 0; i < data_num; i++)
	total+=(long)(dataArray[i]);

    if(total<1E-9)total=1;
    theta2=0.0;
    for (int i = 0; i < data_num; i++) {
	theta1=theta2;
	theta2+=6.2832*(double)dataArray[i]/total;
	draw_pie(theta1,theta2,i);

	if((theta1!=theta2)
	   &&(fabs(theta2-theta1-6.2832)>1e-9)) {
	    vga_back.thick_line(
		centerx,
		centery,
		centerx+(int)(radius*cos(theta1)),
		centery+(int)(radius*sin(theta1)),
		vga_back.translate_color(V_GRAY-5));
	    vga_back.thick_line(
		centerx,
		centery,
		centerx+(int)(radius*cos(theta2)),
		centery+(int)(radius*sin(theta2)),
		vga_back.translate_color(V_GRAY-5));
	}
    }

}