documentationfor yFiles for HTML 3.0.0.3

IEditLabelHelper

Helper interface to handle interactive label editing.

Inheritance Hierarchy
IEditLabelHelper

Remarks

Implementations of this interface are by default retrieved from the ILookup of ILabelOwners and ILabels. If needed, different implementations can be decorated so that it is possible to tweak the behavior on a case by case basis. Hiding the implementation for both an ILabel and its owner can prevent adding or editing labels interactively.

Implementations have to handle ADDing or removing labels or changing a label's text upon finish. Unless developers want to implement all of these actions themselves, it is recommended to either wrap the default implementation or extend EditLabelHelper and call its base methods.

Developers who simply want to change the editing behavior via the LabelEditingEventArgs might also consider handling the query-label-adding and query-label-editing events.

Examples

A wrapper to customize a single aspect of edge editing
class WrappingEditLabelHelper extends BaseClass(IEditLabelHelper) {
  private wrapped!: IEditLabelHelper

  public WrappingEditLabelHelper(wrapped: IEditLabelHelper) {
    this.wrapped = wrapped
  }

  public initialize(
    context: IInputModeContext,
    evt: LabelEditingEventArgs,
    action: LabelEditingAction,
  ): void {
    // let the wrapped implementation do the work
    this.wrapped.initialize(context, evt, action)
    // for new edge labels: use a custom parameter
    if (action == LabelEditingAction.ADD && evt.owner instanceof IEdge) {
      evt.layoutParameter =
        new EdgeSegmentLabelModel().createParameterFromCenter()
    }
  }

  // Finish completely delegates to the wrapped implementation
  public finish(
    context: IInputModeContext,
    evt: LabelEditingEventArgs,
    action: LabelEditingAction,
  ): ILabel | null {
    return this.wrapped.finish(context, evt, action)
  }

  // Cancel completely delegates to the wrapped implementation
  public cancel(
    context: IInputModeContext,
    evt: LabelEditingEventArgs,
  ): void {
    this.wrapped.cancel(context, evt)
  }
}
Wrapping the edge's IEditLabelHelper
graph.decorator.edges.editLabelHelper.addWrapperFactory(
  (label, helper) => new WrappingEditLabelHelper(helper),
)

Type Details

yFiles module
view

See Also

Methods

Static Methods