Skip to content

Commit

Permalink
fix: Fix Legend context
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenngn committed Feb 9, 2024
1 parent 89b9a28 commit 94b7375
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions capellambse_context_diagrams/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def render(self, fmt: str | None, /, **params) -> t.Any:
def _create_diagram(self, params: dict[str, t.Any]) -> cdiagram.Diagram:
data = params.get("elkdata") or get_elkdata(self, params)
layout = try_to_layout(data)
add_context(layout)
add_context(layout, params.get("is_legend", False))
return self.serializer.make_diagram(layout)

@property # type: ignore
Expand Down Expand Up @@ -432,13 +432,20 @@ def _create_diagram(self, params: dict[str, t.Any]) -> cdiagram.Diagram:
legend["layoutOptions"]["aspectRatio"] = width
axis = "y"
params["elkdata"] = legend
params["is_legend"] = True
legend_diagram = super()._create_diagram(params)
stack_diagrams(class_diagram, legend_diagram, axis)
return class_diagram


def add_context(data: _elkjs.ELKOutputData) -> None:
def add_context(data: _elkjs.ELKOutputData, is_legend: bool = False) -> None:
"""Add all connected nodes as context to all elements."""
if is_legend:
for child in data["children"]:
if child["type"] == "node":
child["context"] = [child["id"]] # type: ignore[typeddict-unknown-key]
return

ids: set[str] = set()

def get_ids(obj: _elkjs.ELKOutputNode | _elkjs.ELKOutputEdge) -> None:
Expand Down

0 comments on commit 94b7375

Please sign in to comment.