svgen.element package — docs

Skip to main content
`Ctrl`+`K`

# svgen.element package

## Subpackages

- svgen.element.html package
  - Module contents
    - `Html`
      - `Html.render()`
    - `div()`
- svgen.element.mixins package
  - Module contents
    - `FillColorMixin`
      - `FillColorMixin.assign_fill_color()`
      - `FillColorMixin.fill_color`
      - `FillColorMixin.has_fill_color`
    - `RadiusXyMixin`
      - `RadiusXyMixin.radius_xy_attributes`
    - `RectangularMixin`
      - `RectangularMixin.has_dimensions`
      - `RectangularMixin.rect_attributes`

## 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)

  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

    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

    Create a circle from a point and radius.

  property radius: float

    Get this circle’s radius.

  scale(scale: float = 1.0) → Circle

    Scale this circle’s radius.

  translate(move: Translation) → Circle

    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)

  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

    Create a line.

  translate(move: Translation | float, *args, **kwargs) → Line

    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

  Create a line.

## svgen.element.path module

A module implementing a path element.

class svgen.element.path.Path(tag: str = None, text: str = '', attrib: dict[str, str | int | float | bool] | list[Attribute] | Attribute = None, children: list[Element] = None, head_child: Element = None, tail_child: Element = None, allow_no_end_tag: bool = True, class_str: str = None, preformatted: bool = False, **extra)

  Bases: `Element`

  A path element.

  static create(*cmds: str, **kwargs) → Path

    A helper for creating path elements.

class svgen.element.path.PathBuilder

  Bases: `object`

  A class implementing a path building interface.

  close() → None

    Close the current path.

  horizontal(count: float, relative: bool = True) → None

    Issue a horizontal command.

  path(**kwargs) → Path

    Get a path element based on this builder’s state.

  point(point: Point, cmd: PathCmd) → None

    Issue a point-based command.

  translation(translation: Translation, cmd: PathCmd) → None

    Issue a translation-based command.

  vertical(count: float, relative: bool = True) → None

    Issue a vertical command.

class svgen.element.path.PathCmd(*values)

  Bases: `StrEnum`

  An enumeration of svg path commands.

  LINE = 'L'
  MOVE = 'M'

svgen.element.path.compose_borders(viewbox: ViewBox, config: dict[str, Any]) → list[Element]

  An example function for composing a document.

## 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)

  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

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

  corner(corner: RectangleCorner) → Point

    Get a specific corner of a rectangle.

  static create(width: float, height: float, point: Point = (0.0, 0.0, False, -1), **kwargs) → Rect

    Create a rectangle element.

  grid(columns: int, rows: int) → RectangleGrid

    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

    Scale this rectangle’s width and height.

  scale_whole(scalar: float = 1.0) → Rect

    Scale width and height of this rectangle equally.

  property square: bool

    Determine if this rectangle is square.

  to_square(scale: float = 1.0) → Rect

    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

    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)

  Bases: `Element`

  A class for svg elements.

  static app(config: dict[str, Any] = None) → Svg

    Get an application SVG document.

svgen.element.svg.add_background_grid(svg: Svg, background: dict[str, Any], grid: dict[str, Any]) → None

  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)

  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: dict[str, str | int | float | bool] | list[Attribute] | Attribute = None, children: list[Element] = None, head_child: Element = None, tail_child: Element = None, allow_no_end_tag: bool = True, class_str: str = None, preformatted: bool = False, **extra)

  Bases: `object`

  A basic interface for an SVG element.

  add_attribute(attr: Attribute, strict: bool = True) → T

    Add an attribute to this element.

  add_class(*data: str) → T

    Add a class string.

  attributes: dict[str, Attribute]
  booleans: set[str]
  children: list[Element]
  closing(indent: int = 0) → str

    Create a string to close this element.

  encode(output: TextIO, quote: str = '"', indent: int = 0, newlines: bool = True) → None

    Encode this element to a string stream.

  encode_str(quote: str = '"', indent: int = 0, newlines: bool = True) → str

    Encode this element to a string.

  has_children() → bool

    Determine if this element has any children.

  property style: Style

    Get the style attribute for this element.

  property xml: Element

    Get this element as an xml element.