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

propertyexplanationtypedefault value
anchorthe anchor of this text (Figure 1)Array[“center”, “middle”]
backgroundColorthe background color of the text boxColor“#fff”
borderColorthe border color of the text boxColor“#ccc”
borderWidththe border width of the text box in pixelsNumber1
fontFamilythe font family of the textString“Arial, sans-serif”
fontSizethe font size of the textString“12px”
fontWeightthe font weight of the textString“normal”
textthe text contentString""
textPaththe path the text followsPathundefined
textPathOffsetthe offset along the text pathString“50%”
xthe x coordinate of the anchorNumber0
ythe y coordinate of the anchorNumber0
text anchor

Figure 1: Different anchor properties with the same x and y properties (the orange dot) lead to different text positions.

Properties inherited from Mark

propertyexplanationtypedefault value
bounds the bounding rectangle of the textRectangle
dataScopethe data scope of the textDataScopeundefined
fillColorthe color of the textColor“black”
id the unique id of the textString
opacitythe opacity value of the text (between 0 and 1)Number1
strokeColorthe stroke color of the textColorundefined
strokeDashthe dashes and gaps for the text strokeStringundefined
strokeWidththe stroke width of the text in pixelsNumberundefined
type the type of the textString“text”
visibilitywhether the text is visible (“visible” or “hidden”)String“visible”