GeezerVison is showing maxgraph.github.io — EdgeHandler | @maxgraph/core
Graph event handler that reconnects edges, modifies control points and the edge label location.
It displays a handle on each waypoint of the edge, and one on each terminal to reconnect it.
Uses CellMarker for finding and highlighting new source and target vertices.
Instantiation
This is the handler of the 'default' EdgeStyleHandlerKind. SelectionCellsHandler creates it for
each selected edge whose EdgeStyle is registered under that kind in EdgeStyleRegistry, which covers the
built-in entityRelationEdgeStyle, the edges without EdgeStyle, and any kind having no registered factory.
To have maxGraph create a custom implementation instead, register a factory on the plugin:
selectionCellsHandler.setEdgeHandlerFactory('default', (state) => new MyEdgeHandler(state));
Configuration
Some elements of this handler and its subclasses can be configured globally using EdgeHandlerConfig and
HandleConfig.
Constructors
constructor
-
new EdgeHandler(state: CellState): EdgeHandler
Properties
abspoints
abspoints: ( Point | null) [] = []
active
active: boolean = true
allowHandleBoundsCheck
allowHandleBoundsCheck: boolean = true
Specifies if the bounds of handles should be used for hit-detection in IE.
bends
Holds the Shapes that represent the points.
cloneEnabled
cloneEnabled: boolean = true
Specifies if cloning by control-drag is enabled.
currentPoint
currentPoint: Point | null = null
dblClickRemoveEnabled
dblClickRemoveEnabled: boolean = false
Specifies if removing bends by double click is enabled.
error
error: string | null = null
Holds the current validation error while a connection is being changed.
escapeHandler
escapeHandler: (sender: Listenable, evt: Event) => void
handleImage
Optional Image to be used as handles.
index
index: number | null = null
isLabel
isLabel: boolean = false
isSource
isSource: boolean = false
isTarget
isTarget: boolean = false
labelHandleImage
labelHandleImage: ImageBox | null = null
labelShape
Holds the Shape that represents the label position.
manageLabelHandle
manageLabelHandle: boolean = false
Specifies if the label handle should be moved if it intersects with another
handle. Uses checkLabelHandle for checking and moving.
marker
Holds the CellMarker which is used for highlighting terminals.
mergeRemoveEnabled
mergeRemoveEnabled: boolean = false
Specifies if removing bends by dropping them on other bends is enabled.
outline
outline: boolean = true
outlineConnect
outlineConnect: boolean = false
Specifies if connections to the outline of a highlighted target should be
enabled. This will allow to place the connection point along the outline of
the highlighted target.
parentHighlightEnabled
parentHighlightEnabled: boolean = false
Specifies if the parent should be highlighted if a child cell is selected.
preferHtml
preferHtml: boolean = false
Specifies if bends should be added to the graph container.
This is updated in constructor based on whether the edge or one of its terminals has an HTML label in the container.
shape
Holds the Shape that represents the preview edge.
snapPoint
snapPoint: Point | null = null
snapToTerminals
snapToTerminals: boolean = false
Specifies if waypoints should snap to the routing centers of terminals.
startX
startX: number = 0
startY
startY: number = 0
straightRemoveEnabled
straightRemoveEnabled: boolean = false
Specifies if removing bends by creating straight segments should be enabled.
If enabled, this can be overridden by holding down the alt key while moving.
tolerance
tolerance: number = 0
virtualBends
virtualBends: Shape[] | undefined
Methods
addPoint
-
addPoint(state: CellState, evt: MouseEvent): void
Adds a control point for the given state and event.
Returns void
addPointAt
-
addPointAt(state: CellState, x: number, y: number): void
Adds a control point at the given point.
Returns void
changePoints
-
Changes the control points of the given edge in the graph model.
changeTerminalPoint
-
changeTerminalPoint( edge: Cell, point: Point, isSource: boolean, clone: boolean,): Cell
Changes the terminal point of the given edge.
Parameters
- edge: Cell
- point: Point
- isSource: boolean
- clone: boolean
checkLabelHandle
-
Checks if the label handle intersects the given bounds and moves it if it
intersects.
Returns void
clonePreviewState
-
Returns a clone of the current preview state for the given point and terminal.
connect
-
Changes the terminal or terminal point of the given edge in the graph model.
Parameters
- edge: Cell
Cell that represents the edge to be reconnected.
- terminal: Cell
Cell that represents the new terminal.
- isSource: boolean
Boolean indicating if the new terminal is the source or target terminal.
- _isClone: boolean
Boolean indicating if the new connection should be a clone of the old edge.
- _me: InternalMouseEvent
MouseEvent that contains the mouse up event.
convertPoint
-
convertPoint(point: Point, gridEnabled: boolean): Point
Converts the given point in-place from screen to unscaled, untranslated
graph coordinates and applies the grid. Returns the given, modified
point instance.
Parameters
- point: Point
- gridEnabled: boolean
Boolean that specifies if the grid should be applied.
createBends
-
Creates and returns the bends used for modifying the edge. This is
typically an array of RectangleShape.
ProtectedcreateConstraintHandler
createCustomHandles
-
Returns an array of custom handles. This implementation returns an empty array.
createHandleShape
-
createHandleShape(_index?: number): Shape
Creates the shape used to display the given bend.
Note that the index
Only images and rectangles should be returned if support for HTML labels with not foreign objects is required.
createLabelHandleShape
-
Creates the shape used to display the label handle.
createMarker
-
createMarker(): EdgeHandlerCellMarker
Returns EdgeHandlerCellMarker
createParentHighlightShape
-
Creates the shape used to draw the selection border.
createSelectionShape
-
createSelectionShape(points: ( Point | null) []): Shape
Creates the shape used to draw the selection border.
createVirtualBends
-
createVirtualBends(): Shape[]
Creates and returns the bends used for modifying the edge. This is
typically an array of RectangleShape.
destroyBends
-
Destroys all elements in bends.
Returns void
getCellAt
-
getCellAt(x: number, y: number): Cell | null
getHandleFillColor
-
getHandleFillColor(index: number): string
Returns the fillcolor for the handle at the given index.
Returns string
getHandleForEvent
-
Returns the index of the handle for the given event.
Returns number | null
getPointForEvent
-
Returns the point for the given event.
getPreviewPoints
-
Updates the given preview state taking into account the state of the constraint handler.
Parameters
- pt: Point
Point that contains the current pointer position.
Optionalme: InternalMouseEvent
Optional MouseEvent that contains the current event.
Returns Point[] | null
getPreviewTerminalState
-
Updates the given preview state taking into account the state of the constraint handler.
getSelectionColor
-
getSelectionColor(): string
getSelectionPoints
-
Returns the list of points that defines the selection stroke.
Returns (Point | null)[]
getSelectionStrokeWidth
-
getSelectionStrokeWidth(): number
getSnapToTerminalTolerance
-
getSnapToTerminalTolerance(): number
Returns the tolerance for the guides. Default value is
gridSize * scale / 2.
Returns number
initBend
-
initBend(bend: Shape, dblClick?: (evt: MouseEvent) => void): void
Helper method to initialize the given bend.
Parameters
- bend: Shape
Shape that represents the bend to be initialized.
OptionaldblClick: (evt: MouseEvent) => void
Optional function to be called on double click.
Returns void
isAddPointEvent
-
isAddPointEvent(evt: MouseEvent): boolean
Returns true if the given event is a trigger to add a new Point. This
implementation returns true if shift is pressed.
Returns boolean
isAddVirtualBendEvent
-
Returns true if the given event allows virtual bends to be added. This
implementation returns true.
Returns boolean
isCellEnabled
-
isCellEnabled(cell: Cell): boolean
Returns true if the given cell allows new connections to be created. This implementation
always returns true.
Returns boolean
isConnectableCell
-
isConnectableCell(cell: Cell): boolean
Returns true if the given cell is connectable. This is a hook to
disable floating connections. This implementation returns true.
Returns boolean
isCustomHandleEvent
-
Returns true if the given event allows custom handles to be changed. This
implementation returns true.
Returns boolean
isCustomHandleVisible
-
isCustomHandleVisible(handle: CellHandle): boolean
Returns true if the given custom handle is visible.
Returns boolean
isDestroyed
-
Returns true if destroy was called.
Returns boolean
isHandleEnabled
-
isHandleEnabled(index: number): boolean
Creates the shape used to display the given bend.
Returns boolean
isHandleVisible
-
isHandleVisible(index: number): boolean
Returns true if the handle at the given index is visible.
Returns boolean
isOutlineConnectEvent
-
Returns true if outlineConnect is true and the source of the event is the outline shape
or shift is pressed.
Returns boolean
isParentHighlightVisible
-
isParentHighlightVisible(): boolean | null
Returns true if the parent highlight should be visible. This implementation
always returns true.
Returns boolean | null
isRemovePointEvent
-
isRemovePointEvent(evt: MouseEvent): boolean
Returns true if the given event is a trigger to remove a point. This
implementation returns true if shift is pressed.
Returns boolean
isSelectionDashed
-
isSelectionDashed(): boolean
isVirtualBendsEnabled
-
isVirtualBendsEnabled(evt?: Event): boolean | undefined
Returns true if virtual bends should be added. This returns true if
virtualBendsEnabled is true and the current style allows and
renders custom waypoints.
Returns boolean | undefined
mouseDown
-
Handles the event by checking if a special element of the handler
was clicked, in which case the index parameter is non-null. The
indices may be one of InternalEvent.LABEL_HANDLE or the number of the respective
control point. The source and target points are used for reconnecting
the edge.
Returns void
mouseMove
-
Handles the event by updating the preview.
Returns void
moveLabel
-
moveLabel(edgeState: CellState, x: number, y: number): void
Changes the coordinates for the label of the given edge.
Parameters
- edgeState: CellState
- x: number
Integer that specifies the x-coordinate of the new location.
- y: number
Integer that specifies the y-coordinate of the new location.
Returns void
onDestroy
-
Destroys the handler and all its resources and DOM nodes. This does
normally not need to be called as handlers are destroyed automatically
when the corresponding cell is deselected.
Returns void
redraw
-
redraw(ignoreHandles?: boolean): void
Redraws the preview, and the bends- and label control points.
Parameters
OptionalignoreHandles: boolean
Returns void
redrawInnerBends
-
Updates and redraws the inner bends.
Parameters
- p0: Point
Point that represents the location of the first point.
- pe: Point
Point that represents the location of the last point.
Returns void
refresh
-
Refreshes the bends of this handler.
Returns void
removeHint
-
Hooks for subclassers to hide details when the handler gets inactive.
Returns void
removePoint
-
removePoint(state: CellState, index: number): void
Removes the control point at the given index from the given state.
Returns void
reset
-
Resets the state of this handler.
Returns void
roundLength
-
roundLength(length: number): number
Hook for rounding the unscaled width or height. This uses Math.round.
Returns number
setHandlesVisible
-
setHandlesVisible(visible: boolean): void
setPreviewColor
-
setPreviewColor(color: string): void
Sets the color of the preview to the given value.
Returns void
start
-
start(x: number, y: number, index: number): void
Starts the handling of the mouse gesture.
Parameters
- x: number
- y: number
- index: number
Returns void
updateHint
-
Hook for subclassers do show details while the handler is active.
Returns void
updateParentHighlight
-
updateParentHighlight(): void
updatePreviewState
-
Updates the given preview state taking into account the state of the constraint handler.
Returns void
validateConnection
-
validateConnection(source: Cell | null, target: Cell | null): string | null
Returns the error message or an empty string if the connection for the
given source, target pair is not valid. Otherwise, it returns null. This
implementation uses AbstractGraph.getEdgeValidationError.
Parameters
- source: Cell | null
Cell that represents the source terminal.
- target: Cell | null
Cell that represents the target terminal.
Returns string | null
On This Page
Constructors
Properties
Methods
|