Re: handling multiple graph using gtkplot in gtk application [Please HELP]
"Adrian E. Feiguin" <[email protected]> Fri, 27 Apr 2007 11:58:35 -0700
| Newsgroups | gmane.comp.scigraphica.gtkextra |
|---|---|
| Message-ID | <[email protected]> |
Hi Shupa,
Sorry I didn't get back to you earlier, I am trying to catch up with my
backlog. At firt glance, I don't see anything wrong with your code, and
I don't think your problem is related to gtkextra. It looks to me as
though you are trying to add a canvas to a viewport which already
contains a child widget. A viewport is a gtkbin, which can contain a
single child. You have to remove the old child if you want to add a new
one. You can use testgtkplot and sg_plot_window in scigraphica as nice
self-explanatory examples.
Sorry again for taking so long to reply, I hope this helps, or you've
solved your problems.
Saludos,
<ADRIAN>
shuprabha shakya wrote:
> Hi,
>
> My application needs to plot different graphs as selected by user.
> Here user select graph type in combo and correspnding graph has to be
> plotted.
>
> I am using gtkextra-2.0 widget, gtkplot and gtkcanvas for plotting
> within gtk application in C. I am using liblglade to compile the glade
> files made from glade.
>
> Here, I am trying to plot the graph in a viewport. [I wonder whether,
> this idea is correct or not / gtkextra is supported in gtk application
> or not]
>
> Taking help of the gtk-extra code, I was able to draw a plot in
> viewport. But every, I again try to plot in the view port again it
> gives me following error.
>
> (<unknown>:8762): Gtk-CRITICAL **: gtk_viewport_add: assertion
> `bin->child == NULL' failed
>
> Then, I tried to set the viewport to NULL, which gave me this error:
>
> (<unknown>:8247): Gtk-CRITICAL **: gtk_container_add: assertion
> `GTK_IS_CONTAINER (container)' failed
>
> I wonder what could be the possible reasons?
> Is there any function that can clear the viewport once it is drawn?
> Does gtk application can integrate gtkextra package in this way?
> Does the gtkplot wodget can be shown in pallete window of glade?
> Is there any other solution?
>
> Below is my graph plotting code which i call when user select any
> graph and click display button. The draw_graph_function() is called
> every time user selects the graph type.
>
> //------------------------------------------------------------------------------------------------------
>
> void draw_graph_function()
> {
> GtkWidget * widget;
> GtkWidget * activePlot;
> GtkWidget *canvas;
> gint id;
> GtkPlotCanvasChild *child;
>
> id = get_id_for_graph(); // get which graph has to be plotted
>
> /* canvas */
> canvas = gtk_plot_canvas_new(420, 350, 1.0);
> GTK_PLOT_CANVAS_UNSET_FLAGS(GTK_PLOT_CANVAS(canvas),
> GTK_PLOT_CANVAS_DND_FLAGS);
> gtk_container_add(GTK_CONTAINER(plot_view), canvas); // plot_view
> is //pointer to view port read as
> //plot_view = glade_xml_get_widget(xml,"plot_viewport");
> gtk_widget_show(canvas);
>
> activePlot=GTK_WIDGET(get_plot_outline()); //
> get_plot_outline()sets the x, y axis ticks
> set_plot_for_graph(GTK_PLOT(activePlot));
>
> /* canvas plot */
> child = gtk_plot_canvas_plot_new(GTK_PLOT(activePlot));
> gtk_plot_canvas_put_child(GTK_PLOT_CANVAS(canvas), child, 0.15,
> 0.15, 0.85, 0.85);
> gtk_widget_show(GTK_WIDGET(activePlot));
>
> build_plot(GTK_PLOT(activePlot)); // sets dataset
>
> gtk_plot_canvas_paint(GTK_PLOT_CANVAS(canvas));
> gtk_plot_canvas_refresh(GTK_PLOT_CANVAS(canvas));
>
> }
>
> GtkPlot *
> get_plot_outline()
> {
> GtkPlot *plot;
> gint id;
>
> id = get_id_for_graph();
>
> /* plot */
> switch(id)
> {
> case 0:
> plot = GTK_PLOT(gtk_plot_new(NULL));
> gtk_plot_set_range(plot, 0., 1.5, 0., 1.5);
> gtk_plot_set_ticks(plot, GTK_PLOT_AXIS_X, 0.5, 2);
> gtk_plot_set_ticks(plot, GTK_PLOT_AXIS_Y, 0.5, 2);
> gtk_plot_axis_hide_title(gtk_plot_get_axis(plot,
> GTK_PLOT_AXIS_TOP));
> gtk_plot_axis_hide_title(gtk_plot_get_axis(plot,
> GTK_PLOT_AXIS_RIGHT));
> gtk_plot_axis_set_title(gtk_plot_get_axis(plot,
> GTK_PLOT_AXIS_BOTTOM), "x");
> gtk_plot_axis_set_title(gtk_plot_get_axis(plot,
> GTK_PLOT_AXIS_LEFT), "y");
> gtk_plot_hide_legends(plot);
> break;
>
> case 1:
> plot = GTK_PLOT(gtk_plot_new(NULL));
> gtk_plot_set_range(plot, 0., 2, 0., 2);
> gtk_plot_set_ticks(plot, GTK_PLOT_AXIS_X, 0.5, 2);
> gtk_plot_set_ticks(plot, GTK_PLOT_AXIS_Y, 0.5, 2);
> gtk_plot_axis_hide_title(gtk_plot_get_axis(plot,
> GTK_PLOT_AXIS_TOP));
> gtk_plot_axis_hide_title(gtk_plot_get_axis(plot,
> GTK_PLOT_AXIS_RIGHT));
> gtk_plot_axis_set_title(gtk_plot_get_axis(plot,
> GTK_PLOT_AXIS_BOTTOM), "x1");
> gtk_plot_axis_set_title(gtk_plot_get_axis(plot,
> GTK_PLOT_AXIS_LEFT), "y1");
> gtk_plot_hide_legends(plot);
> break;
>
> default:
> printf("Invalid ID - get plot outline - %d\n", id);
> }
> return plot;
> }
>
> void
> build_plot(GtkPlot * plot)
> {
> GtkPlotData *dataset;
> printf("build plot");
> //gdouble px[NPOINTS];
> //gdouble py[NPOINTS];
> static gdouble px1[6], py1[6];
>
> gint i, id;
>
> id = get_id_for_graph();
>
> switch(id)
> {
> case 0:
>
> for(i=0; i<6;i++)
> {
> px1[i] = i*0.2;
> py1[i] = px1[i];
> }
>
> dataset = GTK_PLOT_DATA(gtk_plot_data_new());
> gtk_plot_add_data(GTK_PLOT(plot), dataset);
> gtk_widget_show(GTK_WIDGET(dataset));
> gtk_plot_data_set_points(dataset, px1, py1, NULL, NULL, 6);
> break;
>
> case 1:
>
> for(i=0; i<8;i++)
> {
> px1[i] = i*0.2;
> py1[i] = px1[i];
> }
>
> dataset = GTK_PLOT_DATA(gtk_plot_data_new());
> gtk_plot_add_data(GTK_PLOT(plot), dataset);
> gtk_widget_show(GTK_WIDGET(dataset));
> gtk_plot_data_set_points(dataset, px1, py1, NULL, NULL, 8);
> break;
>
> default:
> printf("Invalid ID - build plot - %d\n", id);
> }
> }
> //------------------------------------------------------------------------------------------------------
>
>
>
>
>
>
> shupa
>
> ------------------------------------------------------------------------
> Be a PS3 game guru.
> Get your game face on with the latest PS3 news and previews at Yahoo!
> Games. <http://us.rd.yahoo.com/evt=49936/*http://videogames.yahoo.com>
>
>------------------------------------------------------------------------
>
>-------------------------------------------------------------------------
>Take Surveys. Earn Cash. Influence the Future of IT
>Join SourceForge.net's Techsay panel and you'll get the chance to share your
>opinions on IT & business topics through brief surveys - and earn cash
>http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Scigraphica-gtkextra mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/scigraphica-gtkextra
>
>
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/