[rkward-cvs] SF.net SVN: rkward: [1902] trunk/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Fri May 11 00:08:17 UTC 2007


Revision: 1902
          http://svn.sourceforge.net/rkward/?rev=1902&view=rev
Author:   tfry
Date:     2007-05-10 17:08:16 -0700 (Thu, 10 May 2007)

Log Message:
-----------
Make barplot options page embeddable

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/plugins/Makefile.am
    trunk/rkward/rkward/plugins/plots/barplot.php
    trunk/rkward/rkward/plugins/plots/barplot.rkh
    trunk/rkward/rkward/plugins/plots/barplot.xml
    trunk/rkward/rkward/plugins/plots.pluginmap
    trunk/rkward/rkward/rkwardapplication.cpp
    trunk/rkward/rkward/scriptbackends/common.php

Added Paths:
-----------
    trunk/rkward/rkward/plugins/plots/barplot_options.php
    trunk/rkward/rkward/plugins/plots/barplot_options.rkh
    trunk/rkward/rkward/plugins/plots/barplot_options.xml

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2007-05-10 21:18:21 UTC (rev 1901)
+++ trunk/rkward/ChangeLog	2007-05-11 00:08:16 UTC (rev 1902)
@@ -2,7 +2,7 @@
 - create the workspace browser only when it is first shown
 - support for including files and snippets in xml files		TODO: use more
 - all file selection line edits gain filename-completion
-- add a basic file selector window
+- add a basic file selector window				TODO: add window activation shortcut
 - show the focus indication (thin red border) also for detached windows
 - tool windows can be closed and detached in the same way as regular windows
 - fix a crash with detached tool windows

Modified: trunk/rkward/rkward/plugins/Makefile.am
===================================================================
--- trunk/rkward/rkward/plugins/Makefile.am	2007-05-10 21:18:21 UTC (rev 1901)
+++ trunk/rkward/rkward/plugins/Makefile.am	2007-05-11 00:08:16 UTC (rev 1902)
@@ -47,9 +47,12 @@
 	plots/pareto.php \
 	plots/pareto.xml \
 	plots/pareto.rkh \
+	plots/barplot_options.xml \
 	plots/histogram_options.php \
 	plots/histogram_options.rkh \
 	plots/histogram_options.xml \
+	plots/barplot_options.rkh \
+	plots/barplot_options.php \
 	plots/stem.rkh \
 	plots/stem.xml \
 	plots/stem.php \

Modified: trunk/rkward/rkward/plugins/plots/barplot.php
===================================================================
--- trunk/rkward/rkward/plugins/plots/barplot.php	2007-05-10 21:18:21 UTC (rev 1901)
+++ trunk/rkward/rkward/plugins/plots/barplot.php	2007-05-11 00:08:16 UTC (rev 1902)
@@ -16,10 +16,11 @@
 }
 	
 function doPrintout ($final) {
-	$var = getRK_val ("x") ;
-	$labels = getRK_val ("labels")=="TRUE";
-	$tabulate= getRK_val ("tabulate")=="TRUE";
-	
+	$var = getRK_val ("x");
+
+	$barplot_header = getRK_val ("barplot_options.code.preprocess");
+	$barplot_main = getRK_val ("barplot_options.code.printout");
+
 ?>
 x <- <? echo ($var . "\n"); ?>
 <?
@@ -31,27 +32,15 @@
 <? }
 
 	if ($final) { ?>
-rk.header ("Barplot", parameters=list ("Rainbow colors", "<? getRK ("rainbow"); ?>", "Beside", "<? getRK ("beside"); ?>", "Legend", "<? getRK ("legend"); ?>"))
+rk.header ("Barplot", parameters=list ("dummy", "dummy"<? echo ($barplot_header); ?>))
 
 rk.graph.on ()
 <?	}
 ?>
 try ({
-<?	if (getRK_val ("beside") == "TRUE") { ?>
-<?		if ($labels) { ?>
-	# adjust the range so that the labels will fit
-	yrange <- range (x, na.rm=TRUE) * 1.2
-	if (yrange[1] > 0) yrange[1] <- 0
-	if (yrange[2] < 0) yrange[2] <- 0
-<?		} ?>
-	bplot <- barplot(x<? if (getRK_val ("rainbow")=="TRUE") { ?>, col=rainbow( if(is.matrix(x)) dim(x) else length(x))<? } ?>, beside=<? getRK ("beside"); ?>, legend.text=<? getRK ("legend"); ?><? if ($labels) echo (", ylim = yrange"); ?>)
-<?		if ($labels) { ?>
-	text(bplot, x, labels=x, pos=<? getRK ("place"); ?>, offset=.5)
-<?		}
-	} else { ?>
-	barplot(x<? if (getRK_val ("rainbow")=="TRUE") { ?>, col=rainbow( if(is.matrix(x)) dim(x) else length(x))<? } ?>, legend.text=<? getRK ("legend"); ?>)
-<?	}
-	?>
+<?
+	printIndented ("\t", $barplot_main);
+?>
 })
 <?	if ($final) { ?>
 rk.graph.off ()

Modified: trunk/rkward/rkward/plugins/plots/barplot.rkh
===================================================================
--- trunk/rkward/rkward/plugins/plots/barplot.rkh	2007-05-10 21:18:21 UTC (rev 1901)
+++ trunk/rkward/rkward/plugins/plots/barplot.rkh	2007-05-11 00:08:16 UTC (rev 1902)
@@ -5,7 +5,7 @@
 	</summary>
 
 	<usage>
-Choose a matrix, vector or a factor to be plotted. Choose if you want stacked bars, legend, and rainbow colors. Also you can choose if you want to display or not bar values (labels) and in what place.
+Choose a matrix, vector or a factor to be plotted. Further options are available on the second tab.
 	</usage>
 
 	<settings>
@@ -13,18 +13,11 @@
 		<setting id="x">Select a data matrix, a vector or a factor to be plotted.</setting>
 		<setting id="tabulate">Use tabulate option mainly for factor variables or wherever else applicable</setting>
 		<caption id="tab_options"/>
-		<setting id="legend">Select if you want to add a legend to the barplot. The row names of height will be used as labels if they are non-null.</setting>
-		<setting id="rainbow">Select between grey and rainbow collors.</setting>
-		<setting id="beside">Select a type between juxtaposed bars and stacked bars. If you select stacked bars you can not display bar values (labels). </setting>
-		<setting id="labels">Select if you want to display bar values (labels).</setting>
-		<setting id="place">If you have selected to display bar values (labels) you can select where should they be displayed:
-		<li> Above the bars </li>
-		<li> Beside the bars </li>
-		<li> Inside the bars </li>
-		</setting>		
+		<setting id="barplot_options">Since these settings are reused in further plugins, they are documented on a page of their own: See <link href="rkward://component/barplot_options"/>.</setting>
 	</settings>
 	<related>
 		<ul>
+			<li><link href="rkward://component/barplot_options"/></li>
 			<li><link href="rkward://rhelp/barplot"/></li>
 			<li><link href="rkward://rhelp/table"/></li>
 		</ul>

Modified: trunk/rkward/rkward/plugins/plots/barplot.xml
===================================================================
--- trunk/rkward/rkward/plugins/plots/barplot.xml	2007-05-10 21:18:21 UTC (rev 1901)
+++ trunk/rkward/rkward/plugins/plots/barplot.xml	2007-05-11 00:08:16 UTC (rev 1902)
@@ -3,11 +3,7 @@
 	<code file="barplot.php" />
 	<help file="barplot.rkh" />
 	<logic>
-		<convert id="besidevalue" mode="equals" sources="beside.string" standard="TRUE" />
-		<connect client="labels.enabled" governor="besidevalue" />
-		<convert id="labelsvalue" mode="equals" sources="labels.string" standard="TRUE" />
-		<convert id="labelsvalue2" mode="and" sources="labelsvalue;labels.enabled" />
-		<connect client="place.enabled" governor="labelsvalue2" />
+		<set id="barplot_options.xvar" to="x"/>
 	</logic>
 	<dialog label="Barplot" >		
 		<tabbook>
@@ -23,21 +19,7 @@
 				</row>
 			</tab>
 			<tab label="Options" id="tab_options">
-				<checkbox id="legend" label="Legend" value="TRUE" value_unchecked="FALSE" checked="false"/>
-				<checkbox id="rainbow" label="Rainbow colors" value="TRUE" value_unchecked="FALSE" checked="false"/>
-				<radio id="beside" label="Type" >
-					<option value="TRUE" label="Juxtaposed" checked="true"/>
-					<option value="FALSE" label="Stacked"/>
-				</radio>
-				<radio id="labels" label="Label values" >
-					<option value="TRUE" label="Display" />
-					<option value="FALSE" label="Do not Display" checked="true"/>					
-				</radio>
-				<radio id="place" label="Display label values">
-					<option value="3" label="Above Bars" checked="true"/>
-					<option value="2" label="Beside Bars"/>
-					<option value="1" label="Inside Bars"/>
-				</radio>
+				<embed id="barplot_options" component="rkward::barplot_options"/>
 			</tab>
 		</tabbook>			
 	</dialog>

Added: trunk/rkward/rkward/plugins/plots/barplot_options.php
===================================================================
--- trunk/rkward/rkward/plugins/plots/barplot_options.php	                        (rev 0)
+++ trunk/rkward/rkward/plugins/plots/barplot_options.php	2007-05-11 00:08:16 UTC (rev 1902)
@@ -0,0 +1,62 @@
+<?
+function preprocess () {
+	// first fetch all relevant options
+	global $options;
+	$options = array ();
+
+	$options['xvar'] = getRK_val ("xvar");
+	$options['type'] = getRK_val ("type");
+	if ($options['type'] == "juxtaposed") {
+		$options['juxtaposed'] = true;
+		$options['labels'] = getRK_val ("labels");
+		if ($options['labels']) {
+			$options['place'] = getRK_val ("place");
+		}
+	} else {
+		$options['labels'] = false;
+		$options['juxtaposed'] = false;
+	}
+	$options['legend'] = getRK_val ("legend");
+	$options['colors'] = getRK_val ("colors");
+
+	// generate and print argument list suitable for display in rk.header
+	if ($options['legend']) $legend_label = "TRUE";
+	else $legend_label = "FALSE";
+	echo (', "colors", "' . $options['colors'] . '", "Type", "' . $options['type'] . '", "Legend", "' . $legend_label . '"');
+}
+
+function calculate () {
+}
+
+function printout () {
+	global $options;
+
+	if ($options['colors'] == 'rainbow') {
+		$col_option = ', col=rainbow (if(is.matrix(' . $options['xvar'] . ')) dim(' . $options['xvar'] . ') else length(' . $options['xvar'] . '))';
+	}
+
+	// construct the main call to barplot
+	$main_call = 'barplot(' . $options['xvar'] . $col_option;
+	if ($options['juxtaposed']) $main_call .= ', beside=TRUE';
+	if ($options['legend']) $main_call .= ', legend.text=TRUE';
+	if ($options['labels']) $main_call .= ", ylim = yrange";
+	$main_call .= ")\n";
+
+	// now print everything as needed
+	if ($options['labels']) { ?>
+# adjust the range so that the labels will fit
+yrange <- range (<? echo ($options['xvar']); ?>, na.rm=TRUE) * 1.2
+if (yrange[1] > 0) yrange[1] <- 0
+if (yrange[2] < 0) yrange[2] <- 0
+<?	
+		echo ("bplot <- ");
+	}
+
+	echo ($main_call);
+
+	if ($options['labels']) {
+		echo ('text (bplot,' . $options['xvar'] . ', labels=' . $options['xvar'] . ', pos=' . $options['place'] . ', offset=.5)');
+		echo ("\n");
+	}
+}
+?>

Added: trunk/rkward/rkward/plugins/plots/barplot_options.rkh
===================================================================
--- trunk/rkward/rkward/plugins/plots/barplot_options.rkh	                        (rev 0)
+++ trunk/rkward/rkward/plugins/plots/barplot_options.rkh	2007-05-11 00:08:16 UTC (rev 1902)
@@ -0,0 +1,32 @@
+<!DOCTYPE rkhelp>
+<document>
+	<summary>
+Options applicable to bar plots
+	</summary>
+
+	<usage>
+Choose if you want stacked bars, legend, and rainbow colors. Also you can choose if you want to display or not bar values (labels) and in what place.
+	</usage>
+
+	<settings>
+		<setting id="legend">Select if you want to add a legend to the barplot. The row names of height will be used as labels if they are non-null.</setting>
+		<setting id="colors">Select between grey and rainbow collors.</setting>
+		<setting id="type">Select a type between juxtaposed bars and stacked bars. If you select stacked bars you can not display bar values (labels). </setting>
+		<setting id="labels">Select if you want to display bar values (labels).</setting>
+		<setting id="place">If you have selected to display bar values (labels) you can select where should they be displayed:
+		<li> Above the bars </li>
+		<li> Beside the bars </li>
+		<li> Inside the bars </li>
+		</setting>		
+	</settings>
+	<related>
+		<ul>
+			<li><link href="rkward://component/barplot"/></li>
+			<li><link href="rkward://rhelp/barplot"/></li>
+			<li><link href="rkward://rhelp/table"/></li>
+		</ul>
+	</related>
+	<technical>
+		TODO: Write me
+	</technical>
+</document>

Added: trunk/rkward/rkward/plugins/plots/barplot_options.xml
===================================================================
--- trunk/rkward/rkward/plugins/plots/barplot_options.xml	                        (rev 0)
+++ trunk/rkward/rkward/plugins/plots/barplot_options.xml	2007-05-11 00:08:16 UTC (rev 1902)
@@ -0,0 +1,32 @@
+<!DOCTYPE rkplugin>
+<document>
+	<code file="barplot_options.php" />
+	<help file="barplot_options.rkh" />
+	<logic>
+		<external id="xvar" default=""/>
+
+		<convert id="juxtaposed" mode="equals" sources="type.string" standard="juxtaposed" />
+		<connect client="labels.enabled" governor="juxtaposed" />
+		<convert id="labelsvalue" mode="and" sources="labels.state;labels.enabled" />
+		<connect client="place.enabled" governor="labelsvalue" />
+	</logic>
+	<dialog label="Barplot Options">
+		<checkbox id="legend" label="Draw Legend" value="1" value_unchecked="0" checked="false"/>
+		<radio id="colors" label="Colors" >
+			<option value="default" label="Default (grayscale)"/>
+			<option value="rainbow" label="Rainbow colors" checked="true"/>
+		</radio>
+		<radio id="type" label="Type" >
+			<option value="juxtaposed" label="Juxtaposed" checked="true"/>
+			<option value="stacked" label="Stacked"/>
+		</radio>
+		<frame id="Value labels">
+			<checkbox id="labels" label="Display values" value="1" value_unchecked="0"/>
+			<radio id="place" label="Placement">
+				<option value="3" label="Above Bars" checked="true"/>
+				<option value="2" label="Beside Bars"/>
+				<option value="1" label="Inside Bars"/>
+			</radio>
+		</frame>
+	</dialog>	
+</document>

Modified: trunk/rkward/rkward/plugins/plots.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/plots.pluginmap	2007-05-10 21:18:21 UTC (rev 1901)
+++ trunk/rkward/rkward/plugins/plots.pluginmap	2007-05-11 00:08:16 UTC (rev 1902)
@@ -3,6 +3,7 @@
 <document base_prefix="plots/" namespace="rkward">
 	<components>
 		<component type="standard" id="barplot" file="barplot.xml" label="Barplot" />
+		<component type="standard" id="barplot_options" file="barplot_options.xml" label="Barplot Options" />
 		<component type="standard" id="box_plot" file="box_plot.xml" label="Box Plot" />
 		<component type="standard" id="density_plot" file="density_plot.xml" label="Density Plot" />
 		<component type="standard" id="ecdf_plot" file="ecdf_plot.xml" label="ECDF Plot" />

Modified: trunk/rkward/rkward/rkwardapplication.cpp
===================================================================
--- trunk/rkward/rkward/rkwardapplication.cpp	2007-05-10 21:18:21 UTC (rev 1901)
+++ trunk/rkward/rkward/rkwardapplication.cpp	2007-05-11 00:08:16 UTC (rev 1902)
@@ -66,7 +66,7 @@
 
 	if (!created_window) {
 		// we did not see the window, yet? Maybe the event simply hasn't been processed, yet.
-		syncX();
+		syncX ();
 		processEvents ();
 	}
 

Modified: trunk/rkward/rkward/scriptbackends/common.php
===================================================================
--- trunk/rkward/rkward/scriptbackends/common.php	2007-05-10 21:18:21 UTC (rev 1901)
+++ trunk/rkward/rkward/scriptbackends/common.php	2007-05-11 00:08:16 UTC (rev 1902)
@@ -1,6 +1,6 @@
 <?
 function printIndented ($indentation, $lines) {
-	$out = ereg_replace ("\n.", "\\1\n" . $indentation, $lines);
+	$out = ereg_replace ("\n(.)", "\n" . $indentation . "\\1", $lines);
 	echo ($indentation . $out);
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list