# `Macaw.Draw.SVG`
[🔗](https://github.com/dcoai/macaw_draw/blob/v0.1.0/lib/macaw/draw/svg.ex#L1)

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.

# `error`

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

A refusal: faults with their paths.

# `append`

```elixir
@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`.

# `append`

```elixir
@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`.

# `append_all`

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

Appends each of `children` in order.

# `circle`

```elixir
@spec circle(Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
```

A `<circle>`.

# `group`

```elixir
@spec group(Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
```

A `<g>` with `attrs`.

# `line`

```elixir
@spec line(Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
```

A `<line>`.

# `new`

```elixir
@spec new(Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
```

A root `<svg>` with `attrs`.

# `path`

```elixir
@spec path(Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
```

A `<path>`.

# `polygon`

```elixir
@spec polygon(Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
```

A `<polygon>`.

# `polyline`

```elixir
@spec polyline(Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
```

A `<polyline>`.

# `rect`

```elixir
@spec rect(Macaw.Draw.SVG.Element.attrs()) :: Macaw.Draw.SVG.Element.t() | error()
```

A `<rect>`.

# `render`

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

The markup as iodata.

# `text`

```elixir
@spec text(String.t(), Macaw.Draw.SVG.Element.attrs()) ::
  Macaw.Draw.SVG.Element.t() | error()
```

A `<text>` of `content`.

# `to_string`

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

The markup as a binary.

# `translate`

```elixir
@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`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
