Macaw.Draw.SVG (macaw_draw v0.1.0)

Copy Markdown View Source

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

Types

A refusal: faults with their paths.

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

error()

@type error() :: {:error, [Macaw.Base.Fault.t()]}

A refusal: faults with their paths.

Functions

append(parent, child)

Appends an element, a scene IR element or a list of them to parent.

append(parent, tag, attrs)

Appends a new element of tag with attrs to parent.

append_all(parent, children)

@spec append_all(Macaw.Draw.SVG.Element.t(), [term()]) ::
  Macaw.Draw.SVG.Element.t() | error()

Appends each of children in order.

circle(attrs \\ [])

A <circle>.

group(attrs \\ [])

A <g> with attrs.

line(attrs \\ [])

A <line>.

new(attrs \\ [])

A root <svg> with attrs.

path(attrs \\ [])

A <path>.

polygon(attrs \\ [])

A <polygon>.

polyline(attrs \\ [])

A <polyline>.

rect(attrs \\ [])

A <rect>.

render(element)

@spec render(Macaw.Draw.SVG.Element.t()) :: iodata() | error()

The markup as iodata.

text(content, attrs \\ [])

A <text> of content.

to_string(element)

@spec to_string(Macaw.Draw.SVG.Element.t()) :: String.t() | error()

The markup as a binary.

translate(elements, x, y)

A <g transform="translate(x,y)"> around elements.