Skip to content

Commit

Permalink
fix: filters and docs
Browse files Browse the repository at this point in the history
Merge pull request #133 from DSD-DBS/fix-filters-and-docs
  • Loading branch information
ewuerger authored Aug 23, 2024
2 parents 7c1a30d + b9af83a commit d130d6b
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 51 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Example:
>
> Documentation can look like this `docs/index.md`:
> ```markdown
> - ??? example "[`ctx.Mission`][capellambse.model.layers.ctx.Mission] (MCB)"
> - ??? example "[`ctx.Mission`][capellambse.metamodel.sa.Mission] (MCB)"
>
> ``` py
> import capellambse
Expand Down
3 changes: 1 addition & 2 deletions capellambse_context_diagrams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
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 _elkjs, context, styling

Expand Down Expand Up @@ -144,7 +143,7 @@ def patch_styles(classes: cabc.Iterable[SupportedClass]) -> None:
See Also
--------
[capstyle.get_style][capellambse.aird.capstyle.get_style] : Default
[capstyle.get_style][capellambse.diagram.get_style] : Default
style getter.
"""
cap: dict[str, CSSdef] = {
Expand Down
2 changes: 1 addition & 1 deletion capellambse_context_diagrams/_elkjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def call_elkjs(elk_model: ELKInputData) -> ELKOutputData:
Parameters
----------
elk_dict
elk_model
The diagram data, sans layouting information
Returns
Expand Down
4 changes: 2 additions & 2 deletions capellambse_context_diagrams/collectors/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ def collect_label(obj: common.GenericElement) -> str | None:
"""Return the label of a given object.
The label usually comes from the `.name` attribute. Special handling
for [`interaction.AbstractCapabilityExtend`][capellambse.model.crosslayer.interaction.AbstractCapabilityExtend]
and [interaction.AbstractCapabilityInclude`][capellambse.model.crosslayer.interaction.AbstractCapabilityInclude].
for [`interaction.AbstractCapabilityExtend`][capellambse.metamodel.interaction.AbstractCapabilityExtend]
and [interaction.AbstractCapabilityInclude`][capellambse.metamodel.interaction.AbstractCapabilityInclude].
"""
if isinstance(obj, interaction.AbstractCapabilityExtend):
return "« e »"
Expand Down
16 changes: 13 additions & 3 deletions capellambse_context_diagrams/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
"""
Definitions of Custom Accessor- and Diagram-Classtypes based on
[`Accessor`][capellambse.model.common.accessors.Accessor] and [`AbstractDiagram`][capellambse.model.diagram.AbstractDiagram].
[`Accessor`][capellambse.model.Accessor] and [`AbstractDiagram`][capellambse.model.diagram.AbstractDiagram].
"""
from __future__ import annotations

Expand Down Expand Up @@ -731,7 +731,7 @@ def calculate_label_position(
y: float,
width: float,
height: float,
padding: float = 10,
padding: float = 10.0,
) -> tuple[float, float, float]:
"""Calculate the position of the label and tspan.
Expand All @@ -743,10 +743,20 @@ def calculate_label_position(
Parameters
----------
x
The x coordinate of the label position.
y
The y coordinate of the label position.
width
Width of the label.
height
Height of the label
padding
The padding for the label.
Returns
-------
tuple
position
A tuple containing the x- and y-coordinate for the text element
and the adjusted y-coordinate for the tspan element.
"""
Expand Down
10 changes: 4 additions & 6 deletions capellambse_context_diagrams/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@
"""Show the name of `ComponentExchange` or `FunctionalExchange` and its
`ExchangeItems` wrapped in [E1,...] and separated by ',' - filter in Capella.
"""
FEX_EX_ITEMS = SHOW_EX_ITEMS # legacy name
EX_ITEMS = "show.exchange.items.filter"
"""Show `ExchangeItems` wrapped in [E1,...] and separated by ',' - filter
in Capella.
"""
EXCH_OR_EX_ITEMS = (
EX_ITEMS_OR_EXCH = (
"capellambse_context_diagrams-show.exchanges.or.exchange.items.filter"
)
"""Show either the name of the `ComponentExchange` or `FunctionalExchange`, or
its `ExchangeItems` wrapped in [E1,...] and separated by ',' - Custom filter,
"""Show the names of `ExchangeItem`s wrapped in [E1,...] and separated by ','
- Custom filter or the name of the `ComponentExchange` or `FunctionalExchange`,
not available in Capella.
"""
FEX_OR_EX_ITEMS = EXCH_OR_EX_ITEMS # legacy name
NO_UUID = "capellambse_context_diagrams-hide.uuids.filter"
"""Filter out UUIDs from label text."""
SYSTEM_EX_RELABEL = (
Expand Down Expand Up @@ -96,7 +94,7 @@ def relabel_system_exchange(
] = {
EX_ITEMS: lambda obj, _: exchange_items(obj),
SHOW_EX_ITEMS: exchange_name_and_items,
EXCH_OR_EX_ITEMS: lambda obj, label: (
EX_ITEMS_OR_EXCH: lambda obj, label: (
exchange_items(obj)
if getattr(obj, "exchange_items", "")
else label or obj.name
Expand Down
3 changes: 1 addition & 2 deletions capellambse_context_diagrams/styling.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
A dictionary with CSS styles. The keys are the attribute names and the
values can be of the types `str`, `aird.RGB` and even
`t.Sequence[aird.RGB]` for coloring a
[`common.GenericElement`][capellambse.model.common.element.GenericElement]
with a gradient.
[`ModelElement`][capellambse.model.ModelElement] with a gradient.
See also
--------
Expand Down
20 changes: 10 additions & 10 deletions docs/extras/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ adjusted without needing diagram elements from within the .aird file.

Currently the supported filters are:

??? success "Show [`ExchangeItem`][capellambse.model.crosslayer.information.ExchangeItem]s"
??? success "Show [`ExchangeItem`][capellambse.metamodel.information.ExchangeItem]s"

```py
from capellambse import MelodyModel
Expand All @@ -33,40 +33,40 @@ Currently the supported filters are:
<figcaption>Context diagram of Lost SystemFunction with applied filter [`EX_ITEMS_FILTER`][capellambse_context_diagrams.filters.EX_ITEMS]</figcaption>
</figure>

??? success "Show [`FunctionalExchange`][capellambse.model.crosslayer.fa.FunctionalExchange]s and [`ExchangeItem`][capellambse.model.crosslayer.information.ExchangeItem]s"
??? success "Show [`FunctionalExchange`][capellambse.metamodel.fa.FunctionalExchange]s and [`ExchangeItem`][capellambse.metamodel.information.ExchangeItem]s"

```py
from capellambse import MelodyModel
from capellambse_context_diagrams import filters

lost = model.by_uuid("a5642060-c9cc-4d49-af09-defaa3024bae")
diag = obj.context_diagram
assert filters.FEX_EX_ITEMS == "show.functional.exchanges.exchange.items.filter"
filters.filters = {filters.FEX_EX_ITEMS}
assert filters.SHOW_EX_ITEMS == "show.functional.exchanges.exchange.items.filter"
diag.filters = {filters.SHOW_EX_ITEMS}
diag.render("svgdiagram").save(pretty=True)
```
<figure markdown>
<img src="../../assets/images/Context of Lost fex and ex.svg" width="1000000">
<figcaption>Context diagram of Lost SystemFunction with applied filter [`FEX_EX_ITEMS_FILTER`][capellambse_context_diagrams.filters.FEX_EX_ITEMS]</figcaption>
<figcaption>Context diagram of Lost SystemFunction with applied filter [`SHOW_EX_ITEMS`][capellambse_context_diagrams.filters.SHOW_EX_ITEMS]</figcaption>
</figure>

## Custom filters

??? tip "Custom Filter - Show [`FunctionalExchange`][capellambse.model.crosslayer.fa.FunctionalExchange]s **or** [`ExchangeItem`][capellambse.model.crosslayer.information.ExchangeItem]s"
??? tip "Custom Filter - Show [`FunctionalExchange`][capellambse.metamodel.fa.FunctionalExchange]s **or** [`ExchangeItem`][capellambse.metamodel.information.ExchangeItem]s"

```py
from capellambse import MelodyModel
from capellambse_context_diagrams import filters

lost = model.by_uuid("a5642060-c9cc-4d49-af09-defaa3024bae")
diag = obj.context_diagram
assert filters.FEX_OR_EX_ITEMS == "capellambse_context_diagrams-show.functional.exchanges.or.exchange.items.filter"
filters.filters.add(filters.FEX_OR_EX_ITEMS)
assert filters.EX_ITEMS_OR_EXCH == "capellambse_context_diagrams-show.functional.exchanges.or.exchange.items.filter"
diag.filters.add(filters.EX_ITEMS_OR_EXCH)
diag.render("svgdiagram").save(pretty=True)
```
<figure markdown>
<img src="../../assets/images/Context of Lost fex or ex.svg" width="1000000">
<figcaption>Context diagram of Lost SystemFunction with applied filter [`FEX_OR_EX_ITEMS_FILTER`][capellambse_context_diagrams.filters.FEX_OR_EX_ITEMS]</figcaption>
<img src="../../assets/images/Context of Lost ex or fex.svg" width="1000000">
<figcaption>Context diagram of Lost SystemFunction with applied filter [`EX_ITEMS_OR_EXCH`][capellambse_context_diagrams.filters.EX_ITEMS_OR_EXCH]</figcaption>
</figure>

Make sure to check out our [**Stylings**][capellambse_context_diagrams.styling] feature as well.
2 changes: 1 addition & 1 deletion docs/gen_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def generate_interface_with_hide_interface_image():
lost_uuid = general_context_diagram_uuids["Lost"]
generate_filter_image(lost_uuid, filters.EX_ITEMS, "ex")
generate_filter_image(lost_uuid, filters.SHOW_EX_ITEMS, "fex and ex")
generate_filter_image(lost_uuid, filters.EXCH_OR_EX_ITEMS, "fex or ex")
generate_filter_image(lost_uuid, filters.EX_ITEMS_OR_EXCH, "ex or fex")

generate_styling_image(
lost_uuid,
Expand Down
26 changes: 13 additions & 13 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ Generate **Context Diagrams** from your model data!

The data is collected by either

- [portless_collector][capellambse_context_diagrams.collectors.portless.collector] for [`ModelObject`s][capellambse.model.common.element.ModelObject] from the Operational Architecture Layer
- [portless_collector][capellambse_context_diagrams.collectors.portless.collector] for [`ModelObject`s][capellambse.model.ModelObject] from the Operational Architecture Layer
- [with_port_collector][capellambse_context_diagrams.collectors.default.collector] for all other Architecture Layers that use ports as connectors of exchanges.

It is served conveniently by [get_elkdata][capellambse_context_diagrams.collectors.get_elkdata].

Available via `.context_diagram` on a [`ModelObject`][capellambse.model.common.element.ModelObject] with (diagram-class):
Available via `.context_diagram` on a [`ModelObject`][capellambse.model.ModelObject] with (diagram-class):

- ??? example "[`oa.Entity`][capellambse.model.layers.oa.Entity] (OAB)"
- ??? example "[`oa.Entity`][capellambse.metamodel.oa.Entity] (OAB)"

``` py
import capellambse
Expand All @@ -48,7 +48,7 @@ Available via `.context_diagram` on a [`ModelObject`][capellambse.model.common.e
<figcaption>Context diagram of Environment Entity with type [OAB]</figcaption>
</figure>

- ??? example "[`oa.OperationalActivity`][capellambse.model.layers.oa.OperationalActivity] (OAIB)"
- ??? example "[`oa.OperationalActivity`][capellambse.metamodel.oa.OperationalActivity] (OAIB)"

``` py
import capellambse
Expand All @@ -62,7 +62,7 @@ Available via `.context_diagram` on a [`ModelObject`][capellambse.model.common.e
<figcaption>Context diagram of Activity Eat with type [OAIB]</figcaption>
</figure>

- ??? example "[`oa.OperationalCapability`][capellambse.model.layers.oa.OperationalCapability] (OCB)"
- ??? example "[`oa.OperationalCapability`][capellambse.metamodel.oa.OperationalCapability] (OCB)"

``` py
import capellambse
Expand All @@ -76,7 +76,7 @@ Available via `.context_diagram` on a [`ModelObject`][capellambse.model.common.e
<figcaption>Context diagram of Middle OperationalCapability with type [OCB]</figcaption>
</figure>

- ??? example "[`ctx.Mission`][capellambse.model.layers.ctx.Mission] (MCB)"
- ??? example "[`ctx.Mission`][capellambse.metamodel.sa.Mission] (MCB)"

``` py
import capellambse
Expand All @@ -90,7 +90,7 @@ Available via `.context_diagram` on a [`ModelObject`][capellambse.model.common.e
<figcaption>Context diagram of Mission Top secret with type [MCB]</figcaption>
</figure>

- ??? example "[`ctx.Capability`][capellambse.model.layers.ctx.Capability] (MCB)"
- ??? example "[`ctx.Capability`][capellambse.metamodel.sa.Capability] (MCB)"

``` py
import capellambse
Expand All @@ -104,9 +104,9 @@ Available via `.context_diagram` on a [`ModelObject`][capellambse.model.common.e
<figcaption>Context diagram of Capability Capability with type [MCB]</figcaption>
</figure>

- [`ctx.SystemComponent`][capellambse.model.layers.ctx.SystemComponent] (SAB)
- [`ctx.SystemComponent`][capellambse.metamodel.sa.SystemComponent] (SAB)

- ??? example "[`ctx.SystemFunction`][capellambse.model.layers.ctx.SystemFunction] (SDFB)"
- ??? example "[`ctx.SystemFunction`][capellambse.metamodel.sa.SystemFunction] (SDFB)"

``` py
import capellambse
Expand All @@ -120,7 +120,7 @@ Available via `.context_diagram` on a [`ModelObject`][capellambse.model.common.e
<figcaption>Context diagram of Lost SystemFunction with type [SDFB]</figcaption>
</figure>

- ??? example "[`la.LogicalComponent`][capellambse.model.layers.la.LogicalComponent] (LAB)"
- ??? example "[`la.LogicalComponent`][capellambse.metamodel.la.LogicalComponent] (LAB)"

``` py
import capellambse
Expand All @@ -134,7 +134,7 @@ Available via `.context_diagram` on a [`ModelObject`][capellambse.model.common.e
<figcaption>Context diagram of Left LogicalComponent with type [LAB]</figcaption>
</figure>

- ??? example "[`la.LogicalFunction`][capellambse.model.layers.la.LogicalFunction] (LDFB)"
- ??? example "[`la.LogicalFunction`][capellambse.metamodel.la.LogicalFunction] (LDFB)"

``` py
import capellambse
Expand All @@ -148,7 +148,7 @@ Available via `.context_diagram` on a [`ModelObject`][capellambse.model.common.e
<figcaption>Context diagram of educate Wizards LogicalFunction with type [LDFB]</figcaption>
</figure>

- ??? example "[`pa.PhysicalComponent`][capellambse.model.layers.pa.PhysicalComponent] (PAB)"
- ??? example "[`pa.PhysicalComponent`][capellambse.metamodel.pa.PhysicalComponent] (PAB)"

`PhysicalNodeComponent`

Expand Down Expand Up @@ -178,7 +178,7 @@ Available via `.context_diagram` on a [`ModelObject`][capellambse.model.common.e
<figcaption>Context diagram of PC Software [PAB]</figcaption>
</figure>

- ??? example "[`pa.PhysicalFunction`][capellambse.model.layers.pa.PhysicalFunction] (PDFB)"
- ??? example "[`pa.PhysicalFunction`][capellambse.metamodel.pa.PhysicalFunction] (PDFB)"

``` py
import capellambse
Expand Down
2 changes: 1 addition & 1 deletion docs/interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
The data is collected by [get_elkdata_for_exchanges][capellambse_context_diagrams.collectors.exchanges.get_elkdata_for_exchanges] which is using the [`InterfaceContextCollector`][capellambse_context_diagrams.collectors.exchanges.InterfaceContextCollector] underneath.

You can render an interface context view just with `context_diagram` on any
[`fa.ComponentExchange`][capellambse.model.crosslayer.fa.ComponentExchange]:
[`fa.ComponentExchange`][capellambse.metamodel.fa.ComponentExchange]:

``` py
import capellambse
Expand Down
2 changes: 1 addition & 1 deletion docs/tree_view.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Tree View 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_view` on [`Class`][capellambse.model.crosslayer.information.Class]
`.tree_view` on [`Class`][capellambse.metamodel.information.Class]
objects. A tree view diagram shows a tree made from all properties of the
parent class.

Expand Down
16 changes: 9 additions & 7 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,19 @@ plugins:
paths: [capellambse_context_diagrams]
import:
- https://dsd-dbs.github.io/py-capellambse/objects.inv
selection:
enable_inventory: yes
options:
docstring_style: numpy
rendering:
show_root_full_path: no
docstring_section_style: spacy
show_docstring_attributes: true
merge_init_into_class: yes
show_submodules: no
show_signature_annotations: yes
show_root_full_path: no
group_by_category: true
separate_signature: yes
enable_inventory: yes
watch:
- capellambse_context_diagrams
line_length: 79
show_signature_annotations: yes
annotations_path: brief

nav:
- Home:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_context_diagrams_FEX_OR_EX_ITEMS_is_applied(
model: MelodyModel, uuid: str
) -> None:
edges, aird_diag = start_filter_apply_test(
model, uuid, filters.EXCH_OR_EX_ITEMS
model, uuid, filters.EX_ITEMS_OR_EXCH
)

for edge in edges:
Expand Down

0 comments on commit d130d6b

Please sign in to comment.