A container or map is a group of diagram elements. Some special chart types,
such as the SQL Table created by d2_sql_table()
must be set up as a
container. Using containers can also help set element properties including
the class, label, shape and dimensions (width and height) for a set of
diagram elements.
Usage
d2_container(
...,
lines = NULL,
id = NULL,
class = NULL,
name = NULL,
label = NULL,
shape = NULL,
width = NULL,
height = NULL,
icon = NULL,
style = d2_style(),
collapse = NULL
)
Arguments
- ...
Diagram text.
- lines
Optional diagram text. If supplied
lines
is recycled to match the length ofid
.- id
D2 diagram map identifier. All other container or map attributes are recycled to match the length of
id
usingvctrs::vec_recycle_common()
- class
Diagram class
- name
Diagram container name
- label
Diagram label
- shape
Diagram shape
- width, height
Diagram width and height (in pixels?)
- icon
Diagram icon
- style
A string or results from the
d2_style()
helper function.- collapse
If
collapse = "\n"
, return a string with D2 diagram code for a container. Ifcollapse = NULL
(default), return a character vector with the same length as id.
Examples
d2_container(
"team1 <-> team2", "team2 <-> team3", "team3 <-> team1",
id = c("round1", "round2")
)
#> [1] "round1: {\n team1 <-> team2\nteam2 <-> team3\nteam3 <-> team1\n}"
#> [2] "round2: {\n team1 <-> team2\nteam2 <-> team3\nteam3 <-> team1\n}"
d2_container(
lines = c("shark -> fish: eats", "lion -> gazelle: eats"),
id = c("ocean", "savannah")
)
#> [1] "ocean: {\n shark -> fish: eats\n}"
#> [2] "savannah: {\n lion -> gazelle: eats\n}"