Mini How-To: Paint charts in Gtk with libgoffice

June 2nd, 2008

Hello, since some time ago I’ve been using libgoffice to make charts in Gnome applications, instead of using Cairo directly.
This library was separated from Gnumeric , so you could make the same charts that it paints.
The results are very good, but the unique issue that I had was that there is very little documentation about the topic.

Here are some advices to make a GObject “painter of charts”:

  • GObject attributes:

GtkWidget chartWidget; // Widget that will contain the components
GogPlot *plot; // Plot
GogLegend *legend; // Legend

  • Initialize:

libgoffice_init ();
go_plugins_init (NULL, NULL, NULL, NULL, TRUE, GO_PLUGIN_LOADER_MODULE_TYPE);
self->priv->chartWidget = g_object_ref_sink (go_graph_widget_new (NULL));

  • Paint one chart of example:

// Get the embedded graph
graph = go_graph_widget_get_graph (GO_GRAPH_WIDGET (self->priv->chartWidget));

// Get the chart created by the widget initialization
chart = go_graph_widget_get_chart (GO_GRAPH_WIDGET (self->priv->chartWidget));

// Create plot and add to the chart giving its name [1]
self->priv->plot = (GogPlot *) gog_plot_new_by_name (”GogBarColPlot”);
g_object_set (G_OBJECT (self->priv->plot),
“horizontal”, FALSE,
“type”, “stacked”,
“overlap_percentage”, 100,
“guru-hints”, “backplane”,
NULL);
gog_object_add_by_name (GOG_OBJECT (chart), “Plot”, GOG_OBJECT (self->priv->plot));

// Create a series for the plot and populate it with data.
// gchar **legends -> go_data_vector_str_new
// gdouble *values -> go_data_vector_val_new
GogSeries *series;
GOData *data;
GError *error;
// New serie. Each serie is a set of values, one for each legend. We need to set its name to see it in the legend.
// Every time that we need a serie, we have to do gog_plot_new_series, but only adding data, not the legends.
series = gog_plot_new_series (self->priv->plot);
gog_object_set_name (GOG_OBJECT (series), "My first serie", NULL);
data = go_data_vector_str_new ((char const * const *) legends, size, g_free);
gog_series_set_dim (series, 0, data, &error);
data = go_data_vector_val_new (values, size, g_free);
gog_series_set_dim (series, 1, data, &error);
// Add another serie of data
series = gog_plot_new_series (self->priv->plot);
gog_object_set_name (GOG_OBJECT (series), "My second serie", NULL);
data = go_data_vector_val_new (values, size, g_free);
gog_series_set_dim (series, 1, data, &error);

// Add a legend to the chart and get it to be able to clear in the future
gog_object_add_by_name (GOG_OBJECT (chart), "Legend", GOG_OBJECT (self->priv->legend));
self->priv->legend = (GogLegend *) gog_object_get_child_by_name (GOG_OBJECT (chart), "Legend");

  • Clean the chart: (i.e. clean components from the widget, to paint another)

gog_object_clear_parent (GOG_OBJECT (self->priv->plot));
g_object_unref (self->priv->plot);
gog_object_clear_parent (GOG_OBJECT (self->priv->legend));
g_object_unref (self->priv->legend);

  • Dispose:

libgoffice_shutdown ();

[1]: All the plot names and their properties can be queried at /usr/lib/goffice/version/plugins/plot_type/plot-types.xml
I hope that this help to anybody :)

The new “product” of Google: Fear!

December 30th, 2007

Some time ago I realized that Google stores our searches if we are logged in with a Google account. The fact of look Gmail and forget to logout (what happed to me…) causes that Google knows the web pages you visit. But, are there commercial reasons? What makes Google with all this information?

.
google_3.png

If this has scared you, watch what I have discovered. I was looking for how to hack the new type of maps that provides Google (terrain), and then the finder informed me about pages with dangerous content! Will it be true that google can detect, or only is a strategy not to go into pages on which they do not want to the people enter? I don’t know…

.

google_1.png google_2.png

WindGURU en galego

December 1st, 2007
Estamos a traballar na traducción ó galego da páxina web WindGURU, nunha nova aportación de Igalia á comunidade.
Nesta páxina poderás consultar previsións meteorolóxicas, estado do vento, cobertura de nubes, períodos das ondas, temperaturas, etc.

Hello world!

November 13th, 2007

Welcome to my Igalia’s blog. This is my first post, so i’ll not write anything interesting, but thanks to Igalia for give me the oportunity to work with him. I hope to return the confidence they put in me.


Bad Behavior has blocked 1 access attempts in the last 7 days.