<N, E>(options?: MermaidOptions<N, E>): <T extends Kind = "directed">(
graph: Graph<N, E, T> | MutableGraph<N, E, T>
) => string
<N, E, T extends Kind = "directed">(
graph: Graph<N, E, T> | MutableGraph<N, E, T>,
options?: MermaidOptions<N, E>
): stringExports a graph to Mermaid diagram format for visualization.
Details
Mermaid is a popular diagram-as-code tool that generates flowcharts and other visualizations from text-based definitions. This function converts Effect Graph structures to valid Mermaid syntax for use in documentation, web applications, and visualization tools.
Example (Exporting a directed Mermaid diagram)
import { Graph } from "effect"
// Basic directed graph export
const graph = Graph.directed<string, number>((mutable) => {
const app = Graph.addNode(mutable, "App")
const db = Graph.addNode(mutable, "Database")
const cache = Graph.addNode(mutable, "Cache")
Graph.addEdge(mutable, app, db, 1)
Graph.addEdge(mutable, app, cache, 2)
})
const mermaid = Graph.toMermaid(graph)
console.log(mermaid)
// flowchart TD
// 0["App"]
// 1["Database"]
// 2["Cache"]
// 0 -->|"1"| 1
// 0 -->|"2"| 2Example (Exporting an undirected Mermaid diagram)
import { Graph } from "effect"
// Undirected graph with custom labels and direction
const socialGraph = Graph.undirected<{ name: string }, string>((mutable) => {
const alice = Graph.addNode(mutable, { name: "Alice" })
const bob = Graph.addNode(mutable, { name: "Bob" })
const charlie = Graph.addNode(mutable, { name: "Charlie" })
Graph.addEdge(mutable, alice, bob, "friends")
Graph.addEdge(mutable, bob, charlie, "colleagues")
})
const mermaid = Graph.toMermaid(socialGraph, {
nodeLabel: (person) => person.name,
edgeLabel: (relationship) => relationship,
direction: "LR"
})
console.log(mermaid)
// graph LR
// 0["Alice"]
// 1["Bob"]
// 2["Charlie"]
// 0 ---|"friends"| 1
// 1 ---|"colleagues"| 2Example (Customizing Mermaid node shapes)
import { Graph } from "effect"
// Advanced styling with node shapes for flowchart
const workflow = Graph.directed<{ type: string; name: string }, string>(
(mutable) => {
const start = Graph.addNode(mutable, { type: "start", name: "Begin" })
const process = Graph.addNode(mutable, {
type: "process",
name: "Process Data"
})
const decision = Graph.addNode(mutable, {
type: "decision",
name: "Valid?"
})
const end = Graph.addNode(mutable, { type: "end", name: "Complete" })
Graph.addEdge(mutable, start, process, "")
Graph.addEdge(mutable, process, decision, "")
Graph.addEdge(mutable, decision, end, "yes")
}
)
const mermaid = Graph.toMermaid(workflow, {
nodeLabel: (node) => node.name,
nodeShape: (node) => {
switch (node.type) {
case "start":
return "stadium"
case "process":
return "rectangle"
case "decision":
return "diamond"
case "end":
return "stadium"
default:
return "rectangle"
}
}
})
console.log(mermaid)
// flowchart TD
// 0(["Begin"])
// 1["Process Data"]
// 2{"Valid?"}
// 3(["Complete"])
// 0 --> 1
// 1 --> 2
// 2 --> 3Example (Visualizing dependency graphs)
import { Graph } from "effect"
// Real-world example: Software dependency graph
interface Dependency {
name: string
version: string
type: "library" | "framework" | "tool"
}
const dependencyGraph = Graph.directed<Dependency, string>((mutable) => {
const app = Graph.addNode(mutable, {
name: "MyApp",
version: "1.0.0",
type: "library"
})
const react = Graph.addNode(mutable, {
name: "React",
version: "18.0.0",
type: "framework"
})
const lodash = Graph.addNode(mutable, {
name: "Lodash",
version: "4.17.0",
type: "library"
})
const webpack = Graph.addNode(mutable, {
name: "Webpack",
version: "5.0.0",
type: "tool"
})
Graph.addEdge(mutable, app, react, "depends on")
Graph.addEdge(mutable, app, lodash, "depends on")
Graph.addEdge(mutable, app, webpack, "builds with")
})
const dependencyDiagram = Graph.toMermaid(dependencyGraph, {
nodeLabel: (dep) => `${dep.name}\\nv${dep.version}`,
edgeLabel: (edge) => edge,
nodeShape: (dep) =>
dep.type === "framework" ?
"hexagon" :
dep.type === "tool"
? "diamond"
: "rectangle",
direction: "TB"
})
console.log(dependencyDiagram)
// flowchart TB
// 0["MyApp\nv1.0.0"]
// 1{{"React\nv18.0.0"}}
// 2["Lodash\nv4.17.0"]
// 3{"Webpack\nv5.0.0"}
// 0 -->|"depends on"| 1
// 0 -->|"depends on"| 2
// 0 -->|"builds with"| 3export const const toMermaid: {
<N, E>(options?: MermaidOptions<N, E>): <
T extends Kind = "directed"
>(
graph: Graph<N, E, T> | MutableGraph<N, E, T>
) => string
<N, E, T extends Kind = "directed">(
graph: Graph<N, E, T> | MutableGraph<N, E, T>,
options?: MermaidOptions<N, E>
): string
}
Exports a graph to Mermaid diagram format for visualization.
Details
Mermaid is a popular diagram-as-code tool that generates flowcharts and other
visualizations from text-based definitions. This function converts Effect Graph
structures to valid Mermaid syntax for use in documentation, web applications,
and visualization tools.
Example (Exporting a directed Mermaid diagram)
import { Graph } from "effect"
// Basic directed graph export
const graph = Graph.directed<string, number>((mutable) => {
const app = Graph.addNode(mutable, "App")
const db = Graph.addNode(mutable, "Database")
const cache = Graph.addNode(mutable, "Cache")
Graph.addEdge(mutable, app, db, 1)
Graph.addEdge(mutable, app, cache, 2)
})
const mermaid = Graph.toMermaid(graph)
console.log(mermaid)
// flowchart TD
// 0["App"]
// 1["Database"]
// 2["Cache"]
// 0 -->|"1"| 1
// 0 -->|"2"| 2
Example (Exporting an undirected Mermaid diagram)
import { Graph } from "effect"
// Undirected graph with custom labels and direction
const socialGraph = Graph.undirected<{ name: string }, string>((mutable) => {
const alice = Graph.addNode(mutable, { name: "Alice" })
const bob = Graph.addNode(mutable, { name: "Bob" })
const charlie = Graph.addNode(mutable, { name: "Charlie" })
Graph.addEdge(mutable, alice, bob, "friends")
Graph.addEdge(mutable, bob, charlie, "colleagues")
})
const mermaid = Graph.toMermaid(socialGraph, {
nodeLabel: (person) => person.name,
edgeLabel: (relationship) => relationship,
direction: "LR"
})
console.log(mermaid)
// graph LR
// 0["Alice"]
// 1["Bob"]
// 2["Charlie"]
// 0 ---|"friends"| 1
// 1 ---|"colleagues"| 2
Example (Customizing Mermaid node shapes)
import { Graph } from "effect"
// Advanced styling with node shapes for flowchart
const workflow = Graph.directed<{ type: string; name: string }, string>(
(mutable) => {
const start = Graph.addNode(mutable, { type: "start", name: "Begin" })
const process = Graph.addNode(mutable, {
type: "process",
name: "Process Data"
})
const decision = Graph.addNode(mutable, {
type: "decision",
name: "Valid?"
})
const end = Graph.addNode(mutable, { type: "end", name: "Complete" })
Graph.addEdge(mutable, start, process, "")
Graph.addEdge(mutable, process, decision, "")
Graph.addEdge(mutable, decision, end, "yes")
}
)
const mermaid = Graph.toMermaid(workflow, {
nodeLabel: (node) => node.name,
nodeShape: (node) => {
switch (node.type) {
case "start":
return "stadium"
case "process":
return "rectangle"
case "decision":
return "diamond"
case "end":
return "stadium"
default:
return "rectangle"
}
}
})
console.log(mermaid)
// flowchart TD
// 0(["Begin"])
// 1["Process Data"]
// 2{"Valid?"}
// 3(["Complete"])
// 0 --> 1
// 1 --> 2
// 2 --> 3
Example (Visualizing dependency graphs)
import { Graph } from "effect"
// Real-world example: Software dependency graph
interface Dependency {
name: string
version: string
type: "library" | "framework" | "tool"
}
const dependencyGraph = Graph.directed<Dependency, string>((mutable) => {
const app = Graph.addNode(mutable, {
name: "MyApp",
version: "1.0.0",
type: "library"
})
const react = Graph.addNode(mutable, {
name: "React",
version: "18.0.0",
type: "framework"
})
const lodash = Graph.addNode(mutable, {
name: "Lodash",
version: "4.17.0",
type: "library"
})
const webpack = Graph.addNode(mutable, {
name: "Webpack",
version: "5.0.0",
type: "tool"
})
Graph.addEdge(mutable, app, react, "depends on")
Graph.addEdge(mutable, app, lodash, "depends on")
Graph.addEdge(mutable, app, webpack, "builds with")
})
const dependencyDiagram = Graph.toMermaid(dependencyGraph, {
nodeLabel: (dep) => `${dep.name}\\nv${dep.version}`,
edgeLabel: (edge) => edge,
nodeShape: (dep) =>
dep.type === "framework" ?
"hexagon" :
dep.type === "tool"
? "diamond"
: "rectangle",
direction: "TB"
})
console.log(dependencyDiagram)
// flowchart TB
// 0["MyApp\nv1.0.0"]
// 1{{"React\nv18.0.0"}}
// 2["Lodash\nv4.17.0"]
// 3{"Webpack\nv5.0.0"}
// 0 -->|"depends on"| 1
// 0 -->|"depends on"| 2
// 0 -->|"builds with"| 3
toMermaid: {
<function (type parameter) N in <N, E>(options?: MermaidOptions<N, E>): <T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>) => stringN, function (type parameter) E in <N, E>(options?: MermaidOptions<N, E>): <T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>) => stringE>(
options: MermaidOptions<N, E>options?: interface MermaidOptions<N, E>Configuration options for Mermaid diagram generation from graphs.
Details
These options customize node labels, edge labels, diagram type, layout
direction, node shapes, and graph naming in Mermaid format.
Example (Configuring Mermaid output)
import type { Graph } from "effect"
// Basic options with custom labels
const basicOptions: Graph.MermaidOptions<string, number> = {
nodeLabel: (data) => `Node: ${data}`,
edgeLabel: (data) => `Weight: ${data}`
}
// Advanced options with all features
const advancedOptions: Graph.MermaidOptions<string, string> = {
nodeLabel: (data) => data.toUpperCase(),
edgeLabel: (data) => data,
diagramType: "flowchart",
direction: "LR",
nodeShape: (data) => data.includes("start") ? "circle" : "rectangle"
}
MermaidOptions<function (type parameter) N in <N, E>(options?: MermaidOptions<N, E>): <T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>) => stringN, function (type parameter) E in <N, E>(options?: MermaidOptions<N, E>): <T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>) => stringE>
): <function (type parameter) T in <T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>): stringT extends type Kind = "directed" | "undirected"Graph type for distinguishing directed and undirected graphs.
When to use
Use when writing graph-polymorphic types or helpers that need to preserve
whether a graph is directed or undirected.
Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>graph: interface Graph<out N, out E, T extends Kind = "directed">Immutable graph interface.
When to use
Use as the immutable graph model for code that queries, traverses,
transforms, or analyzes graph structure without mutating it.
Graph<function (type parameter) N in <N, E>(options?: MermaidOptions<N, E>): <T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>) => stringN, function (type parameter) E in <N, E>(options?: MermaidOptions<N, E>): <T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>) => stringE, function (type parameter) T in <T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>): stringT> | interface MutableGraph<out N, out E, T extends Kind = "directed">Mutable graph interface.
When to use
Use when adding, removing, or updating nodes and edges inside a graph
mutation scope.
MutableGraph<function (type parameter) N in <N, E>(options?: MermaidOptions<N, E>): <T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>) => stringN, function (type parameter) E in <N, E>(options?: MermaidOptions<N, E>): <T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>) => stringE, function (type parameter) T in <T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>): stringT>) => string
<function (type parameter) N in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringN, function (type parameter) E in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringE, function (type parameter) T in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringT extends type Kind = "directed" | "undirected"Graph type for distinguishing directed and undirected graphs.
When to use
Use when writing graph-polymorphic types or helpers that need to preserve
whether a graph is directed or undirected.
Kind = "directed">(
graph: Graph<N, E, T> | MutableGraph<N, E, T>graph: interface Graph<out N, out E, T extends Kind = "directed">Immutable graph interface.
When to use
Use as the immutable graph model for code that queries, traverses,
transforms, or analyzes graph structure without mutating it.
Graph<function (type parameter) N in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringN, function (type parameter) E in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringE, function (type parameter) T in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringT> | interface MutableGraph<out N, out E, T extends Kind = "directed">Mutable graph interface.
When to use
Use when adding, removing, or updating nodes and edges inside a graph
mutation scope.
MutableGraph<function (type parameter) N in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringN, function (type parameter) E in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringE, function (type parameter) T in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringT>,
options: MermaidOptions<N, E>options?: interface MermaidOptions<N, E>Configuration options for Mermaid diagram generation from graphs.
Details
These options customize node labels, edge labels, diagram type, layout
direction, node shapes, and graph naming in Mermaid format.
Example (Configuring Mermaid output)
import type { Graph } from "effect"
// Basic options with custom labels
const basicOptions: Graph.MermaidOptions<string, number> = {
nodeLabel: (data) => `Node: ${data}`,
edgeLabel: (data) => `Weight: ${data}`
}
// Advanced options with all features
const advancedOptions: Graph.MermaidOptions<string, string> = {
nodeLabel: (data) => data.toUpperCase(),
edgeLabel: (data) => data,
diagramType: "flowchart",
direction: "LR",
nodeShape: (data) => data.includes("start") ? "circle" : "rectangle"
}
MermaidOptions<function (type parameter) N in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringN, function (type parameter) E in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringE>
): string
} = import dualdual((args: anyargs) => const isGraph: (
u: unknown
) => u is Graph<unknown, unknown>
Returns true if a value has the graph runtime type identifier, narrowing
it to a Graph.
When to use
Use to narrow an unknown value before treating it as a graph value.
Gotchas
This guard checks the shared graph runtime type identifier and does not
distinguish immutable graphs from mutable graphs.
isGraph(args: anyargs[0]), <function (type parameter) N in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringN, function (type parameter) E in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringE, function (type parameter) T in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringT extends type Kind = "directed" | "undirected"Graph type for distinguishing directed and undirected graphs.
When to use
Use when writing graph-polymorphic types or helpers that need to preserve
whether a graph is directed or undirected.
Kind = "directed">(
graph: Graph<N, E, T> | MutableGraph<N, E, T>graph: interface Graph<out N, out E, T extends Kind = "directed">Immutable graph interface.
When to use
Use as the immutable graph model for code that queries, traverses,
transforms, or analyzes graph structure without mutating it.
Graph<function (type parameter) N in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringN, function (type parameter) E in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringE, function (type parameter) T in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringT> | interface MutableGraph<out N, out E, T extends Kind = "directed">Mutable graph interface.
When to use
Use when adding, removing, or updating nodes and edges inside a graph
mutation scope.
MutableGraph<function (type parameter) N in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringN, function (type parameter) E in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringE, function (type parameter) T in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringT>,
options: MermaidOptions<N, E>options?: interface MermaidOptions<N, E>Configuration options for Mermaid diagram generation from graphs.
Details
These options customize node labels, edge labels, diagram type, layout
direction, node shapes, and graph naming in Mermaid format.
Example (Configuring Mermaid output)
import type { Graph } from "effect"
// Basic options with custom labels
const basicOptions: Graph.MermaidOptions<string, number> = {
nodeLabel: (data) => `Node: ${data}`,
edgeLabel: (data) => `Weight: ${data}`
}
// Advanced options with all features
const advancedOptions: Graph.MermaidOptions<string, string> = {
nodeLabel: (data) => data.toUpperCase(),
edgeLabel: (data) => data,
diagramType: "flowchart",
direction: "LR",
nodeShape: (data) => data.includes("start") ? "circle" : "rectangle"
}
MermaidOptions<function (type parameter) N in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringN, function (type parameter) E in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringE>
): string => {
// Extract and validate options with defaults
const {
const diagramType:
| MermaidDiagramType
| undefined
Diagram type override. If not specified, automatically detects:
- "flowchart" for directed graphs
- "graph" for undirected graphs
diagramType,
const direction: MermaidDirectionDirection for diagram layout.
Defaults to "TD" (Top Down) if not provided.
direction = "TD",
const edgeLabel: (data: E) => stringFunction to generate custom labels for edges.
Defaults to String(data) if not provided.
edgeLabel = (data: Edata: function (type parameter) E in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringE) => var String: StringConstructor
;(value?: any) => string
Allows manipulation and formatting of text strings and determination and location of substrings within strings.
String(data: Edata),
const nodeLabel: (data: N) => stringFunction to generate custom labels for nodes.
Defaults to String(data) if not provided.
nodeLabel = (data: Ndata: function (type parameter) N in <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): stringN) => var String: StringConstructor
;(value?: any) => string
Allows manipulation and formatting of text strings and determination and location of substrings within strings.
String(data: Ndata),
const nodeShape: (
data: N
) => MermaidNodeShape
Function to determine node shape for each node.
Defaults to "rectangle" for all nodes if not provided.
nodeShape = () => "rectangle" as type const = "rectangle"const
} = options: MermaidOptions<N, E>options ?? {}
// Auto-detect diagram type if not specified
const const finalDiagramType: MermaidDiagramTypefinalDiagramType = const diagramType:
| MermaidDiagramType
| undefined
Diagram type override. If not specified, automatically detects:
- "flowchart" for directed graphs
- "graph" for undirected graphs
diagramType ??
(graph: Graph<N, E, T> | MutableGraph<N, E, T>graph.type: T extends Kind = "directed"type === "directed" ? "flowchart" : "graph")
// Generate diagram header
const const lines: string[]lines: interface Array<T>Array<string> = []
const lines: string[]lines.Array<string>.push(...items: string[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(`${const finalDiagramType: MermaidDiagramTypefinalDiagramType} ${const direction: MermaidDirectionDirection for diagram layout.
Defaults to "TD" (Top Down) if not provided.
direction}`)
// Add nodes
for (const [const nodeIndex: numbernodeIndex, const nodeData: NnodeData] of graph: Graph<N, E, T> | MutableGraph<N, E, T>graph.Proto<out N, out E>.nodes: Map<NodeIndex, N>nodes) {
const const nodeId: stringnodeId = var String: StringConstructor
;(value?: any) => string
Allows manipulation and formatting of text strings and determination and location of substrings within strings.
String(const nodeIndex: numbernodeIndex)
const const label: stringlabel = const escapeMermaidLabel: (
label: string
) => string
Escapes special characters in labels for Mermaid syntax compatibility.
escapeMermaidLabel(const nodeLabel: (data: N) => stringFunction to generate custom labels for nodes.
Defaults to String(data) if not provided.
nodeLabel(const nodeData: NnodeData))
const const shape: MermaidNodeShapeshape = const nodeShape: (
data: N
) => MermaidNodeShape
Function to determine node shape for each node.
Defaults to "rectangle" for all nodes if not provided.
nodeShape(const nodeData: NnodeData)
const const formattedNode: stringformattedNode = const formatMermaidNode: (
nodeId: string,
label: string,
shape: MermaidNodeShape
) => string
Formats a Mermaid node with the specified shape and label.
formatMermaidNode(const nodeId: stringnodeId, const label: stringlabel, const shape: MermaidNodeShapeshape)
const lines: string[]lines.Array<string>.push(...items: string[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(` ${const formattedNode: stringformattedNode}`)
}
// Add edges
const const edgeOperator: "-->" | "---"edgeOperator = const finalDiagramType: MermaidDiagramTypefinalDiagramType === "flowchart" ? "-->" : "---"
for (const [, const edgeData: Edge<E>const edgeData: {
source: number;
target: number;
data: E;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
edgeData] of graph: Graph<N, E, T> | MutableGraph<N, E, T>graph.Proto<out N, out E>.edges: Map<EdgeIndex, Edge<E>>edges) {
const const sourceId: stringsourceId = var String: StringConstructor
;(value?: any) => string
Allows manipulation and formatting of text strings and determination and location of substrings within strings.
String(const edgeData: Edge<E>const edgeData: {
source: number;
target: number;
data: E;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
edgeData.source)
const const targetId: stringtargetId = var String: StringConstructor
;(value?: any) => string
Allows manipulation and formatting of text strings and determination and location of substrings within strings.
String(const edgeData: Edge<E>const edgeData: {
source: number;
target: number;
data: E;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
edgeData.target)
const const label: stringlabel = const escapeMermaidLabel: (
label: string
) => string
Escapes special characters in labels for Mermaid syntax compatibility.
escapeMermaidLabel(const edgeLabel: (data: E) => stringFunction to generate custom labels for edges.
Defaults to String(data) if not provided.
edgeLabel(const edgeData: Edge<E>const edgeData: {
source: number;
target: number;
data: E;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
edgeData.data))
if (const label: stringlabel) {
const lines: string[]lines.Array<string>.push(...items: string[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(` ${const sourceId: stringsourceId} ${const edgeOperator: "-->" | "---"edgeOperator}|"${const label: stringlabel}"| ${const targetId: stringtargetId}`)
} else {
const lines: string[]lines.Array<string>.push(...items: string[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(` ${const sourceId: stringsourceId} ${const edgeOperator: "-->" | "---"edgeOperator} ${const targetId: stringtargetId}`)
}
}
return const lines: string[]lines.Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join("\n")
})