Skip to content

Commit

Permalink
Merge pull request #165 from heavywatal/refactor-daylight
Browse files Browse the repository at this point in the history
Refactor layoutDaylight and its related functions
  • Loading branch information
GuangchuangYu committed Feb 23, 2018
2 parents 114673e + 2fa2335 commit 1b77762
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 156 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Imports:
grid,
magrittr,
methods,
purrr,
rlang,
rvcheck,
scales,
tibble,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ importFrom(methods,is)
importFrom(methods,missingArg)
importFrom(methods,setGeneric)
importFrom(methods,setOldClass)
importFrom(rlang,.data)
importFrom(rvcheck,get_fun_from_pkg)
importFrom(scales,alpha)
importFrom(tibble,data_frame)
Expand Down
31 changes: 7 additions & 24 deletions R/MRCA.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,16 @@ getMRCA.df_internal <- function(data, node1, node2) {
node1 <- which(node1 == data$label | node1 == data[, "node"])
node2 <- which(node2 == data$label | node2 == data[, "node"])

anc1 <- get.ancestor.df(data, node1)
anc2 <- get.ancestor.df(data, node2)
anc1 <- getAncestor.df(data, node1)
anc2 <- getAncestor.df(data, node2)

if(is.null(anc1)){
print("Warning getMRCA.df_internal(): node1 is root")
} else if(is.null(anc2)){
print("Warning getMRCA.df_internal(): node2 is root")
if (length(anc1) == 0L) {
warning("getMRCA.df_internal(): node1 is root")
}
if (length(anc2) == 0L) {
warning("getMRCA.df_internal(): node2 is root")
}

# Return common ancestors.
intersect(c(node1, anc1), c(node2, anc2))[1]
}


get.ancestor.df <- function(df, node) {
pp <- getParent.df(df, node)
pp <- pp[pp != 0]
if (length(pp) == 0) {
#stop("input node is root...")
cat("WARNING: input node ",node," is root.")
return(NULL) # root has no ancestor
}
i <- 1
while(i <= length(pp)) {
pp <- c(pp, getParent.df(df, pp[i]))
pp <- pp[pp!=0]
i <- i+1
}
return(pp)
}
Loading

0 comments on commit 1b77762

Please sign in to comment.