Helper interface to handle interactive label editing.
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
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)
}
}
graph.decorator.edges.editLabelHelper.addWrapperFactory(
(label, helper) => new WrappingEditLabelHelper(helper),
)
Type Details
- yFiles module
- view
See Also
Methods
Invoked if the label editing action has been canceled.
Remarks
Parameters
A map of options to pass to the method.
- context - IInputModeContext
- The current input mode context.
- evt - LabelEditingEventArgs
- Additional information about the label or label owner and whether the editing operation has been canceled programmatically.
Invoked after the label editing gesture has successfully finished.
Remarks
Depending on the action
, implementations have to either ADD a new label, change the text of the given label, or REMOVE the given label.
For operations that fail or are not supported by the implementation, this method has to return null
.
Implementations which maintain a state have to clean up here.
Parameters
A map of options to pass to the method.
- context - IInputModeContext
- The input mode context from the input mode which invoked that method.
- evt - LabelEditingEventArgs
- The LabelEditingEventArgs which provide the information for the label to be added or edited. In particular,
evt
provides the owner for newly added labels or the label to edit or remove, and the text to set when adding or editing labels. - action - LabelEditingAction
Returns
- ↪ILabel?
- The added, edited, or removed label if the action has been completed successfully and
null
otherwise.
Invoked at the beginning of a label adding or label editing gesture.
Remarks
The LabelEditingEventArgs can be configured to customize the label editing behavior. It is also possible to set a custom label or owner. Finally, label editing can be prevented by setting cancel to true.
Implementations which need to maintain a state can configure the state here and clean it up in both finish and cancel. It is important, that these implementations set LabelEditingEventArgs's handled to true
to make sure that no other IEditLabelHelper implementation takes over.
Parameters
A map of options to pass to the method.
- context - IInputModeContext
- The input mode context from the input mode which invoked that method.
- evt - LabelEditingEventArgs
- A configuration object which supports customizing the label editing.
- action - LabelEditingAction
Static Methods
Parameters
A map of options to pass to the method.
- initialize - function(IInputModeContext, LabelEditingEventArgs, LabelEditingAction):void
Invoked at the beginning of a label adding or label editing gesture.
This property holds the implementation for initialize.
- finish - function(IInputModeContext, LabelEditingEventArgs, LabelEditingAction):ILabel
Invoked after the label editing gesture has successfully finished.
This property holds the implementation for finish.
- cancel - function(IInputModeContext, LabelEditingEventArgs):void
Invoked if the label editing action has been canceled.
This property holds the implementation for cancel.