documentationfor yFiles for HTML 3.0.0.3

GenericLabelingData<TNode,TEdge,TNodeLabel,TEdgeLabel>

Specifies custom data for the GenericLabeling.

Inheritance Hierarchy

Examples

The following example shows how to create a new instance of GenericLabelingData<TNode,TEdge,TNodeLabel,TEdgeLabel> and use it with a GenericLabeling:

Creating an instance of LabelingData
const layoutData = new GenericLabelingData()
layoutData.scope.nodeLabels = graphComponent.selection.labels.filter(
  (label) => label.owner instanceof INode,
)
layoutData.scope.edgeLabels = graphComponent.selection.labels.filter(
  (label) => label.owner instanceof IEdge,
)
layoutData.edgeLabelPreferredPlacements = (
  label: ILabel,
): EdgeLabelPreferredPlacement =>
  new EdgeLabelPreferredPlacement({
    // Place short labels horizontally, and others along the edge
    angleReference:
      label.text.length < 5
        ? LabelAngleReferences.ABSOLUTE
        : LabelAngleReferences.RELATIVE_TO_EDGE_FLOW,
  })

graphComponent.graph.applyLayout(new GenericLabeling(), layoutData)

In many cases the complete initialization of GenericLabelingData<TNode,TEdge,TNodeLabel,TEdgeLabel> can also be done in a single object initializer:

Using an object initializer for easy creation of LabelingData
const layoutData = new GenericLabelingData({
  edgeLabelPreferredPlacements: (
    label: ILabel,
  ): EdgeLabelPreferredPlacement =>
    new EdgeLabelPreferredPlacement({
      // Place short labels horizontally, and others along the edge
      angleReference:
        label.text.length < 5
          ? LabelAngleReferences.ABSOLUTE
          : LabelAngleReferences.RELATIVE_TO_EDGE_FLOW,
    }),
})
layoutData.scope.nodeLabels = graphComponent.selection.labels.filter(
  (label) => label.owner instanceof INode,
)
layoutData.scope.edgeLabels = graphComponent.selection.labels.filter(
  (label) => label.owner instanceof IEdge,
)

graphComponent.graph.applyLayout(new GenericLabeling(), layoutData)

Type Parameters

TNode
TEdge
TNodeLabel
TEdgeLabel

Type Details

yFiles module
algorithms

Constructors

Properties

Methods