Re: logarithmic axis/grids



Hello,

> Cournol uses the modified version of gtkdatabox, i. e. the rulers from
> counrol are nxprulers not gtk rulers. The modification patch is under
> patches/gtkdatabox.diff in the cournol source archive.

Moving the mouse pointer over rulers in cournol doesn't highlight them,
so I was assuming you didn't use nxpruler. Looking in nxpgtkdatabox code
I can see that rulers are made inactive. Sorry.

> What do you mean? In ex-1.c no graph, only a drawing area is drawn.

ex-1.c from nxpruler-0.1.tar.bz2 package is basically test.c from gnumexp
renamed. I don't like naming a program "test" for it's a shell command.

There another example named ex-1.c (ok, it's not very clever ;^)) in the
patched gtkdatabox package I put on my homesite. I'am having the same
strange behavior than Fabian. I'am trying to plot log10(x) from 1 to 1e5.
If I call gtk_databox_auto_rescale (), nxpruler is passed a 0 to 1e5
range and scale himself from 1 to 10^(1e5).
I attached this example.

Regards ;


Laurent.
#include <gtk/gtk.h>
#include <gtkdatabox.h>
#include <gtkdatabox_lines.h>
#include <math.h>
#include <nxphruler.h>
#include <nxpvruler.h>

#define POINTS 100000

static void create (void)
{
   GtkWidget *window, *table, *vbox, *box, *hruler, *vruler;   
   GtkDataboxGraph *graph;   
   GtkDataboxValue min, max;   
   gfloat *X, *Y;
   GdkColor color;
   gint i;   
   NxpRulerAdjustment *hadj, *vadj;
   
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_widget_set_size_request (window, 600, 400);

   vbox = gtk_vbox_new (FALSE, 0);
   gtk_container_add (GTK_CONTAINER (window), vbox);
   
   table = gtk_table_new (2, 2, FALSE);
   box = gtk_databox_new ();
   gtk_table_attach (GTK_TABLE (table), box, 1, 2, 0, 1,
                     GTK_FILL | GTK_EXPAND | GTK_SHRINK,
                     GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);

   hadj = nxp_ruler_adjustment_new (0, 5);
   vadj = nxp_ruler_adjustment_new (0, 5);
   
   hruler = nxp_hruler_new (hadj);
   nxp_ruler_set_mode (NXP_RULER (hruler), NXP_RULER_LOG);
   gtk_table_attach (GTK_TABLE (table), hruler, 1, 2, 1, 2,
                     GTK_FILL | GTK_EXPAND | GTK_SHRINK, GTK_FILL, 0, 0);
   gtk_databox_set_hruler (GTK_DATABOX (box), NXP_RULER (hruler));
   
   vruler = nxp_vruler_new (vadj);
   /* nxp_ruler_set_mode (NXP_RULER (vruler), NXP_RULER_LOG); */
   gtk_table_attach (GTK_TABLE (table), vruler, 0, 1, 0, 1,
                     GTK_FILL, GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);
   gtk_databox_set_vruler (GTK_DATABOX (box), NXP_RULER (vruler));
                                      
   gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
   
   g_object_unref (hadj);
   g_object_unref (vadj);
      
   X = g_new0 (gfloat, POINTS);
   Y = g_new0 (gfloat, POINTS);

   for (i = 1 ; i < POINTS + 1; i ++)
   {
      X [i] = i;
      Y [i] = log10 (i);
   }
   color.red = 0;
   color.green = 65535;
   color.blue = 0;

   graph = gtk_databox_lines_new (POINTS, X, Y, &color, 1);
   gtk_databox_graph_add (GTK_DATABOX (box), graph);

   gtk_databox_auto_rescale (GTK_DATABOX (box), 0);   
   /* min.x = 0; */
   /* max.x = 1e5; */
   /* min.y = 0; */
   /* max.y = 5; */
   /* gtk_databox_set_canvas (GTK_DATABOX (box), min, max); */
   gtk_databox_get_canvas (GTK_DATABOX (box), &min, &max);
   printf ("x = (%f, %f)\n", min.x, max.x);
   printf ("y = (%f, %f)\n", min.y, max.y);
   
   g_signal_connect (GTK_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);

   gtk_widget_show_all (window);
   gdk_window_set_cursor (box->window, gdk_cursor_new (GDK_CROSS));
}

gint main (gint argc, char *argv[])
{
   gtk_init (&argc, &argv);

   create ();
   gtk_main ();

   return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]