genius r724 - in trunk: . help/C src



Author: jirka
Date: Tue Feb 17 23:39:50 2009
New Revision: 724
URL: http://svn.gnome.org/viewvc/genius?rev=724&view=rev

Log:

Tue Feb 17 17:35:44 2009  Jiri (George) Lebl <jirka 5z com>

	* src/graphing.c: fix the scales on the axis (the precision was
	  reversed!)

	* src/graphing.c: draw the x/y axis and a dotted grid in grey.  This
	  really improves readability I think.  This should be configurable I
	  guess.

	* src/funclib.c, src/gnome-genius.c, src/genius.c: allow setting
	  default for AskString as second argument

	* help/C/gel-function-list.xml: update



Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/help/C/gel-function-list.xml
   trunk/help/C/genius.txt
   trunk/src/calc.h
   trunk/src/funclib.c
   trunk/src/genius.c
   trunk/src/gnome-genius.c
   trunk/src/graphing.c

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Tue Feb 17 23:39:50 2009
@@ -1,8 +1,14 @@
 Changes to 1.0.6
 
-* Remove dependence on libgnome/ui
+* Draw grid and x/y axis on lineplots in gray, much better readability
 * Draw solutions for vector fields
 * Add VectorfieldDrawSolution and VectorfieldClearSolutions
+* AskString now allows setting a default
+* Fix line plot scale precision in case the x and y axis have very different
+  scales
+* An icon for the plot button
+* Remove dependence on libgnome/ui
+* Translation updates
 
 Changes to 1.0.5
 

Modified: trunk/help/C/gel-function-list.xml
==============================================================================
--- trunk/help/C/gel-function-list.xml	(original)
+++ trunk/help/C/gel-function-list.xml	Tue Feb 17 23:39:50 2009
@@ -68,10 +68,11 @@
          <term>AskString</term>
          <listitem>
           <synopsis>AskString (query)</synopsis>
+          <synopsis>AskString (query, default)</synopsis>
           <para>Asks a question and lets the user enter a string which
 it then returns.  If the user cancels or closes the window, then
 <constant>null</constant> is returned.  The execution of the program
-is blocked until the user responds.</para>
+is blocked until the user responds.  If <varname>default</varname> is given, then it is pre-typed in for the user to just press enter on.</para>
          </listitem>
         </varlistentry>
 
@@ -1020,7 +1021,8 @@
         <varlistentry id="gel-function-log">
          <term>log</term>
          <listitem>
-          <synopsis>log (x,b...)</synopsis>
+          <synopsis>log (x)</synopsis>
+          <synopsis>log (x,b)</synopsis>
           <para>Logarithm of <varname>x</varname> base <varname>b</varname> (calls <function>DiscreteLog</function> if in modulo mode), if base is not given, <varname>e</varname> is used.</para>
          </listitem>
         </varlistentry>

Modified: trunk/help/C/genius.txt
==============================================================================
--- trunk/help/C/genius.txt	(original)
+++ trunk/help/C/genius.txt	Tue Feb 17 23:39:50 2009
@@ -1978,10 +1978,13 @@
 
  AskString (query)
 
+ AskString (query, default)
+
            Asks a question and lets the user enter a string which it then
            returns. If the user cancels or closes the window, then null is
            returned. The execution of the program is blocked until the user
-           responds.
+           responds. If default is given, then it is pre-typed in for the
+           user to just press enter on.
 
    Compose
 
@@ -2694,7 +2697,9 @@
 
    log
 
- log (x,b...)
+ log (x)
+
+ log (x,b)
 
            Logarithm of x base b (calls DiscreteLog if in modulo mode), if
            base is not given, e is used.

Modified: trunk/src/calc.h
==============================================================================
--- trunk/src/calc.h	(original)
+++ trunk/src/calc.h	Tue Feb 17 23:39:50 2009
@@ -113,7 +113,7 @@
 void gel_call_help (const char *function);
 
 /* implemented in the frontend (query can be NULL) */
-char *gel_ask_string (const char *query);
+char *gel_ask_string (const char *query, const char *def);
 
 void gel_help_on (const char *text);
 

Modified: trunk/src/funclib.c
==============================================================================
--- trunk/src/funclib.c	(original)
+++ trunk/src/funclib.c	Tue Feb 17 23:39:50 2009
@@ -5636,11 +5636,18 @@
 AskString_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
 {
 	char *txt;
+	const char *def = NULL;
 
 	if G_UNLIKELY ( ! check_argument_string (a, 0, "AskString"))
 		return NULL;
 
-	txt = gel_ask_string (a[0]->str.str);
+	if (a[1] != NULL) {
+		if G_UNLIKELY ( ! check_argument_string (a, 1, "AskString"))
+			return NULL;
+		def = a[1]->str.str;
+	}
+
+	txt = gel_ask_string (a[0]->str.str, def);
 
 	if (txt == NULL)
 		return gel_makenum_null ();
@@ -6350,7 +6357,7 @@
 	FUNC (Parse, 1, "str", "basic", N_("Parse a string (but do not execute)"));
 	FUNC (Evaluate, 1, "str", "basic", N_("Parse and evaluate a string"));
 
-	FUNC (AskString, 1, "query", "basic", N_("Ask a question and return a string"));
+	VFUNC (AskString, 2, "query,...", "basic", N_("Ask a question and return a string.  Optionally pass in a default."));
 
 	FUNC (CompositeSimpsonsRule, 4, "f,a,b,n", "calculus", N_("Integration of f by Composite Simpson's Rule on the interval [a,b] with n subintervals with error of max(f'''')*h^4*(b-a)/180, note that n should be even"));
 	f->no_mod_all_args = 1;

Modified: trunk/src/genius.c
==============================================================================
--- trunk/src/genius.c	(original)
+++ trunk/src/genius.c	Tue Feb 17 23:39:50 2009
@@ -195,19 +195,27 @@
 }
 
 char *
-gel_ask_string (const char *query)
+gel_ask_string (const char *query, const char *def)
 {
 	char *txt = NULL;
 
 	g_print ("\n%s\n", ve_sure_string (query));
 	if (use_readline) {
-		char *s = readline (">");
+		char *s;
+		if ( ! ve_string_empty (def)) {
+			const char *p;
+			for (p = def; *p != '\0'; p++)
+				rl_stuff_char (*p);
+		}
+		s = readline (">");
 		if (s != NULL) {
 			txt = g_strdup (s);
 			free (s);
 		}
 	} else {
 		char buf[256];
+		if ( ! ve_string_empty (def))
+			g_print (_("Suggested: %s\n"), ve_sure_string (def));
 		if (fgets (buf, sizeof (buf), stdin) != NULL) {
 			int len = strlen (buf);
 			if (buf[len-1] == '\n')

Modified: trunk/src/gnome-genius.c
==============================================================================
--- trunk/src/gnome-genius.c	(original)
+++ trunk/src/gnome-genius.c	Tue Feb 17 23:39:50 2009
@@ -710,7 +710,7 @@
 }
 
 char *
-gel_ask_string (const char *query)
+gel_ask_string (const char *query, const char *def)
 {
 	GtkWidget *d;
 	GtkWidget *e;
@@ -741,6 +741,9 @@
 			    FALSE, FALSE, 0);
 
 	e = gtk_entry_new ();
+	if ( ! ve_string_empty (def)) {
+		gtk_entry_set_text (GTK_ENTRY (e), def);
+	}
 	g_signal_connect (G_OBJECT (e), "activate",
 			  G_CALLBACK (dialog_entry_activate), d);
 	gtk_box_pack_start (GTK_BOX (box),

Modified: trunk/src/graphing.c
==============================================================================
--- trunk/src/graphing.c	(original)
+++ trunk/src/graphing.c	Tue Feb 17 23:39:50 2009
@@ -1862,37 +1862,40 @@
 	int incs;
 	double len = end-start;
 	int tries = 0;
+	int tickprec;
 
-	*tick = pow (10, floor (log10(len)));
+	tickprec = -floor (log10(len));
+	*tick = pow (10, -tickprec);
 	incs = floor (len / *tick);
 
-	while (incs < 3) {
-		*tick /= 2.0;
-		incs = floor (len / *tick);
-		/* sanity */
-		if (tries ++ > 100) {
-			*tick = len / 5;
-			*prec = - (int) log10 (*tick) + 1;
-			return;
-		}
-
-	}
+	if (incs < 3) {
+		while (incs < 3) {
+			*tick /= 2.0;
+
+			tickprec ++;
+
+			incs = floor (len / *tick);
+			/* sanity */
+			if (tries ++ > 100) {
+				break;
+			}
 
-	while (incs > 6) {
-		*tick *= 2.0;
-		incs = floor (len / *tick);
-		/* sanity */
-		if (tries ++ > 200) {
-			*tick = len / 5;
-			*prec = - (int) log10 (*tick) + 1;
-			return;
+		}
+	} else {
+		while (incs > 6) {
+			*tick *= 2.0;
+			incs = floor (len / *tick);
+			/* sanity */
+			if (tries ++ > 100) {
+				break;
+			}
 		}
 	}
 
 	if (*tick >= 0.99) {
 		*prec = 0;
 	} else {
-		*prec = - (int) log10 (*tick) + 1;
+		*prec = tickprec;
 	}
 }
 
@@ -1902,6 +1905,7 @@
 	int xprec, yprec;
 	double xtick, ytick;
 	GtkPlotAxis *x, *y;
+	GdkColor gray;
 
 	get_ticks (plotx1, plotx2, &xtick, &xprec);
 	get_ticks (ploty1, ploty2, &ytick, &yprec);
@@ -1913,26 +1917,58 @@
 	gtk_plot_set_ticks (GTK_PLOT (line_plot), GTK_PLOT_AXIS_X, xtick, 9);
 	gtk_plot_set_ticks (GTK_PLOT (line_plot), GTK_PLOT_AXIS_Y, ytick, 9);
 
-	x = gtk_plot_get_axis (GTK_PLOT (line_plot), GTK_PLOT_AXIS_LEFT);
+	/* this should all be configurable */
+	gtk_plot_x0_set_visible (GTK_PLOT (line_plot), TRUE);
+	gtk_plot_y0_set_visible (GTK_PLOT (line_plot), TRUE);
+
+	gtk_plot_grids_set_visible (GTK_PLOT (line_plot),
+				    TRUE /* vmajor */,
+				    FALSE /* vminor */,
+				    TRUE /* vmajor */,
+				    FALSE /* vminor */);
+
+	gdk_color_parse ("gray75", &gray);
+
+	gtk_plot_x0line_set_attributes (GTK_PLOT (line_plot),
+					GTK_PLOT_LINE_SOLID,
+					1 /* width */,
+					&gray);
+	gtk_plot_y0line_set_attributes (GTK_PLOT (line_plot),
+					GTK_PLOT_LINE_SOLID,
+					1 /* width */,
+					&gray);
+
+	gtk_plot_major_vgrid_set_attributes (GTK_PLOT (line_plot),
+					     GTK_PLOT_LINE_DOTTED,
+					     1 /* width */,
+					     &gray);
+	gtk_plot_major_hgrid_set_attributes (GTK_PLOT (line_plot),
+					     GTK_PLOT_LINE_DOTTED,
+					     1 /* width */,
+					     &gray);
+
+
+	x = gtk_plot_get_axis (GTK_PLOT (line_plot), GTK_PLOT_AXIS_TOP);
 	gtk_plot_axis_set_labels_style (x,
 					GTK_PLOT_LABEL_FLOAT,
 					xprec /* precision */);
 
-	x = gtk_plot_get_axis (GTK_PLOT (line_plot), GTK_PLOT_AXIS_RIGHT);
+	x = gtk_plot_get_axis (GTK_PLOT (line_plot), GTK_PLOT_AXIS_BOTTOM);
 	gtk_plot_axis_set_labels_style (x,
 					GTK_PLOT_LABEL_FLOAT,
 					xprec /* precision */);
 
-	y = gtk_plot_get_axis (GTK_PLOT (line_plot), GTK_PLOT_AXIS_TOP);
+	y = gtk_plot_get_axis (GTK_PLOT (line_plot), GTK_PLOT_AXIS_LEFT);
 	gtk_plot_axis_set_labels_style (y,
 					GTK_PLOT_LABEL_FLOAT,
 					yprec /* precision */);
 
-	y = gtk_plot_get_axis (GTK_PLOT (line_plot), GTK_PLOT_AXIS_BOTTOM);
+	y = gtk_plot_get_axis (GTK_PLOT (line_plot), GTK_PLOT_AXIS_RIGHT);
 	gtk_plot_axis_set_labels_style (y,
 					GTK_PLOT_LABEL_FLOAT,
 					yprec /* precision */);
 
+
 	/* FIXME: implement logarithmic scale
 	gtk_plot_set_xscale (GTK_PLOT (line_plot), GTK_PLOT_SCALE_LOG10);
 	gtk_plot_set_yscale (GTK_PLOT (line_plot), GTK_PLOT_SCALE_LOG10);



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