ngPaneManager

This is the contents of the ngPaneManager service, which contains various auxiliary functions for working with ngPaneManager layouts and configurations.

ngPaneManager
Example

Example of how to use the service:

app.controller('SomePanelController', function($scope, ngPaneManager) {
  $scope.config = {
    layout: {
      id: 'some-panel',
      title: 'Some Panel',
      panel: {
        template: '<div>I am some panel!</div>'
      }
    }
  };
  $scope.config.layout = ngPaneManager.removeLeafWithId($scope.config.layout, 'some-panel');
});
Static Members
findLeaves(root)
findLeafWithId(root, id)
insertLeaf(root, leaf, ratio)
removeLeafWithId(root, id)
findParent(root, node)
removeSplitChild(root, node, index)
removeNode(root, node)
revealNode(root, node)
cloneLayout(root)
layoutsEqual(a, b)
validateLayout(root)
cloneConfig(config)
configsEqual(a, b)
ref(name)
isRef(x)
deref(x, config)
derefLayout(root, config)
derefConfig(config)

getNodeAtPath

Gets the node at the given path.

getNodeAtPath(root: object, path: any, node: object): object
Parameters
root (object) The root node of the layout.
path (any)
node (object) The node to compute the path for.
Returns
object: The node at the given path.

computeNodePath

Computes the path to the node.

computeNodePath(root: any, node: any): Array<Number>
Parameters
root (any)
node (any)
Returns
Array<Number>: Path to the node, or null if the node cannot be found

patterns

Pattern matching (used for insertLeaf)

The way this works is first we try to match against 'patterns'. Each pattern in 'patterns' is a tree, where each node is either a split or a mapping from possible gravities to simpler gravity (this will be defined shortly). If a match is found, each mapping is used to convert the layouts' gravities into a simpler hierarchy. For example, if insertLeaf is given a layout that looks like this:

|---|---|---| | 1 | 2 | 3 | |---|---|---| L L R

and has the following tree:

vsplit / \ 1(L) vsplit / \ 2(L) 3(R)

(L/R means left/right gravity, the number is the panel id).

This layout will match the pattern

{ split: 'vertical', children: [ [['left', 'right'], 'left'], { split: 'vertical', children: [ [[null, 'left', 'right', 'center'], 'center'], [['left', 'right'], 'right'] ] } ] }

and provide a simpler gravity hierarchy for this tree like this:

|---|---|---| | 1 | 2 | 3 | |---|---|---| L C R

(C means center gravity).

Next we consider the gravity of the panel being inserted. Say we want to insert a panel 4 with center gravity.

We look at the simplified hierarchy. If we find a node with the same gravity as that of the panel being inserted, we will create a tab split with that node. In this case, panel 4 will create a tab split with panel 2.

It's possible that the simpler hierarchy won't have the gravity we're looking for. For example, say we did the following transformation:

|---|---| |---|---| | 1 | 2 | -> | 1 | 2 | |---|---| |---|---| L L L R

If we want to insert a panel 3 with center gravity, we need something to figure out how to perform this insertion, since there is no node we can do a tab split with.

Now we look at the insert strategies for the gravity of the panel being inserted. For center, this is the array insertCenterStrategies.

We find the strategy that matches the simplified hierarchy, in this case that would be:

{ from: { split: 'vertical', children: [ 'left', 'right' ] }, split: 'vertical', index: 1, node: function(node) { return node.children[0]; } }

This strategy says to insert the panel by performing a vertical split with the left node and having the center panel be the second item in the vertical split.

In summary, pattern matching works like this: 1. Match 'patterns', simplify the gravity hierarchy using the match. 2. If the simplified hierarchy contains a panel with the same gravity as that of the panel being inserted, create a tab split with that node, otherwise... 3. Find the appropriate insert strategy to insert the panel into the hierarchy.

patterns