graph LR
A[Hard edge] --> B(Round edge)
B --> C{Decision}
C --> D[Result one] C --> E[Result two]
Introduction to mermaid.js
news
code
analysis
mermaid.js
is a Javascript library that allows you to create diagrams by writing “Markdown-ish syntax.” It has native support in Quarto:
Here is mermaid template for the 2023 NBA Playoffs (excluding the play-in tournament)1
library(dplyr, warn.conflicts = FALSE) # to load the magrittr pipe
<- "playoffs_template1.mmd" %>%
my_mmd readLines(warn = F)
%>%
my_mmd paste(collapse = "\n") %>%
::mermaid() DiagrammeR
We can progammatically edit this template with data about the teams and games:
library(readr)
library(stringr)
<- read_csv("nba_2023_seed_xwalk.csv", na = "")
seed_xwalk <- function (mmd) {
helper1_20230423 -1] %>%
mmd[str_trim() %>%
str_split(" --> ", simplify = T) %>%
as_tibble() %>%
setNames(c("From", "To")) %>%
left_join(seed_xwalk, by = c("From" = "seed")) %>%
transmute(
new_edges = paste0(" ",
case_when(!is.na(team_stub) ~ team_stub, T ~ From),
" --> ",
To)%>%
) pull(new_edges) %>%
c(mmd[1], .)
}%>%
my_mmd helper1_20230423() %>%
paste(collapse = "\n") %>%
::mermaid() DiagrammeR
Footnotes
DiagrammeR::mermaid()
does not appear to support every Mermaid diagram syntax, such as flowcharts. But the flowchart syntax can be manually entered into a Quarto mermaid code chunk.↩︎