Class MarkerElement
- All Implemented Interfaces:
Serializable
<marker> element.
The <marker> element defines a graphic used for drawing arrows or polymarkers
on shape elements like <path>, <line>, <polyline>, and <polygon>.
Markers must be placed inside a <defs> element and referenced
by ID using the marker-start, marker-mid, or marker-end attributes.
Example - Creating an arrowhead marker:
MarkerElement arrow = new MarkerElement("arrowhead")
.viewBox(0, 0, 10, 10)
.refX(10).refY(5)
.markerWidth(6).markerHeight(6)
.orient(MarkerElement.Orient.AUTO);
PathElement arrowPath = new PathElement()
.d(p -> p.moveTo(0, 0).lineTo(10, 5).lineTo(0, 10).closePath())
.fill(HexColor.of("#ff0000"));
arrow.add(arrowPath);
// Use on a line
lineElement.markerEnd(arrow);
Write-Only vs Read-Write Methods
This class provides two variants for each attribute setter:
- Default methods (e.g.,
refX(),refY()) - Use an optimized write-only approach. Attribute values are NOT stored on the server and cannot be retrieved viagetAttribute(). - RW methods (e.g.,
refXRW(),refYRW()) - Use traditionalsetAttribute()which stores values on the server for later retrieval.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumMarker unit options.static enumOrientation options for markers.Nested classes/interfaces inherited from class SvgElement
SvgElement.PreserveAspectRatio -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(SvgElement... elements) Adds content elements to this marker.markerHeight(double height) Sets the height of the marker viewport.markerHeight(String height) Sets the height of the marker viewport with a unit.markerHeightRW(double height) Sets the height of the marker viewport (read-write).markerHeightRW(String height) Sets the height of the marker viewport with a unit (read-write).markerSize(double width, double height) Sets both markerWidth and markerHeight at once.markerSizeRW(double width, double height) Sets both markerWidth and markerHeight at once (read-write).Sets the coordinate system for markerWidth and markerHeight.Sets the coordinate system for markerWidth and markerHeight (read-write).markerWidth(double width) Sets the width of the marker viewport.markerWidth(String width) Sets the width of the marker viewport with a unit.markerWidthRW(double width) Sets the width of the marker viewport (read-write).markerWidthRW(String width) Sets the width of the marker viewport with a unit (read-write).orient(double angle) Sets the orientation of the marker to a specific angle in degrees.orient(MarkerElement.Orient orient) Sets the orientation of the marker.Sets the marker to automatically orient along the path direction.Sets the marker to automatically orient along the path direction (read-write).Sets the marker to automatically orient opposite to the path direction at the start.Sets the marker to automatically orient opposite to the path direction at the start (read-write).orientRW(double angle) Sets the orientation of the marker to a specific angle in degrees (read-write).orientRW(MarkerElement.Orient orient) Sets the orientation of the marker (read-write).preserveAspectRatio(String value) Sets the preserveAspectRatio attribute.Sets the preserveAspectRatio attribute.preserveAspectRatioRW(String value) Sets the preserveAspectRatio attribute (read-write).Sets the preserveAspectRatio attribute (read-write).ref(double refX, double refY) Sets both refX and refY coordinates at once.refRW(double refX, double refY) Sets both refX and refY coordinates at once (read-write).refX(double refX) Sets the x coordinate of the marker's reference point.Sets the x coordinate of the marker's reference point with a unit.refXRW(double refX) Sets the x coordinate of the marker's reference point (read-write).Sets the x coordinate of the marker's reference point with a unit (read-write).refY(double refY) Sets the y coordinate of the marker's reference point.Sets the y coordinate of the marker's reference point with a unit.refYRW(double refY) Sets the y coordinate of the marker's reference point (read-write).Sets the y coordinate of the marker's reference point with a unit (read-write).viewBox(double minX, double minY, double width, double height) Sets the viewBox for the marker contents.viewBoxRW(double minX, double minY, double width, double height) Sets the viewBox for the marker contents (read-write).Methods inherited from class SvgElement
emptySvgRoot, flushPendingAttributes, getOuterHTML, getPendingOrAttribute, getStyle, height, height, id, scheduleBeforeClientResponse, setAttribute, setWriteOnlyAttribute, size, size, 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
-
MarkerElement
public MarkerElement() -
MarkerElement
Creates a marker with the given ID.- Parameters:
id- the ID for referencing this marker
-
-
Method Details
-
viewBox
Sets the viewBox for the marker contents.Uses write-only optimization. Use
viewBoxRW(double, double, double, double)if you need to read the value back.- Overrides:
viewBoxin classSvgElement- Parameters:
minX- the minimum x valueminY- the minimum y valuewidth- the widthheight- the height- Returns:
- this element for method chaining
-
viewBoxRW
Sets the viewBox for the marker contents (read-write).- Parameters:
minX- the minimum x valueminY- the minimum y valuewidth- the widthheight- the height- Returns:
- this element for method chaining
-
refX
Sets the x coordinate of the marker's reference point.This is the point within the marker that is placed at the marked position.
Uses write-only optimization. Use
refXRW(double)if you need to read the value back.- Parameters:
refX- the x coordinate of the reference point- Returns:
- this element for method chaining
-
refX
Sets the x coordinate of the marker's reference point with a unit.Uses write-only optimization. Use
refXRW(String)if you need to read the value back.- Parameters:
refX- the x coordinate (e.g., "10", "left", "center", "right")- Returns:
- this element for method chaining
-
refXRW
Sets the x coordinate of the marker's reference point (read-write).- Parameters:
refX- the x coordinate of the reference point- Returns:
- this element for method chaining
-
refXRW
Sets the x coordinate of the marker's reference point with a unit (read-write).- Parameters:
refX- the x coordinate (e.g., "10", "left", "center", "right")- Returns:
- this element for method chaining
-
refY
Sets the y coordinate of the marker's reference point.This is the point within the marker that is placed at the marked position.
Uses write-only optimization. Use
refYRW(double)if you need to read the value back.- Parameters:
refY- the y coordinate of the reference point- Returns:
- this element for method chaining
-
refY
Sets the y coordinate of the marker's reference point with a unit.Uses write-only optimization. Use
refYRW(String)if you need to read the value back.- Parameters:
refY- the y coordinate (e.g., "10", "top", "center", "bottom")- Returns:
- this element for method chaining
-
refYRW
Sets the y coordinate of the marker's reference point (read-write).- Parameters:
refY- the y coordinate of the reference point- Returns:
- this element for method chaining
-
refYRW
Sets the y coordinate of the marker's reference point with a unit (read-write).- Parameters:
refY- the y coordinate (e.g., "10", "top", "center", "bottom")- Returns:
- this element for method chaining
-
ref
Sets both refX and refY coordinates at once.Uses write-only optimization. Use
refRW(double, double)if you need to read the values back.- Parameters:
refX- the x coordinate of the reference pointrefY- the y coordinate of the reference point- Returns:
- this element for method chaining
-
refRW
Sets both refX and refY coordinates at once (read-write).- Parameters:
refX- the x coordinate of the reference pointrefY- the y coordinate of the reference point- Returns:
- this element for method chaining
-
markerWidth
Sets the width of the marker viewport.Uses write-only optimization. Use
markerWidthRW(double)if you need to read the value back.- Parameters:
width- the marker width- Returns:
- this element for method chaining
-
markerWidth
Sets the width of the marker viewport with a unit.Uses write-only optimization. Use
markerWidthRW(String)if you need to read the value back.- Parameters:
width- the marker width (e.g., "10", "10px")- Returns:
- this element for method chaining
-
markerWidthRW
Sets the width of the marker viewport (read-write).- Parameters:
width- the marker width- Returns:
- this element for method chaining
-
markerWidthRW
Sets the width of the marker viewport with a unit (read-write).- Parameters:
width- the marker width (e.g., "10", "10px")- Returns:
- this element for method chaining
-
markerHeight
Sets the height of the marker viewport.Uses write-only optimization. Use
markerHeightRW(double)if you need to read the value back.- Parameters:
height- the marker height- Returns:
- this element for method chaining
-
markerHeight
Sets the height of the marker viewport with a unit.Uses write-only optimization. Use
markerHeightRW(String)if you need to read the value back.- Parameters:
height- the marker height (e.g., "10", "10px")- Returns:
- this element for method chaining
-
markerHeightRW
Sets the height of the marker viewport (read-write).- Parameters:
height- the marker height- Returns:
- this element for method chaining
-
markerHeightRW
Sets the height of the marker viewport with a unit (read-write).- Parameters:
height- the marker height (e.g., "10", "10px")- Returns:
- this element for method chaining
-
markerSize
Sets both markerWidth and markerHeight at once.Uses write-only optimization. Use
markerSizeRW(double, double)if you need to read the values back.- Parameters:
width- the marker widthheight- the marker height- Returns:
- this element for method chaining
-
markerSizeRW
Sets both markerWidth and markerHeight at once (read-write).- Parameters:
width- the marker widthheight- the marker height- Returns:
- this element for method chaining
-
orient
Sets the orientation of the marker.Uses write-only optimization. Use
orientRW(Orient)if you need to read the value back.- Parameters:
orient- the orientation- Returns:
- this element for method chaining
-
orient
Sets the orientation of the marker to a specific angle in degrees.Uses write-only optimization. Use
orientRW(double)if you need to read the value back.- Parameters:
angle- the rotation angle in degrees- Returns:
- this element for method chaining
-
orientRW
Sets the orientation of the marker (read-write).- Parameters:
orient- the orientation- Returns:
- this element for method chaining
-
orientRW
Sets the orientation of the marker to a specific angle in degrees (read-write).- Parameters:
angle- the rotation angle in degrees- Returns:
- this element for method chaining
-
orientAuto
Sets the marker to automatically orient along the path direction.Uses write-only optimization. Use
orientAutoRW()if you need to read the value back.- Returns:
- this element for method chaining
-
orientAutoRW
Sets the marker to automatically orient along the path direction (read-write).- Returns:
- this element for method chaining
-
orientAutoStartReverse
Sets the marker to automatically orient opposite to the path direction at the start.This is useful for creating arrows where the start arrow points backward.
Uses write-only optimization. Use
orientAutoStartReverseRW()if you need to read the value back.- Returns:
- this element for method chaining
-
orientAutoStartReverseRW
Sets the marker to automatically orient opposite to the path direction at the start (read-write).- Returns:
- this element for method chaining
-
markerUnits
Sets the coordinate system for markerWidth and markerHeight.Uses write-only optimization. Use
markerUnitsRW(MarkerUnits)if you need to read the value back.- Parameters:
units- the marker units- Returns:
- this element for method chaining
-
markerUnitsRW
Sets the coordinate system for markerWidth and markerHeight (read-write).- Parameters:
units- the marker units- Returns:
- this element for method chaining
-
preserveAspectRatio
Sets the preserveAspectRatio attribute.Uses write-only optimization. Use
preserveAspectRatioRW(String)if you need to read the value back.- Overrides:
preserveAspectRatioin classSvgElement- Parameters:
value- the preserveAspectRatio value- Returns:
- this element for method chaining
-
preserveAspectRatioRW
Sets the preserveAspectRatio attribute (read-write).- Parameters:
value- the preserveAspectRatio value- Returns:
- this element for method chaining
-
preserveAspectRatio
Sets the preserveAspectRatio attribute.Uses write-only optimization. Use
preserveAspectRatioRW(PreserveAspectRatio)if you need to read the value back.- Overrides:
preserveAspectRatioin classSvgElement- Parameters:
ratio- the preserveAspectRatio setting- Returns:
- this element for method chaining
-
preserveAspectRatioRW
Sets the preserveAspectRatio attribute (read-write).- Parameters:
ratio- the preserveAspectRatio setting- Returns:
- this element for method chaining
-
add
Adds content elements to this marker.- Parameters:
elements- the elements that define the marker graphic- Returns:
- this element for method chaining
-