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

An SVG element as data (spec/07 §24), copied from visualize's `Visualize.SVG.Element`:
`%Macaw.Draw.SVG.Element{tag, attrs, children, content}`, mirroring an element one to
one: `tag` an SVG tag atom, `attrs` a map, `children` a list of elements, `content` text
or `nil`.

    iex> alias Macaw.Draw.SVG.Element
    iex> Element.svg(width: 10) |> Element.append(Element.circle(r: 2)) |> to_string()
    ~s(<svg width="10" xmlns="http://www.w3.org/2000/svg"><circle r="2"/></svg>)

`new(tag, attrs)` and one constructor per tag build elements, each taking a map or a
keyword list; `attrs/2` merges attributes; `append/2` appends an element, a scene IR
element (converted by `from_ir/1`) or a list mixing both; `content/2` sets the text.
`from_ir/1` converts a `Macaw.Draw.IR.Element` tree to the element tree its SVG renderer
writes, exactly: the renderer writes through it (spec/10 §3.2). The element implements
`String.Chars`, and `Phoenix.HTML.Safe` when `Phoenix.HTML` is loaded, so it
interpolates into a template as markup; `Macaw.Draw` takes no Phoenix dependency.

# `attrs`

```elixir
@type attrs() :: map() | keyword()
```

Attributes: a map, or a keyword list.

# `error`

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

A refusal: faults with their paths.

# `t`

```elixir
@type t() :: %Macaw.Draw.SVG.Element{
  attrs: map(),
  children: [t()],
  content: String.t() | nil,
  tag: atom()
}
```

# `append`

```elixir
@spec append(t(), t() | Macaw.Draw.IR.Element.t() | [t() | Macaw.Draw.IR.Element.t()]) ::
  t() | error()
```

Appends an element, a `Macaw.Draw.IR.Element` (by `from_ir/1`), or a list mixing both.

# `attrs`

```elixir
@spec attrs(t(), attrs()) :: t() | error()
```

Merges attributes into an element's.

# `circle`

```elixir
@spec circle(attrs()) :: t() | error()
```

A `<circle>` element.

# `clipPath`

```elixir
@spec clipPath(attrs()) :: t() | error()
```

A `<clipPath>` element.

# `content`

```elixir
@spec content(t(), String.t() | nil) :: t() | error()
```

Sets an element's text content; `nil` clears it.

# `defs`

```elixir
@spec defs(attrs()) :: t() | error()
```

A `<defs>` element.

# `ellipse`

```elixir
@spec ellipse(attrs()) :: t() | error()
```

A `<ellipse>` element.

# `from_ir`

```elixir
@spec from_ir(Macaw.Draw.IR.Element.t()) :: t() | error()
```

The element tree the SVG renderer writes for a scene IR element tree (spec/10 §3): each
node's tag, its attributes as `Macaw.Draw.Render.SVG` writes them, its children and its
text, so the builder and the renderer write one markup. A clipped node converted alone
is its definition and itself, side by side in a group; a node the renderer refuses is
left out, as an interpolation leaves it out (spec/10 §3.5).

# `g`

```elixir
@spec g(attrs()) :: t() | error()
```

A `<g>` element.

# `line`

```elixir
@spec line(attrs()) :: t() | error()
```

A `<line>` element.

# `linearGradient`

```elixir
@spec linearGradient(attrs()) :: t() | error()
```

A `<linearGradient>` element.

# `new`

```elixir
@spec new(atom(), attrs()) :: t() | error()
```

An element of `tag` with `attrs`.

# `path`

```elixir
@spec path(attrs()) :: t() | error()
```

A `<path>` element.

# `polygon`

```elixir
@spec polygon(attrs()) :: t() | error()
```

A `<polygon>` element.

# `polyline`

```elixir
@spec polyline(attrs()) :: t() | error()
```

A `<polyline>` element.

# `radialGradient`

```elixir
@spec radialGradient(attrs()) :: t() | error()
```

A `<radialGradient>` element.

# `rect`

```elixir
@spec rect(attrs()) :: t() | error()
```

A `<rect>` element.

# `stop`

```elixir
@spec stop(attrs()) :: t() | error()
```

A `<stop>` element.

# `svg`

```elixir
@spec svg(attrs()) :: t() | error()
```

A root `<svg>`, with `xmlns="http://www.w3.org/2000/svg"`.

# `text`

```elixir
@spec text(attrs()) :: t() | error()
```

A `<text>` element.

# `title`

```elixir
@spec title(attrs()) :: t() | error()
```

A `<title>` element.

# `tspan`

```elixir
@spec tspan(attrs()) :: t() | error()
```

A `<tspan>` element.

---

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