Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mermaid diagrams: Adjust white space around graph

I'm using mermaid diagrams in my Rmd reports compiled with Rstudio. In the HTML/PDF output, there is a lot of blank space above and below the charts, see example below.

# Header
Text
```{r}
library(DiagrammeR)
mermaid("
graph TD
    classDef style_main_node fill:orange,stroke:#333,stroke-width:0px;
    classDef style_sub_node fill:lightgray,stroke:#333,stroke-width:0px;

0(Top)
0 --> A1(Left)
0 --> B1(Center)
0 --> C1(Right)

    class 0 style_main_node;
    class A1,B1,C1 style_sub_node;
")
```
Text

HTML Output: rendered Rmd with mermaid graph

Is there a way to crop off/adjust the white space around the graph? And possibly also to change its size?

like image 360
mavericks Avatar asked Oct 22 '18 08:10

mavericks


1 Answers

Just specify height and width around diagram with: height = '100%', width = '100%'

# Header
Text
```{r}
library(DiagrammeR)
mermaid("
graph TD
    classDef style_main_node fill:orange,stroke:#333,stroke-width:0px;
    classDef style_sub_node fill:lightgray,stroke:#333,stroke-width:0px;

0(Top)
0 --> A1(Left)
0 --> B1(Center)
0 --> C1(Right)

    class 0 style_main_node;
    class A1,B1,C1 style_sub_node;
", height = '100%', width = '100%')
```
Text

enter image description here

like image 112
Radovan Miletić Avatar answered Nov 02 '22 18:11

Radovan Miletić