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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Feb 11 21:38:00 UTC 2010


Revision: 2742
          http://rkward.svn.sourceforge.net/rkward/?rev=2742&view=rev
Author:   tfry
Date:     2010-02-11 21:38:00 +0000 (Thu, 11 Feb 2010)

Log Message:
-----------
Convert a few plots to JS

Modified Paths:
--------------
    trunk/rkward/rkward/plugins/plots/barplot.js
    trunk/rkward/rkward/plugins/plots/barplot.xml
    trunk/rkward/rkward/plugins/plots/barplot_embed.js
    trunk/rkward/rkward/plugins/plots/barplot_embed.xml
    trunk/rkward/rkward/plugins/plots/color_chooser.js
    trunk/rkward/rkward/plugins/plots/cor_graph.js
    trunk/rkward/rkward/plugins/plots/cor_graph.xml
    trunk/rkward/rkward/plugins/plots/density_plot.js
    trunk/rkward/rkward/plugins/plots/density_plot.xml

Removed Paths:
-------------
    trunk/rkward/rkward/plugins/plots/barplot.php
    trunk/rkward/rkward/plugins/plots/barplot_embed.php
    trunk/rkward/rkward/plugins/plots/color_chooser.php
    trunk/rkward/rkward/plugins/plots/density_plot.php

Modified: trunk/rkward/rkward/plugins/plots/barplot.js
===================================================================
--- trunk/rkward/rkward/plugins/plots/barplot.js	2010-02-11 21:21:19 UTC (rev 2741)
+++ trunk/rkward/rkward/plugins/plots/barplot.js	2010-02-11 21:38:00 UTC (rev 2742)
@@ -1,46 +1,28 @@
-/* ------- This file generated by php2js from PHP code. --------
-Please check this file by hand, and remove this notice, afterwards.
-Messages:
-
----------------------------- */
-
-// globals
-var undefined;
-
-
-
 function printout () {
 	doPrintout (true);
 }
 
 function preview () {
-	preprocess ();
-	calculate ();
 	doPrintout (false);
 }
 
 function doPrintout (full) {
-	var var = "";
-	var names_mode = "";
-	var tabulate = "";
-	var tabulate_header = "";
-	var barplot_header = "";
-	var barplot_main = "";
-	var = getValue ("x");
-	names_mode = getValue ("names_mode");
-	tabulate = getValue ("tabulate");
+	var varname = getValue ("x");
+	var names_mode = getValue ("names_mode");
+	var tabulate = getValue ("tabulate");
 
+	var tabulate_header = "";
 	if (tabulate) {
 		tabulate_header = '"Tabulate", "Yes"';
 	} else {
 		tabulate_header = '"Tabulate", "No"';
 	}
 
-	barplot_header = getValue ("barplot_embed.code.preprocess");
-	barplot_main = getValue ("barplot_embed.code.printout");
+	var barplot_header = getValue ("barplot_embed.code.preprocess");
+	var barplot_main = getValue ("barplot_embed.code.printout");
 
 
-	echo ('x <- ' + var + "\n");
+	echo ('x <- ' + varname + "\n");
 	if (tabulate) {
 		echo ('x <- table(x, exclude=NULL)\n');
 	} else {
@@ -56,16 +38,15 @@
 	}
 
 	if (full) {
-		echo ('rk.header ("Barplot", parameters=list ("Variable", rk.get.description (' + var + '), ' + tabulate_header + barplot_header + '))\n');
+		echo ('rk.header ("Barplot", parameters=list ("Variable", rk.get.description (' + varname + '), ' + tabulate_header + barplot_header + '))\n');
 		echo ('\n');
 		echo ('rk.graph.on ()\n');
 	}
 
 	echo ('try ({\n');
 	printIndented ("\t", barplot_main);
-
-
 	echo ('})\n');
+
 	if (full) {
 		echo ('rk.graph.off ()\n');
 	}

Deleted: trunk/rkward/rkward/plugins/plots/barplot.php
===================================================================
--- trunk/rkward/rkward/plugins/plots/barplot.php	2010-02-11 21:21:19 UTC (rev 2741)
+++ trunk/rkward/rkward/plugins/plots/barplot.php	2010-02-11 21:38:00 UTC (rev 2742)
@@ -1,65 +0,0 @@
-<?
-function preprocess () {
-}
-
-function calculate () {
-}
-
-function printout () {
-	doPrintout (true);
-}
-	
-function preview () {
-	preprocess ();
-	calculate ();
-	doPrintout (false);
-}
-	
-function doPrintout ($final) {
-	$var = getRK_val ("x");
-	$names_mode = getRK_val ("names_mode");
-	$tabulate = getRK_val ("tabulate");
-
-	if ($tabulate) {
-		$tabulate_header = '"Tabulate", "Yes"';
-	} else {
-		$tabulate_header = '"Tabulate", "No"';
-	}
-
-	$barplot_header = getRK_val ("barplot_embed.code.preprocess");
-	$barplot_main = getRK_val ("barplot_embed.code.printout");
-
-?>
-x <- <? echo ($var . "\n"); ?>
-<?
-	if ($tabulate) { ?>
-x <- table(x, exclude=NULL)
-<?      } else { ?>
-# barplot is a bit picky about attributes, so we need to convert to vector explicitely
-if(!is.matrix(x)) x <- as.vector(x)
-if(!is.matrix(x) && is.data.frame(x)) x <- data.matrix(x)
-<?	}
-
-	if ($names_mode == "rexp") {
-		echo ("names(x) <- " . getRK_val ("names_exp") . "\n");
-	} else if ($names_mode == "custom") {
-		echo ("names(x) <- c (\"" . str_replace (";", "\", \"", trim (getRK_val ("names_custom"))) . "\")\n");
-	}
-
-	if ($final) { ?>
-rk.header ("Barplot", parameters=list ("Variable", rk.get.description (<? echo ($var); ?>), <? echo ($tabulate_header . $barplot_header); ?>))
-
-rk.graph.on ()
-<?	}
-?>
-try ({
-<?
-	printIndented ("\t", $barplot_main);
-	
-?>
-})
-<?	if ($final) { ?>
-rk.graph.off ()
-<? }
-}
-?>

Modified: trunk/rkward/rkward/plugins/plots/barplot.xml
===================================================================
--- trunk/rkward/rkward/plugins/plots/barplot.xml	2010-02-11 21:21:19 UTC (rev 2741)
+++ trunk/rkward/rkward/plugins/plots/barplot.xml	2010-02-11 21:38:00 UTC (rev 2742)
@@ -1,6 +1,6 @@
 	<!DOCTYPE rkplugin>
 	<document>
-		<code file="barplot.php" />
+		<code file="barplot.js" />
 		<help file="barplot.rkh" />
 		<logic>
 			<set id="barplot_embed.xvar" to="x"/>

Modified: trunk/rkward/rkward/plugins/plots/barplot_embed.js
===================================================================
--- trunk/rkward/rkward/plugins/plots/barplot_embed.js	2010-02-11 21:21:19 UTC (rev 2741)
+++ trunk/rkward/rkward/plugins/plots/barplot_embed.js	2010-02-11 21:38:00 UTC (rev 2742)
@@ -1,16 +1,5 @@
-/* ------- This file generated by php2js from PHP code. --------
-Please check this file by hand, and remove this notice, afterwards.
-Messages:
-Note: Control statement without braces. This is bad style.
-Note: Control statement without braces. This is bad style.
-Note: Control statement without braces. This is bad style.
-Note: Control statement without braces. This is bad style.
-
----------------------------- */
-
 // globals
 var options;
-var undefined;
 
 function preprocess () {
 	var legend_label = "";
@@ -41,23 +30,20 @@
 
 function printout () {
 	var col_option = "";
-	var main_call = "";
-	var plot_pre = "";
-	var plot_adds = "";
 	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;
+	var 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 += getValue ('plotoptions.code.printout');
 	main_call += ")\n";
 
-	plot_pre = getValue ('plotoptions.code.preprocess');
-	plot_adds = getValue ('plotoptions.code.calculate');
+	var plot_pre = getValue ('plotoptions.code.preprocess');
+	var plot_adds = getValue ('plotoptions.code.calculate');
 
 	// now print everything as needed
 	echo (plot_pre);

Deleted: trunk/rkward/rkward/plugins/plots/barplot_embed.php
===================================================================
--- trunk/rkward/rkward/plugins/plots/barplot_embed.php	2010-02-11 21:21:19 UTC (rev 2741)
+++ trunk/rkward/rkward/plugins/plots/barplot_embed.php	2010-02-11 21:38:00 UTC (rev 2742)
@@ -1,70 +0,0 @@
-<?
-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 .= getRK_val ('plotoptions.code.printout');
-	$main_call .= ")\n";
-
-	$plot_pre = getRK_val ('plotoptions.code.preprocess');
-	$plot_adds = getRK_val ('plotoptions.code.calculate');
-
-	// now print everything as needed
-	echo ($plot_pre);
-
-	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");
-	}
-
-	echo ($plot_adds);
-}
-?>

Modified: trunk/rkward/rkward/plugins/plots/barplot_embed.xml
===================================================================
--- trunk/rkward/rkward/plugins/plots/barplot_embed.xml	2010-02-11 21:21:19 UTC (rev 2741)
+++ trunk/rkward/rkward/plugins/plots/barplot_embed.xml	2010-02-11 21:38:00 UTC (rev 2742)
@@ -1,6 +1,6 @@
 <!DOCTYPE rkplugin>
 <document>
-	<code file="barplot_embed.php" />
+	<code file="barplot_embed.js" />
 	<help file="barplot_embed.rkh" />
 	<logic>
 		<external id="xvar" default=""/>

Modified: trunk/rkward/rkward/plugins/plots/color_chooser.js
===================================================================
--- trunk/rkward/rkward/plugins/plots/color_chooser.js	2010-02-11 21:21:19 UTC (rev 2741)
+++ trunk/rkward/rkward/plugins/plots/color_chooser.js	2010-02-11 21:38:00 UTC (rev 2742)
@@ -1,23 +1,9 @@
-/* ------- This file generated by php2js from PHP code. --------
-Please check this file by hand, and remove this notice, afterwards.
-Messages:
-Warning: multiline comments are not handled! Check by hand!
-Note: Control statement without braces. This is bad style.
-Note: Control statement without braces. This is bad style.
-
----------------------------- */
-
-// globals
-var undefined;
-
-/* NOTE: This file is currently not used by the color_chooser plugin+ It remains here, as it illustrates the functionality better than the hack that is actually in effect+
-
+/* NOTE: This file is currently not used by the color_chooser plugin.
+ Pehaps we can start using it again, now that a full PHP backend no longer needs to be started for this simple plugin. TODO: test it.
 */
 
-
 function printout () {
-	var col = "";
-	col = getValue ("color");
+	var col = getValue ("color");
 	if (empty (col)) col = getValue ("default_color");
 	if (!empty (col)) col = getValue ("argument") + "\"" + col + "\"";
 

Deleted: trunk/rkward/rkward/plugins/plots/color_chooser.php
===================================================================
--- trunk/rkward/rkward/plugins/plots/color_chooser.php	2010-02-11 21:21:19 UTC (rev 2741)
+++ trunk/rkward/rkward/plugins/plots/color_chooser.php	2010-02-11 21:38:00 UTC (rev 2742)
@@ -1,18 +0,0 @@
-<?
-/* NOTE: This file is currently not used by the color_chooser plugin. It remains here, as it illustrates the functionality better than the hack that is actually in effect.
-
-*/
-function preprocess () {
-}
-
-function calculate () {
-}
-
-function printout () {
-	$col = getRK_val ("color");
-	if (empty ($col)) $col = getRK_val ("default_color");
-	if (!empty ($col)) $col = getRK_val ("argument") . "\"" . $col . "\"";
-
-	echo ($col);
-}
-?>
\ No newline at end of file

Modified: trunk/rkward/rkward/plugins/plots/cor_graph.js
===================================================================
--- trunk/rkward/rkward/plugins/plots/cor_graph.js	2010-02-11 21:21:19 UTC (rev 2741)
+++ trunk/rkward/rkward/plugins/plots/cor_graph.js	2010-02-11 21:38:00 UTC (rev 2742)
@@ -1,12 +1,3 @@
-/* ------- This file generated by php2js from PHP code. --------
-Please check this file by hand, and remove this notice, afterwards.
-Messages:
-
----------------------------- */
-
-// globals
-var undefined;
-
 function preprocess () {
 	echo ('cor.graph <- function(x) {\n');
 	echo ('	panel.cor <- function(x, y, digits=' + getValue ("digits") + ', cex.cor, use="' + getValue ("use") + '", method="' + getValue ("method") + '", scale=' + getValue ("scale") + ') {\n');
@@ -30,20 +21,16 @@
 	echo ('}\n');
 }
 
-
 function printout () {
 	doPrintout (true);
 }
 
 function preview () {
-	preprocess ();
-	calculate ();
 	doPrintout (false);
 }
 
 function doPrintout (full) {
-	var vars = "";
-	vars = str_replace ("\n", ",", trim (getValue ("x"))) ;
+	var vars = trim (getValue ("x")).replace (/\n/g, ",");
 
 	echo ('data <- data.frame (' + vars + ')\n');
 	echo ('\n');

Modified: trunk/rkward/rkward/plugins/plots/cor_graph.xml
===================================================================
--- trunk/rkward/rkward/plugins/plots/cor_graph.xml	2010-02-11 21:21:19 UTC (rev 2741)
+++ trunk/rkward/rkward/plugins/plots/cor_graph.xml	2010-02-11 21:38:00 UTC (rev 2742)
@@ -1,6 +1,6 @@
 <!DOCTYPE rkplugin>
 <document>
-	<code file="cor_graph.php" />
+	<code file="cor_graph.js" />
 	<help file="cor_graph.rkh" />
 
 	<dialog label="Correlation Matrix Plot" >		

Modified: trunk/rkward/rkward/plugins/plots/density_plot.js
===================================================================
--- trunk/rkward/rkward/plugins/plots/density_plot.js	2010-02-11 21:21:19 UTC (rev 2741)
+++ trunk/rkward/rkward/plugins/plots/density_plot.js	2010-02-11 21:38:00 UTC (rev 2742)
@@ -1,14 +1,4 @@
-/* ------- This file generated by php2js from PHP code. --------
-Please check this file by hand, and remove this notice, afterwards.
-Messages:
-Note: Control statement without braces. This is bad style.
-Note: Control statement without braces. This is bad style.
-
----------------------------- */
-
-// globals
 var dodensity_plot;
-var undefined;
 
 function preprocess () {
 	dodensity_plot = (getValue ("plot_type") == "density_plot");
@@ -21,7 +11,6 @@
 
 function preview () {
 	preprocess ();
-	calculate ();
 	doPrintout (false);
 }
 
@@ -30,40 +19,34 @@
 }
 
 function doPrintout (full) {
-	var adjust = "";
-	var x = "";
-	var resolution = "";
-	var narm = "";
-	var kern = "";
+	var adjust = getValue ("adjust");
+	var x = getValue ("x");
+	var resolution = getValue ("n");
+	var narm = getValue ("narm");
+	var kern = getValue ("kern");
+	
 	var bw = "";
-	var dorug = "";
-	var density_call = "";
-	var title = "";
-	adjust = getValue ("adjust");
-	x = getValue ("x");
-	resolution = getValue ("n");
-	narm = getValue ("narm");
-	kern = getValue ("kern");
 	if (kern == "gaussian") {
 		bw = getValue ("bw");
 	}
-	dorug = getValue ("rug");
+	var dorug = getValue ("rug");
 
-	density_call = "density(" + x;
-	if (!empty (bw)) density_call += ", bw=\"" + bw + "\"";
+	var density_call = "density(" + x;
+	if (bw != "") density_call += ", bw=\"" + bw + "\"";
 	density_call += ", adjust=" + adjust + ", kern=\"" + kern + "\", n=" + resolution + ", " + narm + ")";
 
+	var title = "";
 	if (dodensity_plot) title = "Density Plot";
 	else title = "Highest density regions";
 
 	if (full) {
 		echo ('rk.header ("' + title + '", list ("Variable", rk.get.description (' + x + ')');
-		if (!empty (bw)) {
+		if (bw != "") {
 			echo (', "Band Width", "');
 			echo (bw);
 			echo ('"');
 		}
-		echo (', "Adjust", ' + adjust) echo (', "Remove Missing Values", ' + narm) echo (', "Length", length (' + x + '), "Resolution", ' + resolution + ', "Smoothing Kernel", "' + kern + '"))\n');
+		echo (', "Adjust", ' + adjust + ', "Remove Missing Values", ' + narm + ', "Length", length (' + x + '), "Resolution", ' + resolution + ', "Smoothing Kernel", "' + kern + '"))\n');
 		echo ('\n');
 		echo ('rk.graph.on ()\n');
 	}

Deleted: trunk/rkward/rkward/plugins/plots/density_plot.php
===================================================================
--- trunk/rkward/rkward/plugins/plots/density_plot.php	2010-02-11 21:21:19 UTC (rev 2741)
+++ trunk/rkward/rkward/plugins/plots/density_plot.php	2010-02-11 21:38:00 UTC (rev 2742)
@@ -1,63 +0,0 @@
-<?
-function preprocess () {
-	global $dodensity_plot;
-	$dodensity_plot = (getRK_val ("plot_type") == "density_plot");
-
-	if (!$dodensity_plot) { ?>
-require(hdrcde)
-<?	}
-}
-
-function calculate () {
-}
-
-function preview () {
-	preprocess ();
-	calculate ();
-	doPrintout (false);
-}
-
-function printout () {
-	doPrintout (true);
-}
-
-function doPrintout ($final) {
-	global $dodensity_plot;
-	$adjust = getRK_val ("adjust");
-	$x = getRK_val ("x");
-	$resolution = getRK_val ("n");
-	$narm = getRK_val ("narm");
-	$kern = getRK_val ("kern");
-	if ($kern == "gaussian") {
-		$bw = getRK_val ("bw");
-	}
-	$dorug = getRK_val ("rug");
-
-	$density_call = "density(" . $x;
-	if (!empty ($bw)) $density_call .= ", bw=\"" . $bw . "\"";
-	$density_call .= ", adjust=" . $adjust . ", kern=\"" . $kern . "\", n=" . $resolution . ", " . $narm . ")";
-
-	if ($dodensity_plot) $title = "Density Plot";
-	else $title = "Highest density regions";
-
-	if ($final) { ?>
-rk.header ("<? echo ($title); ?>", list ("Variable", rk.get.description (<? echo ($x); ?>)<? if (!empty ($bw)) { ?>, "Band Width", "<? echo ($bw); ?>"<? } ?>, "Adjust", <? echo ($adjust) ?>, "Remove Missing Values", <? echo ($narm) ?>, "Length", length (<? echo ($x); ?>), "Resolution", <? echo ($resolution); ?>, "Smoothing Kernel", "<? echo ($kern); ?>"))
-
-rk.graph.on ()
-<?	}
-		?>
-try ({
-<?	if ($dodensity_plot) { ?>
-	plot(<? echo ($density_call); getRK ("plotoptions.code.printout"); ?>)
-<?	} else { ?>
-	hdr.den(den=<? echo ($density_call); getRK ("plotoptions.code.printout"); ?>)
-<?	}
-	if ($dorug) { ?>
-	rug(<? echo ($x); ?>, <? getRK ("rug_ticksize"); ?>, <? getRK ("rug_lwd"); ?>, <? getRK ("rug_side"); ?><? getRK ("rug_col.code.printout"); ?>)
-<?	} ?>
-})
-<?	if ($final) { ?>
-rk.graph.off ()
-<?	}
-}
-?>

Modified: trunk/rkward/rkward/plugins/plots/density_plot.xml
===================================================================
--- trunk/rkward/rkward/plugins/plots/density_plot.xml	2010-02-11 21:21:19 UTC (rev 2741)
+++ trunk/rkward/rkward/plugins/plots/density_plot.xml	2010-02-11 21:38:00 UTC (rev 2742)
@@ -1,6 +1,6 @@
 <!DOCTYPE rkplugin>
 <document>
-	<code file="density_plot.php" />
+	<code file="density_plot.js" />
 	<help file="density_plot.rkh" />
 	
 	<logic>


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