mermaid: Plot a mermaid diagram

View source: R/plot.GRiwrm.R

mermaidR Documentation

Plot a mermaid diagram

Description

These functions download the diagram from https://mermaid.ink which generates the image.

Usage

mermaid(
  diagram,
  format = "png",
  theme = "default",
  dir.dest = tempdir(),
  file.dest = paste0(rlang::hash(link), ".", format),
  link = mermaid_gen_link(diagram, theme = theme, format = format)
)

mermaid_gen_link(
  diagram,
  theme = "default",
  format = "png",
  server = "https://mermaid.ink"
)

## S3 method for class 'mermaid'
plot(x, add = FALSE, ...)

Arguments

diagram

Diagram in mermaid markdown-like language or file (as a connection or file name) containing a diagram specification

format

Image format (either "jpg", or "png", or "svg")

theme

Mermaid theme (See available themes in Mermaid documentation)

dir.dest

Destination folder for the downloaded image. This parameter is ignored if file.dest contains a folder path.

file.dest

Path to the downloaded image. It's combined with dir.dest if it only contains the name of the file without a folder path.

link

Link generated by mermaid_gen_link

server

URL of the server used to generate the link

x

character mermaid diagram dialect

add

logical to add the diagram on the existing plot

...

Other argument passed to mermaid

Details

Compared to the diagrammeR::mermaid function, the generated image or plot is not a HTMLwidget and can be knit in pdf through latex and moreover, its size can be controlled with fig.width and fig.height.

If the generation failed (due to internet connection failure or syntax error in mermaid script), the functions raises no error (see mermaid returned value).

Value

  • mermaid returns the path to the downloaded image or NA if the download failed. In this latter case, get the error message in the attribute "error".

  • mermaid_gen_link returns the link to the web service which generates the diagram

  • plot.mermaid produces a R plot with the mermaid diagram

Nothing, used for side effect.

Examples

## Not run: 
diagram <- "flowchart LR\n  A --> B"
mermaid_gen_link(diagram)
f <- mermaid(diagram)
f

# For displaying the diagram in Rmarkdown document
knitr::include_graphics(mermaid(diagram))

# Clean temporary folder
unlink(f)

## End(Not run)

s <- "flowchart LR
A -> B"
class(s) <- c("mermaid", class(s))
plot(s)

inrae/airGRiwrm documentation built on Sept. 27, 2024, 6:08 p.m.