Skip to contents

Constructors and validators for G6 node, edge, and combo elements.

Usage

g6_node(
  id,
  type = NULL,
  data = NULL,
  style = NULL,
  states = NULL,
  combo = NULL,
  children = NULL,
  ports = NULL,
  collapse = NULL,
  ui = NULL
)

g6_edge(
  source,
  target,
  id = paste(source, target, sep = "-"),
  type = NULL,
  data = NULL,
  style = NULL,
  states = NULL
)

g6_combo(
  id,
  type = NULL,
  data = NULL,
  style = NULL,
  states = NULL,
  combo = NULL,
  collapse = NULL
)

validate_element(x, ...)

# S3 method for class 'g6_element'
validate_element(x, ...)

# S3 method for class 'g6_node'
validate_element(x, ...)

# S3 method for class 'g6_edge'
validate_element(x, ...)

# S3 method for class 'g6_combo'
validate_element(x, ...)

Arguments

id

Character. Unique identifier for the node or combo (required). For edges, this is optional (id is constructed as source-target if not provided).

type

Character. Element type (optional).

data

List. Custom data for the element (optional).

style

List. Element style (optional).

states

Character vector. Initial states for the element (optional).

combo

Character or NULL. Combo ID or parent combo ID (optional).

children

Character vector. Child node IDs (optional, nodes only).

ports

List. Ports definition (optional, nodes only). See g6_ports and g6_port for details.

collapse

List. Collapse button configuration (optional, nodes and combos).

ui

Content of the node: Shiny UI or other HTML tags (optional, nodes only). Implies type = "custom-html-node". The content is built once per node and kept through redraws, moves and zooming, so Shiny inputs and outputs in it are bound once and keep their values. Mark an element of it with a data-g6-drag-handle attribute to drag the node from that element only, so that sliders, maps or text selection inside it do not move the node. Ports that set no r are sized to the node, a fiftieth of its width between 6 and 12, so they stay in proportion to a large card when the graph is zoomed out to fit; r on a port, or portR on the node or in the graph's node options, sets the radius instead. See g6_collapse_options for details. For nodes, only used when node has children. For combos, when provided and type is NULL, auto-sets type to "rect-combo-with-extra-button".

source

Character. Source node ID (required, edges only).

target

Character. Target node ID (required, edges only).

x

An object of class g6_element, g6_node, g6_edge, or g6_combo.

...

Additional arguments (unused). the checks on source and target.

Value

An S3 object of class g6_node, g6_edge, or g6_combo (and g6_element).

Examples

# Create a node
node <- g6_node(
  id = "n1",
  type = "rect",
  data = list(label = "Node 1"),
  style = list(color = "red"),
  states = list("selected"),
  combo = NULL,
  children = c("n2", "n3")
)

# Create an edge
edge <- g6_edge(
  source = "n1",
  target = "n2",
  type = "line",
  style = list(width = 2)
)

# Create a combo
combo <- g6_combo(
  id = "combo1",
  type = "rect",
  data = list(label = "Combo 1"),
  style = list(border = "dashed"),
  states = list("active"),
  combo = NULL
)

# Validate a node explicitly
validate_element(node)
#> $id
#> [1] "n1"
#> 
#> $type
#> [1] "rect"
#> 
#> $data
#> $data$label
#> [1] "Node 1"
#> 
#> 
#> $style
#> $style$color
#> [1] "red"
#> 
#> 
#> $states
#> $states[[1]]
#> [1] "selected"
#> 
#> 
#> $children
#> $children[[1]]
#> [1] "n2"
#> 
#> $children[[2]]
#> [1] "n3"
#> 
#> 
#> attr(,"class")
#> [1] "g6_node"    "g6_element"