Class: Polygon

fabric. Polygon

new Polygon() §

Polygon class
Source:
See:

Extends

Members

<static> ATTRIBUTE_NAMES §

List of attribute names to account for when parsing SVG element (used by `fabric.Polygon.fromElement`)
Source:

angle :Number §

Angle of rotation of an object (in degrees)
Type:
  • Number
Inherited From:
Default Value:
  • 0
Source:

backgroundColor :String §

Background color of an object. Only works with text objects at the moment.
Type:
  • String
Inherited From:
Source:

borderColor :String §

Color of controlling borders of an object (when it's active)
Type:
  • String
Inherited From:
Default Value:
  • "rgba(102,153,255,0.75)"
Source:

borderOpacityWhenMoving :Number §

Opacity of object's controlling borders when object is active and moving
Type:
  • Number
Inherited From:
Default Value:
  • 0.4
Source:

borderScaleFactor :Number §

Scale factor of object's controlling borders
Type:
  • Number
Inherited From:
Default Value:
  • 1
Source:

centeredRotation :Boolean §

When true, this object will use center point as the origin of transformation when being rotated via the controls. Backwards incompatibility note: This property replaces "centerTransform" (Boolean).
Type:
  • Boolean
Since:
  • 1.3.4
Inherited From:
Default Value:
  • true
Source:

centeredScaling :Boolean §

When true, this object will use center point as the origin of transformation when being scaled via the controls. Backwards incompatibility note: This property replaces "centerTransform" (Boolean).
Type:
  • Boolean
Since:
  • 1.3.4
Inherited From:
Default Value:
  • false
Source:

clipTo :Function §

Function that determines clipping of an object (context is passed as a first argument) Note that context origin is at the object's center point (not left/top corner)
Type:
Inherited From:
Source:

cornerColor :String §

Color of controlling corners of an object (when it's active)
Type:
  • String
Inherited From:
Default Value:
  • "rgba(102,153,255,0.5)"
Source:

cornerSize :Number §

Size of object's controlling corners (in pixels)
Type:
  • Number
Inherited From:
Default Value:
  • 12
Source:

evented :Boolean §

When set to `false`, an object can not be a target of events. All events propagate through it. Introduced in v1.3.4
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

fill :String §

Color of object's fill
Type:
  • String
Inherited From:
Default Value:
  • "rgb(0,0,0)"
Source:

fillRule :String §

Fill rule used to fill an object
Type:
  • String
Inherited From:
Default Value:
  • "source-over"
Source:

flipX :Boolean §

When true, an object is rendered as flipped horizontally
Type:
  • Boolean
Inherited From:
Default Value:
  • false
Source:

flipY :Boolean §

When true, an object is rendered as flipped vertically
Type:
  • Boolean
Inherited From:
Default Value:
  • false
Source:

hasBorders :Boolean §

When set to `false`, object's controlling borders are not rendered
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

hasControls :Boolean §

When set to `false`, object's controls are not displayed and can not be used to manipulate object
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

hasRotatingPoint :Boolean §

When set to `false`, object's controlling rotating point will not be visible or selectable
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

hoverCursor :String §

Default cursor value used when hovering over this object on canvas
Type:
  • String
Inherited From:
Default Value:
  • null
Source:

includeDefaultValues :Boolean §

When `false`, default object's values are not included in its serialization
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

left :Number §

Left position of an object. Note that by default it's relative to object center. You can change this by setting originX={left/center/right}
Type:
  • Number
Inherited From:
Default Value:
  • 0
Source:

lockMovementX :Boolean §

When `true`, object horizontal movement is locked
Type:
  • Boolean
Inherited From:
Default Value:
  • false
Source:

lockMovementY :Boolean §

When `true`, object vertical movement is locked
Type:
  • Boolean
Inherited From:
Default Value:
  • false
Source:

lockRotation :Boolean §

When `true`, object rotation is locked
Type:
  • Boolean
Inherited From:
Default Value:
  • false
Source:

lockScalingX :Boolean §

When `true`, object horizontal scaling is locked
Type:
  • Boolean
Inherited From:
Default Value:
  • false
Source:

lockScalingY :Boolean §

When `true`, object vertical scaling is locked
Type:
  • Boolean
Inherited From:
Default Value:
  • false
Source:

lockUniScaling :Boolean §

When `true`, object non-uniform scaling is locked
Type:
  • Boolean
Inherited From:
Default Value:
  • false
Source:

minScaleLimit :Number §

Minimum allowed scale value of an object
Type:
  • Number
Inherited From:
Default Value:
  • 0.01
Source:

oCoords :Object §

Object containing coordinates of object's controls
Type:
  • Object
Inherited From:
Default Value:
  • null
Source:

opacity :Number §

Opacity of an object
Type:
  • Number
Inherited From:
Default Value:
  • 1
Source:

originX :String §

Horizontal origin of transformation of an object (one of "left", "right", "center")
Type:
  • String
Inherited From:
Default Value:
  • "left"
Source:

originY :String §

Vertical origin of transformation of an object (one of "top", "bottom", "center")
Type:
  • String
Inherited From:
Default Value:
  • "top"
Source:

padding :Number §

Padding between object and its controlling borders (in pixels)
Type:
  • Number
Inherited From:
Default Value:
  • 0
Source:

perPixelTargetFind :Boolean §

When set to `true`, objects are "found" on canvas on per-pixel basis rather than according to bounding box
Type:
  • Boolean
Inherited From:
Default Value:
  • false
Source:

points :Array §

Points array
Type:
Default Value:
  • null
Source:

rotatingPointOffset :Number §

Offset for object's controlling rotating point (when enabled via `hasRotatingPoint`)
Type:
  • Number
Inherited From:
Default Value:
  • 40
Source:

scaleX :Number §

Object scale factor (horizontal)
Type:
  • Number
Inherited From:
Default Value:
  • 1
Source:

scaleY :Number §

Object scale factor (vertical)
Type:
  • Number
Inherited From:
Default Value:
  • 1
Source:

selectable :Boolean §

When set to `false`, an object can not be selected for modification (using either point-click-based or group-based selection). But events still fire on it.
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

shadow :fabric.Shadow §

Shadow object representing shadow of this shape
Type:
Inherited From:
Default Value:
  • null
Source:

stateProperties :Array §

List of properties to consider when checking if state of an object is changed (fabric.Object#hasStateChanged) as well as for history (undo/redo) purposes
Type:
Inherited From:
Source:

stroke :String §

When defined, an object is rendered via stroke and this property specifies its color
Type:
  • String
Inherited From:
Default Value:
  • null
Source:

strokeDashArray :Array §

Array specifying dash pattern of an object's stroke (stroke must be defined)
Type:
Inherited From:
Source:

strokeLineCap :String §

Line endings style of an object's stroke (one of "butt", "round", "square")
Type:
  • String
Inherited From:
Default Value:
  • "butt"
Source:

strokeLineJoin :String §

Corner style of an object's stroke (one of "bevil", "round", "miter")
Type:
  • String
Inherited From:
Default Value:
  • "miter"
Source:

strokeMiterLimit :Number §

Maximum miter length (used for strokeLineJoin = "miter") of an object's stroke
Type:
  • Number
Inherited From:
Default Value:
  • 10
Source:

strokeWidth :Number §

Width of a stroke used to render this object
Type:
  • Number
Inherited From:
Default Value:
  • 1
Source:

top :Number §

Top position of an object. Note that by default it's relative to object center. You can change this by setting originY={top/center/bottom}
Type:
  • Number
Inherited From:
Default Value:
  • 0
Source:

transformMatrix :Array §

Transform matrix (similar to SVG's transform matrix)
Type:
Inherited From:
Source:

transparentCorners :Boolean §

When true, object's controlling corners are rendered as transparent inside (i.e. stroke instead of fill)
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

type :String §

Type of an object
Type:
  • String
Default Value:
  • "polygon"
Source:

visible :Boolean §

When set to `false`, an object is not rendered on canvas
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

Methods

<static> fromElement(element, options) → {fabric.Polygon} §

Returns fabric.Polygon instance from an SVG element
Parameters:
Name Type Argument Description
element SVGElement Element to parse
options Object <optional>
Options object
Source:
Returns:
Instance of fabric.Polygon
Type
fabric.Polygon

<static> fromObject(object) → {fabric.Polygon} §

Returns fabric.Polygon instance from an object representation
Parameters:
Name Type Description
object Object Object to create an instance from
Source:
Returns:
Instance of fabric.Polygon
Type
fabric.Polygon

_renderControls(ctx, noTransform) §

Renders controls and borders for the object
Parameters:
Name Type Argument Description
ctx CanvasRenderingContext2D Context to render on
noTransform Boolean <optional>
When true, context is not transformed
Inherited From:
Source:

_restoreFillRule(ctx) §

Restores previously saved canvas globalCompositeOperation after obeject rendering
Parameters:
Name Type Description
ctx CanvasRenderingContext2D Rendering canvas context
Inherited From:
Source:

_setupFillRule(ctx) §

Sets canvas globalCompositeOperation for specific object custom composition operation for the particular object can be specifed using fillRule property
Parameters:
Name Type Description
ctx CanvasRenderingContext2D Rendering canvas context
Inherited From:
Source:

adjustPosition(to) §

Parameters:
Name Type Description
to String One of 'left', 'center', 'right'
Inherited From:
Source:

animate(property, value) → {fabric.Object} §

Animates object's properties
Parameters:
Name Type Description
property String | Object to animate (if string) or properties to animate (if object)
value Number | Object to animate property to (if string was given first) or options object
Inherited From:
Source:
Tutorials:
Returns:
thisArg
Type
fabric.Object

bringForward(intersecting) → {fabric.Object} §

Moves an object up in stack of drawn objects
Parameters:
Name Type Argument Description
intersecting Boolean <optional>
If `true`, send object in front of next upper intersecting object
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

bringToFront() → {fabric.Object} §

Moves an object to the top of the stack of drawn objects
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

center() → {fabric.Object} §

Centers object vertically and horizontally on canvas to which is was added last You might need to call `setCoords` on an object after centering, to update controls area.
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

centerH() → {fabric.Object} §

Centers object horizontally on canvas to which it was added last. You might need to call `setCoords` on an object after centering, to update controls area.
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

centerV() → {fabric.Object} §

Centers object vertically on canvas to which it was added last. You might need to call `setCoords` on an object after centering, to update controls area.
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

clone(callback, propertiesToInclude) → {fabric.Object} §

Clones an instance
Parameters:
Name Type Argument Description
callback Function Callback is invoked with a clone as a first argument
propertiesToInclude Array <optional>
Any properties that you might want to additionally include in the output
Inherited From:
Source:
Returns:
clone of an instance
Type
fabric.Object

cloneAsImage(callback) → {fabric.Object} §

Creates an instance of fabric.Image out of an object
Parameters:
Name Type Description
callback Function callback, invoked with an instance as a first argument
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

complexity() → {Number} §

Returns complexity of an instance
Source:
Returns:
complexity of this instance
Type
Number

containsPoint(point) → {Boolean} §

Checks if point is inside the object
Parameters:
Name Type Description
point fabric.Point Point to check against
Inherited From:
Source:
Returns:
true if point is inside the object
Type
Boolean

drawBorders(ctx) → {fabric.Object} §

Draws borders of an object's bounding box. Requires public properties: width, height Requires public options: padding, borderColor
Parameters:
Name Type Description
ctx CanvasRenderingContext2D Context to draw on
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

drawControls(ctx) → {fabric.Object} §

Draws corners of an object's bounding box. Requires public properties: width, height Requires public options: cornerSize, padding
Parameters:
Name Type Description
ctx CanvasRenderingContext2D Context to draw on
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

fxStraighten(callbacks) → {fabric.Object} §

Same as fabric.Object.prototype.straighten but with animation
Parameters:
Name Type Description
callbacks Object Object with callback functions
Properties
Name Type Argument Description
onComplete Function <optional>
Invoked on completion
onChange Function <optional>
Invoked on every step of animation
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

get(property) → {Any} §

Basic getter
Parameters:
Name Type Description
property String Property name
Inherited From:
Source:
Returns:
value of a property
Type
Any

getAngle() → {Number} §

Retrieves object's angle (in degrees)
Inherited From:
Source:
Returns:
Type
Number

getBoundingRect() → {Object} §

Returns coordinates of object's bounding rectangle (left, top, width, height)
Inherited From:
Source:
Returns:
Object with left, top, width, height properties
Type
Object

getBoundingRectHeight() → {Number} §

Returns height of an object's bounding rectangle
Inherited From:
Deprecated:
  • since 1.0.4
    Source:
    Returns:
    height value
    Type
    Number

    getBoundingRectWidth() → {Number} §

    Returns width of an object's bounding rectangle
    Inherited From:
    Deprecated:
    • since 1.0.4
      Source:
      Returns:
      width value
      Type
      Number

      getCenterPoint() → {fabric.Point} §

      Returns the real center coordinates of the object
      Inherited From:
      Source:
      Returns:
      Type
      fabric.Point

      getClipTo() → {Function} §

      Retrieves object's clipping function
      Inherited From:
      Source:
      Returns:
      Type
      Function

      getFill() → {String} §

      Retrieves object's fill
      Inherited From:
      Source:
      Returns:
      Fill value
      Type
      String

      getFlipX() → {Boolean} §

      Retrieves object's flipX value
      Inherited From:
      Source:
      Returns:
      flipX value
      Type
      Boolean

      getFlipY() → {Boolean} §

      Retrieves object's flipY value
      Inherited From:
      Source:
      Returns:
      flipY value
      Type
      Boolean

      getHeight() → {Number} §

      Returns height of an object
      Inherited From:
      Source:
      Returns:
      height value
      Type
      Number

      getLeft() → {Number} §

      Retrieves object's left position
      Inherited From:
      Source:
      Returns:
      Left value (in pixels)
      Type
      Number

      getLocalPointer(e, pointer) → {Object} §

      Returns coordinates of a pointer relative to an object
      Parameters:
      Name Type Argument Description
      e Event Event to operate upon
      pointer Object <optional>
      Pointer to operate upon (instead of event)
      Inherited From:
      Source:
      Returns:
      Coordinates of a pointer (x, y)
      Type
      Object

      getOpacity() → {Number} §

      Retrieves object's opacity
      Inherited From:
      Source:
      Returns:
      Opacity value (0-1)
      Type
      Number

      getOriginX() → {String} §

      Retrieves object's originX
      Inherited From:
      Source:
      Returns:
      originX value
      Type
      String

      getOriginY() → {String} §

      Retrieves object's originY
      Inherited From:
      Source:
      Returns:
      originY value
      Type
      String

      getPointByOrigin(originX, originY) → {fabric.Point} §

      Returns the coordinates of the object as if it has a different origin
      Parameters:
      Name Type Description
      originX String Horizontal origin: 'left', 'center' or 'right'
      originY String Vertical origin: 'top', 'center' or 'bottom'
      Inherited From:
      Source:
      Returns:
      Type
      fabric.Point

      getScaleX() → {Number} §

      Retrieves object's scaleX value
      Inherited From:
      Source:
      Returns:
      scaleX value
      Type
      Number

      getScaleY() → {Number} §

      Retrieves object's scaleY value
      Inherited From:
      Source:
      Returns:
      scaleY value
      Type
      Number

      getShadow() → {Object} §

      Retrieves object's shadow
      Inherited From:
      Source:
      Returns:
      Shadow instance
      Type
      Object

      getStroke() → {String} §

      Retrieves object's stroke
      Inherited From:
      Source:
      Returns:
      stroke value
      Type
      String

      getStrokeWidth() → {Number} §

      Retrieves object's strokeWidth
      Inherited From:
      Source:
      Returns:
      strokeWidth value
      Type
      Number

      getSvgStyles() → {String} §

      Returns styles-string for svg-export
      Inherited From:
      Source:
      Returns:
      Type
      String

      getSvgTransform() → {String} §

      Returns transform-string for svg-export
      Inherited From:
      Source:
      Returns:
      Type
      String

      getTop() → {Number} §

      Retrieves object's top position
      Inherited From:
      Source:
      Returns:
      Top value (in pixels)
      Type
      Number

      getTransformMatrix() → {Array} §

      Retrieves object's transformMatrix
      Inherited From:
      Source:
      Returns:
      transformMatrix
      Type
      Array

      getViewportTransform() → {Boolean} §

      Retrieves viewportTransform from Object's canvas if possible
      Inherited From:
      Source:
      Returns:
      flipY value // TODO
      Type
      Boolean

      getVisible() → {Boolean} §

      Retrieves object's visible state
      Inherited From:
      Source:
      Returns:
      True if visible
      Type
      Boolean

      getWidth() → {Number} §

      Returns width of an object
      Inherited From:
      Source:
      Returns:
      width value
      Type
      Number

      hasStateChanged() → {Boolean} §

      Returns true if object state (one of its state properties) was changed
      Inherited From:
      Source:
      Returns:
      true if instance' state has changed since `fabric.Object#saveState` was called
      Type
      Boolean

      initialize(points, options, skipOffset) → {fabric.Polygon} §

      Constructor
      Parameters:
      Name Type Argument Description
      points Array Array of points
      options Object <optional>
      Options object
      skipOffset Boolean <optional>
      Whether points offsetting should be skipped
      Source:
      Returns:
      thisArg
      Type
      fabric.Polygon

      intersectsWithObject(other) → {Boolean} §

      Checks if object intersects with another object
      Parameters:
      Name Type Description
      other Object Object to test
      Inherited From:
      Source:
      Returns:
      true if object intersects with another object
      Type
      Boolean

      intersectsWithRect(pointTL, pointBR) → {Boolean} §

      Checks if object intersects with an area formed by 2 points
      Parameters:
      Name Type Description
      pointTL Object top-left point of area
      pointBR Object bottom-right point of area
      Inherited From:
      Source:
      Returns:
      true if object intersects with an area formed by 2 points
      Type
      Boolean

      isContainedWithinObject(other) → {Boolean} §

      Checks if object is fully contained within area of another object
      Parameters:
      Name Type Description
      other Object Object to test
      Inherited From:
      Source:
      Returns:
      true if object is fully contained within area of another object
      Type
      Boolean

      isContainedWithinRect(pointTL, pointBR) → {Boolean} §

      Checks if object is fully contained within area formed by 2 points
      Parameters:
      Name Type Description
      pointTL Object top-left point of area
      pointBR Object bottom-right point of area
      Inherited From:
      Source:
      Returns:
      true if object is fully contained within area formed by 2 points
      Type
      Boolean

      isControlVisible(controlName) → {Boolean} §

      Returns true if the specified control is visible, false otherwise.
      Parameters:
      Name Type Description
      controlName String The name of the control. Possible values are 'tl', 'tr', 'br', 'bl', 'ml', 'mt', 'mr', 'mb', 'mtr'.
      Inherited From:
      Source:
      Returns:
      true if the specified control is visible, false otherwise
      Type
      Boolean

      isType(type) → {Boolean} §

      Returns true if specified type is identical to the type of an instance
      Parameters:
      Name Type Description
      type String Type to check against
      Inherited From:
      Source:
      Returns:
      Type
      Boolean

      moveTo(index) → {fabric.Object} §

      Moves an object to specified level in stack of drawn objects
      Parameters:
      Name Type Description
      index Number New position of object
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      remove() → {fabric.Object} §

      Removes object from canvas to which it was added last
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      render(ctx, noTransform) §

      Renders an object on a specified context
      Parameters:
      Name Type Argument Description
      ctx CanvasRenderingContext2D Context to render on
      noTransform Boolean <optional>
      When true, context is not transformed
      Inherited From:
      Source:

      saveState(options) → {fabric.Object} §

      Saves state of an object
      Parameters:
      Name Type Argument Description
      options Object <optional>
      Object with additional `stateProperties` array to include when saving state
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      scale(value) → {fabric.Object} §

      Scales an object (equally by x and y)
      Parameters:
      Name Type Description
      value Number Scale factor
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      scaleToHeight(value) → {fabric.Object} §

      Scales an object to a given height, with respect to bounding box (scaling by x/y equally)
      Parameters:
      Name Type Description
      value Number New height value
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      scaleToWidth(value) → {fabric.Object} §

      Scales an object to a given width, with respect to bounding box (scaling by x/y equally)
      Parameters:
      Name Type Description
      value Number New width value
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      sendBackwards(intersecting) → {fabric.Object} §

      Moves an object down in stack of drawn objects
      Parameters:
      Name Type Argument Description
      intersecting Boolean <optional>
      If `true`, send object behind next lower intersecting object
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      sendToBack() → {fabric.Object} §

      Moves an object to the bottom of the stack of drawn objects
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      set(key, value) → {fabric.Object} §

      Sets property to a given value. When changing position/dimension -related properties (left, top, scale, angle, etc.) `set` does not update position of object's borders/controls. If you need to update those, call `setCoords()`.
      Parameters:
      Name Type Description
      key String | Object Property name or object (if object, iterate over the object properties)
      value Object | Function Property value (if function, the value is passed into it and its return value is used as a new one)
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setAngle(value) → {fabric.Object} §

      Sets object's angle
      Parameters:
      Name Type Description
      value Number Angle value (in degrees)
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setAngle(angle) → {fabric.Object} §

      Sets "angle" of an instance
      Parameters:
      Name Type Description
      angle Number Angle value
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setClipTo(clipTo) → {fabric.Object} §

      Sets object's clipping function
      Parameters:
      Name Type Description
      clipTo Function Clipping function
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setColor(color) → {fabric.Object} §

      Sets "color" of an instance (alias of `set('fill', …)`)
      Parameters:
      Name Type Description
      color String Color value
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setControlsVisibility(options) → {fabric.Object} §

      Sets the visibility state of object controls.
      Parameters:
      Name Type Argument Description
      options Object <optional>
      Options object
      Properties
      Name Type Argument Description
      bl Boolean <optional>
      true to enable the bottom-left control, false to disable it
      br Boolean <optional>
      true to enable the bottom-right control, false to disable it
      mb Boolean <optional>
      true to enable the middle-bottom control, false to disable it
      ml Boolean <optional>
      true to enable the middle-left control, false to disable it
      mr Boolean <optional>
      true to enable the middle-right control, false to disable it
      mt Boolean <optional>
      true to enable the middle-top control, false to disable it
      tl Boolean <optional>
      true to enable the top-left control, false to disable it
      tr Boolean <optional>
      true to enable the top-right control, false to disable it
      mtr Boolean <optional>
      true to enable the middle-top-rotate control, false to disable it
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setControlVisible(controlName, visible) → {fabric.Object} §

      Sets the visibility of the specified control.
      Parameters:
      Name Type Description
      controlName String The name of the control. Possible values are 'tl', 'tr', 'br', 'bl', 'ml', 'mt', 'mr', 'mb', 'mtr'.
      visible Boolean true to set the specified control visible, false otherwise
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setCoords() → {fabric.Object} §

      Sets corner position coordinates based on current angle, width and height
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setFill(value) → {fabric.Object} §

      Sets object's fill
      Parameters:
      Name Type Description
      value String Fill value
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setFlipX(value) → {fabric.Object} §

      Sets object's flipX value
      Parameters:
      Name Type Description
      value Boolean flipX value
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setFlipY(value) → {fabric.Object} §

      Sets object's flipY value
      Parameters:
      Name Type Description
      value Boolean flipY value
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setGradient(property, options) → {fabric.Object} §

      Sets gradient (fill or stroke) of an object Backwards incompatibility note: This method was named "setGradientFill" until v1.1.0
      Parameters:
      Name Type Argument Description
      property String Property name 'stroke' or 'fill'
      options Object <optional>
      Options object
      Properties
      Name Type Argument Default Description
      type String <optional>
      Type of gradient 'radial' or 'linear'
      x1 Number <optional>
      0 x-coordinate of start point
      y1 Number <optional>
      0 y-coordinate of start point
      x2 Number <optional>
      0 x-coordinate of end point
      y2 Number <optional>
      0 y-coordinate of end point
      r1 Number <optional>
      0 Radius of start point (only for radial gradients)
      r2 Number <optional>
      0 Radius of end point (only for radial gradients)
      colorStops Object <optional>
      Color stops object eg. {0: 'ff0000', 1: '000000'}
      Inherited From:
      Source:
      See:
      Returns:
      thisArg
      Type
      fabric.Object
      Examples

      Set linear gradient

      object.setGradient('fill', {
        type: 'linear',
        x1: -object.width / 2,
        y1: 0,
        x2: object.width / 2,
        y2: 0,
        colorStops: {
          0: 'red',
          0.5: '#005555',
          1: 'rgba(0,0,255,0.5)'
        }
      });
      canvas.renderAll();

      Set radial gradient

      object.setGradient('fill', {
        type: 'radial',
        x1: 0,
        y1: 0,
        x2: 0,
        y2: 0,
        r1: object.width / 2,
        r2: 10,
        colorStops: {
          0: 'red',
          0.5: '#005555',
          1: 'rgba(0,0,255,0.5)'
        }
      });
      canvas.renderAll();

      setLeft(value) → {fabric.Object} §

      Sets object's left position
      Parameters:
      Name Type Description
      value Number Left value (in pixels)
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setOpacity(value) → {fabric.Object} §

      Sets object's opacity
      Parameters:
      Name Type Description
      value Number Opacity value (0-1)
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setOptions(options) §

      Sets object's properties from options
      Parameters:
      Name Type Argument Description
      options Object <optional>
      Options object
      Inherited From:
      Source:

      setOriginX(value) → {fabric.Object} §

      Sets object's originX
      Parameters:
      Name Type Description
      value String originX value
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setOriginY(value) → {fabric.Object} §

      Sets object's originY
      Parameters:
      Name Type Description
      value String originY value
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setPatternFill(options) → {fabric.Object} §

      Sets pattern fill of an object
      Parameters:
      Name Type Description
      options Object Options object
      Properties
      Name Type Argument Default Description
      source String | HTMLImageElement Pattern source
      repeat String <optional>
      repeat Repeat property of a pattern (one of repeat, repeat-x, repeat-y or no-repeat)
      offsetX Number <optional>
      0 Pattern horizontal offset from object's left/top corner
      offsetY Number <optional>
      0 Pattern vertical offset from object's left/top corner
      Inherited From:
      Source:
      See:
      Returns:
      thisArg
      Type
      fabric.Object
      Example

      Set pattern

      fabric.util.loadImage('http://fabricjs.com/assets/escheresque_ste.png', function(img) {
        object.setPatternFill({
          source: img,
          repeat: 'repeat'
        });
        canvas.renderAll();
      });

      setPositionByOrigin(pos, originX, originY) → {void} §

      Sets the position of the object taking into consideration the object's origin
      Parameters:
      Name Type Description
      pos fabric.Point The new position of the object
      originX String Horizontal origin: 'left', 'center' or 'right'
      originY String Vertical origin: 'top', 'center' or 'bottom'
      Inherited From:
      Source:
      Returns:
      Type
      void

      setScaleX(value) → {fabric.Object} §

      Sets object's scaleX value
      Parameters:
      Name Type Description
      value Number scaleX value
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setScaleY(value) → {fabric.Object} §

      Sets object's scaleY value
      Parameters:
      Name Type Description
      value Number scaleY value
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setShadow(options) → {fabric.Object} §

      Sets shadow of an object
      Parameters:
      Name Type Argument Description
      options Object | String <optional>
      Options object or string (e.g. "2px 2px 10px rgba(0,0,0,0.2)")
      Properties
      Name Type Argument Default Description
      color String <optional>
      rgb(0,0,0) Shadow color
      blur Number <optional>
      0 Shadow blur
      offsetX Number <optional>
      0 Shadow horizontal offset
      offsetY Number <optional>
      0 Shadow vertical offset
      Inherited From:
      Source:
      See:
      Returns:
      thisArg
      Type
      fabric.Object
      Examples

      Set shadow with string notation

      object.setShadow('2px 2px 10px rgba(0,0,0,0.2)');
      canvas.renderAll();

      Set shadow with object notation

      object.setShadow({
        color: 'red',
        blur: 10,
        offsetX: 20,
        offsetY: 20
      });
      canvas.renderAll();

      setSourcePath(value) → {fabric.Object} §

      Sets sourcePath of an object
      Parameters:
      Name Type Description
      value String Value to set sourcePath to
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setStroke(value) → {fabric.Object} §

      Sets object's stroke
      Parameters:
      Name Type Description
      value String stroke value
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setStrokeWidth(value) → {fabric.Object} §

      Sets object's strokeWidth
      Parameters:
      Name Type Description
      value Number strokeWidth value
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setTop(value) → {fabric.Object} §

      Sets object's top position
      Parameters:
      Name Type Description
      value Number Top value (in pixels)
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setTransformMatrix(transformMatrix) → {fabric.Object} §

      Sets object's transformMatrix
      Parameters:
      Name Type Description
      transformMatrix Array
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setupState() → {fabric.Object} §

      Setups state of an object
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      setVisible(value) → {fabric.Object} §

      Sets object's visible state
      Parameters:
      Name Type Description
      value Boolean visible value
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      straighten() → {fabric.Object} §

      Straightens an object (rotating it from current angle to one of 0, 90, 180, 270, etc. depending on which is closer)
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      toDatalessObject(propertiesToInclude) → {Object} §

      Returns (dataless) object representation of an instance
      Parameters:
      Name Type Argument Description
      propertiesToInclude Array <optional>
      Any properties that you might want to additionally include in the output
      Inherited From:
      Source:
      Returns:
      Object representation of an instance
      Type
      Object

      toDataURL(options) → {String} §

      Converts an object into a data-url-like string
      Parameters:
      Name Type Description
      options Object Options object
      Properties
      Name Type Argument Default Description
      format String <optional>
      png The format of the output image. Either "jpeg" or "png"
      quality Number <optional>
      1 Quality level (0..1). Only used for jpeg.
      multiplier Number <optional>
      1 Multiplier to scale by
      left Number <optional>
      Cropping left offset. Introduced in v1.2.14
      top Number <optional>
      Cropping top offset. Introduced in v1.2.14
      width Number <optional>
      Cropping width. Introduced in v1.2.14
      height Number <optional>
      Cropping height. Introduced in v1.2.14
      Inherited From:
      Source:
      Returns:
      Returns a data: URL containing a representation of the object in the format specified by options.format
      Type
      String

      toggle(property) → {fabric.Object} §

      Toggles specified property from `true` to `false` or from `false` to `true`
      Parameters:
      Name Type Description
      property String Property to toggle
      Inherited From:
      Source:
      Returns:
      thisArg
      Type
      fabric.Object

      toJSON(propertiesToInclude) → {Object} §

      Returns a JSON representation of an instance
      Parameters:
      Name Type Argument Description
      propertiesToInclude Array <optional>
      Any properties that you might want to additionally include in the output
      Inherited From:
      Source:
      Returns:
      JSON
      Type
      Object

      toLocalPoint(point, originX, originY) → {fabric.Point} §

      Returns the point in local coordinates
      Parameters:
      Name Type Description
      point fabric.Point The point relative to the global coordinate system
      originX String Horizontal origin: 'left', 'center' or 'right'
      originY String Vertical origin: 'top', 'center' or 'bottom'
      Inherited From:
      Source:
      Returns:
      Type
      fabric.Point

      toObject(propertiesToInclude) → {Object} §

      Returns object representation of an instance
      Parameters:
      Name Type Argument Description
      propertiesToInclude Array <optional>
      Any properties that you might want to additionally include in the output
      Source:
      Returns:
      Object representation of an instance
      Type
      Object

      toString() → {String} §

      Returns a string representation of an instance
      Inherited From:
      Source:
      Returns:
      Type
      String

      toSVG(reviver) → {String} §

      Returns svg representation of an instance
      Parameters:
      Name Type Argument Description
      reviver Function <optional>
      Method for further parsing of svg representation.
      Source:
      Returns:
      svg representation of an instance
      Type
      String

      transform(ctx, fromLeft) §

      Transforms context when rendering an object
      Parameters:
      Name Type Description
      ctx CanvasRenderingContext2D Context
      fromLeft Boolean When true, context is transformed to object's top/left corner. This is used when rendering text on Node
      Inherited From:
      Source:

      translateToCenterPoint(point, originX, originY) → {fabric.Point} §

      Translates the coordinates from origin to center coordinates (based on the object's dimensions)
      Parameters:
      Name Type Description
      point fabric.Point The point which corresponds to the originX and originY params
      originX String Horizontal origin: 'left', 'center' or 'right'
      originY String Vertical origin: 'top', 'center' or 'bottom'
      Inherited From:
      Source:
      Returns:
      Type
      fabric.Point

      translateToOriginPoint(center, originX, originY) → {fabric.Point} §

      Translates the coordinates from center to origin coordinates (based on the object's dimensions)
      Parameters:
      Name Type Description
      center fabric.Point The point which corresponds to center of the object
      originX String Horizontal origin: 'left', 'center' or 'right'
      originY String Vertical origin: 'top', 'center' or 'bottom'
      Inherited From:
      Source:
      Returns:
      Type
      fabric.Point