See the Ports Intro page for an explanation of GoJS ports.

Diagram Model saved in JSON format:
{ "class": "GraphLinksModel", "copiesArrays": true, "copiesArrayObjects": true, "linkFromPortIdProperty": "fromPort", "linkToPortIdProperty": "toPort", "nodeDataArray": [ {"key":1,"name":"Unit One","loc":"101 204","leftArray":[{"portColor":0,"portId":"left0"}],"topArray":[{"portColor":1,"portId":"top0"}],"bottomArray":[{"portColor":2,"portId":"bottom0"}],"rightArray":[{"portColor":3,"portId":"right0"},{"portColor":0,"portId":"right1"}]}, {"key":2,"name":"Unit Two","loc":"320 152","leftArray":[{"portColor":0,"portId":"left0"},{"portColor":0,"portId":"left1"},{"portColor":0,"portId":"left2"}],"topArray":[{"portColor":3,"portId":"top0"}],"bottomArray":[{"portColor":2,"portId":"bottom0"},{"portColor":3,"portId":"bottom1"},{"portColor":0,"portId":"bottom2"}],"rightArray":[]}, {"key":3,"name":"Unit Three","loc":"384 319","leftArray":[{"portColor":0,"portId":"left0"},{"portColor":0,"portId":"left1"},{"portColor":0,"portId":"left2"}],"topArray":[{"portColor":0,"portId":"top0"}],"bottomArray":[{"portColor":2,"portId":"bottom0"}],"rightArray":[]}, {"key":4,"name":"Unit Four","loc":"138 351","leftArray":[{"portColor":0,"portId":"left0"}],"topArray":[{"portColor":0,"portId":"top0"}],"bottomArray":[{"portColor":2,"portId":"bottom0"}],"rightArray":[{"portColor":0,"portId":"right0"},{"portColor":0,"portId":"right1"}]}, {"key":5,"name":"Unit Five","loc":"260 460","leftArray":[],"topArray":[{"portColor":0,"portId":"top0"},{"portColor":1,"portId":"top1"}],"bottomArray":[],"rightArray":[{"portColor":0,"portId":"right0"},{"portColor":0,"portId":"right1"}]}, {"key":6,"name":"Unit Six","loc":"12 508","leftArray":[],"topArray":[{"portColor":0,"portId":"top0"},{"portColor":1,"portId":"top1"}],"bottomArray":[],"rightArray":[{"portColor":0,"portId":"right0"},{"portColor":0,"portId":"right1"}]} ], "linkDataArray": [ {"from":4,"to":2,"fromPort":"top0","toPort":"bottom0","labelText":"Unit 4 to 2","labelColor":"lightblue"}, {"from":4,"to":2,"fromPort":"top0","toPort":"bottom0","labelText":"Unit 4 to 2","labelColor":"lightblue"}, {"from":3,"to":2,"fromPort":"top0","toPort":"bottom1","labelText":"Unit 3 to 2","labelColor":"lightblue"}, {"from":4,"to":3,"fromPort":"right0","toPort":"left0","labelText":"Unit 4 to 3","labelColor":"lightblue"}, {"from":4,"to":3,"fromPort":"right1","toPort":"left2","labelText":"Unit 4 to 3","labelColor":"lightblue"}, {"from":1,"to":2,"fromPort":"right0","toPort":"left1","labelText":"Unit 1 to 2","labelColor":"lightblue"}, {"from":1,"to":2,"fromPort":"right1","toPort":"left2","labelText":"Unit 1 to 2","labelColor":"lightblue"}, {"from":6,"to":4,"fromPort":"top1","toPort":"left0","labelText":"Unit 6 to 4","labelColor":"lightblue"}, {"from":6,"to":4,"fromPort":"top0","toPort":"left0","labelText":"Unit 6 to 4","labelColor":"lightblue"}, {"from":6,"to":5,"fromPort":"right0","toPort":"top0","labelText":"Unit 6 to 5","labelColor":"lightblue"}, {"from":6,"to":5,"fromPort":"right1","toPort":"right1","labelText":"Unit 6 to 5","labelColor":"lightblue"}, {"from":6,"to":1,"fromPort":"top1","toPort":"bottom0","labelText":"Unit 6 to 1","labelColor":"lightblue"}, {"from":6,"to":1,"fromPort":"top1","toPort":"top0","labelText":"Unit 6 to 1","labelColor":"lightblue"}, {"from":5,"to":4,"fromPort":"top1","toPort":"bottom0","labelText":"Unit 5 to 4","labelColor":"lightblue"}, {"from":5,"to":3,"fromPort":"right0","toPort":"bottom0","labelText":"Unit 5 to 3","labelColor":"lightblue"} ]}

### GoJS Features in this sample

#### Custom Link Routing

Each Link performs a very fast default computation of its desired path, its "route", based only on the properties of the Link and the properties of the port objects that it is connected with. GoJS 3.0 provides a way to customize link routing by allowing consideration of other Nodes and Links, with the Router class.

Routers work by defining a method, Router.routeLinks, which takes a collection of recently recomputed link routes, plus a collection context that is either a Group or the Diagram. This method is called by the Diagram during the update phase after layouts are performed.

More information can be found in the GoJS Intro.

Related samples

#### GoJS Extensions

GoJS can be extended in a variety of ways. The most common way to change the standard behavior is to set properties on the GraphObject, Diagram, CommandHandler, Tool, or Layout. But when the desired property does not exist, you might need to override methods of CommandHandler, Tool, Layout, Link, or Node. Methods that you can override are documented in the API reference. Various features of GoJS can be overriden, either by replacing a method on an instance (a feature of JavaScript) or by defining a subclass. You should not modify the prototypes of any of the GoJS classes.

In addition to our samples, GoJS provides an extensions gallery, showcasing the creation of custom tools and layouts. Those classes and samples are written in TypeScript, available at `../extensionsJSM/`, as ECMAScript/JavaScript modules -- these use the `../release/go-module.js` library. We recommend that you copy the files that you need into your project, so that you can adjust how they refer to the GoJS library that you choose and so that you can include them into your own building and packaging procedures.

More information can be found in the GoJS Intro.

Related samples