Re: Traversing through data points and displaying the value
"Adrian E. Feiguin" <[email protected]> Fri, 08 Jul 2005 13:39:25 -0700
| Newsgroups | gmane.comp.scigraphica.gtkextra |
|---|---|
| Message-ID | <[email protected]> |
Look at the gtkplot example: You can select a data point, and retreive
the info about that point.
You have to use:
gtk_signal_connect(GTK_OBJECT(canvas), "select_item",
(GtkSignalFunc) select_item, NULL);
and in select item you so something like:
gint
select_item(GtkWidget *widget, GdkEvent *event, GtkPlotCanvasChild *child,
gpointer data)
{
if(GTK_IS_PLOT_CANVAS_PLOT(child) && GTK_PLOT_CANVAS_PLOT(child)->pos
== GTK_PLOT_CANVAS_PLOT_IN_DATA){
gdouble *x = NULL, *y = NULL;
gint n;
x = gtk_plot_data_get_x(GTK_PLOT_CANVAS_PLOT(child)->data, &n);
y = gtk_plot_data_get_y(GTK_PLOT_CANVAS_PLOT(child)->data, &n);
n = GTK_PLOT_CANVAS_PLOT(child)->datapoint;
printf("Item selected: DATA\n");
printf("Active point: %d -> %f %f\n",
GTK_PLOT_CANVAS_PLOT(child)->datapoint, x[n], y[n]);
}
}
Michael Noble wrote:
>>I was wondering if there is a simple way using the GtkExtra library to
>>be able to click at a point in the graph and then by using cursors or
>>some other way to traverse from one point to the next and get the y &
>>x values as you go along.
>>
>>
>
>Using S-Lang as pseudo-code, add a signal handler for motion events
>
> ... = g_signal_connect(canvas,"motion_notify_event", ...
>
>to the canvas, and within the handler do something like
>
> gtk_widget_get_pointer(canvas, &x, &y);
> gtk_plot_get_point(plot, x, y, &x, &y);
>
>and display it how you wish, such as in a label
>
> gtk_label_set_text(label, sprintf("( %5.3f, %5.3f )", x, y));
>
>HTH,
>-Mike
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
>July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
>core and dual graphics technology at this free one hour event hosted by HP,
>AMD, and NVIDIA. To register visit http://www.hp.com/go/dualwebinar
>_______________________________________________
>Scigraphica-gtkextra mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/scigraphica-gtkextra
>
>.
>
>
>
-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA. To register visit http://www.hp.com/go/dualwebinar