Learn R Programming

g6R (version 0.5.0)

g6_node: G6 Graph Elements

Description

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
)

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 )

validate_element(x, ...)

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

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

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

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

Value

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

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).

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.

Examples

Run this code
# 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)

Run the code above in your browser using DataLab