The <path> element is the most versatile SVG shape, capable of defining any shape.
It uses a "data" attribute (d) consisting of a series of commands that move
a virtual "pen" across the drawing surface.
Why use a Path?
While Circle and Rectangle are easier for simple shapes, <path> is necessary
for everything else: complex logos, icons, line charts, and organic shapes.
Because all other basic shapes can be represented as paths, many design tools
export everything as paths.
Path Commands: How they work
Move To(M/m): Lifts the pen and places it at a new coordinate.Line To(L/l): Draws a straight line from the current position.Horizontal/Vertical Line To(H/V): Shorthands for drawing straight lines along an axis.Bezier Curve(C/Q): Draws smooth curves using control points to influence the curve's direction.Elliptical Arc(A/a): Draws a portion of an ellipse. Useful for pie charts or rounded complex corners.Close Path(Z): Draws a straight line back to the start of the current sub-path.
Absolute vs. Relative: Uppercase commands (e.g., L) use coordinates
relative to the drawing's origin (0,0). Lowercase commands (e.g., l) use
coordinates relative to the last pen position.
Examples
# Draws a simple triangle
Vectored.Elements.Path.new()
|> Vectored.Elements.Path.move_to(10, 10)
|> Vectored.Elements.Path.line_to(90, 10)
|> Vectored.Elements.Path.line_to(50, 90)
|> Vectored.Elements.Path.close_path()
Summary
Functions
Append a raw command string to the path.
Close the current sub-path by drawing a straight line back to the start.
Draw a cubic Bezier curve.
Remove a dataset attribute
Draw an elliptical arc.
Draw a horizontal line to the given x-coordinate.
Draw a straight line from the current position to (x, y).
Move the pen to a new location without drawing a line.
Create a new path element.
Set a dataset attribute. Mimics the DOM Element.dataset API. The key will be converted from camelCase to kebab-case for the data-* attribute.
Draw a quadratic Bezier curve.
Draw a smooth cubic Bezier curve.
Draw a smooth quadratic Bezier curve.
Draw a vertical line to the given y-coordinate.
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 d 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 pathLength 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
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
@type paths() :: [String.t()]
@type t() :: %Vectored.Elements.Path{ 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(), d: paths(), 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: term(), href: term(), id: term(), image_rendering: term(), letter_spacing: term(), lighting_color: term(), marker_end: String.t() | nil, marker_mid: String.t() | nil, marker_start: String.t() | nil, mask: term(), mask_type: term(), opacity: term(), overflow: term(), paint_order: term(), path_length: String.t() | number() | nil, 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: term(), word_spacing: term(), writing_mode: term(), x: term(), y: term() }
Functions
Append a raw command string to the path.
Use this if you have an existing SVG path string you want to extend.
Close the current sub-path by drawing a straight line back to the start.
Always use this for shapes you intend to fill, as it ensures a clean closure.
Draw a cubic Bezier curve.
This is the "standard" curve. It uses two control points:
- (x1, y1) controls the "pull" from the start point.
- (x2, y2) controls the "pull" from the end point. (x, y) is where the curve ends.
Remove a dataset attribute
Draw an elliptical arc.
Arcs are complex but powerful.
Parameters
rx,ry: Radii of the ellipse the arc is part of.angle: How much the ellipse is rotated.large_arc_flag:1to draw the long way around,0for the short way.sweep_flag:1for clockwise,0for counter-clockwise.x,y: The end point.
Draw a horizontal line to the given x-coordinate.
Useful for drawing perfectly flat lines without worrying about the y-coordinate.
Draw a straight line from the current position to (x, y).
Equivalent to L (absolute) or l (relative).
Move the pen to a new location without drawing a line.
Equivalent to the M command. Always call this first in a new path.
Create a new path element.
You can optionally pass a list of initial path command strings.
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.
Draw a quadratic Bezier curve.
A simpler curve that uses only one control point (x1, y1) for the whole arc.
Draw a smooth cubic Bezier curve.
A shorthand that assumes the first control point is a reflection of the previous curve's last control point. Use this to keep curves perfectly smooth without math.
The SVG S/s command takes only the second control point x2,y2 and the
endpoint x,y; the first control point is inferred.
Draw a smooth quadratic Bezier curve.
The SVG T/t command takes only the endpoint x,y; the control point is
inferred as the reflection of the previous curve's control point.
Draw a vertical line to the given y-coordinate.
Useful for drawing perfectly vertical lines.
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 d 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 pathLength 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
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