[Gnucash-changes] r13409 - gnucash/trunk - Andreas Kohler's patch for barchart improvements: segment color setting, axis rotation and formatting.

Joshua Sled jsled at cvs.gnucash.org
Sun Feb 26 16:42:06 EST 2006


Author: jsled
Date: 2006-02-26 16:42:06 -0500 (Sun, 26 Feb 2006)
New Revision: 13409
Trac: http://svn.gnucash.org/trac/changeset/13409

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/gnome-utils/gnc-html-graph-gog.c
Log:
Andreas Kohler's patch for barchart improvements: segment color setting, axis rotation and formatting.


Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-02-26 21:15:52 UTC (rev 13408)
+++ gnucash/trunk/ChangeLog	2006-02-26 21:42:06 UTC (rev 13409)
@@ -25,6 +25,10 @@
 
 2006-02-26  Joshua Sled  <jsled at asynchronous.org>
 
+	* src/gnome-utils/gnc-html-graph-gog.c:
+	Andreas Köhler's patch for barchart improvements: segment color
+	setting, axis rotation and formatting.
+
 	* src/engine/SX-book.c (gnc_sx_get_sxes_referencing_account): 
 	* src/gnome/dialog-scheduledxaction.c: Add handler for
 	account-deleted events, determine and display editors for SXes

Modified: gnucash/trunk/src/gnome-utils/gnc-html-graph-gog.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-html-graph-gog.c	2006-02-26 21:15:52 UTC (rev 13408)
+++ gnucash/trunk/src/gnome-utils/gnc-html-graph-gog.c	2006-02-26 21:42:06 UTC (rev 13409)
@@ -354,14 +354,14 @@
 }
 
 /**
- * datarows:int
- * datacols:int
- * data:doubles[], datarows*datacols
+ * data_rows:int
+ * data_cols:int
+ * data:doubles[], data_rows*data_cols
  * x_axis_label:string
  * y_axis_label:string
+ * row_labels:string[]
  * col_labels:string[]
- * row_labels:string[]
- * col_colors:string
+ * col_colors:string[]
  * rotate_row_labels:boolean
  * stacked:boolean
  **/
@@ -371,115 +371,120 @@
   GogObject *graph, *chart;
   GogPlot *plot;
   GogSeries *series;
-  GOData *labelData, *sliceData;
-  int datarows, datacols;
+  GogStyle *style;
+  GOData *label_data, *slice_data;
+  int data_rows, data_cols;
   double *data = NULL;
   char **col_labels = NULL, **row_labels = NULL, **col_colors = NULL;
-  //gboolean rotate_row_labels;
+  gboolean rotate_row_labels = FALSE;
   gboolean stacked = FALSE;
-  char *barType = "normal";
-  int barOverlap = 0 /*percent*/; // seperate bars; no overlap.
+  char *bar_type = "normal";
+  int bar_overlap = 0 /*percent*/; // seperate bars; no overlap.
 
-  gtkhtml_3_3_2_bug_workaround(eb);
+  gtkhtml_3_3_2_bug_workaround (eb);
 
   // parse data from the text-ized params
   // series => bars [gnc:cols]
   // series-elements => segments [gnc:rows]
   {
-    char *datarowsStr, *datacolsStr, *dataStr, *colLabelsStr, *rowLabelsStr, *colColorsStr, *stackedStr;
-    gint stackedInt;
+    char *data_rows_str, *data_cols_str, *data_str, *col_labels_str, *row_labels_str;
+    char *col_colors_str, *rotate_row_labels_str = NULL, *stacked_str = NULL;
 
-    datarowsStr  = g_hash_table_lookup(eb->params, "data_rows");
-    datacolsStr  = g_hash_table_lookup(eb->params, "data_cols");
-    dataStr      = g_hash_table_lookup(eb->params, "data" );
-    colLabelsStr = g_hash_table_lookup(eb->params, "col_labels");
-    rowLabelsStr = g_hash_table_lookup(eb->params, "row_labels");
-    colColorsStr = g_hash_table_lookup(eb->params, "col_colors");
-    stackedStr = NULL;
-    stackedStr   = g_hash_table_lookup(eb->params, "stacked");
-    stackedInt = atoi( stackedStr );
-    stacked = (gboolean)stackedInt;
+    data_rows_str         = g_hash_table_lookup (eb->params, "data_rows");
+    data_cols_str         = g_hash_table_lookup (eb->params, "data_cols");
+    data_str              = g_hash_table_lookup (eb->params, "data" );
+    row_labels_str        = g_hash_table_lookup (eb->params, "row_labels");
+    col_labels_str        = g_hash_table_lookup (eb->params, "col_labels");
+    col_colors_str        = g_hash_table_lookup (eb->params, "col_colors");
+    rotate_row_labels_str = g_hash_table_lookup (eb->params, "rotate_row_labels");
+    stacked_str           = g_hash_table_lookup (eb->params, "stacked");
 
+    rotate_row_labels     = (gboolean) atoi (rotate_row_labels_str);
+    stacked               = (gboolean) atoi (stacked_str);
+
 #if 0 // too strong at the moment.
-    g_return_val_if_fail( datarowsStr != NULL
-                          && datacolsStr != NULL
-                          && dataStr != NULL
-                          && colLabelsStr != NULL
-                          && rowLabelsStr != NULL
-                          && colColorsStr != NULL, FALSE );
+    g_return_val_if_fail (data_rows_str != NULL
+                          && data_cols_str != NULL
+                          && data_str != NULL
+                          && col_labels_str != NULL
+                          && row_labels_str != NULL
+                          && col_colors_str != NULL, FALSE );
 #endif // 0
-    datarows = atoi( datarowsStr );
-    datacols = atoi( datacolsStr );
-    data = read_doubles( dataStr, datarows*datacols );
-    row_labels = read_strings( rowLabelsStr, datarows );
-    col_labels = read_strings( colLabelsStr, datacols );
-    col_colors = read_strings( colColorsStr, datacols );
+    data_rows = atoi (data_rows_str);
+    data_cols = atoi (data_cols_str);
+    data = read_doubles (data_str, data_rows*data_cols);
+    row_labels = read_strings (row_labels_str, data_rows);
+    col_labels = read_strings (col_labels_str, data_cols);
+    col_colors = read_strings (col_colors_str, data_cols);
   }
 
-  if (!create_basic_plot_elements("GogBarColPlot", &graph, &chart, &plot))
-  {
+  if (!create_basic_plot_elements("GogBarColPlot", &graph, &chart, &plot)) {
     return FALSE;
   }
 
-  if ( stacked )
-  {
+  if ( stacked ) {
     // when stacked, we want the bars on _top_ of eachother.
-    barType = "stacked";
-    barOverlap = 100 /*percent*/;
+    bar_type = "stacked";
+    bar_overlap = 100 /*percent*/;
   }
 
   g_object_set (G_OBJECT (plot),
                 //"vary_style_by_element",	TRUE,
-                "type",                         barType,
-                "overlap_percentage",           barOverlap, 
+                "type",                         bar_type,
+                "overlap_percentage",           bar_overlap, 
 		NULL);
-  labelData = go_data_vector_str_new((char const * const *)row_labels, datacols, NULL);
+  label_data = go_data_vector_str_new ((char const * const *)row_labels, data_rows, NULL);
   {
     // foreach row:
     //   series = row
+    GdkColor color;
     int i;
-    for (i = 0; i < datacols; i++)
-    {
+    for (i = 0; i < data_cols; i++) {
       GError *err = NULL;
 
-      series = gog_plot_new_series( plot );
-      gog_object_set_name(GOG_OBJECT(series), col_labels[i], &err);
+      series = gog_plot_new_series (plot);
+      gog_object_set_name (GOG_OBJECT (series), col_labels[i], &err);
       if (err != NULL)
       {
         PERR("error setting name [%s] on series [%d]: [%s]\n",
              col_labels[i], i, err->message);
       }
 
-      g_object_ref(labelData);
-      gog_series_set_dim(series, 0, labelData, NULL);
-      go_data_emit_changed (GO_DATA (labelData));
+      g_object_ref (label_data);
+      gog_series_set_dim (series, 0, label_data, NULL);
+      go_data_emit_changed (GO_DATA (label_data));
 
-      sliceData = go_data_vector_val_new( data + (i*datarows), datarows, NULL );
-      gog_series_set_dim( series, 1, sliceData, NULL );
-      
-      /*
-       This appears from code inspection to be what's required, but doesn't
-       seem to work correctly...
-        GOG_STYLED_OBJECT(series)->style->fill.type = GOG_FILL_STYLE_PATTERN;
-        GOG_STYLED_OBJECT(series)->style->fill.auto_fore = FALSE;
-        go_pattern_set_solid(&GOG_STYLED_OBJECT(series)->style->fill.pattern,
-                             go_color_from_str("00:ff:00:00"));
-        gog_style_set_fill_brightness(GOG_STYLED_OBJECT(series)->style, 100.);
-      */
+      slice_data = go_data_vector_val_new (data + (i*data_rows), data_rows, NULL);
+      gog_series_set_dim (series, 1, slice_data, NULL);
+      go_data_emit_changed (GO_DATA (slice_data));
 
-      go_data_emit_changed (GO_DATA (sliceData));
+      style = gog_styled_object_get_style (GOG_STYLED_OBJECT (series));
+      style->fill.type = GOG_FILL_STYLE_PATTERN;
+      if (gdk_color_parse (col_colors[i], &color)) {
+	style->fill.auto_back = FALSE;
+	go_pattern_set_solid (&style->fill.pattern, GDK_TO_UINT (color));
+      } else {
+	PERR("cannot parse color %s.", col_colors[i]);
+      }
     }
   }
 
-  set_chart_titles_from_hash(chart, eb);
-  set_chart_axis_labels_from_hash(chart, eb);
+  if (rotate_row_labels) {
+    GogObject *object = gog_object_get_child_by_role (
+      chart, gog_object_find_role_by_name (chart, "X-Axis"));
+    style = gog_styled_object_get_style (GOG_STYLED_OBJECT (object));
+    gog_style_set_text_angle (style, 90.0);
+  }
 
+  set_chart_titles_from_hash (chart, eb);
+  set_chart_axis_labels_from_hash (chart, eb);
+
   // we need to do this twice for the barchart... :p
-  gog_object_update( GOG_OBJECT(graph) );
+  gog_object_update (GOG_OBJECT (graph));
 
-  addPixbufGraphWidget( eb, graph );
+  addPixbufGraphWidget (eb, graph);
 
-  PINFO( "barchart rendered." );
+  PINFO("barchart rendered.");
   return TRUE;
 }
 



More information about the gnucash-changes mailing list