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(vec2.Vec2(Float), Float, Float, String)
  Circle(vec2.Vec2(Float), Float, String)
  Ellipse(vec2.Vec2(Float), vec2.Vec2(Float), String)
  Text(String, String, vec2.Vec2(Float), Int)
}

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(vec2.Vec2(Float), Float, Float, String)

    A <rect> element.

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

  • Circle(vec2.Vec2(Float), Float, String)

    A <circle> element.

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

  • Ellipse(vec2.Vec2(Float), vec2.Vec2(Float), String)

    An <ellipse> element.

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

  • Text(String, String, vec2.Vec2(Float), 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.

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: vec2.Vec2(Float),
  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