From: Joseph Pingenot Date: Wed, 23 Jul 2008 03:30:37 +0000 (-0500) Subject: * Offsets work great now. Graph now gets positioned correctly. X-Git-Url: http://vcs.maemo.org/git/?p=scdataviz;a=commitdiff_plain;h=a87b0e37a16ab8f7d2661fd4e6e0cd30ec7c61dc * Offsets work great now. Graph now gets positioned correctly. --- diff --git a/Makefile b/Makefile index ee840ac..d834447 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ INCL = # List of *.h # Optional add # ################ IPATH = -I. # path of include file -OBJOPT = -ggdb -g3 -Wall -Wstrict-prototypes # option for obj +OBJOPT = -ggdb -g3 -Wall -Wstrict-prototypes -DDEBUG # option for obj EXEOPT = -ggdb -g3 -Wall -Wstrict-prototypes # option for exe (-lefence ...) LPATH = -L. # path for librairies ... diff --git a/graphwidget.c b/graphwidget.c index 3dec40e..03da4c6 100644 --- a/graphwidget.c +++ b/graphwidget.c @@ -34,6 +34,8 @@ G_DEFINE_TYPE(GraphWidget, graph_widget, GTK_TYPE_DRAWING_AREA); +#define INSET_PERCENT 0.1 + struct drawing_context { GtkWidget *widget; cairo_t *cr; @@ -59,7 +61,7 @@ static void draw(GtkWidget *graph, cairo_t *cr) { struct drawing_context cxt; GraphWidget *gw = GRAPH_WIDGET(graph); #ifdef DEBUG - fprintf(stderr, "draw(%d, %d)\n", graph, cr); + fprintf(stderr, "draw(%d, %d)\n", (int)graph, (int)cr); fprintf(stderr, "allocation.x=%d, allocation.y=%d, allocation.height=%d, allocation.width=%d\n", graph->allocation.x, graph->allocation.y, graph->allocation.height, graph->allocation.width); #endif double x0=graph->allocation.x; @@ -68,19 +70,23 @@ static void draw(GtkWidget *graph, cairo_t *cr) { double width=graph->allocation.width; cxt.widget = graph; cxt.cr = cr; - cxt.radius = 0.1; + cxt.radius = 0.01; cxt.xscaling = (gw->graph->points->len == 1)? 1 : (1/(gw->graph->maxx - gw->graph->minx)); cxt.yscaling = (gw->graph->points->len == 1)? 1 : (1/(gw->graph->maxy - gw->graph->miny)); cxt.xoffset = (gw->graph->points->len == 1)? (-gw->graph->minx/2) : (-gw->graph->minx); cxt.yoffset = (gw->graph->points->len == 1)? (-gw->graph->miny/2) : (-gw->graph->miny); #ifdef DEBUG fprintf(stderr, "x0=%g, y0=%g, width=%g, height=%g\n", x0, y0, height, width); - fprintf(stderr, "move_to(%d, %g->%g, %g->%g)\n", cr, graph_data[0], graph->allocation.x + graph_data[0]*(graph->allocation.width), graph_data[1], graph->allocation.y + graph_data[1]*(graph->allocation.height)); - #endif + fprintf(stderr, "translate=(%g, %g)\n", x0 + ((width>height)?(width-height)/2.0:0), y0+((width > height)?height:width) + ((height>width)?(height-width)/2.0:0)); +#endif + double offset_height = ((width>=height)?height*INSET_PERCENT:0);; + double offset_width = ((height>=width)?width*INSET_PERCENT:0); + double inset_height = height - offset_height; + double inset_width = width - offset_width; cairo_save(cr); - cairo_translate(cr, x0, y0+height); - cairo_scale(cr, width, -height); - cairo_set_line_width(cr, 0.05); + cairo_translate(cr, x0 + ((inset_width>inset_height)?(inset_width-inset_height)/2.0:0) + offset_width/2, y0+((inset_width > inset_height)?inset_height:inset_width) + ((inset_width>=inset_height)?0:(inset_height-inset_width)/2.0) + offset_height/2 ); + cairo_scale(cr, (inset_width > inset_height)?inset_height:inset_width, (inset_width > inset_height)?-inset_height:-inset_width); + cairo_set_line_width(cr, 0.005); g_ptr_array_foreach(GRAPH_WIDGET(graph)->graph->points, &draw_point, (gpointer)&cxt); cairo_restore(cr); }