GitHub

Marker

The <Marker /> element defines a graphic drawn on the vertices of a <Line />, <Polyline />, <Polygon /> or <Path />, typically an arrowhead or a data point.

Declare it inside a <Defs /> element and reference it from the shape through the markerStart, markerMid and markerEnd attributes, which paint it on the first vertex, every intermediate vertex and the last vertex respectively.

import {
  Svg,
  Defs,
  Marker,
  Path,
  Circle,
  Line,
  Polyline,
} from '@react-pdf/renderer';

const Flow = () => (
  <Svg viewBox="0 0 120 60" width={240} height={120}>
    <Defs>
      <Marker
        id="arrow"
        viewBox="0 0 10 10"
        refX={9}
        refY={5}
        markerWidth={6}
        markerHeight={6}
        orient="auto"
      >
        <Path d="M 0 0 L 10 5 L 0 10 z" fill="#e82200" />
      </Marker>
      <Marker
        id="dot"
        viewBox="0 0 10 10"
        refX={5}
        refY={5}
        markerWidth={4}
        markerHeight={4}
      >
        <Circle cx="5" cy="5" r="5" fill="#8d1602" />
      </Marker>
    </Defs>
    <Line
      x1="8"
      y1="16"
      x2="104"
      y2="16"
      stroke="#e82200"
      strokeWidth={2}
      markerEnd="url(#arrow)"
    />
    <Polyline
      points="8,48 36,32 64,44 92,26"
      fill="none"
      stroke="#c9c2b6"
      strokeWidth={2}
      markerStart="url(#dot)"
      markerMid="url(#dot)"
      markerEnd="url(#dot)"
    />
  </Svg>
);
Show preview

Valid props

Prop nameDescriptionTypeDefault
idUnique identifier used to reference the marker from a shape.Stringundefined
viewBoxDefines the coordinate system of the marker contents, as "minX minY maxX maxY".Stringundefined
markerWidthWidth of the marker viewport. Only applied when viewBox is present.String, Number3
markerHeightHeight of the marker viewport. Only applied when viewBox is present.String, Number3
refXPosition of the marker point on its x-axis, aligned to the vertex.String, Number0
refYPosition of the marker point on its y-axis, aligned to the vertex.String, Number0
orientRotation applied to the marker. auto follows the direction of the shape, auto-start-reverse also flips the start marker, and a number sets a fixed angle in degrees.String, Number0
markerUnitsCoordinate system for the marker. strokeWidth scales it with the shape's strokeWidth, userSpaceOnUse keeps its size constant.StringstrokeWidth

See also Presentation Attributes

On this page