# Class DrawCommandHandler

GoJS® Diagramming Components
version 3.0.14
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

- CommandHandler
  - DrawCommandHandler

This CommandHandler class allows the user to position selected Parts in a diagram relative to the first part selected, in addition to overriding the doKeyDown method of the CommandHandler for handling the arrow keys in additional manners.

Typical usage:

      new go.Diagram("myDiagramDiv",
        {
          commandHandler: new DrawCommandHandler(),
          . . .
        }
      )

or:

       myDiagram.commandHandler = new DrawCommandHandler();

If you want to experiment with this extension, try the Drawing Commands sample.

#####
Index

### Constructors

constructor

### Accessors

arrowKeyBehavior
pasteOffset

### Methods

alignBottom
alignCenterX
alignCenterY
alignColumn
alignLeft
alignRight
alignRow
alignTop
canAlignSelection
canRotate
copyToClipboard
doKeyDown
pasteFromClipboard
pullToFront
pushToBack
rotate
spaceEvenlyHorizontally
spaceEvenlyVertically

#####
Inherited Index

### Accessors

CommandHandler.archetypeGroupData
CommandHandler.copiesConnectedLinks
CommandHandler.copiesGroupKey
CommandHandler.copiesParentKey
CommandHandler.copiesTree
CommandHandler.deletesConnectedLinks
CommandHandler.deletesTree
CommandHandler.diagram
CommandHandler.isZoomToFitRestoreEnabled
CommandHandler.memberValidation
CommandHandler.zoomFactor

### Methods

CommandHandler.addTopLevelParts
CommandHandler.canCollapseSubGraph
CommandHandler.canCollapseTree
CommandHandler.canCopySelection
CommandHandler.canCutSelection
CommandHandler.canDecreaseZoom
CommandHandler.canDeleteSelection
CommandHandler.canEditTextBlock
CommandHandler.canExpandSubGraph
CommandHandler.canExpandTree
CommandHandler.canGroupSelection
CommandHandler.canIncreaseZoom
CommandHandler.canPasteSelection
CommandHandler.canRedo
CommandHandler.canResetZoom
CommandHandler.canScrollToPart
CommandHandler.canSelectAll
CommandHandler.canShowContextMenu
CommandHandler.canStopCommand
CommandHandler.canUndo
CommandHandler.canUngroupSelection
CommandHandler.canZoomToFit
CommandHandler.collapseSubGraph
CommandHandler.collapseTree
CommandHandler.computeEffectiveCollection
CommandHandler.copySelection
CommandHandler.cutSelection
CommandHandler.decreaseZoom
CommandHandler.deleteSelection
CommandHandler.doKeyUp
CommandHandler.editTextBlock
CommandHandler.expandSubGraph
CommandHandler.expandTree
CommandHandler.groupSelection
CommandHandler.increaseZoom
CommandHandler.isValidMember
CommandHandler.pasteSelection
CommandHandler.redo
CommandHandler.resetZoom
CommandHandler.scrollToPart
CommandHandler.selectAll
CommandHandler.showContextMenu
CommandHandler.stopCommand
CommandHandler.undo
CommandHandler.ungroupSelection
CommandHandler.zoomToFit

## Constructors

### constructor

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

- #### Parameters

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

  #### Returns DrawCommandHandler

## Accessors

### arrowKeyBehavior
: string

- Gets or sets the arrow key behavior. Possible values are "move", "select", "scroll", "tree", and "none".

  The default value is "move".

### pasteOffset
: Point

- Gets or sets the offset at which each repeated pasteSelection puts the new copied parts from the clipboard.

## Methods

### alignBottom

- alignBottom(): void

- Aligns selected parts at the bottom-most edge of the bottom-most part.

  #### Returns void

### alignCenterX

- alignCenterX(): void

- Aligns selected parts at the x-value of the center point of the first selected part.

  #### Returns void

### alignCenterY

- alignCenterY(): void

- Aligns selected parts at the y-value of the center point of the first selected part.

  #### Returns void

### alignColumn

- alignColumn(distance: number): void

- Aligns selected parts top-to-bottom in order of the order selected. Distance between parts can be specified. Default distance is 0.

  #### Parameters

  - ##### distance: number

  #### Returns void

### alignLeft

- alignLeft(): void

- Aligns selected parts along the left-most edge of the left-most part.

  #### Returns void

### alignRight

- alignRight(): void

- Aligns selected parts at the right-most edge of the right-most part.

  #### Returns void

### alignRow

- alignRow(distance: number): void

- Aligns selected parts left-to-right in order of the order selected. Distance between parts can be specified. Default distance is 0.

  #### Parameters

  - ##### distance: number

  #### Returns void

### alignTop

- alignTop(): void

- Aligns selected parts at the top-most edge of the top-most part.

  #### Returns void

### canAlignSelection

- canAlignSelection(): boolean

- This controls whether or not the user can invoke the alignLeft, alignRight, alignTop, alignBottom, alignCenterX, alignCenterY commands.

  #### Returns boolean

  This returns true: if the diagram is not go.Diagram.isReadOnly, if the model is not go.Model.isReadOnly, and if there are at least two selected go.Parts.

### canRotate

- canRotate(): boolean

- This controls whether or not the user can invoke the rotate command.

  #### Returns boolean

  This returns true: if the diagram is not go.Diagram.isReadOnly, if the model is not go.Model.isReadOnly, and if there is at least one selected go.Part.

### `Override` copyToClipboard

- copyToClipboard(coll: Iterable<Part>): void

- Reset the last offset for pasting.

  #### Parameters

  - ##### coll: Iterable<Part>

    a collection of go.Parts.

  #### Returns void

### `Override` doKeyDown

- doKeyDown(): void

- This implements custom behaviors for arrow key keyboard events. Set arrowKeyBehavior to "select", "move" (the default), "scroll" (the standard behavior), or "none" to affect the behavior when the user types an arrow key.

  #### Returns void

### `Override` pasteFromClipboard

- pasteFromClipboard(): Set<Part>

- Paste from the clipboard with an offset incremented on each paste, and reset when copied.

  #### Returns Set<Part>

  a collection of newly pasted go.Parts

### pullToFront

- pullToFront(): void

- Change the z-ordering of selected parts to pull them forward, in front of all other parts in their respective layers. All unselected parts in each layer with a selected Part with a non-numeric go.Part.zOrder will get a zOrder of zero.

  #### Returns void

### pushToBack

- pushToBack(): void

- Change the z-ordering of selected parts to push them backward, behind of all other parts in their respective layers. All unselected parts in each layer with a selected Part with a non-numeric go.Part.zOrder will get a zOrder of zero.

  #### Returns void

### rotate

- rotate(angle: number): void

- Change the angle of the parts connected with the given part. This is in the command handler so it can be easily accessed for the purpose of creating commands that change the rotation of a part.

  #### Parameters

  - ##### angle: number

    the positive (clockwise) or negative (counter-clockwise) change in the rotation angle of each Part, in degrees.

  #### Returns void

### spaceEvenlyHorizontally

- spaceEvenlyHorizontally(): void

- Position each selected non-Link horizontally so that each distance between them is the same, given the total width of the area occupied by them. Their Y positions are not modified. It tries to maintain the same ordering of selected Parts by their X position.

  Note that if there is not enough room, the spacing might be negative -- the Parts might overlap.

  #### Returns void

### spaceEvenlyVertically

- spaceEvenlyVertically(): void

- Position each selected non-Link vertically so that each distance between them is the same, given the total height of the area occupied by them. Their X positions are not modified. It tries to maintain the same ordering of selected Parts by their Y position.

  Note that if there is not enough room, the spacing might be negative -- the Parts might overlap.

  #### Returns void

Copyright © 1998-2024 by Northwoods Software Corporation.