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"});


propertyexplanationtypedefault value
anchorthe anchor of this text (Figure 1)Array[“center”, “middle”]
xthe x coordinate of the anchorNumber0
ythe y coordinate of the anchorNumber0
textthe text contentString""
fontFamilythe font family of the textString“Arial”
fontSizethe font size of the textString“12px”
fontWeightthe font weight of the textString“regular”
fillColorthe color of the textColor“black”
bounds the bounding rectangle of the textRectangle
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
id the unique id of the textString
type the type of the textString“pointText”
dataScopethe data scope of the textDataScopeundefined
opacitythe opacity value of the text (between 0 and 1)Number1
visibilitywhether the text is visible (“visible” or “hidden”)String“visible”

Methods inherited from Mark

methodexplanationreturn type
contains(x, y)whether this text contains a point
x (Number): x coordinate of the point
y (Number): y coordinate of the point
getScene()returns the scene in which this mark residesScene
duplicate()returns a copy of this markText