Victor (Victor v0.1.0)

A simple solution for creating SVGs in Elixir.

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.

Functions

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

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.add(%Victor{}, :circle, %{cx: 10, cy: 10, r: 20})
%Victor{width: 100, height: 100, items: [{:circle, %{cx: 10, cy: 10, r: 20}, []}]}

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

get_svg(map)

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.add(%Victor{}, :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>"

new()

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: []}

new(map)

write_file(svg, filepath)

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.