Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tree-view): Add handling of properties w/o Associations #140

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions capellambse_context_diagrams/collectors/tree_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from __future__ import annotations

import collections
import collections.abc as cabc
import copy
import dataclasses
Expand Down Expand Up @@ -38,7 +39,7 @@ def __init__(self, data: _elkjs.ELKInputData) -> None:
self.data_types: set[str] = set()
self.legend_boxes: list[_elkjs.ELKInputChild] = []

self._edge_count: dict[str, int] = {}
self._edge_count: dict[str, int] = collections.defaultdict(int)

def __contains__(self, uuid: str) -> bool:
objects = self.data.children + self.data.edges # type: ignore[operator]
Expand All @@ -51,24 +52,21 @@ def process_class(self, cls: ClassInfo, params: dict[str, t.Any]):
assert cls.prop is not None
self._process_box(cls.target, cls.partition, params)

aggregation_kind_excludes = {
None,
modeltypes.AggregationKind.UNSET,
}
if cls.prop.association is not None:
edge_id = cls.prop.association.uuid
else:
logger.warning(
"No Association found for %s set on 'navigable_members'",
cls.prop._short_repr_(),
)
if cls.prop.kind not in aggregation_kind_excludes:
if cls.prop.kind != modeltypes.AggregationKind.UNSET:
styleclass = cls.prop.kind.name.capitalize()
else:
styleclass = "Association"

i = self._edge_count.setdefault(cls.prop.uuid, 0)
i += 1
self._edge_count.setdefault(cls.prop.uuid, 0)
self._edge_count[cls.prop.uuid] += 1
Comment on lines +67 to +68
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The beauty of a defaultdict is that you don't need the explicit setdefault call anymore. 🙃 But having it this way doesn't exactly hurt either.

i = self._edge_count[cls.prop.uuid]
edge_id = f"__{styleclass}:{cls.prop.uuid}-{i}"

if edge_id not in self.made_edges:
Expand Down
Loading