-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into remove-unstyled-ports
- Loading branch information
Showing
15 changed files
with
611 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# SPDX-FileCopyrightText: 2022 Copyright DB Netz AG and the capellambse-context-diagrams contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
"""This submodule defines the collector for the Class-Tree diagram.""" | ||
from __future__ import annotations | ||
|
||
import collections.abc as cabc | ||
import typing as t | ||
|
||
from capellambse import helpers | ||
from capellambse.model.crosslayer import information | ||
|
||
from .. import _elkjs, context | ||
from . import generic, makers | ||
|
||
|
||
def collector( | ||
diagram: context.ContextDiagram, params: dict[str, t.Any] | ||
) -> _elkjs.ELKInputData: | ||
"""Return the class tree data for ELK.""" | ||
assert isinstance(diagram.target, information.Class) | ||
data = generic.collector(diagram, no_symbol=True) | ||
if params.get("partitioning", False): | ||
data["layoutOptions"]["partitioning.activate"] = True | ||
data["children"][0]["layoutOptions"] = {} | ||
data["children"][0]["layoutOptions"]["elk.partitioning.partition"] = 0 | ||
|
||
data["layoutOptions"]["edgeLabels.sideSelection"] = params.get( | ||
"edgeLabelsSide", "ALWAYS_DOWN" | ||
) | ||
data["layoutOptions"]["algorithm"] = params.get("algorithm", "layered") | ||
data["layoutOptions"]["elk.direction"] = params.get("direction", "DOWN") | ||
data["layoutOptions"]["edgeRouting"] = params.get( | ||
"edgeRouting", "ORTHOGONAL" | ||
) | ||
|
||
made_boxes: set[str] = set() | ||
for _, (source, prop, target, partition) in get_all_classes( | ||
diagram.target | ||
): | ||
if target.uuid not in made_boxes: | ||
made_boxes.add(target.uuid) | ||
box = makers.make_box(target) | ||
if params.get("partitioning", False): | ||
box["layoutOptions"] = {} | ||
box["layoutOptions"]["elk.partitioning.partition"] = int( | ||
partition | ||
) | ||
data["children"].append(box) | ||
|
||
width, height = helpers.extent_func(prop.name) | ||
label: _elkjs.ELKInputLabel = { | ||
"text": prop.name, | ||
"width": width + 2 * makers.LABEL_HPAD, | ||
"height": height + 2 * makers.LABEL_VPAD, | ||
} | ||
data["edges"].append( | ||
{ | ||
"id": prop.uuid, | ||
"sources": [source.uuid], | ||
"targets": [target.uuid], | ||
"labels": [label], | ||
} | ||
) | ||
return data | ||
|
||
|
||
ClassContext = tuple[ | ||
information.Class, information.Property, information.Class, int | ||
] | ||
|
||
|
||
def get_all_classes( | ||
root: information.Class, partition: int = 0 | ||
) -> cabc.Iterator[tuple[str, ClassContext]]: | ||
"""Yield all classes of the class tree.""" | ||
partition += 1 | ||
classes: dict[str, ClassContext] = {} | ||
for prop in root.properties: | ||
if prop.type.xtype.endswith("Class"): | ||
edge_id = f"{root.uuid} {prop.uuid} {prop.type.uuid}" | ||
if edge_id not in classes: | ||
classes[edge_id] = (root, prop, prop.type, partition) | ||
classes.update(dict(get_all_classes(prop.type, partition))) | ||
|
||
yield from classes.items() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<!-- | ||
~ SPDX-FileCopyrightText: 2022 Copyright DB Netz AG and the capellambse-context-diagrams contributors | ||
~ SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
# Class Tree Diagram | ||
|
||
With release [`v0.5.35`](https://github.com/DSD-DBS/py-capellambse/releases/tag/v0.5.35) of [py-capellambse](https://github.com/DSD-DBS/py-capellambse) you can access the | ||
`.tree_diagram` on [`Class`][capellambse.model.crosslayer.information.Class] | ||
objects. A class tree diagram shows a tree made from all properties of the | ||
parent class. | ||
|
||
??? example "Class Tree of Root" | ||
|
||
``` py | ||
import capellambse | ||
|
||
model = capellambse.MelodyModel("tests/data/ContextDiagram.aird") | ||
diag = model.by_uuid("b7c7f442-377f-492c-90bf-331e66988bda").tree_diagram | ||
diag.render("svgdiagram").save_drawing(pretty=True) | ||
``` | ||
<figure markdown> | ||
<img src="../assets/images/Class Tree of Root.svg"> | ||
<figcaption>[CDB] Class Tree Diagram of Root</figcaption> | ||
</figure> | ||
|
||
Additional rendering parameters enable the control over the layout computed by | ||
ELK. The available options are: | ||
|
||
1. edgeRouting - Controls the style of the edges. | ||
- POLYLINE (default) | ||
- ORTHOGONAL | ||
- SPLINE | ||
2. algorithm - Controls the algorithm for the diagram layout. | ||
- layered (default) | ||
- mr.tree | ||
- ... Have a look for [all available ELK algorithms](https://eclipse.dev/elk/reference/algorithms.html). | ||
3. direction - The flow direction for the ELK Layered algortihm. | ||
- DOWN (DEFAULT) | ||
- UP | ||
- RIGHT | ||
- LEFT | ||
4. partitioning - Enable partitioning. Each recursion level for collecting the | ||
classes is its own partition. | ||
- True (default) | ||
- False | ||
5. edgeLabelSide - Controls edge label placement. | ||
- SMART_DOWN (default) | ||
- SMART_UP | ||
- ALWAYS_UP | ||
- ALWAYS_DOWN | ||
- DIRECTION_UP | ||
- DIRECTION_DOWN | ||
|
||
Here is an example that shows how convenient these parameters can be passed | ||
before rendering: | ||
|
||
??? example "Class Tree of Root" | ||
|
||
``` py | ||
import capellambse | ||
|
||
model = capellambse.MelodyModel("tests/data/ContextDiagram.aird") | ||
diag = model.by_uuid("b7c7f442-377f-492c-90bf-331e66988bda").tree_diagram | ||
diag.render( | ||
"svgdiagram", | ||
edgeRouting="ORTHOGONAL", | ||
direction="Right", | ||
# partitioning=False, | ||
# edgeLabelsSide="ALWAYS_DOWN", | ||
).save_drawing(pretty=True) | ||
``` | ||
<figure markdown> | ||
<img src="../assets/images/Class Tree of Root-params.svg"> | ||
<figcaption>[CDB] Class Tree Diagram of Root</figcaption> | ||
</figure> | ||
|
||
They are optional and don't need to be set all together. | ||
|
||
## Check out the code | ||
|
||
To understand the collection have a look into the | ||
[`class_tree`][capellambse_context_diagrams.collectors.class_tree] module. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.