Class PathElement

java.lang.Object
com.vaadin.flow.dom.Node<com.vaadin.flow.dom.Element>
com.vaadin.flow.dom.Element
All Implemented Interfaces:
Serializable

public class PathElement extends SvgGraphicsElement
A typed Java API for the SVG <path> element.

The <path> element is the generic element to define a shape. All basic shapes can be created with a path element.

Use the d(String) method to set the path data directly, or use the fluent path builder methods like moveTo(double, double), lineTo(double, double), etc.

Write-Only vs Read-Write Methods

This class provides two variants for attribute setters:

  • Default methods (e.g., d(), pathLength()) - Use an optimized write-only approach. Attribute values are NOT stored on the server and cannot be retrieved via getAttribute().
  • RW methods (e.g., dRW(), pathLengthRW()) - Use traditional setAttribute() which stores values on the server for later retrieval.
See Also:
  • Constructor Details

    • PathElement

      public PathElement()
  • Method Details

    • d

      public PathElement d(String d)
      Sets the path data directly.

      This replaces any path data built using the fluent methods.

      Uses write-only optimization. Use dRW(String) if you need to read the value back.

      Parameters:
      d - the path data string
      Returns:
      this element for method chaining
    • dRW

      public PathElement dRW(String d)
      Sets the path data directly (read-write).

      This replaces any path data built using the fluent methods.

      Parameters:
      d - the path data string
      Returns:
      this element for method chaining
    • clear

      public PathElement clear()
      Clears the currently scheduled drawing commands.
      Returns:
      this element for method chaining
    • pathLength

      public PathElement pathLength(double pathLength)
      Sets the total length for the path in user units.

      Uses write-only optimization. Use pathLengthRW(double) if you need to read the value back.

      Parameters:
      pathLength - the total path length
      Returns:
      this element for method chaining
    • pathLengthRW

      public PathElement pathLengthRW(double pathLength)
      Sets the total length for the path in user units (read-write).
      Parameters:
      pathLength - the total path length
      Returns:
      this element for method chaining
    • moveTo

      public PathElement moveTo(double x, double y)
      Move to the specified point (absolute coordinates).

      Equivalent to the "M" command.

      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      this element for method chaining
    • moveToRelative

      public PathElement moveToRelative(double dx, double dy)
      Move to the specified point (relative coordinates).

      Equivalent to the "m" command.

      Parameters:
      dx - the relative x offset
      dy - the relative y offset
      Returns:
      this element for method chaining
    • lineTo

      public PathElement lineTo(double x, double y)
      Draw a line to the specified point (absolute coordinates).

      Equivalent to the "L" command.

      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      this element for method chaining
    • lineToRelative

      public PathElement lineToRelative(double dx, double dy)
      Draw a line to the specified point (relative coordinates).

      Equivalent to the "l" command.

      Parameters:
      dx - the relative x offset
      dy - the relative y offset
      Returns:
      this element for method chaining
    • horizontalLineTo

      public PathElement horizontalLineTo(double x)
      Draw a horizontal line to the specified x coordinate (absolute).

      Equivalent to the "H" command.

      Parameters:
      x - the x coordinate
      Returns:
      this element for method chaining
    • horizontalLineToRelative

      public PathElement horizontalLineToRelative(double dx)
      Draw a horizontal line by the specified offset (relative).

      Equivalent to the "h" command.

      Parameters:
      dx - the relative x offset
      Returns:
      this element for method chaining
    • verticalLineTo

      public PathElement verticalLineTo(double y)
      Draw a vertical line to the specified y coordinate (absolute).

      Equivalent to the "V" command.

      Parameters:
      y - the y coordinate
      Returns:
      this element for method chaining
    • verticalLineToRelative

      public PathElement verticalLineToRelative(double dy)
      Draw a vertical line by the specified offset (relative).

      Equivalent to the "v" command.

      Parameters:
      dy - the relative y offset
      Returns:
      this element for method chaining
    • closePath

      public PathElement closePath()
      Close the current path by drawing a straight line back to the start.

      Equivalent to the "Z" or "z" command.

      Returns:
      this element for method chaining
    • cubicBezierTo

      public PathElement cubicBezierTo(double x1, double y1, double x2, double y2, double x, double y)
      Draw a cubic Bézier curve (absolute coordinates).

      Equivalent to the "C" command.

      Parameters:
      x1 - x coordinate of the first control point
      y1 - y coordinate of the first control point
      x2 - x coordinate of the second control point
      y2 - y coordinate of the second control point
      x - x coordinate of the end point
      y - y coordinate of the end point
      Returns:
      this element for method chaining
    • cubicBezierToRelative

      public PathElement cubicBezierToRelative(double dx1, double dy1, double dx2, double dy2, double dx, double dy)
      Draw a cubic Bézier curve (relative coordinates).

      Equivalent to the "c" command.

      Parameters:
      dx1 - relative x offset of the first control point
      dy1 - relative y offset of the first control point
      dx2 - relative x offset of the second control point
      dy2 - relative y offset of the second control point
      dx - relative x offset of the end point
      dy - relative y offset of the end point
      Returns:
      this element for method chaining
    • smoothCubicBezierTo

      public PathElement smoothCubicBezierTo(double x2, double y2, double x, double y)
      Draw a smooth cubic Bézier curve (absolute coordinates).

      Equivalent to the "S" command. The first control point is assumed to be the reflection of the second control point of the previous command.

      Parameters:
      x2 - x coordinate of the second control point
      y2 - y coordinate of the second control point
      x - x coordinate of the end point
      y - y coordinate of the end point
      Returns:
      this element for method chaining
    • smoothCubicBezierToRelative

      public PathElement smoothCubicBezierToRelative(double dx2, double dy2, double dx, double dy)
      Draw a smooth cubic Bézier curve (relative coordinates).

      Equivalent to the "s" command.

      Parameters:
      dx2 - relative x offset of the second control point
      dy2 - relative y offset of the second control point
      dx - relative x offset of the end point
      dy - relative y offset of the end point
      Returns:
      this element for method chaining
    • quadraticBezierTo

      public PathElement quadraticBezierTo(double x1, double y1, double x, double y)
      Draw a quadratic Bézier curve (absolute coordinates).

      Equivalent to the "Q" command.

      Parameters:
      x1 - x coordinate of the control point
      y1 - y coordinate of the control point
      x - x coordinate of the end point
      y - y coordinate of the end point
      Returns:
      this element for method chaining
    • quadraticBezierToRelative

      public PathElement quadraticBezierToRelative(double dx1, double dy1, double dx, double dy)
      Draw a quadratic Bézier curve (relative coordinates).

      Equivalent to the "q" command.

      Parameters:
      dx1 - relative x offset of the control point
      dy1 - relative y offset of the control point
      dx - relative x offset of the end point
      dy - relative y offset of the end point
      Returns:
      this element for method chaining
    • smoothQuadraticBezierTo

      public PathElement smoothQuadraticBezierTo(double x, double y)
      Draw a smooth quadratic Bézier curve (absolute coordinates).

      Equivalent to the "T" command. The control point is assumed to be the reflection of the control point of the previous command.

      Parameters:
      x - x coordinate of the end point
      y - y coordinate of the end point
      Returns:
      this element for method chaining
    • smoothQuadraticBezierToRelative

      public PathElement smoothQuadraticBezierToRelative(double dx, double dy)
      Draw a smooth quadratic Bézier curve (relative coordinates).

      Equivalent to the "t" command.

      Parameters:
      dx - relative x offset of the end point
      dy - relative y offset of the end point
      Returns:
      this element for method chaining
    • arcTo

      public PathElement arcTo(double rx, double ry, double xAxisRotation, boolean largeArcFlag, boolean sweepFlag, double x, double y)
      Draw an elliptical arc (absolute coordinates).

      Equivalent to the "A" command.

      Parameters:
      rx - x radius of the ellipse
      ry - y radius of the ellipse
      xAxisRotation - rotation of the ellipse in degrees
      largeArcFlag - if true, draw the larger arc
      sweepFlag - if true, draw the arc in positive angle direction
      x - x coordinate of the end point
      y - y coordinate of the end point
      Returns:
      this element for method chaining
    • arcToRelative

      public PathElement arcToRelative(double rx, double ry, double xAxisRotation, boolean largeArcFlag, boolean sweepFlag, double dx, double dy)
      Draw an elliptical arc (relative coordinates).

      Equivalent to the "a" command.

      Parameters:
      rx - x radius of the ellipse
      ry - y radius of the ellipse
      xAxisRotation - rotation of the ellipse in degrees
      largeArcFlag - if true, draw the larger arc
      sweepFlag - if true, draw the arc in positive angle direction
      dx - relative x offset of the end point
      dy - relative y offset of the end point
      Returns:
      this element for method chaining
    • flushPendingAttributes

      protected void flushPendingAttributes()
      Overrides:
      flushPendingAttributes in class SvgElement