]> git.donarmstrong.com Git - ape.git/blobdiff - R/identify.phylo.R
new trex() + kronoviz() and bug fixing in identify.phylo()
[ape.git] / R / identify.phylo.R
index 130a8788c658b35471af23895981068e9d622e58..64ecc38734dd2be60e6dd72edf87eccbe45be497 100644 (file)
@@ -1,19 +1,31 @@
-## identify.phylo.R (2008-02-28)
+## identify.phylo.R (2011-03-23)
 
 ##   Graphical Identification of Nodes and Tips
 
-## Copyright 2008 Emmanuel Paradis
+## Copyright 2008-2011 Emmanuel Paradis
 
 ## This file is part of the R-package `ape'.
 ## See the file ../COPYING for licensing issues.
 
 identify.phylo <- function(x, nodes = TRUE, tips = FALSE,
-                           labels = FALSE, ...)
+                           labels = FALSE, quiet = FALSE, ...)
 {
-    cat("Click close to a node of the tree...\n")
+    if (!quiet)
+        cat("Click close to a node of the tree...\n")
     xy <- locator(1)
+    if (is.null(xy)) return(NULL)
     lastPP <- get("last_plot.phylo", envir = .PlotPhyloEnv)
-    d <- sqrt((xy$x - lastPP$xx)^2 + (xy$y - lastPP$yy)^2)
+    ## rescale the coordinates (especially if the x- and
+    ## y-scales are very different):
+    pin <- par("pin")
+    rescaleX <- pin[1]/max(lastPP$xx)
+    xx <- rescaleX * lastPP$xx
+    rescaleY <- pin[2]/max(lastPP$yy)
+    yy <- rescaleY * lastPP$yy
+    xy$x <- rescaleX * xy$x
+    xy$y <- rescaleY * xy$y
+    ## end of rescaling
+    d <- (xy$x - xx)^2 + (xy$y - yy)^2 # no need to sqrt()
     NODE <- which.min(d)
     res <- list()
     if (NODE <= lastPP$Ntip) {