Vectored.Elements.Use (Vectored v0.4.0)

Copy Markdown View Source

The <use> element duplicates a graphical object defined elsewhere in the SVG.

Why use Use?

The <use> element is the "copy-paste" of the SVG world. It allows you to:

  • Save space: Define a complex icon once in <defs> and "use" it multiple times.
  • Centralized updates: Change the original definition, and every duplicate updates instantly.
  • Performance: The browser only has to process the geometry once.

Examples

# Define a star once
defs = Vectored.Elements.Defs.new([
  Vectored.Elements.Circle.new(0, 0, 5) |> Vectored.Elements.Circle.with_id("star")
])

# Place many stars in different spots
stars = [
  Vectored.Elements.Use.new("#star") |> Vectored.Elements.Use.at_location(10, 10),
  Vectored.Elements.Use.new("#star") |> Vectored.Elements.Use.at_location(50, 20)
]

Summary

Functions

Set the location of the <use> element.

Remove a dataset attribute

Create a new <use> element referencing an ID via href.

Create a new <use> element with href and position.

Set a dataset attribute. Mimics the DOM Element.dataset API. The key will be converted from camelCase to kebab-case for the data-* attribute.

Simple setter to put the value alignment-baseline onto the element

Simple setter to put the value baseline-shift onto the element

Simple setter to put the value class onto the element

Simple setter to put the value clip-path onto the element

Simple setter to put the value clip-rule onto the element

Simple setter to put the value color onto the element

Simple setter to put the value color-interpolation onto the element

Simple setter to put the value color-interpolation-filters onto the element

Simple setter to put the value cursor onto the element

Simple setter to put the value dataset onto the element

Simple setter to put the value direction onto the element

Simple setter to put the value display onto the element

Simple setter to put the value dominant-baseline onto the element

Simple setter to put the value fill onto the element

Simple setter to put the value fill-opacity onto the element

Simple setter to put the value fill-rule onto the element

Simple setter to put the value filter onto the element

Simple setter to put the value flood-color onto the element

Simple setter to put the value flood-opacity onto the element

Simple setter to put the value font-family onto the element

Simple setter to put the value font-size onto the element

Simple setter to put the value font-size-adjust onto the element

Simple setter to put the value font-stretch onto the element

Simple setter to put the value font-style onto the element

Simple setter to put the value font-variant onto the element

Simple setter to put the value font-weight onto the element

Simple setter to put the value glyph-orientation-horizontal onto the element

Simple setter to put the value glyph-orientation-vertical onto the element

Simple setter to put the value height onto the element

Simple setter to put the value href onto the element

Simple setter to put the value id onto the element

Simple setter to put the value image-rendering onto the element

Simple setter to put the value letter-spacing onto the element

Simple setter to put the value lighting-color onto the element

Simple setter to put the value marker-end onto the element

Simple setter to put the value marker-mid onto the element

Simple setter to put the value marker-start onto the element

Simple setter to put the value mask onto the element

Simple setter to put the value mask-type onto the element

Simple setter to put the value opacity onto the element

Simple setter to put the value overflow onto the element

Simple setter to put the value paint-order onto the element

Simple setter to put the value pointer-events onto the element

Simple setter to put the value preserveAspectRatio onto the element

Simple setter to put the value shape-rendering onto the element

Set the dimensions of the <use> element.

Simple setter to put the value stop-color onto the element

Simple setter to put the value stop-opacity onto the element

Simple setter to put the value stroke onto the element

Simple setter to put the value stroke-dasharray onto the element

Simple setter to put the value stroke-dashoffset onto the element

Simple setter to put the value stroke-linecap onto the element

Simple setter to put the value stroke-linejoin onto the element

Simple setter to put the value stroke-miterlimit onto the element

Simple setter to put the value stroke-opacity onto the element

Simple setter to put the value stroke-width onto the element

Simple setter to put the value style onto the element

Simple setter to put the value text-anchor onto the element

Simple setter to put the value text-decoration onto the element

Simple setter to put the value text-overflow onto the element

Simple setter to put the value text-rendering onto the element

Simple setter to put the value transform onto the element

Simple setter to put the value transform-origin onto the element

Simple setter to put the value unicode-bidi onto the element

Simple setter to put the value vector-effect onto the element

Simple setter to put the value viewBox onto the element

Simple setter to put the value visibility onto the element

Simple setter to put the value white-space onto the element

Simple setter to put the value width onto the element

Simple setter to put the value word-spacing onto the element

Simple setter to put the value writing-mode onto the element

Simple setter to put the value x onto the element

Simple setter to put the value y onto the element

Types

t()

@type t() :: %Vectored.Elements.Use{
  alignment_baseline: term(),
  baseline_shift: term(),
  class: term(),
  clip_path: term(),
  clip_rule: term(),
  color: term(),
  color_interpolation: term(),
  color_interpolation_filters: term(),
  cursor: term(),
  dataset: term(),
  desc: term(),
  direction: term(),
  display: term(),
  dominant_baseline: term(),
  fill: term(),
  fill_opacity: term(),
  fill_rule: term(),
  filter: term(),
  flood_color: term(),
  flood_opacity: term(),
  font_family: term(),
  font_size: term(),
  font_size_adjust: term(),
  font_stretch: term(),
  font_style: term(),
  font_variant: term(),
  font_weight: term(),
  glyph_orientation_horizontal: term(),
  glyph_orientation_vertical: term(),
  height: String.t() | number() | nil,
  href: String.t(),
  id: term(),
  image_rendering: term(),
  letter_spacing: term(),
  lighting_color: term(),
  marker_end: term(),
  marker_mid: term(),
  marker_start: term(),
  mask: term(),
  mask_type: term(),
  opacity: term(),
  overflow: term(),
  paint_order: term(),
  pointer_events: term(),
  preserve_aspect_ratio: term(),
  shape_rendering: term(),
  stop_color: term(),
  stop_opacity: term(),
  stroke: term(),
  stroke_dasharray: term(),
  stroke_dashoffset: term(),
  stroke_linecap: term(),
  stroke_linejoin: term(),
  stroke_miterlimit: term(),
  stroke_opacity: term(),
  stroke_width: term(),
  style: term(),
  text_anchor: term(),
  text_decoration: term(),
  text_overflow: term(),
  text_rendering: term(),
  title: term(),
  transform: term(),
  transform_origin: term(),
  unicode_bidi: term(),
  vector_effect: term(),
  view_box: term(),
  visibility: term(),
  white_space: term(),
  width: String.t() | number() | nil,
  word_spacing: term(),
  writing_mode: term(),
  x: String.t() | number() | nil,
  y: String.t() | number() | nil
}

Functions

at_location(use, x, y)

@spec at_location(t(), String.t() | number(), String.t() | number()) :: t()

Set the location of the <use> element.

attributes(element)

attrs()

delete_dataset(elem, key)

Remove a dataset attribute

new(href)

@spec new(String.t()) :: t()

Create a new <use> element referencing an ID via href.

new(href, x, y)

@spec new(String.t(), String.t() | number(), String.t() | number()) :: t()

Create a new <use> element with href and position.

put_dataset(elem, key, value)

Set a dataset attribute. Mimics the DOM Element.dataset API. The key will be converted from camelCase to kebab-case for the data-* attribute.

Security

The key is converted to an atom at render time (required by :xmerl). Never pass untrusted/user-derived strings as key — unbounded distinct keys exhaust the atom table and crash the BEAM. Use static key names. value is safe and may be dynamic.

rendered_key(key)

with_alignment_baseline(elem, value)

@spec with_alignment_baseline(t(), term()) :: t()

Simple setter to put the value alignment-baseline onto the element

with_baseline_shift(elem, value)

@spec with_baseline_shift(t(), term()) :: t()

Simple setter to put the value baseline-shift onto the element

with_class(elem, value)

@spec with_class(t(), term()) :: t()

Simple setter to put the value class onto the element

with_clip_path(elem, value)

@spec with_clip_path(t(), term()) :: t()

Simple setter to put the value clip-path onto the element

with_clip_rule(elem, value)

@spec with_clip_rule(t(), term()) :: t()

Simple setter to put the value clip-rule onto the element

with_color(elem, value)

@spec with_color(t(), term()) :: t()

Simple setter to put the value color onto the element

with_color_interpolation(elem, value)

@spec with_color_interpolation(t(), term()) :: t()

Simple setter to put the value color-interpolation onto the element

with_color_interpolation_filters(elem, value)

@spec with_color_interpolation_filters(t(), term()) :: t()

Simple setter to put the value color-interpolation-filters onto the element

with_cursor(elem, value)

@spec with_cursor(t(), term()) :: t()

Simple setter to put the value cursor onto the element

with_dataset(elem, dataset)

@spec with_dataset(t(), term()) :: t()

Simple setter to put the value dataset onto the element

with_description(elem, content)

with_direction(elem, value)

@spec with_direction(t(), term()) :: t()

Simple setter to put the value direction onto the element

with_display(elem, value)

@spec with_display(t(), term()) :: t()

Simple setter to put the value display onto the element

with_dominant_baseline(elem, value)

@spec with_dominant_baseline(t(), term()) :: t()

Simple setter to put the value dominant-baseline onto the element

with_fill(elem, value)

@spec with_fill(t(), term()) :: t()

Simple setter to put the value fill onto the element

with_fill_opacity(elem, value)

@spec with_fill_opacity(t(), term()) :: t()

Simple setter to put the value fill-opacity onto the element

with_fill_rule(elem, value)

@spec with_fill_rule(t(), term()) :: t()

Simple setter to put the value fill-rule onto the element

with_filter(elem, value)

@spec with_filter(t(), term()) :: t()

Simple setter to put the value filter onto the element

with_flood_color(elem, value)

@spec with_flood_color(t(), term()) :: t()

Simple setter to put the value flood-color onto the element

with_flood_opacity(elem, value)

@spec with_flood_opacity(t(), term()) :: t()

Simple setter to put the value flood-opacity onto the element

with_font_family(elem, value)

@spec with_font_family(t(), term()) :: t()

Simple setter to put the value font-family onto the element

with_font_size(elem, value)

@spec with_font_size(t(), term()) :: t()

Simple setter to put the value font-size onto the element

with_font_size_adjust(elem, value)

@spec with_font_size_adjust(t(), term()) :: t()

Simple setter to put the value font-size-adjust onto the element

with_font_stretch(elem, value)

@spec with_font_stretch(t(), term()) :: t()

Simple setter to put the value font-stretch onto the element

with_font_style(elem, value)

@spec with_font_style(t(), term()) :: t()

Simple setter to put the value font-style onto the element

with_font_variant(elem, value)

@spec with_font_variant(t(), term()) :: t()

Simple setter to put the value font-variant onto the element

with_font_weight(elem, value)

@spec with_font_weight(t(), term()) :: t()

Simple setter to put the value font-weight onto the element

with_glyph_orientation_horizontal(elem, value)

@spec with_glyph_orientation_horizontal(t(), term()) :: t()

Simple setter to put the value glyph-orientation-horizontal onto the element

with_glyph_orientation_vertical(elem, value)

@spec with_glyph_orientation_vertical(t(), term()) :: t()

Simple setter to put the value glyph-orientation-vertical onto the element

with_height(elem, value)

@spec with_height(t(), term()) :: t()

Simple setter to put the value height onto the element

with_href(elem, value)

@spec with_href(t(), term()) :: t()

Simple setter to put the value href onto the element

with_id(elem, value)

@spec with_id(t(), term()) :: t()

Simple setter to put the value id onto the element

with_image_rendering(elem, value)

@spec with_image_rendering(t(), term()) :: t()

Simple setter to put the value image-rendering onto the element

with_letter_spacing(elem, value)

@spec with_letter_spacing(t(), term()) :: t()

Simple setter to put the value letter-spacing onto the element

with_lighting_color(elem, value)

@spec with_lighting_color(t(), term()) :: t()

Simple setter to put the value lighting-color onto the element

with_marker_end(elem, value)

@spec with_marker_end(t(), term()) :: t()

Simple setter to put the value marker-end onto the element

with_marker_mid(elem, value)

@spec with_marker_mid(t(), term()) :: t()

Simple setter to put the value marker-mid onto the element

with_marker_start(elem, value)

@spec with_marker_start(t(), term()) :: t()

Simple setter to put the value marker-start onto the element

with_mask(elem, value)

@spec with_mask(t(), term()) :: t()

Simple setter to put the value mask onto the element

with_mask_type(elem, value)

@spec with_mask_type(t(), term()) :: t()

Simple setter to put the value mask-type onto the element

with_opacity(elem, value)

@spec with_opacity(t(), term()) :: t()

Simple setter to put the value opacity onto the element

with_overflow(elem, value)

@spec with_overflow(t(), term()) :: t()

Simple setter to put the value overflow onto the element

with_paint_order(elem, value)

@spec with_paint_order(t(), term()) :: t()

Simple setter to put the value paint-order onto the element

with_pointer_events(elem, value)

@spec with_pointer_events(t(), term()) :: t()

Simple setter to put the value pointer-events onto the element

with_preserve_aspect_ratio(elem, value)

@spec with_preserve_aspect_ratio(t(), term()) :: t()

Simple setter to put the value preserveAspectRatio onto the element

with_shape_rendering(elem, value)

@spec with_shape_rendering(t(), term()) :: t()

Simple setter to put the value shape-rendering onto the element

with_size(use, width, height)

@spec with_size(t(), String.t() | number(), String.t() | number()) :: t()

Set the dimensions of the <use> element.

with_stop_color(elem, value)

@spec with_stop_color(t(), term()) :: t()

Simple setter to put the value stop-color onto the element

with_stop_opacity(elem, value)

@spec with_stop_opacity(t(), term()) :: t()

Simple setter to put the value stop-opacity onto the element

with_stroke(elem, value)

@spec with_stroke(t(), term()) :: t()

Simple setter to put the value stroke onto the element

with_stroke_dasharray(elem, value)

@spec with_stroke_dasharray(t(), term()) :: t()

Simple setter to put the value stroke-dasharray onto the element

with_stroke_dashoffset(elem, value)

@spec with_stroke_dashoffset(t(), term()) :: t()

Simple setter to put the value stroke-dashoffset onto the element

with_stroke_linecap(elem, value)

@spec with_stroke_linecap(t(), term()) :: t()

Simple setter to put the value stroke-linecap onto the element

with_stroke_linejoin(elem, value)

@spec with_stroke_linejoin(t(), term()) :: t()

Simple setter to put the value stroke-linejoin onto the element

with_stroke_miterlimit(elem, value)

@spec with_stroke_miterlimit(t(), term()) :: t()

Simple setter to put the value stroke-miterlimit onto the element

with_stroke_opacity(elem, value)

@spec with_stroke_opacity(t(), term()) :: t()

Simple setter to put the value stroke-opacity onto the element

with_stroke_width(elem, value)

@spec with_stroke_width(t(), term()) :: t()

Simple setter to put the value stroke-width onto the element

with_style(elem, styles)

@spec with_style(t(), term()) :: t()

Simple setter to put the value style onto the element

with_text_anchor(elem, value)

@spec with_text_anchor(t(), term()) :: t()

Simple setter to put the value text-anchor onto the element

with_text_decoration(elem, value)

@spec with_text_decoration(t(), term()) :: t()

Simple setter to put the value text-decoration onto the element

with_text_overflow(elem, value)

@spec with_text_overflow(t(), term()) :: t()

Simple setter to put the value text-overflow onto the element

with_text_rendering(elem, value)

@spec with_text_rendering(t(), term()) :: t()

Simple setter to put the value text-rendering onto the element

with_title(elem, content)

with_transform(elem, value)

@spec with_transform(t(), term()) :: t()

Simple setter to put the value transform onto the element

with_transform_origin(elem, value)

@spec with_transform_origin(t(), term()) :: t()

Simple setter to put the value transform-origin onto the element

with_unicode_bidi(elem, value)

@spec with_unicode_bidi(t(), term()) :: t()

Simple setter to put the value unicode-bidi onto the element

with_vector_effect(elem, value)

@spec with_vector_effect(t(), term()) :: t()

Simple setter to put the value vector-effect onto the element

with_view_box(elem, value)

@spec with_view_box(t(), term()) :: t()

Simple setter to put the value viewBox onto the element

with_view_box(elem, width, height)

with_view_box(elem, minx, miny, width, height)

with_visibility(elem, value)

@spec with_visibility(t(), term()) :: t()

Simple setter to put the value visibility onto the element

with_white_space(elem, value)

@spec with_white_space(t(), term()) :: t()

Simple setter to put the value white-space onto the element

with_width(elem, value)

@spec with_width(t(), term()) :: t()

Simple setter to put the value width onto the element

with_word_spacing(elem, value)

@spec with_word_spacing(t(), term()) :: t()

Simple setter to put the value word-spacing onto the element

with_writing_mode(elem, value)

@spec with_writing_mode(t(), term()) :: t()

Simple setter to put the value writing-mode onto the element

with_x(elem, value)

@spec with_x(t(), term()) :: t()

Simple setter to put the value x onto the element

with_y(elem, value)

@spec with_y(t(), term()) :: t()

Simple setter to put the value y onto the element