svgen.element package#

Subpackages#

Submodules#

svgen.element.circle module#

svgen - A module for the ‘circle’ element.

class svgen.element.circle.Circle(circle: Circle, attrs: dict[str, str | int | float | bool] | list[Attribute] | Attribute = None, **extra)[source]#

Bases: Element

A class for circle elements.

property center: Point#

Get this circle’s center.

static centered(box: ViewBox | Rectangle, radius_scale: float = 1.0, color: str | Hsl | Rgb | Color = None, prop: str = 'fill', **kwargs) Circle[source]#

From a viewBox, create a circle that is centered with an appropriately scaled radius.

static create(center: Point, radius: float, color: str | Hsl | Rgb | Color = None, prop: str = 'fill', **kwargs) Circle[source]#

Create a circle from a point and radius.

property radius: float#

Get this circle’s radius.

scale(scale: float = 1.0) Circle[source]#

Scale this circle’s radius.

translate(move: Translation) Circle[source]#

Move this circle by a given translation.

svgen.element.line module#

svgen - A module for the ‘line’ element.

class svgen.element.line.Line(p1: Point, p2: Point, attrs: dict[str, str | int | float | bool] | list[Attribute] | Attribute = None, **extra)[source]#

Bases: Element

A definition of a line.

static create(x2: float, y2: float, x1: float = 0.0, y1: float = 0.0, attrs: dict[str, str | int | float | bool] | list[Attribute] | Attribute = None, **extra) Line[source]#

Create a line.

translate(move: Translation | float, *args, **kwargs) Line[source]#

Move a rectangle by a given translation.

svgen.element.line.line(x2: float, y2: float, x1: float = 0.0, y1: float = 0.0, attrs: dict[str, str | int | float | bool] | list[Attribute] | Attribute = None, **extra) Line[source]#

Create a line.

svgen.element.rect module#

svgen - A module for the ‘rect’ element.

class svgen.element.rect.Rect(rect: Rectangle, rx: float = 0.0, ry: float = 0.0, attrs: dict[str, str | int | float | bool] | list[Attribute] | Attribute = None, **extra)[source]#

Bases: FillColorMixin, RectangularMixin, RadiusXyMixin

A class for rect elements.

property bottom_left: Point#

Get the bottom left corner point.

property bottom_right: Point#

Get the bottom right corner point.

static centered(box: ViewBox | Rectangle, width_scale: float = 1.0, height_scale: float = 1.0, color: str | Hsl | Rgb | Color = None, prop: str = 'fill', square: bool = False, **kwargs) Rect[source]#

From a viewBox, created a centered-and-scaled rectangle.

corner(corner: RectangleCorner) Point[source]#

Get a specific corner of a rectangle.

static create(width: float, height: float, point: Point = (0.0, 0.0, False, -1), **kwargs) Rect[source]#

Create a rectangle element.

grid(columns: int, rows: int) RectangleGrid[source]#

Create a grid from this rectangle.

property height: float#

Get the height of this rectangle element.

scale(width_scale: float = 1.0, height_scale: float = 1.0) Rect[source]#

Scale this rectangle’s width and height.

scale_whole(scalar: float = 1.0) Rect[source]#

Scale width and height of this rectangle equally.

property square: bool#

Determine if this rectangle is square.

to_square(scale: float = 1.0) Rect[source]#

Convert this rectangle to a square.

property top_left: Point#

Get the top left corner point.

property top_right: Point#

Get the top right corner point.

translate(move: Translation) Rect[source]#

Move this rectangle by a given translation.

property width: float#

Get the width of this rectangle element.

svgen.element.svg module#

svgen - A module for the ‘svg’ element.

class svgen.element.svg.Svg(viewbox: ViewBox, document: bool = True, **extra)[source]#

Bases: Element

A class for svg elements.

svgen.element.svg.add_background_grid(svg: Svg, background: Dict[str, Any], grid: Dict[str, Any]) None[source]#

Add background and grid objects to an svg element, if they’re specified in their respective configurations.

svgen.element.text module#

A module for the ‘text’ element.

class svgen.element.text.Text(text: str, rect: Rect, attrs: dict[str, str | int | float | bool] | list[Attribute] | Attribute = None, **extra)[source]#

Bases: FillColorMixin, RectangularMixin

A class for text elements

has_dimensions = False#

Module contents#

svgen - Common interfaces and assets for SVG elements.

class svgen.element.Element(tag: str = None, text: str = '', attrib: List[Attribute] = None, children: List[Element] = None, allow_no_end_tag: bool = True, class_str: str = None, preformatted: bool = False, **extra)[source]#

Bases: object

A basic interface for an SVG element.

add_attribute(attr: Attribute, strict: bool = True) T[source]#

Add an attribute to this element.

add_class(*data: str) T[source]#

Add a class string.

closing(indent: int = 0) str[source]#

Create a string to close this element.

encode(output: TextIO, quote: str = '"', indent: int = 0, newlines: bool = True) None[source]#

Encode this element to a string stream.

encode_str(quote: str = '"', indent: int = 0, newlines: bool = True) str[source]#

Encode this element to a string.

property style: Style#

Get the style attribute for this element.

property xml: Element#

Get this element as an xml element.