Class ResizingTool

Extends Tool. The ResizingTool is used to interactively change the size of a GraphObject in the selected Part or Node by setting its GraphObject.desiredSize property. You may want to save the size to the model by using a TwoWay Binding on the "desiredSize" property of the GraphObject that is named by Part.resizeObjectName. This tool does not operate on Links.

You can limit the permitted minimum and maximum dimensions by setting minSize and maxSize. The resizing will also respect the GraphObject.minSize and GraphObject.maxSize properties. Width or height values that are NaN do not constrain the resizing.

You can also limit the width and/or height to be multiples of a particular size by setting Part.resizeCellSize. If either or both of these values are NaN, as they are by default, it will get the values from this tool's cellSize.

If either or both of the width and height are still NaN, and if DraggingTool.isGridSnapEnabled is true, it will use the DraggingTool.gridSnapCellSize. Finally it will consider the Diagram.grid's Panel.gridCellSize if isGridSnapEnabled is true.

Pressing the Shift key or resizing a Shape with a Shape.geometryStretch of GraphObject.Uniform or GraphObject.UniformToFill will maintain the aspect ratio during the resize.

This tool makes use of an Adornment, shown when the Part or Node is selected, that includes some number of resize handles. The resize handles are normally copies of ResizingTool.handleArchetype, unless you specify a custom resize Adornment by setting Part.resizeAdornmentTemplate.

This tool conducts a transaction while the tool is active. A successful resizing will result in a "PartResized" DiagramEvent and a "Resizing" transaction.

Constructor Summary Details

Name Description
ResizingTool()

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

The Tool.name of this tool is "Resizing".

Properties Summary Details

Name, Value Type Description
adornedObject

Gets the GraphObject that is being resized.More... This may be the same object as the selected Part or it may be contained within that Part.

This property is also settable, but should only be set when overriding functions in ResizingTool, and not during normal operation.

cellSize
{Size}

Gets or sets the width and height multiples with which the user must resize.More... The effective cell size is computed by first looking at the AdornedPart's Part.resizeCellSize. If either or both of its width and height are NaN, it will use this property, cellSize. If either or both of this property's width and height are NaN, it will consider the DraggingTool.gridSnapCellSize and the Diagram.grid's Panel.gridCellSize.

The default value is NaN x NaN. Setting this property does not raise any events.

handle

This read-only property returns the GraphObject that is the tool handle being dragged by the user.More... This will be contained by an Adornment whose category is "ResizingTool". Its Adornment.adornedObject is the same as the adornedObject.

handleArchetype

Gets or sets a small GraphObject that is copied as a resizing handle for the selected part.More... By default this is a Shape that is a small blue rectangle. Setting this property does not raise any events.

Here is an example of changing the default handle to be larger yellow circles:

  myDiagram.toolManager.resizingTool.handleArchetype =
    $(go.Shape, "Circle",
      { width: 10, height: 10, fill: "yellow" });

This property is ignored when a custom resizing Adornment is specified as the Part.resizeAdornmentTemplate.

isGridSnapEnabled
{boolean}

Gets or sets whether the ResizingTool snaps object sizes to the diagram's background grid during the resize.More... By default this property is false. Setting this property does not raise any events.

maxSize
{Size}

Gets or sets the maximum size to which the user can resize.More... The effective maximum size is the minimum of this value and the GraphObject.maxSize, independently in each direction.

The default value is 9999 x 9999. Any new value must be of type Size; the width and height must not be NaN. Setting this property does not raise any events.

minSize
{Size}

Gets or sets the minimum size to which the user can resize.More... The effective minimum size is the maximum of this value and the GraphObject.minSize, independently in each direction.

The default value is 1 x 1. Any new value must be of type Size; the width and height must not be NaN. Setting this property does not raise any events.

originalDesiredSize
{Size} 1.1

This read-only property returns the Size that was the original value of the GraphObject.desiredSize of the element that is being resized.

originalLocation
{Point} 1.1

This read-only property returns the Point that was the original value of the Part.location of the Part that is being resized.

Properties borrowed from class Tool:
diagram, isActive, isEnabled, name, transactionResult

Method Summary Details

Name, Return Type Description
canStart()
{boolean}

This tool may run when there is a mouse-down event on a resize handle, the diagram is not read-only and it allows resizing, the left mouse button is being used, and this tool's adornment's resize handle is at the current mouse point.More...

This method may be overridden.

Returns:
{boolean}
computeCellSize()
{Size}

The size should be a multiple of the value returned by this method.More...

This method may be overridden. This is called once when the tool is activated. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Returns:
{Size}
computeMaxSize()
{Size}

The effective maximum resizing size is the minimum of the maxSize and the adornedObject's GraphObject.maxSize.More...

This method may be overridden. This is called once when the tool is activated. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Returns:
{Size}
computeMinSize()
{Size}

The effective minimum resizing size is the maximum of minSize and the adornedObject's GraphObject.minSize.More...

This method may be overridden. This is called once when the tool is activated. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Returns:
{Size}
computeResize(newPoint, spot, min, max, cell, reshape)
{Rect}

Given a Spot in the original bounds of the object being resized and a new Point, compute the new Rect.More...

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Parameters:
{Point} newPoint
a Point in local coordinates.
{Spot} spot
the alignment spot of the handle being dragged.
{Size} min
the result of the call to computeMinSize.
{Size} max
the result of the call to computeMaxSize.
{Size} cell
the result of the call to computeCellSize.
{boolean} reshape
true if the new size may change the aspect ratio from that of the natural bounds of the adornedObject.
Returns:
{Rect}
doActivate()

Capture the mouse, remember the object's original bounds, and start a transaction.

doCancel()

Restore the original GraphObject's size.

doDeactivate()

Stop the current transaction and release the mouse.

doMouseMove()

Call resize with a new size determined by the current mouse point.More... This determines the new bounds by calling computeResize.

When this calls computeResize it sets the reshape argument to false if the shift key is pressed, or if the resize object is a Shape with a Shape.geometryStretch of GraphObject.Uniform or GraphObject.UniformToFill.

doMouseUp()

Call resize with the final bounds based on the most recent mouse point, commit the transaction, and raise the "PartResized" DiagramEvent.More... This determines the new bounds by calling computeResize.

When this calls computeResize it sets the reshape argument to false if the shift key is pressed, or if the resize object is a Shape with a Shape.geometryStretch of GraphObject.Uniform or GraphObject.UniformToFill.

resize(newr)

Change the size of the selected part's Part.resizeObject to have the given bounds.More... This modifies its GraphObject.desiredSize and maybe its Part.location.

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Parameters:
{Rect} newr
a Rectangle in the adornedObject's local coordinates, not in document coordinates
updateAdornments(part)

Show an Adornment with the resize handles at points along the edge of the bounds of the selected Part's Part.resizeObject.More...

First this finds the object in the visual tree of the Part that should get the resize adornment and that the user will be able to resize interactively. It finds the object that has the Part.resizeObjectName property of the Part. If the Part.resizeObjectName property is an empty string, as it is by default, it uses the whole part.

It then builds the adornment, associating it with the chosen resize object. The adornment gets eight handles, four at the corners and four at the middle of each side.

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Parameters:
{Part} part
Methods borrowed from class Tool:
cancelWaitAfter, canStartMultiTouch, doKeyDown, doKeyUp, doMouseDown, doMouseWheel, doStart, doStop, doWaitAfter, findToolHandleAt, isBeyondDragSize, standardMouseClick, standardMouseOver, standardMouseSelect, standardMouseWheel, standardPinchZoomMove, standardPinchZoomStart, standardWaitAfter, startTransaction, stopTool, stopTransaction