Main SVG module providing a fluent API for building SVG documents.
Examples
render/1 returns iodata, which a template writes as it is; flattened, it is the
markup:
iex> alias Visualize.SVG
iex> SVG.new(width: 400, height: 300)
...> |> SVG.append(:rect, x: 10, y: 10, width: 100, height: 50, fill: "blue")
...> |> SVG.append(:circle, cx: 200, cy: 150, r: 40, fill: "red")
...> |> SVG.render()
...> |> IO.iodata_to_binary()
~s(<svg height="300" width="400" xmlns="http://www.w3.org/2000/svg">) <>
~s(<rect fill="blue" height="50" width="100" x="10" y="10"/>) <>
~s(<circle cx="200" cy="150" fill="red" r="40"/></svg>)
Summary
Functions
Appends a child element to the SVG.
Appends multiple children at once.
Creates a circle element
Creates a group element with optional attributes.
Creates a line element
Creates a new SVG root element.
Creates a path element
Creates a polygon element
Creates a polyline element
Creates a rect element
Renders the SVG element tree to an iolist (efficient for Phoenix).
Creates a text element
Renders the SVG element tree to a string.
Wraps elements in a group with a transform.
Functions
Appends a child element to the SVG.
Can take either an Element struct or a tag atom with attributes.
@spec append( Visualize.SVG.Element.t(), Visualize.SVG.Element.t() | atom(), keyword() | map() ) :: Visualize.SVG.Element.t()
@spec append_all(Visualize.SVG.Element.t(), [Visualize.SVG.Element.t()]) :: Visualize.SVG.Element.t()
Appends multiple children at once.
Creates a circle element
@spec group(keyword()) :: Visualize.SVG.Element.t()
Creates a group element with optional attributes.
Creates a line element
@spec new(keyword()) :: Visualize.SVG.Element.t()
Creates a new SVG root element.
Creates a path element
Creates a polygon element
Creates a polyline element
Creates a rect element
@spec render(Visualize.SVG.Element.t()) :: iolist()
Renders the SVG element tree to an iolist (efficient for Phoenix).
Creates a text element
@spec to_string(Visualize.SVG.Element.t()) :: String.t()
Renders the SVG element tree to a string.
@spec translate( Visualize.SVG.Element.t() | [Visualize.SVG.Element.t()], number(), number() ) :: Visualize.SVG.Element.t()
Wraps elements in a group with a transform.