Class LinkingTool

This abstract class is the base class for the LinkingTool and RelinkingTool classes. This class includes properties for defining and accessing any temporary nodes and temporary link that are used during any linking operation, as well as access to the existing diagram's nodes and link (if any) that are involved with the linking operation.

Hierarchy

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(): LinkingTool

You do not normally need to create an instance of this tool because one already exists as the ToolManager#linkingTool, which you can modify.

Returns

LinkingTool

Properties

public static BackwardsOnly: EnumValue

This value for LinkingTool#direction indicates that users may draw new links backwards only.

public static Either: EnumValue

This value for LinkingTool#direction indicates that users may draw new links in either direction.

public static ForwardsOnly: EnumValue

This value for LinkingTool#direction indicates that users may draw new links forwards only.

public archetypeLabelNodeData: Object

Gets or sets an optional node data object representing a link label, that is copied by #insertLink and added to the GraphLinksModel when creating a new Link.

public archetypeLinkData: Object

Gets or sets a data object that is copied by #insertLink and added to the GraphLinksModel when creating a new Link.

public diagram: Diagram

Gets the Diagram that owns this tool and for which this tool is handling input events.

public direction: EnumValue

Gets or sets the direction in which new links may be drawn.

public isActive: boolean

Gets or sets whether this tool is started and is actively doing something.

public isEnabled: boolean

Gets or sets whether this tool can be started by a mouse event.

public isForwards: boolean

Gets whether the linking operation is in the forwards direction, connecting from the "From" port to the "To" port.

public linkValidation: (fromNode: go.Node, fromPort: go.GraphObject, toNode: go.Node, toPort: go.GraphObject, link: go.Link) => boolean

Gets or sets a predicate that determines whether or not a new link between two ports would be valid.

public name: string

Gets or sets the name of this tool.

public originalFromNode: Node

Gets or sets the original Node from which the new link is being drawn or from which the #originalLink was connected when being relinked.

public originalFromPort: GraphObject

Gets or sets the GraphObject that is the port in the #originalFromNode.

public originalLink: Link

Gets or sets the original Link being reconnected by the RelinkingTool.

public originalToNode: Node

Gets or sets the original Node to which the new link is being drawn or to which the #originalLink was connected when being relinked.

public originalToPort: GraphObject

Gets or sets the GraphObject that is the port in the #originalToNode.

public portGravity: number

Gets or sets the distance at which link snapping occurs.

public portTargeted: (realNode: go.Node, realPort: go.GraphObject, tempNode: go.Node, tempPort: go.GraphObject, toend: boolean) => void

Gets or sets a function that is called as the tool targets the nearest valid port.

public startObject: GraphObject

Gets or sets the GraphObject at which #findLinkablePort should start its search.

public targetPort: GraphObject

Gets or sets a proposed GraphObject port for connecting a link.

public temporaryFromNode: Node

Gets or sets the temporary Node at the "from" end of the #temporaryLink while the user is drawing or reconnecting a link.

public temporaryFromPort: GraphObject

Gets or sets the GraphObject that is the port at the "from" end of the #temporaryLink while the user is drawing or reconnecting a link.

public temporaryLink: Link

Gets or sets the temporary Link that is shown while the user is drawing or reconnecting a link.

public temporaryToNode: Node

Gets or sets the temporary Node at the "to" end of the #temporaryLink while the user is drawing or reconnecting a link.

public temporaryToPort: GraphObject

Gets or sets the GraphObject that is the port at the "to" end of the #temporaryLink while the user is drawing or reconnecting a link.

public transactionResult: string

Gets or sets the name of the transaction to be committed by #stopTransaction; if null, the transaction will be rolled back.

Methods

public canStart(): boolean

This tool can run when the diagram allows linking, the model is modifiable, the left-button mouse drag has moved far enough away to not be a click, and when #findLinkablePort has returned a valid port.

Returns

boolean

public cancelWaitAfter(): any

This is called to cancel any running "WaitAfter" timer.

Returns

any

public copyPortProperties(realnode: Node, realport: GraphObject, tempnode: Node, tempport: GraphObject, toend: boolean): any

Make a temporary port look and act like a real one.

Parameters

Returns

any

public doActivate(): any

Start the linking operation.

Returns

any

public doCancel(): any

The diagram will call this method when the user wishes to cancel the current tool's operation.

Returns

any

public doDeactivate(): any

Finishing the linking operation stops the transaction, releases the mouse, and resets the cursor.

Returns

any

public doKeyDown(): any

The diagram will call this method upon a key down event.

Returns

any

public doKeyUp(): any

The diagram will call this method upon a key up event.

Returns

any

public doMouseDown(): any

The diagram will call this method upon a mouse down event.

Returns

any

public doMouseMove(): any

Mouse movement results in a temporary node moving to where a valid target port is located, or to where the mouse is if there is no valid target port nearby.

Returns

any

public doMouseUp(): any

A mouse-up ends the linking operation; if there is a valid #targetPort nearby, this adds a new Link by calling #insertLink.

Returns

any

public doMouseWheel(): any

The diagram will call this method as the mouse wheel is rotated.

Returns

any

public doStart(): any

This method is called by the diagram when this tool becomes the current tool; you should not call this method.

Returns

any

public doStop(): any

This method is called by the diagram when this tool stops being the current tool; you should not call this method.

Returns

any

public doWaitAfter(): any

This is called a certain delay after a call to #standardWaitAfter if there has not been any call to #cancelWaitAfter.

Returns

any

public findLinkablePort(): GraphObject

Return the GraphObject at the mouse-down point, if it is part of a node and if it is valid to link with it.

Returns

GraphObject

public findTargetPort(toend: boolean): GraphObject

Find a port with which the user could complete a valid link.

Parameters

  • toend: boolean

    true if looking for a "to" port.

Returns

GraphObject

public findToolHandleAt(p: Point, category: string): GraphObject

This convenience function finds the front-most GraphObject that is at a given point and that is part of an Adornment that is of a given category.

Parameters

  • p: Point

    a Point in document coordinates.

  • category: string

    the required Part#category of the Adornment.

Returns

GraphObject

public insertLink(fromnode: Node, fromport: GraphObject, tonode: Node, toport: GraphObject): Link

Make a copy of the #archetypeLinkData, set its node and port properties, and add it to the model.

Parameters

Returns

Link

public isBeyondDragSize(first?: Point, last?: Point): boolean

Return true when the last mouse point is far enough away from the first mouse down point to constitute a drag operation instead of just a potential click.

Parameters

  • first?: Point optional

    Point in view coordinates, defaults to Diagram#firstInput's InputEvent#viewPoint.

  • last?: Point optional

    Point in view coordinates, defaults to Diagram#lastInput's InputEvent#viewPoint.

Returns

boolean

public isInSameNode(fromport: GraphObject, toport: GraphObject): boolean

This predicate is true if both argument ports are in the same Node.

Parameters

Returns

boolean

public isLinked(fromport: GraphObject, toport: GraphObject): boolean

This predicate is true if there is a link in the diagram going from the given port to the given port

Parameters

Returns

boolean

public isValidFrom(fromnode: Node, fromport: GraphObject): boolean

This predicate is true if it is permissible to connect a link from a given node/port.

Parameters

  • fromnode: Node
  • fromport: GraphObject

    False if the node is in a Layer that does not Layer#allowLink. False if the port's GraphObject#fromLinkable is either false or null. False if the number of links connected to the port would exceed the port's GraphObject#fromMaxLinks. Otherwise true.

Returns

boolean

public isValidLink(fromnode: Node, fromport: GraphObject, tonode: Node, toport: GraphObject): boolean

This predicate should be true when it is logically valid to connect a new link from one node/port to another node/port.

Parameters

  • fromnode: Node

    the "from" Node.

  • fromport: GraphObject

    the "from" GraphObject port.

  • tonode: Node

    the "to" Node.

  • toport: GraphObject

    the "to" GraphObject port. False if #isValidFrom is false for the "from" node/port. False if #isValidTo is false for the "to" node/port. False if #isInSameNode is true unless GraphObject#fromLinkableSelfNode and GraphObject#toLinkableSelfNode are true for the two ports. False if #isLinked is true unless GraphObject#fromLinkableDuplicates and GraphObject#toLinkableDuplicates are true for the two ports. False if trying to link to the link's own label node(s). If #linkValidation is a predicate and if it returns false, this predicate returns false. Otherwise this predicate is true.

Returns

boolean

public isValidTo(tonode: Node, toport: GraphObject): boolean

This predicate is true if it is permissible to connect a link to a given node/port.

Parameters

  • tonode: Node
  • toport: GraphObject

    False if the node is in a Layer that does not Layer#allowLink. False if the port's GraphObject#toLinkable is either false or null. False if the number of links connected from the port would exceed the port's GraphObject#toMaxLinks. Otherwise true.

Returns

boolean

public setNoTargetPortProperties(tempnode: Node, tempport: GraphObject, toend: boolean): any

Reset a temporary port's properties to neutral values when there is no target port.

Parameters

Returns

any

public standardMouseClick(navig?: (obj: go.GraphObject) => go.GraphObject, pred?: (obj: go.GraphObject) => boolean): any

Implement the standard behavior for mouse clicks, searching for and calling click handler functions on GraphObjects or on Diagram, and raising the corresponding DiagramEvent.

Parameters

  • navig?: (obj: go.GraphObject) => go.GraphObject optional

    An optional custom navigation function to find target objects.

  • pred?: (obj: go.GraphObject) => boolean optional

    An optional custom predicate

Returns

any

public standardMouseOver(): any

Implement the standard behavior for mouse enter, over, and leave events, where the mouse is moving but no button is pressed.

Returns

any

public standardMouseSelect(): any

Implement the standard behavior for selecting parts with the mouse, depending on the control and shift modifier keys.

Returns

any

public standardMouseWheel(): any

Implement the standard behavior for mouse wheel events.

Returns

any

public standardWaitAfter(delay: number): any

This is called to start a new timer to call #doWaitAfter after a given delay.

Parameters

  • delay: number

    in milliseconds

Returns

any

public startTransaction(tname?: string): boolean

Call Diagram#startTransaction with the given transaction name.

Parameters

  • tname?: string optional

    a description of the transaction

Returns

boolean

public stopTool(): any

If the Diagram#currentTool is this tool, stop this tool and start the Diagram#defaultTool by making it be the new current tool.

Returns

any

public stopTransaction(): boolean

If #transactionResult is null, call Diagram#rollbackTransaction, otherwise call Diagram#commitTransaction.

Returns

boolean

public updateAdornments(part: Part): any

The diagram asks each tool to update any adornments the tool might use for a given part.

Parameters

Returns

any