This is an extension and not part of the main GoJS library. Note that the API for this class may change at any time. If you intend to use an extension in production, you should copy the code to your own source directory. Extensions can be found in the GoJS kit under the `extensions` or `extensionsTS` folders. See the Extensions intro page for more information.

### Hierarchy

- Layout
  - DoubleTreeLayout

Perform two TreeLayouts, one going rightwards and one going leftwards. The choice of direction is determined by the mandatory predicate directionFunction, which is called on each child Node of the root Node.

You can also set vertical to true if you want the DoubleTreeLayout to perform TreeLayouts both downwards and upwards.

Normally there should be a single root node. Hoewver if there are multiple root nodes found in the nodes and links that this layout is responsible for, this will pretend that there is a real root node and make all of the apparent root nodes children of that pretend root.

If there is no root node, all nodes are involved in cycles, so the first given node is chosen.

If you want to experiment with this extension, try the Double Tree sample.

## Index

### Properties

- bottomRightOptions
- directionFunction
- topLeftOptions
- vertical

### Methods

- createTreeLayout
- doLayout
- isPositiveDirection
- separatePartsForLayout

## Properties

### bottomRightOptions : Partial<TreeLayout> | null

- Gets or sets the options to be applied to a TreeLayout. By default this is null -- no properties are set on the TreeLayout other than the TreeLayout.angle, depending on vertical and the result of calling directionFunction.

### directionFunction : function(node: Node): boolean

- This function is called on each child node of the root node in order to determine whether the subtree starting from that child node will grow towards larger coordinates or towards smaller ones. The value must be a function and must not be null. It must return true if isPositiveDirection should return true; otherwise it should return false.

### topLeftOptions : Partial<TreeLayout> | null

- Gets or sets the options to be applied to a TreeLayout. By default this is null -- no properties are set on the TreeLayout other than the TreeLayout.angle, depending on vertical and the result of calling directionFunction.

### vertical : boolean

- When false, the layout should grow towards the left and towards the right; when true, the layout show grow upwards and downwards. The default value is false.

## Methods

### Protected createTreeLayout

- createTreeLayout(positive: boolean): TreeLayout

- This just returns an instance of TreeLayout. The caller will set the TreeLayout.angle.

  #### Parameters

  - ##### positive: boolean

    true for growth downward or rightward

  #### Returns TreeLayout

### Override doLayout

- doLayout(coll: Diagram | Iterable<Part> | Group): void

- Perform two TreeLayouts by splitting the collection of Parts into two separate subsets but sharing only a single root Node.

  #### Parameters

  - ##### coll: Diagram | Iterable<Part> | Group

  #### Returns void

### Protected isPositiveDirection

- isPositiveDirection(child: Node): boolean

- This predicate is called on each child node of the root node, and only on immediate children of the root. It should return true if this child node is the root of a subtree that should grow rightwards or downwards, or false otherwise.

  #### Parameters

  - ##### child: Node

  #### Returns boolean

  true if grows towards right or towards bottom; false otherwise

### Protected separatePartsForLayout

- separatePartsForLayout(coll: Set<Part>, leftParts: Set<Part>, rightParts: Set<Part>): void

- This is called by doLayout to split the collection of Nodes and Links into two Sets, one for the subtrees growing towards the left or upwards, and one for the subtrees growing towards the right or downwards.

  #### Parameters

  - ##### coll: Set<Part>

  - ##### leftParts: Set<Part>

  - ##### rightParts: Set<Part>

  #### Returns void

Copyright © 1998-2021 by Northwoods Software Corporation.