Re: more libgoffice help



You need a GogRenderer. If you don't have one, create it, something
like:

GogRenderer *rend = gog_renderer_new (graph);
gog_renderer_update (rend, allocation->width, allocation->height);


Then you need the GogView for the plot to know it's allocation:

GogView *view;
g_object_get (G_OBJECT (rend), "view", &view, NULL);
view = gog_view_find_child_view (view, chart);
view = gog_view_find_child_view (view, plot);

and you can use the allocation to create the map:

map = gog_chart_map_new (plotpresent->gchart, &(view->allocation),
x_axis, y_axis, NULL, FALSE);

Here, you might test if the map is valid and if the event occurred inside the plot:
if (gog_chart_map_is_valid (map) &&
    event->x >= view->allocation.x && event->x < view->allocation.x + view->allocation.w &&
    event->y >= view->allocation.y && event->y < view->allocation.y + view->allocation.h) {
        x_map = gog_chart_map_get_axis_map (map, 0);
        y_map = gog_chart_map_get_axis_map (map, 1);
        x = gog_axis_map_from_view (x_map, event->x);
        y = gog_axis_map_from_view (y_map, event->y);
}


Le mercredi 20 mai 2009 à 19:06 +0200, Jean Bréfort a écrit :
I'm not sure how you must do at the moment. I'll have to make some tests
and time is missing just now. But you surely need to take plot_area.x
and plot_area.y into account. Anyway this is related to the enhancement
feature #580545 even it is for an xy plot instead if a pie plot.
I intend to woekon that quite soon, and I'll let you know how things are
going.

Best regards,
Jean

Le mercredi 20 mai 2009 à 09:53 +0100, jcupitt gmail com a écrit :
Hi all,

I'm displaying a chart with libgoffice and I'd like to map motion
notify event coordinates to axis positions.

I've got fairly close, but I can't see how to take account of the
margins around the edges of the chart :-( Can anyone point me to some
sample code that does this?

Here's what I have:

        axes = gog_chart_get_axes( plotpresent->gchart, GOG_AXIS_X );
        x_axis = GOG_AXIS( axes->data );
        g_slist_free( axes );

        axes = gog_chart_get_axes( plotpresent->gchart, GOG_AXIS_Y );
        y_axis = GOG_AXIS( axes->data );
        g_slist_free( axes );

        gog_chart_get_plot_area( plotpresent->gchart, &plot_area );

        map = gog_chart_map_new( plotpresent->gchart,
                &plot_area, x_axis, y_axis, NULL, FALSE );

        x_map = gog_chart_map_get_axis_map( map, 0 );
        y_map = gog_chart_map_get_axis_map( map, 1 );

        x_canvas = event->x / (double) allocation->width;
        y_canvas = event->y / (double) allocation->height;

        x = gog_axis_map_from_view( x_map, x_canvas );
        y = gog_axis_map_from_view( y_map, y_canvas );

        gog_chart_map_free( map );

        printf( "event->x = %g, event->y = %g\n", event->x, event->y );
        printf( "x_canvas = %g, y_canvas = %g\n", x_canvas, y_canvas );
        printf( "x = %g, y = %g\n", x, y );

John
_______________________________________________
gnumeric-list mailing list
gnumeric-list gnome org
http://mail.gnome.org/mailman/listinfo/gnumeric-list




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