Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Builder

A declarative SVG path builder

export
class

Builder

Hierarchy

  • Builder

Index

Properties

Private path

path: string = ""

Methods

Private ammend

  • ammend(value: string): void
  • A private function used to combine previous commands with path string.

    memberof

    Builder

    Parameters

    • value: string

      string to amend to current path string

    Returns void

arcTo

  • arcTo(rx: number, ry: number, xAxisRotation: number, largeArc: boolean, sweep: boolean, x: number, y: number): Builder
  • Arcs are sections of circles or ellipses. For a given x-radius and y-radius, there are two ellipses that can connect any two points (as long as they're within the radius of the circle). Along either of those circles there are two possible paths that you can take to connect the points, so in any situation there are four possible arcs available.
    At its start, the arc element takes in two arguments for the x-radius and y-radius. The final two arguments designate the x and y coordinates to end the stroke. Together, these four values define the basic structure of the arc.
    The third parameter describes the rotation of the arc.
    The fourth argument, is the large arc flag and simply determines if the arc should be greater than or less than 180 degrees; in the end, this flag determines which direction the arc will travel around a given circle.
    The fifth argument is the sweep-flag. It determines if the arc should begin moving at positive angles or negative ones, which essentially picks which of the two circles you will travel around.

    This uses absolute positioning.

    For relative positioning, see:
    arcToRel()

    Arc commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.arcTo(30, 50, 0, false, true, 165.55, 162.45).close();
    // => 'A 30 50 0 0 1 165.55 162.45 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.arcTo(30, 50, 0, false, true, 165.55, 162.45).close();
    // => 'A 30 50 0 0 1 165.55 162.45 z'
    memberof

    Builder

    Parameters

    • rx: number

      radius of the ellipse across the x axis

    • ry: number

      radius of the ellipse across the y axis

    • xAxisRotation: number

      rotation of the arc across the x axis

    • largeArc: boolean

      a value indicating whether or not the arc should be greater than 180deg or not

    • sweep: boolean

      a value indicating whether or not the arc should be moving in positive angles or not

    • x: number

      x coordinate of the ellipse

    • y: number

      y coordinate of the ellipse

    Returns Builder

    an instance of the current builder to chain from

arcToRel

  • arcToRel(rx: number, ry: number, xAxisRotation: number, largeArc: boolean, sweep: boolean, x: number, y: number): Builder
  • Arcs are sections of circles or ellipses. For a given x-radius and y-radius, there are two ellipses that can connect any two points (as long as they're within the radius of the circle). Along either of those circles there are two possible paths that you can take to connect the points, so in any situation there are four possible arcs available.
    At its start, the arc element takes in two arguments for the x-radius and y-radius. The final two arguments designate the x and y coordinates to end the stroke. Together, these four values define the basic structure of the arc.
    The third parameter describes the rotation of the arc.
    The fourth argument, is the large arc flag and simply determines if the arc should be greater than or less than 180 degrees; in the end, this flag determines which direction the arc will travel around a given circle.
    The fifth argument is the sweep-flag. It determines if the arc should begin moving at positive angles or negative ones, which essentially picks which of the two circles you will travel around.

    This uses relative positioning.

    For absolute positioning, see:
    arcTo()

    Arc commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.arcToRel(30, 50, 0, false, true, 165.55, 162.45).close();
    // => 'a 30 50 0 0 1 165.55 162.45 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.arcToRel(30, 50, 0, false, true, 165.55, 162.45).close();
    // => 'a 30 50 0 0 1 165.55 162.45 z'
    memberof

    Builder

    Parameters

    • rx: number

      radius of the ellipse across the x axis

    • ry: number

      radius of the ellipse across the y axis

    • xAxisRotation: number

      rotation of the arc across the x axis

    • largeArc: boolean

      a value indicating whether or not the arc should be greater than 180deg or not

    • sweep: boolean

      a value indicating whether or not the arc should be moving in positive angles or not

    • x: number

      x coordinate of the ellipse

    • y: number

      y coordinate of the ellipse

    Returns Builder

    an instance of the current builder to chain from

close

  • close(): string
  • Closes the path by amending a 'Z' and returning the string.

    memberof

    Builder

    Returns string

    A path as a string

cubicTo

  • cubicTo(x1: number, y1: number, x2: number, y2: number, x: number, y: number): Builder
  • Cubic Beziers take in two control points for each point. Therefore, to create a cubic Bezier, you need to specify three sets of coordinates.
    The last set of coordinates (x,y) are where you want the line to end. The other two are control points. (x1,y1) is the control point for the start of your curve, and (x2,y2) is the control point for the end. The control points essentially describe the slope of your line starting at each point. The Bezier function then creates a smooth curve that transfers you from the slope you established at the beginning of your line, to the slope at the other end.

    This uses absolute positioning.

    For relative positioning, see:
    cubicToRel()

    Curve commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.cubicTo(10, 10, 10, 10, 10, 10).close();
    // => 'C 10 10 10 10 10 10 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.cubicTo(10, 10, 10, 10, 10, 10).close();
    // => 'C 10 10 10 10 10 10 z'
    memberof

    Builder

    Parameters

    • x1: number

      x1 coordinate of the start control point

    • y1: number

      y1 coordinate of the start control point

    • x2: number

      x2 coordinate of the end control point

    • y2: number

      y2 coordinate of the end control point

    • x: number

      x coordinate of where to end the curve

    • y: number

      y coordinate of where to end the curve

    Returns Builder

    an instance of the current builder to chain from

cubicToRel

  • cubicToRel(x1: number, y1: number, x2: number, y2: number, x: number, y: number): Builder
  • Cubic Beziers take in two control points for each point. Therefore, to create a cubic Bezier, you need to specify three sets of coordinates.
    The last set of coordinates (x,y) are where you want the line to end. The other two are control points. (x1,y1) is the control point for the start of your curve, and (x2,y2) is the control point for the end. The control points essentially describe the slope of your line starting at each point. The Bezier function then creates a smooth curve that transfers you from the slope you established at the beginning of your line, to the slope at the other end.

    This uses relative positioning.

    For absolute positioning, see:
    cubicTo()

    Curve commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.cubicToRel(10, 10, 10, 10, 10, 10).close();
    // => 'c 10 10 10 10 10 10 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.cubicToRel(10, 10, 10, 10, 10, 10).close();
    // => 'c 10 10 10 10 10 10 z'
    memberof

    Builder

    Parameters

    • x1: number

      x1 coordinate of the start control point

    • y1: number

      y1 coordinate of the start control point

    • x2: number

      x2 coordinate of the end control point

    • y2: number

      y2 coordinate of the end control point

    • x: number

      x coordinate of where to end the curve

    • y: number

      y coordinate of where to end the curve

    Returns Builder

    an instance of the current builder to chain from

end

  • end(): string
  • Ends the path without amending a 'Z' and returning the string.

    memberof

    Builder

    Returns string

    A path as a string

horizontalTo

  • The "Horizontal To" command takes one parameter—x coordinate—and draws a line from the current position horizontally to a new position.

    This uses absolute positioning.

    For relative positioning, see:
    horizontalToRel()

    Line commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.horizontalTo(10).close();
    // => 'H 10 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.horizontalTo(10).close();
    // => 'H 10 z'
    memberof

    Builder

    Parameters

    • x: number

      x coordinate to draw a horizontal line on

    Returns Builder

    an instance of the current builder to chain from

horizontalToRel

  • horizontalToRel(x: number): Builder
  • The "Horizontal To" command takes one parameter—x coordinate—and draws a line from the current position horizontally to a new position.

    This uses relative positioning.

    For absolute positioning, see:
    horizontalTo()

    Line commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.horizontalToRel(10).close();
    // => 'h 10 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.horizontalToRel(10).close();
    // => 'h 10 z'
    memberof

    Builder

    Parameters

    • x: number

      x coordinate to draw a horizontal line on

    Returns Builder

    an instance of the current builder to chain from

lineTo

  • lineTo(x: number, y: number): Builder
  • The "Line To" command takes two parameters—x and y coordinates—and draws a line from the current position to a new position.

    This uses absolute positioning.

    For relative positioning, see:
    lineToRel()

    Line commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.lineTo(10, 10).close();
    // => 'L 10 10 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.lineTo(10, 10).close();
    // => 'L 10 10 z'
    memberof

    Builder

    Parameters

    • x: number

      x coordinate to draw a line to

    • y: number

      y coordinate to draw a line to

    Returns Builder

    an instance of the current builder to chain from

lineToRel

  • lineToRel(x: number, y: number): Builder
  • The "Line To" command takes two parameters—x and y coordinates—and draws a line from the current position to a new position.

    This uses relative positioning.

    For absolute positioning, see:
    lineTo()

    Line commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.lineToRel(10, 10).close();
    // => 'l 10 10 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.lineToRel(10, 10).close();
    // => 'l 10 10 z'
    memberof

    Builder

    Parameters

    • x: number

      x coordinate to draw a line to

    • y: number

      y coordinate to draw a line to

    Returns Builder

    an instance of the current builder to chain from

moveTo

  • moveTo(x: number, y: number): Builder
  • The "Move To" command appears at the beginning of paths to specify where the drawing should start.
    If your cursor already was somewhere on the page, no line is drawn to connect the two places.

    This uses absolute positioning.

    For relative positioning, see:
    moveToRel()

    Line commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.moveTo(10, 10).close();
    // => 'M 10 10 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.moveTo(10, 10).close();
    // => 'M 10 10 z'
    memberof

    Builder

    Parameters

    • x: number

      x coordinate to move pen to

    • y: number

      y coordinate to move pen to

    Returns Builder

    an instance of the current builder to chain from

moveToRel

  • moveToRel(x: number, y: number): Builder
  • The "Move To" command appears at the beginning of paths to specify where the drawing should start.
    If your cursor already was somewhere on the page, no line is drawn to connect the two places.

    This uses relative positioning.

    For absolute positioning, see: moveTo()

    Line commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.moveToRel(10, 10).close();
    // => 'm 10 10 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.moveToRel(10, 10).close();
    // => 'm 10 10 z'
    memberof

    Builder

    Parameters

    • x: number

      x coordinate to move pen to

    • y: number

      y coordinate to move pen to

    Returns Builder

    an instance of the current builder to chain from

quadStringTo

  • quadStringTo(x: number, y: number): Builder
  • The "Quadradic String To" command is a shortcut for stringing together multiple quadratic Beziers.
    This shortcut looks at the previous control point you used and infers a new one from it. This means that after your first control point, you can make fairly complex shapes by specifying only end points.
    This only works if the previous command was a "Quadratic To" or a "Quadradic String To" command. If it is not, then the control point is assumed to be the same as the previous point, and you'll only draw lines.

    This uses absolute positioning.

    For relative positioning, see:
    quadStringToRel()

    Curve commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.quadStringTo(180, 80).close();
    // => 'T 180 80 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.quadStringTo(180, 80).close();
    // => 'T 180 80 z'
    memberof

    Builder

    Parameters

    • x: number

      x coordinate of where to end the curve

    • y: number

      y coordinate of where to end the curve

    Returns Builder

    an instance of the current builder to chain from

quadStringToRel

  • quadStringToRel(x: number, y: number): Builder
  • The "Quadradic String To" command is a shortcut for stringing together multiple quadratic Beziers.
    This shortcut looks at the previous control point you used and infers a new one from it. This means that after your first control point, you can make fairly complex shapes by specifying only end points.
    This only works if the previous command was a "Quadratic To" or a "Quadradic String To" command. If it is not, then the control point is assumed to be the same as the previous point, and you'll only draw lines.

    This uses relative positioning.

    For absolute positioning, see:
    quadStringTo()

    Curve commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.quadStringToRel(180, 80).close();
    // => 't 180 80 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.quadStringToRel(180, 80).close();
    // => 't 180 80 z'
    memberof

    Builder

    Parameters

    • x: number

      x coordinate of where to end the curve

    • y: number

      y coordinate of where to end the curve

    Returns Builder

    an instance of the current builder to chain from

quadTo

  • quadTo(x1: number, y1: number, x: number, y: number): Builder
  • The "Quadradic To" command produces the same type of curve as the Cubic Bezier, requires one control point which determines the slope of the curve at both the start point and the end point. It takes two arguments: the control point and the end point of the curve.

    This uses absolute positioning.

    For relative positioning, see:
    quadToRel()

    Curve commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.quadTo(10, 10, 10, 10).close();
    // => 'Q 10 10 10 10 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.quadTo(10, 10, 10, 10).close();
    // => 'Q 10 10 10 10 z'
    memberof

    Builder

    Parameters

    • x1: number

      x2 coordinate of the control point

    • y1: number

      y2 coordinate of the control point

    • x: number

      x coordinate of where to end the curve

    • y: number

      y coordinate of where to end the curve

    Returns Builder

    an instance of the current builder to chain from

quadToRel

  • quadToRel(x1: number, y1: number, x: number, y: number): Builder
  • The "Quadradic To" command produces the same type of curve as the Cubic Bezier, requires one control point which determines the slope of the curve at both the start point and the end point. It takes two arguments: the control point and the end point of the curve.

    This uses relative positioning.

    For absolute positioning, see:
    quadTo()

    Curve commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.quadToRel(10, 10, 10, 10).close();
    // => 'q 10 10 10 10 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.quadToRel(10, 10, 10, 10).close();
    // => 'q 10 10 10 10 z'
    memberof

    Builder

    Parameters

    • x1: number

      x2 coordinate of the control point

    • y1: number

      y2 coordinate of the control point

    • x: number

      x coordinate of where to end the curve

    • y: number

      y coordinate of where to end the curve

    Returns Builder

    an instance of the current builder to chain from

smoothTo

  • smoothTo(x2: number, y2: number, x: number, y: number): Builder
  • The "Smooth To" command produces the same type of curve as the Cubic Bezier, but if it follows another "Smooth To" command or a "Cubic Bezier" command, the first control point is assumed to be a reflection of the one used previously. If the "Smooth To" command doesn't follow another "Smooth To" command or "Cubic Bezier" command, then the current position of the cursor is used as the first control point.

    This uses absolute positioning.

    For relative positioning, see:
    smoothToRel()

    Curve commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.smoothTo(10, 10, 10, 10).close();
    // => 'S 10 10 10 10 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.smoothTo(10, 10, 10, 10).close();
    // => 'S 10 10 10 10 z'
    memberof

    Builder

    Parameters

    • x2: number

      x2 coordinate of the end control point

    • y2: number

      y2 coordinate of the end control point

    • x: number

      x coordinate of where to end the curve

    • y: number

      y coordinate of where to end the curve

    Returns Builder

    an instance of the current builder to chain from

smoothToRel

  • smoothToRel(x2: number, y2: number, x: number, y: number): Builder
  • The "Smooth To" command produces the same type of curve as the Cubic Bezier, but if it follows another "Smooth To" command or a "Cubic Bezier" command, the first control point is assumed to be a reflection of the one used previously. If the "Smooth To" command doesn't follow another "Smooth To" command or "Cubic Bezier" command, then the current position of the cursor is used as the first control point.

    This uses relative positioning.

    For absolute positioning, see:
    smoothTo()

    Curve commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.smoothToRel(10, 10, 10, 10).close();
    // => 's 10 10 10 10 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.smoothToRel(10, 10, 10, 10).close();
    // => 's 10 10 10 10 z'
    memberof

    Builder

    Parameters

    • x2: number

      x2 coordinate of the end control point

    • y2: number

      y2 coordinate of the end control point

    • x: number

      x coordinate of where to end the curve

    • y: number

      y coordinate of where to end the curve

    Returns Builder

    an instance of the current builder to chain from

verticalTo

  • The "Vertical To" command takes one parameter—y coordinate—and draws a line from the current position vertically to a new position.

    This uses absolute positioning.

    For relative positioning, see:
    verticalToRel()

    Line commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.verticalTo(10).close();
    // => 'V 10 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.verticalTo(10).close();
    // => 'V 10 z'
    memberof

    Builder

    Parameters

    • y: number

      y coordinate to draw a vertical line on

    Returns Builder

    an instance of the current builder to chain from

verticalToRel

  • verticalToRel(x: number): Builder
  • The "Vertical To" command takes one parameter—y coordinate—and draws a line from the current position vertically to a new position.

    This uses relative positioning.

    For absolute positioning, see:
    verticalTo()

    Line commands - MSD web docs

    Example (es imports)

    import Builder from 'svg-builder-js'
    const builder = new Builder();
    const path = builder.verticalToRel(10).close();
    // => 'v 10 z'

    Example (commonjs)

    var Builder = require('svg-builder-js').Builder;
    const builder = new Builder();
    const path = builder.verticalToRel(10).close();
    // => 'v 10 z'
    memberof

    Builder

    Parameters

    • x: number

    Returns Builder

    an instance of the current builder to chain from

Generated using TypeDoc