Search code examples
graphvizsoftware-design

V-model with graphviz


I want to draw a V-Modell for software development. I want to use graphviz to keep it more maintainable than in Visio.

How can I get the typical V-structure in Graphviz?

I think I need horizontal and vertical alignment. I tried to work with dummy-nodes but the layout is still poor.


Solution

  • This code works for me. It has a bit of a workaround in it to create the V shape. I use an invisible node and invisible edges to create a wedge between the 2 sides of the V-model.

    digraph Vmodel {
    // Transparent background
    graph [bgcolor=none]
    
    // Node style
    node [
        shape=record
        style="rounded, filled"
        width=2.5
        height=0.8
        fillcolor=white 
    ];
    
    // Create the nodes
    user_req_models     [label="User\nRequirements\nModels"]
    sys_req_models      [label="System\nRequirements\Models"]
    arch_models         [label="Architectural\Models"]
    comp_design_models  [label="Component\Design\Models"]
    unit_design_models  [label="Unit\nDesign\nModels"]
    units               [label="Units\n(SW, HW and Data)"]
    components          [label="Components\n(SW, HW and Data)"]
    subsystems          [label="Subsystems"]
    integrated_system   [label="Integrated System"]
    operational_system  [label="Operational System"]
    
    // Create a hidden node to form a V-shaped wedge
    hidden              [style="invis"]
    
    // Create the basic layout of the V model
    user_req_models->sys_req_models
    sys_req_models->arch_models
    arch_models->comp_design_models
    comp_design_models->unit_design_models
    unit_design_models->units
    units->components
    components->subsystems
    subsystems->integrated_system
    integrated_system->operational_system
    
    // Create the dashed edges
    user_req_models->operational_system [style="dashed", constraint=false]
    sys_req_models->integrated_system   [style="dashed", constraint=false]
    arch_models->subsystems             [style="dashed", constraint=false]
    comp_design_models->components      [style="dashed", constraint=false]
    
    // Create a wedge between the two parts
    hidden->user_req_models         [style="invis"]
    hidden->sys_req_models          [style="invis"]
    hidden->arch_models             [style="invis"]
    hidden->comp_design_models      [style="invis"]
    hidden->operational_system      [style="invis"]
    hidden->integrated_system       [style="invis"]
    hidden->subsystems              [style="invis"]
    hidden->components              [style="invis"]
    hidden->unit_design_models      [style="invis"]
    hidden->units                   [style="invis"]
    
    // Ranking on the same level
    {rank=same; user_req_models, operational_system}
    {rank=same; sys_req_models, integrated_system}
    {rank=same; arch_models, subsystems}
    {rank=same; comp_design_models, components}
    {rank=same; unit_design_models, units}
    }