I

ILabelDefaults

Interface used by IGraph and the like to declare and obtain the defaults for labels.
Inheritance Hierarchy

Remarks

Note that changing these defaults does not change properties of already created model items. Rather, only items created after the change are affected.

Examples

Setting defaults for labels
// Labels on nodes, edges, and ports have different ILabelDefaults instances.
// These can be retrieved from their owner type's defaults

// the defaults for node labels can be set on the ILabelDefaults instance
// found at the Labels property of the node defaults
graph.nodeDefaults.labels.layoutParameter = InteriorNodeLabelModel.CENTER
graph.nodeDefaults.labels.style = new LabelStyle()

// the defaults for edge labels can be set on the ILabelDefaults instance
// found at the Labels property of the edge defaults
graph.edgeDefaults.labels.layoutParameter =
  new EdgeSegmentLabelModel().createParameterFromCenter()
graph.edgeDefaults.labels.style = new LabelStyle()

// defaults for port labels can be set on the ILabelDefaults instance
// found at the Labels property of their owner type's defaults
graph.nodeDefaults.ports.labels.layoutParameter =
  new InsideOutsidePortLabelModel().createInsideParameter()
graph.edgeDefaults.ports.labels.layoutParameter =
  FreePortLabelModel.CENTER

See Also

Developer's Guide

API

labels, labels, nodeDefaults, edgeDefaults, groupNodeDefaults

Members

No filters for this type

Properties

Gets or sets a property that determines whether to automatically adjust the preferred size of a label.
On a call to setLabelText or setStyle, the preferred size of the label will automatically be adjusted to the preferred size that is suggested by the label's style renderer, if this property is set to true.
abstract

Examples

const node = graph.createNodeAt(new Point(0, 0))
const label = graph.addLabel(node, 'Text')
const preferredSize1 = label.preferredSize
// enable auto adjust
graph.nodeDefaults.labels.autoAdjustPreferredSize = true
graph.setLabelText(label, 'Another Label Text')
const preferredSize2 = label.preferredSize
// preferred size has been adjusted to changed text
console.log(preferredSize1.equals(preferredSize2)) // false

// disable auto adjust
graph.nodeDefaults.labels.autoAdjustPreferredSize = false
graph.setLabelText(label, 'x')
const preferredSize3 = label.preferredSize
// preferred size has not been adjusted to changed text
console.log(preferredSize2.equals(preferredSize3)) // true

// adjusting the preferred size can be triggered manually, though
graph.adjustLabelPreferredSize(label)

See Also

API
getPreferredSize
Gets or sets the label model parameter to use for labels.
Depending on the setting of shareLayoutParameterInstance, the getLayoutParameterInstance method should return a clone of this instance or the very same instance.
abstract

Property Value

The parameter to use as a template.

Examples

graph.nodeDefaults.labels.layoutParameter = InteriorNodeLabelModel.CENTER
graph.nodeDefaults.labels.style = new LabelStyle()

See Also

API
shareLayoutParameterInstance, getLayoutParameterInstance
Gets or sets a value indicating whether the layoutParameter instance should be shared referentially or cloned upon a call to getLayoutParameterInstance.
abstract

Property Value

true if the reference should be shared; false otherwise.

See Also

API
getLayoutParameterInstance, layoutParameter
Gets or sets a value indicating whether the style instance should be shared referentially or cloned upon a call to getStyleInstance.
abstract

Property Value

true if the reference should be shared; false otherwise.

Examples

Shared vs. cloned styles
const n1 = graph.createNodeAt(new Point(0, 0))
const n2 = graph.createNodeAt(new Point(0, 50))
const n3 = graph.createNodeAt(new Point(0, 100))
const n4 = graph.createNodeAt(new Point(0, 150))

const defaultStyle = new LabelStyle()
graph.nodeDefaults.labels.style = defaultStyle

// share style instances
graph.nodeDefaults.labels.shareStyleInstance = true
const l1 = graph.addLabel(n1, 'Text')
const l2 = graph.addLabel(n2, 'Text')
// l1.style === defaultStyle; l2.style === defaultStyle; l1.style === l2.style;
defaultStyle.backgroundFill = Color.RED // l1 and l2 both turn red, too

// clone style instances
graph.nodeDefaults.labels.shareStyleInstance = false
const l3 = graph.addLabel(n3, 'Text')
const l4 = graph.addLabel(n4, 'Text')
// l3.style !== defaultStyle; l4.style !== defaultStyle; l3.style !== l4.style;
defaultStyle.backgroundFill = Color.YELLOW // l3 and l4 don't change their color

See Also

API
getStyleInstance, style
Gets or sets the style to use for labels.
Depending on the setting of shareStyleInstance, the getStyleInstance method should return a clone of this instance or the very same instance.
abstract

Property Value

The style to use as a template.

Examples

graph.nodeDefaults.labels.layoutParameter = InteriorNodeLabelModel.CENTER
graph.nodeDefaults.labels.style = new LabelStyle()

See Also

API
shareStyleInstance

Implemented in

LabelDefaults.style

Methods

Factory method that returns a label model parameter instance for use with newly created labels.
Most implementations will yield either, a clone of or the layoutParameter property, if shareLayoutParameterInstance is enabled, but they might use more complicated logic, too.
abstract

Parameters

owner: ILabelOwner
The owner of the label that will be created.

Return Value

ILabelModelParameter
The parameter to use, which for most implementations is either a clone of or the layoutParameter property, if shareLayoutParameterInstance is enabled.
Factory method that returns a style instance for use with newly created labels.
Most implementations will yield either, a clone of or the style property, if shareStyleInstance is enabled, but they might use more complicated logic, too.
abstract

Parameters

owner: ILabelOwner
The owner of the label that will be created.

Return Value

ILabelStyle
The style to use, which for most implementations is either a clone of or the style property, if shareStyleInstance is enabled.