# Class Diagram

GoJS® Diagramming Components
version 3.0.14
by Northwoods Software®

#### Hierarchy

- Diagram
  - Palette
  - Overview

A Diagram is associated with an HTML DIV element. Constructing a Diagram creates an HTML Canvas element which it places inside of the given DIV element, in addition to several helper DIVs. GoJS will manage the contents of this DIV -- you should not modify the contents of the DIV, although you may style the given DIV (background, border, etc) and position and size it as needed.

Minimal Diagram construction looks like this. HTML:

    <div id="myDiagramDiv" style="border: solid 1px black; width:400px; height:400px"></div>

JavaScript:

    const myDiagram =
      new go.Diagram("myDiagramDiv",  // create a Diagram for the Div HTML element
        { // with various property and subproperty settings...
          "undoManager.isEnabled": true  // enable undo & redo
        });

The diagram will draw onto an HTML Canvas element, created inside the Diagram DIV.

Each Diagram holds a set of Layers each of which holds some number of Parts such as Nodes and Links. Each Part consists of GraphObjects such as TextBlocks and Shapes and Panels holding yet more GraphObjects.

A Diagram and its Parts provide the visual representation of a Model that holds JavaScript data objects for the nodes and the links. The model provides the way to recognize the relationships between the data.

Two Diagrams can display and manipulate the same Model. (Example)

A diagram will automatically create Nodes and Links corresponding to the model data. The diagram has a number of named templates it uses to create the actual parts: nodeTemplateMap, groupTemplateMap, and linkTemplateMap. Each template may have some data Bindings that set the part's GraphObjects' properties based on the value of properties of the data.

A simple Node template and Model data (both nodes and links) may look like this:

    // define a simple Node template
    myDiagram.nodeTemplate =
      new go.Node("Auto").add(  // the Shape will go around the TextBlock
        new go.Shape("RoundedRectangle")
          // Shape.fill is bound to Node.data.color
          .bind("fill", "color"),
        new go.TextBlock({ margin: 3 })  // some room around the text
          // TextBlock.text is bound to Node.data.key
          .bind("text", "key")
      );

    // create the model data that will be represented by Nodes and Links
    myDiagram.model = new go.GraphLinksModel(
    [
      { key: "Alpha", color: "lightblue" },
      { key: "Beta", color: "orange" },
      { key: "Gamma", color: "lightgreen" },
      { key: "Delta", color: "pink" }
    ],
    [
      { from: "Alpha", to: "Beta" },
      { from: "Alpha", to: "Gamma" },
      { from: "Beta", to: "Beta" },
      { from: "Gamma", to: "Delta" },
      { from: "Delta", to: "Alpha" }
    ]);

The above code is used to make the Minimal sample, a simple example of creating a Diagram and setting its model.

Read about models on the Using Models page in the introduction. A diagram is responsible for scrolling (position) and zooming (scale) all of the parts that it shows. Each Part occupies some area given by its GraphObject.actualBounds.

The union of all of the parts' bounds constitutes the documentBounds. The document bounds determines the area that the diagram can be scrolled to. There are several properties that you can set, such as initialContentAlignment, that control the initial size and position of the diagram contents.

At any later time you can also explicitly set the position and/or scale to get the appearance that you want. But you may find it easier to call methods to get the desired effect. For example, if you want to make a particular Node be centered in the viewport, call either centerRect or scrollToRect with the Node's GraphObject.actualBounds, depending on whether or not you want the view to be scrolled if the node is already in view.

Read in the Introduction about Viewports and the Initial Viewport. You can have the diagram perform automatic layouts of its nodes and links by setting layout to an instance of the Layout subclass of your choice. The default layout is an instance of the Layout base class that ignores links and only positions Nodes that do not have a location. This default layout will allow you to programmatically position nodes (including by loading from a database) and will also allow the user to manually position nodes using the DraggingTool.

If you do supply a particular layout as the layout, you can control which Parts it operates on by setting Part.isLayoutPositioned. Normally, of course, it works on all top-level nodes and links. The layout is performed both after the model is first loaded as well as after any part is added or removed or changes visibility or size. You can disable the initial layout by setting Layout.isInitial to false. You can disable later automatic layouts by setting Layout.isOngoing to false.

See the Layouts page in the Introduction for a summary of layout behavior.

A diagram maintains a collection of selected parts, the Diagram.selection. To select a Part you set its Part.isSelected property to true.

There are many properties, named "allow...", that control what operations the user may perform on the parts in the diagram. These correspond to the same named properties on Layer that govern the behavior for those parts in a particular layer. Furthermore for some of these properties there are corresponding properties on Part, named "...able", that govern the behavior for that individual part. For example, the allowCopy property corresponds to Layer.allowCopy and to the property Part.copyable. The Part.canCopy predicate is false if any of these properties is false.

See the Permissions page for a more thorough discussion.

The commandHandler implements various standard commands, such as the CommandHandler.deleteSelection method and the CommandHandler.canDeleteSelection predicate.

See the Commands page for a listing of keyboard commands and the use of commands in general.

The diagram supports modular behavior for mouse events by implementing "tools". All mouse and keyboard events are represented by InputEvents and redirected to the currentTool. The default tool is an instance of ToolManager which keeps three lists of mode-less tools: ToolManager.mouseDownTools, ToolManager.mouseMoveTools, and ToolManager.mouseUpTools. The ToolManager searches these lists when a mouse event happens to find the first tool that can run. It then makes that tool the new currentTool, where it can continue to process input events. When the tool is done, it stops itself, causing the defaultTool to be the new currentTool.

Mouse-down tools include:

- ToolManager.actionTool, to support objects like "buttons"
- ToolManager.relinkingTool, to reconnect an existing link
- ToolManager.linkReshapingTool, to modify the route of an existing link
- ToolManager.rotatingTool, to change the angle of an object
- ToolManager.resizingTool, to change the size of an object

Mouse-move tools include:

- ToolManager.linkingTool, to draw a new link
- ToolManager.draggingTool, to move or copy the selection
- ToolManager.dragSelectingTool, to select parts within a rectangular area
- ToolManager.panningTool, to pan the diagram

Mouse-up tools include:

- ToolManager.contextMenuTool, to manage context menus
- ToolManager.textEditingTool, to support in-place text editing
- ToolManager.clickCreatingTool, to create new parts where the user clicks
- ToolManager.clickSelectingTool, to select parts

You can also run a tool in a modal fashion by explicitly setting currentTool. That tool will keep running until some code replaces the currentTool. This normally happens when the current tool calls Tool.stopTool, such as on a mouse-up event.

See the Tools page for a listing of predefined tools and how they operate.

A diagram raises various DiagramEvents when interesting things happen that may have affected the whole diagram. See the documentation for DiagramEvent for a complete listing.

When you need to display multiple Models, but not at the same time, you can do so by using only one Diagram and setting the model to a different one. You can also have two Diagrams share a DIV by swapping the div to `null` on one Diagram and setting it on the other. When permanently removing a Diagram,t o clear any memory used, set the div to `null` and remove all references to the Diagram. These scenarios are discussed more on the Replacing Diagrams and Models intro page.

#####
Index

### Constructors

constructor

### Accessors

allowClipboard
allowCopy
allowDelete
allowDragOut
allowDrop
allowGroup
allowHorizontalScroll
allowInsert
allowLink
allowMove
allowRelink
allowReshape
allowResize
allowRotate
allowSelect
allowTextEdit
allowUndo
allowUngroup
allowVerticalScroll
allowZoom
animationManager
autoScale
autoScrollInterval
autoScrollRegion
click
commandHandler
contentAlignment
contextClick
contextMenu
currentCursor
currentTool
defaultCursor
defaultScale
defaultTool
div
documentBounds
doubleClick
firstInput
fixedBounds
grid
groupSelectionAdornmentTemplate
groupTemplate
groupTemplateMap
handlesDragDropForTopLevelParts
hasHorizontalScrollbar
hasVerticalScrollbar
highlighteds
initialAutoScale
initialContentAlignment
initialDocumentSpot
initialPosition
initialScale
initialViewportSpot
isEnabled
isModelReadOnly
isModified
isMouseCaptured
isReadOnly
isTreePathToChildren
lastInput
layers
layout
linkSelectionAdornmentTemplate
linkTemplate
linkTemplateMap
links
maxScale
maxSelectionCount
minScale
model
mouseDragOver
mouseDrop
mouseEnter
mouseHold
mouseHover
mouseLeave
mouseOver
nodeSelectionAdornmentTemplate
nodeTemplate
nodeTemplateMap
nodes
opacity
padding
parts
position
positionComputation
renderer
routers
scale
scaleComputation
scrollHorizontalLineChange
scrollMargin
scrollMode
scrollVerticalLineChange
scrollsPageOnFocus
selection
skipsUndoManager
themeManager
toolManager
toolTip
undoManager
validCycle
viewSize
viewportBounds
zoomPoint
licenseKey
version

### Methods

add
addChangedListener
addDiagramListener
addLayer
addLayerAfter
addLayerBefore
addModelChangedListener
alignDocument
attach
centerRect
clear
clearHighlighteds
clearSelection
commit
commitTransaction
computeBounds
computeMove
computePartsBounds
copyParts
delayInitialization
ensureBounds
findLayer
findLinkForData
findLinkForKey
findLinksByExample
findNodeForData
findNodeForKey
findNodesByExample
findObjectAt
findObjectsAt
findObjectsIn
findObjectsNear
findPartAt
findPartForData
findPartForKey
findPartsAt
findPartsIn
findPartsNear
findRouter
findTopLevelGroups
findTreeRoots
focus
highlight
highlightCollection
layoutDiagram
makeImage
makeImageData
makeSvg
moveParts
rebuildParts
remove
removeChangedListener
removeDiagramListener
removeLayer
removeModelChangedListener
removeParts
requestUpdate
rollbackTransaction
scroll
scrollToRect
select
selectCollection
set
setDivBackground
setProperties
startTransaction
transformDocToView
transformViewToDoc
updateAllRelationshipsFromData
updateAllTargetBindings
updateAllThemeBindings
zoomToFit
zoomToRect
fromDiv
isUsingDOM
useDOM

### Properties

CycleAll
CycleDestinationTree
CycleNotDirected
CycleNotUndirected
CycleSourceTree
DocumentScroll
InfiniteScroll
None
Uniform
UniformToFill

## Constructors

### constructor

- new Diagram(div?: string | Element, init?: DiagramInitOptions): Diagram

- Construct an empty Diagram for a particular DIV HTML element.

  You will normally initialize properties of the Diagram that control its appearance and behavior. These properties include:

  - templates (such as nodeTemplate or linkSelectionAdornmentTemplate),
  - an automatic layout (if desired, layout),
  - positioning or scaling (such as initialContentAlignment or initialAutoScale),
  - permissions (such as isReadOnly or allowDelete), or
  - Tool or CommandHandler customization (such as CommandHandler.archetypeGroupData or Tool.isEnabled): `diagram.toolManager.dragSelectingTool.isEnabled = false;`.

  Then you will need to construct a Model (usually a GraphLinksModel) for the Diagram, initialize its data by setting its Model.nodeDataArray and other properties, and then set the diagram's model.

  Finally, if you want to disassociate the Diagram from the HTML Div element, set Diagram.div to null. If you remove a part of the HTML DOM containing a Div with a Diagram, you will need to set div to null in order for the page to recover the memory.

  Unlike GraphObject, the Diagram constructor passes its init options to GraphObject.make. This allows you to quickly set sub-properties when initializing a Diagram, such as setting properties on the Diagram's undoManager or commandHandler. For example:

      const myDiagram = new go.Diagram("myDiagramDiv",
          {
            allowZoom: false,
            "animationManager.isEnabled": false,  // turn off automatic animations
            "grid.visible": true,  // display a background grid for the whole diagram
            "grid.gridCellSize": new go.Size(20, 20),
            // allow double-click in background to create a new node
            "clickCreatingTool.archetypeNodeData": { text: "Node" },
            // allow Ctrl-G to call the groupSelection command
            "commandHandler.archetypeGroupData":
              { text: "Group", isGroup: true, color: "blue" },
            "commandHandler.copiesTree": true,  // for the copy command
            "commandHandler.deletesTree": true, // for the delete command
            "toolManager.hoverDelay": 100,  // how quickly tooltips are shown
            // mouse wheel zooms instead of scrolls
            "toolManager.mouseWheelBehavior": go.WheelMode.Zoom,
            "draggingTool.dragsTree": true,  // dragging for both move and copy
            "draggingTool.isGridSnapEnabled": true,
            layout: new go.TreeLayout(
                { angle: 90, sorting: go.TreeLayout.SortingAscending }),
            "undoManager.isEnabled": true,  // enable undo & redo
            // a Changed listener on the Diagram.model
            "ModelChanged": e => { if (e.isTransactionFinished) saveModel(); }
          });

  #### Parameters

  - ##### `Optional` div: string | Element

    A reference to a DIV HTML element or its ID as a string. If no DIV is supplied, a Diagram will be created in memory. The Diagram's Diagram.div property can then be set later on.

  - ##### `Optional` init: DiagramInitOptions

    A JavaScript object specifying optional initialization properties object. Can specify Diagram properties, Diagram sub-properties such as `"undoManager.isEnabled": true`, and DiagramEvent listeners. Example:

        {
          allowZoom: false,
          "animationManager.isEnabled": false,
          "ModelChanged": e => { if (e.isTransactionFinished) saveModel(); }
        }

  #### Returns Diagram

- new Diagram(init?: DiagramInitOptions): Diagram

- #### Parameters

  - ##### `Optional` init: DiagramInitOptions

    A JavaScript object specifying optional initialization properties object. Can specify Diagram properties, Diagram sub-properties such as `"undoManager.isEnabled": true`, and DiagramEvent listeners. Example:

        {
          allowZoom: false,
          "animationManager.isEnabled": false,
          "ModelChanged": e => { if (e.isTransactionFinished) saveModel(); }
        }

  #### Returns Diagram

## Accessors

### allowClipboard
: boolean

- Gets or sets whether the user may copy to or paste parts from the internal clipboard. This allows use of CommandHandler.cutSelection, CommandHandler.copySelection and CommandHandler.pasteSelection. The initial value is true.

### allowCopy
: boolean

- Gets or sets whether the user may copy objects. The initial value is true.

  `see`
  - Part.copyable
  - Part.canCopy
  - Layer.allowCopy

### allowDelete
: boolean

- Gets or sets whether the user may delete objects from the Diagram. The initial value is true.

  `see`
  - Part.deletable
  - Part.canDelete
  - Layer.allowDelete

### allowDragOut
: boolean

- Gets or sets whether the user may start a drag-and-drop in this Diagram, possibly dropping in a different element. The initial value is false.

### allowDrop
: boolean

- Gets or sets whether the user may end a drag-and-drop operation in this Diagram. This is typically set to true when a Diagram is used with a Palette.

  The initial value is true.

### allowGroup
: boolean

- Gets or sets whether the user may group parts together. The initial value is true.

  `see`
  - Part.groupable
  - Part.canGroup
  - Layer.allowGroup

### allowHorizontalScroll
: boolean

- Gets or sets whether the user is allowed to use the horizontal scrollbar. The initial value is true.

  `see`
  - hasHorizontalScrollbar
  - allowVerticalScroll

### allowInsert
: boolean

- Gets or sets whether the user may add parts to the Diagram. The initial value is true.

### allowLink
: boolean

- Gets or sets whether the user may draw new links. The initial value is true.

  `see`

  Layer.allowLink

### allowMove
: boolean

- Gets or sets whether the user may move objects. The initial value is true.

  `see`
  - Part.movable
  - Part.canMove
  - Layer.allowMove

### allowRelink
: boolean

- Gets or sets whether the user may reconnect existing links. The initial value is true.

  `see`
  - Link.relinkableFrom
  - Link.relinkableTo
  - Link.canRelinkFrom
  - Link.canRelinkTo
  - Layer.allowRelink

### allowReshape
: boolean

- Gets or sets whether the user may reshape parts. The initial value is true.

  `see`
  - Part.reshapable
  - Part.canReshape
  - Layer.allowReshape

### allowResize
: boolean

- Gets or sets whether the user may resize parts. The initial value is true.

  `see`
  - Part.resizable
  - Part.canResize
  - Layer.allowResize

### allowRotate
: boolean

- Gets or sets whether the user may rotate parts. The initial value is true.

  `see`
  - Part.rotatable
  - Part.canRotate
  - Layer.allowRotate

### allowSelect
: boolean

- Gets or sets whether the user may select objects. The initial value is true.

  `see`
  - Part.selectable
  - Part.canSelect
  - Layer.allowSelect

### allowTextEdit
: boolean

- Gets or sets whether the user may do in-place text editing. The initial value is true.

  `see`
  - Part.textEditable
  - Part.canEdit
  - Layer.allowTextEdit

### allowUndo
: boolean

- Gets or sets whether the user may undo or redo any changes. The initial value is true.

### allowUngroup
: boolean

- Gets or sets whether the user may ungroup existing groups. The initial value is true.

  `see`
  - Group.ungroupable
  - Group.canUngroup
  - Layer.allowUngroup

### allowVerticalScroll
: boolean

- Gets or sets whether the user is allowed to use the vertical scrollbar. The initial value is true.

  `see`
  - hasVerticalScrollbar
  - allowHorizontalScroll

### allowZoom
: boolean

- Gets or sets whether the user may zoom into or out of the Diagram. The initial value is true.

### `Readonly` animationManager
: AnimationManager

- This read-only property returns the AnimationManager for this Diagram.

### autoScale
: AutoScale

- Gets or sets the autoScale behavior of the Diagram, controlling whether or not the Diagram's bounds automatically scale to fit the view.

  The only accepted values are the constant properties of Diagram, AutoScale.None, AutoScale.Uniform, or AutoScale.UniformToFill. Setting this will change the Diagram's Diagram.scale and Diagram.position, if appropriate.

  The default value is AutoScale.None - the scale and position are not automatically adjusted according to the area covered by the document. When the value is not None, any value for initialAutoScale or initialScale is ignored.

  When autoScale is set to a non-AutoScale.None value, the user will not be able to zoom, and setting scale will do nothing. If you only want to scale automatically on initialization, use initialAutoScale.

  Setting this property to AutoScale.Uniform is basically the same as calling zoomToFit all the time, or just disabling interactive zooming.

  Note that depending on the values of maxScale and minScale, the actual value for scale might be limited.

  The scale will not be increased past the value of defaultScale, which is normally 1.0, so as to prevent a single node from appearing to fill up the whole viewport.

  `see`

  initialAutoScale

### autoScrollInterval
: number

- Gets or sets number of milliseconds between autoscroll events. The default value is 250.

  `since`

  2.2

### autoScrollRegion
: MarginLike

- Gets or sets the Margin that describes the area along the inside edges of the viewport, in viewport coordinates, where autoscrolling will occur while the mouse (pointer) is held there during dragging or linking or drag-selecting.

  The default value is a Margin of 16 on all sides. Increase this value in order to make it easier for the user to autoscroll by having a larger area in which to hold the mouse (pointer) down during a dragging operation.

  When the mouse (pointer) drag point is within this region on the left or right sides, the view will automatically scroll horizontally in that direction. When the point is within the region on the top or bottom, the view will automatically scroll vertically in that direction. You can specify a Margin side of zero to disable autoscrolling in a particular direction; a value of Margin(0,0,0,0) turns off autoscrolling in all four directions.

### click
: ((e: InputEvent) => void)

- Gets or sets the function to execute when the user single-primary-clicks on the background of the Diagram. This typically involves a mouse-down followed by a prompt mouse-up at approximately the same position using the left (primary) mouse button. This property is used by the ClickSelectingTool when the user clicks on no object. The function is called in addition to the DiagramEvent that is raised with the name "BackgroundSingleClicked".

  If this property value is a function, it is called with an InputEvent. By default this property is null.

  If you do provide a function that makes changes to the diagram or to its model, you should do so within a transaction -- call startTransaction and commitTransaction, or call commit.

  `see`
  - doubleClick
  - contextClick
  - GraphObject.click

### commandHandler
: CommandHandler

- Gets or sets the CommandHandler for this Diagram.

  This is set to a new instance of CommandHandler on Diagram instantiation.

  Setting this property does not notify about any changed event. The value cannot be null and must not be shared with other Diagrams.

### contentAlignment
: Spot

- Gets or sets the content alignment Spot of this Diagram, to be used in determining how parts are positioned when the viewportBounds width or height is larger than the documentBounds.

  For instance a spot of Spot.Center would ensure that the Diagram's contents are always centered in the viewport.

  If you want the content to be aligned only initially, use initialContentAlignment instead.

  The default value is Spot.Default, which causes no automatic scrolling or positioning. When the value is not Default, any value for initialContentAlignment or initialPosition is ignored.

  Setting this property has the same effect as implementing a "LayoutCompleted" DiagramEvent listener that scrolls the viewport to align the content.

### contextClick
: ((e: InputEvent) => void)

- Gets or sets the function to execute when the user single-secondary-clicks on the background of the Diagram. This typically involves a mouse-down followed by a prompt mouse-up at approximately the same position using the right (secondary) mouse button. This property is used by the ClickSelectingTool when the user clicks on no object. The function is called in addition to the DiagramEvent that is raised with the name "BackgroundContextClicked".

  If this property value is a function, it is called with an InputEvent. By default this property is null.

  If you do provide a function that makes changes to the diagram or to its model, you should do so within a transaction -- call startTransaction and commitTransaction, or call commit.

  `see`
  - click
  - doubleClick
  - GraphObject.contextClick

### contextMenu
: Adornment | HTMLInfo

- This Adornment or HTMLInfo is shown when the use context clicks in the background. The default value is null, which means no context menu is shown. On touch devices, a special default context menu will appear even there is no context menu defined. See ContextMenuTool.defaultTouchContextMenu for details.

       diagram.contextMenu =
         go.GraphObject.build("ContextMenu").add(
           go.GraphObject.build("ContextMenuButton",
               { click: (e, obj) => e.diagram.commandHandler.undo() })
             .add(new go.TextBlock("Undo"))
             .bindObject("visible", "", o => o.diagram.commandHandler.canUndo()),
           go.GraphObject.build("ContextMenuButton",
               { click: (e, obj) => e.diagram.commandHandler.redo() })
             .add(new go.TextBlock("Redo"))
             .bindObject("visible", "", o => o.diagram.commandHandler.canRedo())
         );

  `see`
  - GraphObject.contextMenu
  - ContextMenuTool

### currentCursor
: string

- Gets or sets the current cursor for the Diagram, overriding the defaultCursor.

  Valid CSS cursors are accepted, such as "auto", "default", "none", "context-menu", "help", "pointer", "progress", "wait", etc.

  It is possible to use custom cursors with the syntax "url(path_to_image), default". A fallback (like default here) is necessary for a custom cursor to work.

  To read more about cursor syntax, go to: CSS cursors (mozilla.org).

  If the specified cursor is not accepted by the platform, this property setter will try prepending `-webkit-` and `-moz-` prefixes when assigning the "cursor" CSS style property.

  Setting this property does not notify about any changed event. Setting this value to the empty string ('') returns the Diagram's cursor to the defaultCursor.

  `see`
  - defaultCursor
  - GraphObject.cursor

### currentTool
: Tool

- Gets or sets the current tool for this Diagram that handles all input events. This value is frequently replaced by the toolManager as different tools run.

  Each Diagram has a number of tools that define its behavior when responding to mouse events. These include ClickSelectingTool, DraggingTool, DragSelectingTool, LinkingTool, and ResizingTool, among others.

  Initially this is set to the value of defaultTool. Setting this to a null value is treated as if it were set to the defaultTool, because there should always be a currently running tool, except when the diagram is being initialized.

  A ToolManager is the default tool used by a Diagram - it chooses to run one of the other tools depending on the circumstances.

  Setting this property to a new tool stops the previous current tool

  Setting this property does not notify about any changed event.

  `see`
  - defaultTool
  - toolManager

### defaultCursor
: string

- Gets or sets the cursor to be used for the Diagram when no GraphObject specifies a different cursor.

  Valid CSS cursors are accepted, such as "auto", "default", "none", "context-menu", "help", "pointer", "progress", "wait", etc.

  It is possible to use custom cursors with the syntax "url(path_to_image), default". A fallback (like default here) is necessary for a custom cursor to work.

  To read more about cursor syntax, go to: CSS cursors (mozilla.org). The default value is "auto".

  `see`
  - currentCursor
  - GraphObject.cursor

### defaultScale
: number

- Gets or sets the Diagram.scale set by CommandHandler.resetZoom and when computing stretch values, such as when autoScale or initialAutoScale are set, or when zoomToFit is called.

  The default value is 1.0. The value must be a number larger than 0. Setting this property does not raise any events.

  `since`

  2.0

### defaultTool
: Tool

- Gets or sets the default tool for this Diagram that becomes the current tool when the current tool stops. Initially this value is the same tool as toolManager, which is an instance of ToolManager.

  Setting this property also sets the currentTool if the old default tool is the currently running tool.

  Setting this property does not notify about any changed event. The value cannot be null and must not be shared with other Diagrams.

  `see`
  - currentTool
  - toolManager

### div
: HTMLDivElement

- Gets or sets the Diagram's HTMLDivElement, via an HTML Element ID. This is typically set automatically when a Div is supplied as an argument to Diagram's constructor.

  Setting this property to a new value will clobber any HTML and inner DOM elements inside of both the new and the old divs. It will then populate the Div with the elements (inner Divs, Canvases) needed for the Diagram to function.

  If you want to disassociate the Diagram from the HTML Div element, set Diagram.div to null. If you remove a part of the HTML DOM containing a Div with a Diagram, you will need to set div to null in order for the page to recover the memory.

  You should not attempt to manually modify the contents of this Div. Changing this property value does not raise a Changed event.

### `Readonly` documentBounds
: Rect

- This read-only property returns the bounds of the diagram's contents, in document coordinates.

  This is normally computed and set by computeBounds during Diagram updates that can occur for any number of relevant reasons, such as a Part changing size.

  The Diagram's documentBounds can have an unvarying specific value by setting the fixedBounds property.

  If the documentBounds are larger than the viewportBounds, scrollbars will appear on desktop browsers. You can disable scrolling with the allowHorizontalScroll and allowVerticalScroll properties, and you can disable scrollbars themselves with the hasHorizontalScrollbar and hasVerticalScrollbar properties.

### doubleClick
: ((e: InputEvent) => void)

- Gets or sets the function to execute when the user double-primary-clicks on the background of the Diagram. This typically involves a mouse-down/up/down/up in rapid succession at approximately the same position using the left (primary) mouse button. This property is used by the ClickSelectingTool when the user clicks on no object. The function is called in addition to the DiagramEvent that is raised with the name "BackgroundDoubleClicked".

  If this property value is a function, it is called with an InputEvent. By default this property is null.

  If you do provide a function that makes changes to the diagram or to its model, you should do so within a transaction -- call startTransaction and commitTransaction, or call commit.

  `see`
  - click
  - contextClick
  - GraphObject.doubleClick

### firstInput
: InputEvent

- Gets or sets the most recent mouse-down InputEvent that occurred.

  Setting this property does not notify about any changed event.

  `see`

  lastInput

### fixedBounds
: Rect

- Gets or sets a fixed bounding rectangle to be returned by documentBounds and computeBounds. By default this has NaN values, meaning that computeBounds will compute the union of all of the parts in the Diagram to determine the documentBounds. If all x/y/width/height values are real numbers, this value is used as the documentBounds.

### grid
: Panel

- Gets or sets a Panel of type Panel.Grid acting as the background grid extending across the whole viewport of this diagram.

### groupSelectionAdornmentTemplate
: Adornment

- Gets or sets the default selection Adornment template, used to adorn selected Groups.

  Each Group can have its own Part.selectionAdornmentTemplate, which if non-null will take precedence over this Diagram property.

  This Adornment must not be in the visual tree of any Diagram. The value must not be null.

### groupTemplate
: Group

- Gets or sets the default Group template used as the archetype for group data that is added to the model.

  Setting this property just modifies the groupTemplateMap by replacing the entry named with the empty string. The value must not be null and must be a Group, not a Node or simple Part. This Part must not be in the visual tree of any Diagram.

### groupTemplateMap
: Map<string, Group>

- Gets or sets a go.Map mapping template names to Groups. These groups are copied for each group data that is added to the model.

  The new value must not be null, nor may it contain a Node or Link or simple Part. The Links must not be in the visual tree of any Diagram. Replacing this Map will automatically call rebuildParts.

  If you modify this go.Map, by replacing a Group in it or by adding or removing a map entry, you need to explicitly call rebuildParts afterwards.

### handlesDragDropForTopLevelParts
: boolean

- Gets or sets whether drag-and-drop events may be bubbled up to the diagram if not handled by a part. The default value is false -- each Node or Link that in the diagram needs to define its own GraphObject.mouseDragEnter, GraphObject.mouseDragLeave, and GraphObject.mouseDrop event handlers if you want dragging/dropping on a part to act as if the user were acting on the diagram.

  If set to true, this will call Diagram.mouseDragOver during a drag, even while dragging over top-level parts, and Diagram.mouseDrop will be called even when dropping onto parts.

  This property will have no impact while dropping on a Group. The Group's mouseDrop and Group.handlesDragDropForMembers should be set if desired.

  GraphObjects do not have a mouseDragOver property, so if this is set to true, the Diagram's mouseDragOver will always be called, even when dragging over a part.

  `see`
  - mouseDragOver
  - mouseDrop
  - Group.handlesDragDropForMembers
  - GraphObject.mouseDrop
  `since`

  2.0

### hasHorizontalScrollbar
: boolean

- Gets or sets whether the Diagram has a horizontal Scrollbar.

  To enable or disable scrolling itself, use allowHorizontalScroll and allowVerticalScroll.

  Adding or removing a scrollbar modifies the diagram's viewport.

  The initial value is true.

  `see`
  - allowHorizontalScroll
  - hasVerticalScrollbar

### hasVerticalScrollbar
: boolean

- Gets or sets whether the Diagram has a vertical Scrollbar.

  To enable or disable scrolling itself, use allowHorizontalScroll and allowVerticalScroll.

  Adding or removing a scrollbar modifies the diagram's viewport.

  The initial value is true.

  `see`
  - allowVerticalScroll
  - hasHorizontalScrollbar

### `Readonly` highlighteds
: Set<Part>

- This read-only property returns the read-only collection of highlighted parts.

  Do not modify this collection. If you want to highlight or remove the highlight for a particular Part in a Diagram, set the Part.isHighlighted property. If you want to highlight a collection of Parts, call highlightCollection. If you want to remove all highlights and highlight a single object, call highlight. If you want to remove all highlights, call clearHighlighteds.

  Note that highlighteds collection and Part.isHighlighted property are completely independent of the selection collection and the Part.isSelected property. No predefined command or tool operates on this highlighteds collection.

### initialAutoScale
: AutoScale

- Gets or sets how the scale of the diagram is automatically set at the time of the "InitialLayoutCompleted" DiagramEvent, after the model has been replaced.

  The only accepted values are listed as constant properties of Diagram, such as AutoScale.None, AutoScale.Uniform, or AutoScale.UniformToFill. Setting this will change the Diagram's Diagram.scale and Diagram.position, if appropriate.

  If you want to always automatically scale the Diagram, set autoScale instead. If you want to set the scale to a specific value on initialization (each time the model is replaced), set initialScale.

  The default value is AutoScale.None -- the scale and position are not automatically adjusted according to the area covered by the document.

  Setting this property to AutoScale.Uniform is basically the same as calling zoomToFit in an "InitialLayoutCompleted" DiagramEvent listener.

  Note that depending on the values of maxScale and minScale, the actual value for scale might be limited.

  Setting this property to AutoScale.Uniform is basically the same as calling zoomToFit all the time, or just disabling interactive zooming.

  Note that depending on the values of maxScale and minScale, the actual value for scale might be limited.

  The scale will not be increased past the value of defaultScale, which is normally 1.0, so as to prevent a single node from appearing to fill up the whole viewport.

  `see`

  autoScale

### initialContentAlignment
: Spot

- Gets or sets the initial content alignment Spot of this Diagram, to be used in determining how parts are positioned initially relative to the viewport, when the viewportBounds width or height is larger than the documentBounds.

  For instance a spot of Spot.Center would ensure that the Diagram's contents are initially centered in the viewport.

  To initially align the document when the documentBounds are larger than the viewport, use initialDocumentSpot and initialViewportSpot.

  If you want the content to be constantly aligned with a spot, use contentAlignment instead.

  The default value is Spot.Default, which causes no automatic scrolling or positioning.

  Setting this property has the same effect as implementing an "InitialLayoutCompleted" DiagramEvent listener that scrolls the viewport to align the content.

  `see`
  - initialDocumentSpot
  - initialViewportSpot

### initialDocumentSpot
: Spot

- Gets or sets the spot in the document's area that should be coincident with the initialViewportSpot of the viewport when the document is first initialized. The default value is Spot.None.

  If you set this, often you will also want to set initialViewportSpot. If you set initialPosition, it will take precedence over this property.

  Setting this property and initialViewportSpot has the same effect as implementing an "InitialLayoutCompleted" DiagramEvent listener that calls alignDocument.

  `see`
  - initialViewportSpot
  - initialPosition
  - initialContentAlignment

### initialPosition
: Point

- Gets or sets the initial coordinates of this Diagram in the viewport, eventually setting the position. This value is relevant on initialization of a model or if delayInitialization is called. Value must be of type Point in document coordinates. The default is Point(NaN, NaN).

  Setting this property has the same effect as implementing an "InitialLayoutCompleted" DiagramEvent listener that sets position.

  Setting this property does not notify about any changed event.

  `see`
  - initialDocumentSpot
  - initialViewportSpot

### initialScale
: number

- Gets or sets the initial scale of this Diagram in the viewport, eventually setting the scale. This value is relevant on initialization of a model or if delayInitialization is called. The default is NaN.

  Setting this property has the same effect as implementing an "InitialLayoutCompleted" DiagramEvent listener that sets scale.

### initialViewportSpot
: Spot

- Gets or sets the spot in the viewport that should be coincident with the initialDocumentSpot of the document when the document is first initialized. The default value is Spot.None.

  If you set this, often you will also want to set initialDocumentSpot. If you set initialPosition, it will take precedence over this property.

  Setting this property and initialDocumentSpot has the same effect as implementing an "InitialLayoutCompleted" DiagramEvent listener that calls alignDocument.

  `see`
  - initialDocumentSpot
  - initialContentAlignment

### isEnabled
: boolean

- Gets or sets whether the user may interact with the Diagram.

  `see`
  - isReadOnly
  - isModelReadOnly

### isModelReadOnly
: boolean

- Gets or sets whether the Diagram's Diagram.model is Model.isReadOnly.

  `see`
  - isReadOnly
  - isEnabled

### isModified
: boolean

- Gets or sets whether this Diagram's state has been modified. Setting this property does not notify about any changed event, but it does raise the "Modified" DiagramEvent, although perhaps not immediately.

  Returns true if the Diagram has been changed, if the undoManager has recorded any changes, or if an undo has been performed without a corresponding redo.

  Replacing the model automatically sets this property to false after the initial layout has completed. The "Modified" DiagramEvent is also raised when an undo or a redo has finished. A "Modified" DiagramEvent listener must not modify this Diagram or its Model.

### isMouseCaptured
: boolean

- Gets or sets whether mouse events initiated within the Diagram will be captured. The initial value is true. Setting this property does not notify about any changed event.

### isReadOnly
: boolean

- Gets or sets whether the Diagram may be modified by the user, while still allowing the user to scroll, zoom, and select. The initial value is false.

  `see`
  - isModelReadOnly
  - isEnabled

### isTreePathToChildren
: boolean

- Gets or sets whether the Diagram tree structure is defined by links going from the parent node to their children, or vice-versa. By default this property is true: links go from the parent node to the child node.

### lastInput
: InputEvent

- Gets or sets the last InputEvent that occurred.

  This property is useful in tools and real-time operations for determining where the mouse pointer was most recently located.

  Setting this property does not notify about any changed event.

  `see`

  firstInput

### `Readonly` layers
: Iterator<Layer>

- This read-only property returns an iterator for this Diagram's Layers.

  `see`
  - addLayer
  - removeLayer

### layout
: Layout

- Gets or sets the Layout used to position all of the top-level nodes and links in this Diagram. By default this property is an instance of a simple Layout that assigns positions to all parts that need it. The value cannot be null and must not be shared with other Diagrams.

### linkSelectionAdornmentTemplate
: Adornment

- Gets or sets the default selection Adornment template, used to adorn selected Links.

  Each Link can have its own Part.selectionAdornmentTemplate, which if non-null will take precedence over this Diagram property.

  This Adornment must not be in the visual tree of any Diagram. The value must not be null.

### linkTemplate
: Link

- Gets or sets the default Link template used as the archetype for link data that is added to the model.

  Setting this property just modifies the linkTemplateMap by replacing the entry named with the empty string. The value must not be null and must be a Link, not a Node or simple Part. This Link must not be in the visual tree of any Diagram.

### linkTemplateMap
: Map<string, Link>

- Gets or sets a go.Map mapping template names to Links. These links are copied for each link data that is added to the model.

  The new value must not be null and must contain only Links, not Nodes or simple Parts. The Links must not be in the visual tree of any Diagram. Replacing this Map will automatically call rebuildParts.

  If you modify this go.Map, by replacing a Link in it or by adding or removing a map entry, you need to explicitly call rebuildParts afterwards.

### `Readonly` links
: Iterator<Link>

- This read-only property returns an iterator of all Links in the Diagram.

  This includes both data-bound and unbound links, and both top-level links and links inside Groups.

### maxScale
: number

- Gets or sets the largest value that scale may take. This property is only used to limit the range of new values of scale.

  The default value is 100.0. Values must be no less than one. Setting this to a value that is less than the current scale will cause the current diagram scale to be set to this new value.

### maxSelectionCount
: number

- Gets or sets the maximum number of selected objects. The default value is a large positive integer. Values must be non-negative. Decreasing this value may cause objects to be removed from selection in order to meet the new lower limit.

### minScale
: number

- Gets or sets the smallest value greater than zero that scale may take. This property is only used to limit the range of new values of scale.

  The default value is 0.0001. Values must be larger than zero and not greater than one. Setting this to a value that is greater than the current scale will cause the current diagram scale to be set to this new value.

### model
: Model

- Gets or sets the Model holding data corresponding to the data-bound nodes and links of this Diagram.

  Replacing this value causes all of the bound Nodes and Links to be deleted and re-created from the new model data.

  Models may be shared by multiple Diagrams. One common approach is to have two Diagrams displaying the same Model but using different templates (see nodeTemplate, nodeTemplateMap, and the associated link and group properties) and sometimes even different Layouts.

  Setting this property does not notify about any changed event; the new value must not be null. Typically a new Model will have its own UndoManager, thereby replacing the Diagram's current UndoManager.

  Replacing or re-setting the model will re-initialize the Diagram, taking in to account initialPosition, initialScale, initialAutoScale, and initialContentAlignment. It will also set isModified to false.

  The default behavior when replacing the model is to copy a few UndoManager properties to the new UndoManager, including UndoManager.isEnabled and UndoManager.maxHistoryLength.

  It is an error to replace the Diagram.model while a transaction is in progress.

### mouseDragOver
: ((e: InputEvent) => void)

- Gets or sets the function to execute when the user is dragging the selection in the background of the Diagram during a DraggingTool drag-and-drop, not over any GraphObjects.

  If this property value is a function, it is called with an InputEvent. It is called within the transaction performed by the DraggingTool. By default this property is null.

  Note that for a drag-and-drop that originates in a different diagram, the target diagram's selection collection will not be the parts that are being dragged. Instead the temporary parts being dragged can be found as the source diagram's DraggingTool.copiedParts.

  This function is called with Diagram.skipsUndoManager temporarily set to true, so that any changes to GraphObjects are not recorded in the UndoManager. You do not need to start and commit any transaction in this function. After calling this function the diagram will be updated immediately.

  For example, if you want to prevent the user from dropping Parts into the background of the diagram, and want to provide feedback about that during a drag:

        myDiagram.mouseDragOver = e => {
          myDiagram.currentCursor = "no-drop";
        }

  `see`
  - mouseDrop
  - GraphObject.mouseDragEnter
  - GraphObject.mouseDragLeave

### mouseDrop
: ((e: InputEvent) => void)

- Gets or sets the function to execute when the user drops the selection in the background of the Diagram at the end of a DraggingTool drag-and-drop, not onto any GraphObjects.

  If this property value is a function, it is called with an InputEvent. It is called within the transaction performed by the DraggingTool. By default this property is null.

  For example, if you want to prevent the user from dropping Parts into the background of the diagram:

        myDiagram.mouseDrop = e => {
          myDiagram.currentTool.doCancel();
        }

  `see`
  - mouseDragOver
  - GraphObject.mouseDrop

### mouseEnter
: ((e: InputEvent) => void)

- Gets or sets the function to execute when the mouse (pointer) enters the Diagram. (When the browser's mouseEnter event fires on the Diagram canvas.)

  If this property value is a function, it is called with an InputEvent. By default this property is null.

  If you do provide a function that makes changes to the diagram or to its model, you should do so within a transaction -- call startTransaction and commitTransaction, or call commit.

  `see`
  - mouseLeave
  - GraphObject.mouseEnter
  `since`

  2.0

### mouseHold
: ((e: InputEvent) => void)

- Gets or sets the function to execute when the user holds the mouse (pointer) stationary in the background of the Diagram while holding down a button, not over any GraphObjects. This property is used by the ToolManager.

  If this property value is a function, it is called with an InputEvent. By default this property is null.

  If you do provide a function that makes changes to the diagram or to its model, you should do so within a transaction -- call startTransaction and commitTransaction, or call commit.

  `see`
  - GraphObject.mouseHold
  - ToolManager.doMouseHover

### mouseHover
: ((e: InputEvent) => void)

- Gets or sets the function to execute when the user holds the mouse (pointer) stationary in the background of the Diagram without holding down any buttons, not over any GraphObjects. This property is used by the ToolManager.

  If this property value is a function, it is called with an InputEvent. By default this property is null.

  If you do provide a function that makes changes to the diagram or to its model, you should do so within a transaction -- call startTransaction and commitTransaction, or call commit.

  `see`
  - mouseOver
  - GraphObject.mouseHover
  - ToolManager.doMouseHover

### mouseLeave
: ((e: InputEvent) => void)

- Gets or sets the function to execute when the mouse (pointer) leaves the Diagram.

  If this property value is a function, it is called with an InputEvent. By default this property is null.

  If you do provide a function that makes changes to the diagram or to its model, you should do so within a transaction -- call startTransaction and commitTransaction, or call commit.

  `see`
  - mouseEnter
  - GraphObject.mouseLeave
  `since`

  2.0

### mouseOver
: ((e: InputEvent) => void)

- Gets or sets the function to execute when the user moves the mouse (pointer) in the background of the Diagram without holding down any buttons, not over any GraphObjects. This property is used by the ToolManager.

  If this property value is a function, it is called with an InputEvent. By default this property is null.

  This function is called with Diagram.skipsUndoManager temporarily set to true, so that any changes to GraphObjects are not recorded in the UndoManager. You do not need to start and commit any transaction in this function. After calling this function the diagram will be updated immediately.

  `see`
  - mouseHover
  - GraphObject.mouseOver

### nodeSelectionAdornmentTemplate
: Adornment

- Gets or sets the default selection Adornment template, used to adorn selected Parts other than Groups or Links.

  Each Node or simple Part can have its own Part.selectionAdornmentTemplate, which if non-null will take precedence over this Diagram property.

  This Adornment must not be in the visual tree of any Diagram. The value must not be null.

### nodeTemplate
: Part

- Gets or sets the default Node template used as the archetype for node data that is added to the model. Setting this property just modifies the nodeTemplateMap by replacing the entry named with the empty string.

  The value must not be null. The template may be either a Node or a simple Part, but not a Link or a Group.

  This Part must not be in the visual tree of any Diagram.

### nodeTemplateMap
: Map<string, Part>

- Gets or sets a go.Map mapping template names to Parts. These nodes are copied for each node data that is added to the model.

  The new value must not be null and must contain Nodes or simple Parts. These Parts must not be in the visual tree of any Diagram. Replacing this Map will automatically call rebuildParts.

  If you modify this go.Map, by replacing a Node or by adding or removing a map entry, you need to explicitly call rebuildParts afterwards. Any new map values must not be Links or Groups.

  If you want to create Groups, use groupTemplateMap instead.

### `Readonly` nodes
: Iterator<Node>

- This read-only property returns an iterator of all Nodes and Groups in the Diagram.

  This includes both data-bound and unbound nodes, and both top-level nodes and nodes inside Groups. All of the simple Parts are accessible via the parts property.

  `see`
  - findTopLevelGroups
  - findTreeRoots

### opacity
: number

- Gets or sets the opacity for all parts in this diagram. The value must be between 0.0 (fully transparent) and 1.0 (no additional transparency). This value is multiplicative with any existing transparency, for instance from a Brush or image transparency. The default value is 1.

  `since`

  2.1

  `see`
  - Layer.opacity
  - GraphObject.opacity

### padding
: MarginLike

- Gets or sets the Margin that describes the Diagram's padding, which controls how much extra space in document coordinates there is around the area occupied by the document. This keeps nodes from butting up against the side of the diagram (unless scrolled).

  The default value is a margin of 5, all around the edge of the document.

### `Readonly` parts
: Iterator<Part>

- This read-only property returns an iterator of all Parts in the Diagram that are not Nodes or Links or Adornments.

  This includes both data-bound and unbound parts, and both top-level parts and parts inside Groups. Use the nodes or links properties for getting the collection of all Nodes or Links in the diagram.

### position
: Point

- Gets or sets the coordinates of this Diagram in the viewport. Value must be of type Point in document coordinates. The default is Point(NaN, NaN), but is typically set to a real value when a Diagram is initialized.

  Scrolling and panning the Diagram modify the Diagram's position.

  Setting this property does not notify about any changed event. However you can listen with addDiagramListener for a DiagramEvent with the name "ViewportBoundsChanged".

  The viewportBounds x and y values are always the same as the Diagram's position values.

  If you set this property any replacement of the model will result in a layout and a computation of new documentBounds, which in turn may cause the diagram to be scrolled and zoomed, depending on various Diagram properties named "initial...". You may want to set initialPosition instead of setting this property around the time that you are loading a model.

### positionComputation
: ((thisDiagram: Diagram, newPosition: Point) => Point)

- Gets or sets the function used to determine the position that this Diagram can be scrolled or moved to.

  By default this function is null and the Diagram's position is bound only by the document bounds.

  When this property is set the function is given a reference to the diagram and the proposed new position Point. The function must return a new point.

  An example that disallows decimal position values:

        function computeIntegralPosition(diagram, pt) {
          return new go.Point(Math.floor(pt.x), Math.floor(pt.y));
        }

  The function, if supplied, must not have any side-effects.

### renderer
: "canvas" | "svg" | "default"

- Gets or sets the rendering context type. Values are `'default'`, which uses the HTML Canvas, or `'svg'`, which builds and updates an SVG DOM.

  Setting this value dynamically is uncommon, typically a render is chosen only once, when the Diagram is initially created. Using the SVG rendering context is also uncommon, because the default canvas context has considerably greater performance.

  For more information, see the intro page on the SVG drawing context.

  `since`

  2.3

### `Readonly` routers
: List<Router>

- This read-only property returns the list of Routers that might run during this Diagram's update loop. The typical usage when initializing the Diagram is to construct a particular Router and add it to this List.

  By default, this list contains one router, the undocumented AvoidsNodesRouter.

  `since`

  3.0

### scale
: number

- Gets or sets the scale transform of this Diagram. Value must be a positive number. The default value is 1. Any new value will be coerced to be between minScale and maxScale.

  Scale can automatically be set by the autoScale property. There are also initialScale and initialAutoScale for setting the scale on (re)initialization of a Diagram.

  Setting this property does not notify about any changed event. However you can listen with addDiagramListener for a DiagramEvent with the name "ViewportBoundsChanged".

  If you set this property any replacement of the model will result in a layout and a computation of new documentBounds, which in turn may cause the diagram to be scrolled and zoomed, depending on various Diagram properties named "initial...". You may want to set initialScale instead of setting this property around the time that you are loading a model.

### scaleComputation
: ((thisDiagram: Diagram, newScale: number) => number)

- Gets or sets the function used to determine valid scale values for this Diagram.

### scrollHorizontalLineChange
: number

- Gets or sets the distance in screen pixels that the horizontal scrollbar will scroll when scrolling by a line.

  The default value is 16.

  `see`

  scrollVerticalLineChange

### scrollMargin
: MarginLike

- Gets or sets a scrollable area in document coordinates that surrounds the document bounds, allowing the user to scroll into empty space.

  The margin is only effective in each direction when the document bounds plus margin is greater than the viewport bounds.

  The default value is a margin of 0, all around the edge of the document.

### scrollMode
: ScrollMode

- Gets or sets the scrollMode of the Diagram, allowing the user to either scroll to document bound borders with ScrollMode.Document, or scroll endlessly with ScrollMode.Infinite.

  The default value is ScrollMode.Document. Changing this property value does not raise a Changed event.

### scrollVerticalLineChange
: number

- Gets or sets the distance in screen pixels that the vertical scrollbar will scroll when scrolling by a line.

  The default value is 16.

  `see`

  scrollHorizontalLineChange

### scrollsPageOnFocus
: boolean

- Gets or sets whether the page may be scrolled when the diagram receives focus. This happens in some browsers when the top-left corner of the diagram's HTMLDivElement is scrolled out of view, the diagram does not have focus, and the user clicks in the diagram.

  The default value is false.

### `Readonly` selection
: Set<Part>

- This read-only property returns the read-only collection of selected objects. Most commands and many tools operate on this collection.

  Do not modify this collection. If you want to select or deselect a particular object in a Diagram, set the Part.isSelected property. If you want to select a collection of Parts, call selectCollection. If you want to deselect all objects, call clearSelection. If you want to deselect all objects and select a single object, call select.

  You can limit how many objects the user can select by setting maxSelectionCount.

  There are also DiagramEvents for "ChangingSelection" and "ChangedSelection", which are raised by commands and tools before and after changes to this selection collection.

  Note that selection collection and Part.isSelected property are completely independent of the highlighteds collection and the Part.isHighlighted property.

### skipsUndoManager
: boolean

- Gets or sets whether ChangedEvents are not recorded by the UndoManager. The initial and normal value is false. WARNING: while this property is true do not perform any changes that cause any previous transactions to become impossible to undo.

  While this property is true, changing the Diagram or any GraphObject does not call UndoManager.handleChanged. Even when this property is true, transactions (such as calls to startTransaction) and undo/redo (such as calls to CommandHandler.undo) are still delegated to the undoManager.

  You should set this to true only temporarily, and you should remember its previous value before setting this to true. When finishing the period for which you want the UndoManager to be disabled, you should set this back to the remembered value it had before it was set to true.

  For more permanent disabling of the UndoManager, set UndoManager.isEnabled to false.

  Setting this property also sets Model.skipsUndoManager to the same value. Setting this property does not notify about any changed event.

### themeManager
: ThemeManager

- Gets or sets the ThemeManager for this Diagram.

### toolManager
: ToolManager

- Gets or sets the ToolManager for this Diagram. This tool is used for mode-less operation. It is responsible for choosing a particular tool to run as the currentTool.

  This tool is normally also the defaultTool. If you don't want the ToolManager to run at all, replace the defaultTool with your own tool.

  Setting this property does not notify about any changed event. The value cannot be null and must not be shared with other Diagrams. If you set this property, you will probably also want to set defaultTool.

  `see`

  defaultTool

### toolTip
: Adornment | HTMLInfo

- This Adornment or HTMLInfo is shown when the mouse (pointer) stays motionless in the background. The default value is null, which means no tooltip is shown.

  Here is a simple example:

       diagram.toolTip =
         new go.Adornment("Auto").add(
           new go.Shape({ fill: "#CCFFCC" }),
           new go.TextBlock("This diagram lets you control the world.",
               { margin: 4 })
         );

  `see`
  - GraphObject.toolTip
  - ToolManager.doToolTip

### `Readonly` undoManager
: UndoManager

- This read-only property returns the UndoManager for this Diagram, which actually belongs to the model.

  The default UndoManager has its UndoManager.isEnabled property set to false. If you want users to undo and redo, you should set that property to true once you have initialized the Diagram or its Model.

  Note that the UndoManager might be shared with other Diagrams that are showing the same Model. The UndoManager might also be shared with other Models too.

### validCycle
: CycleMode

- Gets or sets what kinds of graphs this diagram allows the user to draw. By default this property is CycleMode.All -- all kinds of cycles are permitted. Common values include CycleMode.DestinationTree and CycleMode.NotDirected.

### viewSize
: Size

- Gets or sets a fixed size in document coordinates to be returned by viewportBounds. This is typically only set when the Diagram's div is `null`. This property is intended to be used in DOM-less environments where there is no Diagram div expected, to simulate the size of the DIV. Normally, the viewportBounds is sized by the DIV instead.

  By default this is `Size(NaN, NaN)`. If this property is set, its size will always be used to compute the viewportBounds, even if a div is also set. It is uncommon to set both this property and a Diagram DIV.

  See the intro page on GoJS within Node.js for a usage example.

  `see`

  viewportBounds

  `since`

  2.0

### `Readonly` viewportBounds
: Rect

- This read-only property returns the bounds of the portion of the Diagram in document coordinates that is viewable from its HTML Canvas. Typically when the viewport bounds are smaller than the documentBounds, the user can scroll or pan the view.

  The x and y coordinates are equal to the position of the Diagram, and the width and height are equal to the Diagram's canvas width and height, divided by the scale.

### zoomPoint
: Point

- Gets or sets the zoom point of this Diagram, in viewport coordinates. This is used by Tool.standardMouseWheel and scale-setting commands to control where to zoom in or out.

  Typical usage is to remember the value of this property and to set this property to some point within the viewport (between zero and the canvas width and height). This is commonly accomplished by using the InputEvent.viewPoint of Diagram.lastInput. Then one changes the scale somehow, perhaps by executing one of the CommandHandler commands, or by rotating the mouse wheel, or just by setting the Diagram.scale property. Finally one restores the original value of this property.

  The default value is Point(NaN, NaN). Value must be of type Point, in element coordinates, not in document coordinates. Setting this property does not notify about any changed event.

### `Static` licenseKey
: string

- Gets or sets the license key. Read more about the license key at Deployment.

  `since`

  2.0

### `Static` `Readonly` version
: string

- Gets the current GoJS version.

  `since`

  2.0

## Methods

### add

- add(part: Part): void

- Adds a Part to the Layer that matches the Part's Part.layerName, or else the default layer, which is named with the empty string.

  Normally parts added to a diagram are top-level parts. If you want nodes to be members of a Group, in addition to calling this method call Group.addMembers or set each Part.containingGroup.

  #### Parameters

  - ##### part: Part

  #### Returns void

  `see`

  remove

### addChangedListener

- addChangedListener(listener: ChangedEventHandler): Diagram

- Register an event handler that is called when there is a ChangedEvent because this Diagram or one of its Parts has changed, but not because the Model or any model data has changed.

  It is unusual to listen for Diagram ChangedEvents -- it is far more common to listen for specific DiagramEvents by calling addDiagramListener, or to listen for Model ChangedEvents (i.e. changes to the model) by calling addModelChangedListener.

  Do not add or remove Changed listeners during the execution of a Changed listener.

  #### Parameters

  - ##### listener: ChangedEventHandler

    a function that takes a ChangedEvent as its argument.

  #### Returns Diagram

  this Diagram

  `see`

  removeChangedListener

### addDiagramListener

- addDiagramListener(name: DiagramEventName, listener: DiagramEventHandler): Diagram

- Register an event handler that is called when there is a DiagramEvent of a given name.

  See the DiagramEvent documentation for a complete listing of diagram event names and their purposes.

  #### Parameters

  - ##### name: DiagramEventName

    the name is normally capitalized, but this method uses case-insensitive comparison.

  - ##### listener: DiagramEventHandler

    a function that takes a DiagramEvent as its argument.

  #### Returns Diagram

  this Diagram

  `see`

  removeDiagramListener

### addLayer

- addLayer(layer: Layer): Diagram

- Adds a new Layer to the list of layers. If Layer.isTemporary is false, the layer is added after all existing non-temporary layers. If Layer.isTemporary is true, the layer is added as the very last layer.

  #### Parameters

  - ##### layer: Layer

    The new Layer to add. It is an error if the Layer already belongs to a Diagram.

  #### Returns Diagram

  this Diagram

  `see`
  - addLayerBefore
  - addLayerAfter
  - removeLayer
  - findLayer

### addLayerAfter

- addLayerAfter(layer: Layer, existingLayer: Layer): Diagram

- Adds a layer to the list of layers after a specified layer. This method can also re-order layers.

  #### Parameters

  - ##### layer: Layer

    the new Layer to add or existing Layer to move in Z-order.

  - ##### existingLayer: Layer

    the other Layer in this Diagram which should come just before the new or moved layer.

  #### Returns Diagram

  this Diagram

  `see`
  - addLayer
  - addLayerBefore
  - removeLayer

### addLayerBefore

- addLayerBefore(layer: Layer, existingLayer: Layer): Diagram

- Adds a layer to the list of layers before a specified layer. This method can also re-order layers.

  #### Parameters

  - ##### layer: Layer

    the new Layer to add or existing Layer to move in Z-order.

  - ##### existingLayer: Layer

    the other Layer in this Diagram which should come just after the new or moved layer.

  #### Returns Diagram

  this Diagram

  `see`
  - addLayer
  - addLayerAfter
  - removeLayer

### addModelChangedListener

- addModelChangedListener(listener: ChangedEventHandler): Diagram

- Register an event handler on this Diagram's Diagram.model that is called when there is a ChangedEvent on the Model, not in this diagram. Be sure to call removeModelChangedListener when you are done with the diagram.

  This is convenient when the Diagram.model may be replaced. Using this method to register a Model Changed listener is more convenient than calling Model.addChangedListener directly because when this diagram's Model is replaced, one does not need to call Model.removeChangedListener on the old Model and then Model.addChangedListener again on the new Model.

  You can establish Model Changed listeners when you create a Diagram. The Diagram init options are passed to GraphObject.make, which accepts "ModelChanged" as a shorthand. For example:

      new go.Diagram("myDiagramDiv",
         {
           "ModelChanged": e => { if (e.isTransactionFinished) saveModel(e.model); }
           // ... other Diagram properties
         })

  This is equivalent to:

      new go.Diagram("myDiagramDiv",
         {
             // ... Diagram properties
         })
         .addModelChangedListener(e => { if (e.isTransactionFinished) saveModel(e.model); })

  Do not add or remove Changed listeners during the execution of a Changed listener.

  #### Parameters

  - ##### listener: ChangedEventHandler

    a function that takes a ChangedEvent as its argument.

  #### Returns Diagram

  this Diagram

  `see`

  removeModelChangedListener

### alignDocument

- alignDocument(documentspot: Spot, viewportspot: Spot): void

- Aligns the Diagram's position based on a desired document Spot and viewport Spot.

  #### Parameters

  - ##### documentspot: Spot

  - ##### viewportspot: Spot

  #### Returns void

### attach

- attach(props: ObjectData): Diagram

- This method sets a collection of properties according to the property/value pairs that have been set on the given Object, in the same manner as GraphObject.make does when constructing a Diagram with an argument that is a simple JavaScript Object.

  This method does not use TypeScript compile-time type checking like Diagram.set does, but is considerably more flexible in allowing you to set sub-properties and DiagramEvents by quoted string names.

  You can set properties on an object that is the value of a property of the Diagram, or on the Diagram.toolManager, Diagram.animationManager, or Diagram.commandHandler by using a `"subpropname.property"` syntax for the property name. At the current time only a single dot is permitted in the property "name".

  The property name may also be the name of a DiagramEvent, in which case this calls addDiagramListener with that DiagramEvent name.

      aDiagram.attach({
        allowDelete: false,
        "animationManager.isEnabled": false,  // turn off automatic animations
        // specify a group membership validation predicate
        "commandHandler.memberValidation": (group, part) => ...,
        "commandHandler.copiesTree": true,  // for the copy command
        // mouse wheel zooms instead of scrolls
        "toolManager.mouseWheelBehavior": go.WheelMode.Zoom,
        "draggingTool.dragsTree": true,  // dragging for both move and copy
        "draggingTool.isGridSnapEnabled": true,
        layout: new go.TreeLayout(),
        // add a DiagramEvent listener
        "ExternalObjectsDropped": e => { e.subject.each(part => { ... }); }
      });

  #### Parameters

  - ##### props: ObjectData

    a plain JavaScript object with various property values to be set on this Diagram or on a part of this Diagram.

  #### Returns Diagram

  this Diagram

  `since`

  2.2

  `see`
  - setProperties a synonym of this method
  - set a type-safe method to set a collection of properties

### centerRect

- centerRect(r: Rect): void

- Modifies the position to show a given Rect of the Diagram by centering the viewport on that Rect.

  If the rect is near the documentBounds and if the scrollMargin is small, it might not be possible to scroll far enough to actually put the Rect area in the center of the viewport.

  #### Parameters

  - ##### r: Rect

  #### Returns void

  `see`
  - scrollToRect
  - scroll

### clear

- clear(): void

- Removes all Parts from the Diagram, including unbound Parts except for the background grid, and also clears out the Model and UndoManager and clipboard. This operation is not undoable.

  Alternative actions are to replace the model with a new Model (probably a GraphLinksModel or a TreeModel), or to set Model.nodeDataArray with an empty JavaScript Array (and GraphLinksModel.linkDataArray).

  This does not remove any listeners from the diagram.

  #### Returns void

### `Virtual` clearHighlighteds

- clearHighlighteds(): void

- Remove highlights from all Parts. This removes all parts from the highlighteds collection.

  Note that no predefined command or tool operates on the highlighteds collection, and there is no predefined visual rendering when a part becomes Part.isHighlighted.

  #### Returns void

  `see`
  - highlight
  - highlightCollection
  - Part.isHighlighted
  - clearSelection

### `Virtual` clearSelection

- clearSelection(skipsEvents?: boolean): void

- Deselect all selected Parts. This removes all parts from the selection collection.

  This method raises the "ChangingSelection" and "ChangedSelection" DiagramEvents.

  #### Parameters

  - ##### `Optional` skipsEvents: boolean

    if true, do not raise the DiagramEvents "ChangingSelection" and "ChangedSelection"; if not supplied the value is assumed to be false.

  #### Returns void

  `see`
  - select
  - selectCollection
  - clearHighlighteds

### commit

- commit(func: ((d: Diagram) => void), tname?: string): void

- Starts a new transaction, calls the provided function, and commits the transaction. Code is called within a try-finally statement. If the function does not return normally, this rolls back the transaction rather than committing it. Example usage:

      myDiagram.commit(d => d.remove(somePart), "Remove Part");

  Note: passing null as the second argument will temporarily set Diagram.skipsUndoManager to true. It is commonplace to call this method with no second argument, which would commit a transaction with a transaction name that is the empty string.

  #### Parameters

  - ##### func: ((d: Diagram) => void)

    the function to call as the transaction body

    - - (d: Diagram): void

      - #### Parameters

        - ##### d: Diagram

        #### Returns void

  - ##### `Optional` tname: string

    a descriptive name for the transaction, or null to temporarily set skipsUndoManager to true; if no string transaction name is given, an empty string is used as the transaction name

  #### Returns void

### commitTransaction

- commitTransaction(tname?: string): boolean

- Commit the changes of the current transaction. This just calls UndoManager.commitTransaction.

  #### Parameters

  - ##### `Optional` tname: string

    a descriptive name for the transaction.

  #### Returns boolean

  the value returned by UndoManager.commitTransaction.

### `Protected` `Virtual` computeBounds

- computeBounds(rect?: Rect): Rect

- This is called during a Diagram update to determine a new value for documentBounds. By default this computes the union of the bounds of all the visible GraphObjects in this Diagram, unless Diagram.fixedBounds is set. This ignores parts for which Part.isVisible is false and ignores those for which Part.isInDocumentBounds is false. The returned value includes the addition of the padding margin.

  To compute the bounds of a collection of Parts, call computePartsBounds.

  #### Parameters

  - ##### `Optional` rect: Rect

    An optional Rect to modify and return, instead of returning a new Rect

  #### Returns Rect

  a Rect in document coordinates. If the argument rect was specified, it returns that modified rect.

### `Virtual` computeMove

- computeMove(n: Part, newloc: Point, dragOptions: DraggingOptions, result?: Point): Point

- This method computes the new location for a Node or simple Part, given a new desired location, taking any grid-snapping into consideration, any Part.dragComputation function, and any Part.minLocation and Part.maxLocation.

  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

  - ##### n: Part

    the Node or simple Part that is being moved

  - ##### newloc: Point

    the proposed new location

  - ##### dragOptions: DraggingOptions

    the dragging options

  - ##### `Optional` result: Point

    an optional Point that is modified and returned

  #### Returns Point

  the possibly grid-snapped computed Point that is within the minimum and maximum permitted locations

  `since`

  2.0

### `Virtual` computePartsBounds

- computePartsBounds(coll: Iterable<Part> | Part[], includeLinks?: boolean): Rect

- Find the union of the GraphObject.actualBounds of all of the Parts in the given collection, excluding Links unless the second argument is true.

  Unlike computeBounds, this ignores the visibility of each Part and does not add any padding to the result.

  #### Parameters

  - ##### coll: Iterable<Part> | Part[]

    an iterable collection or Array of Parts.

  - ##### `Optional` includeLinks: boolean

    defaults to false

  #### Returns Rect

  This returns the bounding area of the given Parts; if there are no Parts in the collection, this returns a Rect with zero width and height and an X and Y that are NaN.

### copyParts

- copyParts(coll: Iterable<Part> | Part[], diagram: Diagram, check?: boolean): Map<Part, Part>

- Make a copy of a collection of Parts and return them in a go.Map mapping each original Part to its copy. It may optionally add them to a given Diagram. Copying a Group will also copy its member Nodes and Links. Copying a Link will also copy any label Nodes that it owns.

  This does not perform a transaction nor does it raise a DiagramEvent. Call CommandHandler.copySelection, which calls this method, if you want to copy all selected Parts into the clipboard. The CommandHandler.copySelection command may also copy additional Parts as well, depending on CommandHandler.copiesTree.

  #### Parameters

  - ##### coll: Iterable<Part> | Part[]

    A List or a go.Set or Iterator of Parts, or an Array of Parts.

  - ##### diagram: Diagram

    The destination diagram; if null, the copied parts are not added to this diagram.

  - ##### `Optional` check: boolean

    Whether to check Part.canCopy on each part. The default value is false.

  #### Returns Map<Part, Part>

### delayInitialization

- delayInitialization(func?: ((diag: Diagram) => void)): void

- Updates the diagram immediately, then resets initialization flags so that actions taken in the argument function will be considered part of Diagram initialization, and will participate in initial layouts, initialAutoScale, initialContentAlignment, etc.

  This is useful in situations where you do not wish for the first content added to the diagram to be considered the "initial" content, such as with a Node that represents a "Loading" bar.

  #### Parameters

  - ##### `Optional` func: ((diag: Diagram) => void)

    an optional function of actions to perform as part of another diagram initialization.

    - - (diag: Diagram): void

      - #### Parameters

        - ##### diag: Diagram

        #### Returns void

### ensureBounds

- ensureBounds(): void

- Ensures that the documentBounds are up to date. This is sometimes necessary when operations need updated document bounds immediately.

  It is uncommon to call this method outside of customization. For efficiency, do not call this method unnecessarily.

  #### Returns void

  `since`

  2.1.30

  `see`

  Part.ensureBounds

### findLayer

- findLayer(name: string): Layer

- Finds a layer with a given name.

  #### Parameters

  - ##### name: string

  #### Returns Layer

  a Layer with the given name, or null if no such layer was found.

  `see`
  - addLayerBefore
  - addLayerAfter
  - removeLayer

### findLinkForData

- findLinkForData(linkdata: ObjectData): Link

- Look for a Link corresponding to a GraphLinksModel's link data object.

  #### Parameters

  - ##### linkdata: ObjectData

    a JavaScript object matched by reference identity; use findLinksByExample if you want to find those Links whose data matches an example data object

  #### Returns Link

  an existing Link in this Diagram that was created because its `Part.data` was the link data in the Diagram's Model.

### findLinkForKey

- findLinkForKey(key: Key): Link

- Look for a Link corresponding to a model's link data object's unique key.

  #### Parameters

  - ##### key: Key

    a string or number.

  #### Returns Link

  null if a link data with that key cannot be found in the model, or if a corresponding Link cannot be found in the Diagram, or if the model is a GraphLinksModel without GraphLinksModel.linkKeyProperty set to a non-empty string.

  `since`

  2.1

### findLinksByExample

- findLinksByExample(...examples: ObjectData[]): Iterator<Link>

- Search for Links by matching the Link data with example data holding values, RegExps, or predicates.

  See the documentation of findNodesByExample for how the example data can match data of bound Parts.

  #### Parameters

  - ##### `Rest` ...examples: ObjectData[]

    one or more JavaScript Objects whose properties are either predicates to be applied or RegExps to be tested or values to be compared to the corresponding data property value

  #### Returns Iterator<Link>

  `see`

  findNodesByExample

### findNodeForData

- findNodeForData(nodedata: ObjectData): Node

- Look for a Node or Group corresponding to a model's node data object.

  #### Parameters

  - ##### nodedata: ObjectData

    a JavaScript object matched by reference identity; use findNodesByExample if you want to find those Nodes whose data matches an example data object

  #### Returns Node

  an existing Node or Group in this Diagram that was created because its `Part.data` was the node data in the Diagram's Model. This will be null if there is no such part or if it's just a Part or Link.

### findNodeForKey

- findNodeForKey(key: Key): Node

- Look for a Node or Group corresponding to a model's node data object's unique key.

  #### Parameters

  - ##### key: Key

    a string or number.

  #### Returns Node

  null if a node data with that key cannot be found in the model, or if a corresponding Node or Group cannot be found in the Diagram, or if what is found is just a Part.

### findNodesByExample

- findNodesByExample(...examples: ObjectData[]): Iterator<Node>

- Search for Nodes or Groups by matching the Node data with example data holding values, RegExps, or predicates.

  For example, calling this method with an argument object: `{ sex: "M", name: /^Alex/i, age: n => n >= 18 }` will return an iterator of Nodes whose `Node.data` is a JavaScript object whose:

  - sex is "M" (a case-sensitive string comparison), and
  - name starts with the string "Alex" (using a case-insensitive match), and
  - age is greater than or equal to 18

  Here is how an example value can match the corresponding data value:

  - A string, number, or boolean is compared with the === operator.

  - A function is treated as a predicate and applied to the data value.

  - A regular expression (RexExp) is matched against the toString() of the data value. Common expressions include:

    - `/abc/` matches any string that includes exactly the substring "abc"
    - `/abc/i` matches any string that includes the substring "abc", but uses a case-insensitive comparison
    - `/^no/i` matches any string that starts with "no", ignoring case
    - `/ism$` matches any string that ends with "ism" exactly
    - `/(green|red) apple/` matches any string that includes either "green apple" or "red apple"

    For more details read Regular Expressions (mozilla.org).

  - An Array requires the data value to also be an Array of equal or greater length. Each example array item that is not undefined is matched with the corresponding data array item.

  - An Object is recursively matched with the data value, which must also be an Object.

  All properties given by the argument example data must be present on the node data, unless the example property value is undefined. All other data properties are ignored when matching.

  When multiple argument objects are given, if any of the objects match the node's data, the node is included in the results.

  #### Parameters

  - ##### `Rest` ...examples: ObjectData[]

    one or more JavaScript Objects whose properties are either predicates to be applied or RegExps to be tested or values to be compared to the corresponding data property value

  #### Returns Iterator<Node>

  `see`

  findLinksByExample

### findObjectAt

- findObjectAt<T extends GraphObject>(p: Point, navig?: ((a: GraphObject) => T), pred?: ((a: T) => boolean)): T

- Find the front-most GraphObject at the given point in document coordinates.

  If Layer.visible is false, this method will not find any objects in that layer. However, Layer.opacity does not affect this method.

  Example usage:

      // Returns the top-most object that is a selectable Part, or null if there isn't one
      myDiagram.findObjectAt(
        myDiagram.lastInput.documentPoint,
        // Navigation function
        x => x.part,
        // Because of the navigation function, x will always be a Part.
        x => x.canSelect()
      );

  #### Type Parameters

  - #### T extends GraphObject

  #### Parameters

  - ##### p: Point

    A Point in document coordinates.

  - ##### `Optional` navig: ((a: GraphObject) => T)

    A function taking a GraphObject and returning a GraphObject, defaulting to the identity.

    - - (a: GraphObject): T

      - #### Parameters

        - ##### a: GraphObject

        #### Returns T

  - ##### `Optional` pred: ((a: T) => boolean)

    A function taking the GraphObject returned by navig and returning true if that object should be returned, defaulting to a predicate that always returns true.

    - - (a: T): boolean

      - #### Parameters

        - ##### a: T

        #### Returns boolean

  #### Returns T

  The first GraphObject returned by the navig function and satisfying the pred function that is at the point p, in Z-order from front to back, or else null if nothing is found.

  `see`
  - findObjectsAt
  - findObjectsIn
  - findObjectsNear
  - findPartAt

### findObjectsAt

- findObjectsAt<T extends GraphObject, S extends List<T> | Set<T>>(p: Point, navig?: ((a: GraphObject) => T), pred?: ((a: T) => boolean), coll?: S): S

- Return a collection of the GraphObjects at the given point in document coordinates.

  If Layer.visible is false, this method will not find any objects in that layer. However, Layer.opacity does not affect this method.

  Example usage:

      // Returns the Nodes that are at a given point, overlapping each other
      myDiagram.findObjectsAt(somePoint,
        // Navigation function -- only return Nodes
        x => { const p = x.part; return (p instanceof go.Node) ? p : null; }
      );

  #### Type Parameters

  - #### T extends GraphObject

  - #### S extends List<T> | Set<T> = Set<T>

  #### Parameters

  - ##### p: Point

    A Point in document coordinates.

  - ##### `Optional` navig: ((a: GraphObject) => T)

    A function taking a GraphObject and returning a GraphObject, defaulting to the identity. If this function returns null, the given GraphObject will not be included in the results.

    - - (a: GraphObject): T

      - #### Parameters

        - ##### a: GraphObject

        #### Returns T

  - ##### `Optional` pred: ((a: T) => boolean)

    A function taking the GraphObject returned by navig and returning true if that object should be returned, defaulting to a predicate that always returns true.

    - - (a: T): boolean

      - #### Parameters

        - ##### a: T

        #### Returns boolean

  - ##### `Optional` coll: S

    An optional collection (List or Set) to add the results to.

  #### Returns S

  a collection of GraphObjects returned by the navig function and satisfying the pred that are located at the point p, or else an empty collection. If a List or Set was passed in, it is returned.

  `see`
  - findObjectAt
  - findObjectsIn
  - findObjectsNear
  - findPartsAt

### findObjectsIn

- findObjectsIn<T extends GraphObject, S extends List<T> | Set<T>>(r: Rect, navig?: ((a: GraphObject) => T), pred?: ((a: T) => boolean), partialInclusion?: boolean, coll?: S): S

- Returns a collection of all GraphObjects that are inside or that intersect a given Rect in document coordinates.

  If Layer.visible is false, this method will not find any objects in that layer. However, Layer.opacity does not affect this method.

  Example usage:

      // Returns the Links that intersect a given rectangle and have a certain data property
      myDiagram.findObjectsIn(someRect,
        // Navigation function -- only return Links
        x => { const p = x.part; return (p instanceof go.Link) ? p : null; },
        // Predicate that always receives a Link, due to above navigation function
        link => link.data.someProp > 17,
        // the links may only partly overlap the given rectangle
        true
      );

  #### Type Parameters

  - #### T extends GraphObject

  - #### S extends List<T> | Set<T> = Set<T>

  #### Parameters

  - ##### r: Rect

    A Rect in document coordinates.

  - ##### `Optional` navig: ((a: GraphObject) => T)

    A function taking a GraphObject and returning a GraphObject, defaulting to the identity. If this function returns null, the given GraphObject will not be included in the results.

    - - (a: GraphObject): T

      - #### Parameters

        - ##### a: GraphObject

        #### Returns T

  - ##### `Optional` pred: ((a: T) => boolean)

    A function taking the GraphObject returned by navig and returning true if that object should be returned, defaulting to a predicate that always returns true.

    - - (a: T): boolean

      - #### Parameters

        - ##### a: T

        #### Returns boolean

  - ##### `Optional` partialInclusion: boolean

    Whether an object can match if it merely intersects the rectangular area (true) or if it must be entirely inside the rectangular area (false). The default value is false.

  - ##### `Optional` coll: S

    An optional collection (List or Set) to add the results to.

  #### Returns S

  a collection of GraphObjects returned by the navig function and satisfying the pred function that are within the rectangle r, or else an empty collection. If a List or Set was passed in, it is returned.

  `see`
  - findObjectAt
  - findObjectsAt
  - findObjectsNear
  - findPartsIn

### findObjectsNear

- findObjectsNear<T extends GraphObject, S extends List<T> | Set<T>>(p: Point, dist: number, navig?: ((a: GraphObject) => T), pred?: ((a: T) => boolean), partialInclusion?: boolean | S, coll?: S): S

- Returns a collection of all GraphObjects that are within a certain distance of a given point in document coordinates.

  If Layer.visible is false, this method will not find any objects in that layer. However, Layer.opacity does not affect this method.

  Example usage:

      // Returns the Nodes that intersect a given circular area and have a certain data property
      myDiagram.findObjectsNear(somePoint,
        // The circular area is centered at somePoint and has radius 100
        100,
        // Navigation function -- only return Nodes
        x => { const p = x.part; return (p instanceof go.Node) ? p : null; },
        // Predicate that always receives a Node, due to above navigation function
        node => node.data.someProp > 17,
        // the nodes may only partly overlap the given circular area
        true
      );

  #### Type Parameters

  - #### T extends GraphObject

  - #### S extends List<T> | Set<T> = Set<T>

  #### Parameters

  - ##### p: Point

    A Point in document coordinates.

  - ##### dist: number

    The distance from the point.

  - ##### `Optional` navig: ((a: GraphObject) => T)

    A function taking a GraphObject and returning a GraphObject, defaulting to the identity. If this function returns null, the given GraphObject will not be included in the results.

    - - (a: GraphObject): T

      - #### Parameters

        - ##### a: GraphObject

        #### Returns T

  - ##### `Optional` pred: ((a: T) => boolean)

    A function taking the GraphObject returned by navig and returning true if that object should be returned, defaulting to a predicate that always returns true.

    - - (a: T): boolean

      - #### Parameters

        - ##### a: T

        #### Returns boolean

  - ##### `Optional` partialInclusion: boolean | S

    Whether an object can match if it merely intersects the circular area (true) or if it must be entirely inside the circular area (false). The default value is true. The default is true.

  - ##### `Optional` coll: S

    An optional collection (List or Set) to add the results to.

  #### Returns S

  a collection of GraphObjects returned by the navig function and satisfying the pred that are located near the point p, or else an empty collection. If a List or Set was passed in, it is returned.

  `see`
  - findObjectAt
  - findObjectsAt
  - findObjectsIn
  - findPartsNear

### findPartAt

- findPartAt(p: Point, selectable?: boolean): Part

- This convenience function finds the front-most Part that is at a given point that might be selectable and that is not in a temporary layer.

  This just calls findObjectAt with appropriate arguments, but ignoring Layers that are Layer.isTemporary.

  #### Parameters

  - ##### p: Point

    a Point in document coordinates.

  - ##### `Optional` selectable: boolean

    Whether to only consider parts that are Part.selectable. The default is true.

  #### Returns Part

  `see`
  - findObjectAt
  - findObjectsAt
  - findObjectsIn
  - findObjectsNear
  - findPartsAt
  - findPartsIn
  - findPartsNear

### findPartForData

- findPartForData(data: ObjectData): Part

- Look for a Part, Node, Group, or Link corresponding to a Model's data object. We recommend that you call findNodeForData or findLinkForData if you are looking for a Node or a Link.

  #### Parameters

  - ##### data: ObjectData

    a JavaScript object matched by reference identity

  #### Returns Part

  an existing Part in this Diagram that was created because its `Part.data` was the data in the Diagram's Model.

### findPartForKey

- findPartForKey(key: Key): Part

- Look for a Part or Node or Group corresponding to a model's data object's unique key. This will find a Link if the model is a GraphLinksModel that is maintaining a key on the link data objects.

  #### Parameters

  - ##### key: Key

    a string or number.

  #### Returns Part

  null if a data with that key cannot be found in the model, or if a corresponding Part cannot be found in the Diagram. This will not return a Link unless the model is a GraphLinksModel and GraphLinksModel.linkKeyProperty has been set. If the same key is used for both a node data object and a link data object, this will return a Node.

### findPartsAt

- findPartsAt<T extends Part, S extends List<T> | Set<T>>(p: Point, selectable?: boolean, coll?: S): S

- This convenience function finds all Parts that are at a point in document coordinates and that are not in temporary layers.

  #### Type Parameters

  - #### T extends Part

  - #### S extends List<T> | Set<T> = Set<T>

  #### Parameters

  - ##### p: Point

    A Point in document coordinates.

  - ##### `Optional` selectable: boolean

    Whether to only consider parts that are Part.selectable. The default is true.

  - ##### `Optional` coll: S

    An optional collection (List or Set) to add the results to.

  #### Returns S

  `see`
  - findPartAt
  - findPartsIn
  - findPartsNear
  - findObjectsAt
  `since`

  2.0

### findPartsIn

- findPartsIn<T extends Part, S extends Set<T> | List<T>>(r: Rect, partialInclusion?: boolean, selectable?: boolean, coll?: S): S

- This convenience function finds Parts that are inside or that intersect a given Rect in document coordinates.

  This just calls findObjectsIn with appropriate arguments, but ignoring Layers that are Layer.isTemporary.

  #### Type Parameters

  - #### T extends Part

  - #### S extends Set<T> | List<T> = Set<T>

  #### Parameters

  - ##### r: Rect

    a Rect in document coordinates.

  - ##### `Optional` partialInclusion: boolean

    Whether a Part can match if it merely intersects the rectangular area (true) or if it must be entirely inside the rectangular area (false). The default value is false.

  - ##### `Optional` selectable: boolean

    Whether to only consider parts that are Part.selectable. The default is true.

  - ##### `Optional` coll: S

    An optional collection (List or Set) to add the results to.

  #### Returns S

  `see`
  - findPartAt
  - findPartsAt
  - findPartsNear
  - findObjectsIn
  `since`

  2.0

### findPartsNear

- findPartsNear<T extends Part, S extends List<T> | Set<T>>(p: Point, dist: number, partialInclusion?: boolean, selectable?: boolean, coll?: S): S

- This convenience function finds Parts that are within a certain distance of a given point in document coordinates.

  This just calls findObjectsNear with appropriate arguments, but ignoring Layers that are Layer.isTemporary.

  #### Type Parameters

  - #### T extends Part

  - #### S extends List<T> | Set<T> = Set<T>

  #### Parameters

  - ##### p: Point

    A Point in document coordinates.

  - ##### dist: number

    The distance from the point.

  - ##### `Optional` partialInclusion: boolean

    Whether an object can match if it merely intersects the circular area (true) or if it must be entirely inside the circular area (false). The default is true.

  - ##### `Optional` selectable: boolean

    Whether to only consider parts that are Part.selectable. The default is true.

  - ##### `Optional` coll: S

    An optional collection (List or Set) to add the results to.

  #### Returns S

  `see`
  - findPartAt
  - findPartsAt
  - findPartsIn
  - findObjectsNear
  `since`

  2.0

### findRouter

- findRouter(name: string): Router

- Finds a router with a given name in the Diagram's routers list. By default, the only router is "AvoidsNodes"

  #### Parameters

  - ##### name: string

  #### Returns Router

  a Router with the given name, or null if no such router was found.

  `since`

  3.0

### findTopLevelGroups

- findTopLevelGroups(): Iterator<Group>

- Returns an iterator of all Groups that are at top-level, in other words that are not themselves inside other Groups.

  This is useful for when you want to traverse the diagram's graph by recursing into Groups.

  #### Returns Iterator<Group>

### findTreeRoots

- findTreeRoots(): Iterator<Node>

- Returns an iterator of all top-level Nodes that have no tree parents.

  This is useful for when you want to traverse the diagram's graph by starting at the root of each tree, assuming that the diagram consists of one tree or a forest of trees.

  #### Returns Iterator<Node>

### focus

- focus(): void

- Explicitly bring HTML focus to the Diagram's canvas. This is called by tools that may create other HTML elements such as TextEditingTool.

  If scrollsPageOnFocus is false, this tries to keep the page at the same scroll position that it had before calling focus. This method is not overridable.

  #### Returns void

### highlight

- highlight(part: Part): void

- Make the given part the only highlighted part. Afterwards the highlighteds collection will have only the given part in it.

  Note that no predefined command or tool operates on the highlighteds collection, and there is no predefined visual rendering when a part becomes Part.isHighlighted.

  #### Parameters

  - ##### part: Part

    a Part that is already in a layer of this Diagram. If the value is null, this does nothing.

  #### Returns void

  `see`
  - Part.isHighlighted
  - highlightCollection
  - clearHighlighteds
  - select

### highlightCollection

- highlightCollection(coll: Iterable<Part> | Part[]): void

- Highlight all of the Parts supplied in the given collection, and unhighlight all other highlighted Parts.

  Note that no predefined command or tool operates on the highlighteds collection, and there is no predefined visual rendering when a part becomes Part.isHighlighted.

  #### Parameters

  - ##### coll: Iterable<Part> | Part[]

    a List or go.Set or Iterator or Array, of Parts to be highlighted.

  #### Returns void

  `see`
  - Part.isHighlighted
  - highlight
  - clearHighlighteds
  - selectCollection

### layoutDiagram

- layoutDiagram(invalidateAll?: boolean): void

- Perform all invalid layouts. If the optional argument is true, this will perform all of the layouts (Diagram.layout and all Group.layouts), not just the invalid ones.

  Under normal circumstances you should not need to call this method, because layouts will be performed automatically after they become invalid. However you may have disabled automatic layouts by setting Layout.isInitial and/or Layout.isOngoing to false, or by restricting a Part's Part.layoutConditions. If that is the case you might call this method (perhaps due to a user command) to perform the layout at a time of your choosing.

  #### Parameters

  - ##### `Optional` invalidateAll: boolean

    If true, this will explicitly set Layout.isValidLayout to false on each Layout in the diagram.

  #### Returns void

### makeImage

- makeImage(options?: ImageRendererOptions): HTMLImageElement

- Create an HTMLImageElement that contains a bitmap of the current Diagram. This method is just a convenience function that creates an image, sets its source to the returned string of makeImageData, and returns a reference to that Image.

  See makeImageData for a complete explanation of possible options.

  By default this method returns a snapshot of the visible diagram, but optional arguments give more options.

  Note that a returned HTMLImageElement, either returned directly or passed to the callback function, might not yet have the `complete` property set to true. So if you need to draw the image immediately, you should check that property first. If it is false, add a "load" listener to the HTMLImageElement that does the drawing you want.

  At the current time methods such as Diagram.makeImage, Diagram.makeImageData and Diagram.makeSvg do not work on Overviews.

  For the rendering to work, the diagram must have an HTML Div element as the div.

  #### Parameters

  - ##### `Optional` options: ImageRendererOptions

    a JavaScript object detailing optional arguments for image creation, to be passed to makeImageData.

  #### Returns HTMLImageElement

  An HTML Image element, or null if a callback is specified, or null if there is no DOM.

  `see`
  - makeImageData
  - makeSvg

### makeImageData

- makeImageData(options?: ImageRendererOptions): string | HTMLImageElement | ImageData

- Create a bitmap of the current Diagram encoded as a base64 string, or returned as an ImageData object. This method uses the toDataURL method of the HTMLCanvasElement to create the data URL, or the getImageData method of the Canvas Context. Unlike toDataURL, this method will not throw an error if cross-domain images were drawn on the canvas, instead it will return a data URL of a bitmap with those images omitted.

  A simple example:

      myDiagram.makeImageData({
        scale: 1.5,
        size: new go.Size(100,100)
      });

  See the page on Making Images for more usage examples.

  Note that a returned HTMLImageElement, either returned directly or passed to the callback function, might not yet have the `complete` property set to true. So if you need to draw the image immediately, you should check that property first. If it is false, add a "load" listener to the HTMLImageElement that does the drawing you want.

  At the current time methods such as Diagram.makeImage, Diagram.makeImageData and Diagram.makeSvg do not work on Overviews.

  For the rendering to work, the diagram must have an HTML Div element as the div.

  #### Parameters

  - ##### `Optional` options: ImageRendererOptions

    a JavaScript object detailing optional arguments for image creation, described by ImageRendererOptions (and DiagramRendererOptions via inheritance)

  #### Returns string | HTMLImageElement | ImageData

  An ImageData, or a base64-encoded string describing an image, or an HTMLImageElement, or null if a callback is specified.

  `see`

  makeImage

### makeSvg

- makeSvg(options?: SvgRendererOptions): SVGElement

- Create an SVGElement that contains a SVG rendering of the current Diagram.

  By default this method returns a snapshot of the visible diagram, but optional arguments give more options.

  See the page on Making SVG for usage examples. See the Minimal SVG Download sample, which also demonstrates downloading an SVG file without involving a web server.

  Note that the resulting SVG DOM is not interactive -- it is a snapshot of this diagram at this time.

  At the current time methods such as Diagram.makeImage, Diagram.makeImageData and Diagram.makeSvg do not work on Overviews.

  For the rendering to work, the diagram must have an HTML Div element as the div.

  #### Parameters

  - ##### `Optional` options: SvgRendererOptions

    a JavaScript object detailing optional arguments for SVG creation, described by SvgRendererOptions (and DiagramRendererOptions via inheritance)

  #### Returns SVGElement

  `see`

  makeImage

### moveParts

- moveParts(coll: Iterable<Part> | Part[], offset: Point, check?: boolean, dragOptions?: DraggingOptions): void

- Move a collection of Parts in this Diagram by a given offset. Moving a Group will also move its member Nodes and Links. Moving with a zero X and a zero Y offset is potentially useful in order to snap Parts to the grid if DraggingTool.isGridSnapEnabled is true.

  This does not perform a transaction nor does it raise a DiagramEvent.

  #### Parameters

  - ##### coll: Iterable<Part> | Part[]

    A List or a go.Set or Iterator of Parts, or an Array of Parts, or null to move all of the Parts in this Diagram.

  - ##### offset: Point

    the amount to move each Part, in document coordinates.

  - ##### `Optional` check: boolean

    Whether to check Part.canMove on each part. The default value is false.

  - ##### `Optional` dragOptions: DraggingOptions

    Optional dragging options. By default this uses the settings from the Diagram's DraggingTool.

  #### Returns void

### rebuildParts

- rebuildParts(): void

- Remove all of the Parts created from model data and then create them again. This must be called after modifying or replacing any of the template maps such as nodeTemplateMap. This re-selects all of the new Parts that were created from data of the original selected Parts.

  If you modify a template Map, there is no notification that the map has changed. You will need to call rebuildParts explicitly. If you are replacing the nodeTemplate or the nodeTemplateMap or the corresponding properties for Groups or Links, the Diagram property setters will automatically call rebuildParts.

  It is extremely wasteful to call this method after making some model data changes that you want to be reflected in the diagram. Instead, it is better call Model.setDataProperty, Model.addNodeData, Model.removeNodeData, or other model methods. Not only do those methods update efficiently, they also preserve unbound state and support undo/redo.

  #### Returns void

### remove

- remove(part: Part): void

- Removes a Part from its Layer, provided the Layer is in this Diagram. Removing a Node will also remove any Links that are connected with it. Removing a Group will also remove all of its members. Removing a Link will also remove all of its label Nodes, if it has any.

  #### Parameters

  - ##### part: Part

  #### Returns void

  `see`

  add

### removeChangedListener

- removeChangedListener(listener: ChangedEventHandler): void

- Unregister a ChangedEvent handler. The function argument must be the same reference as was passed to addChangedListener.

  #### Parameters

  - ##### listener: ChangedEventHandler

    a function that takes a ChangedEvent as its argument.

  #### Returns void

  `see`

  addChangedListener

### removeDiagramListener

- removeDiagramListener(name: DiagramEventName, listener: DiagramEventHandler): void

- Unregister a DiagramEvent handler.

  See the documentation for DiagramEvent for a complete listing of diagram event names and their purposes.

  #### Parameters

  - ##### name: DiagramEventName

    the name is normally capitalized, but this method uses case-insensitive comparison.

  - ##### listener: DiagramEventHandler

    a function that takes a DiagramEvent as its argument.

  #### Returns void

  `see`

  addDiagramListener

### removeLayer

- removeLayer(layer: Layer): void

- Removes the given layer from the list of layers.

  Removing a layer does not remove the Parts in the layer. Instead, those Parts are placed into the default layer. To remove all Parts in a layer you can call Diagram.removeParts with Layer.parts as the argument.

  You cannot remove the default layer, the one named with the empty string.

  #### Parameters

  - ##### layer: Layer

  #### Returns void

  `see`
  - addLayer
  - addLayerBefore
  - addLayerAfter
  - findLayer

### removeModelChangedListener

- removeModelChangedListener(listener: ChangedEventHandler): void

- Unregister a ChangedEvent handler from this Diagram's Diagram.model. The function argument must be the same reference as was passed to addChangedListener.

  #### Parameters

  - ##### listener: ChangedEventHandler

    a function that takes a ChangedEvent as its argument.

  #### Returns void

  `see`

  addModelChangedListener

### removeParts

- removeParts(coll: Iterable<Part> | Part[], check?: boolean): void

- This method removes from this Diagram all of the Parts in a collection. Removing a Node will also remove any Links that are connected with it. Removing a Group will also remove all of its members. Removing a Link will also remove all of its label Nodes, if it has any.

  This does not perform a transaction nor does it raise a DiagramEvent. Call CommandHandler.deleteSelection, which calls this method, if you want to delete all selected Parts. The CommandHandler.deleteSelection command may delete other Parts as well, depending on CommandHandler.deletesTree.

  At this time there is no "addParts" method -- just call Diagram.add on each Part.

  #### Parameters

  - ##### coll: Iterable<Part> | Part[]

    A List or go.Set or Iterator or Array of Parts.

  - ##### `Optional` check: boolean

    Whether to check Part.canDelete on each part; default value is false.

  #### Returns void

### requestUpdate

- requestUpdate(alwaysQueueUpdate?: boolean): void

- Usage of this method is uncommon and may affect performance, for efficiency do not call this method unless you have a well-defined need. Normally, GoJS updates the diagram automatically, and completeing a transaction ensures an immediate update.

  The most common reason to call this method when the HTML Div has changed size but the window has not changed size, and the Diagram needs to be notified of this DOM change. See an example of resizing diagrams here.

  Requests that in the near-future the diagram makes sure all GraphObjects are arranged, recomputes the document bounds, updates the scrollbars, and redraws the viewport.

  #### Parameters

  - ##### `Optional` alwaysQueueUpdate: boolean

    If true the Diagram will queue another update, even if an update is already occurring. The default value is false. Side effects in an "InitialLayoutCompleted" DiagramEvent listener might necessitate setting this parameter.

  #### Returns void

### rollbackTransaction

- rollbackTransaction(): boolean

- Rollback the current transaction, undoing any recorded changes. This just calls UndoManager.rollbackTransaction.

  #### Returns boolean

  the value returned by UndoManager.rollbackTransaction.

### scroll

- scroll(unit: "line" | "pixel" | "page" | "document", dir: "right" | "left" | "up" | "down", dist?: number): void

- Scrolling function used by primarily by commandHandler's CommandHandler.doKeyDown.

  #### Parameters

  - ##### unit: "line" | "pixel" | "page" | "document"

    A string representing the unit of the scroll operation. Can only be 'pixel', 'line', 'page', or 'document'.

  - ##### dir: "right" | "left" | "up" | "down"

    The direction of the scroll operation. Can only be 'up', 'down', 'left', or 'right'.

  - ##### `Optional` dist: number

    An optional distance multiplier, for multiple pixels, lines, or pages. The default value is 1. This argument is ignored when the unit is 'document'.

  #### Returns void

  `see`
  - scrollToRect
  - centerRect

### scrollToRect

- scrollToRect(r: Rect): void

- Modifies the position to show a given Rect of the Diagram by centering the viewport on that Rect. Does nothing if the Rect is already entirely in view.

  See also centerRect

  #### Parameters

  - ##### r: Rect

  #### Returns void

  `see`
  - centerRect
  - scroll
  - CommandHandler.scrollToPart

### select

- select(part: Part): void

- Make the given object the only selected object. Afterwards the selection collection will have only the given part in it.

  This method raises the "ChangingSelection" and "ChangedSelection" DiagramEvents.

  #### Parameters

  - ##### part: Part

    a Part that is already in a layer of this Diagram. If the value is null, this does nothing.

  #### Returns void

  `see`
  - selectCollection
  - clearSelection
  - highlight

### selectCollection

- selectCollection(coll: Iterable<Part> | Part[]): void

- Select all of the Parts supplied in the given collection, and deselect all other Parts.

  This method raises the "ChangingSelection" and "ChangedSelection" DiagramEvents.

  #### Parameters

  - ##### coll: Iterable<Part> | Part[]

    a List or go.Set or Iterator or Array, of Parts to be selected.

  #### Returns void

  `see`
  - select
  - clearSelection
  - highlightCollection

### set

- set(config: Partial<Diagram>): Diagram

- Set any number of properties on this Diagram. This is common in initialization. This method can only be used to set existing properties on this object. To attach new properties, or to set properties of sub-objects such as the Diagram.toolManager, Diagram.animationManager, or Diagram.commandHandler, use Diagram.attach.

  This method uses TypeScript compile-time type checking, but does no runtime type checking.

  #### Parameters

  - ##### config: Partial<Diagram>

  #### Returns Diagram

  this Diagram

  `since`

  2.2

  `see`

  setProperties

### setDivBackground

- setDivBackground(color: string): void

- If this Diagram has a div set, update the div's background color with the given CSS color string.

  #### Parameters

  - ##### color: string

  #### Returns void

  `since`

  3.0

### setProperties

- setProperties(props: ObjectData): Diagram

- This method sets a collection of properties according to the property/value pairs that have been set on the given Object, in the same manner as GraphObject.make does when constructing a Diagram with an argument that is a simple JavaScript Object.

  This method does not use TypeScript compile-time type checking like Diagram.set does, but is considerably more flexible in allowing you to set sub-properties and DiagramEvents by quoted string names.

  You can set properties on an object that is the value of a property of the Diagram, or on the Diagram.toolManager, Diagram.animationManager, or Diagram.commandHandler by using a `"subpropname.property"` syntax for the property name. At the current time only a single dot is permitted in the property "name".

  The property name may also be the name of a DiagramEvent, in which case this calls addDiagramListener with that DiagramEvent name.

      aDiagram.attach({
        allowDelete: false,
        "animationManager.isEnabled": false,  // turn off automatic animations
        // specify a group membership validation predicate
        "commandHandler.memberValidation": (group, part) => return ...,
        "commandHandler.copiesTree": true,  // for the copy command
        // mouse wheel zooms instead of scrolls
        "toolManager.mouseWheelBehavior": go.WheelMode.Zoom,
        "draggingTool.dragsTree": true,  // dragging for both move and copy
        "draggingTool.isGridSnapEnabled": true,
        layout: new go.TreeLayout(),
        // add a DiagramEvent listener
        "ExternalObjectsDropped": e => e.subject.each(part => { ... })
      });

  #### Parameters

  - ##### props: ObjectData

    a plain JavaScript object with various property values to be set on this Diagram or on a part of this Diagram.

  #### Returns Diagram

  this Diagram

  `see`
  - attach a synonym of this method
  - set a type-safe method to set a collection of properties

### startTransaction

- startTransaction(tname?: string): boolean

- Begin a transaction, where the changes are held by a Transaction object in the UndoManager. This just calls UndoManager.startTransaction.

  #### Parameters

  - ##### `Optional` tname: string

    a descriptive name for the transaction.

  #### Returns boolean

  the value returned by UndoManager.startTransaction.

  `see`

  commit

### transformDocToView

- transformDocToView(p: Point): Point

- Given a Point in document coordinates, return a new Point in viewport coordinates.

  #### Parameters

  - ##### p: Point

  #### Returns Point

  The given Point converted into View coordinates.

  `see`
  - transformViewToDoc
  - GraphObject.getDocumentPoint

### transformViewToDoc

- transformViewToDoc(p: Point): Point

- Given a point in viewport coordinates, return a new Point in document coordinates.

  #### Parameters

  - ##### p: Point

  #### Returns Point

  The given point converted into Document coordinates.

  `see`
  - transformDocToView
  - GraphObject.getDocumentPoint

### updateAllRelationshipsFromData

- updateAllRelationshipsFromData(): void

- Add or remove any nodes or links according to additional or missing data objects in the model and update all of the references to nodes, in case they had been modified in the model without properly notifying the model by calling Model.addNodeData or GraphLinksModel.removeLinkData or GraphLinksModel.setGroupKeyForNodeData or GraphLinksModel.setToKeyForLinkData or other similar methods. This method does not conduct a transaction, so you need to start and commit one yourself.

  It is better to call Model.addNodeData, Model.removeNodeData, GraphLinksModel.addLinkData, GraphLinksModel.removeLinkData, Model.setDataProperty, and other model methods to add/remove/modify data, because those methods will both record changes for undo/redo and will update all bindings that make depend on that property. Simply modifying the data and calling an "update..." method will not be able to record the previous value(s) of properties in the model data to support undo.

  This only adds, removes, or updates the relationships between nodes and links, to have them reflect what is now declared in the model data. If you know which model data objects have been modified, it will be more efficient to update only the Parts that need it by calling Part.updateRelationshipsFromData.

  To update GraphObject properties that are data bound, call updateAllTargetBindings.

  #### Returns void

  `see`

  updateAllTargetBindings

### updateAllTargetBindings

- updateAllTargetBindings(srcprop?: string): void

- Update all of the data-bound properties of Nodes and Links in this diagram, without having to call Model.setDataProperty. This copies/converts model data properties to set properties on Parts. This method does not conduct a transaction, so you need to start and commit one yourself.

  It is better to call Model.setDataProperty to modify data properties, because that will both record changes for undo/redo and will update all bindings that make depend on that property. Simply modifying the data and calling an "update..." method will not be able to record the previous value(s) of properties in the model data to support undo.

  If you know which model data objects have been modified, it will be more efficient to update only the Parts that need it by calling Panel.updateTargetBindings.

  To update relationships between nodes, call updateAllRelationshipsFromData.

  #### Parameters

  - ##### `Optional` srcprop: string

    An optional source data property name: when provided, only evaluates those Bindings that use that particular property; when not provided or when it is the empty string, all bindings are evaluated.

  #### Returns void

  `see`

  updateAllRelationshipsFromData

### updateAllThemeBindings

- updateAllThemeBindings(): void

- Update all of the theme-bound properties of Nodes and Links in this diagram.

  This method does not conduct a transaction, so you need to start and commit one yourself. Typically, this transaction should skip the UndoManager.

  #### Returns void

  `since`

  3.0

### zoomToFit

- zoomToFit(): void

- Scales the Diagram to uniformly fit into the viewport. To have this done automatically, set the Diagram's autoScale to AutoScale.Uniform.

  The scale will not be increased past the value of defaultScale, which is normally 1.0, so as to prevent a single node from appearing to fill up the whole viewport.

  To Animate zoomToFit, use CommandHandler.zoomToFit.

  #### Returns void

  `see`

  CommandHandler.zoomToFit

### zoomToRect

- zoomToRect(r: Rect, scaling?: AutoScale): void

- Modifies the scale and position of the Diagram so that the viewport displays a given document-coordinates rectangle.

  #### Parameters

  - ##### r: Rect

    rectangular bounds in document coordinates.

  - ##### `Optional` scaling: AutoScale

    an optional value of either AutoScale.Uniform (the default) or AutoScale.UniformToFill.

  #### Returns void

### `Static` fromDiv

- fromDiv(div: string | Element): Diagram

- This static function gets the Diagram that is attached to an HTML DIV element.

  #### Parameters

  - ##### div: string | Element

  #### Returns Diagram

  null if there is no Diagram associated with the given DIV, or if the argument is not a DIV element nor a string naming such a DIV element in the HTML document.

### `Static` isUsingDOM

- isUsingDOM(): boolean

- This static function returns `true` if GoJS detects a DOM. In browser environments this is expected to be `true`, in Node-like environments, `false`. Specifically, this will be `false` if there is no root `document` in the JavaScript context, or if the DOM was disabled explicitly by calling Diagram.useDOM.

  Incomplete or mock implementations of a DOM may make this return true when it is more appropriate that it returns false. If that is the case, set it to false by calling Diagram.useDOM.

  #### Returns boolean

  `since`

  2.2

### `Static` useDOM

- useDOM(value: boolean): void

- This static function sets whether or not GoJS should use a DOM, if one exists. This can be set to `false` to simulate a DOM-less environment. It is uncommon to set this, but may be required in some testing environments.

  #### Parameters

  - ##### value: boolean

  #### Returns void

  `since`

  2.2

## Properties

### `Static` `Readonly` CycleAll

`deprecated`

See CycleMode.All.

### `Static` `Readonly` CycleDestinationTree

`deprecated`

See CycleMode.DestinationTree.

### `Static` `Readonly` CycleNotDirected

`deprecated`

See CycleMode.NotDirected.

### `Static` `Readonly` CycleNotUndirected

`deprecated`

See CycleMode.NotUndirected.

### `Static` `Readonly` CycleSourceTree

`deprecated`

See CycleMode.SourceTree.

### `Static` `Readonly` DocumentScroll

`deprecated`

See ScrollMode.Document.

### `Static` `Readonly` InfiniteScroll

`deprecated`

See ScrollMode.Infinite.

### `Static` `Readonly` None

`deprecated`

See AutoScale.None.

### `Static` `Readonly` Uniform

`deprecated`

See AutoScale.Uniform.

### `Static` `Readonly` UniformToFill

`deprecated`

See AutoScale.UniformToFill.

Copyright © 1998-2024 by Northwoods Software Corporation.