Behaviour defining the interface for rendering backends.
Backends convert the intermediate representation (IR) to their target output format (SVG strings, Canvas commands, etc.).
Built-in Backends
Visualize.Backend.SVG- SVG string output (default)Visualize.Backend.Canvas- Canvas 2D API commands
Configuration
Set the default backend in your config:
config :visualize, default_backend: :svgOr specify at render time:
Visualize.Render.to_string(element, backend: :canvas)Implementing a Custom Backend
To implement a custom backend, define a module that implements this behaviour:
defmodule MyApp.PDFBackend do
@behaviour Visualize.Backend
@impl true
def path_data(path), do: ...
@impl true
def render_path(path, opts), do: ...
@impl true
def render_element(element, opts), do: ...
@impl true
def render_scene(elements, opts), do: ...
end
Summary
Callbacks
Converts a Path IR to backend-specific path data.
Renders an Element IR tree to the backend's output format.
Renders a Path IR to the backend's output format.
Renders a complete scene (list of elements) to output.
Wraps content in a root container.
Types
Callbacks
@callback path_data(Visualize.IR.Path.t()) :: String.t() | [tuple()]
Converts a Path IR to backend-specific path data.
For SVG, this returns the d attribute string (e.g., "M10,20L100,200Z").
For Canvas, this returns a list of drawing commands.
@callback render_element(Visualize.IR.Element.t(), options()) :: output()
Renders an Element IR tree to the backend's output format.
@callback render_path(Visualize.IR.Path.t(), options()) :: output()
Renders a Path IR to the backend's output format.
Options may include style information and other backend-specific settings.
@callback render_scene([Visualize.IR.Element.t()], options()) :: output()
Renders a complete scene (list of elements) to output.
Wraps content in a root container.
For SVG, this wraps in <svg> tags. For Canvas, this may generate
the canvas element and setup code.
This callback is optional.
Functions
@spec default() :: module()
Gets the configured default backend module.
Resolves a backend from various inputs.
Accepts:
nil- returns the default backend:svg- returnsVisualize.Backend.SVG:canvas- returnsVisualize.Backend.Canvas- A module atom - returns the module directly