Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DragCreatingTool Extension

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. Extensions can be found in the GoJS kit under the extensions (for loading via script tags),extensionsTS (UMD modules), or extensionsJSM (ES6 modules) folders. See the Extensions intro page for more information.

Hierarchy

  • Tool
    • DragCreatingTool

The DragCreatingTool lets the user create a new node by dragging in the background to indicate its size and position.

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

This tool will not be able to start running unless you have set the archetypeNodeData property to an object that can be copied and added to the diagram's model.

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

  diagram.currentTool = new DragCreatingTool();

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

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

However when used mode-lessly as a mouse-move tool, in 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 Adornments or tool handles, but it does temporarily add the box Part to the diagram. This tool does conduct a transaction when inserting the new node.

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

Index

Inherited Members

Constructors

  • Constructs a DragCreatingTool, sets box to a magenta rectangle, and sets name of the tool.

    Returns DragCreatingTool

Properties

  • Gets or sets a data object that will be copied and added to the diagram's model each time this tool executes.

    The default value is null. The value must be non-null for this tool to be able to run. Setting this property does not raise any events.

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

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

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

  • 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. A value of zero will allow this tool to run without any wait after the mouse down. Setting this property does not raise any events.

Methods

  • 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(): Rect
  • This just returns a Rect stretching from the mouse-down point to the current mouse point.

    Returns Rect

    a Rect in document coordinates.

  • doActivate(): void
  • Capture the mouse and show the box.

    Returns void

  • doDeactivate(): void
  • Release the mouse and remove any box.

    Returns void

  • doMouseMove(): void
  • doMouseUp(): void
  • Create a node by adding a copy of the archetypeNodeData object to the diagram's model, assign its GraphObject.position and GraphObject.desiredSize according to the given bounds, and select the new part.

    The actual part that is added to the diagram may be a Part, a Node, or even a Group, depending on the properties of the archetypeNodeData and the type of the template that is copied to create the part.

    Parameters

    • bounds: Rect

      a Point in document coordinates.

    Returns Part

    the newly created Part, or null if it failed.