Skip to content

Commit

Permalink
fix: Fix minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenngn committed Aug 21, 2024
1 parent c13f8f7 commit 9692703
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions capellambse_context_diagrams/collectors/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ def process_context(self):
self.centerbox.height, *stack_heights.values()
)

def _process_port_spread(self, exs, attr, port_spread, owners) -> None:
def _process_port_spread(
self,
exs: list[fa.AbstractExchange],
attr: str,
inc: int,
port_spread: dict[str, int],
owners: dict[str, str],
) -> None:
for ex in exs:
elem = getattr(ex, attr).owner
if (owner := owners.get(elem.uuid)) is None:
Expand All @@ -121,9 +128,10 @@ def _process_port_spread(self, exs, attr, port_spread, owners) -> None:
][-1]
except (IndexError, AttributeError):
owner = elem.uuid
assert owner is not None
owners[elem.uuid] = owner
port_spread.setdefault(owner, 0)
port_spread[owner] += 1
port_spread[owner] += inc

def _process_exchanges(self) -> tuple[
list[common.GenericElement],
Expand All @@ -136,8 +144,12 @@ def _process_exchanges(self) -> tuple[
out_exchanges = list(chain.from_iterable(out_c.values()))
port_spread: dict[str, int] = {}
owners: dict[str, str] = {}
self._process_port_spread(inc_exchanges, "source", port_spread, owners)
self._process_port_spread(out_exchanges, "target", port_spread, owners)
self._process_port_spread(
inc_exchanges, "source", 1, port_spread, owners
)
self._process_port_spread(
out_exchanges, "target", -1, port_spread, owners
)
self.exchanges = inc_exchanges + out_exchanges
ex_datas: list[generic.ExchangeData] = []
for ex in self.exchanges:
Expand All @@ -161,14 +173,14 @@ def _process_exchanges(self) -> tuple[
is_hierarchical,
)
src, tgt = generic.exchange_data_collector(ex_data)
src_owner = owners.get(src.owner.uuid, "-1")
tgt_owner = owners.get(tgt.owner.uuid, "-1")
if (
(src.parent == self.diagram.target)
and (port_spread.get(tgt_owner, 0) > 0)
) or (
(tgt.parent == self.diagram.target)
and (port_spread.get(src_owner, 0) <= 0)
src_owner = owners.get(src.owner.uuid, "")
tgt_owner = owners.get(tgt.owner.uuid, "")
is_inc = tgt.parent == self.diagram.target
is_out = src.parent == self.diagram.target
if is_inc and is_out:
pass
elif (is_out and (port_spread.get(tgt_owner, 0) > 0)) or (
is_inc and (port_spread.get(src_owner, 0) <= 0)
):
elkdata.edges[-1].sources = [tgt.uuid]
elkdata.edges[-1].targets = [src.uuid]
Expand Down

0 comments on commit 9692703

Please sign in to comment.