static void graph_setup_title (GogGraph *graph, const gchar *title) { GogLabel *label; GOData *data; GOStyle *style; PangoFontDescription *desc; label = g_object_new(GOG_TYPE_LABEL, NULL); data = go_data_scalar_str_new(title, FALSE); gog_dataset_set_dim(GOG_DATASET(label), 0, data, NULL); gog_object_add_by_name(GOG_OBJECT(graph), "Title", GOG_OBJECT(label)); style = go_styled_object_get_style(GO_STYLED_OBJECT(label)); desc = pango_font_description_from_string("Sans bold 16"); go_style_set_font_desc(style, desc); }
static GogPlot * setup_page (GtkNotebook *notebook, const gchar *service_id) { GtkWidget *child, *w; GogChart *chart; GogGraph *graph; GogLabel *label; GogPlot *plot; GOData *data; GOStyle *style; PangoFontDescription *desc; child = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_notebook_append_page (notebook, child, gtk_label_new (service_id)); /* Create a graph widget and add it to the GtkVBox */ w = go_graph_widget_new (NULL); gtk_box_pack_end (GTK_BOX (child), w, TRUE, TRUE, 0); /* Get the embedded graph */ graph = go_graph_widget_get_graph (GO_GRAPH_WIDGET (w)); /* Add a title */ label = (GogLabel *) g_object_new (GOG_TYPE_LABEL, NULL); data = go_data_scalar_str_new (service_id, FALSE); gog_dataset_set_dim (GOG_DATASET (label), 0, data, NULL); gog_object_add_by_name (GOG_OBJECT (graph), "Title", GOG_OBJECT (label)); /* Change the title font */ style = go_styled_object_get_style (GO_STYLED_OBJECT (label)); desc = pango_font_description_from_string ("Sans bold 16"); go_style_set_font_desc (style, desc); /* Get the chart created by the widget initialization */ chart = go_graph_widget_get_chart (GO_GRAPH_WIDGET (w)); /* Create a plot and add it to the chart */ plot = (GogPlot *) gog_plot_new_by_name (service_id); gog_object_add_by_name (GOG_OBJECT (chart), "Plot", GOG_OBJECT (plot)); /* Add a legend to the chart */ gog_object_add_by_name (GOG_OBJECT (chart), "Legend", NULL); return plot; }
int main (int argc, char *argv[]) { GtkWidget *window, *box, *w; GogChart *chart; GogGraph *graph; GogLabel *label; GogPlot *pie; GogSeries *series; GOStyle *style; GOData *data; GError *error; PangoFontDescription *desc; char const *title = "Some statistics"; char const * const legends[] = {"first", "second", "third", "fourth"}; double values[] = {10., 20., 30., 40.}; gtk_init (&argc, &argv); /* Initialize libgoffice */ libgoffice_init (); /* Initialize plugins manager */ go_plugins_init (NULL, NULL, NULL, NULL, TRUE, GO_TYPE_PLUGIN_LOADER_MODULE); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_resize (GTK_WINDOW (window), 300, 340); gtk_window_set_title (GTK_WINDOW (window), "pie demo"); g_signal_connect (window, "destroy", gtk_main_quit, NULL); box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); w = gtk_button_new_from_stock (GTK_STOCK_QUIT); g_signal_connect_swapped (w, "clicked", G_CALLBACK (on_quit), window); gtk_box_pack_end (GTK_BOX (box), w, FALSE, FALSE, 0); w = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL); gtk_box_pack_end (GTK_BOX (box), w, FALSE, FALSE, 2); /* Create a graph widget and add it to the GtkVBox */ w = go_graph_widget_new (NULL); gtk_box_pack_end (GTK_BOX (box), w, TRUE, TRUE, 0); /* Get the embedded graph */ graph = go_graph_widget_get_graph (GO_GRAPH_WIDGET (w)); /* Add a title */ label = (GogLabel *) g_object_new (GOG_TYPE_LABEL, NULL); data = go_data_scalar_str_new (title, FALSE); gog_dataset_set_dim (GOG_DATASET (label), 0, data, NULL); gog_object_add_by_name (GOG_OBJECT (graph), "Title", GOG_OBJECT (label)); /* Change the title font */ style = go_styled_object_get_style (GO_STYLED_OBJECT (label)); desc = pango_font_description_from_string ("Sans bold 16"); go_style_set_font_desc (style, desc); /* Get the chart created by the widget initialization */ chart = go_graph_widget_get_chart (GO_GRAPH_WIDGET (w)); /* Create a pie plot and add it to the chart */ pie = (GogPlot *) gog_plot_new_by_name ("GogPiePlot"); gog_object_add_by_name (GOG_OBJECT (chart), "Plot", GOG_OBJECT (pie)); /* Create a series for the plot and populate it with some simple data */ series = gog_plot_new_series (pie); data = go_data_vector_str_new (legends, 4, NULL); gog_series_set_dim (series, 0, data, &error); data = go_data_vector_val_new (values, 4, NULL); gog_series_set_dim (series, 1, data, &error); /* Add a legend to the chart */ gog_object_add_by_name (GOG_OBJECT (chart), "Legend", NULL); gtk_container_add (GTK_CONTAINER (window), box); gtk_widget_show_all (GTK_WIDGET (window)); w = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL); gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 0); gtk_main (); /* Clean libgoffice stuff */ libgoffice_shutdown (); return 0; }
static void cb_gnm_so_path_changed (GnmSOPath const *sop, G_GNUC_UNUSED GParamSpec *pspec, GnmSOPathView *group) { GList *ptr = GOC_GROUP (group)->children; for (; ptr && ptr->data; ptr = ptr->next) if (GOC_IS_PATH (ptr->data)) cb_gnm_so_path_style_changed (GOC_ITEM (ptr->data), sop); if (sop->text != NULL && *sop->text != 0) { /* set a font, a very bad solution, but will do until we move to GOString */ PangoFontDescription *desc = pango_font_description_from_string ("Sans 10"); GOStyle *style; if (group->text == NULL) { double x0, y0, x1, y1; if (group->path) goc_item_get_bounds (group->path, &x0, &y0, &x1, &y1); else { unsigned i; double mx, my, Mx, My; x0 = y0 = G_MAXDOUBLE; x1 = y1 = -G_MAXDOUBLE; for (i = 0; i < group->paths->len; i++) { goc_item_get_bounds (GOC_ITEM (g_ptr_array_index (group->paths, i)), &mx, &my, &Mx, &My); if (mx < x0) x0 = mx; if (my < y0) y0 = my; if (Mx > x1) x1 = Mx; if (My > y1) y1 = My; } } x1 -= x0 + sop->margin_pts.left + sop->margin_pts.right; y1 -= y0 + sop->margin_pts.top + sop->margin_pts.bottom; x0 += x1 / 2. + sop->margin_pts.left; y0 += y1 / 2. + sop->margin_pts.top; x1 = MAX (x1, DBL_MIN); y1 = MAX (y1, DBL_MIN); group->text = goc_item_new (GOC_GROUP (group), GOC_TYPE_TEXT, "anchor", GO_ANCHOR_CENTER, "clip", TRUE, "x", x0, "y", y0, "clip-height", y1, "clip-width", x1, "wrap-width", x1, "attributes", sop->markup, NULL); } style = go_styled_object_get_style (GO_STYLED_OBJECT (group->text)); go_style_set_font_desc (style, desc); goc_item_set (group->text, "text", sop->text, "attributes", sop->markup, NULL); } else if (group->text != NULL) { g_object_unref (group->text); group->text = NULL; } }