On Wed, Nov 19, 2008 at 8:55 AM, Daniel Kornhauser
<dkor at northwestern.edu> wrote:
Hi:
(Tried to find a bug report about this issue, but was unable to find it, let
me know if this is a known issue)
I have been working on an interface to highlight xyplot panels on mouse
overs in JavaGD but I have stumbled with what seems to be a bug in
trellis.focus.
I am using R 2.8 with lattice 0.17-15
*** To replicate the bug:
1.- display an xyplot. For example, from the xyplot help page:
library(lattice)
require(stats)
EE <- equal.count(ethanol$E, number=9, overlap=1/4)
## Constructing panel functions on the fly; prepanel
xyplot(NOx ~ C | EE, data = ethanol,
prepanel = function(x, y) prepanel.loess(x, y, span = 1),
xlab = "Compression Ratio", ylab = "NOx (micrograms/J)",
panel = function(x, y) {
panel.grid(h=-1, v= 2)
panel.xyplot(x, y)
panel.loess(x,y, span=1)
},
aspect = "xy")
2.- resize to window be rectangular and have large margins in the left hand
and right hand side.
3.- run trellis.focus() and try to select the first or last panel, you
should observe that it does not select the right one.
sidenotes:
There are other problems with the focus in JavaGD but I just wanted to
include a simple self contained example in this mail.
If you make the window smaller, trellis.focus() works fine, you have to make
it bigger than the initial size.
*** To Fix the bug:
I tried to fix this bug in interraction.R but I was unsuccesful.
The problem should stem from the a bad calculation of the pads in the
follwoing lines :
leftPad <-
convertX(sum(glayout$page.layout$widths[1:(colRange[1]-1)]), "npc",
valueOnly = TRUE)
rightPad <-
convertX(sum(glayout$page.layout$widths[(colRange[2]+1):layCols]), "npc",
valueOnly = TRUE)
topPad <-
convertY(sum(glayout$page.layout$heights[1:(rowRange[1]-1)]), "npc",
valueOnly = TRUE)
botPad <-
convertY(sum(glayout$page.layout$heights[(rowRange[2]+1):layRows]), "npc",
valueOnly = TRUE)
I was succesful in tweaking the follwing lines adding arbitrary constants to
make it work for a particular instance of a xyplot with a particular size of
a window
clickXScaled <- (as.numeric(clickLoc$x) - leftPad + Danielconstant1)
/ (1 - leftPad - rightPad + Danielconstant1)
....
clickYScaled <- (as.numeric(clickLoc$y) - botPad + Danielconstant2)
/ (1 - botPad - topPad + Danielconstant3)
This is of course a useless fix, since you want the fix to work for any plot
with any window size, but I might be valuable information.
*** Questions:
- Is this a real bug ?
- Any suggestions for fixing it ?
- If it can't be fixed, is there a way around this bug ?
(For example, setting the margins to be zero and set a fixed size for the
xplot)
It appears that the conversions used in the current implementation
(contributed by Felix Andrews) don't work when aspect != "fill"
(probably leading back to the use of 'respect = TRUE' in grid.layout).