Lesson 1: My First Graph
A graph is specified as follows:
Nodes, edges, graph attributes etc. are specified inside the graph,
i.e. between the curly brackets.
A node is specified as follows:
node: { title: "the node's title" } |
All node titles have to be unique. The titles are case-sensitive
and whitespace-sensitive. For example, the names "a",
"A" and
"a " refer to three different nodes.
An edge is specified as follows:
edge: { source: "source node title"
target: "target node title"
} |
Example of a simple graph:
graph: {
node: { title: "mom" }
node: { title: "dad" }
node: { title: "son" }
edge: { source: "mom" target: "son" }
edge: { source: "dad" target: "son" }
} |
|
 |
By default, nodes are labeled with their titles.
To specify a different label for a node, use the attribute "label".
node: { title: "dad"
label: "John Smith"
} |
|
 |
Labels may contain the special characters
"\n" (new line), "\t" (tab), and
"\"" (double quotes).
node: { title: "dad"
label: "John\n\"Rambo\"\nSmith"
} |
|
 |
The graph specification may contain comments
in C style (a comment is enclosed between "/*" and "*/")
and in C++ style (a comment starts with a "//" and continues until the end of the line):
// This is a comment
// in C++ style
/* And this is a
comment in C style */ |
Example graph:
graph: {
// Nodes:
node: { title: "mom" }
node: { title: "dad" }
node: { title: "son 1" label: "son\n(James)" }
node: { title: "son 2" label: "son\n(Jim)" }
// Edges:
edge: { source: "mom" target: "son 1" }
edge: { source: "mom" target: "son 2" }
edge: { source: "dad" target: "son 1" }
edge: { source: "dad" target: "son 2" }
} |
|
 |
|