Label

Label

Helper class for various types of labels to be drawn on/around the Link. Consists of two main SVG elements:

  • An SVG Text element with the label text, drawn in some given colour
  • Another SVG Text element with the same text, but with a larger stroke width and drawn in white, to serve as the background for the main element

Constructor

new Label(mainSvg, svg, text, addClass)

Parameters:
Name Type Description
mainSvg

The main SVG document (for firing events, etc.)

svg svgjs.Doc

The SVG document/group to draw the Text elements in

text String

The text of the Label

addClass String

Any additional CSS classes to add to the SVG elements

Source:

Members

svgText :svgjs.Text

Source:

Methods

show()

Shows the Label text elements

Source:

hide()

Hides the Label text elements

Source:

move(x, y)

Moves the centre of the baseline of the Label text elements to the given coordinates (N.B.: SVG Text elements are positioned horizontally by their centres, by default. Also, setting the y-attribute directly allows us to move the Text element directly by its baseline, rather than its top edge)

Parameters:
Name Type Description
x

New horizontal centre of the Label

y

New baseline of the Label

Source:

centre(x, y)

Centres the Label elements horizontally and vertically on the given point

Parameters:
Name Type Description
x

New horizontal centre of the Label

y

New vertical centre of the Label

Source:

length()

Returns the length (i.e., width) of the main label https://svgjs.com/docs/2.7/elements/#text-length

Source:

drawTextBbox()

Draws the outline of the text element's bounding box

Source: