Skip to content

Commit

Permalink
added node coloring in DependencyReporter (fixes #238, #239) (#243)
Browse files Browse the repository at this point in the history
* added node coloring in DependencyReporter

* why does this not work

* ugh

* refactored plotting

* added notes on color scheme

* updated color choices for DependencyReporter

* Added legend and cleaned up left-behind code

* more changes

* replace delete Rmd and undo unrelated formatting sttuff

* update text about colors
  • Loading branch information
jameslamb authored Jul 21, 2020
1 parent bd70ded commit 330f379
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ importFrom(assertthat,is.readable)
importFrom(assertthat,is.string)
importFrom(assertthat,is.writeable)
importFrom(covr,package_coverage)
importFrom(data.table,":=")
importFrom(data.table,as.data.table)
importFrom(data.table,copy)
importFrom(data.table,data.table)
Expand Down
27 changes: 26 additions & 1 deletion R/DependencyReporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ NULL
#' @importFrom assertthat assert_that is.flag
#' @importFrom utils installed.packages
#' @importFrom tools package_dependencies
#' @importFrom data.table data.table rbindlist setkeyv
#' @importFrom data.table := data.table rbindlist setkeyv
#' @importFrom visNetwork visHierarchicalLayout
#' @export
DependencyReporter <- R6::R6Class(
Expand Down Expand Up @@ -221,6 +221,31 @@ DependencyReporter <- R6::R6Class(
}

, plot_network = function() {

# color base packages and the package in focus differently
gray <- "#dfdfdf"
orange <- "#FFBD33"
bright_green <- "#aafca8"

packageDT <- data.table::as.data.table(
installed.packages()
)
base_packages <- packageDT[!is.na(Priority) & Priority == "base"][, Package]

nodeDT <- self$nodes
nodeDT[, package_type := "regular_dependency"]
nodeDT[node %in% base_packages, package_type := "base_dependency"]
nodeDT[node == self$pkg_name, package_type := "report_package"]
private$update_nodes(nodeDT)
private$set_plot_node_color_scheme(
field = "package_type"
, palette = c(
"regular_dependency" = bright_green
, "report_package" = orange
, "base_dependency" = gray
)
)

g <- (
super$plot_network()
%>% visNetwork::visHierarchicalLayout(
Expand Down
6 changes: 6 additions & 0 deletions inst/package_report/package_dependency_reporter.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ output: html_document

This section analyzes the recursive package dependencies of **`r reporter$pkg_name`**.

In the plot below, you'll see the following colors:

- gray: **`r reporter$pkg_name`**
- orange: R packages available [in every R session by default](https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Default-packages)
- green: third-party R packages

```{r echo = FALSE, error = TRUE}
reporter$calculate_default_measures()
```
Expand Down

0 comments on commit 330f379

Please sign in to comment.