# Class PortShiftingTool

GoJS® Diagramming Components
version 3.0.7
by Northwoods Software®

This is an extension and not part of the main GoJS library. Note that the API for this class may change at any time. If you intend to use an extension in production, you should copy the code to your own source directory. See the Extensions intro page for more information.

#### Hierarchy

- Tool
  - PortShiftingTool

The PortShiftingTool class lets a user move a port on a go.Node.

This tool only works when the Node has a port (any GraphObject) marked with a non-null and non-empty portId that is positioned in a Spot Panel, and the user holds down the Shift key. It works by modifying that port's go.GraphObject.alignment property.

If you want to experiment with this extension, try the Port Shifting sample.

#####
Index

### Constructors

constructor

### Methods

canStart
doActivate
doCancel
doDeactivate
doMouseMove
doMouseUp
doStop
findPort
updateAlignment

### Properties

port

#####
Inherited Index

### Accessors

Tool.diagram
Tool.isActive
Tool.isEnabled
Tool.name
Tool.transactionResult

### Methods

Tool.canStartMultiTouch
Tool.cancelWaitAfter
Tool.doKeyDown
Tool.doKeyUp
Tool.doMouseDown
Tool.doMouseWheel
Tool.doStart
Tool.doWaitAfter
Tool.findToolHandleAt
Tool.isBeyondDragSize
Tool.standardMouseClick
Tool.standardMouseOver
Tool.standardMouseSelect
Tool.standardMouseWheel
Tool.standardPinchZoomMove
Tool.standardPinchZoomStart
Tool.standardWaitAfter
Tool.startTransaction
Tool.stopTool
Tool.stopTransaction
Tool.updateAdornments

## Constructors

### constructor

- new PortShiftingTool(init?: Partial<PortShiftingTool>): PortShiftingTool

- Constructs a PortShiftingTool and sets the name for the tool.

  #### Parameters

  - ##### `Optional` init: Partial<PortShiftingTool>

  #### Returns PortShiftingTool

## Methods

### `Override` canStart

- canStart(): boolean

- This tool can only start if the mouse has moved enough so that it is not a click, and if the mouse down point is on a GraphObject "port" in a Spot Panel, as determined by findPort.

  #### Returns boolean

### `Override` doActivate

- doActivate(): void

- Start a transaction, call findPort and remember it as the "port" property, and remember the original value for the port's go.GraphObject.alignment property.

  #### Returns void

### `Override` doCancel

- doCancel(): void

- Restore the port's original value for GraphObject.alignment.

  #### Returns void

### `Override` doDeactivate

- doDeactivate(): void

- Stop any ongoing transaction.

  #### Returns void

### `Override` doMouseMove

- doMouseMove(): void

- During the drag, call updateAlignment in order to set the go.GraphObject.alignment of the port.

  #### Returns void

### `Override` doMouseUp

- doMouseUp(): void

- At the end of the drag, update the alignment of the port and finish the tool, completing a transaction.

  #### Returns void

### `Override` doStop

- doStop(): void

- Clear any reference to a port element.

  #### Returns void

### findPort

- findPort(): GraphObject

- From the go.GraphObject at the mouse point, search up the visual tree until we get to an object that has the go.GraphObject.portId property set to a non-empty string, that is in a Spot Panel, and that is not the main element of the panel (typically the first element).

  #### Returns GraphObject

  This returns null if no such port is at the mouse down point.

### updateAlignment

- updateAlignment(): void

- Save the port's go.GraphObject.alignment as a fractional Spot in the Spot Panel that the port is in. Thus if the main element changes size, the relative positions of the ports will be maintained. But that does assume that the port must remain inside the main element -- it cannot wander away from the node. This does not modify the port's go.GraphObject.alignmentFocus property.

  #### Returns void

## Properties

### port
: GraphObject

The port being shifted.

Copyright © 1998-2024 by Northwoods Software Corporation.