gnumeric r16802 - in trunk: . src/dialogs src/tools



Author: guelzow
Date: Wed Sep 17 07:30:19 2008
New Revision: 16802
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16802&view=rev

Log:
2008-09-17  Andreas J. Guelzow <aguelzow pyrshep ca>

	* histogram.glade: enable chart check box
	* dialog-analysis-tools.c (histogram_tool_ok_clicked_cb): read chart
	  check box.

2008-09-17  Andreas J. Guelzow <aguelzow pyrshep ca>

	* analysis-histogram.c (analysis_tool_histogram_engine_run): create
	  histogram chart if appropriate
	* analysis-histogram.h (chart_t): new
	(analysis_tools_data_histogram_t): change field format for chart
	* dao.h (dao_set_sheet_object): new
	(dao_get_rangeref): new
	(dao_go_data_vector): new
	* dao.c (dao_set_sheet_object): new
	(dao_get_rangeref): new
	(dao_go_data_vector): new



Modified:
   trunk/NEWS
   trunk/src/dialogs/ChangeLog
   trunk/src/dialogs/dialog-analysis-tools.c
   trunk/src/dialogs/histogram.glade
   trunk/src/tools/ChangeLog
   trunk/src/tools/analysis-histogram.c
   trunk/src/tools/analysis-histogram.h
   trunk/src/tools/dao.c
   trunk/src/tools/dao.h

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Wed Sep 17 07:30:19 2008
@@ -11,7 +11,7 @@
 	* Don't force text export of empty sheets [#521726]
 	* By default cells with hyperlinks should not be empty [#152617]
 	* Fix command names for hyperlink additions.
-	* Improve histogram tool [#385458]
+	* Improve histogram tool [#385458][#552161]
 
 Jean:
 	* Fix printing of rotated text. [#539734]

Modified: trunk/src/dialogs/dialog-analysis-tools.c
==============================================================================
--- trunk/src/dialogs/dialog-analysis-tools.c	(original)
+++ trunk/src/dialogs/dialog-analysis-tools.c	Wed Sep 17 07:30:19 2008
@@ -2546,8 +2546,11 @@
 	data->percentage = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w));
 	w = glade_xml_get_widget (state->base.gui, "cum-button");
 	data->cumulative = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w));
-/* 	w = glade_xml_get_widget (state->base.gui, "chart-button"); */
-/* 	data->chart = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)); */
+	w = glade_xml_get_widget (state->base.gui, "chart-button");
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w))) 
+		data->chart = HISTOGRAM_CHART;
+	else
+		data->chart = NO_CHART;
 
 	if (!cmd_analysis_tool (WORKBOOK_CONTROL (state->base.wbcg), state->base.sheet,
 			       dao, data, analysis_tool_histogram_engine))

Modified: trunk/src/dialogs/histogram.glade
==============================================================================
--- trunk/src/dialogs/histogram.glade	(original)
+++ trunk/src/dialogs/histogram.glade	Wed Sep 17 07:30:19 2008
@@ -521,7 +521,6 @@
                 <child>
                   <widget class="GtkCheckButton" id="chart-button">
                     <property name="visible">True</property>
-                    <property name="sensitive">False</property>
                     <property name="can_focus">True</property>
                     <property name="label" translatable="yes">_Chart output</property>
                     <property name="use_underline">True</property>
@@ -551,12 +550,10 @@
                     </child>
                     <child>
                       <widget class="GtkRadioButton" id="columnchart-button">
-                        <property name="visible">True</property>
                         <property name="sensitive">False</property>
                         <property name="can_focus">True</property>
                         <property name="label" translatable="yes">Column chart</property>
                         <property name="response_id">0</property>
-                        <property name="active">True</property>
                         <property name="draw_indicator">True</property>
                         <property name="group">barchart-button</property>
                       </widget>
@@ -574,6 +571,7 @@
                         <property name="can_focus">True</property>
                         <property name="label" translatable="yes">Histogram chart</property>
                         <property name="response_id">0</property>
+                        <property name="active">True</property>
                         <property name="draw_indicator">True</property>
                         <property name="group">barchart-button</property>
                       </widget>
@@ -586,12 +584,10 @@
                     </child>
                     <child>
                       <widget class="GtkRadioButton" id="barchart-button">
-                        <property name="visible">True</property>
                         <property name="sensitive">False</property>
                         <property name="can_focus">True</property>
                         <property name="label" translatable="yes">Bar chart</property>
                         <property name="response_id">0</property>
-                        <property name="active">True</property>
                         <property name="draw_indicator">True</property>
                       </widget>
                       <packing>

Modified: trunk/src/tools/analysis-histogram.c
==============================================================================
--- trunk/src/tools/analysis-histogram.c	(original)
+++ trunk/src/tools/analysis-histogram.c	Wed Sep 17 07:30:19 2008
@@ -35,6 +35,10 @@
 #include "expr.h"
 #include "func.h"
 #include "numbers.h"
+#include "sheet-object-graph.h"
+#include <goffice/graph/gog-graph.h>
+#include <goffice/graph/gog-object.h>
+#include <goffice/graph/gog-chart.h>
 
 static gboolean
 analysis_tool_histogram_engine_run (data_analysis_output_t *dao,
@@ -174,7 +178,7 @@
 								   GNM_EXPR_OP_SUB, 
 								   gnm_expr_copy (expr_min)), 
 								  GNM_EXPR_OP_DIV,
-								  gnm_expr_new_constant (value_new_int (info->n))))));
+								  gnm_expr_new_constant (value_new_int (info->n - 1))))));
 		
 		gnm_expr_free (expr_min);
 		gnm_expr_free (expr_max);
@@ -311,6 +315,51 @@
 	if (fd_count != NULL)
 		gnm_func_unref (fd_count);
 
+	/* Create Chart if requested */
+
+	switch (info->chart) {
+		SheetObject *so;
+		GogGraph     *graph;
+		GogChart     *chart;
+		GogPlot	     *plot;
+		GogSeries    *series;
+		GOData *limits;
+		GOData *values;
+		int ct;
+
+	case HISTOGRAM_CHART:
+		graph = g_object_new (GOG_GRAPH_TYPE, NULL);
+		chart = GOG_CHART (gog_object_add_by_name (
+					   GOG_OBJECT (graph), "Chart", NULL));
+		plot = gog_plot_new_by_name ("GogHistogramPlot");
+		gog_object_add_by_name (GOG_OBJECT (chart),
+					"Plot", GOG_OBJECT (plot));
+
+		limits = dao_go_data_vector (dao, to_col, i_start, to_col, 
+					     i_start + i_limit - 1);
+
+		for (ct = 1; ct < (col - to_col); ct ++) {
+			g_object_ref (limits);
+			values = dao_go_data_vector (dao, to_col + ct, i_start + 1, 
+						     to_col + ct, i_start + i_limit - 1);
+			
+			series = gog_plot_new_series (plot);
+			gog_series_set_dim (series, 0, limits, NULL);
+			gog_series_set_dim (series, 1, values, NULL);
+		}
+		g_object_unref (limits);
+
+		so = sheet_object_graph_new (graph);
+
+		dao_set_sheet_object (dao, 0, 1, so);
+		break;
+	case BAR_CHART:  /* not yet implemented */
+	case COLUMN_CHART:  /* not yet implemented */
+	case NO_CHART:
+	default:
+		break;
+	}
+
 	dao_redraw_respan (dao);
 
 	return FALSE;

Modified: trunk/src/tools/analysis-histogram.h
==============================================================================
--- trunk/src/tools/analysis-histogram.h	(original)
+++ trunk/src/tools/analysis-histogram.h	Wed Sep 17 07:30:19 2008
@@ -46,6 +46,14 @@
 	bintype_pm_inf_upper = bintype_m_inf_lower | bintype_p_inf_lower | bintype_no_inf_upper
 } analysis_histogram_bin_type_t;
 
+typedef enum {
+	NO_CHART = 0,
+	HISTOGRAM_CHART,
+	BAR_CHART,
+	COLUMN_CHART
+} chart_t;
+
+
 typedef struct {
 	analysis_tools_data_generic_t base;
 	gboolean   predetermined;
@@ -58,7 +66,7 @@
 	gint       n;
 	gboolean   percentage;
 	gboolean   cumulative;
-	gboolean   chart;	
+	chart_t   chart;	
 } analysis_tools_data_histogram_t;
 
 gboolean analysis_tool_histogram_engine (data_analysis_output_t *dao, gpointer specs,

Modified: trunk/src/tools/dao.c
==============================================================================
--- trunk/src/tools/dao.c	(original)
+++ trunk/src/tools/dao.c	Wed Sep 17 07:30:19 2008
@@ -42,6 +42,7 @@
 #include "gnm-format.h"
 #include "sheet-object-cell-comment.h"
 #include "style-color.h"
+#include "graph.h"
 #include <goffice/app/go-doc.h>
 
 #include <glib.h>
@@ -1113,14 +1114,61 @@
 
 
 GnmExpr const  *
-dao_get_cellref (data_analysis_output_t *dao, int dx, int dy)
+dao_get_cellref (data_analysis_output_t *dao, int x, int y)
 {
 	GnmCellRef r;
 	r.sheet = dao->sheet;
-	r.col = dx + dao->start_col + dao->offset_col;
+	r.col = x + dao->start_col + dao->offset_col;
 	r.col_relative = FALSE;
-	r.row = dy + dao->start_row + dao->offset_row;
+	r.row = y + dao->start_row + dao->offset_row;
 	r.row_relative = FALSE;
 	return gnm_expr_new_cellref (&r);
 }
 
+GnmExpr const  *
+dao_get_rangeref (data_analysis_output_t *dao, int ax, int ay,  int bx, int by)
+{
+	GnmValue *v;
+	GnmCellRef ar;
+	GnmCellRef br;
+
+	ar.sheet = dao->sheet;
+	ar.col = ax + dao->start_col + dao->offset_col;
+	ar.col_relative = FALSE;
+	ar.row = ay + dao->start_row + dao->offset_row;
+	ar.row_relative = FALSE;
+
+	br.sheet = dao->sheet;
+	br.col = bx + dao->start_col + dao->offset_col;
+	br.col_relative = FALSE;
+	br.row = by + dao->start_row + dao->offset_row;
+	br.row_relative = FALSE;
+
+	v = value_new_cellrange (&ar, &br, 0, 0);
+	return gnm_expr_new_constant (v);
+}
+
+
+void 
+dao_set_sheet_object (data_analysis_output_t *dao, int col, int row, SheetObject* so)
+{
+	SheetObjectAnchor anchor;
+	GnmRange	  anchor_r;
+
+	g_return_if_fail (so != NULL);
+		
+	range_init (&anchor_r, dao->start_col + col, dao->start_row + row,
+		    dao->start_col + dao->cols - 1,
+		    dao->start_row + dao->rows - 1);
+
+	sheet_object_anchor_init (&anchor, &anchor_r, 0, GOD_ANCHOR_DIR_UNKNOWN);
+	sheet_object_set_anchor (so, &anchor);
+	sheet_object_set_sheet (so, dao->sheet);
+	g_object_unref (so);
+}
+
+GOData	*
+dao_go_data_vector (data_analysis_output_t *dao, int ax, int ay,  int bx, int by)
+{
+	return gnm_go_data_vector_new_expr (dao->sheet, gnm_expr_top_new (dao_get_rangeref (dao, ax, ay, bx, by)));
+}

Modified: trunk/src/tools/dao.h
==============================================================================
--- trunk/src/tools/dao.h	(original)
+++ trunk/src/tools/dao.h	Wed Sep 17 07:30:19 2008
@@ -31,6 +31,7 @@
 #include "gnumeric.h"
 #include "numbers.h"
 #include "style.h"
+#include <goffice/data/goffice-data.h>
 
 typedef enum {
         NewSheetOutput, NewWorkbookOutput, RangeOutput, InPlaceOutput
@@ -103,6 +104,7 @@
 			   gboolean is_valid);
 void dao_set_cell_comment (data_analysis_output_t *dao, int col, int row,
 			   char const *comment);
+void dao_set_sheet_object (data_analysis_output_t *dao, int col, int row, SheetObject* so);
 
 void dao_prepare_output       (WorkbookControl *wbc,  
 			       data_analysis_output_t *dao, char const *name);
@@ -126,7 +128,9 @@
 void dao_convert_to_values (data_analysis_output_t *dao);
 void dao_redraw_respan (data_analysis_output_t *dao);
 
-GnmExpr const *dao_get_cellref (data_analysis_output_t *dao, int dx, int dy);
+GnmExpr const *dao_get_cellref  (data_analysis_output_t *dao, int x, int y);
+GnmExpr const *dao_get_rangeref (data_analysis_output_t *dao, int ax, int ay,  int bx, int by);
 
+GOData *dao_go_data_vector (data_analysis_output_t *dao, int ax, int ay,  int bx, int by);
 
 #endif



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