svg_path/svg

Small helpers for rendering paths as complete SVG documents.

Types

One item to render inside a generated SVG document.

This type is intentionally small. It supports styled paths, rectangles, circles, ellipses, and text labels for quick debugging drawings and examples.

pub type ThingToDraw {
  StyledPath(svg_path.Path, String)
  Rectangle(svg_path.Point, Float, Float, String)
  RotatedRectangle(
    svg_path.Point,
    Float,
    Float,
    String,
    rotation: Float,
    origin: svg_path.Point,
  )
  Circle(svg_path.Point, Float, String)
  Ellipse(svg_path.Point, svg_path.Point, String)
  Text(String, String, svg_path.Point, Int)
  RotatedText(
    String,
    String,
    svg_path.Point,
    Int,
    rotation: Float,
    origin: svg_path.Point,
  )
}

Constructors

  • StyledPath(svg_path.Path, String)

    A <path> element.

    The first field is serialized as the element’s d attribute. The second field is used directly as the element’s style attribute after XML attribute escaping.

  • Rectangle(svg_path.Point, Float, Float, String)

    A <rect> element.

    The fields are the top-left point, width, height, and raw CSS declarations for the style attribute.

  • RotatedRectangle(
      svg_path.Point,
      Float,
      Float,
      String,
      rotation: Float,
      origin: svg_path.Point,
    )

    A rectangle rotated in degrees around the supplied origin.

  • Circle(svg_path.Point, Float, String)

    A <circle> element.

    The fields are the center point, radius, and raw CSS declarations for the style attribute.

  • Ellipse(svg_path.Point, svg_path.Point, String)

    An <ellipse> element.

    The fields are the center point, x/y radii, and raw CSS declarations for the style attribute.

  • Text(String, String, svg_path.Point, Int)

    A <text> element.

    The fields are text content, raw CSS declarations for the style attribute, the text position, and the font size in SVG user units.

  • RotatedText(
      String,
      String,
      svg_path.Point,
      Int,
      rotation: Float,
      origin: svg_path.Point,
    )

    Text rotated in degrees around the supplied origin.

A list of items to render inside a generated SVG document.

pub type ThingsToDraw =
  List(ThingToDraw)

Values

pub fn document(
  things things: List(ThingToDraw),
  view_box view_box: svg_path.BoundingBox,
) -> String

Render styled paths and text labels as a complete SVG document.

The supplied bounding box is used directly as the document viewBox.

pub fn labeled_point(
  label: String,
  color: String,
  point: svg_path.Point,
  font_size: Int,
) -> List(ThingToDraw)
pub fn paths(
  things things: List(ThingToDraw),
  view_box view_box: svg_path.BoundingBox,
) -> String

Render styled paths and text labels as a complete SVG document.

This is an older name for document.

Search Document