Skip to content

A subgraph (or cluster) inside a Graph.

Obtain via Graph.addSubgraph. All mutation methods return this for chaining. Call Subgraph.delete (or use the using keyword) when finished to free the underlying WASM wrapper — the actual subgraph data is owned by the parent Graph and is freed with it.

Clusters are subgraphs whose name starts with "cluster". Layout engines draw them as a bounded rectangle:

ts
using cluster = graph.addSubgraph("cluster_0");
cluster
  .setAttr("label", "My Cluster")
  .setAttr("style", "filled")
  .setAttr("color", "lightblue")
  .addEdge("a", "b");

Constructors

Constructor

new Subgraph(sg): Subgraph

Internal

Parameters

sg

CSubgraph

Returns

Subgraph

Methods

addNode()

addNode(name): this

Create (or find) a node and add it to this subgraph.

Parameters

name

string

Returns

this


addEdge()

addEdge(tail, head, key?): this

Create an edge inside this subgraph. Both endpoints are created automatically if they do not already exist.

Parameters

tail

string

string

key?

string = ""

Returns

this


removeNode()

removeNode(name): this

Remove a node from this subgraph only. The node (and any edges connecting it) remains in the root graph and all other subgraphs. No-op if the node is not in this subgraph.

Parameters

name

string

Returns

this


removeEdge()

removeEdge(tail, head, key?): this

Remove a single edge from this subgraph only. The edge remains in the root graph and all other subgraphs. No-op if the edge is not present.

Parameters

tail

string

head

string

key?

string = ""

Returns

this


setAttr()

Call Signature

setAttr<K>(attr, value?, defaultValue?): this

Set an attribute on the subgraph itself (e.g. "label", "style", "color", "bgcolor"). See the official Graphviz attribute reference for supported attributes and values.

When attr is a known cluster attribute the value type is inferred automatically. A generic string | number | boolean fallback is provided for custom or less-common attributes. Omit value to reset the attribute to Graphviz's default empty value. defaultValue is passed to Graphviz as the default for this attribute if it has not already been declared.

Type Parameters
K

K extends ClusterDotAttr

Parameters
attr

K

value?

NonNullable<ClusterAttrs[K]>

defaultValue?

string | number | boolean

Returns

this

Call Signature

setAttr(attr, value?, defaultValue?): this

Set an attribute on the subgraph itself (e.g. "label", "style", "color", "bgcolor"). See the official Graphviz attribute reference for supported attributes and values.

When attr is a known cluster attribute the value type is inferred automatically. A generic string | number | boolean fallback is provided for custom or less-common attributes. Omit value to reset the attribute to Graphviz's default empty value. defaultValue is passed to Graphviz as the default for this attribute if it has not already been declared.

Parameters
attr

string

value?

string | number | boolean

defaultValue?

string | number | boolean

Returns

this


setHtmlAttr()

Call Signature

setHtmlAttr<K>(attr, value, defaultValue?): this

Type Parameters
K

K extends ClusterDotAttr

Parameters
attr

K

value

NonNullable<ClusterAttrs[K]>

defaultValue?

string | number | boolean

Returns

this

Call Signature

setHtmlAttr(attr, value, defaultValue?): this

Parameters
attr

string

value

string | number | boolean

defaultValue?

string | number | boolean

Returns

this


setDefaultAttr()

Call Signature

setDefaultAttr<K>(attr, value): this

Type Parameters
K

K extends ClusterDotAttr

Parameters
attr

K

value

NonNullable<ClusterAttrs[K]>

Returns

this

Call Signature

setDefaultAttr(attr, value): this

Parameters
attr

string

value

string | number | boolean

Returns

this


setDefaultHtmlAttr()

Call Signature

setDefaultHtmlAttr<K>(attr, value): this

Type Parameters
K

K extends ClusterDotAttr

Parameters
attr

K

value

NonNullable<ClusterAttrs[K]>

Returns

this

Call Signature

setDefaultHtmlAttr(attr, value): this

Parameters
attr

string

value

string | number | boolean

Returns

this


removeAttr()

removeAttr(attr): this

Clear a subgraph-level attribute by resetting it to its default (empty) value. Equivalent to setAttr(attr, "").

Parameters

attr

string

Returns

this


setNodeAttr()

Call Signature

setNodeAttr<K>(node, attr, value?, defaultValue?): this

Set an attribute on a node inside this subgraph.

When attr is a known node attribute the value type is inferred automatically. A generic string | number | boolean fallback is provided for custom attributes. Omit value to reset the attribute to Graphviz's default empty value. defaultValue is passed to Graphviz as the default for this attribute if it has not already been declared.

Type Parameters
K

K extends NodeDotAttr

Parameters
node

string

attr

K

value?

NonNullable<NodeAttrs[K]>

defaultValue?

string | number | boolean

Returns

this

Call Signature

setNodeAttr(node, attr, value?, defaultValue?): this

Set an attribute on a node inside this subgraph.

When attr is a known node attribute the value type is inferred automatically. A generic string | number | boolean fallback is provided for custom attributes. Omit value to reset the attribute to Graphviz's default empty value. defaultValue is passed to Graphviz as the default for this attribute if it has not already been declared.

Parameters
node

string

attr

string

value?

string | number | boolean

defaultValue?

string | number | boolean

Returns

this


setNodeHtmlAttr()

Call Signature

setNodeHtmlAttr<K>(node, attr, value, defaultValue?): this

Type Parameters
K

K extends NodeDotAttr

Parameters
node

string

attr

K

value

NonNullable<NodeAttrs[K]>

defaultValue?

string | number | boolean

Returns

this

Call Signature

setNodeHtmlAttr(node, attr, value, defaultValue?): this

Parameters
node

string

attr

string

value

string | number | boolean

defaultValue?

string | number | boolean

Returns

this


setDefaultNodeAttr()

Call Signature

setDefaultNodeAttr<K>(attr, value): this

Type Parameters
K

K extends NodeDotAttr

Parameters
attr

K

value

NonNullable<NodeAttrs[K]>

Returns

this

Call Signature

setDefaultNodeAttr(attr, value): this

Parameters
attr

string

value

string | number | boolean

Returns

this


setDefaultNodeHtmlAttr()

Call Signature

setDefaultNodeHtmlAttr<K>(attr, value): this

Type Parameters
K

K extends NodeDotAttr

Parameters
attr

K

value

NonNullable<NodeAttrs[K]>

Returns

this

Call Signature

setDefaultNodeHtmlAttr(attr, value): this

Parameters
attr

string

value

string | number | boolean

Returns

this


removeNodeAttr()

removeNodeAttr(node, attr): this

Clear a node attribute inside this subgraph by resetting it to its default (empty) value. Equivalent to setNodeAttr(node, attr, "").

Parameters

node

string

attr

string

Returns

this


setEdgeAttr()

Call Signature

setEdgeAttr<K>(tail, head, key, attr, value?, defaultValue?): this

Set an attribute on an edge inside this subgraph (identified by tail, head, and key).

When attr is a known edge attribute the value type is inferred automatically. A generic string | number | boolean fallback is provided for custom attributes. Omit value to reset the attribute to Graphviz's default empty value. defaultValue is passed to Graphviz as the default for this attribute if it has not already been declared.

Type Parameters
K

K extends EdgeDotAttr

Parameters
tail

string

head

string

key

string

attr

K

value?

NonNullable<EdgeAttrs[K]>

defaultValue?

string | number | boolean

Returns

this

Call Signature

setEdgeAttr(tail, head, key, attr, value?, defaultValue?): this

Set an attribute on an edge inside this subgraph (identified by tail, head, and key).

When attr is a known edge attribute the value type is inferred automatically. A generic string | number | boolean fallback is provided for custom attributes. Omit value to reset the attribute to Graphviz's default empty value. defaultValue is passed to Graphviz as the default for this attribute if it has not already been declared.

Parameters
tail

string

head

string

key

string

attr

string

value?

string | number | boolean

defaultValue?

string | number | boolean

Returns

this


setEdgeHtmlAttr()

Call Signature

setEdgeHtmlAttr<K>(tail, head, key, attr, value, defaultValue?): this

Type Parameters
K

K extends EdgeDotAttr

Parameters
tail

string

head

string

key

string

attr

K

value

NonNullable<EdgeAttrs[K]>

defaultValue?

string | number | boolean

Returns

this

Call Signature

setEdgeHtmlAttr(tail, head, key, attr, value, defaultValue?): this

Parameters
tail

string

head

string

key

string

attr

string

value

string | number | boolean

defaultValue?

string | number | boolean

Returns

this


setDefaultEdgeAttr()

Call Signature

setDefaultEdgeAttr<K>(attr, value): this

Type Parameters
K

K extends EdgeDotAttr

Parameters
attr

K

value

NonNullable<EdgeAttrs[K]>

Returns

this

Call Signature

setDefaultEdgeAttr(attr, value): this

Parameters
attr

string

value

string | number | boolean

Returns

this


setDefaultEdgeHtmlAttr()

Call Signature

setDefaultEdgeHtmlAttr<K>(attr, value): this

Type Parameters
K

K extends EdgeDotAttr

Parameters
attr

K

value

NonNullable<EdgeAttrs[K]>

Returns

this

Call Signature

setDefaultEdgeHtmlAttr(attr, value): this

Parameters
attr

string

value

string | number | boolean

Returns

this


removeEdgeAttr()

removeEdgeAttr(tail, head, key, attr): this

Clear an edge attribute inside this subgraph by resetting it to its default (empty) value. Equivalent to setEdgeAttr(tail, head, key, attr, "").

Parameters

tail

string

head

string

key

string

attr

string

Returns

this


hasNode()

hasNode(name): boolean

Returns true if a node with the given name exists in this subgraph.

Parameters

name

string

Returns

boolean


hasEdge()

hasEdge(tail, head, key?): boolean

Returns true if an edge from tail to head exists in this subgraph. Pass key to check for a specific parallel edge; omit (or pass "") to check for any edge between the two nodes.

Parameters

tail

string

head

string

key?

string = ""

Returns

boolean


nodeCount()

nodeCount(): number

Returns the number of nodes in this subgraph.

Returns

number


edgeCount()

edgeCount(): number

Returns the number of edges in this subgraph.

Returns

number


nodeDegree()

nodeDegree(node, inDegree?, outDegree?): number

Returns the degree of a named node in this subgraph.

Parameters

node

string

inDegree?

number = 1

outDegree?

number = 1

Returns

number


getAttr()

getAttr(attr): string

Returns the current value of a subgraph-level attribute, or "" if the attribute has not been set.

Parameters

attr

string

Returns

string


getNodeAttr()

getNodeAttr(node, attr): string

Returns the current value of the named attribute on a node in this subgraph, or "" if the node or attribute does not exist.

Parameters

node

string

attr

string

Returns

string


getEdgeAttr()

getEdgeAttr(tail, head, key, attr): string

Returns the current value of the named attribute on an edge in this subgraph, or "" if the edge or attribute does not exist. Pass key = "" for the first (or only) edge between tail and head.

Parameters

tail

string

head

string

key

string

attr

string

Returns

string


nodeNames()

nodeNames(): string[]

Returns the names of all nodes in this subgraph (in internal iteration order).

Returns

string[]


edges()

edges(): EdgeInfo[]

Returns all edges in this subgraph. Each unique edge is listed exactly once.

Returns

EdgeInfo[]


outEdges()

outEdges(node): EdgeInfo[]

Returns the out-edges of the named node in this subgraph. Returns [] if the node does not exist.

Parameters

node

string

Returns

EdgeInfo[]


inEdges()

inEdges(node): EdgeInfo[]

Returns the in-edges of the named node in this subgraph. Returns [] if the node does not exist.

Parameters

node

string

Returns

EdgeInfo[]


nodeEdges()

nodeEdges(node): EdgeInfo[]

Returns all edges incident to the named node in this subgraph (both in and out). Returns [] if the node does not exist.

Parameters

node

string

Returns

EdgeInfo[]


delete()

delete(): void

Release the WASM wrapper. The subgraph data itself is freed when the parent Graph is deleted.

Returns

void


[dispose]()

[dispose](): void

Internal

– supports the using keyword (explicit resource management).

Returns

void

Released under the Apache-2.0 License.