Text
extends Mark
The Text class represents a text element. To create a Text object, use the mark method in the Scene class, for example:
let txt = scene.mark("text", {x: 50, y: 100, text: "hello"});
Properties
| property | explanation | type | default value |
|---|---|---|---|
| anchor | the anchor of this text (Figure 1) | Array | [“center”, “middle”] |
| backgroundColor | the background color of the text box | Color | “#fff” |
| borderColor | the border color of the text box | Color | “#ccc” |
| borderWidth | the border width of the text box in pixels | Number | 1 |
| fontFamily | the font family of the text | String | “Arial, sans-serif” |
| fontSize | the font size of the text | String | “12px” |
| fontWeight | the font weight of the text | String | “normal” |
| text | the text content | String | "" |
| textPath | the path the text follows | Path | undefined |
| textPathOffset | the offset along the text path | String | “50%” |
| x | the x coordinate of the anchor | Number | 0 |
| y | the y coordinate of the anchor | Number | 0 |

Figure 1: Different anchor properties with the same x and y properties (the orange dot) lead to different text positions.
Properties inherited from Mark
| property | explanation | type | default value |
|---|---|---|---|
bounds ![]() | the bounding rectangle of the text | Rectangle | |
| dataScope | the data scope of the text | DataScope | undefined |
| fillColor | the color of the text | Color | “black” |
id ![]() | the unique id of the text | String | |
| opacity | the opacity value of the text (between 0 and 1) | Number | 1 |
| strokeColor | the stroke color of the text | Color | undefined |
| strokeDash | the dashes and gaps for the text stroke | String | undefined |
| strokeWidth | the stroke width of the text in pixels | Number | undefined |
type ![]() | the type of the text | String | “text” |
| visibility | whether the text is visible (“visible” or “hidden”) | String | “visible” |
