Skip to content

Commit

Permalink
feat!(context-diagram): Include owners
Browse files Browse the repository at this point in the history
Solves (#93)

---------

Co-authored-by: ewuerger <[email protected]>
  • Loading branch information
ewuerger committed May 15, 2024
1 parent 747d43a commit b8497ce
Show file tree
Hide file tree
Showing 25 changed files with 4,924 additions and 2,469 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
exclude: '^(versioneer\.py|.*/_version\.py)$'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -25,15 +25,15 @@ repos:
- id: fix-byte-order-marker
- id: trailing-whitespace
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.3.0
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
rev: v1.10.0
hooks:
- id: mypy
- repo: https://github.com/Lucas-C/pre-commit-hooks
Expand Down Expand Up @@ -67,6 +67,6 @@ repos:
- --comment-style
- "/*| *| */"
- repo: https://github.com/fsfe/reuse-tool
rev: v3.0.1
rev: v3.0.2
hooks:
- id: reuse
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ When the extension is installed you get additional method `.context_diagram` ava

### Interface context

![Interface context diagram of **Left to right**](https://raw.githubusercontent.com/DSD-DBS/capellambse-context-diagrams/main/docs/assets/images/Interface%20Context%20of%20Left%20to%20right.svg "Interface context diagram of **Left to right**")
![Interface context diagram of **Interface**](https://raw.githubusercontent.com/DSD-DBS/capellambse-context-diagrams/main/docs/assets/images/Interface%20Context%20of%20Interface.svg "Interface context diagram of **Interface**")

Have a look at our [documentation](https://dsd-dbs.github.io/capellambse-context-diagrams/) to get started and see the capabilities of this extension.

Expand Down
93 changes: 46 additions & 47 deletions capellambse_context_diagrams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
from capellambse.model.crosslayer import fa, information
from capellambse.model.layers import ctx, la, oa, pa
from capellambse.model.modeltypes import DiagramType
from capellambse.svg import decorations

from . import context, styling
from . import _elkjs, context, styling

try:
__version__ = metadata.version("capellambse-context-diagrams")
Expand All @@ -46,6 +47,18 @@
ATTR_NAME = "context_diagram"


def install_elk() -> None:
"""Install elk.js and its dependencies into the local cache directory.
When rendering a context diagram, elk.js will be installed
automatically into a persistent local cache directory. This function
may be called while building a container, starting a server or
similar tasks in order to prepare the elk.js execution environment
ahead of time.
"""
_elkjs._install_required_npm_pkg_versions()


def init() -> None:
"""Initialize the extension."""
register_classes()
Expand All @@ -60,7 +73,11 @@ def register_classes() -> None:
"""Add the `context_diagram` property to the relevant model objects."""
supported_classes: list[SupportedClass] = [
(oa.Entity, DiagramType.OAB, {}),
(oa.OperationalActivity, DiagramType.OAIB, {}),
(
oa.OperationalActivity,
DiagramType.OAB,
{"display_parent_relation": True},
),
(oa.OperationalCapability, DiagramType.OCB, {}),
(ctx.Mission, DiagramType.MCB, {}),
(ctx.Capability, DiagramType.MCB, {"display_symbols_as_boxes": False}),
Expand All @@ -69,33 +86,52 @@ def register_classes() -> None:
DiagramType.SAB,
{
"display_symbols_as_boxes": True,
"display_parent_relation": True,
"render_styles": styling.BLUE_ACTOR_FNCS,
},
),
(
ctx.SystemFunction,
DiagramType.SDFB,
{"render_styles": styling.BLUE_ACTOR_FNCS},
DiagramType.SAB,
{
"display_symbols_as_boxes": True,
"display_parent_relation": True,
"render_styles": styling.BLUE_ACTOR_FNCS,
},
),
(
la.LogicalComponent,
DiagramType.LAB,
{"render_styles": styling.BLUE_ACTOR_FNCS},
{
"display_symbols_as_boxes": True,
"display_parent_relation": True,
"render_styles": styling.BLUE_ACTOR_FNCS,
},
),
(
la.LogicalFunction,
DiagramType.LDFB,
{"render_styles": styling.BLUE_ACTOR_FNCS},
DiagramType.LAB,
{
"display_symbols_as_boxes": True,
"display_parent_relation": True,
"render_styles": styling.BLUE_ACTOR_FNCS,
},
),
(
pa.PhysicalComponent,
DiagramType.PAB,
{"render_styles": styling.BLUE_ACTOR_FNCS},
{
"display_parent_relation": True,
"render_styles": styling.BLUE_ACTOR_FNCS,
},
),
(
pa.PhysicalFunction,
DiagramType.PDFB,
{"render_styles": styling.BLUE_ACTOR_FNCS},
DiagramType.PAB,
{
"display_parent_relation": True,
"render_styles": styling.BLUE_ACTOR_FNCS,
},
),
]
patch_styles(supported_classes)
Expand Down Expand Up @@ -128,43 +164,6 @@ def patch_styles(classes: cabc.Iterable[SupportedClass]) -> None:
for _, dt, _ in classes:
capstyle.STYLES[dt.value]["Circle.FunctionalExchange"] = circle_style

for dt in (DiagramType.SAB, DiagramType.LAB, DiagramType.PAB):
text_fill = COLORS["black"]
if dt == DiagramType.SAB:
fill = [
COLORS["_CAP_Component_Blue_min"],
COLORS["_CAP_Component_Blue"],
]
stroke = COLORS["_CAP_Component_Border_Blue"]
elif dt == DiagramType.LAB:
fill = [
COLORS["_CAP_Component_Blue_min"],
COLORS["_CAP_Component_Blue"],
]
text_fill = COLORS["_CAP_Component_Label_Blue"]
elif dt == DiagramType.PAB:
fill = [
COLORS["_CAP_Unset_Gray_min"],
COLORS["_CAP_Unset_Gray"],
]
stroke = COLORS["_CAP_Lifeline_Gray"]

capstyle.STYLES[dt.value].update(
{
"Box.DerivedBox": {
"fill": fill,
"stroke": stroke,
"stroke-dasharray": "4",
"text_fill": text_fill,
},
"Edge.DerivedComponentExchange": {
"stroke": COLORS["_CAP_Component_Border_Blue"],
"stroke-width": 2,
"stroke-dasharray": "4",
},
}
)


def register_interface_context() -> None:
"""Add the `context_diagram` property to interface model objects."""
Expand Down
1 change: 1 addition & 0 deletions capellambse_context_diagrams/_elkjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"hierarchyHandling": "INCLUDE_CHILDREN",
"layered.edgeLabels.sideSelection": "ALWAYS_DOWN",
"layered.nodePlacement.strategy": "BRANDES_KOEPF",
"layered.considerModelOrder.strategy": "NODES_AND_EDGES",
"spacing.labelNode": "0.0",
}
"""
Expand Down
5 changes: 3 additions & 2 deletions capellambse_context_diagrams/collectors/dataflow_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import functools
import operator
import typing as t
from itertools import chain

from capellambse.model import modeltypes
from capellambse.model.crosslayer import fa
Expand Down Expand Up @@ -128,7 +129,7 @@ def collector_default(
connections = default.port_exchange_collector(_ports, filter=filter)
in_ports: dict[str, fa.FunctionPort] = {}
out_ports: dict[str, fa.FunctionPort] = {}
for edge in connections:
for edge in (edges := list(chain.from_iterable(connections.values()))):
if edge.source.owner == fnc:
out_ports.setdefault(edge.source.uuid, edge.source)
else:
Expand All @@ -142,7 +143,7 @@ def collector_default(
) * max(len(in_ports), len(out_ports))

ex_datas: list[generic.ExchangeData] = []
for ex in connections:
for ex in edges:
if ex.uuid in made_edges:
continue

Expand Down
Loading

0 comments on commit b8497ce

Please sign in to comment.