Skip to content

Commit

Permalink
remove bumpup methods for lineplots
Browse files Browse the repository at this point in the history
  • Loading branch information
tdhock committed Jun 28, 2021
1 parent 5e4ddc6 commit b543ce1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 42 deletions.
6 changes: 2 additions & 4 deletions R/densityplot.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
### Positioning Method for the top of a group of points.
top.points <-
gapply.fun(transform(d[which.max(d$y),],hjust=0.5,vjust=0))
top.points <- gapply.fun(transform(d[which.max(d$y),],hjust=0.5,vjust=0))

### Positioning Method for the bottom of a group of points.
bottom.points <-
gapply.fun(transform(d[which.min(d$y),],hjust=0.5,vjust=1))
bottom.points <- gapply.fun(transform(d[which.min(d$y),],hjust=0.5,vjust=1))

### Label the tops, but bump labels up to avoid collisions.
top.bumpup <- list("top.points","bumpup")
Expand Down
70 changes: 32 additions & 38 deletions R/lineplot.R
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
### Label points at the zero before the first nonzero y value.
lasso.labels <-
list(rot=60,
gapply.fun({ ## figure out where the path hits 0
d <- d[order(d$x),]
zero <- d$y[1]
i <- which(d$y!=zero)[1]
if(!is.na(i)){
just <- as.integer(d[i,"y"]>zero)
transform(d[i-1,],hjust=just,vjust=just)
}
}),
"calc.boxes",
## calculate how wide the tilted box is
dl.trans(hyp=h/sin(2*pi*rot/360)),
dl.trans(left=x-hyp/2,right=x+hyp/2),
## avoid collisions between tilted boxes
function(d,...){
solver <- qp.labels("x","left","right")
## apply the solver independently for top and bottom labels.
solution.list <- list()
for(vj in c(0,1)){
these <- d$vjust == vj
if(any(these)){
one.side <- d[these,]
solved <- solver(one.side)
solution.list[[paste(vj)]] <- solved
}
}
do.call(rbind, solution.list)
})
lasso.labels <- list(
rot=60,
gapply.fun({ ## figure out where the path hits 0
d <- d[order(d$x),]
zero <- d$y[1]
i <- which(d$y!=zero)[1]
if(!is.na(i)){
just <- as.integer(d[i,"y"]>zero)
transform(d[i-1,],hjust=just,vjust=just)
}
}),
"calc.boxes",
## calculate how wide the tilted box is
dl.trans(hyp=h/sin(2*pi*rot/360)),
dl.trans(left=x-hyp/2,right=x+hyp/2),
## avoid collisions between tilted boxes
function(d,...){
solver <- qp.labels("x","left","right")
## apply the solver independently for top and bottom labels.
solution.list <- list()
for(vj in c(0,1)){
these <- d$vjust == vj
if(any(these)){
one.side <- d[these,]
solved <- solver(one.side)
solution.list[[paste(vj)]] <- solved
}
}
do.call(rbind, solution.list)
})

### Positioning Method for the first of a group of points.
first.points <- label.endpoints(min,1)
Expand Down Expand Up @@ -57,12 +57,6 @@ maxvar.points <- function(d,...){
apply.method(FUN,d,...)
}

### Label last points, bumping labels up if they collide.
last.bumpup <- list("last.points","bumpup")

### Label first points, bumping labels up if they collide.
first.bumpup <- list("first.points","bumpup")

### Label last points from QP solver that ensures labels do not collide.
last.qp <- vertical.qp("last.points")

Expand Down Expand Up @@ -135,5 +129,5 @@ lines2 <- function

### Draw a box with the label inside, at the point furthest away from
### the plot border and any other curve.
angled.boxes <-
list("far.from.others.borders","calc.boxes","enlarge.box","draw.rects")
angled.boxes <- list(
"far.from.others.borders","calc.boxes","enlarge.box","draw.rects")

0 comments on commit b543ce1

Please sign in to comment.