Class LinearGradientElement
- All Implemented Interfaces:
Serializable
<linearGradient> element.
The <linearGradient> element defines a linear gradient to be used
as a fill or stroke for other SVG elements. The gradient is defined along
a line specified by x1, y1, x2, y2 coordinates.
Linear gradients must be placed inside a <defs> element and
referenced by ID (e.g., fill="url(#myGradient)").
Write-Only vs Read-Write Methods
This class provides two variants for each attribute setter:
- Default methods (e.g.,
x1(),y1()) - Use an optimized write-only approach. Attribute values are NOT stored on the server and cannot be retrieved viagetAttribute(). - RW methods (e.g.,
x1RW(),y1RW()) - Use traditionalsetAttribute()which stores values on the server for later retrieval.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumGradient unit options.static enumSpread method options for gradients.Nested classes/interfaces inherited from class SvgElement
SvgElement.PreserveAspectRatio -
Constructor Summary
ConstructorsConstructorDescriptionCreates a linear gradient with the given ID. -
Method Summary
Modifier and TypeMethodDescriptionaddStop(double offset, in.virit.color.Color color) Adds a stop at the specified offset with the given color.Adds a stop at the specified offset with the given color.addStops(StopElement... stops) Adds stop elements to this gradient.diagonal()Creates a diagonal gradient (top-left to bottom-right).gradientTransform(String transform) Sets a transform on the gradient.gradientTransformRW(String transform) Sets a transform on the gradient (read-write).Sets the coordinate system for the gradient vector.Sets the coordinate system for the gradient vector (read-write).Creates a horizontal gradient (left to right).References another gradient to inherit stops and attributes from.References another gradient to inherit stops and attributes from (read-write).Sets how the gradient behaves outside its bounds.Sets how the gradient behaves outside its bounds (read-write).vector(double x1, double y1, double x2, double y2) Sets the gradient vector from start to end point.vectorRW(double x1, double y1, double x2, double y2) Sets the gradient vector from start to end point (read-write).vertical()Creates a vertical gradient (top to bottom).x1(double x1) Sets the x coordinate of the gradient start point.Sets the x coordinate of the gradient start point with a unit.x1RW(double x1) Sets the x coordinate of the gradient start point (read-write).Sets the x coordinate of the gradient start point with a unit (read-write).x2(double x2) Sets the x coordinate of the gradient end point.Sets the x coordinate of the gradient end point with a unit.x2RW(double x2) Sets the x coordinate of the gradient end point (read-write).Sets the x coordinate of the gradient end point with a unit (read-write).y1(double y1) Sets the y coordinate of the gradient start point.Sets the y coordinate of the gradient start point with a unit.y1RW(double y1) Sets the y coordinate of the gradient start point (read-write).Sets the y coordinate of the gradient start point with a unit (read-write).y2(double y2) Sets the y coordinate of the gradient end point.Sets the y coordinate of the gradient end point with a unit.y2RW(double y2) Sets the y coordinate of the gradient end point (read-write).Sets the y coordinate of the gradient end point with a unit (read-write).Methods inherited from class SvgElement
emptySvgRoot, flushPendingAttributes, getOuterHTML, getPendingOrAttribute, getStyle, height, height, id, preserveAspectRatio, preserveAspectRatio, scheduleBeforeClientResponse, setAttribute, setWriteOnlyAttribute, size, size, viewBox, width, widthMethods inherited from class com.vaadin.flow.dom.Element
addAttachListener, addDetachListener, addEventListener, addPropertyChangeListener, addPropertyChangeListener, as, attachShadow, bindAttribute, bindProperty, bindText, callJsFunction, callJsFunction, createText, executeJs, executeJs, get, get, getAttribute, getAttributeNames, getChild, getChildCount, getChildren, getClassList, getComponent, getParent, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyBean, getPropertyBean, getPropertyNames, getPropertyRaw, getSelf, getShadowRoot, getTag, getText, getTextRecursively, getThemeList, hasAttribute, hasProperty, isEnabled, isTextNode, isVisible, removeAttribute, removeFromParent, removeFromTree, removeFromTree, removeProperty, scrollIntoView, scrollIntoView, setAttribute, setAttribute, setAttribute, setEnabled, setProperty, setProperty, setProperty, setPropertyBean, setPropertyJson, setPropertyList, setPropertyMap, setText, setVisible, toStringMethods inherited from class com.vaadin.flow.dom.Node
accept, appendChild, appendChild, appendVirtualChild, appendVirtualChild, ensureChildHasParent, equals, getNode, getParentNode, getStateProvider, hashCode, indexOfChild, insertChild, insertChild, isVirtualChild, removeAllChildren, removeChild, removeChild, removeChild, removeVirtualChild, removeVirtualChild, setChild
-
Constructor Details
-
LinearGradientElement
public LinearGradientElement() -
LinearGradientElement
Creates a linear gradient with the given ID.- Parameters:
id- the ID for referencing this gradient
-
-
Method Details
-
x1
Sets the x coordinate of the gradient start point.Uses write-only optimization. Use
x1RW(double)if you need to read the value back.- Parameters:
x1- the x coordinate (default is 0)- Returns:
- this element for method chaining
-
x1
Sets the x coordinate of the gradient start point with a unit.Uses write-only optimization. Use
x1RW(String)if you need to read the value back.- Parameters:
x1- the x coordinate (e.g., "0%", "50%")- Returns:
- this element for method chaining
-
x1RW
Sets the x coordinate of the gradient start point (read-write).- Parameters:
x1- the x coordinate (default is 0)- Returns:
- this element for method chaining
-
x1RW
Sets the x coordinate of the gradient start point with a unit (read-write).- Parameters:
x1- the x coordinate (e.g., "0%", "50%")- Returns:
- this element for method chaining
-
y1
Sets the y coordinate of the gradient start point.Uses write-only optimization. Use
y1RW(double)if you need to read the value back.- Parameters:
y1- the y coordinate (default is 0)- Returns:
- this element for method chaining
-
y1
Sets the y coordinate of the gradient start point with a unit.Uses write-only optimization. Use
y1RW(String)if you need to read the value back.- Parameters:
y1- the y coordinate (e.g., "0%", "50%")- Returns:
- this element for method chaining
-
y1RW
Sets the y coordinate of the gradient start point (read-write).- Parameters:
y1- the y coordinate (default is 0)- Returns:
- this element for method chaining
-
y1RW
Sets the y coordinate of the gradient start point with a unit (read-write).- Parameters:
y1- the y coordinate (e.g., "0%", "50%")- Returns:
- this element for method chaining
-
x2
Sets the x coordinate of the gradient end point.Uses write-only optimization. Use
x2RW(double)if you need to read the value back.- Parameters:
x2- the x coordinate (default is 1 or 100%)- Returns:
- this element for method chaining
-
x2
Sets the x coordinate of the gradient end point with a unit.Uses write-only optimization. Use
x2RW(String)if you need to read the value back.- Parameters:
x2- the x coordinate (e.g., "100%", "50%")- Returns:
- this element for method chaining
-
x2RW
Sets the x coordinate of the gradient end point (read-write).- Parameters:
x2- the x coordinate (default is 1 or 100%)- Returns:
- this element for method chaining
-
x2RW
Sets the x coordinate of the gradient end point with a unit (read-write).- Parameters:
x2- the x coordinate (e.g., "100%", "50%")- Returns:
- this element for method chaining
-
y2
Sets the y coordinate of the gradient end point.Uses write-only optimization. Use
y2RW(double)if you need to read the value back.- Parameters:
y2- the y coordinate (default is 0)- Returns:
- this element for method chaining
-
y2
Sets the y coordinate of the gradient end point with a unit.Uses write-only optimization. Use
y2RW(String)if you need to read the value back.- Parameters:
y2- the y coordinate (e.g., "100%", "50%")- Returns:
- this element for method chaining
-
y2RW
Sets the y coordinate of the gradient end point (read-write).- Parameters:
y2- the y coordinate (default is 0)- Returns:
- this element for method chaining
-
y2RW
Sets the y coordinate of the gradient end point with a unit (read-write).- Parameters:
y2- the y coordinate (e.g., "100%", "50%")- Returns:
- this element for method chaining
-
vector
Sets the gradient vector from start to end point.Default is horizontal (0,0 to 1,0).
Uses write-only optimization. Use
vectorRW(double, double, double, double)if you need to read the values back.- Parameters:
x1- start x coordinatey1- start y coordinatex2- end x coordinatey2- end y coordinate- Returns:
- this element for method chaining
-
vectorRW
Sets the gradient vector from start to end point (read-write).- Parameters:
x1- start x coordinatey1- start y coordinatex2- end x coordinatey2- end y coordinate- Returns:
- this element for method chaining
-
horizontal
Creates a horizontal gradient (left to right).Uses write-only optimization.
- Returns:
- this element for method chaining
-
vertical
Creates a vertical gradient (top to bottom).Uses write-only optimization.
- Returns:
- this element for method chaining
-
diagonal
Creates a diagonal gradient (top-left to bottom-right).Uses write-only optimization.
- Returns:
- this element for method chaining
-
gradientUnits
Sets the coordinate system for the gradient vector.Uses write-only optimization. Use
gradientUnitsRW(GradientUnits)if you need to read the value back.- Parameters:
units- the gradient units- Returns:
- this element for method chaining
-
gradientUnitsRW
Sets the coordinate system for the gradient vector (read-write).- Parameters:
units- the gradient units- Returns:
- this element for method chaining
-
spreadMethod
Sets how the gradient behaves outside its bounds.Uses write-only optimization. Use
spreadMethodRW(SpreadMethod)if you need to read the value back.- Parameters:
method- the spread method- Returns:
- this element for method chaining
-
spreadMethodRW
Sets how the gradient behaves outside its bounds (read-write).- Parameters:
method- the spread method- Returns:
- this element for method chaining
-
gradientTransform
Sets a transform on the gradient.Uses write-only optimization. Use
gradientTransformRW(String)if you need to read the value back.- Parameters:
transform- the transform string- Returns:
- this element for method chaining
-
gradientTransformRW
Sets a transform on the gradient (read-write).- Parameters:
transform- the transform string- Returns:
- this element for method chaining
-
href
References another gradient to inherit stops and attributes from.Uses write-only optimization. Use
hrefRW(String)if you need to read the value back.- Parameters:
href- the reference (e.g., "#otherGradient")- Returns:
- this element for method chaining
-
hrefRW
References another gradient to inherit stops and attributes from (read-write).- Parameters:
href- the reference (e.g., "#otherGradient")- Returns:
- this element for method chaining
-
addStops
Adds stop elements to this gradient.- Parameters:
stops- the stop elements- Returns:
- this element for method chaining
-
addStop
Adds a stop at the specified offset with the given color.- Parameters:
offset- the offset (0.0 to 1.0)color- the color- Returns:
- this element for method chaining
-
addStop
Adds a stop at the specified offset with the given color.- Parameters:
offset- the offset (0.0 to 1.0)color- the color string- Returns:
- this element for method chaining
-