GoJS® Diagramming Components
version 1.7.26 for JavaScript/HTML
by Northwoods Software®

## Class TextBlock

Extends GraphObject. A TextBlock is a GraphObject that displays a text string in a given font.

The size and appearance of the text is specified by font, which takes a well-formed CSS string as its value. The order of the CSS properties given is important for cross-browser compatibility, and should be given in this order:

"font-style font-variant font-weight font-size font-family"

For example, "Italic small-caps bold 32px Georgia, Serif" is a valid font string using every CSS font property. Note that not all browsers may support every property.

Text is drawn using the stroke brush, which may be any CSS color string or a Brush. Some created TextBlocks:

    var $ = go.GraphObject.make;  // for conciseness in defining GraphObjects

    // A TextBlock with text and stroke properties set:
    $(go.TextBlock, { text: "Hello World", stroke: "gray" })
    // Alternatively:
    $(go.TextBlock, "Hello World", { stroke: "gray" })

TextBlocks typically receive a natural size based on their text and font strings, but often a width is given in order to cause the text to wrap at a certain place. In order for wrapping to occur, the wrap property must not be TextBlock.None.

TextBlocks can be edited by users using the TextEditingTool. The HTML Element that a given TextBlock uses as its text editor can be customized by setting the textEditor property. For an example of custom text editing tool use, see the Custom TextEditingTool Sample.

For examples of TextBlock possibilities and functionality, see the Introduction page on TextBlocks.

## Constructor Summary Details

Name | Description
--- | ---
TextBlock() | A newly constructed TextBlock has no string to show; if it did, it would draw the text, wrapping if needed, in the default font using a black stroke.

## Properties Summary Details

Name, Value Type | Description
--- | ---
choices {Array.<string>|null} 1.7 | Gets or sets the an array of possible choices for a custom TextEditingTool.More... The value must be an array of strings. The default value is null. For example usage, see the Custom TextEditingTool Sample.
editable {boolean} | Gets or sets whether or not this TextBlock allows in-place editing of the text string by the user with the help of the TextEditingTool.More... The default is false. See also Part.textEditable.
errorFunction {function(TextEditingTool, string, string) | null} | Gets or sets the function to call if a text edit made with the TextEditingTool is invalid.More... The default is null.

font
{string}

Gets or sets the current font settings.More... The font property must be a valid CSS string describing a font. The font string can accept several CSS properties but they must be in a specific order in order to render correctly across all browsers:

`"font-style font-variant font-weight font-size font-family"`

For example, `"Italic small-caps bold 32px Georgia, Serif"` is a valid font string using every CSS font property. Not every browser can render every font option. For more information about CSS font syntax, see CSS fonts (mozilla.org).

The default font is "13px sans-serif".

graduatedEnd {number} 1.7 | Gets or sets the fractional distance along the main shape of a "Graduated" Panel at which this kind of tick text should end.More... The default is 1; the value should range from 0 to 1.

graduatedFunction
{function(number): string} 1.7

Gets or sets the function to convert from a value along a "Graduated" Panel to a string.More... The default returns a string representing the value rounded to at most 2 decimals.

The function takes a number argument, a value between Panel.graduatedMin and Panel.graduatedMax. The function will return a string, the text that will appear at the value of the argument.

graduatedStart {number} 1.7 | Gets or sets the fractional distance along the main shape of a "Graduated" Panel at which this text should start.More... The default is 0; the value should range from 0 to 1.
interval {number} 1.7 | Gets or sets how frequently this text should be drawn within a "Graduated" Panel, in multiples of the Panel.graduatedTickUnit.More... The default is 1. Any new value must be a positive integer.

isMultiline
{boolean}

Gets or sets whether or not the text displays multiple lines or embedded newlines.More... If this is false, all characters including and after the first newline will be omitted. The default is true.

See also:

- maxLines

isStrikethrough
{boolean} 1.2

Gets or sets whether or not the text has a strikethrough line (line-through).More... The default is false.

See also:

- isUnderline

isUnderline
{boolean} 1.2

Gets or sets whether or not the text is underlined.More... The default is false.

See also:

- isStrikethrough

lineCount {number} | This read-only property returns the total number of lines in this TextBlock, including lines created from embedded newlines (`\n`), wrapping, and maxLines.More... This value may be meaningless before the TextBlock is measured.

maxLines
{number} 1.5

Gets or sets the maximum number of lines that this TextBlock can display.More... Value must be a greater than zero whole number or `Infinity`. The default is `Infinity`.

Modifying this value may modify the computed height of the TextBlock. If maxLines is set, the value of lineCount will never be larger than maxLines.

See also:

- isMultiline

naturalBounds {Rect} | This read-only property returns the natural bounds of this TextBlock in local coordinates, as determined by its font and text string, and optionally its desiredSize.

overflow
{EnumValue} 1.4

Gets or sets how text that is too long to display should be handled.More...

Possible values are TextBlock.OverflowClip and TextBlock.OverflowEllipsis. For OverflowEllipsis to work, you must also set wrap to TextBlock.None or limit the number of lines with maxLines.

The default value is TextBlock.OverflowClip.

See also:

- wrap

stroke {string|Brush} | Gets or sets the Brush or string that describes the stroke (color) of the text that is drawn.More... The default value is `"black"`. Any valid CSS string can specify a solid color, and the Brush class can be used to specify a gradient or pattern. More information about the syntax of CSS color strings is available at: CSS colors (mozilla.org).

text
{string}

Gets or sets the TextBlock's text string.More... The default is an empty string. The text of a TextBlock, along with the values of font, wrap, isMultiline and sizing restrictions are what naturally determine the size of the TextBlock.

The text in textblocks can include manual line-breaks by using the character escape, `\n`.

Leading and trailing whitespace is eliminated in each line of TextBlock text.

If editable is set to true, users can edit textblocks with the TextEditingTool.

textAlign
{string}

Gets or sets the alignment location in the TextBlock's given space.More... The possible values are `"start"`, `"end"`, `"left"`, `"right"`, and `"center"`. Any other value is invalid.

This property is most pertinent when the TextBlock has multiple lines of text, or when the TextBlock is given a size that differs from the text's natural size (such as with desiredSize).

In left-to-right writing systems, `"start"` and `"left"` are synonymous, as are `"end"` and `"right"`.

The default is `"start"`.

See also:

- verticalAlignment

textEdited
{function(TextBlock, string, string) | null} 1.7

Gets or sets the function that is called after the TextBlock's text has been edited by the TextEditingTool.More...

- The first argument is a reference to this TextBlock.
- The second argument is the previous text, before editing.
- The third argument is the current text, which is also TextBlock.text.

    function(textBlock, previousText, currentText)

The default value is null -- no function is called.

textEditor
{HTMLInfo|HTMLElement}

Gets or sets the HTMLInfo or HTML Element that this TextBlock uses as its text editor in the TextEditingTool.More... If null, the TextBlock will use the default text editor of the TextEditingTool. The default is null. The value should be set to an instance of HTMLInfo. Setting this to an HTML Element is deprecated functionality, but it will continue to work until version 2.0.

For example usage, see the Custom TextEditingTool Sample.

textValidation
{function(TextBlock, string, string):boolean | null}

Gets or sets the predicate that determines whether or not a user-edited string of text is valid.More... If this is non-null, the predicate is called in addition to any TextEditingTool.textValidation predicate. See TextEditingTool.isValidText for more details.

    function(textBlock, oldString, newString)

The default predicate is null, which is equivalent to simply returning true.

The function, if supplied, must not have any side-effects, and must return true or false.

See also:

- TextEditingTool.textValidation

verticalAlignment
{Spot} 1.7

Gets or sets the vertical alignment Spot of this TextBlock, used when the TextBlock has more available vertical space than it needs to draw all lines.More...

The default value is Spot.Top, which aligns the TextBlock to the top of its available space.

The textAlign is often used along with this property to specify where the should be positioned in its available space.

This does not affect TextBlock coordinates or bounds, it only affects where text is drawn within the given area.

See also:

- textAlign

wrap
{EnumValue}

Gets or sets whether the text should be wrapped if it is too long to fit on one line.More...

Possible values are TextBlock.WrapDesiredSize TextBlock.WrapFit and TextBlock.None.

The default value is TextBlock.WrapDesiredSize.

See also:

- overflow

Properties borrowed from class GraphObject:
  actionCancel, actionDown, actionMove, actionUp, actualBounds, alignment, alignmentFocus, angle, areaBackground, background, click, column, columnSpan, contextClick, contextMenu, cursor, Default, desiredSize, diagram, doubleClick, enabledChanged, Fill, fromEndSegmentLength, fromLinkable, fromLinkableDuplicates, fromLinkableSelfNode, fromMaxLinks, fromShortLength, fromSpot, height, Horizontal, isActionable, isPanelMain, layer, margin, maxSize, measuredBounds, minSize, mouseDragEnter, mouseDragLeave, mouseDrop, mouseEnter, mouseHold, mouseHover, mouseLeave, mouseOver, name, opacity, panel, part, pickable, portId, position, row, rowSpan, scale, segmentFraction, segmentIndex, segmentOffset, segmentOrientation, shadowVisible, stretch, toEndSegmentLength, toLinkable, toLinkableDuplicates, toLinkableSelfNode, toMaxLinks, toolTip, toShortLength, toSpot, Uniform, UniformToFill, Vertical, visible, width

Methods borrowed from class GraphObject:
  bind, copy, getDocumentAngle, getDocumentPoint, getDocumentScale, getLocalPoint, isContainedBy, isEnabledObject, isVisibleObject, setProperties

## Constants Summary Details

Name | Description
--- | ---
None {EnumValue} | Used as a value for TextBlock.wrap, the TextBlock will not wrap its text.
OverflowClip 1.4 {EnumValue} | Used as the default value for TextBlock.overflow: if the width is too small to display all text, the TextBlock will clip.
OverflowEllipsis 1.4 {EnumValue} | Used as a value for TextBlock.overflow: if the width is too small to display all text, the TextBlock will display an ellipsis.
WrapDesiredSize {EnumValue} | Used as the default value for TextBlock.wrap, the TextBlock will wrap text and the width of the TextBlock will be the desiredSize's width, if any.
WrapFit {EnumValue} | Used as a value for TextBlock.wrap, the TextBlock will wrap text, making the width of the TextBlock equal to the width of the longest line.