gnucash, charts and interactivity
Jean Bréfort
jean.brefort at normalesup.org
Sun Nov 22 05:37:38 EST 2009
Hi,
I think that goffice has now what is needed to fix #359224
( https://bugzilla.gnome.org/show_bug.cgi?id=359224 ) (at least
partially, things have not been implemented for bar/column plots yet,
only pies).
Reading gnucash plots, I found that charts are displayed as pixbufs in
html pages. Btw, the renderer is not unreferenced in
create_graph_pixbuf, which introduces a memory leak, however, the
renderer will be needed later, so I think the appropriate way is to use
g_object_set_data:
g_object_set_data_full( G_OBJECT(buf), "renderer", renderer, g_object_unref );
For older goffice versions, just unref pixbuf_renderer and
cairo_renderer.
Now, the only way I can think of to get a callback for the graph, is to
use a server side html map
( http://www.w3.org/TR/html401/struct/objects.html#h-13.6.2 ). The URI
needs to include some way to know which pixbuf has been clicked, then
you just need a callback such as:
graph_clicked_cb (GdkPixbuf *pixbuf, int x, int y)
with x and y the coordinates given by the called URI as described in the
HTML specification. Of course, I might miss something, being not
familiar with gnucah code.
The callback should contain code such as (needs goffice-0.7.16 to build
and work):
GogRenderer *rend = g_object_get (pixbuf, "renderer");
GogView *view;
GogSeries *series = NULL;
unsigned index;
if (!rend)
return; /* can't do anything without the renderer */
g_object_get (G_OBJECT (graph->renderer), "view", &view, NULL);
/* get the appropriate child view */
view = gog_view_get_view_at_point (view, x, y, NULL, NULL);
if (!GOG_IS_PLOT_VIEW (view))
return /* clicked occur outside of any plot */
index = gog_plot_view_get_data_at_point (GOG_PLOT_VIEW (view), x, y, &series);
if (index < 0)
return; /* nothing found at (x,y) */
/* now do want is needed knowing that you have the series and the index
of the data inside the series */
...
What is new in that code is gog_plot_view_get_data_at_point which did
not exist before 0.7.16.
Hope this helps, best regards,
Jean
More information about the gnucash-devel
mailing list