Skip to content

Commit

Permalink
Draw only labels in the plotting region
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Oct 21, 2024
1 parent b9bf18a commit 1cd62d7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions R/annotations.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#' @return
#' `label()` is called it for its side-effects: it results in a graphic
#' being displayed.
#' @details
#' Only labels in the plotting region (given by `par("usr")`) will be drawn.
#' @seealso [graphics::text()]
#' @note
#' This function is modeled after [car::pointLabel()] (originally from the
Expand All @@ -34,6 +36,17 @@ label <- function(x, y = NULL, labels = seq_along(x$x),
labels <- grDevices::as.graphicsAnnot(labels)
if (length(labels) < length(x$x)) labels <- rep(labels, length(x$x))

## 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 <- x$x[xy_filter]
x$y <- x$y[xy_filter]
labels <- labels[xy_filter]

## Compute label positions
labs <- compute_labels(x = x$x, y = x$y, labels = labels)

Expand Down
3 changes: 3 additions & 0 deletions man/label.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1cd62d7

Please sign in to comment.