[Glade-users] handling multiple graph using gtkplot in gtk application [Please HELP]



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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/glade-users/attachments/20070123/7e787f2a/attachment.html 




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