capellambse.svg package

Export diagrams to .svg files.

Submodules

capellambse.svg.decorations module

The decoration factories for svg elements.

class capellambse.svg.decorations.MarkerFactories

Bases: dict[str, MarkerFactory]

class capellambse.svg.decorations.MarkerFactory

Bases: object

MarkerFactory(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 = 1

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=10, 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.

Return type:

None

Parameters:
  • filename (str | None)

  • kw (Any)

to_string()

Return a string representation of the SVG.

Return type:

str

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.

Return type:

Vector2D

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

Calculate the label positions.

Return type:

Vector2D

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

Return Lines data to render a label.

Return type:

LinesData

Parameters:

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)
Return type:

DiagramMetadata

Parameters:

data (DiagramMetadataDict)

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.

Return type:

None

Parameters:

obj (ContentsDict)

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.

Return type:

None

Parameters:
  • filename (str | None)

  • pretty (bool)

  • indent (int)

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')
Return type:

tuple[Sequence[str], float, float]

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

list[str]

Parameters:

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.arrow_mark(id_, /, **kw)
Return type:

Marker

capellambse.svg.symbols.diamond_mark(id_, /, **kw)
Return type:

Marker

capellambse.svg.symbols.filled_arrow_mark(id_, /, **kw)
Return type:

Marker

capellambse.svg.symbols.filled_diamond_mark(id_, /, **kw)
Return type:

Marker

capellambse.svg.symbols.fine_arrow_mark(id_, /, **kw)
Return type:

Marker

capellambse.svg.symbols.generalization_mark(id_, /, **kw)
Return type:

Marker