Gradient
Gradient class Gradient
Tutorial
http://fabricjs.com/fabric-intro-part-2#gradients
Type Parameters
• S
• T extends GradientType
= S
extends GradientType
? S
: "linear"
Constructors
new Gradient()
new Gradient<
S
,T
>(options
):Gradient
<S
,T
>
Parameters
• options: GradientOptions
<T
>
Returns
Gradient
<S
, T
>
Defined in
Properties
colorStops
colorStops:
ColorStop
[]
Defines how many colors a gradient has and how they are located on the axis defined by coords
Defined in
coords
coords:
GradientCoords
<T
>
Defines how the gradient is located in space and spread
Defined in
excludeFromExport?
optional
excludeFromExport:boolean
If true, this object will not be exported during the serialization of a canvas
Defined in
gradientTransform?
optional
gradientTransform:TMat2D
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.
Default
Defined in
gradientUnits
gradientUnits:
GradientUnits
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.
Default
Defined in
id
readonly
id:string
|number
ID used for SVG export functionalities
Defined in
offsetX
offsetX:
number
Horizontal offset for aligning gradients coming from SVG when outside pathgroups
Default
Defined in
offsetY
offsetY:
number
Vertical offset for aligning gradients coming from SVG when outside pathgroups
Default
Defined in
type
type:
T
Gradient type linear or radial
Default
Defined in
type
static
type:string
='Gradient'
Defined in
Methods
addColorStop()
addColorStop(
colorStops
):Gradient
<S
,T
>
Adds another colorStop
Parameters
• colorStops: Record
<string
, string
>
Returns
Gradient
<S
, T
>
thisArg
Defined in
toLive()
toLive(
ctx
):CanvasGradient
Returns an instance of CanvasGradient
Parameters
• ctx: CanvasRenderingContext2D
Context to render on
Returns
CanvasGradient
Defined in
toObject()
toObject(
propertiesToInclude
?):Partial
<Gradient
<S
,T
>> &object
Returns object representation of a gradient
Parameters
• propertiesToInclude?: string
[]
Any properties that you might want to additionally include in the output
Returns
Partial
<Gradient
<S
, T
>> & object
Defined in
toSVG()
toSVG(
object
,__namedParameters
):string
Returns SVG representation of an gradient
Parameters
• object: FabricObject
<Partial
<FabricObjectProps
>, SerializedObjectProps
, ObjectEvents
>
Object to create a gradient for
• __namedParameters = {}
• __namedParameters.additionalTransform?: string
Returns
string
SVG representation of an gradient (linear/radial)
Defined in
fromElement()
static
fromElement(el
,instance
,svgOptions
):Gradient
<GradientType
,GradientType
>
Returns Gradient instance from an SVG element
Parameters
• el: SVGGradientElement
SVG gradient element
• instance: FabricObject
<Partial
<FabricObjectProps
>, SerializedObjectProps
, ObjectEvents
>
• svgOptions: SVGOptions
an object containing the size of the SVG in order to parse correctly gradients that uses gradientUnits as ‘userSpaceOnUse’ and percentages.
Returns
Gradient
<GradientType
, GradientType
>
Gradient instance
Static
Member Of
Gradient
See
- http://www.w3.org/TR/SVG/pservers.html#LinearGradientElement
- http://www.w3.org/TR/SVG/pservers.html#RadialGradientElement
Example
Defined in
fromObject()
fromObject(options)
static
fromObject(options
):Promise
<Gradient
<"radial"
,"radial"
>>
Parameters
• options: GradientOptions
<"linear"
>
Returns
Promise
<Gradient
<"radial"
, "radial"
>>
Defined in
fromObject(options)
static
fromObject(options
):Promise
<Gradient
<"radial"
,"radial"
>>
Parameters
• options: GradientOptions
<"radial"
>
Returns
Promise
<Gradient
<"radial"
, "radial"
>>