Hi

Two points:

1. grid.remove() redraws the entire scene (and because the drawing is slow you see a flicker)

2.  Doing this ...

dev.hold()
grid.gremove("lastShape")
dev.flush()

... may reduce flicker for you.

Paul

On 07/25/13 06:10, Daniel Guetta wrote:
I'm designing an interactive plot using the `grid` package in R. As
part of the interactivity, I repeatedly delete and re-create various
parts of the plot. However, the total number of grid elements (as
obtained using the `grid.ls()` command) stays constant; everything I
create was previously removed.

The problem is as follows - once I've gone through a few cycles of
creation and deletion, every deletion I make to the graphic, however
small, causes all the interactive parts of the plot (those I've been
repeatedly deleting and creating) to flicker.

Here's the simplest example I could come up with - first run this code
to set up the `grid` graphic, and repeatedly delete and re-create
certain elements

###############################

     library(grid)

     pushViewport(viewport())

     for (x in seq(0, 1, length=5))
     {
     for (y in seq(0, 1, length=5))
     {
     pushViewport(viewport(x = x, y = y, width=1/5, height=1/5,
name=paste("foo", x, y, sep="")))
     grid.rect()

     pushViewport(viewport(x = 0, 0, width=1/4, height=1/4, name="bar1"))
     grid.circle(name="testing")
     grid.text("123")
     upViewport()

     pushViewport(viewport(x = 1, 0, width=1/4, height=1/4, name="bar2"))
     grid.circle(name="testing")
     grid.text("123")
     upViewport()

     pushViewport(viewport(x = 0, 1, width=1/4, height=1/4, name="bar3"))
     grid.circle(name="testing")
     grid.text("123")
     upViewport()

     pushViewport(viewport(x = 1, 1, width=1/4, height=1/4, name="bar4"))
     grid.circle(name="testing")
     grid.text("123")
     upViewport()

     upViewport()
     }
     }

     for (i in 1:10)
     {

     grid.gremove("testing")

     for (x in seq(0, 1, length=5))
     {
     for (y in seq(0, 1, length=5))
     {
     downViewport(paste("foo", x, y, sep=""))

     downViewport("bar1"); grid.circle(name="testing"); upViewport()
     downViewport("bar2"); grid.circle(name="testing"); upViewport()
     downViewport("bar3"); grid.circle(name="testing"); upViewport()
     downViewport("bar4"); grid.circle(name="testing"); upViewport()

     upViewport()
     }
     }

     }

###############################

Once this is all set up, create a new arbitrary square on the device

###############################
     grid.rect(height=0.5, width=0.5, gp=gpar(lty = 2), name = "lastShape")
###############################

Now try to delete it

###############################
     grid.gremove("lastShape")
###############################

Notice that when you run this last deletion command, all the small
circles that I've been creating and deleting flicker slightly, even
though I haven't touched them. This makes the entire graphic very
distracting.

The thing is, if I don't delete and re-create the original graphics so
many times, this doesn't happen! So I figure I must be leaving a trail
somewhere because of inefficient deleting.

Any ideas how to prevent that?

Thanks a million!

------------------------------------------------------

Daniel Guetta
PhD Candidate, Columbia University

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to