From: trelane@digitasaru.net Date: Fri, 25 Jul 2008 22:06:30 +0000 (-0500) Subject: * Well, the groundwork has been laid, but now I can't see my data anymore. X-Git-Url: http://vcs.maemo.org/git/?p=scdataviz;a=commitdiff_plain;h=dc71e64d8c4327a0c18c91ec42586f6fd0eff4bb * Well, the groundwork has been laid, but now I can't see my data anymore. --- diff --git a/Makefile b/Makefile index d834447..bdecce4 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,8 @@ INCL = # List of *.h # Optional add # ################ IPATH = -I. # path of include file -OBJOPT = -ggdb -g3 -Wall -Wstrict-prototypes -DDEBUG # option for obj -EXEOPT = -ggdb -g3 -Wall -Wstrict-prototypes # option for exe (-lefence ...) +OBJOPT = -ggdb -g3 -Wall -Wstrict-prototypes -DDEBUG -std=c99 -D_GNU_SOURCE # option for obj +EXEOPT = -ggdb -g3 -Wall -Wstrict-prototypes -std=c99 -D_GNU_SOURCE # option for exe (-lefence ...) LPATH = -L. # path for librairies ... ##################### diff --git a/graph.c b/graph.c index 507e557..fa7029e 100644 --- a/graph.c +++ b/graph.c @@ -32,6 +32,7 @@ along with this program. If not, see . #include #include #include +#include G_DEFINE_TYPE(Graph, graph, G_TYPE_OBJECT); @@ -175,18 +176,38 @@ void graph_set_yaxis(Graph *g, struct graph_axis *axis) { g->yaxis=axis; } -void graph_autoset_xaxis(Graph *g) { +int graph_autoset_xaxis(Graph *g, GString *title) { struct graph_axis *axis; + double range_mag; + double start_mag; + double stop_mag; + if(g->points->len == 0) { + return 2; + } if((axis=(struct graph_axis *)malloc(sizeof(struct graph_axis))) == NULL) { return 1; } + if(g->points->len == 1) { + axis->major=1; + axis->minor=0; + axis->subminor=0; + axis->major_start=g->minx; + axis->major_step=g->maxx; + }else{ + range_mag = round(pow(10, floor(log10(g->maxx-g->minx)))); + start_mag = copysign(round(pow(10, floor(log10(fabs(g->minx))))), g->minx); + stop_mag = copysign(round(pow(10, floor(log10(fabs(g->maxx))))), g->maxx); + axis->major=10; + axis->minor=0; + axis->subminor=0; + axis->major_start=start_mag; + axis->major_step=range_mag/(axis->major); + } + axis->title=g_string_new(title->str); graph_set_xaxis(g, axis); + return 0; } -void graph_autoset_yaxis(Graph *g) { - struct graph_axis *axis; - if((axis=(struct graph_axis *)malloc(sizeof(struct graph_axis))) == NULL) { - return 1; - } - graph_set_xaxis(g, axis); +int graph_autoset_yaxis(Graph *g, GString *title) { + return 0; } diff --git a/graph.h b/graph.h index cbdfe5d..31d441f 100644 --- a/graph.h +++ b/graph.h @@ -53,11 +53,12 @@ struct graph_line { }; struct graph_axis { - double start; - double step; - int xminor; + double major_start; + double major_step; + int major; + int minor; int subminor; - GString title; + GString *title; }; typedef struct _Graph { @@ -96,6 +97,10 @@ void graph_add_linear_connectors(Graph* graph); void graph_bezier_linear_to_cubic(double x0, double x3, double *x1, double *x2); /*Provide x0, x1, x2. x1 and x2 will be set appropriately.*/ void graph_bezier_quadratic_to_cubic(double x0, double x3, double *x1, double *x2); +void graph_set_xaxis(Graph *g, struct graph_axis *axis); +void graph_set_yaxis(Graph *g, struct graph_axis *axis); +int graph_autoset_xaxis(Graph *g, GString *title); +int graph_autoset_yaxis(Graph *g, GString *title); diff --git a/graphwidget.c b/graphwidget.c index 95b9722..f4a7d70 100644 --- a/graphwidget.c +++ b/graphwidget.c @@ -79,6 +79,11 @@ static void draw_lines(gpointer data, gpointer user_data) { cairo_curve_to(cxt->cr, p1_x, p1_y, p2_x, p2_y, p3_x, p3_y); } +static void draw_axis(gpointer data, gpointer user_data) { + struct graph_axis *xs = data; + struct drawing_context *cxt = user_data; +} + static void draw(GtkWidget *graph, cairo_t *cr) { struct drawing_context cxt; GraphWidget *gw = GRAPH_WIDGET(graph); @@ -90,15 +95,27 @@ static void draw(GtkWidget *graph, cairo_t *cr) { double y0=graph->allocation.y; double height=graph->allocation.height; double width=graph->allocation.width; + double minx = gw->graph->minx; + double maxx = gw->graph->maxx; + double miny = gw->graph->miny; + double maxy = gw->graph->maxy; + if(gw->graph->xaxis != NULL) { + minx = gw->graph->xaxis->major_start; + maxx = gw->graph->xaxis->major_start + gw->graph->xaxis->major_step*gw->graph->xaxis->major; + } + if(gw->graph->yaxis != NULL) { + miny = gw->graph->yaxis->major_start; + maxy = gw->graph->yaxis->major_start + gw->graph->yaxis->major_step*gw->graph->yaxis->major; + } cxt.widget = graph; cxt.cr = cr; 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); + cxt.xscaling = (gw->graph->points->len == 1)? 1 : (1/(maxx - minx)); + cxt.yscaling = (gw->graph->points->len == 1)? 1 : (1/(maxy - miny)); + cxt.xoffset = (gw->graph->points->len == 1)? (-minx/2) : (-minx); + cxt.yoffset = (gw->graph->points->len == 1)? (-miny/2) : (-miny); #ifdef DEBUG - fprintf(stderr, "minx=%g, maxx=%g, miny=%g, maxy=%g, xscaling=%g, yscaling=%g, xoffset=%g, yoffset=%g\n", gw->graph->minx, gw->graph->maxx, gw->graph->miny, gw->graph->maxy, cxt.xscaling, cxt.yscaling, cxt.xoffset, cxt.yoffset); + fprintf(stderr, "minx=%g, maxx=%g, miny=%g, maxy=%g, xscaling=%g, yscaling=%g, xoffset=%g, yoffset=%g\n", minx, maxx, miny, maxy, cxt.xscaling, cxt.yscaling, cxt.xoffset, cxt.yoffset); fprintf(stderr, "x0=%g, y0=%g, width=%g, height=%g\n", x0, y0, height, width); 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 diff --git a/scdataviz.c b/scdataviz.c index 4c0851d..e141e26 100644 --- a/scdataviz.c +++ b/scdataviz.c @@ -162,7 +162,7 @@ int main(int argc, char *argv[]) g_hash_table_foreach(mdb->materials, &put_mat_in_graph, &propmap); //graph_add_linear_connectors(propmap.graph); g_hash_table_foreach(mdb->materials, &link_materials, &propmap); - + graph_autoset_xaxis(propmap.graph, propmap.xprop); //Connect signals g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);