The plain SVG builder's fluent API (spec/07 §24; visualize spec/02 §5), copied from
visualize's Visualize.SVG: markup for host code and tests without a frame. A frame
draws through the scene IR and its renderers (spec/10), and the builder shares their
attribute naming and escaping, so the two write the same markup for the same element.
iex> alias Macaw.Draw.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.to_string()
~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>)render/1 answers the markup as iodata, to_string/1 as a binary. A path is a
Macaw.Draw.IR.Path; visualize's Visualize.SVG.Path shim is not carried over.
Summary
Functions
Appends an element, a scene IR element or a list of them to parent.
Appends a new element of tag with attrs to parent.
Appends each of children in order.
A <circle>.
A <g> with attrs.
A <line>.
A root <svg> with attrs.
A <path>.
A <polygon>.
A <polyline>.
A <rect>.
The markup as iodata.
A <text> of content.
The markup as a binary.
A <g transform="translate(x,y)"> around elements.
Types
@type error() :: {:error, [Macaw.Base.Fault.t()]}
A refusal: faults with their paths.
Functions
@spec append(Macaw.Draw.SVG.Element.t(), term()) :: Macaw.Draw.SVG.Element.t() | error()
Appends an element, a scene IR element or a list of them to parent.
@spec append(Macaw.Draw.SVG.Element.t(), atom(), Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
Appends a new element of tag with attrs to parent.
@spec append_all(Macaw.Draw.SVG.Element.t(), [term()]) :: Macaw.Draw.SVG.Element.t() | error()
Appends each of children in order.
@spec circle(Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
A <circle>.
@spec group(Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
A <g> with attrs.
@spec line(Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
A <line>.
@spec new(Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
A root <svg> with attrs.
@spec path(Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
A <path>.
@spec polygon(Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
A <polygon>.
@spec polyline(Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
A <polyline>.
@spec rect(Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
A <rect>.
@spec render(Macaw.Draw.SVG.Element.t()) :: iodata() | error()
The markup as iodata.
@spec text(String.t(), Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
A <text> of content.
@spec to_string(Macaw.Draw.SVG.Element.t()) :: String.t() | error()
The markup as a binary.
@spec translate( Macaw.Draw.SVG.Element.t() | [Macaw.Draw.SVG.Element.t()], number(), number() ) :: Macaw.Draw.SVG.Element.t() | error()
A <g transform="translate(x,y)"> around elements.