# Class DragZoomingTool

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
  - DragZoomingTool

The DragZoomingTool lets the user zoom into a diagram by stretching a box to indicate the new contents of the diagram's viewport (the area of the model shown by the Diagram). Hold down the Shift key in order to zoom out.

The default drag selection box is a magenta rectangle. You can modify the box to customize its appearance.

The diagram that is zoomed by this tool is specified by the zoomedDiagram property. If the value is null, the tool zooms its own go.Tool.diagram.

You can use this tool in a modal manner by executing:

      diagram.currentTool = new DragZoomingTool();

Use this tool in a mode-less manner by executing:

      myDiagram.toolManager.mouseMoveTools.insertAt(2, new DragZoomingTool());

However when used mode-lessly as a mouse-move tool, in go.ToolManager.mouseMoveTools, this cannot start running unless there has been a motionless delay after the mouse-down event of at least delay milliseconds.

This tool does not utilize any go.Adornments or tool handles, but it does temporarily add the box part to the diagram. This tool does not modify the model or conduct any transaction.

If you want to experiment with this extension, try the Drag Zooming sample.

#####
Index

### Constructors

constructor

### Accessors

box
delay
zoomedDiagram

### Methods

canStart
computeBoxBounds
doActivate
doDeactivate
doMouseMove
doMouseUp
zoomToRect

#####
Inherited Index

### Accessors

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

### Methods

Tool.canStartMultiTouch
Tool.cancelWaitAfter
Tool.doCancel
Tool.doKeyDown
Tool.doKeyUp
Tool.doMouseDown
Tool.doMouseWheel
Tool.doStart
Tool.doStop
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 DragZoomingTool(init?: Partial<DragZoomingTool>): DragZoomingTool

- Constructs a DragZoomingTool, sets box to a magenta rectangle, and sets name of the tool.

  #### Parameters

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

  #### Returns DragZoomingTool

## Accessors

### box
: Part

- Gets or sets the go.Part used as the "rubber-band zoom box" that is stretched to follow the mouse, as feedback for what area will be passed to zoomToRect upon a mouse-up.

  Initially this is a go.Part containing only a simple magenta rectangular go.Shape. The object to be resized should be named "SHAPE". Setting this property does not raise any events.

  Modifying this property while this tool go.Tool.isActive might have no effect.

### delay
: number

- Gets or sets the time in milliseconds for which the mouse must be stationary before this tool can be started.

  The default value is 175 milliseconds. Setting this property does not raise any events.

### zoomedDiagram
: Diagram

- Gets or sets the go.Diagram whose go.Diagram.position and go.Diagram.scale should be set to display the drawn box rectangular bounds.

  The default value is null, which causes zoomToRect to modify this tool's go.Tool.diagram. Setting this property does not raise any events.

## Methods

### `Override` canStart

- canStart(): boolean

- This tool can run when there has been a mouse-drag, far enough away not to be a click, and there has been delay of at least delay milliseconds after the mouse-down before a mouse-move.

  #### Returns boolean

### computeBoxBounds

- computeBoxBounds(): Rect

- This just returns a go.Rect stretching from the mouse-down point to the current mouse point while maintaining the aspect ratio of the zoomedDiagram.

  #### Returns Rect

  a go.Rect in document coordinates.

### `Override` doActivate

- doActivate(): void

- Capture the mouse and show the box.

  #### Returns void

### `Override` doDeactivate

- doDeactivate(): void

- Release the mouse and remove any box.

  #### Returns void

### `Override` doMouseMove

- doMouseMove(): void

- Update the box's position and size according to the value of computeBoxBounds.

  #### Returns void

### `Override` doMouseUp

- doMouseUp(): void

- Call zoomToRect with the value of a call to computeBoxBounds.

  #### Returns void

### zoomToRect

- zoomToRect(r: Rect): void

- This method is called to change the zoomedDiagram's viewport to match the given rectangle.

  #### Parameters

  - ##### r: Rect

    a rectangular bounds in document coordinates.

  #### Returns void

Copyright © 1998-2024 by Northwoods Software Corporation.