Skip to content

Commit e7de35e

Browse files
committed
simplify PositionNudge$compute_layer()
1 parent f765685 commit e7de35e

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

R/position-nudge.R

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,8 @@ PositionNudge <- ggproto("PositionNudge", Position,
4646
},
4747

4848
compute_layer = function(self, data, params, layout) {
49-
# transform only the dimensions for which non-zero nudging is requested
50-
if (any(params$x != 0)) {
51-
if (any(params$y != 0)) {
52-
transform_position(data, function(x) x + params$x, function(y) y + params$y)
53-
} else {
54-
transform_position(data, function(x) x + params$x, NULL)
55-
}
56-
} else if (any(params$y != 0)) {
57-
transform_position(data, NULL, function(y) y + params$y)
58-
} else {
59-
data # if both x and y are 0 we don't need to transform
60-
}
49+
trans_x <- if (any(params$x != 0)) function(x) x + params$x
50+
trans_y <- if (any(params$y != 0)) function(y) y + params$y
51+
transform_position(data, trans_x, trans_y)
6152
}
6253
)

0 commit comments

Comments
 (0)