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 JGR R 2.8 with lattice 0.17-15
Note: It's important to you use JGR to use the Java Graphics Device.

*** 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 to have large margins on all sides.
3.- run trellis.focus() and try to select the first or last panel, you
should observe that it does not select the right one.

sidenote:
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 unsuccessful.

The problem should stem from the a bad calculation of the margins.
Notice that if you set the margins to 0 size the bug above does not appear.
You can test this with:
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)
       },
       par.settings=list(
        layout.widths=list(left.padding=0, right.padding=0),
        layout.heights=list(top.padding=0, bottom.padding=0))
    )

I traced the a bad calculation of the pads in the following 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 ?
- The only way around I have found around this bug is to make the margins 0
is there any other way.

IMPORTANT NOTE:
I have found other problems with the focus in JavaGD but did not mention
them since I just wanted to include a simple self contained example in this
mail.

          Thanks.

        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to