Skip to content

Commit

Permalink
fix: Set max width for context diagrams to 100%
Browse files Browse the repository at this point in the history
Merge pull request #41 from DSD-DBS/fix-context-diagram-width
  • Loading branch information
ewuerger authored Jan 18, 2024
2 parents 96e28c8 + a6860d2 commit c9f98eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions capella2polarion/converters/element_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ def _condition(
return {"type": _type, "value": value}


def _generate_image_html(src: str) -> str:
"""Generate an image as HTMl with the given source."""
style = "; ".join(
(f"{key}: {value}" for key, value in DIAGRAM_STYLES.items())
)
description = f'<html><p><img style="{style}" src="{src}" /></p></html>'
return description


class CapellaWorkItemSerializer:
"""The general serializer class for CapellaWorkItems."""

Expand Down Expand Up @@ -174,12 +183,7 @@ def _diagram(
diag = converter_data.capella_element
diagram_path = self.diagram_cache_path / f"{diag.uuid}.svg"
src = _decode_diagram(diagram_path)
style = "; ".join(
(f"{key}: {value}" for key, value in DIAGRAM_STYLES.items())
)
description = (
f'<html><p><img style="{style}" src="{src}" /></p></html>'
)
description = _generate_image_html(src)
return data_models.CapellaWorkItem(
type=converter_data.type_config.p_type,
title=diag.name,
Expand Down Expand Up @@ -324,6 +328,6 @@ def _add_context_diagram(
diagram = converter_data.capella_element.context_diagram
work_item.additional_attributes["context_diagram"] = {
"type": "text/html",
"value": diagram.as_html_img,
"value": _generate_image_html(diagram.as_datauri_svg),
}
return work_item
2 changes: 1 addition & 1 deletion tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,4 +1265,4 @@ def test_add_context_diagram(self, model: capellambse.MelodyModel):
assert "context_diagram" in work_item.additional_attributes
assert str(
work_item.additional_attributes["context_diagram"]["value"]
).startswith('<img src="data:image/svg+xml;base64,')
).startswith(TEST_DIAG_DESCR)

0 comments on commit c9f98eb

Please sign in to comment.