[rkward-cvs] SF.net SVN: rkward:[2937] trunk/rkward/rkward/rbackend/rpackages/rkward/R/ public_graphics.R
kapatp at users.sourceforge.net
kapatp at users.sourceforge.net
Mon Jul 5 08:54:05 UTC 2010
Revision: 2937
http://rkward.svn.sourceforge.net/rkward/?rev=2937&view=rev
Author: kapatp
Date: 2010-07-05 08:54:05 +0000 (Mon, 05 Jul 2010)
Log Message:
-----------
finally enforcing the history limits; needs a lot of testing...
Modified Paths:
--------------
trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R 2010-07-05 08:49:36 UTC (rev 2936)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R 2010-07-05 08:54:05 UTC (rev 2937)
@@ -59,7 +59,7 @@
"rk.record.plot" <- function ()
{
# TODO:
- # - add a length and size limit to recorded () list
+ # - check when decreasing the max history length below the current recorded length
# - add one or more tests to rkward_application_tests.R
# - .... ?
@@ -99,6 +99,46 @@
histPositions [[deviceId]] <<- newPlotExists [[deviceId]] <<- NULL
}
}
+ push.pop.and.record <- function (which.pop = NULL, which.push = NULL, deviceId = NULL, newplot = FALSE, oldplot = !newplot)
+ {
+ if (class (try (unsavedPlot <- recordPlot(), silent=TRUE)) != 'try-error') {
+ s <- object.size (unsavedPlot) # in bytes
+
+
+ if (s <= getOption ('rk.graphics.hist.max.plotsize') * 1024) {
+ if (oldplot) {
+ recorded [[which.push]] <<- unsavedPlot
+ return (TRUE)
+ }
+
+ len.r <- length(recorded)
+ ml <- getOption ('rk.graphics.hist.max.length')
+
+ if (len.r < ml) {
+ n <- len.r + 1
+ } else if (len.r == ml) {
+ warning ('Max length reached, popping out the first plot.')
+ remove (deviceId = NULL, pos = which.pop)
+ n <- len.r
+ } else {
+ warning ('Current history length > max length: plot not added to history!')
+ return (FALSE)
+ }
+
+ if (!is.null (deviceId)) histPositions [[deviceId]] <<- n
+ .rk.graph.history.gui ()
+ recorded [[n]] <<- unsavedPlot
+
+ return (TRUE)
+ } else {
+ warning ('Oversized plot: not added to history!') # don't use stop (...)
+ return (FALSE)
+ }
+ } else {
+ warning ('recordPlot () bailed out!') # don't use stop (...)
+ return (FALSE)
+ }
+ }
record <- function(deviceId = dev.cur (), newplotflag = TRUE, force = FALSE)
{
deviceId <- as.character (deviceId)
@@ -112,15 +152,12 @@
if (isManaged) {
# device is managed, that is, non-preview-interactive
+ succeded <- TRUE
if (newPlotExists [[deviceId]]) {
# there is a new plot on this device, so save it,
# immaterial of whether force == TRUE or FALSE
- if (class (try (unsavedPlot <- recordPlot(), silent=TRUE)) != 'try-error') {
- histPositions [[deviceId]] <<- n <- length(recorded) + 1
- recorded [[n]] <<- unsavedPlot
- .rk.graph.history.gui ()
- }
+ succeded <- push.pop.and.record (which.pop = 1, deviceId = deviceId, newplot = TRUE)
} else if (force) {
# no new plot on this managed device but force == TRUE
# in other words, called from a non-preview interactive device by clicking "Add to history" icon
@@ -134,12 +171,11 @@
newPlotExists [[deviceId]] <<- TRUE
record (deviceId, newplotflag = FALSE, force = FALSE)
} else {
- if (class (try (unsavedPlot <- recordPlot(), silent=TRUE)) != 'try-error') {
- recorded [[n]] <<- unsavedPlot
- }
+ succeded <- push.pop.and.record (which.push = n, oldplot = TRUE)
}
}
- newPlotExists [[deviceId]] <<- newplotflag
+ if (succeded || !force)
+ newPlotExists [[deviceId]] <<- newplotflag
} else {
# device is not managed but due to (*) force == TRUE
# in other words, called from a preview device by clicking "Add to history" icon
@@ -149,11 +185,7 @@
# save a particular "preview" plot to history (useful since preview plots are _not_
# automatically added to history)
- n <- length (recorded) + 1
- if (class (try (unsavedPlot <- recordPlot(), silent=TRUE)) != 'try-error') {
- recorded [[n]] <<- unsavedPlot
- .rk.graph.history.gui ()
- }
+ push.pop.and.record (which.pop = 1, deviceId = NULL, newplot = TRUE)
}
dev.set (cur.deviceId)
@@ -219,7 +251,8 @@
pop.and.update (n = pos)
}
} else if (all(pos > 0) && all (pos <= history_length)) {
- # not called from any managed devices, so pop and update
+ # call from: push.pop.and.record () (see above) not from any device
+
pop.and.update (n = pos)
} else
stop (paste ('Invalid position(s)'))
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