Skip to content

Commit

Permalink
run repel algo in 0-1 scale
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Jan 24, 2024
1 parent 52885b5 commit bffdd56
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
23 changes: 13 additions & 10 deletions R/geom-label-repel.R
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ makeContent.labelrepeltree <- function(x) {
gw <- width_cm(grobWidth(r))
gh <- height_cm(grobHeight(r))
c(
"x1" = row$x - gw * row$hjust - box.padding + row$nudge_x * width,
"y1" = row$y - gh * row$vjust - box.padding + row$nudge_y * height,
"x2" = row$x + gw * (1 - row$hjust) + box.padding + row$nudge_x * width,
"y2" = row$y + gh * (1 - row$vjust) + box.padding + row$nudge_y * height
"x1" = (row$x - gw * row$hjust - box.padding) / width + row$nudge_x,
"y1" = (row$y - gh * row$vjust - box.padding) / height + row$nudge_y,
"x2" = (row$x + gw * (1 - row$hjust) + box.padding) / width + row$nudge_x,
"y2" = (row$y + gh * (1 - row$vjust) + box.padding) / height + row$nudge_y
)
})

Expand All @@ -284,13 +284,14 @@ makeContent.labelrepeltree <- function(x) {

# Repel overlapping bounding boxes away from each other.
repel <- with_seed_null(x$seed, repel_boxes2(
data_points = as.matrix(x$data[,c("x","y")]),
point_size = point.size,
point_padding_x = point.padding,
point_padding_y = point.padding,
data_points = cbind(x$data$x / width, x$data$y / height),
# data_points = as.matrix(x$data[,c("x","y")]),
point_size = point.size / width,
point_padding_x = point.padding / width,
point_padding_y = point.padding / width,
boxes = do.call(rbind, boxes),
xlim = c(0, width),
ylim = c(0, height),
xlim = range(x$limits$x),
ylim = range(x$limits$y),
hjust = x$data$hjust %||% 0.5,
vjust = x$data$vjust %||% 0.5,
force_push = x$force * 1e-6,
Expand All @@ -301,6 +302,8 @@ makeContent.labelrepeltree <- function(x) {
direction = x$direction,
verbose = x$verbose
))
repel$x <- repel$x * width
repel$y <- repel$y * height

if (any(repel$too_many_overlaps)) {
warn(
Expand Down
23 changes: 13 additions & 10 deletions R/geom-text-repel.R
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,10 @@ makeContent.textrepeltree <- function(x) {
y1 <- y_cm(grobY(tg, "south"))
y2 <- y_cm(grobY(tg, "north"))
c(
"x1" = x1 - box.padding + row$nudge_x * width,
"y1" = y1 - box.padding + row$nudge_y * height,
"x2" = x2 + box.padding + row$nudge_x * width,
"y2" = y2 + box.padding + row$nudge_y * height
"x1" = (x1 - box.padding) / width + row$nudge_x,
"y1" = (y1 - box.padding) / height + row$nudge_y,
"x2" = (x2 + box.padding) / width + row$nudge_x,
"y2" = (y2 + box.padding) / height + row$nudge_y
)
})

Expand All @@ -424,13 +424,14 @@ makeContent.textrepeltree <- function(x) {

# Repel overlapping bounding boxes away from each other.
repel <- with_seed_null(x$seed, repel_boxes2(
data_points = as.matrix(x$data[,c("x","y")]),
point_size = point.size,
point_padding_x = point.padding,
point_padding_y = point.padding,
data_points = cbind(x$data$x / width, x$data$y / height),
# data_points = as.matrix(x$data[,c("x","y")]),
point_size = point.size / width,
point_padding_x = point.padding / width,
point_padding_y = point.padding / width,
boxes = do.call(rbind, boxes),
xlim = c(0, width),
ylim = c(0, height),
xlim = range(x$limits$x),
ylim = range(x$limits$y),
hjust = x$data$hjust %||% 0.5,
vjust = x$data$vjust %||% 0.5,
force_push = x$force * 1e-6,
Expand All @@ -441,6 +442,8 @@ makeContent.textrepeltree <- function(x) {
direction = x$direction,
verbose = x$verbose
))
repel$x <- repel$x * width
repel$y <- repel$y * height

if (any(repel$too_many_overlaps)) {
warn(
Expand Down

0 comments on commit bffdd56

Please sign in to comment.