Examples

Examples are inspired by https://graphviz.org/gallery/.

Hello World

https://graphviz.org/Gallery/directed/hello.html

Model:

digraph G {
        hello -> world
}
hello_world.json
{
    "edges": [
        {"from": "hello", "to": "world"}
    ]
}

Command:

$ cat examples/hello_world.json | graphviz-overlay digraph > hello_world.dot

Generated source:

hello_world.dot
digraph G {
        hello -> world
}

Clusters

https://graphviz.org/Gallery/directed/cluster.html

Model:

digraph G {
        start [shape=Mdiamond]
        end [shape=Msquare]
        subgraph cluster_0 {
                graph [color=lightgrey label="process #1" style=filled]
                node [color=white style=filled]
                a0 -> a1
                a1 -> a2
                a2 -> a3
        }
        subgraph cluster_1 {
                graph [color=blue label="process #2" style=solid]
                node [style=filled]
                b0 -> b1
                b1 -> b2
                b2 -> b3
        }
        start -> a0
        start -> b0
        a1 -> b3
        b2 -> a3
        a3 -> a0
        a3 -> end
        b3 -> end
}
cluster.json
{
    "nodes": {
        "start": {
            "shape": "Mdiamond"
        },
        "end": {
            "shape": "Msquare"
        }
    },
    "edges": [
        {"from": "start", "to": "a0"},
        {"from": "start", "to": "b0"},
        {"from": "a1", "to": "b3"},
        {"from": "b2", "to": "a3"},
        {"from": "a3", "to": "a0"},
        {"from": "a3", "to": "end"},
        {"from": "b3", "to": "end"}
    ],
    "subgraphs": {
        "0": {
            "cluster": true,
            "style": ["filled"],
            "color": "lightgrey",
            "styles": {
                "node": {
                    "style": ["filled"],
                    "color": "white"
                }
            },
            "edges": [
                {"from": "a0", "to": "a1"},
                {"from": "a1", "to": "a2"},
                {"from": "a2", "to": "a3"}
            ],
            "label": "process #1"
        },
        "1": {
            "cluster": true,
            "styles": {
                "node": {
                    "style": ["filled"]
                }
            },
            "edges": [
                {"from": "b0", "to": "b1"},
                {"from": "b1", "to": "b2"},
                {"from": "b2", "to": "b3"}
            ],
            "label": "process #2",
            "color": "blue"
        }
    },
    "styles": {
        "diamond": {
            "shape": "Mdiamond"
        }
    }
}

Command:

$ cat examples/cluster.json | graphviz-overlay digraph > cluster.dot

Generated source:

cluster.dot
digraph G {
        start [shape=Mdiamond]
        end [shape=Msquare]
        subgraph cluster_0 {
                graph [color=lightgrey label="process #1" style=filled]
                node [color=white style=filled]
                a0 -> a1
                a1 -> a2
                a2 -> a3
        }
        subgraph cluster_1 {
                graph [color=blue label="process #2" style=solid]
                node [style=filled]
                b0 -> b1
                b1 -> b2
                b2 -> b3
        }
        start -> a0
        start -> b0
        a1 -> b3
        b2 -> a3
        a3 -> a0
        a3 -> end
        b3 -> end
}

Entity-Relation Data Model

https://graphviz.org/Gallery/undirected/ER.html

Model:

graph G {
        graph [layout=neato]
        course [shape=box]
        course_name [label=name]
        course_name -- course
        course_code [label=code]
        course_code -- course
        institute [shape=box]
        institute_name [label=name]
        institute_name -- institute
        student [shape=box]
        student_name [label=name]
        student_name -- student
        student_number [label=number]
        student_number -- student
        student_grade [label=grade]
        student_grade -- student
        course_institute [label="C-I" color=lightgrey shape=diamond style=filled]
        course -- course_institute [label=n]
        course_institute -- institute [label=1]
        student_course [label="S-C" color=lightgrey shape=diamond style=filled]
        student -- student_course [label=m]
        student_course -- course [label=n]
        student_institute [label="S-I" color=lightgrey shape=diamond style=filled]
        student -- student_institute [label=n]
        student_institute -- institute [label=1]
}
er.json
{
    "entities": {
        "course": {
            "name": "course",
            "attributes": {
                "name": {},
                "code": {}
            }
        },
        "institute": {
            "name": "institute",
            "attributes": {
                "name": {}
            }
        },
        "student": {
            "name": "student",
            "attributes": {
                "name": {},
                "number": {},
                "grade": {}
            }
        }
    },
    "relationships": [
        {
            "from": {
                "name": "course",
                "cardinality": "n"
            },
            "to": {
                "name": "institute",
                "cardinality": "1"
            }
        },
        {
            "to": {
                "name": "course",
                "cardinality": "n"
            },
            "from": {
                "name": "student",
                "cardinality": "m"
            }
        },
        {
            "to": {
                "name": "institute",
                "cardinality": "1"
            },
            "from": {
                "name": "student",
                "cardinality": "n"
            }
        }
    ],
    "layout": "neato"
}

Command:

$ cat examples/er.json | graphviz-overlay er > er.dot

Generated source:

er.dot
graph G {
        graph [layout=neato]
        course [shape=box]
        course_name [label=name]
        course_name -- course
        course_code [label=code]
        course_code -- course
        institute [shape=box]
        institute_name [label=name]
        institute_name -- institute
        student [shape=box]
        student_name [label=name]
        student_name -- student
        student_number [label=number]
        student_number -- student
        student_grade [label=grade]
        student_grade -- student
        course_institute [label="C-I" color=lightgrey shape=diamond style=filled]
        course -- course_institute [label=n]
        course_institute -- institute [label=1]
        student_course [label="S-C" color=lightgrey shape=diamond style=filled]
        student -- student_course [label=m]
        student_course -- course [label=n]
        student_institute [label="S-I" color=lightgrey shape=diamond style=filled]
        student -- student_institute [label=n]
        student_institute -- institute [label=1]
}