|
| 1 | +--- |
| 2 | +title: "Network" |
| 3 | +execute: |
| 4 | + echo: false |
| 5 | +format: |
| 6 | + html: |
| 7 | + fig-width: 8 |
| 8 | + fig-height: 4 |
| 9 | + code-fold: false |
| 10 | +--- |
| 11 | + |
| 12 | +```{r load-pkg, echo = FALSE, message = FALSE} |
| 13 | +library (repometrics) |
| 14 | +requireNamespace ("dplyr", quietly = TRUE) |
| 15 | +requireNamespace ("tidyr", quietly = TRUE) |
| 16 | +``` |
| 17 | +```{r load-data} |
| 18 | +dat_pkg <- readRDS ("results-repo.Rds") |
| 19 | +dat_users <- readRDS ("results-users.Rds") |
| 20 | +
|
| 21 | +deps <- dat_pkg$rm$dependencies |
| 22 | +get_dep_df <- function (deps, type = "Imports", group = 1L) { |
| 23 | + index <- which (deps$type == type) |
| 24 | + data.frame (id = deps$name [index], group = rep (group, length (index))) |
| 25 | +} |
| 26 | +
|
| 27 | +nodes_pkg_ <- rbind ( |
| 28 | + get_dep_df (deps, "Imports", 1L), |
| 29 | + get_dep_df (deps, "Suggests", 2L) |
| 30 | +) |
| 31 | +nodes_user <- data.frame (id = dat_pkg$rm$contribs_from_gh_api$login, group = 4L) |
| 32 | +nodes_user$group [which (nodes_user$id %in% names (dat_users))] <- 3L |
| 33 | +``` |
| 34 | + |
| 35 | +```{ojs ForceGraph-import} |
| 36 | +import {ForceGraph} from "@d3/force-directed-graph-component" |
| 37 | +``` |
| 38 | + |
| 39 | +```{ojs import-network-data} |
| 40 | +network = FileAttachment("results-user-network.json").json() |
| 41 | +``` |
| 42 | + |
| 43 | +```{ojs ForceGraph-plot} |
| 44 | +chart = ForceGraph(network, { |
| 45 | + nodeId: d => d.id, |
| 46 | + nodeGroup: d => d.group, |
| 47 | + nodeTitle: d => `${d.id}\n${d.group}`, |
| 48 | + linkStrokeWidth: l => Math.sqrt(l.value), |
| 49 | + width, |
| 50 | + height: 600, |
| 51 | + invalidation // a promise to stop the simulation when the cell is re-run |
| 52 | +}) |
| 53 | +``` |
0 commit comments