Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potpourri of graph viz and other improvements #143

Merged
merged 11 commits into from
Dec 12, 2018
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ tests/testthat/Rplots.pdf
**/*.tar.gz
pkgnet.Rcheck/*
.Rproj.user

# Compiled vignette
inst/doc/*
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Authors@R: c(
person("Brian", "Burns", email = "brian.burns@uptake.com", role = c("aut", "cre")),
person("James", "Lamb", email = "james.lamb@uptake.com", role = c("aut")),
person("Patrick", "Boueri", email = "patrick.boueri@uptake.com", role = c("ctb")),
person("Jay", "Qi", email = "jay.qi@uptake.com", role = c("ctb"))
person("Jay", "Qi", email = "jay.qi@uptake.com", role = c("aut"))
jayqi marked this conversation as resolved.
Show resolved Hide resolved
)
Maintainer: Brian Burns <brian.burns@uptake.com>
Description: Tools from the domain of graph theory can be used to quantify the complexity
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ importFrom(data.table,data.table)
importFrom(data.table,melt)
importFrom(data.table,rbindlist)
importFrom(data.table,setcolorder)
importFrom(data.table,setkeyv)
importFrom(data.table,setnames)
importFrom(data.table,uniqueN)
importFrom(futile.logger,INFO)
Expand Down
288 changes: 144 additions & 144 deletions R/AbstractGraphReporter.R

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions R/PackageDependencyReporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ DependencyReporter <- R6::R6Class(
),

private = list(
# Default graph viz layout
private_layout_type = "layout_as_tree",

dep_types = NULL,
ignore_packages = NULL,
Expand Down Expand Up @@ -173,12 +175,15 @@ DependencyReporter <- R6::R6Class(
log_fatal(sprintf(msg, self$pkg_name, paste(private$dep_types, collapse = ", ")))
}

# If pkg A depends on pkg B, then A -> B
# A is the SOURCE and B is the TARGET
# This is UML dependency convention
edges <- data.table::rbindlist(lapply(
names(dependencyList),
function(pkgN){
data.table::data.table(
SOURCE = dependencyList[[pkgN]]
, TARGET = rep(pkgN,length(dependencyList[[pkgN]]))
SOURCE = rep(pkgN, length(dependencyList[[pkgN]]))
, TARGET = dependencyList[[pkgN]]
)
}
))
Expand Down Expand Up @@ -236,5 +241,16 @@ DependencyReporter <- R6::R6Class(
}
return(outPackages)
}
)

, plot_network = function() {
g <- super$plot_network()

g <- (g
%>% visNetwork::visHierarchicalLayout(
sortMethod = "directed"
, direction = "UD")
)
return(g)
}
) # /private
)
36 changes: 25 additions & 11 deletions R/PackageFunctionReporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ FunctionReporter <- R6::R6Class(

private = list(

# Default graph viz layout
private_layout_type = "layout_with_graphopt",

get_pkg_env = function() {
if (is.null(private$cache$pkg_env)) {
# create a custom environment w/ this package's contents
Expand Down Expand Up @@ -314,6 +317,15 @@ FunctionReporter <- R6::R6Class(

return(edgeDT)
}

, plot_network = function() {
g <- super$plot_network()

g <- (g
%>% visNetwork::visHierarchicalLayout(enabled = FALSE)
)
return(g)
}
)
)

Expand Down Expand Up @@ -349,13 +361,14 @@ FunctionReporter <- R6::R6Class(
return(invisible(NULL))
}

# Convention: If B depends on A, then B is the TARGET
# and A is the SOURCE so that it looks like A -> B
# Convention: If A depends on B, then A is the SOURCE
# and B is the TARGET so that it looks like A -> B
# This is consistent with the UML dependency convention
# fname calls <matches>. So fname depends on <matches>.
# So fname is TARGET and <matches> are SOURCEs
# So fname is SOURCE and <matches> are TARGETs
edgeDT <- data.table::data.table(
SOURCE = unique(all_functions[matches])
, TARGET = fname
SOURCE = fname
, TARGET = unique(all_functions[matches])
)

return(edgeDT)
Expand Down Expand Up @@ -486,13 +499,14 @@ FunctionReporter <- R6::R6Class(
return(NULL)
}

# Convention: If B depends on A, then B is the TARGET
# and A is the SOURCE so that it looks like A -> B
# fname calls <matches>. So fname depends on <matches>.
# So fname is TARGET and <matches> are SOURCEs
# Convention: If A depends on B, then A is the SOURCE
# and B is the TARGET so that it looks like A -> B
# This is consistent with the UML dependency convention.
# The method calls the MATCHes, so method is SOURCE and
# the MATCHes are the TARGETs
edgeDT <- data.table::data.table(
SOURCE = unique(mbodyDT[!is.na(MATCH), MATCH])
, TARGET = paste(class_name, method_type, method_name, sep = "$")
SOURCE = paste(class_name, method_type, method_name, sep = "$")
, TARGET = unique(mbodyDT[!is.na(MATCH), MATCH])
)

return(edgeDT)
Expand Down
26 changes: 25 additions & 1 deletion R/PackageInheritanceReporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ InheritanceReporter <- R6::R6Class(

if (nrow(nodeDT) == 0) {
msg <- sprintf(
'No Reference Class or R6 Class definitions found in package %s'
'No S4, Reference, or R6 class definitions found in package %s'
, self$pkg_name
)
log_warn(msg)
Expand Down Expand Up @@ -194,7 +194,12 @@ InheritanceReporter <- R6::R6Class(
}
}

# Combine all edges together
edgeDT <- data.table::rbindlist(edgeList)

# Filter out any parents that are external to the package
edgeDT <- edgeDT[TARGET %in% nodeDT[, node]]

private$cache$edges <- edgeDT

}
Expand All @@ -207,12 +212,31 @@ InheritanceReporter <- R6::R6Class(
),

private = list(
# Default graph viz layout
private_layout_type = "layout_as_tree",

plotNodeColorScheme = list(
field = "classType"
, palette = c('#f0f9e8', '#bae4bc', '#7bccc4')
jayqi marked this conversation as resolved.
Show resolved Hide resolved
),

get_pkg_env = function() {
if (is.null(private$cache$pkg_env)) {
# create a custom environment w/ this package's contents
private$cache$pkg_env <- loadNamespace(self$pkg_name)
}
return(private$cache$pkg_env)
},

plot_network = function() {
g <- super$plot_network()

g <- (g
%>% visNetwork::visHierarchicalLayout(
sortMethod = "directed"
, direction = "DU")
)
return(g)
}
)

Expand Down
7 changes: 7 additions & 0 deletions R/pkgnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ globalVariables(c('.'
,'xend'
,'y'
,'yend'
, 'CLASS_NAME'
, 'MATCH'
, 'METHOD_NAME'
, 'METHOD_TYPE'
, 'PARENT_IN_PKG'
, 'PARENT_NAME'
, 'SYMBOL'
))

# NULL object for common parameter documentation
Expand Down
2 changes: 1 addition & 1 deletion inst/milne/R/The_Friend.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ RightAnswer <- setRefClass(
# @description Incorrect Answer to a Question
WrongAnswer <- setRefClass(
Class = "WrongAnswer",
contains = "PoohAnswer"
contains = c("PoohAnswer", "numeric")
)
12 changes: 11 additions & 1 deletion inst/package_report/package_report.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@ params:
pkg_name: params$pkg_name
---

<style>
body .main-container {
max-width: 80%;
}
</style>

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning=FALSE)
knitr::opts_chunk$set(
echo = FALSE
, warning=FALSE
, out.width='100%'
jayqi marked this conversation as resolved.
Show resolved Hide resolved
)
pkgnet:::silence_logger()
```

Expand Down
6 changes: 2 additions & 4 deletions man/AbstractGraphReporter.Rd

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

4 changes: 2 additions & 2 deletions man/FunctionReporter.Rd

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

42 changes: 21 additions & 21 deletions man/InheritanceReporter.Rd

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

13 changes: 10 additions & 3 deletions tests/testthat/test-AbstractGraphReporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ futile.logger::flog.threshold(0)
## Structure Available ##

test_that('AbstractGraphReporter structure is as expected', {

expect_named(
object = AbstractGraphReporter$public_methods
, expected = c("clone")
, info = "Available public methods for AbstractGraphReporter not as expected."
, ignore.order = TRUE
, ignore.case = FALSE
)

expect_named(
object = AbstractGraphReporter$public_fields
, expected = NULL
Expand All @@ -37,8 +37,15 @@ test_that('AbstractGraphReporter structure is as expected', {

### USAGE OF PUBLIC AND PRIVATE METHODS AND FIELDS TO BE TESTED BY CHILD OBJECTS

test_that(".igraphAvailableLayouts returns layouts correctly", {
expect_true({
length(pkgnet:::.igraphAvailableLayouts()) > 0
})
})


##### TEST TEAR DOWN #####

futile.logger::flog.threshold(origLogThreshold)
rm(list = ls())
closeAllConnections()
closeAllConnections()
Loading