Kale Graph is an Obsidian plugin making it easy to visualize graphs (the Graph theory kind).
Getting started is as simple as installing the plugin and making a new code
block,
specifying kale
as the language.
Kale code blocks are parsed line by line. A line can specify flags, add vertices or add edges. A line cannot do multiple of these at the same time.
Kale code blocks can specify flags that change how the code block is
parsed/rendered. If the first line of a code block starts with a hyphen -
any
letter on the rest of the line will be treated as a flag and apply changes as
specified below.
Flag | Name | Description |
---|---|---|
d |
Directed | Makes the graph directed |
s |
Simple | Removes repeated edges |
a |
Auto | Adds missing vertices that edges are connected to |
f |
Flipped | Flips the rows and columns of an adjacency matrix |
A vertex is specified simply by a name that identifies that vertex. Vertex
names may contain letters, digits and underscores (_
). Multiple vertices can
be defined on a single line using the following syntax (spaces are optional):
vertex1, vertex2, vertex3
If a vertex is defined more than once the later occurences are ignored.
Tip
Any vertex that starts with an underscore (_
) will be treated as an
invisible vertex, meaning it is not rendered but still offsets other
vertices. Useful for making subgraphs where you want the shaape to stay the
same but not contain all vertices. Unlike normal vertices, invisible
vertices names do not have to be unique.
An edge is a connection between two vertices. An edge is specified
by two vertices surrounded by parenthesis ()
and seperated by a comma ,
. If
the Directed flag is active the edge will point from the first vertex to
the second.
a,b,c
(a,b), (b,c) // An edge from a to b, and one from b to c
Several edges in sequence can be specified as a path, which is represented as
multiple vertices seperated by a connector -
.
a,b,c,d,e,f
(a,b),(b,c),(c,d),(d,e),(e,f) // Long and tedious definition of every edge
a-b-c-d-e-f // Shorter path definition
Paths are also an easy way to define cycles:
a,b,c
a-b-c-a // A cycle from a to a
Edges can also be represented as an adjacency matrix, the syntax is shown below. Adjacency matrices can be flipped with the Flipped flag.
a,b,c
0 1 0 // Spaces are optional for single digits
1 0 0
0 0 2
Note
An adjacency matrix cannot be combined with other ways of defining edges and will give an error.
Any text after //
will be treated as a comment and ignored when parsing a
code block.
The appearance of Kale code blocks can be customized in the plugin's settings.