Usage
Props
Content
The text content to render.Numbers are converted to strings. Null and undefined render nothing.
Position
The x-coordinate of the text.
The y-coordinate of the text.
Horizontal offset from the x position.
Vertical offset from the y position.
Alignment
Horizontal text alignment within the text element.
start: Text starts at the x coordinate (left-aligned for LTR text)middle: Text is centered on the x coordinateend: Text ends at the x coordinate (right-aligned for LTR text)inherit: Inherits from parent element
Vertical text alignment relative to the y coordinate.
start: Text baseline starts at y coordinate (text appears below y)middle: Text is vertically centered on y coordinateend: Text baseline ends at y coordinate (text appears above y)
Line breaking
When specified, text automatically wraps by calculating the width.Can be a number (pixels) or CSS string value.
Enables character-level breaking instead of word-level breaking.
false: Text breaks at word boundaries (spaces, tabs)true: Text can break between any characters (useful for languages without spaces)
width is defined.Maximum number of lines to display when text wrapping is enabled.When text exceeds this limit, it is truncated with an ellipsis (…).Requirements for ellipsis truncation:
widthmust be definedscaleToFitmust be false- Text must actually overflow
Line height for multi-line text.Can be a number (pixels) or string with CSS units.
Used to calculate spacing between lines.
Scaling
When true, scales the text to fit within the specified width.Important interactions:
- Requires
widthto be defined - When enabled,
maxLinesrestrictions are bypassed - Uses the first line’s width to calculate scale factor
Rotation
Text rotation angle in degrees.Positive values rotate clockwise, negative values rotate counterclockwise.
Styling
CSS styles applied to the text element.Font-related properties are particularly important for accurate text measurements when using width constraints or scaleToFit.
The fill color of the text.
The stroke color of the text.
The font size of the text.
The font family of the text.
The font weight of the text.
Other
CSS class name for the text element.
The cap height used for vertical alignment calculations.This is a magic number from d3.
Notes
- Text measurement is performed in the browser, so results may vary slightly across different browsers and operating systems.
- When using
scaleToFit, ensure your text is short enough that scaling doesn’t make it unreadable. - The
maxLinesprop uses binary search to find the optimal truncation point for performance. - Text wrapping and scaling features are disabled in server-side rendering (SSR) environments.