Skip to content

Context Diagram extension for capellambse🔗

This is a pluggable extension for py-capellambse that extends the AbstractDiagram base class with ContextDiagrams that are layouted by elkjs' Layered algorithm.

Context diagram of Left

Generate Context Diagrams from your model data!

Interface context diagram of Interface

Features🔗

Functions & Components🔗

The data is collected by either

Available via .context_diagram on a ModelObject with (diagram-class):

  • oa.Entity (OAB)

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    diag = model.by_uuid("e37510b9-3166-4f80-a919-dfaac9b696c7").context_diagram
    diag.render("svgdiagram").save(pretty=True)
    
    Context diagram of Environment Entity with type [OAB]

  • oa.OperationalActivity (OAIB)

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    diag = model.by_uuid("8bcb11e6-443b-4b92-bec2-ff1d87a224e7").context_diagram
    diag.render("svgdiagram").save(pretty=True)
    
    Context diagram of Activity Eat with type [OAIB]

  • oa.OperationalCapability (OCB)

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    diag = model.by_uuid("da08ddb6-92ba-4c3b-956a-017424dbfe85").context_diagram
    diag.render("svgdiagram").save(pretty=True)
    
    Context diagram of Middle OperationalCapability with type [OCB]

  • ctx.Mission (MCB)

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    diag = model.by_uuid("5bf3f1e3-0f5e-4fec-81d5-c113d3a1b3a6").context_diagram
    diag.render("svgdiagram").save(pretty=True)
    
    Context diagram of Mission Top secret with type [MCB]

  • ctx.Capability (MCB)

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    diag = model.by_uuid("9390b7d5-598a-42db-bef8-23677e45ba06").context_diagram
    diag.render("svgdiagram").save(pretty=True)
    
    Context diagram of Capability Capability with type [MCB]

  • ctx.SystemComponent (SAB)

  • ctx.SystemFunction (SDFB)

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    diag = model.by_uuid("a5642060-c9cc-4d49-af09-defaa3024bae").context_diagram
    diag.render("svgdiagram").save(pretty=True)
    
    Context diagram of Lost SystemFunction with type [SDFB]

  • la.LogicalComponent (LAB)

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    diag = model.by_uuid("f632888e-51bc-4c9f-8e81-73e9404de784").context_diagram
    diag.render("svgdiagram").save(pretty=True)
    
    Context diagram of Left LogicalComponent with type [LAB]

  • la.LogicalFunction (LDFB)

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    diag = model.by_uuid("957c5799-1d4a-4ac0-b5de-33a65bf1519c").context_diagram
    diag.render("svgdiagram").save(pretty=True)
    
    Context diagram of educate Wizards LogicalFunction with type [LDFB]

  • pa.PhysicalComponent (PAB)

    PhysicalNodeComponent

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    diag = model.by_uuid("fdb34c92-7c49-491d-bf11-dd139930786e").context_diagram
    diag.render("svgdiagram").save(pretty=True)
    
    ContextDiagram of Physical Component [PAB]

    PhysicalBehaviourComponent

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    diag = model.by_uuid("313f48f4-fb7e-47a8-b28a-76440932fcb9").context_diagram
    diag.render("svgdiagram").save(pretty=True)
    
    Context diagram of PC Software [PAB]

  • pa.PhysicalFunction (PDFB)

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    diag = model.by_uuid("ee745644-07d7-40b9-ad7a-910dc8cbb805").context_diagram
    diag.render("svgdiagram").save(pretty=True)
    
    ContextDiagram of Maintain Switch Firmware [PDFB]

  • pa.PhysicalPort (PAB)

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    diag = model.by_uuid("c403d4f4-9633-42a2-a5d6-9e1df2655146").context_diagram
    diag.render("svgdiagram").save(pretty=True)
    
    PhysicalPortContextDiagram of PP 1 [PAB]

FunctionalChains🔗

The context_diagram attribute is also available to FunctionalChains and OperationalProcesses:

fa.FunctionalChain

import capellambse

model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
diag = model.by_uuid("ec1ecf8b-d58b-4468-9742-6fdfd6cff702").context_diagram
diag.render("svgdiagram").save(pretty=True)
FunctionalChainContextDiagram of Context [LAB]

and with the following rendering parameters:

  • display_parent_relation=False

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    diag = model.by_uuid("ec1ecf8b-d58b-4468-9742-6fdfd6cff702").context_diagram
    diag.render("svgdiagram", display_parent_relation=False).save(pretty=True)
    
    FunctionalChainContextDiagram of Context without Component Allocation [LAB]

OperationalProcess🔗

oa.OperationalProcess

import capellambse

model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
diag = model.by_uuid("bec38a21-cc4b-4c06-8acf-067bd5f44824").context_diagram
diag.render("svgdiagram").save(pretty=True)
FunctionalChainContextDiagram of OAContext [LAB]

Hierarchy in diagrams🔗

Hierarchical diagrams are diagrams where boxes have child boxes and edges contained. These form subdiagrams which can be layouted via ELK again. Hierarchy is identified and supported:

Hierarchical diagram

import capellambse

model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
obj = model.by_uuid("16b4fcc5-548d-4721-b62a-d3d5b1c1d2eb")
diagram = obj.context_diagram.render("svgdiagram", display_parent_relation=True)
diagram.save(pretty=True)
Context diagram of Hierarchy LogicalComponenet with type [LAB]

Customized edge routing🔗

Custom routing

The routing differs from ELK's Layered Algorithm: The flow display is disrupted! We configure exchanges such that they appear in between the context participants. This decision breaks the display of data flow which is one of the main aims of ELK's Layered algorithm. However this lets counter flow exchanges routes lengths and bendpoints increase.

Context diagram of Weird guy SystemFunction

View modes🔗

Whitebox🔗

There are different view modes for context diagrams. WHITEBOX is enabled per default.

WHITEBOX view mode

import capellambse

model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
obj = model.by_uuid("309296b1-cf37-45d7-b0f3-f7bc00422a59")
diagram = obj.context_diagram.render("svgdiagram", mode="WHITEBOX")
diagram.save(pretty=True)
Context diagram of Box PhysicalComponent with WHITEBOX mode

Additional render parameters for WHITEBOX mode are offered via:

  • include_external_context=True

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    obj = model.by_uuid("309296b1-cf37-45d7-b0f3-f7bc00422a59")
    diagram = obj.context_diagram.render(
      "svgdiagram", mode="WHITEBOX", include_external_context=True,
    )
    diagram.save(pretty=True)
    
    Context diagram of Box PhysicalComponent with WHITEBOX mode and External Context display

Greybox🔗

The GREYBOX view mode provides a hybrid approach between WHITEBOX and BLACKBOX modes. It collects the target context and its children's context, but limits parent relationship resolution to the first level only. This provides more detail than BLACKBOX while maintaining better performance than full WHITEBOX mode for complex hierarchies.

GREYBOX view mode

import capellambse

model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
obj = model.by_uuid("309296b1-cf37-45d7-b0f3-f7bc00422a59")
diagram = obj.context_diagram.render("svgdiagram", mode="GREYBOX")
diagram.save(pretty=True)
Context diagram of Box PhysicalComponent with GREYBOX mode

Additional render parameters for GREYBOX mode are offered via:

  • restrict_external_depth=False

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    obj = model.by_uuid("309296b1-cf37-45d7-b0f3-f7bc00422a59")
    diagram = obj.context_diagram.render(
        "svgdiagram",
        mode="GREYBOX",
        restrict_external_depth=False,
    )
    diagram.save(pretty=True)
    
    Context diagram of Box PhysicalComponent with GREYBOX mode and restrict external depth display

Blackbox🔗

This render parameter conceals internal details to provide a streamlined black box representation of the system of interest.

BLACKBOX view mode

import capellambse

model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
obj = model.by_uuid("309296b1-cf37-45d7-b0f3-f7bc00422a59")
diagram = obj.context_diagram.render("svgdiagram", mode="BLACKBOX")
diagram.save(pretty=True)
Context diagram of Box PhysicalComponent with BLACKBOX mode

Additional render parameters for hiding internal relations (dashed) or even cyclic internal relations are offered via:

  • display_internal_relations=False

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    obj = model.by_uuid("309296b1-cf37-45d7-b0f3-f7bc00422a59")
    diagram = obj.context_diagram.render(
      "svgdiagram", mode="BLACKBOX", display_internal_relations=False
    )
    diagram.save(pretty=True)
    
    Context diagram of Box PhysicalComponent with BLACKBOX mode

  • display_cyclic_relations=True

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    obj = model.by_uuid("309296b1-cf37-45d7-b0f3-f7bc00422a59")
    diagram = obj.context_diagram.render(
        "svgdiagram",
        mode="BLACKBOX",
        display_internal_relations=True, # per default
        display_cyclic_relations=True,
    )
    diagram.save(pretty=True)
    
    Context diagram of Box PhysicalComponent with BLACKBOX mode and Cycle display

  • include_external_context=True

    import capellambse
    
    model = capellambse.MelodyModel("tests/data/ContextDiagram.aird")
    obj = model.by_uuid("309296b1-cf37-45d7-b0f3-f7bc00422a59")
    diagram = obj.context_diagram.render(
        "svgdiagram",
        mode="BLACKBOX",
        display_internal_relations=True, # per default
        include_external_context=True,
    )
    diagram.save(pretty=True)
    
    Context diagram of Box PhysicalComponent with BLACKBOX mode and External Context display


See the code reference section for understanding the underlying implementation.