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)¶
- 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:
metadata (DiagramMetadata)
font_family (str)
font_size (int)
transparent_background (bool)
- draw_object(obj)¶
Draw an object into this drawing.
- save_as(filename=None, **kw)¶
Write the SVG to a file.
If
filename
wasn’t given the underlyingfilename
is taken.
- 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')¶
- 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)¶
- capellambse.svg.drawing.get_label_icon_position(builder, lines)¶
Calculate the icon’s position.
- Return type:
- Parameters:
builder (LabelBuilder)
lines (LinesData)
- capellambse.svg.drawing.get_label_position(builder, lines)¶
Calculate the label positions.
- Return type:
- Parameters:
builder (LabelBuilder)
lines (LinesData)
- capellambse.svg.drawing.render_hbounded_lines(builder, render_icon)¶
Return Lines data to render a label.
- Return type:
- Parameters:
builder (LabelBuilder)
render_icon (bool)
capellambse.svg.generate module¶
- 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)¶
- classmethod from_dict(data)¶
- Return type:
- Parameters:
data (DiagramMetadataDict)
- class capellambse.svg.generate.DiagramMetadataDict¶
Bases:
TypedDict
-
contents:
Sequence
[ContentsDict
]¶
-
contents:
- 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 theDiagramMetadata
and a list of objects that are dictionaries describing the components to be drawn on the diagram canvas of typeDrawing
.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:
metadata (DiagramMetadata)
objects (Sequence[ContentsDict])
- Return type:
None
- draw_object(obj)¶
Draw the given
obj
on the underlayingDrawing
.- Return type:
- Parameters:
obj (ContentsDict)
- classmethod from_json(jsonstring)¶
Create an SVGDiagram from the given JSON string.
- Parameters:
jsonstring (
str
) – Json/dictionary instr
format- Returns:
SVG diagram object
- Return type:
- classmethod from_json_path(path)¶
Create an SVGDiagram from the given JSON file.
- Parameters:
- Returns:
SVG diagram object
- Return type:
- save(filename=None, pretty=False, indent=2)¶
Write the underlying
Drawing
to an SVG file.
capellambse.svg.helpers module¶
- capellambse.svg.helpers.check_for_horizontal_overflow(text, width, icon_padding, icon_size, alignment='center')¶
capellambse.svg.style module¶
Stylesheet generator for SVG diagrams.