capellambse.svg package

Export diagrams to .svg files.

Submodules

capellambse.svg.decorations module

The decoration factories for svg elements.

class capellambse.svg.decorations.DecoFactories

Bases: dict[str, DecoFactory]

class capellambse.svg.decorations.DecoFactory

Bases: object

DecoFactory(function: ‘cabc.Callable’, dependencies: ‘tuple[str, …]’)

__init__(function, dependencies)
Parameters:
Return type:

None

dependencies: tuple[str, ...]
function: Callable
capellambse.svg.decorations.feature_space = 24

Default margins/padding (top/bot and left/right) for feature text.

capellambse.svg.decorations.icon_padding = 2

Default icon padding (left/right side).

capellambse.svg.decorations.icon_size = 20

Default icon size.

capellambse.svg.decorations.max_label_width = 1500

Maximum width for a label.

capellambse.svg.decorations.min_symbol_width = 200

Minimum width (available horizontal space) for a symbol.

capellambse.svg.drawing module

Custom extensions to the svgwrite Drawing object.

capellambse.svg.drawing.DEBUG = False

Debug flag to render helping lines.

class capellambse.svg.drawing.Drawing

Bases: object

The main container that stores all svg elements.

__init__(metadata, *, font_family="'Open Sans','Segoe UI',Arial,sans-serif", font_size=11, transparent_background=False)
Parameters:
draw_object(obj)

Draw an object into this drawing.

Parameters:

obj (Mapping[str, Any]) – The (decoded) JSON-dict of a single diagram object.

Return type:

None

property filename: str

Return the filename of the SVG.

save_as(filename=None, **kw)

Write the SVG to a file.

If filename wasn’t given the underlying filename is taken.

Parameters:
  • filename (str | None)

  • kw (Any)

Return type:

None

to_string()

Return a string representation of the SVG.

Return type:

str

capellambse.svg.drawing.LABEL_ICON_PADDING = 2

Default padding between a label’s icon and text.

class capellambse.svg.drawing.LabelBuilder

Bases: object

Helper data-class for building labels.

__init__(rect_width, rect_height, labels, group, labelstyle, class_=None, y_margin=0, text_anchor='start', icon=True, icon_size=20, alignment='center')
Parameters:
Return type:

None

alignment: Literal['center', 'left', 'right'] = 'center'
class_: str | None = None
group: Group
icon: bool = True
icon_size: float | int = 20
labels: list[LabelDict]
labelstyle: Styling
rect_height: int | float
rect_width: int | float
text_anchor: str = 'start'
y_margin: int | float = 0
class capellambse.svg.drawing.LabelDict

Bases: TypedDict

class: str
height: float
text: str
width: float
x: float
y: float
class capellambse.svg.drawing.LinesData

Bases: object

Helper data-tuple for rendering text-lines from labels.

__init__(lines, line_height, text_height, margin, max_line_width, min_x=None)
Parameters:
Return type:

None

line_height: float
lines: list[str]
margin: float
max_line_width: float
min_x: float | None = None
text_height: float
capellambse.svg.drawing.get_label_icon_position(builder, lines)

Calculate the icon’s position.

Parameters:
Return type:

Vector2D

capellambse.svg.drawing.get_label_position(builder, lines)

Calculate the label positions.

Parameters:
Return type:

Vector2D

capellambse.svg.drawing.render_hbounded_lines(builder, render_icon)

Return Lines data to render a label.

Parameters:
Return type:

LinesData

capellambse.svg.generate module

class capellambse.svg.generate.ContentsDict

Bases: TypedDict

class: str
height: float
id: str
label: LabelDict | str
points: List[List[int]]
type: str
width: float
x: float
y: float
class capellambse.svg.generate.DiagramMetadata

Bases: object

Holds metadata about a diagram.

The metadata of a diagram includes the diagram-name, (x, y) position, (w, h) size, the viewbox string and the diagram class, e.g. LogicalArchitectureBlank.

__init__(pos, size, name, class_, **_kw)
Parameters:
Return type:

None

class_: str | None
classmethod from_dict(data)
Parameters:

data (DiagramMetadataDict)

Return type:

DiagramMetadata

name: str
pos: tuple[float, float]
size: tuple[float, float]
viewbox: str
class capellambse.svg.generate.DiagramMetadataDict

Bases: TypedDict

class: str | None
contents: Sequence[ContentsDict]
height: float
name: str
width: float
x: float
y: float
class capellambse.svg.generate.SVGDiagram

Bases: object

An SVG diagram that can be drawn on and serialized.

SVG diagram object that takes the metadata of a diagram via the DiagramMetadata and a list of objects that are dictionaries describing the components to be drawn on the diagram canvas of type Drawing.

Example of expected json-file/string:

{
    "name": "FA00 - Functional Architecture Example",
    "class": "LogicalArchitectureBlank",
    "x": 10,
    "y": 20,
    "width": 100,
    "height": 200,
    "contents": [
        {
            "type": "box",
            "id": "_ZNVPYDHuEeqOg4absf8kjA",
            "class": "LogicalFunction",
            "x": 150,
            "y": 130,
            "width": 101,
            "height": 101,
            "label": "example label"
        }
    ]
}
__init__(metadata, objects, params=None)
Parameters:
Return type:

None

draw_object(obj)

Draw the given obj on the underlaying Drawing.

Parameters:

obj (ContentsDict)

Return type:

None

classmethod from_json(jsonstring)

Create an SVGDiagram from the given JSON string.

Parameters:

jsonstring (str) – Json/dictionary in str format

Returns:

SVG diagram object

Return type:

SVGDiagram

classmethod from_json_path(path)

Create an SVGDiagram from the given JSON file.

Parameters:

path (str | PathLike) – path to .json file

Returns:

SVG diagram object

Return type:

SVGDiagram

save(filename=None, pretty=False, indent=2)

Write the underlying Drawing to an SVG file.

Parameters:
  • filename (str | None)

  • pretty (bool)

  • indent (int)

Return type:

None

save_drawing(*args, **kwargs)
Return type:

None

to_string()

Return a string representation of the underlying Drawing.

Return type:

str

capellambse.svg.helpers module

capellambse.svg.helpers.check_for_horizontal_overflow(text, width, icon_padding, icon_size, alignment='center')
Parameters:
Return type:

tuple[Sequence[str], float, float]

capellambse.svg.helpers.check_for_vertical_overflow(lines, height, max_text_width)
Parameters:
Return type:

list[str]

capellambse.svg.style module

Stylesheet generator for SVG diagrams.

class capellambse.svg.style.Styling

Bases: object

Container for style attributes of svg objects.

Notes

Attributes containing ‘-’ are only referenceable via getattr() or subscripting syntax, due to Python identifier naming rules.

__init__(diagram_class, class_, prefix='', **attr)
Parameters:
  • diagram_class (str | None)

  • class_ (str)

  • prefix (str)

_to_dict()

Convert this styling to a dictionary.

The returned dict also includes the built-in default styles for the diagram class and object class given to the constructor.

Return type:

dict[str, float | int | str]

capellambse.svg.symbols module

capellambse.svg.symbols.and_control_node_symbol(id_='AndControlNodeSymbol')
capellambse.svg.symbols.arrow_mark(id_='Arrow', **kw)
Parameters:

id_ (str)

Return type:

Marker

capellambse.svg.symbols.capability_symbol(id_='CapabilitySymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.class_symbol(id_='ClassSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.component_exchange_symbol(id_='ComponentExchangeSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.component_port_symbol(id_='ComponentPortSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.diamond_mark(id_='Diamond', **kw)
Parameters:

id_ (str)

Return type:

Marker

capellambse.svg.symbols.entity_symbol(id_='EntitySymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.error_symbol(id_='ErrorSymbol', **kw)
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.filled_diamond_mark(id_='FilledDiamond', **kw)
Parameters:

id_ (str)

Return type:

Marker

capellambse.svg.symbols.final_state_symbol(id_='FinalStateSymbol')
capellambse.svg.symbols.fine_arrow_mark(id_='FineArrow', **kw)
Parameters:

id_ (str)

Return type:

Marker

capellambse.svg.symbols.function_symbol(id_='FunctionSymbol', colors=('#6CB35B', '#ffffff'), gradient_url='green', label='F')
Parameters:
Return type:

Symbol

capellambse.svg.symbols.functional_exchange_symbol(id_='FunctionalExchangeSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.generalization_mark(id_='Generalization', **kw)
Parameters:

id_ (str)

Return type:

Marker

capellambse.svg.symbols.initial_pseudo_state_symbol(id_='InitialPseudoStateSymbol')
capellambse.svg.symbols.iterate_control_node_symbol(id_='IterateControlNodeSymbol')
capellambse.svg.symbols.logical_actor_symbol(id_='LogicalActorSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.logical_component_symbol(id_='LogicalComponentSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.logical_function_symbol(id_='LogicalFunctionSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.logical_human_actor_symbol(id_='LogicalHumanActorSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.logical_human_component_symbol(id_='LogicalHumanComponentSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.mission_symbol(id_='MissionSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.mode_symbol(id_='ModeSymbol')
capellambse.svg.symbols.operational_activity_symbol(id_='OperationalActivitySymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.operational_actor_box_symbol(id_='OperationalActorBoxSymbol')
capellambse.svg.symbols.operational_actor_symbol(id_='OperationalActorSymbol')
capellambse.svg.symbols.operational_capability_symbol(id_='OperationalCapabilitySymbol')
capellambse.svg.symbols.operational_exchange_symbol(id_='OperationalExchangeSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.or_control_node_symbol(id_='OrControlNodeSymbol')
capellambse.svg.symbols.physical_behavior_actor_symbol(id_='PhysicalBehaviorActorSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.physical_behavior_component_symbol(id_='PhysicalBehaviorComponentSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.physical_behavior_human_actor_symbol(id_='PhysicalBehaviorHumanActorSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.physical_behavior_human_component_symbol(id_='PhysicalBehaviorHumanComponentSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.physical_component_symbol(id_='PhysicalComponentSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.physical_function_symbol(id_='PhysicalFunctionSymbol')
Parameters:

id_ (str)

Return type:

Symbol

Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.physical_node_actor_symbol(id_='PhysicalNodeActorSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.physical_node_component_symbol(id_='PhysicalNodeComponentSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.physical_node_human_actor_symbol(id_='PhysicalNodeHumanActorSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.physical_node_human_component_symbol(id_='PhysicalNodeHumanComponentSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.port_symbol(id_='PortSymbol')
Parameters:

id_ (str)

Return type:

Symbol

Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.requirement_symbol(id_='RequirementSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.standalone_stick_figure_symbol(id_='StandaloneStickFigureSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.state_symbol(id_='StateSymbol')
capellambse.svg.symbols.stick_figure_symbol(id_='StickFigureSymbol', transform=None, head_color='none', **kw)

Generate StickFigure svg symbol.

Parameters:
Return type:

Symbol

capellambse.svg.symbols.system_actor_symbol(id_='SystemActorSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.system_component_symbol(id_='SystemComponentSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.system_function_symbol(id_='SystemFunctionSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.system_human_actor_symbol(id_='SystemHumanActorSymbol')
Parameters:

id_ (str)

Return type:

Symbol

capellambse.svg.symbols.terminate_pseudo_state_symbol(id_='TerminatePseudoStateSymbol', stroke='#000', stroke_width=0.165)