Svg Module

This module contains classes for generating SVG documents.

class Shape2D[source]

Abstract base class for 2D shapes.

abstract to_svg() str[source]

Return the SVG representation of the shape.

Returns:

The SVG representation of the shape.

Return type:

str

class Circle2D(reference: str, center: Point2D, radius: float)[source]

A 2D circle.

Parameters:
  • reference (str) – The reference name of the circle.

  • center (Point2D) – The center of the circle with shape (2,).

  • radius (float) – The radius of the circle.

to_svg() str[source]

Return the SVG representation of the circle.

Returns:

The SVG representation of the circle.

Return type:

str

class Line2D(reference: str, start: Point2D, end: Point2D)[source]

A 2D line.

Parameters:
  • reference (str) – The reference name of the line.

  • start (Point2D) – The start point of the line with shape (2,).

  • end (Point2D) – The end point of the line with shape (2,).

to_svg() str[source]

Return the SVG representation of the line.

Returns:

The SVG representation of the line.

Return type:

str

class Polygon2D(reference: str, points: List[Point2D])[source]

A 2D polygon.

Parameters:
  • reference (str) – The reference name of the polygon.

  • points (ty.List[Point2D]) – The vertices of the polygon.

to_svg() str[source]

Return the SVG representation of the polygon.

Returns:

The SVG representation of the polygon.

Return type:

str

class ViewBox(min_x: float, min_y: float, width: float, height: float)[source]

A view box.

Parameters:
  • min_x (float) – The minimum x coordinate.

  • min_y (float) – The minimum y coordinate.

  • width (float) – The width of the view box.

  • height (float) – The height of the view box.

to_svg() str[source]

Return the SVG representation of the view box.

Returns:

The SVG representation of the view box.

Return type:

str

class Svg(view_box: ViewBox, window: Tuple[float, float] | None = None, background_color: Color | None = None, version: float = 1.0, encoding: str = 'UTF-8', fills: List[Fill] | None = None, objects: List[Shape2D] | None = None)[source]

An SVG document.

Initialize the SVG document.

Parameters:
  • view_box (ViewBox) – The view box of the SVG document.

  • window (ty.Optional[ty.Tuple[float, float]]) – The window of the SVG document.

  • background_color (ty.Optional[Color]) – The background color of the SVG document.

  • version (float) – The version of the SVG document.

  • encoding (str) – The encoding of the SVG document.

  • fills (ty.List[Fill]) – The fills of the SVG document.

  • objects (ty.List[Shape2D]) – The objects of the SVG document.

header() str[source]

Return the header of the SVG document.

Returns:

The header of the SVG document.

Return type:

str

footer() str[source]

Return the footer of the SVG document.

Returns:

The footer of the SVG document.

Return type:

str

to_svg() str[source]

Return the SVG representation of the SVG document.

Returns:

The SVG representation of the SVG document.

Return type:

str