new Gradient()
Gradient class
- Source:
- Tutorials:
- See:
-
- fabric.Gradient#initialize for constructor definition
Members
gradientTransform :Array.<Number>
A transform matrix to apply to the gradient before painting.
Imported from svg gradients, is not applied with the current transform in the center.
Before this transform is applied, the origin point is at the top left corner of the object
plus the addition of offsetY and offsetX.
Type:
- Array.<Number>
gradientUnits :String
coordinates units for coords.
If `pixels`, the number of coords are in the same unit of width / height.
If set as `percentage` the coords are still a number, but 1 means 100% of width
for the X and 100% of the height for the y. It can be bigger than 1 and negative.
allowed values pixels or percentage.
Type:
- String
offsetX :Number
Horizontal offset for aligning gradients coming from SVG when outside pathgroups
Type:
- Number
offsetY :Number
Vertical offset for aligning gradients coming from SVG when outside pathgroups
Type:
- Number
type :String
Gradient type linear or radial
Type:
- String
Methods
(static) fromElement(el, instance, opacityAttr, svgOptions, viewBoxWidth, viewBoxHeight, width, height) → {fabric.Gradient}
Returns fabric.Gradient instance from an SVG element
Parameters:
Name | Type | Description |
---|---|---|
el |
SVGGradientElement | SVG gradient element |
instance |
fabric.Object | |
opacityAttr |
String | A fill-opacity or stroke-opacity attribute to multiply to each stop's opacity. |
svgOptions |
Object | an object containing the size of the SVG in order to parse correctly gradients that uses gradientUnits as 'userSpaceOnUse' and percentages. |
viewBoxWidth |
Object.number | width part of the viewBox attribute on svg |
viewBoxHeight |
Object.number | height part of the viewBox attribute on svg |
width |
Object.number | width part of the svg tag if viewBox is not specified |
height |
Object.number | height part of the svg tag if viewBox is not specified |
- Source:
- See:
Returns:
Gradient instance
- Type
- fabric.Gradient
addColorStop(colorStop) → {fabric.Gradient}
Adds another colorStop
Parameters:
Name | Type | Description |
---|---|---|
colorStop |
Object | Object with offset and color |
Returns:
thisArg
- Type
- fabric.Gradient
initialize(options) → {fabric.Gradient}
Constructor
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Options object with type, coords, gradientUnits and colorStops
Properties
|
Returns:
thisArg
- Type
- fabric.Gradient
toLive(ctx) → {CanvasGradient}
Returns an instance of CanvasGradient
Parameters:
Name | Type | Description |
---|---|---|
ctx |
CanvasRenderingContext2D | Context to render on |
Returns:
- Type
- CanvasGradient
toObject(propertiesToIncludeopt) → {Object}
Returns object representation of a gradient
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
propertiesToInclude |
Array |
<optional> |
Any properties that you might want to additionally include in the output |
Returns:
- Type
- Object
toSVG(object) → {String}
Returns SVG representation of an gradient
Parameters:
Name | Type | Description |
---|---|---|
object |
Object | Object to create a gradient for |
Returns:
SVG representation of an gradient (linear/radial)
- Type
- String