Class GraphObject

This is the abstract base class for all graphical objects. Classes inheriting from GraphObject include: Shape, TextBlock, Picture, and Panel. From the Panel class the Part class is derived, from which the Node and Link classes derive.

It is very common to make use of the static function GraphObject.make in order to build up a visual tree of GraphObjects. You can see many examples of this throughout the Introduction, starting at Building Objects, and the Samples, starting with Minimal Sample.

Since GraphObject is an abstract class, programmers do not create GraphObjects themselves, but this class defines many properties used by all kinds of GraphObjects.

The only visual properties on GraphObject are background and areaBackground. However one can control whether the GraphObject is drawn at all by setting visible, or by setting opacity to zero if you still want the GraphObject to occupy space. Also, if you want to control whether any mouse or touch events "see" the GraphObject, you can set pickable to false.

For more information about specifying how things get drawn, see the properties on the Shape, TextBlock, and Picture classes.

GraphObject Sizing

GraphObject defines most of the properties that cause objects to size themselves differently. The most prominent ones include:

All GraphObjects in a Diagram are measured and then arranged by their containing Panels in a tree-like fashion. After measuring and arranging, a GraphObject will have valid values for the read-only properties naturalBounds, measuredBounds, and actualBounds.

See the Introduction page on sizing for usage information and examples.

GraphObject Size and Position within Panel

Several GraphObject properties guide the containing Panel for how to size and position the object within the panel.

See the Introduction page on Panels and Table Panels for an overview of the capabilities.

Top-level GraphObjects are Parts

A Part is a derived class of GraphObject representing a top-level object. All top-level GraphObjects must be Parts, and Node, Link, Group, and Adornment derive from Part. The position of a Part determines the point of the Part's top-left corner in document coordinates. See also Part.location, which supports an way to specify the position based on a different spot of a different element within the Part.

There are several read-only properties that help navigate up the visual tree.

See the Visual Tree sample for a diagram displaying the visual tree of a simple diagram.

User Interaction

GraphObjects have several properties enabling dynamic customizable interaction. There are several definable functions that execute on input events: mouseDragEnter, mouseDragLeave, mouseDrop, mouseEnter, mouseHold, mouseHover, mouseLeave, and mouseOver. For example, you could define mouse enter-and-leave event handlers to modify the appearance of a link as the mouse passes over it:

myDiagram.linkTemplate =
  $(go.Link,
    $(go.Shape,
      { strokeWidth: 2, stroke: "gray" },  // default color is "gray"
      { // here E is the InputEvent and OBJ is this Shape
        mouseEnter: function(e, obj) { obj.strokeWidth = 4; obj.stroke = "dodgerblue"; },
        mouseLeave: function(e, obj) { obj.strokeWidth = 2; obj.stroke = "gray"; }
      }));

There are click, doubleClick, and contextClick functions that execute when a user appropriately clicks the GraphObject. These click functions are called with the InputEvent as the first argument and this GraphObject as the second argument. For example, you could define a click event handler on a Node that goes to another page:

myDiagram.nodeTemplate =
  $(go.Node, "Auto",
    $(go.Shape, "RoundedRectangle",
      new go.Binding("fill", "color")),
    $(go.TextBlock,
      { name: "TB", margin: 3 },
      new go.Binding("text", "key")),
    { // second arg will be this GraphObject, which in this case is the Node itself:
      click: function(e, node) {
        window.open("https://en.wikipedia.org/Wiki/" + node.data.key);
      }
    });

Note: you may prefer defining DiagramEvent listeners on the Diagram rather than on individual GraphObjects. DiagramEvents also include more general events that do not necessarily correspond to input events.

The properties actionCancel, actionDown, actionMove, and actionUp define functions to execute when the GraphObject's isActionable property is set to true (default false). See the ActionTool for more detail.

See the Introduction page on Events for a more general discussion.

GraphObjects as Ports

In GoJS, Links can only connect to elements within a Node that are specified as "ports", and by default the only port is the Node itself. Setting the portId of a GraphObject inside a Node allows that object to act as a port. Note: the only kind of model that can save which port a link is connected with, i.e. portIds that are not an empty string, is a GraphLinksModel whose GraphLinksModel.linkFromPortIdProperty and GraphLinksModel.linkToPortIdProperty have been set to name properties on the link data objects.

GraphObjects have several properties that are only relevant when they are acting as ports. These port-related properties are:

See the Introduction page on ports and link connection points for port usage information and examples.

GraphObjects as labels on a Link

GraphObjects can also be used as "labels" on a Link. In addition to the alignmentFocus property, these properties direct a Link Panel to position a "label" at a particular point along the route of the link, in a particular manner:

See the Introduction page on link labels for examples of how to make use of labels on Links.

Interactive Behavior

There are several properties that specify fairly high-level interactive behavior:

For more information, please read the Introduction page about Context Menus and the page about ToolTips.

Also see the Basic sample for examples of how to show context menus and tooltips.

Constructor Summary Details

Name Description
GraphObject()

This is an abstract class, so you should not use this constructor.

Properties Summary Details

Name, Value Type Description
actionCancel
{function(InputEvent, GraphObject) | null}

Gets or sets the function to execute when the ActionTool is cancelled and this GraphObject's isActionable is set to true.More... This property is infrequently set. By default this property is null.

This functional property is only set on objects such as buttons, knobs, or sliders that want to handle all events, in conjunction with ActionTool, pre-empting the normal tool mechanisms.

The ActionTool does not conduct any transaction, so if this property has a value, the function will not be called within a transaction.

actionDown
{function(InputEvent, GraphObject) | null}

Gets or sets the function to execute on a mouse-down event when this GraphObject's isActionable is set to true.More... This property is infrequently set. By default this property is null.

This functional property is only set on objects such as buttons, knobs, or sliders that want to handle all events, in conjunction with ActionTool, pre-empting the normal tool mechanisms.

The ActionTool does not conduct any transaction, so if this property has a value, the function will not be called within a transaction.

actionMove
{function(InputEvent, GraphObject) | null}

Gets or sets the function to execute on a mouse-move event when this GraphObject's isActionable is set to true.More... This property is infrequently set. By default this property is null.

This functional property is only set on objects such as buttons, knobs, or sliders that want to handle all events, in conjunction with ActionTool, pre-empting the normal tool mechanisms.

The ActionTool does not conduct any transaction, so if this property has a value, the function will not be called within a transaction.

actionUp
{function(InputEvent, GraphObject) | null}

Gets or sets the function to execute on a mouse-up event when this GraphObject's isActionable is set to true.More... This property is infrequently set. By default this property is null.

This functional property is only set on objects such as buttons, knobs, or sliders that want to handle all events, in conjunction with ActionTool, pre-empting the normal tool mechanisms.

The ActionTool does not conduct any transaction, so if this property has a value, the function will not be called within a transaction. If you do provide a function that makes changes to the diagram or to its model, you should do so within a transaction -- call Diagram.startTransaction and Diagram.commitTransaction.

actualBounds
{Rect}

This read-only property returns the bounds of this GraphObject in container coordinates.More... This means that the actualBounds are in the coordinate space of the GraphObject's Panel, unless this is a Part, in which case they are in the Diagram's coordinate system.

If the GraphObject is a Part, then the x and y values of the actualBounds are identical to that Part's position, and the width and height values of the actualBounds represent the rectangular space occupied by the Part in Diagram.documentBounds coordinates.

If the GraphObject is not a top-level object (not a Part), then the actualBounds x and y values represent that GraphObject's position within its Panel. In a Panel of type Panel.Position this is identical to the GraphObject's position, but in other cases it is dependent on the unique workings of each Panel type. The actualBounds width and height of a GraphObject are relative to the compounded transformations of its Panel.

It is possible for a GraphObject (be it an GraphObject or a Panel containing several more GraphObjects) to have no containing Part, in which case these GraphObjects cannot possibly be in a Diagram. These GraphObjects are unlikely to have real-number values for their actualBounds, as they may never have had the chance to be measured and arranged.

alignment
{Spot}

Gets or sets the alignment Spot of this GraphObject used in Panel layouts, to determine where in the area allocated by the panel this object should be placed.More...

The default value is Spot.Default, which lets the Panel determine the Spot using Panel.defaultAlignment. If that property is also Spot.Default, then the alignment spot will be different depending on the Panel type.

The alignmentFocus is often used along with this property to specify where this object should be positioned in a Panel.

alignmentFocus
{Spot}

Gets or sets the spot on this GraphObject to be used as the alignment point in Spot and Fixed Panels.More... Value must be of the Spot.

The default value is Spot.Default, which means that the Panel type can decide the effective alignment spot.

The alignment is often used along with this property to specify where this object should be positioned in a Panel.

For Panel.Graduated, the alignmentFocus spot determines the spot on a child element to be aligned with some point along the main element.

When you want a link label Node to be positioned by its location spot rather than by this alignmentFocus spot, you can set this property to Spot.None, only on Nodes.

angle
{number}

Gets or sets the angle transform, in degrees, of this GraphObject.More... Value must be a number. If the value is not between (0 <= value < 360), it will be normalized to be in that range. Zero is along the positive X-axis; 90 is along the positive Y-axis. Default is 0.

See also:
areaBackground
{string|Brush}

Gets or sets the areaBackground Brush of this GraphObject.More... The areaBackground fills the rectangle described by this GraphObject's containing panel's coordinates. If the object is rotated, the area background will expand to fill the entire measured bounds of the object, without rotating the brush.

The value may be either a Brush object or a string that is a CSS color. The default value is null -- no area background is drawn. More information about the syntax of CSS color strings is available at: CSS colors (mozilla.org).

background
{string|Brush}

Gets or sets the background Brush of this GraphObject, filling the rectangle of this object's local coordinate space.More... If the object is rotated, the background will rotate with it.

The value may be either a Brush object or a string that is a CSS color. The default value is null -- no background is drawn. More information about the syntax of CSS color strings is available at: CSS colors (mozilla.org).

click
{function(InputEvent, GraphObject) | null}

Gets or sets the function to execute when the user single-primary-clicks on this object.More... 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 a GraphObject. The function is called in addition to the DiagramEvent that is raised with the name "ObjectSingleClicked".

If this property value is a function, it is called with an InputEvent and this GraphObject. The InputEvent.targetObject provides the GraphObject that was found at the mouse point before looking up the visual tree of GraphObject.panels to get to this object.

From the second argument, obj, you can get to the Node or Link via the part property. From there you can access the bound data via the Panel.data property. So from an event handler you can get the bound data by obj.part.data.

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 Diagram.startTransaction and Diagram.commitTransaction.

An example of a click event handler is shown in the Arrowheads sample.

column
{number}

Gets or sets the column of this GraphObject if it is in a Table Panel.More... The value cannot be negative. The default is 0.

columnSpan
{number}

Gets or sets the number of columns spanned by this GraphObject if it is in a Table Panel.More... The value cannot be negative or zero. The default is 1.

contextClick
{function(InputEvent, GraphObject) | null}

Gets or sets the function to execute when the user single-secondary-clicks on this object.More... 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 a GraphObject. The function is called in addition to the DiagramEvent that is raised with the name "ObjectContextClicked".

If this property value is a function, it is called with an InputEvent and this GraphObject. The InputEvent.targetObject provides the GraphObject that was found at the mouse point before looking up the visual tree of GraphObject.panels to get to this object.

From the second argument, obj, you can get to the Node or Link via the part property. From there you can access the bound data via the Panel.data property. So from an event handler you can get the bound data by obj.part.data.

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 Diagram.startTransaction and Diagram.commitTransaction.

contextMenu

This Adornment or HTMLInfo is shown upon a context click on this object.More... The default value is null, which means no context menu is shown.

Changing this value will not modify or remove any existing menu that is being shown for this object.

Context menus may also depend on having the same data binding as the adorned Part (i.e. the same value for Panel.data).

Context menus are not copied by copy, so that context menus may be shared by all instances of a template.

A typical context menu is implemented as an Adornment with several buttons in it. For example, this context menu is defined in the Dynamic Port sample:

var nodeMenu =  // context menu for each Node
 $(go.Adornment, "Vertical",
    $("ContextMenuButton",
      $(go.TextBlock, "Add top port"),
      { click: function(e, obj) { addPort("top"); } }),
    $("ContextMenuButton",
      $(go.TextBlock, "Add left port"),
      { click: function(e, obj) { addPort("left"); } }),
    $("ContextMenuButton",
      $(go.TextBlock, "Add right port"),
      { click: function(e, obj) { addPort("right"); } }),
    $("ContextMenuButton",
      $(go.TextBlock, "Add bottom port"),
      { click: function(e, obj) { addPort("bottom"); } }));
and is used in the node template:
myDiagram.nodeTemplate =
  $(go.Node, "Table",
    { . . .
      contextMenu: nodeMenu
    },
    . . .);

Context menus are normally positioned by ContextMenuTool.positionContextMenu. However, if there is a Placeholder in the context menu, the context menu (i.e. an Adornment) will be positioned so that the Placeholder is at the same position as this adorned GraphObject.

The Basic sample also shows how to make context menu items invisible when the command is disabled.

Replacing this value will not modify or remove any existing context menu that is being shown for this object.

Read more about context menus at Context Menus.

cursor
{string}

Gets or sets the mouse cursor to use when the mouse is over this object with no mouse buttons pressed.More... The value is null when no particular cursor is specified for this object; the actual cursor is determined by any containing Panel.

The default value is the empty string, which means the current mouse cursor is determined by the Diagram. Other strings should be valid CSS strings that specify a cursor. This provides some more information about cursor syntax: CSS cursors (mozilla.org).

desiredSize
{Size}

Gets or sets the desired size of this GraphObject in local coordinates.More... Value must be of type Size. Default is Size(NaN, NaN). The size does not include any transformation due to scale or angle, nor any pen thickness due to Shape.strokeWidth if this is a Shape. If there is a containing Panel the Panel will determine the actual size. If the desiredSize is greater than the allowed size that the GraphObject's Panel determines, then the GraphObject may be visually clipped.

Getting or setting width or height is equivalent to getting or setting the width or height of this property.

diagram

This read-only property returns the Diagram that this GraphObject is in, if it is.More...

This property is not settable. Although you cannot add any plain GraphObject to a Diagram, you can call Diagram.add to add a Part to a Diagram.

doubleClick
{function(InputEvent, GraphObject) | null}

Gets or sets the function to execute when the user double-primary-clicks on this object.More... 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 a GraphObject. The function is called in addition to the DiagramEvent that is raised with the name "ObjectDoubleClicked".

If this property value is a function, it is called with an InputEvent and this GraphObject. The InputEvent.targetObject provides the GraphObject that was found at the mouse point before looking up the visual tree of GraphObject.panels to get to this object.

From the second argument, obj, you can get to the Node or Link via the part property. From there you can access the bound data via the Panel.data property. So from an event handler you can get the bound data by obj.part.data.

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 Diagram.startTransaction and Diagram.commitTransaction.

The Class Hierarchy sample demonstrates the definition of a double-click event handler that opens up a web page with the documentation for that class:

diagram.nodeTemplate =
  $(go.Node, . . .,
    {
      doubleClick:  // here the second argument is this object, which is this Node
        function(e, node) { window.open("../api/symbols/" + node.data.key + ".html"); }
    },
    . . .
    );
enabledChanged
{function(GraphObject, boolean) | null} 1.7

Gets or sets the function to execute when some containing Panel changes the value of Panel.isEnabled.More... It is typically used to modify the appearance of the object. This function must not change the value of any panel Panel.isEnabled.

If this property value is a function, it is called with two arguments, this GraphObject and the new value. By default this property is null -- no function is called.

fromEndSegmentLength
{number}

Gets or sets the length of the first segment of a link coming from this port.More... This value is used when the computed "from spot" is not Spot.None. The default value is 10. This value also limits how short the Link.fromShortLength may be drawn.

The value of Link.fromEndSegmentLength, if not NaN, takes precedence over the value at this port when determining the route of the link.

For examples of how to use this property, see Link Connection Points.

You must set this property on a GraphObject whose portId is non-null, unless the whole Node is acting as a single port, in which case this property should be set on the Node.

fromLinkable
{boolean|null}

Gets or sets whether the user may draw Links from this port.More... This property is used by LinkingBaseTool.isValidFrom.

The default value is null, which indicates that the real value is inherited from the parent Panel, or false if there is no containing panel.

You must set this property on a GraphObject whose portId is non-null, unless the whole Node is acting as a single port, in which case this property should be set on the Node, or unless you are disabling the "linkability" of a particular GraphObject inside a Panel whose fromLinkable has been set or bound to true.

fromLinkableDuplicates
{boolean}

Gets or sets whether the user may draw duplicate Links from this port.More... This property is used by LinkingBaseTool.isValidLink. The default value is false.

You must set this property on a GraphObject whose portId is non-null, unless the whole Node is acting as a single port, in which case this property should be set on the Node.

fromLinkableSelfNode
{boolean}

Gets or sets whether the user may draw Links that connect from this port's Node.More... This property is used by LinkingBaseTool.isValidLink. The default value is false.

You must set this property on a GraphObject whose portId is non-null, unless the whole Node is acting as a single port, in which case this property should be set on the Node.

fromShortLength
{number}

Gets or sets how far the end segment of a link coming from this port stops short of the actual port.More... Positive values are limited by the fromEndSegmentLength or Link.fromEndSegmentLength. Negative values cause the link to extend into the port. The default value is zero.

This property is useful when you have a thick link and a pointy arrowhead. Normally the link Shape extends all the way to the end of the arrowhead. If the link Shape is wide, its edges will be seen behind the arrowhead. By setting this property to a small positive value, the link Shape can end within the body of the arrowhead, leaving only the point of the arrowhead visible at the end of the link.

A negative value for this property can also be useful when you want the link Shape to continue into the port, perhaps because a portion of the port is transparent and you want the link to appear to connect visually with a different point on the node.

The value of Link.fromShortLength, if not NaN, takes precedence over the value at this port when determining the route of the link.

For examples of how to use this property, see Link Connection Points.

You must set this property on a GraphObject whose portId is non-null, unless the whole Node is acting as a single port, in which case this property should be set on the Node.

fromSpot
{Spot}

Gets or sets where a link should connect from this port.More... The default value is Spot.None, meaning that the link routing must consider the shape of the port and connect at closest point.

The value of Link.fromSpot, if not Spot.Default, takes precedence over the value at this port when determining the route of the link.

For examples of how to use this property, see Link Connection Points.

You must set this property on a GraphObject whose portId is non-null, unless the whole Node is acting as a single port, in which case this property should be set on the Node.

height
{number}

Gets or sets the desired height of this GraphObject in local coordinates.More... This just gets or sets the height component of the desiredSize. Default is NaN. The height does not include any transformation due to scale or angle, nor any pen thickness due to Shape.strokeWidth if this is a Shape. If there is a containing Panel the Panel will determine the actual size.

isActionable
{boolean}

This property determines whether or not this GraphObject's events occur before all other events, including selection.More... This enables the actionDown, actionMove, actionUp, and actionCancel events, which are all handled by the ActionTool.

This object does not get any mouse/touch events if it is not visible or if it is not pickable.

This property is infrequently used -- typically only when implementing objects that act as buttons or knobs or sliders. The default value is false.

isPanelMain
{boolean}

Gets or sets whether a GraphObject is the "main" object for some types of Panel.More... Panels that use a "main" object include Panel.Auto, Panel.Spot, and Panel.Link.

Panels that use a "main" object will use the first object that has this property set to true, or else just the first object, if none have the property set.

layer
{Layer}

This read-only property returns the GraphObject's containing Layer, if there is any.More... A plain GraphObject cannot belong directly to a Layer -- only a Part can belong directly to a Layer.

This property is not settable. Normally one changes which Layer that a GraphObject is in by setting Part.layerName. Adding a Part to a Diagram will automatically add that Part to a Layer in that Diagram based on the layerName.

margin
{Margin|number}

Gets or sets the size of empty area around this GraphObject, as a Margin, in the containing Panel coordinates.More...

Negative values are permitted but may cause overlaps with adjacent objects in a Panel. Default margin is Margin(0,0,0,0).

The property setter accepts a number instead of a Margin object: providing a number N will result in using a Margin(N, N, N, N). The property getter will always return a Margin.

maxSize
{Size}

Gets or sets the maximum size of this GraphObject in container coordinates (either a Panel or the document).More... Any new value must be of type Size; the width and height must not be NaN. The default value is Infinity by Infinity. A containing Panel will determine the actual size of this object.

See also:
measuredBounds
{Rect}

This read-only property returns the measuredBounds of the GraphObject in container coordinates (either a Panel or the document).More... This describes the transformed bounds with margins excluded. Default is null.

minSize
{Size}

Gets or sets the minimum size of this GraphObject in container coordinates (either a Panel or the document).More... Any new value must be of type Size; the width and height must not be NaN. The default value is zero by zero. A containing Panel will determine the actual size of this object.

See also:
mouseDragEnter
{function(InputEvent, GraphObject, GraphObject) | null}

Gets or sets the function to execute when the user moves the mouse into this stationary object during a DraggingTool drag; this allows you to provide feedback during a drag based on where it might drop.More...

If this property value is a function, it is called with an InputEvent, this GraphObject, and any previous GraphObject. The InputEvent.targetObject provides the GraphObject that was found at the mouse point before looking up the visual tree of GraphObject.panels to get to this object. 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, because the DraggingTool will be conducting one already. After calling this function the diagram will be updated immediately.

For an example of a mouseDragEnter event handler, see the node template in the Org Chart Editor sample.

mouseDragLeave
{function(InputEvent, GraphObject, GraphObject) | null}

Gets or sets the function to execute when the user moves the mouse out of this stationary object during a DraggingTool drag; this allows you to provide feedback during a drag based on where it might drop.More...

If this property value is a function, it is called with an InputEvent, this GraphObject, and any new GraphObject that the mouse is in. The InputEvent.targetObject provides the GraphObject that was found at the mouse point before looking up the visual tree of GraphObject.panels to get to this object. 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, because the DraggingTool will be conducting one already. After calling this function the diagram will be updated immediately.

For an example of a mouseDragLeave event handler, see the node template in the Org Chart Editor sample.

mouseDrop
{function(InputEvent, GraphObject) | null}

Gets or sets the function to execute when a user drops the selection on this object at the end of a DraggingTool drag; this allows you to customize the behavior when a drop occurs on an object.More...

If this property value is a function, it is called with an InputEvent, this GraphObject. The InputEvent.targetObject provides the GraphObject that was found at the mouse point before looking up the visual tree of GraphObject.panels to get to this object. The function is called within the transaction performed by the DraggingTool, so you do not need to conduct one. By default this property is null.

For an example of a mouseDrop event handler, see the node template in the Org Chart Editor sample.

mouseEnter
{function(InputEvent, GraphObject, GraphObject) | null}

Gets or sets the function to execute when the user moves the mouse into this object without holding down any buttons.More... This property is used by the ToolManager.

If this property value is a function, it is called with an InputEvent, this GraphObject that the mouse is now in, and any previous GraphObject that the mouse was in. The InputEvent.targetObject provides the GraphObject that was found at the mouse point before looking up the visual tree of GraphObject.panels to get to this object. 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.

For example, consider the situation where one wants to display buttons that the user can click whenever the user passes the mouse over a node, and the buttons automatically disappear when the mouse leaves the node. This can be implemented by showing an Adornment holding the buttons.

var nodeContextMenu =
  $(go.Adornment, "Spot",
    { background: "transparent" },  // to help detect when the mouse leaves the area
    $(go.Placeholder),
    $(go.Panel, "Vertical",
      { alignment: go.Spot.Right, alignmentFocus: go.Spot.Left },
      $("Button",
        $(go.TextBlock, "Command 1"),
        {
          click: function(e, obj) {
            var node = obj.part.adornedPart;
            alert("Command 1 on " + node.data.text);
            node.removeAdornment("ContextMenuOver");
          }
        }),
      $("Button",
        $(go.TextBlock, "Command 2"),
        {
          click: function(e, obj) {
            var node = obj.part.adornedPart;
            alert("Command 2 on " + node.data.text);
            node.removeAdornment("ContextMenuOver");
          }
        })
      ));
Then in the definition of the Node we can implement a mouseEnter event handler:
myDiagram.nodeTemplate =
  $(go.Node,
    . . .
    {
      mouseEnter: function(e, node) {
        nodeContextMenu.adornedObject = node;
        nodeContextMenu.mouseLeave = function(ev, cm) {
          node.removeAdornment("ContextMenuOver");
        };
        node.addAdornment("ContextMenuOver", nodeContextMenu);
      }
    });
Note how it automatically defines a mouseLeave event handler too. The context menu Adornment is removed either when the mouse leaves the area of the Adornment or when the user executes a button click event handler.
mouseHold
{function(InputEvent, GraphObject) | null}

Gets or sets the function to execute when the user holds the mouse still for a while over this object while holding down a button.More... 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 Diagram.startTransaction and Diagram.commitTransaction.

You can control how long the user must wait during a drag with a motionless mouse before a "mouse hold" event occurs, by setting ToolManager.holdDelay. For example:

myDiagram =
  $(go.Diagram, "myDiagramDiv",
    { "toolManager.holdDelay": 500 });  // 500 milliseconds
or:
myDiagram.toolManager.holdDelay = 500;  // 500 milliseconds
mouseHover
{function(InputEvent, GraphObject) | null}

Gets or sets the function to execute when the user holds the mouse still for a while over this object without holding down any buttons.More... 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 Diagram.startTransaction and Diagram.commitTransaction.

You can control how long the user must wait with a motionless mouse before a "mouse hover" event occurs, by setting ToolManager.hoverDelay. For example:

myDiagram =
  $(go.Diagram, "myDiagramDiv",
    { "toolManager.hoverDelay": 500 });  // 500 milliseconds
or:
myDiagram.toolManager.hoverDelay = 500;  // 500 milliseconds
mouseLeave
{function(InputEvent, GraphObject, GraphObject) | null}

Gets or sets the function to execute when the user moves the mouse into this object without holding down any buttons.More... This property is used by the ToolManager.

If this property value is a function, it is called with an InputEvent, this GraphObject that the mouse has left, and any next GraphObject that the mouse is now in. The InputEvent.targetObject provides the GraphObject that was found at the mouse point before looking up the visual tree of GraphObject.panels to get to this object. 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.

For example, the Flow Chart sample automatically shows and hides the ports as the mouse passes over a node. The node template includes the following settings:

myDiagram.nodeTemplate =
  $(go.Node,
    . . .
    {
      . . .
      // handle mouse enter/leave events to show/hide the ports
      mouseEnter: function(e, obj) { showPorts(obj.part, true); },
      mouseLeave: function(e, obj) { showPorts(obj.part, false); }
      . . .
    });
where the showPorts function is defined to set the visible property of each of the port elements of the node.
mouseOver
{function(InputEvent, GraphObject) | null}

Gets or sets the function to execute when the user moves the mouse over this object without holding down any buttons.More... This property is used by the ToolManager. This property is infrequently used -- it is more common to implement mouseEnter and mouseLeave functions.

If this property value is a function, it is called with an InputEvent and this GraphObject. The InputEvent.targetObject provides the GraphObject that was found at the mouse point before looking up the visual tree of GraphObject.panels to get to this object. 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.

name
{string}

Gets or sets the name for this object.More... The default value is the empty string. The name should be unique within a Panel, although if it isn't, it reduces the usefulness of methods such as Panel.findObject.

You must not modify the name of a GraphObject once it is in the visual tree of a Part.

This is frequently needed to identify a particular GraphObject in the visual tree of a Part, for example as the value of the Part.locationObjectName or Part.selectionObjectName properties.

naturalBounds
{Rect}

This read-only property returns the natural bounding rectangle of this GraphObject in local coordinates, before any transformation by scale or angle, and before any resizing due to minSize or maxSize or stretch.More... Defaults to unknown (NaN,NaN). Can only be changed by changing properties of the particular GraphObject, such as GraphObject.desiredSize, Shape.geometry, or TextBlock.font.

opacity
{number} 1.4

Gets or sets the multiplicative opacity for this GraphObject and (if a Panel) all elements.More... The value must be between 0.0 (fully transparent) and 1.0 (no additional transparency).

Unlike visible, Opacity only affects drawing, it does not cause objects to be resized or remeasured. Opacity settings do not change the shape of the object or exclude it from object-picking (does not change whether any objects are found by the "find..." methods).

This value is multiplicative with any existing transparency, for instance from Layer.opacity or a GraphObject's opacity higher in the visual tree, or from a Brush or image transparency. The default value is 1.

See also:
panel
{Panel}

This read-only property returns the GraphObject's containing Panel, or null if this object is not in a Panel.More...

Although Part inherits from this class, a Part will never belong to a Panel, so this property will always be null for every Node or Link.

This property is not settable. Instead, call Panel.add in order to put a GraphObject in a Panel.

part
{Part}

This read-only property returns the Part containing this object, if any.More... The Part will be the root GraphObject in this GraphObject's visual tree.

It is common to refer to the containing Part of a GraphObject in order to refer to the Panel.data to which it is bound.

This property is not settable. If you want this GraphObject to belong to a Part, you will need to add it to a Part, or else add it to some visual tree structure that is added to a Part using Panel.add.

Note that for objects such as buttons that are in Adornments such as tooltips or context menus, this property will return that Adornment, not the Node or Link that is adorned.

If you want to find a Group that contains a Part, use the Part.containingGroup property: someObj.part.containingGroup

pickable
{boolean} 1.2

Gets or sets whether or not this GraphObject can be chosen by visual "find" or "hit-test" methods such as Diagram.findObjectAt.More...

This object does not get any mouse/touch events if it is not visible or if it is not pickable.

The default value is true -- mouse events on this object will be noticed. If this value is false and this object is a Panel, not only is this Panel not "hittable", but all of the elements inside the Panel will be ignored.

portId
{string}

Gets or sets an identifier for an object acting as a port on a Node.More... The default value is null -- this object is not a port.

A value that is the empty string is used by convention to mean the primary (and usually only) port of the node.

If a Node has no named ports, then the Node itself is the sole port.

Note: the only kind of model that can save port information, i.e. portIds that are not an empty string, for links is a GraphLinksModel whose GraphLinksModel.linkFromPortIdProperty and GraphLinksModel.linkToPortIdProperty have been set to name properties on the link data objects.

The value should be unique within the Node. You must not modify this property once this GraphObject is in the visual tree of a Node.

See the Introduction page on ports for usage information and examples.

position
{Point}

Gets or sets the position of this GraphObject in container coordinates (either a Panel or the document).More... Value must be of type Point. Default is Point(NaN, NaN).

For Parts, see also Part.location.

row
{number}

Gets or sets the row of this GraphObject if it is in a Table Panel.More... The value cannot be negative. The default is 0.

rowSpan
{number}

Gets or sets the number of rows spanned by this GraphObject if it is in a Table Panel.More... The value cannot be negative or zero. The default is 1.

scale
{number}

Gets or sets the scale transform of this GraphObject.More... Value must be a number; larger values will make this object appear bigger. Default is 1.

See also:
segmentFraction
{number}

Gets or sets the fractional distance along a segment of a GraphObject that is in a Link.More... The value should be between zero and one, where zero is at the point at the start of the segment, and where one is at the point at the end of the segment. The default value is zero.

For examples of how to use this property, see Link Labels.

segmentIndex
{number}

Gets or sets the segment index of a GraphObject that is in a Link.More... Non-negative numbers count up from zero, which is the first segment, at the "from" end of the Link. Negative numbers count segments from the "to" end of the Link, where -1 means the last segment and -2 means the next-to-last segment. The value should be an integer.

If you do not set this property, the Link will choose a place that is approximately at the mid-point of the link's route.

For examples of how to use this property, see Link Labels.

segmentOffset
{Point}

Gets or sets the offset of a GraphObject that is in a Link from a point on a segment or in a Panel.Graduated from a point along the main element.More... The X component of the Point indicates the distance along the route, with positive values going further toward the "to" end of the link or panel. The Y component of the Point indicates the distance away from the route, with positive values towards the right as seen when facing further towards the "to" end of the link or panel. The value defaults to the Point (0, 0).

For labels that are near either end of a link, it may be convenient to set the segmentOffset to Point(NaN, NaN). This causes the offset to be half the width and half the height of the label object.

For examples of how to use this property, see Link Labels.

segmentOrientation
{EnumValue}

Gets or sets the orientation of a GraphObject that is in a Link or Panel.Graduated.More... This controls the automatic rotation of the object by the Link Panel or Graduated Panel. The only accepted values are the Link "Orient..." values of Link and the default value: Link.None.

When the value is Link.None, the angle of this object is unchanged as the link is routed. Setting this to a value of Link.OrientAlong will cause routing to set the angle to be the angle of the segment that this object is on. Other values compute the angle somewhat differently. If the value is changed back to Link.None, the angle of this object is set to zero.

Note that when this property is not Link.None, this property takes precedence over any setting or binding of the angle property. Changes to the angle caused by orientation might not result in Changed events, and any original value for the angle may be lost.

For examples of how to use this property, see Link Labels.

shadowVisible
{boolean|null} 1.6

Gets or sets whether or not this GraphObject will be shadowed inside a Part that has Part.isShadowed set to true.More...

The default is null, which means this GraphObject will obey the default shadow rules (see Part.isShadowed).

A value of true or false will ensure that this part is shadowed or not regardless of the default shadow rules, but this GraphObject's shadowed status will not affect other GraphObjects in the Part.

Typically this property does not need to be set, but you may need to set this value to false on GraphObjects inside a Part that you do not wish to be shadowed.

See also:
stretch
{EnumValue}

Gets or sets the stretch of the GraphObject.More... This controls whether the width and/or height of this object automatically adjusts to fill the area allotted by the containing Panel.

The only accepted values are listed as constant properties of GraphObject, such as GraphObject.None, GraphObject.Fill, GraphObject.Horizontal, or GraphObject.Vertical. The default value is GraphObject.Default, which allows the Panel to decide how to treat this object, depending on the type of Panel.

Objects with an angle that are stretched may look incorrect unless the angle is a multiple of 90.

toEndSegmentLength
{number}

Gets or sets the length of the last segment of a link going to this port.More... This value is used when the computed "to spot" is not Spot.None. The default value is 10.

The value of Link.toEndSegmentLength, if not NaN, takes precedence over the value at this port when determining the route of the link. This value also limits how short the Link.toShortLength may be drawn.

For examples of how to use this property, see Link Connection Points.

You must set this property on a GraphObject whose portId is non-null, unless the whole Node is acting as a single port, in which case this property should be set on the Node.

toLinkable
{boolean|null}

Gets or sets whether the user may draw Links to this port.More... This property is used by LinkingBaseTool.isValidTo.

The default value is null, which indicates that the real value is inherited from the parent Panel, or false if there is no containing panel.

You must set this property on a GraphObject whose portId is non-null, unless the whole Node is acting as a single port, in which case this property should be set on the Node, or unless you are disabling the "linkability" of a particular GraphObject inside a Panel whose toLinkable has been set or bound to true.

toLinkableDuplicates
{boolean}

Gets or sets whether the user may draw duplicate Links to this port.More... This property is used by LinkingBaseTool.isValidLink. The default value is false.

You must set this property on a GraphObject whose portId is non-null, unless the whole Node is acting as a single port, in which case this property should be set on the Node.

toLinkableSelfNode
{boolean}

Gets or sets whether the user may draw Links that connect to this port's Node.More... This property is used by LinkingBaseTool.isValidLink. The default value is false.

You must set this property on a GraphObject whose portId is non-null, unless the whole Node is acting as a single port, in which case this property should be set on the Node.

toolTip

This Adornment or HTMLInfo is shown when the mouse hovers over this object.More... The default value is null, which means no tooltip is shown.

A typical tooltip is defined in the following manner, as taken from the Kitten Monitor sample:

myDiagram.nodeTemplate =
  $(go.Node,
    . . .
    { // this tooltip shows the name and picture of the kitten
      toolTip:
        $(go.Adornment, "Auto",
          $(go.Shape, { fill: "lightyellow" }),
          $(go.Panel, "Vertical",
            $(go.Picture,
              new go.Binding("source", "src", function(s) { return "images/" + s + ".png"; })),
            $(go.TextBlock, { margin: 3 },
              new go.Binding("text", "key"))))
    });
Note that this Adornment depends on having the same data binding as the adorned Part (i.e. the same value for Panel.data).

Tooltips are not copied by copy, so that tooltips may be shared by all instances of a template.

Tooltips are shown after a timed delay given by the ToolManager.hoverDelay. You can change the delay time by:

myDiagram =
  $(go.Diagram, "myDiagramDiv",
    { "toolManager.hoverDelay": 500 });  // 500 milliseconds
or:
myDiagram.toolManager.hoverDelay = 500;  // 500 milliseconds

Tooltips are normally positioned by ToolManager.positionToolTip. However, if there is a Placeholder in the tooltip, the tooltip (i.e. an Adornment) will be positioned so that the Placeholder is at the same position as this adorned GraphObject.

Replacing this value will not modify or remove any existing tooltip that is being shown for this object.

Read more about tooltips at ToolTips.

toShortLength
{number}

Gets or sets how far the end segment of a link going to this port stops short of the actual port.More... Positive values are limited by the toEndSegmentLength or Link.toEndSegmentLength. Negative values cause the link to extend into the port. The default value is zero.

This property is useful when you have a thick link and a pointy arrowhead. Normally the link Shape extends all the way to the end of the arrowhead. If the link Shape is wide, its edges will be seen behind the arrowhead. By setting this property to a small positive value, the link Shape can end within the body of the arrowhead, leaving only the point of the arrowhead visible at the end of the link.

A negative value for this property can also be useful when you want the link Shape to continue into the port, perhaps because a portion of the port is transparent and you want the link to appear to connect visually with a different point on the node.

The value of Link.toShortLength, if not NaN, takes precedence over the value at this port when determining the route of the link.

For examples of how to use this property, see Link Connection Points.

You must set this property on a GraphObject whose portId is non-null, unless the whole Node is acting as a single port, in which case this property should be set on the Node.

toSpot
{Spot}

Gets or sets where a link should connect to this port.More... The default value is Spot.None, meaning that the link routing must consider the shape of the port and connect to closest point.

The value of Link.toSpot, if not Spot.Default, takes precedence over the value at this port when determining the route of the link.

For examples of how to use this property, see Link Connection Points.

You must set this property on a GraphObject whose portId is non-null, unless the whole Node is acting as a single port, in which case this property should be set on the Node.

visible
{boolean}

Gets or sets whether a GraphObject is visible.More... The default value is true. A not visible object takes no space in the Panel that it is in. Toggling visibility may cause elements in the visual tree to re-measure and re-arrange. Making a Panel not visible causes all of its elements not to be seen or receive input events. Changing a Panel to become visible causes all of its elements to be seen and be active, unless those elements are themselves not visible.

This object does not get any mouse/touch events if it is not visible or if it is not pickable.

One can have a visible Shape that is not drawn by setting its Shape.fill and Shape.stroke to null or to "transparent". Similarly, one can set TextBlock.stroke to null or to "transparent". It is also possible make a GraphObjects transparent by setting GraphObject.opacity to 0. Finally, one can make a whole Layer-full of Parts invisible by setting Layer.visible to false.

Use the isVisibleObject predicate to see if this GraphObject is visible and is inside a Panel that is isVisibleObject, and so forth up the chain of panels until reaching the Part.

For Parts, you can call the Part.isVisible predicate to determine if not only the Part is visible but also any containing Group or Link, and whether the Layer it is in is visible.

See also:
width
{number}

Gets or sets the desired width of this GraphObject in local coordinates.More... This just gets or sets the width component of the desiredSize. Default is NaN. The width does not include any transformation due to scale or angle, nor any pen thickness due to Shape.strokeWidth if this is a Shape. If there is a containing Panel the Panel will determine the actual size.

Method Summary Details

Name, Return Type Description
bind(binding)

Add a data-binding of a property on this GraphObject to a property on a data object.More...

Parameters:
{Binding} binding
copy()

Creates a deep copy of this GraphObject and returns it.More... This method is the same as a clone for simple GraphObjects such as Shape, TextBlock, and Picture. For Panel this method copies the visual tree of GraphObjects that it contains.

Returns:
{GraphObject}
<static>
GraphObject.defineBuilder(name, func)
1.5

This static function defines a named function that GraphObject.make can use to build objects.More... Once this is called one can use the name as the first argument for GraphObject.make. Names are case sensitive.

The second argument must be a function that returns a newly created object, typically a GraphObject. It is commonplace for that object to be a Panel holding a newly created visual tree of GraphObjects. The function receives as its only argument an Array that is holds all of the arguments that are being passed to GraphObject.make, which it may modify in order to change the arguments that GraphObject.make receives.

Predefined builder names include: "Button", "TreeExpanderButton", "SubGraphExpanderButton", "PanelExpanderButton", and "ContextMenuButton". The implementation of these builders is provided by Buttons.js in the Extensions directory.

Parameters:
{string} name
a capitalized name; must not be "" or "None"
{function(Array.<*>):Object} func
that takes an Array of GraphObject.make arguments and returns a new object
getDocumentAngle()
{number}

Returns the effective angle that the object is drawn at, in document coordinates, normalized to between 0 and 360.More...

Basically this adds together all of the rotation declared by this angle and the angles of all of its containing Panels, including the Part.

Returns:
{number}
getDocumentPoint(local, result)
{Point}

Returns the Point in document coordinates for a given Spot in this object's bounds or for a Point in local coordinates.More...

For example, for an instance of a Node like this:

myDiagram.nodeTemplate =
  $(go.Node, "Auto",
    $(go.Shape, "RoundedRectangle",
      new go.Binding("fill", "color")),
    $(go.TextBlock,
      { name: "TB", margin: 3 },
      new go.Binding("text", "key")));
where the Node is positioned at 100, 200,
  node.findObject("TB").getDocumentPoint(go.Spot.Center)
could return a Point that is approximately at 122, 213.
Parameters:
{Spot|Point} local
a real Spot describing a relative location in or near this GraphObject, or a real Point in local coordinates.
{Point=} result
an optional Point that is modified and returned.
Returns:
{Point} in document coordinates.
getDocumentScale()
{number}

Returns the total scale that the object is drawn at, in document coordinates.More...

Basically this multiplies together this scale with the scales of all of its containing Panels, including the Part.

Returns:
{number}
getLocalPoint(p, result)
{Point}

Given a Point in document coordinates, returns a new Point in local coordinates.More...

For example, if you have a mouse event whose InputEvent.documentPoint is at 122, 213, and if you have a Node whose position is at 100, 200, node.getLocalPoint(e.documentPoint) could return a Point that is at 22, 13. For a GraphObject within the Node named "TB",

  node.findObject("TB").getLocalPoint(e.documentPoint)
could return a Point that is at 15.7, 6.7, if that "TB" object is positioned somewhat inside the bounds of the Node.
Parameters:
{Point} p
a real Point in document coordinates.
{Point=} result
an optional Point that is modified and returned.
Returns:
{Point} The corresponding Point in local coordinates.
isContainedBy(panel)
{boolean}

This predicate is true if this object is an element, perhaps indirectly, of the given panel.More...

For example, if this GraphObject is inside a Part but is not itself the Part, obj.isContainedBy(obj.part) should be true.

Parameters:
{GraphObject} panel
Returns:
{boolean} true if this object is contained by the given panel, or if it is contained by another panel that is contained by the given panel, to any depth; false if the argument is null or is not a Panel.
isEnabledObject()
{boolean} 1.7

This predicate is false if this object is inside any Panel that is not Panel.isEnabled, or if this is itself a disabled panel.More... This ignores the visible and pickable properties.

Returns:
{boolean}
isVisibleObject()
{boolean}

This predicate is true if this object is visible and each of its visual containing panels are also visible.More... This ignores the actual location or appearance (except visibility) of the panel that this object is part of, as well as ignoring all properties of the Layer or Diagram.

For Parts, you can call the Part.isVisible predicate to determine if not only the Part is visible but also any containing Group or Link.

Returns:
{boolean}
<static>
GraphObject.make(type, initializers)
{Object}

This static function builds an object given its class and additional arguments providing initial properties or GraphObjects that become Panel elements.More...

The first argument must be the class type or the name of a class or the name of a predefined kind of Panel. This function will construct a new instance of that type and use the rest of the arguments to initialize the object. The first argument cannot be a regular Object (such as a GraphObject) that you are trying to initialize; for that you can call setProperties or Diagram.setProperties, although that would be less efficient than setting properties directly.

If an initializer argument is an enumerated value, this tries to set the property that seems most appropriate.

If an initializer argument is a string, this sets a particular property depending on the type of object being built.

If an initializer argument is a particular kind of object, this can add that object to the object being built.

When the initializer argument is a plain JavaScript Object, there are several ways that that object's properties are applied. If the property name is a string with a period inside it, this has a special meaning if the object is a Panel or a Diagram. At the current time only a single period separator is valid syntax for a property string, and it is valid only on Panels and Diagrams.

For Panels, the substring before the period is used as the name passed to Panel.findObject to get the actual object on which to set the property, which is the substring after the period. This is normally useful only on the predefined Panels:

  • a "Button" has a Shape named "ButtonBorder" surrounding the content of the Panel.
  • a "TreeExpanderButton" has a "ButtonBorder" Shape and a "ButtonIcon" Shape that is the plus-or-minus sign.
  • a "SubGraphExpanderButton" has a "ButtonBorder" Shape and a "ButtonIcon" Shape that is the plus-or-minus sign.
  • a "ContextMenuButton" has a Shape named "ButtonBorder" surrounding the content of the Panel.
But you can define your own names that GraphObject.make can build by calling the static function GraphObject.defineBuilder.

For Diagrams, the substring before the period is used as the name of a property on the Diagram itself to get the actual object on which to set the property. As a special case, if such a property value does not exist on the Diagram, it looks on the Diagram.toolManager. See some examples below.

Also for Diagrams, and only for Diagrams, if the property name is the name of a DiagramEvent, the property value must be a DiagramEvent listener function, and Diagram.addDiagramListener is called using that DiagramEvent name and that function. Note that all DiagramEvent names are capitalized and do not contain any periods, so there cannot be any name conflicts with any properties on Diagram or ToolManager. Although you can register multiple listeners for the same DiagramEvent names, due to JavaScript limitations those need to be declared using separate JavaScript objects, because JavaScript does not permit duplicate property names in an Object literal.

Furthermore for Diagrams, if the property name is "Changed" or "ModelChanged", the property value must be a ChangedEvent listener function, which is called with a ChangedEvent argument. When the property name is "Changed", it calls Diagram.addChangedListener, notifying about changes to the Diagram or its Layers or GraphObjects. When the property name is "ModelChanged", it calls Model.addChangedListener on the Diagram.model, resulting in notifications about changes to the Model or its data. This is handy because the Diagram.model property setter will automatically call Model.removeChangedListener on the old model, thereby avoiding any overhead if there are any more changes to the old model and also avoiding a reference to the listener which might cause garbage collection retention. It also will call Model.addChangedListener on the new model, helping implement the same behavior with the new model.

If the property name is a number and if the object being constructed is a Brush, the number and value are added to the Brush by calling Brush.addColorStop.

Otherwise the property name is used as a regular property name on the object being built. This tries to do some property name and value checking: when a property is not defined on the object being built, it will signal an error. Many typos can be found this way that would be ignored by JavaScript code.

If the property name begins with an underscore, this will not complain about the property being undefined. Not only is that underscore property set on the object being built, but calls to copy will also copy the values of such named properties to the new objects.

In the samples and in the intro pages this function is called using the alias $. You can use a different short name if you would like to preserve the use of $ for another JavaScript library.

 var $ = go.GraphObject.make;

 var diagram =
   $(go.Diagram, "myDiagramDiv",
     {
       initialContentAlignment: go.Spot.Center,
        // don't initialize some properties until after a new model has been loaded
        "InitialLayoutCompleted": loadDiagramProperties,
       allowZoom: false,  // don't allow the user to change the diagram's scale
       "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" },
       "toolManager.hoverDelay": 100,  // how quickly tooltips are shown
       // mouse wheel zooms instead of scrolls
       "toolManager.mouseWheelBehavior": go.ToolManager.WheelZoom,
       "commandHandler.copiesTree": true,  // for the copy command
       "commandHandler.deletesTree": true, // for the delete command
       "draggingTool.dragsTree": true,  // dragging for both move and copy
       "draggingTool.isGridSnapEnabled": true,
       layout: $(go.TreeLayout,
                 { angle: 90, sorting: go.TreeLayout.SortingAscending })
     });

 diagram.nodeTemplate =
   $(go.Node, "Auto",  // or go.Panel.Auto
     new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
     $(go.Shape, "RoundedRectangle",
       {
         fill: $(go.Brush, "Linear", { 0: "#FEC901", 1: "#FEA200" }),
         stroke: "gray",
         strokeWidth: 2,
         strokeDashArray: [3, 3]
       }),
     $(go.TextBlock,
       { margin: 5, font: "bold 12pt sans-serif" },
       new go.Binding("text", "key"))
   );

See the Introduction page on building objects for usage information and examples of GraphObject.make.

Parameters:
{Function|string} type
a class function or the name of a class in the go namespace, or one of several predefined kinds of Panels: "Button", "TreeExpanderButton", "SubGraphExpanderButton", or "ContextMenuButton".
{...*} initializers
zero or more values that initialize the new object, typically an Object with properties whose values are set on the new object, or a JavaScript Array with additional initializer arguments, or a GraphObject that is added to a Panel, or a Binding for one of the new object's properties, or an EnumValue as the initial value of a single property of the new object that is recognized to take that value, or a string that is used as the value of a commonly set property.
Returns:
{Object}
setProperties(props)
1.5

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 GraphObject with an argument that is a simple JavaScript Object.More...

If this is a Panel, you can set properties on named elements within the panel by using a name.property syntax for the property name. For example, if a Node has a Picture that is named "ICON" (because its name property has been set to "ICON") and a TextBlock whose name is "TB", one could set properties on the Node and on each of those named elements by:

aNode.setProperties({
    background: "red",
    "ICON.source": "https://www.example.com/images/alert.jpg",
    "TB.font": "bold 12pt sans-serif"
});

At the current time only a single dot is permitted in the property "name". Note that the use of all-upper-case object names is simply a convention.

Calling this method is much less efficient than setting properties directly.

Parameters:
{Object} props
a plain JavaScript object with various property values to be set on this GraphObject.
<static>
GraphObject.takeBuilderArgument(args, defval, pred)
{*} 1.5

This static function returns the first argument from the arguments array passed to a GraphObject.defineBuilder function by GraphObject.make.More... By default this requires the first argument to be a string, but you can provide a predicate to determine whether the argument is suitable.

Parameters:
{Array.<*>} args
the arguments Array passed to the builder function; this may be modified if an acceptable argument is found and returned
{*=} defval
the default value to return if the argument is optional and not present as the first argument; otherwise throw an error when the argument is not there
{function(*):boolean|null=} pred
a predicate to determine the acceptability of the argument; the default predicate checks whether the argument is a string
Returns:
{*}

Constants Summary Details

Name Description
Default {EnumValue}

GraphObjects with this enumeration as the value of GraphObject.stretch are stretched depending on the context they are used.More... For instance a 'Circle' figure might be uniformly stretched whereas an 'Ellipse' figure might be non-uniformly stretched.

Fill {EnumValue}

GraphObjects with this enumeration as the value of GraphObject.stretch are scaled in both directions so as to fit exactly in the given bounds; there is no clipping but the aspect ratio may change, causing the object to appear stretched.

Horizontal {EnumValue}

GraphObjects with this enumeration as the value of GraphObject.stretch are scaled as much as possible in the x-axis.

None {EnumValue}

GraphObjects with this enumeration as the value of GraphObject.stretch are not automatically scaled to fit in the given bounds; there may be clipping in one or both directions if the available dimensions are too small.

Uniform {EnumValue}

Pictures with this enumeration as the value of Picture.imageStretch are drawn with equal scale in both directions to fit the arranged (actual) bounds; Panels of type Viewbox with this as the value of Panel.viewboxStretch are scaled equally in both directions to fit in the given bounds.

UniformToFill {EnumValue}

Pictures with this enumeration as the value of Picture.imageStretch are drawn with equal scale in both directions to fit the larger side of the image bounds; Panels of type Viewbox with this as the value of Panel.viewboxStretch are scaled equally in both directions to fit the larger side of the element's bounds.More... there may be clipping in one dimension.

Vertical {EnumValue}

GraphObjects with this enumeration as the value of GraphObject.stretch are scaled as much as possible in the y-axis.