diff --git a/NEWS.md b/NEWS.md index 78a009a..d77befb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,9 @@ ## New classes and methods * Add `export()` to create a Zip archive of all results in CSV format. +## Internals +* Compute the position and draw only the labels in the plotting region. + # dimensio 0.9.0 ## New classes and methods * Add `pcoa()` to compute principal coordinates analysis. diff --git a/R/annotations.R b/R/annotations.R index 9f3e94d..91bda30 100644 --- a/R/annotations.R +++ b/R/annotations.R @@ -38,12 +38,13 @@ label <- function(x, y = NULL, labels = seq_along(x$x), labs <- compute_labels(x = x$x, y = x$y, labels = labels) ## Draw labels - switch( + fun <- switch( type, - text = graphics::text(labs, labels = labels, ...), - shadow = text_shadow(labs, labels = labels, ...), - box = text_box(labs, labels = labels, ...) + text = graphics::text, + shadow = text_shadow, + box = text_box ) + fun(labs, labels = labels, ...) invisible(labs) } diff --git a/R/biplot.R b/R/biplot.R index 2351c0e..3a5c015 100644 --- a/R/biplot.R +++ b/R/biplot.R @@ -212,26 +212,10 @@ viz_biplot <- function(coord_row, coord_col, ..., rows = TRUE, columns = TRUE, if (!is.null(labels)) { labels <- match.arg(labels, several.ok = TRUE) if (any(labels == "rows") | any(labels == "individuals")) { - label( - x = coord_row$x, - y = coord_row$y, - labels = coord_row$label, - type = "shadow", - cex = coord_row$cex, - col = coord_row$col, - xpd = TRUE - ) + viz_labels(coord_row, filter = NULL) } if (any(labels == "columns") | any(labels == "variables")) { - label( - x = coord_col$x, - y = coord_col$y, - labels = coord_col$label, - type = "shadow", - cex = coord_col$cex, - col = coord_col$col, - xpd = TRUE - ) + viz_labels(coord_col, filter = NULL) } } diff --git a/R/viz_coordinates.R b/R/viz_coordinates.R index 98f328b..a2da994 100644 --- a/R/viz_coordinates.R +++ b/R/viz_coordinates.R @@ -364,6 +364,8 @@ viz_points <- function(x, margin, axes, ..., #' It must be one of "`text`", "`shadow`" or "`box`". Any unambiguous substring #' can be given. #' @param ... Currently not used. +#' @details +#' Only labels in the plotting region (given by `par("usr")`) will be drawn. #' @author N. Frerebeau #' @keywords internal viz_labels <- function(x, filter = "contribution", n = 10, @@ -376,6 +378,14 @@ viz_labels <- function(x, filter = "contribution", n = 10, x <- x[k, , drop = FALSE] # Subset } + ## Filter + xlim <- graphics::par("usr")[c(1, 2)] + ylim <- graphics::par("usr")[c(3, 4)] + x_filter <- x$x >= min(xlim) & x$x <= max(xlim) + y_filter <- x$y >= min(ylim) & x$y <= max(ylim) + xy_filter <- which(x_filter & y_filter) + x <- x[xy_filter, , drop = FALSE] + label( x = x$x, y = x$y, diff --git a/man/viz_labels.Rd b/man/viz_labels.Rd index 283b2aa..ccb5612 100644 --- a/man/viz_labels.Rd +++ b/man/viz_labels.Rd @@ -25,6 +25,9 @@ can be given.} \description{ Non-Overlapping Text Labels } +\details{ +Only labels in the plotting region (given by \code{par("usr")}) will be drawn. +} \author{ N. Frerebeau }