Interface IBehavior
A behavior that can observe and optionally intercept graph input events.
public interface IBehavior
Remarks
Behaviors provide an extensibility mechanism for customizing graph interactions without modifying the core input handling logic. They are inspired by the Behavior pattern from Blazor.Diagrams.
Lifecycle:
- Before core processing: OnBeforePointerPressed(IGraphInputEvent) etc.
- Core processing (InputProcessor) runs if not suppressed
- After core processing: OnAfterPointerPressed(IGraphInputEvent) etc.
Performance (Gemini Optimization): Behaviors can specify which states they're active in via ActiveInStates. The dispatcher skips behaviors that aren't relevant to the current state, avoiding iteration overhead on high-frequency events like PointerMoved.
Use Cases:
- Custom selection modes (marquee, lasso)
- Snap-to-grid visualization
- Connection validation feedback
- Accessibility enhancements
- Analytics/logging
Properties
ActiveInStates
The input state names this behavior is active in. If null or empty, the behavior is active in all states.
IReadOnlySet<string>? ActiveInStates { get; }
Property Value
Remarks
Gemini Optimization: Behaviors that are only relevant in specific states (e.g., a selection box behavior only during Idle or BoxSelecting) should specify those states here. The dispatcher will skip the behavior entirely in other states, avoiding unnecessary method calls on high-frequency events.
State names match IInputState.Name (e.g., "Idle", "Dragging", "Panning").
IsEnabled
Whether this behavior is currently active. Disabled behaviors receive no events.
bool IsEnabled { get; set; }
Property Value
Name
Display name for debugging and UI purposes.
string Name { get; }
Property Value
Priority
Priority relative to other behaviors. Higher = called first. Default behaviors use 0. Use negative for "always last" behaviors.
int Priority { get; }
Property Value
Methods
IsActiveInState(string)
Checks if this behavior should be invoked for the given state. Default: active in all states if ActiveInStates is null/empty.
bool IsActiveInState(string stateName)
Parameters
stateNamestring
Returns
OnAfterKeyDown(IGraphInputEvent)
Called after key down has been processed.
void OnAfterKeyDown(IGraphInputEvent e)
Parameters
OnAfterPointerMoved(IGraphInputEvent)
Called after pointer moved has been processed.
void OnAfterPointerMoved(IGraphInputEvent e)
Parameters
OnAfterPointerPressed(IGraphInputEvent)
Called after pointer pressed has been processed.
void OnAfterPointerPressed(IGraphInputEvent e)
Parameters
OnAfterPointerReleased(IGraphInputEvent)
Called after pointer released has been processed.
void OnAfterPointerReleased(IGraphInputEvent e)
Parameters
OnAfterPointerWheel(IGraphInputEvent)
Called after wheel/scroll has been processed.
void OnAfterPointerWheel(IGraphInputEvent e)
Parameters
OnAttached(Graph)
Called when the behavior is attached to a graph canvas.
void OnAttached(Graph graph)
Parameters
graphGraph
OnBeforeKeyDown(IGraphInputEvent)
Called before key down is processed.
BehaviorResult OnBeforeKeyDown(IGraphInputEvent e)
Parameters
Returns
OnBeforePointerMoved(IGraphInputEvent)
Called before pointer moved is processed.
BehaviorResult OnBeforePointerMoved(IGraphInputEvent e)
Parameters
Returns
OnBeforePointerPressed(IGraphInputEvent)
Called before pointer pressed is processed. Return HandledSuppress to prevent default handling.
BehaviorResult OnBeforePointerPressed(IGraphInputEvent e)
Parameters
Returns
OnBeforePointerReleased(IGraphInputEvent)
Called before pointer released is processed.
BehaviorResult OnBeforePointerReleased(IGraphInputEvent e)
Parameters
Returns
OnBeforePointerWheel(IGraphInputEvent)
Called before wheel/scroll is processed.
BehaviorResult OnBeforePointerWheel(IGraphInputEvent e)
Parameters
Returns
OnDetached()
Called when the behavior is detached from a graph canvas.
void OnDetached()