Visualize.SVG.Element (Visualize v0.2.35)

Copy Markdown View Source

Represents an SVG element as an Elixir data structure.

Elements can be nested and rendered to SVG strings or used directly in LiveView templates.

Summary

Types

t()

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

Functions

append(parent, child)

@spec append(t(), t() | Visualize.IR.Element.t() | [t() | Visualize.IR.Element.t()]) ::
  t()

Appends a child element. Also accepts IR.Element which will be converted.

attrs(element, new_attrs)

@spec attrs(t(), map() | keyword()) :: t()

Sets attributes on an element.

circle(attrs \\ %{})

clipPath(attrs \\ %{})

content(element, text)

@spec content(t(), String.t()) :: t()

Sets text content for the element.

defs(attrs \\ %{})

ellipse(attrs \\ %{})

from_ir(ir)

@spec from_ir(Visualize.IR.Element.t()) :: t()

Converts an IR.Element to an SVG.Element.

g(attrs \\ %{})

line(attrs \\ %{})

linearGradient(attrs \\ %{})

new(tag, attrs \\ %{})

@spec new(atom(), map()) :: t()

Creates a new SVG element.

Examples

iex> Visualize.SVG.Element.new(:rect, %{x: 0, y: 0, width: 100, height: 50})
%Visualize.SVG.Element{tag: :rect, attrs: %{x: 0, y: 0, width: 100, height: 50}, children: [], content: nil}

path(attrs \\ %{})

polygon(attrs \\ %{})

polyline(attrs \\ %{})

radialGradient(attrs \\ %{})

rect(attrs \\ %{})

stop(attrs \\ %{})

svg(attrs \\ %{})

Common SVG element constructors.

text(attrs \\ %{})

title(attrs \\ %{})

tspan(attrs \\ %{})