From 01399dbbb2b67d6fbe8d22eac1a1482f8efee461 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 17 Mar 2002 22:40:18 +0000 Subject: [PATCH] Changed the way circle sections are drawn. git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@96 a5681a0c-68f1-0310-ab6d-d61299d08faa --- src/rrd_gfx.c | 46 ----------------------------- src/rrd_gfx.h | 7 ----- src/rrd_graph.c | 92 ++++++++++++++++++++++++++++++++++++++++++--------------- 3 files changed, 69 insertions(+), 76 deletions(-) diff --git a/src/rrd_gfx.c b/src/rrd_gfx.c index 1a45439..405291b 100644 --- a/src/rrd_gfx.c +++ b/src/rrd_gfx.c @@ -108,52 +108,6 @@ gfx_node_t *gfx_new_area (gfx_canvas_t *canvas, return node; } -/* create an arc section (2*M_PI is full circle) */ -gfx_node_t *gfx_arc_sect (gfx_canvas_t *canvas, - double centerx, double centery, - double radiusx, double radiusy, - double start, double end, - gfx_color_t color) { - - gfx_node_t *node; - ArtVpath *vec; - int counter; - double position; - -/* 20 is too low, 100 is overkill */ -#define AMOUNT_OF_VECTORS 50 - - node = gfx_new_node(canvas,GFX_AREA); - if (node == NULL) return NULL; - vec = art_new(ArtVpath, AMOUNT_OF_VECTORS+4); - if (vec == NULL) return NULL; - - vec[0].code = ART_MOVETO; - vec[0].x = centerx; - vec[0].y = centery; - - for (counter=0;counter<=AMOUNT_OF_VECTORS;) { - position=start + counter*(end-start)/AMOUNT_OF_VECTORS; - - counter++; - vec[counter].code = ART_LINETO; - vec[counter].x = centerx + sin(position)*radiusx; - vec[counter].y = centery - cos(position)*radiusy; - } - - vec[AMOUNT_OF_VECTORS+2].code = ART_LINETO; - vec[AMOUNT_OF_VECTORS+2].x = centerx; - vec[AMOUNT_OF_VECTORS+2].y = centery; - - vec[AMOUNT_OF_VECTORS+3].code = ART_END; - - node->points = AMOUNT_OF_VECTORS+4; - node->points_max = AMOUNT_OF_VECTORS+4; - node->color = color; - node->path = vec; - - return node; -} /* add a point to a line or to an area */ int gfx_add_point (gfx_node_t *node, diff --git a/src/rrd_gfx.h b/src/rrd_gfx.h index 8362ff1..808b7c4 100644 --- a/src/rrd_gfx.h +++ b/src/rrd_gfx.h @@ -54,13 +54,6 @@ gfx_node_t *gfx_new_area (gfx_canvas_t *canvas, double x2, double y2, gfx_color_t color); -/* create an arc section (2*M_PI is full circle) */ -gfx_node_t *gfx_arc_sect (gfx_canvas_t *canvas, - double centerx, double centery, - double radiusx, double radiusy, - double start, double end, - gfx_color_t color); - /* add a point to a line or to an area */ int gfx_add_point (gfx_node_t *node, double x, double y); diff --git a/src/rrd_graph.c b/src/rrd_graph.c index c7ba63e..ea7ed0d 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -1851,8 +1851,8 @@ graph_paint(image_desc_t *im, char ***calcpr) { int i,ii; int lazy = lazy_check(im); - int piechart = 0, PieSize, PieCenterX, PieCenterY; - double PieStart=0.0; + int piechart = 0; + double PieStart=0.0, PieSize, PieCenterX, PieCenterY; FILE *fo; gfx_canvas_t *canvas; gfx_node_t *node; @@ -1933,7 +1933,7 @@ graph_paint(image_desc_t *im, char ***calcpr) PieCenterX = im->xorigin + im->xsize + 50 + PieSize*0.6; PieCenterY = im->yorigin - PieSize*0.5; } - + /* determine where to place the legends onto the graphics. and set im->ygif to match space requirements for text */ if(leg_place(im)==-1) @@ -1941,6 +1941,7 @@ graph_paint(image_desc_t *im, char ***calcpr) canvas=gfx_new_canvas(); + /* the actual graph is created by going through the individual graph elements and then drawing them */ @@ -1960,22 +1961,54 @@ graph_paint(image_desc_t *im, char ***calcpr) gfx_add_point(node,im->xorigin, im->yorigin - im->ysize); - if (piechart) { -#if 1 - node=gfx_arc_sect (canvas, - PieCenterX,PieCenterY, - PieSize*0.6, PieSize*0.6, /* 20% more as background */ - 0,M_PI*2, - im->graph_col[GRC_CANVAS]); -#else - node=gfx_new_area ( canvas, - PieCenterX-0.6*PieSize, PieCenterY-0.6*PieSize, - PieCenterX+0.6*PieSize, PieCenterY-0.6*PieSize, - PieCenterX+0.6*PieSize, PieCenterY+0.6*PieSize, - im->graph_col[GRC_CANVAS]); - gfx_add_point(node, - PieCenterX-0.6*PieSize, PieCenterY+0.6*PieSize); +#if 0 +/****************************************************************** + ** Just to play around. If you see this, I forgot to remove it ** + ******************************************************************/ + im->ygif+=100; + node=gfx_new_area(canvas, + 0, im->ygif-100, + im->xgif, im->ygif-100, + im->xgif, im->ygif, + im->graph_col[GRC_CANVAS]); + gfx_add_point(node,0,im->ygif); + + node=gfx_new_line (canvas, + 0, im->ygif-100, + im->xgif-3, im->ygif-100, + 1.0, + 0xFF0000FF); + gfx_add_point(node,im->xgif-3,im->ygif-3); + gfx_add_point(node,2,im->ygif-3); + gfx_add_point(node,2,im->ygif-100); + + +#if 0 + node=gfx_new_area ( canvas, + 1, im->ygif-99, + im->xgif-1, im->ygif-99, + im->xgif-1, im->ygif-1, + im->graph_col[GRC_CANVAS]); + gfx_add_point(node,1,im->ygif-1); +#endif + #endif + + if (piechart) { + int n; + + node=gfx_new_area(canvas, + PieCenterX,PieCenterY-PieSize*0.6, + PieCenterX,PieCenterY, + PieCenterX,PieCenterY-PieSize*0.6, + im->graph_col[GRC_CANVAS]); + for (n=1;n<500;n++) { + double angle; + angle=M_PI*2.0*n/500.0; + gfx_add_point(node, + PieCenterX+sin(angle)*PieSize*0.6, + PieCenterY-cos(angle)*PieSize*0.6 ); + } } if (im->minval > 0.0) @@ -2110,12 +2143,25 @@ graph_paint(image_desc_t *im, char ***calcpr) im->gdes[i].yrule = im->gdes[im->gdes[i].vidx].vf.val; if (finite(im->gdes[i].yrule)) { /* even the fetched var can be NaN */ - node=gfx_arc_sect(canvas, - PieCenterX, PieCenterY, - PieSize/2,PieSize/2, - M_PI*2.0*PieStart/100.0, - M_PI*2.0*(PieStart+im->gdes[i].yrule)/100.0, + double angle,endangle; + int n; + + angle=M_PI*2.0*PieStart/100.0; + endangle=M_PI*2.0*(PieStart+im->gdes[i].yrule)/100.0; + node=gfx_new_area(canvas, + PieCenterX+sin(endangle)*PieSize/2, + PieCenterY-cos(endangle)*PieSize/2, + PieCenterX, + PieCenterY, + PieCenterX+sin(angle)*PieSize/2, + PieCenterY-cos(angle)*PieSize/2, im->gdes[i].col); + for (n=1;n<100;n++) { + angle=M_PI*2.0*(PieStart+n/100.0*im->gdes[i].yrule)/100.0; + gfx_add_point(node, + PieCenterX+sin(angle)*PieSize/2, + PieCenterY-cos(angle)*PieSize/2 ); + } PieStart += im->gdes[i].yrule; } break; -- 2.11.0