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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon Sep 12 10:45:13 UTC 2011


Revision: 3757
          http://rkward.svn.sourceforge.net/rkward/?rev=3757&view=rev
Author:   tfry
Date:     2011-09-12 10:45:13 +0000 (Mon, 12 Sep 2011)
Log Message:
-----------
Split limitation functionality into a separate embeddable plugin (useful also for dotchart, piechart, etc.)

Modified Paths:
--------------
    trunk/rkward/rkward/plugins/embedded.pluginmap
    trunk/rkward/rkward/plugins/plots/pareto.js
    trunk/rkward/rkward/plugins/plots/pareto.rkh
    trunk/rkward/rkward/plugins/plots/pareto.xml

Added Paths:
-----------
    trunk/rkward/rkward/plugins/data/limit_vector_length.js
    trunk/rkward/rkward/plugins/data/limit_vector_length.rkh
    trunk/rkward/rkward/plugins/data/limit_vector_length.xml

Added: trunk/rkward/rkward/plugins/data/limit_vector_length.js
===================================================================
--- trunk/rkward/rkward/plugins/data/limit_vector_length.js	                        (rev 0)
+++ trunk/rkward/rkward/plugins/data/limit_vector_length.js	2011-09-12 10:45:13 UTC (rev 3757)
@@ -0,0 +1,27 @@
+function calculate () {
+	var invar = getValue ("invar");
+	var outvar = getValue ("outvar");
+
+	echo ('max.categories <- ' + getValue ("cutoff") + '\n');
+	echo ('if (length (' + invar + ') > max.categories) {\n');
+	echo ('\t' + invar + ' <- sort (' + invar);
+	if (getValue ("sorting") != "lowest") echo (', decreasing=TRUE');
+	echo (')\n');
+	if (getValue ("include_others.checked")) {
+		var others_labelling = getValue ("others_label");
+		if (others_labelling != "") others_labelling = quote (others_labelling) + '=';
+		echo ('\tothers <- ' + invar + '[(max.categories+1):length(' + invar + ')]\n');
+		
+		var fun = getValue ("others_statistic");
+		if (fun == "custom") {
+			echo ('\tfun <- function (x) ' + getValue ("custom_stat") + '\n');
+			fun = "fun";
+		}
+
+		echo ('\t' + outvar + ' <- c (' + invar + '[1:max.categories], ' + others_labelling + fun + ' (others)' + ')\n');
+	} else {
+		echo ('\t' + outvar + ' <- ' + invar + '[1:max.categories]\n');
+	}
+	echo ('}\n');
+}
+

Added: trunk/rkward/rkward/plugins/data/limit_vector_length.rkh
===================================================================
--- trunk/rkward/rkward/plugins/data/limit_vector_length.rkh	                        (rev 0)
+++ trunk/rkward/rkward/plugins/data/limit_vector_length.rkh	2011-09-12 10:45:13 UTC (rev 3757)
@@ -0,0 +1,19 @@
+<!DOCTYPE rkhelp>
+<document>
+	<summary>
+		Generic plugin to limit a single numeric vector to the n largest / smallest values. This plugin is designed to be embeded into other plugins.
+	</summary>
+
+	<usage>
+		Specify the desired length cutoff and sorting. Note that the result is always sorted, with the sum of remainder values appended at the end.
+	</usage>
+
+	<settings>
+		<setting id="cutoff">Maximum number of regular groups to display. One additonal group "others" will be displayed, if appropriate.</setting>
+		<setting id="sorting">Should the largest or the lowest values be kept? For most purposes, you will want to keep the largest values.</setting>
+		<setting id="include_others">Should a category be added for the remaining value (those which have been cut off)? Note: This will always be appended to the end of the vector.</setting>
+		<setting id="others_statistic">Statistic to use for summarizing the cut off values.</setting>
+		<setting id="custom_stat">If you chose to use a custom statistic for summarizing the cut off values, specify it, here, as a function of <em>x</em>.</setting>
+		<setting id="others_label">Label to use for the "others" category. Note: If your data is not labelled, emptying this field will sometimes be preferrable.</setting>
+	</settings>
+</document>

Added: trunk/rkward/rkward/plugins/data/limit_vector_length.xml
===================================================================
--- trunk/rkward/rkward/plugins/data/limit_vector_length.xml	                        (rev 0)
+++ trunk/rkward/rkward/plugins/data/limit_vector_length.xml	2011-09-12 10:45:13 UTC (rev 3757)
@@ -0,0 +1,28 @@
+<!DOCTYPE rkplugin>
+<document>
+	<code file="limit_vector_length.js" />
+	<help file="limit_vector_length.rkh" />
+	<logic>
+		<external id="invar" default="x"/>
+		<external id="outvar" default="x"/>
+	</logic>
+	<dialog label="Limit Vector Length">
+		<row>
+			<spinbox type="integer" id="cutoff" initial="10" min="1" label="Limit"/>
+			<radio id="sorting" label="Sorting">
+				<option value="lowest" label="Keep smallest values"/>
+				<option value="highest" checked="true" label="Keep largest values"/>
+			</radio>
+		</row>
+		<frame id="include_others" label="Add remainder category" checkable="true" checked="true">
+			<radio id="others_statistic" label="Statistic">
+				<option value="sum" label="Sum" checked="true"/>
+				<option value="mean" label="Mean"/>
+				<option value="custom" label="Other:"/>
+			</radio>
+			<input id="custom_stat" label="Custom statistic (as function of x)" initial="sd (x)"/>
+
+			<input id="others_label" label="Remainder category label" initial="Other"/>
+		</frame>
+	</dialog>
+</document>

Modified: trunk/rkward/rkward/plugins/embedded.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/embedded.pluginmap	2011-09-12 09:17:38 UTC (rev 3756)
+++ trunk/rkward/rkward/plugins/embedded.pluginmap	2011-09-12 10:45:13 UTC (rev 3757)
@@ -10,6 +10,7 @@
 		<component type="standard" id="barplot_embed" file="plots/barplot_embed.xml" label="Barplot Options" />
 
 		<component type="standard" id="one_var_tabulation" file="data/one_var_tabulation.xml" label="Tabulate" />
+		<component type="standard" id="limit_vector_length" file="data/limit_vector_length.xml" label="Limit Vector Length" />
 
 		<component type="standard" id="x11grid" file="x11device/grid.xml" label="Draw Grid" />
 

Modified: trunk/rkward/rkward/plugins/plots/pareto.js
===================================================================
--- trunk/rkward/rkward/plugins/plots/pareto.js	2011-09-12 09:17:38 UTC (rev 3756)
+++ trunk/rkward/rkward/plugins/plots/pareto.js	2011-09-12 10:45:13 UTC (rev 3757)
@@ -14,13 +14,7 @@
 	}
 
 	if (getValue ("limit.checked")) {
-		echo ('max.categories <- ' + getValue ("cutoff") + '\n');
-		echo ('if (length (x) > max.categories) {\n');
-		echo ('\tx <- sort (x');
-		if (getValue ("sorting") != "lowest") echo (', decreasing=TRUE');
-		echo (')\n');
-		echo ('\tx <- c (x[1:max.categories], ' + quote (getValue ("others_label")) + '=sum (x[(max.categories+1):length(x)]))\n');
-		echo ('}\n');
+		echo (getValue ('limit_options.code.calculate'));
 	}
 }
 

Modified: trunk/rkward/rkward/plugins/plots/pareto.rkh
===================================================================
--- trunk/rkward/rkward/plugins/plots/pareto.rkh	2011-09-12 09:17:38 UTC (rev 3756)
+++ trunk/rkward/rkward/plugins/plots/pareto.rkh	2011-09-12 10:45:13 UTC (rev 3757)
@@ -14,10 +14,7 @@
 		<setting id="x">If your data is already contains defect counts or defect costs, or other data suitable for direct display in a pareto chart, specify it here. Otherwise, leave this empty, and check the "Tabulate" option, above.</setting>
 		<setting id="descriptives">Whether to print the frequency, cumulative frequency, percentage and cumulative percentage below the plot in the output window.</setting>
 		<caption id="tab_limit_options"/>
-		<setting id="limit">If there are very many categories in your data, it may make sense to limit the amount of categories that will be displayed. Check this, if you want to set a limit.</setting>
-		<setting id="cutoff">Maximum number of regular groups to display. One additonal group "others" will be displayed, if appropriate.</setting>
-		<setting id="sorting">Should the largest or the lowest values be kept? For a pareto chart, you will almost certainly want to keep the largest values.</setting>
-		<setting id="others_label">Allows to customize the label for the "others" category.</setting>
+		<setting id="limit">If there are very many categories in your data, it may make sense to limit the amount of categories that will be displayed. Check this, if you want to set a limit. See Refer to <link href="rkward://component/limit_vector_length"/> for details on the dependent options.</setting>
 		<caption id="tab_plot_options"/>
 		<setting id="plotoptions">Further options for the plot. Refer to <link href="rkward://component/plot_options"/> for details.</setting>
 	</settings>

Modified: trunk/rkward/rkward/plugins/plots/pareto.xml
===================================================================
--- trunk/rkward/rkward/plugins/plots/pareto.xml	2011-09-12 09:17:38 UTC (rev 3756)
+++ trunk/rkward/rkward/plugins/plots/pareto.xml	2011-09-12 10:45:13 UTC (rev 3757)
@@ -44,14 +44,7 @@
 			</tab>
 			<tab label="Limit" id="tab_limit_options">
 				<frame id="limit" label="Limit number of groups" checkable="true" checked="false">
-					<row>
-						<spinbox type="integer" id="cutoff" initial="10" min="1" label="Limit"/>
-						<radio id="sorting" label="Sorting">
-							<option value="lowest" label="Smallest values"/>
-							<option value="highest" checked="true" label="Largest values"/>
-						</radio>
-					</row>
-					<input id="others_label" label="Remainder category label" initial="Other" required="true"/>
+					<embed id="limit_options" component="rkward::limit_vector_length" as_button="false" label="Limit Categories"/>
 				</frame>
 				<stretch/>
 			</tab>

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