Vectored (Vectored v0.4.0)

Copy Markdown View Source

Vectored is a library for creating and rendering SVG documents using a functional API.

It provides a structured way to build SVG elements and render them to XML strings. The library follows the SVG specification and provides helper functions for common attributes and transformations.

Examples

svg =
  Vectored.new(100, 100)
  |> Vectored.Elements.Svg.append(Vectored.Elements.Circle.new(50, 50, 40))

{:ok, xml} = Vectored.to_svg_string(svg)
# xml => ~s(<svg height="100" width="100" xmlns="...">...<circle .../></svg>)

Summary

Functions

Create a new SVG document with default dimensions.

Create a new SVG document with specified width and height.

Render a Vectored element to its internal representation.

Render a Vectored element or document to an XML string.

Functions

new()

Create a new SVG document with default dimensions.

Returns a %Vectored.Elements.Svg{} struct.

new(width, height)

Create a new SVG document with specified width and height.

Parameters

  • width - The width of the SVG viewport.
  • height - The height of the SVG viewport.

Returns a %Vectored.Elements.Svg{} struct.

to_svg(element)

Render a Vectored element to its internal representation.

This is generally used internally by to_svg_string/1 but can be useful for inspecting the structure before final rendering.

to_svg_string(element)

Render a Vectored element or document to an XML string.

It automatically adds the xmlns attribute if the root element is an SVG tag.

Examples

{:ok, xml} = Vectored.Elements.Circle.new(10) |> Vectored.to_svg_string()
# xml => ~s(<circle cx="0" cy="0" r="10"/>)