Victor (Victor v0.1.1) View Source

A simple solution for creating SVGs in Elixir.

Link to this section Summary

Functions

Adds a new SVG item to a Victor.

Gets the string representation of a SVG.

Creates a new Victor.

Writes a SVG string to a given file.

Link to this section Functions

Link to this function

add(victor, tag, props, style \\ %{})

View Source

Adds a new SVG item to a Victor.

Parameters

  • victor - A Victor struct to add the item to.
  • tag - The SVG tag type to be added (as an atom).
  • props - A map of properties for the SVG item (i.e. width).
  • style - An optional map of style properties for the SVG item.

Examples

iex> Victor.new()
...> |> Victor.add(:circle, %{cx: 10, cy: 10, r: 20})
%Victor{
  height: 100,
  items: [{:circle, %{cx: 10, cy: 10, r: 20}, []}],
  width: 100
}

iex> Victor.new()
...> |> Victor.add(:rect, %{x: 10, y: 10, width: 100, height: 50}, %{fill: "red"})
%Victor{
  height: 100,
  items: [
    {:rect, %{height: 50, style: "fill:red", width: 100, x: 10, y: 10}, []}
  ],
  width: 100
}

iex> Victor.new()
...> |> Victor.add(:path, [[:m, 130, 110], [:c, 120, 140, 180, 140, 170, 110]])
%Victor{
  height: 100,
  items: [
    {:path, %{d: "M 130 110 C 120 140 180 140 170 110"}, []}
  ],
  width: 100
}

Gets the string representation of a SVG.

Parameters

  • victor - A Victor struct to convert to a string.

Examples

iex> Victor.get_svg(%Victor{})
"<svg viewBox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\" />"

iex> Victor.new()
...> |> Victor.add(:circle, %{cx: 10, cy: 10, r: 20})
...> |> Victor.get_svg()
"<svg viewBox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\">\n\t<circle cx=\"10\" cy=\"10\" r=\"20\" />\n</svg>"

Creates a new Victor.

Parameters

  • size - An optional map with width and height keys.

Examples

iex> Victor.new()
%Victor{width: 100, height: 100, items: []}

iex> Victor.new(%{width: 600, height: 400})
%Victor{width: 600, height: 400, items: []}
Link to this function

write_file(svg, filepath)

View Source

Writes a SVG string to a given file.

A simple wrapper around File.write/2.

Parameters

  • svg - A string representation of a SVG.
  • filepath - The path to the file.