Usage
Props
Content
string | number | boolean | null | undefined
The text content to render.Numbers are converted to strings. Null and undefined render nothing.
Position
number
default:"0"
The x-coordinate of the text.
number
default:"0"
The y-coordinate of the text.
number
Horizontal offset from the x position.
number
Vertical offset from the y position.
Alignment
'start' | 'middle' | 'end' | 'inherit'
default:"start"
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
'start' | 'middle' | 'end'
default:"end"
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
number | string
When specified, text automatically wraps by calculating the width.Can be a number (pixels) or CSS string value.
boolean
default:"false"
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.number
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
number | string
default:"1em"
Line height for multi-line text.Can be a number (pixels) or string with CSS units.
Used to calculate spacing between lines.
Scaling
boolean
default:"false"
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
number
default:"0"
Text rotation angle in degrees.Positive values rotate clockwise, negative values rotate counterclockwise.
Styling
CSSProperties
CSS styles applied to the text element.Font-related properties are particularly important for accurate text measurements when using width constraints or scaleToFit.
string
default:"#808080"
The fill color of the text.
string
The stroke color of the text.
number | string
The font size of the text.
string
The font family of the text.
string | number
The font weight of the text.
Other
string
CSS class name for the text element.
string
default:"0.71em"
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.