A sequence diagram is an interaction diagram that shows how entities operate with one another and in what order. In this sample, we show the interaction between different people in a restaurant.

The diagram uses the Diagram.groupTemplate for "lifelines," Diagram.nodeTemplate for "activities," and Diagram.linkTemplate for "messages" between the entities. Also featured are a custom Link class and custom LinkingTool to draw links between lifelines and create activities at the end of the new link. Nodes use a binding function on the location property to ensure they are anchored to their lifeline.

Diagram Model saved in JSON format:
{ "class": "go.GraphLinksModel", "nodeDataArray": [ {"key":"Fred", "text":"Fred: Patron", "isGroup":true, "loc":"0 0", "duration":9}, {"key":"Bob", "text":"Bob: Waiter", "isGroup":true, "loc":"100 0", "duration":9}, {"key":"Hank", "text":"Hank: Cook", "isGroup":true, "loc":"200 0", "duration":9}, {"key":"Renee", "text":"Renee: Cashier", "isGroup":true, "loc":"300 0", "duration":9}, {"group":"Bob", "start":1, "duration":2}, {"group":"Hank", "start":2, "duration":3}, {"group":"Fred", "start":3, "duration":1}, {"group":"Bob", "start":5, "duration":1}, {"group":"Fred", "start":6, "duration":2}, {"group":"Renee", "start":8, "duration":1} ], "linkDataArray": [ {"from":"Fred", "to":"Bob", "text":"order", "time":1}, {"from":"Bob", "to":"Hank", "text":"order food", "time":2}, {"from":"Bob", "to":"Fred", "text":"serve drinks", "time":3}, {"from":"Hank", "to":"Bob", "text":"finish cooking", "time":5}, {"from":"Bob", "to":"Fred", "text":"serve food", "time":6}, {"from":"Fred", "to":"Renee", "text":"pay", "time":8} ]}

### GoJS Features in this sample

#### Links

The Link class is used to implement a visual relationship between nodes. Links are normally created by the presence of link data objects in the GraphLinksModel.linkDataArray or by a parent key reference as the value of the TreeModel.nodeParentKeyProperty of a node data object in a TreeModel. More information can be found in the GoJS Intro.

Related samples

#### Groups

The Group class is used to treat a collection of Nodes and Links as if they were a single Node. Those nodes and links are members of the group; together they constitute a subgraph.

A subgraph is not another Diagram, so there is no separate HTML Div element for the subgraph of a group. All of the Parts that are members of a Group belong to the same Diagram as the Group. There can be links between member nodes and nodes outside of the group as well as links between the group itself and other nodes. There can even be links between member nodes and the containing group itself.

More information can be found in the GoJS Intro.

Related samples

#### Tools

Tools handle all input events, such as mouse and keyboard interactions, in a Diagram. There are many kinds of predefined Tool classes that implement all of the common operations that users do.

For flexibility and simplicity, all input events are canonicalized as InputEvents and redirected by the diagram to go to the Diagram.currentTool. By default the Diagram.currentTool is an instance of ToolManager held as the Diagram.toolManager. The ToolManager implements support for all mode-less tools. The ToolManager is responsible for finding another tool that is ready to run and then making it the new current tool. This causes the new tool to process all of the input events (mouse, keyboard, and touch) until the tool decides that it is finished, at which time the diagram's current tool reverts back to the Diagram.defaultTool, which is normally the ToolManager, again.

More information can be found in the GoJS Intro.

Related samples

#### Grid Patterns

GoJS provides functionality to display a grid of lines drawn at regular intervals. Grid Panels can also force dragged parts to be aligned on grid points, and resize parts to be multiples of the grid cell size.

Grids are implemented using a type of Panel, Panel.Grid. Grid Panels, like most other types of Panels, can be used within Nodes or any other kind of Part. However when they are used as the Diagram.grid, they are effectively infinite in extent.

More information can be found in the GoJS Intro.

Related samples