Skip to content

Commit fdb7c35

Browse files
ilaifMidnighter
andcommitted
feat: add nearest neighbours method
Co-authored-by: Midnighter <[email protected]>
1 parent 24c6762 commit fdb7c35

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/structurizr/view/static_view.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
from abc import ABC, abstractmethod
2020
from typing import Iterable, List, Optional, Union
2121

22-
from ..model import Person, SoftwareSystem
2322
from .animation import Animation, AnimationIO
2423
from .view import View, ViewIO
24+
from ..model import Element, Person, SoftwareSystem
2525

2626

2727
__all__ = ("StaticView", "StaticViewIO")
@@ -92,3 +92,22 @@ def add_all_software_systems(self) -> None:
9292
"""Add all people in the model to this view."""
9393
for system in self.software_system.get_model().software_systems:
9494
self.add(system)
95+
96+
def add_nearest_neighbours(self, element: Element,) -> None:
97+
"""Add all permitted elements from a model to this view."""
98+
self._add_element(element, True)
99+
100+
element_type = type(element)
101+
# TODO(ilaif): @midnighter - Should we move to @property instead
102+
# of get_X()? More pythonic.
103+
# (midnighter): Probably yes.
104+
for relationship in self.software_system.get_model().get_relationships():
105+
if relationship.source == element and isinstance(
106+
relationship.destination, element_type
107+
):
108+
self._add_element(relationship.destination, add_relationships=True)
109+
110+
if relationship.destination == element and isinstance(
111+
relationship.source, element_type
112+
):
113+
self._add_element(relationship.source, add_relationships=True)

0 commit comments

Comments
 (0)