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.
Optionalinit: Partial<DrawCommandHandler>Gets or sets a data object that is copied by groupSelection when creating a new Group.
The default value is null. If you set this to an Object, be sure that GraphLinksModel.isGroupForNodeData is true for that object. Setting this property does not raise any events.
Gets or sets the arrow key behavior. Possible values are "move", "select", "scroll", "tree", "none", and "default".
The default value is "move". Set this property to "default" in order to make use of the additional commands in this class without affecting the arrow key behaviors.
Note that this functionality is different from the focus navigation behavior of the CommandHandler that was added in version 3.1 and enabled by the CommandHandler.isFocusEnabled property. In this DrawCommandHandler the arrow keys for the "move", "select" or "tree" behaviors depend on and modify the Diagram.selection. The built-in focus navigation is completely independent of the selection mechanism.
Gets or sets whether copySelection should also copy Links that connect with selected Nodes. The default value is true. Setting this property does not raise any events.
The DraggingTool.copiesEffectiveCollection property serves a similar role for the DraggingTool when the user holds down the control key to modify the drag into a copy operation.
Gets or sets whether copySelection and copyToClipboard copy the node data property whose value is the containing group data's key.
Set this property to true if you want a copy/paste of a node to automatically have the new node be a member of the original group. Caution: this only has an effect if the Diagram's Diagram.model is a GraphLinksModel.
The default value is false.
Gets or sets whether copySelection and copyToClipboard copy the node data property whose value is the tree-parent node data's key.
Set this property to true if you want a copy/paste of a node to automatically have the new node be a tree-child of the original tree-parent node. Caution: this only has an effect if the Diagram's Diagram.model is a TreeModel.
The default value is false.
Gets or sets whether copySelection should also copy subtrees. The default value is false. Setting this property does not raise any events.
The DraggingTool.dragsTree property serves a similar role for the DraggingTool for both moving and copying operations.
Gets or sets whether deleteSelection should also delete links that are connected to nodes that are deleted. The default value is true. Setting this property does not raise any events.
Gets or sets whether deleteSelection should also delete subtrees. The default value is false. Setting this property does not raise any events.
ReadonlydiagramThis read-only property returns the Diagram that is using this CommandHandler, after Diagram.commandHandler has been set to this object.
Gets or sets the GraphObject that has focus for this CommandHandler; the value may be null. Changing the focus automatically cancels any running Tool and sets isVirtualPointerDown to false. Whichever GraphObject has focus automatically gets the focusBox Adornment.
The initial value is null. This can only be set, and thus focus navigation mode can only be started, when isFocusEnabled is true. Any new focus GraphObject must be in the same Diagram as this CommandHandler.
This property is different than the Diagram.focus method, which requests DOM keyboard event focus.
since3.1
Gets or sets the Adornment used to show the current GraphObject that has focus.
This defaults to two Shapes surrounding the focus object: a lime (or darkcyan if Part.isSelected) border and a dotted magenta border. Here is how the default focusBox is defined:
// in the "Tool" Layer so that it's in front of all regular Adornments
new Adornment('Auto', { layerName: 'Tool', pickable: false, selectable: false })
.add(
new Panel('Spot')
.add(
new Shape({
name: 'SHAPE', fill: null, stroke: 'lime', strokeWidth: 4
})
.bindObject('stroke', 'adornedPart', part => part.isSelected ? 'darkcyan' : 'lime'),
new Shape({
name: 'SHAPE2', stretch: Stretch.Fill, fill: null,
stroke: 'magenta', strokeWidth: 4, strokeDashArray: [4, 4]
})
),
new Placeholder({ padding: 4 })
);
This definition may change in any version.
since3.1
Gets or sets a function to be called as the focus changes to a different GraphObject or to null. The default value for this property is null -- no function is called when the focus has changed.
When this is null, the CommandHandler uses its own live element to update screen readers.
since3.1
Gets or sets whether the arrow/Enter/Escape/Space/ContextMenu keys are used for doing focus navigation.
The default value is false. This must be set to true in order for the user to be able to use keyboard navigation. When set to false, the focus is also set to null.
since3.1
Gets or sets whether the virtual pointer has the primary mouse button held down or not.
Note that this state is maintained even when the virtualPointerBox is not visible because
the user has let go of the Shift key.
The initial value is false -- as if the mouse button is not being held down. This can only be set when isVirtualPointerEnabled is true.
since3.1
Gets or sets whether the Shift key shows a virtual pointer (virtualPointerBox)
causing the arrow keys and Enter to produce simulated mouse InputEvents.
The default value is false. This must be set to true in order for the user to be able to use the virtual pointer.
since3.1
Gets or sets whether the zoomToFit command ever restores the previous Diagram scale and position. When this property is false, this command always calls Diagram.zoomToFit.
The default value is false. Setting this property does not raise any events.
since2.2
Gets or sets the id of the HTML element, typically an <output> element, used to hold the description of the current focus
and possibly other state information.
The default value is the empty string. Note that the element must be in the same DOM as the diagram. Element id reference scope
If you do not provide your own HTML element by id nor your own your own focusChanged event handler,
this will create and use one automatically.
However we suggest that you implement your own live element so that you can control its appearance and behavior.
since3.1
see
Gets or sets a function that is used to set Diagram.model. It can do more things before and/or after the actual setting of Diagram.model.
The default value is null. Setting this property does not raise any events.
If non-null, the function is called by loadLocalFile.
Gets or sets an HTMLElement so that the user can load a file saved by saveLocalFile by drag-and-dropping it on this element.
By default the value is null -- there is no such element. Setting this property does not raise any events or modify the DOM, but does add or remove listeners, including a "drop" listener that actually calls loadLocalFile and Diagram.focus.
If you want to support drag-and-drop loading of files, you will need to add the element to your page and set this property.
since3.1
Gets or sets an HTMLInputElement so that the user can load a file saved by saveLocalFile by using the browser's file picker user interface.
By default the value is null -- there is no such input element. Setting this property does not raise any events or modify the DOM, but does add or remove a "change" listener that actually calls loadLocalFile and Diagram.focus.
If you want to support the user's picking of a file to load,
you will need to add an <input type="file"> element to your page and set this property.
It is moderately common to have this input element be hidden and invoke the input file picker by programmatically
calling click() on the element.
since3.1
Gets or sets the default file type for locally saved files. The default value is "gojs". Setting this property does not raise any events.
since3.1
Gets or sets the predicate that determines whether or not a node may become a member of a group. This predicate is called in addition to any existing group's Group.memberValidation predicate. The default predicate is null, which is equivalent to simply returning true. The predicate may be called passing null as the first argument (the Group) -- this asks whether it is OK to make the second argument (the Part, but not a Link) a top-level Part of the diagram.
For a more general discussion of validation, see Learn page on Validation.
The function, if supplied, must not have any side-effects.
Gets or sets the offset at which each repeated pasteSelection puts the new copied parts from the clipboard.
Gets or sets where the clipboard is stored.
The value must be one of: "memory", "sessionStorage", "localStorage", or "systemClipboard".
If this value is not "memory", the value of window[this.storageLocation]
is expected to implement the Storage interface.
The default value is "memory".
since3.1
Gets or sets the 'Tool' layer Part used to indicate the current location of the virtual pointer. Its Part.location will be positioned exactly where the InputEvents happen.
The default box has some magenta lines looking like a target. In addition there is a thick dark-cyan circle that is shown when isVirtualPointerDown is true. Also, there is a visual indication of which mouse button is held down for future simulated mouse events, there is a visual indication of which keyboard modifiers those future simulated mouse events will have, and a visual indication of whether a future simulated mouse-up event is one-time double-click event.
Here is how the default virtual pointer box is defined:
new Part({
layerName: 'Tool', isInDocumentBounds: false, // avoid modifying documentBounds
locationObjectName: 'CIRCLE', locationSpot: Spot.Center,
pickable: false, selectable: false
})
.add(
new Shape('Circle', {
isGeometryPositioned: true, width: 30, height: 30,
fill: null, stroke: 'darkcyan', strokeWidth: 6, visible: false
})
.bind('visible', 'down'),
new Shape({ isGeometryPositioned: true, geometryString: 'M15 0L15 30', stroke: 'magenta' }),
new Shape({ isGeometryPositioned: true, geometryString: 'M0 15L30 15', stroke: 'magenta' }),
new Shape('Circle', { name: 'CIRCLE',
isGeometryPositioned: true, width: 20, height: 20,
fill: null, stroke: 'magenta', position: new Point(5, 5)
}),
new Shape({
isGeometryPositioned: true, geometry: CommandHandler._LeftButtonGeo,
fill: null, stroke: 'cyan', strokeWidth: 4
})
.bind('geometry', 'button', CommandHandler._showButton),
new TextBlock({ position: new Point(12, 0), font: 'bold 10pt sans-serif' })
.bind('text', 'clickCount', c => c > 1 ? c.toString() : ''),
new TextBlock({ position: new Point(0, 16) })
.bind('text', 'modifiers', CommandHandler._showModifiers)
)
This definition may change in any version.
since3.1
Gets or sets a function that is called when the virtualPointerBox is replaced or modified.
Note that some of the state of the virtual pointer is stored in the Panel.data of the box Part.
since3.1
Gets or sets the location of the virtual pointer, the virtualPointerBox Part.
Changing this property results in InputEvents and calls to doMouseMove.
The initial value is (NaN, NaN).
since3.1
Gets or sets the amount by which decreaseZoom and increaseZoom change the Diagram.scale.
The default value is 1.05 (5%). The value must be a number larger than 1.0. Setting this property does not raise any events.
VirtualaddMake sure all of the unnested Parts in the given collection are removed from any containing Groups.
This sets Part.containingGroup to null on each Part that is not a member of another Part in the argument collection. If the check argument to this method is supplied and true, this will call isValidMember on each part, passing null as the first argument.
This functionality is similar to ungroupSelection, except that this is not a command (there is no transaction and this does not raise a DiagramEvent) and the parts are necessarily becoming top-level parts (whereas ungrouping would add them to the Group containing the Group being ungrouped).
This function is typically called in a Diagram.mouseDrop event handler in order to remove the selected Parts from whatever Group they had been in.
If you want to add Parts to be members of a Group, call Group.addMembers. If you want to remove Parts completely from a Diagram, call Diagram.removeParts.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
a collection of Parts.
Optionalcheck: booleanwhether to call isValidMember to confirm that changing the Part to be a top-level Part is valid.
true if all non-Links were changed to be top-level Parts in this Diagram; false if some Parts or Nodes were not able to be added.
Aligns selected parts at the bottom-most edge of the bottom-most part.
Aligns selected parts at the x-value of the center point of the first selected part.
Aligns selected parts at the y-value of the center point of the first selected part.
Aligns selected parts top-to-bottom in order of the order selected. Distance between parts can be specified. Default distance is 0.
Aligns selected parts along the left-most edge of the left-most part.
Aligns selected parts at the right-most edge of the right-most part.
Aligns selected parts left-to-right in order of the order selected. Distance between parts can be specified. Default distance is 0.
Aligns selected parts at the top-most edge of the top-most part.
This controls whether or not the user can invoke the alignLeft, alignRight, alignTop, alignBottom, alignCenterX, alignCenterY commands.
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.
VirtualcanThis predicate controls whether the user can collapse expanded Groups.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalgroup: Group | nullif supplied, ignore the selection and consider collapsing this particular Group.
VirtualcanThis predicate controls whether the user can collapse expanded subtrees of Nodes.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalnode: Node | nullif supplied, ignore the selection and consider collapsing this particular Node.
see
VirtualcanThis predicate controls whether or not the user can invoke the copySelection command.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
This returns true: if Diagram.allowCopy is true, if Diagram.allowClipboard is true, and if there are some selected Parts.
VirtualcanThis predicate controls whether or not the user can invoke the cutSelection command.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
This returns true: if the diagram is not Diagram.isReadOnly, if Diagram.allowCopy is true, if Diagram.allowDelete is true, if Diagram.allowClipboard is true, and if there are some selected Parts.
see
VirtualcanThis predicate controls whether or not the user can invoke the decreaseZoom command.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalfactor: numberThis defaults to 1/zoomFactor. The value should be less than one and greater than zero.
This returns true if Diagram.allowZoom is true and if the new scale is within the range of Diagram.minScale and Diagram.maxScale.
see
VirtualcanThis predicate controls whether or not the user can invoke the deleteSelection command.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
This returns true: if the diagram is not Diagram.isReadOnly, if Diagram.allowDelete is true, and if there are some selected Parts.
VirtualcanThis predicate controls whether or not the user can invoke the downloadSvg command.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionaloptions: SvgRendererOptions & { name?: string }an optional Object that satisfies the SvgRendererOptions interface and may also have an optional "name" property for the name of the downloaded file
true, by default
see
since3.1
VirtualcanThis predicate controls whether or not the user can invoke the editTextBlock command.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
This returns true: if the diagram is not Diagram.isReadOnly, if Diagram.allowTextEdit is true, if there is a ToolManager.textEditingTool, and if there is any selected Part for which Part.canEdit is true.
VirtualcanThis predicate controls whether the user can expand collapsed Groups.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalgroup: Group | nullif supplied, ignore the selection and consider expanding this particular Group.
VirtualcanThis predicate controls whether the user can expand collapsed subtrees of Nodes.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalnode: Node | nullif supplied, ignore the selection and consider expanding this particular Node.
see
VirtualcanThis predicate controls whether or not the user can invoke the groupSelection command.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
This returns true: if the archetypeGroupData is not null, if the diagram is not Diagram.isReadOnly, if Diagram.allowInsert is true, if Diagram.allowGroup is true, if Diagram.model is a GraphLinksModel, and if there is any selected Part that can be Part.canGrouped.
VirtualcanThis predicate controls whether or not the user can invoke the increaseZoom command.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalfactor: numberThis defaults to zoomFactor. The value should be greater than one.
This returns true if Diagram.allowZoom is true and if the new scale is within the range of Diagram.minScale and Diagram.maxScale.
see
VirtualcanThis predicate controls whether or not the user can invoke the pasteSelection command.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalpos: PointPoint at which to center the newly pasted parts; if not present the parts would not be moved.
This returns true: if the diagram is not Diagram.isReadOnly, if Diagram.allowInsert is true, if Diagram.allowClipboard is true, and if the clipboard has parts in it.
VirtualcanThis predicate controls whether or not the user can invoke the redo command.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
This returns true: if the diagram is not Diagram.isReadOnly, if Diagram.allowUndo is true, and if the UndoManager.canRedo predicate returns true.
see
VirtualcanThis predicate controls whether or not the user can invoke the resetZoom command.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalnewscale: numberThis defaults to Diagram.defaultScale, which is normally 1.0. The value should be greater than zero.
This returns true if Diagram.allowZoom is true. and if the new scale is within the range of Diagram.minScale and Diagram.maxScale.
see
This controls whether or not the user can invoke the rotate command.
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.
This predicate controls whether or not the user can invoke the saveLocalFile command.
true, by default
since3.1
VirtualcanThis predicate controls whether or not the user can invoke the scrollToPart command. This returns false if there is no argument Part and there are no selected Parts.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalpart: Part | nullThis defaults to the first selected Part of Diagram.selection
This returns true if Diagram.allowHorizontalScroll and Diagram.allowVerticalScroll are true.
see
VirtualcanThis predicate controls whether or not the user can invoke the selectAll command.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
This returns true if Diagram.allowSelect is true.
see
VirtualcanThis predicate controls whether or not the user can invoke the showContextMenu command.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalobj: GraphObject | Diagram | nulla GraphObject or Diagram with a contextMenu defined. If none is given, this method will use the first selected object, or else the Diagram.
VirtualcanThis predicate controls whether the user may stop the current tool. This just returns true.
This method may be overridden, but probably should not be overridden. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
true.
see
VirtualcanThis predicate controls whether or not the user can invoke the undo command.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
This returns true: if the diagram is not Diagram.isReadOnly, if Diagram.allowUndo is true, and if the UndoManager.canUndo predicate returns true.
see
VirtualcanThis predicate controls whether or not the user can invoke the ungroupSelection command.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalgroup: Group | nullif supplied, ignore the selection and consider ungrouping this particular Group.
This returns true: if the diagram is not Diagram.isReadOnly, if Diagram.allowDelete is true, if Diagram.allowUngroup is true, if Diagram.model is a GraphLinksModel, and if there are any selected Groups that are Group.ungroupable.
VirtualcanThis predicate controls whether or not the user can invoke the zoomToFit command.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalrect: Rectan optional Rect in document bounds that is the intended new viewport bounds.
This returns true if Diagram.allowZoom is true.
see
VirtualcollapseThis command collapses all expanded selected Groups. This operation is performed within a "Collapse SubGraph" transaction. Just before the end of the transaction this raises the "SubGraphCollapsed" DiagramEvent, with a collection of collapsed Groups as the subject. This currently has no default keyboard shortcut.
This calls Group.collapseSubGraph to perform the collapse, which will set Group.isSubGraphExpanded to false. You may want to save the collapsed/expanded state to the model by using a TwoWay Binding on the "isSubGraphExpanded" property of your Groups, and perhaps also on the Group.wasSubGraphExpanded property.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalgroup: Group | nullif supplied, ignore the selection and collapse this particular Group.
VirtualcollapseThis command collapses all expanded selected Nodes. This operation is performed within a "Collapse Tree" transaction. Just before the end of the transaction this raises the "TreeCollapsed" DiagramEvent, with a collection of collapsed Nodes as the subject. This currently has no default keyboard shortcut.
This calls Node.collapseTree to perform the collapse, which will set Node.isTreeExpanded to false. You may want to save the collapsed/expanded state to the model by using a TwoWay Binding on the "isTreeExpanded" property of your Nodes, and perhaps also on the Node.wasTreeExpanded property.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalnode: Node | nullif supplied, ignore the selection and collapse this particular Node subtree.
VirtualcomputeFind the actual collection of nodes and links to be moved or copied, given an initial collection. This includes links that connected at both ends to nodes being moved or copied, members of Groups, and if DraggingTool.dragsTree is true, this includes nodes and links that are "tree" descendants from selected nodes.
Note that this does not return a simple collection of Parts, but a go.Map associating a chosen Part with an Object holding its original location Points as the value of the "point" property.
This method may be overridden. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionaloptions: DraggingOptionsPotential options for the collection computation. If not specified, this uses the DraggingTool's drag options.
a Map mapping Parts to DraggingInfo Objects that have a "point" property remembering the original location of that Part.
since2.0
VirtualcopyThis command copies the currently selected parts, Diagram.selection, from the Diagram into the clipboard.
This is normally invoked by the Ctrl-C keyboard shortcut.
This makes a copy of the current selection by calling copyToClipboard. This also raises the "ClipboardChanged" diagram event.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
OverridecopyVirtualcutThis command executes a copySelection followed by a deleteSelection.
This is normally invoked by the Ctrl-X keyboard shortcut.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
VirtualdecreaseThis command decreases the Diagram.scale by a given factor.
This is normally invoked by the Ctrl-- and Numpad-- keyboard shortcuts.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalfactor: numberThis defaults to 1/zoomFactor. The value should be less than one and greater than zero.
VirtualdeleteThis command deletes the currently selected parts from the diagram.
This is normally invoked by the Del keyboard shortcut.
This will first start a "Delete" transaction, then raise the "SelectionDeleting" DiagramEvent, call Diagram.removeParts on a perhaps extended collection of selected Parts, raise the "SelectionDeleted" diagram event, and finally commit the transaction.
Because this command changes the selection, this method also raises the "ChangingSelection" and "ChangedSelection" diagram events. Changes are performed within a transaction, but the selection events are raised outside the transaction.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
VirtualdescribeThis produces the default description string for a GraphObject that is the new focus.
This will need to be replaced or overridden for internationalization purposes if you have not specified an event handler for focusChanged. Internally this is only called when focusChanged is null.
the previous value for focus, might be null or the same value oas NEWOBJ
the new value for focus, might be null or the same value as OLDOBJ
a generic string describing the NEWOBJ, to be read by a screen reader
since3.1
OverridedoThis 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. Set that property to "default" in order to make use of the additional commands in this class without affecting the arrow key behaviors.
Note that this functionality is different from the focus navigation behavior of the CommandHandler that was added in version 3.1 and enabled by the CommandHandler.isFocusEnabled property. In this DrawCommandHandler the arrow keys for the "move", "select" or "tree" behaviors depend on and modify the Diagram.selection. The built-in focus navigation is completely independent of the selection mechanism.
VirtualdoThis is called by tools to handle keyboard commands.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
VirtualdownloadThis command downloads an SVG file that holds a rendering of this diagram.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionaloptions: SvgRendererOptions & { name?: string }an optional Object that satisfies the SvgRendererOptions interface and may also have an optional "name" property for the name of the downloaded file; if "name" is not supplied, the downloaded file name will be the Model.name if it is not an empty string, with an "svg" file type.
since3.1
VirtualeditThis command starts in-place editing of a TextBlock in the selected Part.
This is normally invoked by the F2 keyboard shortcut.
This starts the TextEditingTool to have the user enter or modify the text string and finally set the TextBlock.text. You may want to save the new string to the model by using a TwoWay Binding on the "text" property of your TextBlock.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
VirtualexpandThis command expands all collapsed selected Groups. This operation is performed within an "Expand SubGraph" transaction. Just before the end of the transaction this raises the "SubGraphExpanded" DiagramEvent, with a collection of expanded Groups as the subject. This currently has no default keyboard shortcut.
This calls Group.expandSubGraph to perform the collapse, which will set Group.isSubGraphExpanded to true. You may want to save the collapsed/expanded state to the model by using a TwoWay Binding on the "isSubGraphExpanded" property of your Groups, and perhaps also on the Group.wasSubGraphExpanded property.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalgroup: Group | nullif supplied, ignore the selection and expand this particular Group.
VirtualexpandThis command expands all collapsed selected Nodes. This operation is performed within an "Expand Tree" transaction. Just before the end of the transaction this raises the "TreeExpanded" DiagramEvent, with a collection of expanded Nodes as the subject. This currently has no default keyboard shortcut.
This calls Node.expandTree to perform the expand, which will set Node.isTreeExpanded to true. You may want to save the collapsed/expanded state to the model by using a TwoWay Binding on the "isTreeExpanded" property of your Nodes, and perhaps also on the Node.wasTreeExpanded property.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalnode: Node | nullif supplied, ignore the selection and collapse this particular Node subtree.
VirtualgroupThis command adds a copy of archetypeGroupData to the diagram's model
to create a new Group and then adds the selected Parts to that new group.
This is normally invoked by the Ctrl-G keyboard shortcut.
This creates a new Group by adding a copy of the archetypeGroupData to the model. Each of the selected parts for which Part.canGroup is true and for which isValidMember is true is made a member of that new group. If all of the selected groupable parts were members of a pre-existing group, the new group also becomes a member of that pre-existing group, if isValidMember is true for that existing group with the new group. The new group becomes the only selected part. This raises the "SelectionGrouped" diagram event. This method also raises the "ChangingSelection" and "ChangedSelection" diagram events. Changes are performed in a "Group" transaction, but the selection events are raised outside the transaction.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
VirtualincreaseThis command increases the Diagram.scale by a given factor.
This is normally invoked by the Ctrl-+ and Numpad-+ keyboard shortcuts.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalfactor: numberThis defaults to zoomFactor. The value should be greater than one.
VirtualisThis predicate is called to determine whether a Node may be added as a member of a Group. This always checks to make sure no group might become a member of itself, either directly or indirectly. If the Group has a Group.memberValidation predicate and if it returns false, this method returns false. If this CommandHandler has a memberValidation predicate and if it returns false, this method returns false. Otherwise this will return true.
For a more general discussion of validation, see Learn page on Validation.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
true if OK to add the node to the group.
This method loads a text file that the user chooses or drops that holds this diagram's model as JSON-formatted text, normally saved via saveLocalFile.
This calls Model.fromJson. This is called by the "change" event of the localFileInput element (if present) or the "drop" event of the localFileDropElement (if present).
The file type of the File.name must match the localFileType, or it must not have a file type.
a File instance from which to read the JSON-formatted text
Optionalloader: ((diagram: Diagram, model: Model, name: string) => void) | nullan optional function that sets Diagram.model, perhaps modifying the model first, and perhaps doing other updates after assigning the given Model to the given Diagram.
since3.1
OverridepasteVirtualpasteThis command copies the contents of the clipboard into this diagram and makes those new parts the new selection.
This is normally invoked by the Ctrl-V keyboard shortcut.
This calls pasteFromClipboard to add copies of Parts into this diagram, and then selects all of the newly created parts. This also raises the "ClipboardPasted" diagram event. This method raises the "ChangingSelection" and "ChangedSelection" diagram events. Changes are performed in a transaction, but the selection events are raised outside the transaction.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalpos: PointPoint at which to center the newly pasted parts; if not present the parts are not moved.
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.
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.
VirtualredoThis command calls UndoManager.redo.
This is normally invoked by the Ctrl-Y keyboard shortcut.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
see
VirtualresetThis command sets the Diagram.scale to a new scale value, by default 1.
This is normally invoked by the Ctrl-0 keyboard shortcut.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalnewscale: numberThis defaults to Diagram.defaultScale, which is normally 1.0. The value should be greater than zero.
see
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.
the positive (clockwise) or negative (counter-clockwise) change in the rotation angle of each Part, in degrees.
This command downloads a text file that holds this diagram's model as JSON-formatted text.
This calls Model.toJson.
Optionaloptions: { mimetype?: string; name?: string }an optional file name (defaults to Model.name.localFileType) and an optional MIME type (defaults to "application/text")
since3.1
VirtualscrollThis command scrolls the diagram to make a highlighted or selected Part visible in the viewport. Call this command repeatedly to cycle through the Diagram.highlighteds collection, if there are any Parts in that collection, or else in the Diagram.selection collection, scrolling to each one in turn by calling Diagram.centerRect.
This method animates to the scrolled part, and Diagram.scrollToRect does not. If the part is hidden because it is a member of a collapsed subgraph/group, or because it is a child of a collapsed subtree node, those groups or nodes will be expanded first.
This is normally invoked by the Space keyboard shortcut.
If there is no argument and there is no highlighted or selected Part, this command does nothing.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalpart: Part | nullThis defaults to the first highlighted Part of Diagram.highlighteds, or, if there are no highlighted Parts, the first selected Part.
VirtualselectThis command selects all of the selectable Parts in the diagram by setting Part.isSelected to true on each one.
This is normally invoked by the Ctrl-A keyboard shortcut.
This method raises the "ChangingSelection" and "ChangedSelection" diagram events. This ignores all parts in temporary layers.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
see
VirtualshowThis command opens the context menu for a selected Part or given GraphObject, or else for the whole Diagram.
This is normally invoked by the Menu keyboard shortcut.
The given GraphObject must have a GraphObject.contextMenu defined in order to show anything.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalobj: GraphObject | Diagram | nulla GraphObject or Diagram with a contextMenu defined. If none is given, this method will use the first selected object, or else the Diagram. The method will simulate a right-button click at the middle of the GraphObject or, if a Diagram, at the current mouse position if it is in the viewport.
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.
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.
VirtualstopThis command hides any visible tooltip, clears the selection, and cancels the operation of the current tool.
This is typically called when the user presses Escape.
If the current tool is a ToolManager and a tooltip is visible, this hides the tooltip and returns. If the current tool is a ToolManager and no tooltip is visible, this clears the diagram's selection, and then calls Tool.doCancel on the current tool.
VirtualundoThis command calls UndoManager.undo.
This is normally invoked by the Ctrl-Z keyboard shortcut.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
see
VirtualungroupThis command removes selected groups from the diagram without removing their members from the diagram.
This is normally invoked by the Ctrl-Shift-G keyboard shortcut.
For the given group, or if not supplied, each selected Group that is Group.ungroupable, expand the subgraph and change all of its member parts to be members of the group that the selected group node is in. (If the selected group is a top-level node, i.e. not a member of any group node, its members become top-level parts too.) All of those selected groups are deleted. All of the reparented member parts are selected.
This raises the "SelectionUngrouped" diagram event. This method also raises the "ChangingSelection" and "ChangedSelection" diagram events. Changes are performed in an "Ungroup" transaction, but the selection events are raised outside the transaction.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalgroup: Group | nullif supplied, ignore the selection and consider ungrouping this particular Group.
VirtualzoomThis command changes the Diagram.scale so that the Diagram.documentBounds fits within the viewport.
If isZoomToFitRestoreEnabled is true and this command had been called before without any other zooming since then,
the original Diagram scale and position are restored.
This is normally invoked by the Shift-Z keyboard shortcut.
If you provide a Rect argument, it will change the Diagram scale and position to match, calling Diagram.zoomToRect. Otherwise it calls Diagram.zoomToFit in order to fit the document bounds in the viewport.
This animates zooming, unless animation has been disabled. Diagram.zoomToFit and Diagram.zoomToRect do not animate.
This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Learn page on Extensions for how to override methods and how to call this base method.
Optionalrect: Recta Rect in document bounds that is the intended new viewport bounds. If this is provided, the command will call Diagram.zoomToRect, otherwise it will call Diagram.zoomToFit.
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:
or:
If you want to experiment with this extension, try the Drawing Commands sample.
New in version 3.1 this adds a command to save the model as a text file in the user's local file system, typically in their Downloads folder, saveLocalFile. And it adds a method for loading a File: loadLocalFile.
There are two optional properties that can be used for calling loadLocalFile: localFileInput and localFileDropElement. The former may be a file type HTMLInputElement that you have on your page; the latter may be an HTMLElement, or even the whole document.body, where the user may drag-and-drop a saved file.
The default file type for files is controlled by localFileType.