Skip to content

Commit

Permalink
feat: Add context to elements
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenngn committed Dec 18, 2023
1 parent d120b72 commit 5ee68c6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Test ClassTree Diagram",
"type": "python",
"request": "launch",
"console": "integratedTerminal",
"envFile": ".env",
"pythonArgs": ["-Xdev"],
"module": "capellambse.repl",
"args": ["ros-msg"]
}
]
}
14 changes: 8 additions & 6 deletions capellambse_context_diagrams/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,9 @@ def _create_diagram(self, params: dict[str, t.Any]) -> cdiagram.Diagram:
)
data, legend = tree_view.collector(self, params)
params["elkdata"] = data
add_context(data)
class_diagram = super()._create_diagram(params)
layout = _elkjs.call_elkjs(data)
add_context(layout)
class_diagram = self.serializer.make_diagram(layout)
width, height = class_diagram.viewport.size
axis: t.Literal["x", "y"]
if params["elk.direction"] in {"DOWN", "UP"}:
Expand All @@ -380,18 +381,19 @@ def _create_diagram(self, params: dict[str, t.Any]) -> cdiagram.Diagram:
return class_diagram


def add_context(data: _elkjs.ELKInputData) -> None:
def add_context(data: _elkjs.ELKOutputData) -> None:
ids: set[str] = set()

def get_ids(obj: _elkjs.ELKInputChild):
ids.add(obj["id"])
def get_ids(obj: _elkjs.ELKOutputChild):
if obj["id"] and not obj["id"].startswith("g_"):
ids.add(obj["id"])
for cobj in obj.get("children", []):
get_ids(cobj)

for child in data["children"]:
get_ids(child)

for child in data["children"] + data["edges"]:
for child in data["children"]:
child["context"] = list(ids)


Expand Down

0 comments on commit 5ee68c6

Please sign in to comment.