This sample demonstrates a custom Layout, ArrangingLayout, that provides layouts of layouts. It assumes the graph should be split up and laid out by potentially three separate Layouts.

The first step of ArrangingLayout is that all unconnected nodes are separated out to be laid out later by the ArrangingLayout.sideLayout, which by default is a GridLayout.

The remaining nodes and links are partitioned into separate subgraphs with no links between subgraphs. The ArrangingLayout.primaryLayout is performed on each subgraph.

If there is more than one subgraph, those subgraphs are treated as if they were individual nodes and are laid out by the ArrangingLayout.arrangingLayout.

Finally the unconnected nodes are laid out by ArrangingLayout.sideLayout and they are all positioned at the ArrangingLayout.side Spot relative to the main body of nodes and links.

This extension layout is defined in its own file, as ArrangingLayout.js.


GoJS Features in this sample

Grid Layouts

This predefined layout is used for placing Nodes in a grid-like arrangement. Nodes can be ordered, spaced apart, and wrapped as needed. This Layout ignores any Links connecting the nodes being laid out. More information can be found in the GoJS Intro.

Related samples


Custom Layouts

GoJS allows for the creation of custom layouts to meet specific needs.

There are also many layouts that are extensions -- not predefined in the go.js or go-debug.js library, but available as source code in one of the three extension directories, with some documentation and corresponding samples. 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