Creates a family object
Family
Family(source)
Creates a family object
Returns: Family - returns new instance of family structure
| Param | Type | Default | Description |
|---|---|---|---|
source |
Family | undefined |
Reference to optional family object to clone properties from |
| Name | Type | Default | Description |
|---|---|---|---|
BREAK |
number | 1 |
B R E A K |
SKIP |
number | 2 |
S K I P |
add(parents, nodeid, node)
Adds new family member
| Param | Type | Default | Description |
|---|---|---|---|
parents |
string[] | `` | A collection of parents ids |
nodeid |
string | `` | An id of the new node |
node |
object | `` | A reference to the new node |
adopt(parents, nodeid)
Makes node to be a child of every parent in the collection of parents
| Param | Type | Default | Description |
|---|---|---|---|
parents |
string[] | `` | A collection of parents ids |
nodeid |
string | `` | An id of the new node |
bundleChildren(parent, children, bundleItemId, bundleItem)
Adds extra bundle item in between parent and its children. The parent node becomes parent of the bundle node, and bundle becomes parent of the children. Existing parent child relations are removed.
Returns: boolean - returns true if nodes bundle is valid
| Param | Type | Default | Description |
|---|---|---|---|
parent |
string | `` | The parent node id |
children |
string[] | `` | The collection of child nodes ids |
bundleItemId |
string | `` | The bundle node id |
bundleItem |
object | `` | The bundle item context object |
bundleParents(child, parents, bundleItemId, bundleItem)
Adds extra bundle item in between child node and its parents. The child node becomes child of the bundle node, and bundle becomes child of the parents. Existing parent child relations are removed.
Returns: boolean - returns true if the bundle is valid
| Param | Type | Default | Description |
|---|---|---|---|
child |
string | `` | The parent node id |
parents |
string[] | `` | The collection of child nodes ids |
bundleItemId |
string | `` | The bundle node id |
bundleItem |
object | `` | The bundle item context object |
clone()
Clones family structure.
Returns: family - returns copy of the family structure.
countChildren(parent)
Returns number of children
Returns: number - number of children
| Param | Type | Default | Description |
|---|---|---|---|
parent |
string | `` | The parent node id |
countParents(child)
Returns number of parents
Returns: number - number of parents
| Param | Type | Default | Description |
|---|---|---|---|
child |
string | `` | The child node id |
eliminateManyToMany(onNewBundleItem)
Eliminates many to many relations in family structure It is needed to simplify layout process of the diagram
| Param | Type | Default | Description |
|---|---|---|---|
onNewBundleItem |
onNewFamilyNodeCallback | `` | Callback function for creation of new bundle node |
| Callbacks |
onNewFamilyNodeCallback()
Callback function for creation of new family nodes
Returns: object - returns new family node.
findLargestRoot()
Finds root node having largest number of nodes in its hierarchy
Returns: string - returns largest sub-hierarchy root node id.
firstChild(parent)
First available child
Returns: string - returns first available child id or null.
| Param | Type | Default | Description |
|---|---|---|---|
parent |
string | `` | The parent node id |
firstParent(child)
First available parent
Returns: string - returns first available parent id or null.
| Param | Type | Default | Description |
|---|---|---|---|
child |
string | `` | The child node id |
getFamilyWithoutGrandParentsRelations()
Eliminates direct relations between grand parent nodes.
Returns: family - returns family structure without direct grand parent relations.
getGraph(thisArg, onEdge)
Creates graph structure out of the family structure.
Returns: graph - returns graph structure of the family.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
onEdge |
onFamilyEdgeCallback | `` | A callback function to call for every new edge added to the final graph |
| Callbacks |
onFamilyEdgeCallback(from, to)
Callback for getting default edge value
Returns: object - returns new edge object.
| Param | Type | Default | Description |
|---|---|---|---|
from |
string | `` | From node id |
to |
string | `` | The node |
getPlanarFamily(treeLevels)
Eliminates crossing parent child relations between nodes based of nodes order in treeLevels structure.
Returns: family - returns planar family structure.
| Param | Type | Default | Description |
|---|---|---|---|
treeLevels |
treeLevels | `` | Tree levels structure keeps orders of nodes level by level. |
groupBy(thisArg, size, onGroup, onGroupId)
Creates graph structure out of the family structure.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
onGroup |
onFamilyGroupCallback | `` | A callback function to call for every new group of nodes found |
onGroupId |
onFamilyGroupIdCallback | `` | A callback function to call for every new group of nodes found |
| Callbacks |
onFamilyGroupCallback(parent, child, nodes)
Callback for grouping nodes having common single parent and child
| Param | Type | Default | Description |
|---|---|---|---|
parent |
string | `` | The common parent node id |
child |
string | `` | The common child node id |
nodes |
Array.<Array.> | `` | Collection of collections of grouped items |
onFamilyGroupIdCallback(nodes)
Callback for getting group id for group of nodes
Returns: string - returns group id or null. null adds node to default group. return -1 to disable grouping.
| Param | Type | Default | Description |
|---|---|---|---|
nodes |
Array. | `` | Collection of nodes to get group id for. |
hasCommonChild(parents)
Checks whether parents share a child node. Common child should belong only to the given collection of parents, if child's parents don't match given collection of parents, it is not considered as common child.
Returns: boolean - returns true if common child exist.
| Param | Type | Default | Description |
|---|---|---|---|
parents |
string[] | `` | Collection of parents |
hasLoops()
Checks if family structure has loops in references.
Returns: boolean - returns true if family structure contains loops in references.
hasNodes()
Returns true if structure has nodes.
Returns: boolean - returns true if family structure has nodes
loop(thisArg, onItem)
Loops through nodes of family structure
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
onItem |
onFamilyItemCallback | `` | A callback function to call for every family node |
| Callbacks |
onFamilyItemCallback(itemid, item)
Callback for iterating family nodes
Returns: boolean - returns true to break the loop
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | The node id |
item |
object | `` | The node |
loopChildren(thisArg, nodeid, onItem)
Loops through child nodes of family structure level by level
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
nodeid |
string | `` | The node id to start children traversing |
onItem |
onFamilyItemWithLevelCallback | `` | A callback function to call for every child node |
| Callbacks |
onFamilyItemWithLevelCallback(itemid, item, levelIndex)
Callback for iterating family nodes level by level
Returns: number - returns break to break the loop and exit. returns skip to skip node's branch traversing.
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | The node id |
item |
object | `` | The node |
levelIndex |
number | `` | The node level index |
loopLevels(thisArg, parentAligned, onItem)
Loops through nodes of family structure level by level. This function aligns nodes top or bottom.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
parentAligned |
boolean | `` | True if nodes should be placed at the next level after their parents level, otherwise nodes placed at levels close to their children. |
onItem |
onFamilyItemWithLevelCallback | `` | A callback function to call for every node |
| Callbacks |
onFamilyItemWithLevelCallback(itemid, item, levelIndex)
Callback for iterating family nodes level by level
Returns: number - returns break to break the loop and exit. returns skip to skip node's branch traversing.
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | The node id |
item |
object | `` | The node |
levelIndex |
number | `` | The node level index |
loopNeighbours(thisArg, itemid, onItem)
Loops through the node neighbours of the family structure level by level
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
itemid |
string | `` | The node id to start traversing neighbour nodes |
onItem |
onFamilyItemNeighbourCallback | `` | A callback function to call for every neighbour node |
| Callbacks |
onFamilyItemNeighbourCallback(itemid, item, levelIndex)
Callback for iterating family node neighbours level by level
Returns: number - returns true to skip further neighbous traversing.
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | The node id |
item |
object | `` | The node |
levelIndex |
number | `` | The neigbour node distance from the start node |
loopParents(thisArg, nodeid, onItem)
Loops through parent nodes of family structure level by level
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
nodeid |
string | `` | The node id to start parents traversing |
onItem |
onFamilyItemWithLevelCallback | `` | A callback function to call for every parent node |
| Callbacks |
onFamilyItemWithLevelCallback(itemid, item, levelIndex)
Callback for iterating family nodes level by level
Returns: number - returns break to break the loop and exit. returns skip to skip node's branch traversing.
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | The node id |
item |
object | `` | The node |
levelIndex |
number | `` | The node level index |
loopRoots(thisArg, onItem)
Loops root nodes of family structure.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
onItem |
onFamilyItemCallback | `` | A callback function to call for every family root node |
| Callbacks |
onFamilyItemCallback(itemid, item)
Callback for iterating family nodes
Returns: boolean - returns true to break the loop
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | The node id |
item |
object | `` | The node |
loopTopo(thisArg, onItem)
Loops through topologically sorted nodes of family structure
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
onItem |
onFamilyTopoCallback | `` | A callback function to call for every node |
| Callbacks |
onFamilyTopoCallback(itemid, item, position)
Callback for iterating family nodes in topological sort order
Returns: boolean - returns true to break the loop and exit.
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | The node id |
item |
object | `` | The node |
position |
number | `` | The node position in the sequence |
loopTopoReversed(thisArg, onItem)
Loops through reversed order topologically sorted nodes of family structure
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
onItem |
onFamilyTopoCallback | `` | A callback function to call for every node |
| Callbacks |
onFamilyTopoCallback(itemid, item, position)
Callback for iterating family nodes in topological sort order
Returns: boolean - returns true to break the loop and exit.
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | The node id |
item |
object | `` | The node |
position |
number | `` | The node position in the sequence |
node(nodeid)
Returns family node by id
Returns: object|undefined - a reference to the node or undefined if id does not exists
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | The id of the node |
optimizeReferences(onNewBundleItem)
Optimizes references between family members. It creates bundles eliminating excessive intersections between nodes relations.
| Param | Type | Default | Description |
|---|---|---|---|
onNewBundleItem |
onNewFamilyNodeCallback | `` | Callback function to create a new family node context object. |
| Callbacks |
onNewFamilyNodeCallback()
Callback function for creation of new family nodes
Returns: object - returns new family node.
removeChildRelation(parentid, childid)
Removes child relation
Returns: true - if relation was broken
| Param | Type | Default | Description |
|---|---|---|---|
parentid |
string | `` | The parent node id |
childid |
string | `` | The child node id |
removeNode(nodeid)
Removes node
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | The id of the node |
removeRelation(fromid, toid)
Removes first available parent child or child parent relation
Returns: true - if relation was broken
| Param | Type | Default | Description |
|---|---|---|---|
fromid |
string | `` | From node id |
toid |
string | `` | To node id |
validate(info)
Validates internal data structure consistency of the family.
| Param | Type | Default | Description |
|---|---|---|---|
info |
object | `` | Optional validation object. |
Creates family alignment data structure. This structure aligns horizontally planar family of nodes.
FamilyAlignment
FamilyAlignment(thisArg, family, treeLevels, onItemSize)
Creates family alignment data structure. This structure aligns horizontally planar family of nodes.
Returns: FamilyAlignment - returns family alignment structure
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
family |
family | `` | Family data structure |
treeLevels |
TreeLevels | `` | Three levels data structure |
onItemSize |
onFamilyAlignmentItemSizeCallback | `` | Callback function to measure family node width |
getOffset(nodeid)
Returns horizontal node offset from left margin of the family diagram
Returns: number - node offset
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | Family node id |
Creates Fibonacci Heap structure
FibonacciHeap
FibonacciHeap(isMaximum)
Creates Fibonacci Heap structure
Returns: FibonacciHeap - returns new fibonacciheap object
| Param | Type | Default | Description |
|---|---|---|---|
isMaximum |
boolean | `` | Is maximum heap |
add(key, priority, item)
Adds a new item into the heap
| Param | Type | Default | Description |
|---|---|---|---|
key |
string | `` | A key of the new element |
priority |
number | `` | A priority of the new element |
item |
object | `` | A context object of the new element |
deleteKey(key)
Deletes heap element by key
| Param | Type | Default | Description |
|---|---|---|---|
key |
string | `` | The Key |
extractRoot()
Returns heap root element with removal
Returns: HeapResult - returns root element of the heap
getPriority(key)
Gets priority of element by key
Returns: number - returns priority of the element
| Param | Type | Default | Description |
|---|---|---|---|
key |
string | `` | The element key |
heapRoot()
Returns heap root element
Returns: HeapResult - returns root element of the heap
setPriority(key, priority)
Sets priority of an element by key
| Param | Type | Default | Description |
|---|---|---|---|
key |
string | `` | The key of the element |
priority |
number | `` | Priority |
validate()
Validates internal structure consistency.
Returns: boolean - returns true if structure pass data consistency check.
Creates an undirected graph structure backed by adjacency lists. Each edge stores a context object provided by the caller.
Graph
Graph()
Creates an undirected graph structure backed by adjacency lists. Each edge stores a context object provided by the caller.
Returns: Graph - a new graph instance
addEdge(from, to, edge)
Adds an undirected edge between two nodes. If the edge already exists, it will not be replaced.
| Param | Type | Default | Description |
|---|---|---|---|
from |
string | `` | The starting node id |
to |
string | `` | The ending node id |
edge |
object | `` | The edge context object |
dfsLoop(thisArg, startNode, onEdge, onNode)
Performs a depth-first traversal starting at a node. Edge usability is determined by the onEdge callback.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
object | `` | Execution context |
startNode |
string | `` | The start node id |
onEdge |
onPathEdgeCallback | `` | Callback deciding edge usability |
onNode |
onNodeCallback | `` | Callback invoked for each newly visited node |
| Callbacks |
onPathEdgeCallback(from, to, edge)
Callback used for filtering usable edges during DFS path search.
Returns: boolean - true if the edge may be used in traversal
| Param | Type | Default | Description |
|---|---|---|---|
from |
string | `` | The start node id |
to |
string | `` | The end node id |
edge |
Object | `` | The edge context object |
onNodeCallback(to)
Callback for node iteration functions.
Returns: boolean - return true to stop traversal early
| Param | Type | Default | Description |
|---|---|---|---|
to |
string | `` | The node id visited |
dfsPath(thisArg, startNode, endNode, onEdge)
Finds any path between two nodes using depth-first search.
Returns: string[] - array of node ids forming the found path
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
object | `` | Execution context for callbacks |
startNode |
string | `` | The start node id |
endNode |
string | `` | The end node id |
onEdge |
onPathEdgeCallback | `` | Callback deciding whether an edge is usable |
| Callbacks |
onPathEdgeCallback(from, to, edge)
Callback used for filtering usable edges during DFS path search.
Returns: boolean - true if the edge may be used in traversal
| Param | Type | Default | Description |
|---|---|---|---|
from |
string | `` | The start node id |
to |
string | `` | The end node id |
edge |
Object | `` | The edge context object |
edge(from, to)
Retrieves the stored edge context object for a given pair of nodes.
Returns: object|null - the edge's context object, or null if none exists
| Param | Type | Default | Description |
|---|---|---|---|
from |
string | `` | The source node id |
to |
string | `` | The target node id |
getLevelGraph(thisArg, startNode, onEdge)
Computes a level graph starting from a given node. Levels are assigned via BFS using only edges allowed by the callback.
Returns: Graph - a new graph representing the level structure
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
object | `` | Execution context |
startNode |
string | `` | The start node id |
onEdge |
onPathEdgeCallback | `` | Callback deciding if an edge is valid to traverse |
| Callbacks |
onPathEdgeCallback(from, to, edge)
Callback used for filtering usable edges during DFS path search.
Returns: boolean - true if the edge may be used in traversal
| Param | Type | Default | Description |
|---|---|---|---|
from |
string | `` | The start node id |
to |
string | `` | The end node id |
edge |
Object | `` | The edge context object |
getMinimumWeightGrowthSequence(thisArg, startNode, onEdgeWeight, onItem)
Get minimum weight graph growth sequence. The sequence of the traversing order of the graph nodes.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
object | `` | The callback function invocation context |
startNode |
string | undefined |
The optional start node id |
onEdgeWeight |
getGraphEdgeWeightCallback | `` | Callback function to get weight of an edge. |
onItem |
onNodeCallback | `` | A callback function to be called for every node of the growth sequence |
| Callbacks |
getGraphEdgeWeightCallback(edge, fromItem, toItem)
Returns edge weight used in certain algorithms.
Returns: number - the weight of the edge
| Param | Type | Default | Description |
|---|---|---|---|
edge |
object | `` | The edge context object |
fromItem |
string | `` | The start node id |
toItem |
string | `` | The end node id |
onNodeCallback(to)
Callback for node iteration functions.
Returns: boolean - return true to stop traversal early
| Param | Type | Default | Description |
|---|---|---|---|
to |
string | `` | The node id visited |
getShortestPath(thisArg, startNode, endNodes, getWeightFunc, onPathFound)
Computes the shortest paths from a start node to one or more target nodes.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
object | `` | Execution context for callbacks |
startNode |
string | `` | Starting node id |
endNodes |
string[] | `` | Target node ids |
getWeightFunc |
getGraphEdgeWeightCallback | `` | Optional function returning edge weight |
onPathFound |
onPathFoundCallback | `` | Callback invoked when a target path is found |
| Callbacks |
getGraphEdgeWeightCallback(edge, fromItem, toItem)
Returns edge weight used in certain algorithms.
Returns: number - the weight of the edge
| Param | Type | Default | Description |
|---|---|---|---|
edge |
object | `` | The edge context object |
fromItem |
string | `` | The start node id |
toItem |
string | `` | The end node id |
onPathFoundCallback(path, to)
Callback invoked when a full path has been reconstructed.
| Param | Type | Default | Description |
|---|---|---|---|
path |
string[] | `` | The node sequence forming the path |
to |
string | `` | The end node id |
getSpanningTree(startNode, getWeightFunc)
Computes a maximum spanning tree using a priority queue. The graph may be disconnected; a start node is required.
Returns: tree - a tree structure containing the maximum spanning tree
| Param | Type | Default | Description |
|---|---|---|---|
startNode |
string | `` | Node to begin spanning tree search |
getWeightFunc |
getGraphEdgeWeightCallback | `` | Function returning edge weight |
| Callbacks |
getGraphEdgeWeightCallback(edge, fromItem, toItem)
Returns edge weight used in certain algorithms.
Returns: number - the weight of the edge
| Param | Type | Default | Description |
|---|---|---|---|
edge |
object | `` | The edge context object |
fromItem |
string | `` | The start node id |
toItem |
string | `` | The end node id |
getTotalWeightGrowthSequence(thisArg, onEdgeWeight, onItem)
Get graph growth sequence. The sequence of graph traversing order.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
object | `` | The callback function invocation context |
getWeightFunc |
getGraphEdgeWeightCallback | `` | Callback function to get weight of an edge. |
onItem |
onNodeCallback | `` | A callback function to be called for every node of the growth sequence |
| Callbacks |
getGraphEdgeWeightCallback(edge, fromItem, toItem)
Returns edge weight used in certain algorithms.
Returns: number - the weight of the edge
| Param | Type | Default | Description |
|---|---|---|---|
edge |
object | `` | The edge context object |
fromItem |
string | `` | The start node id |
toItem |
string | `` | The end node id |
onNodeCallback(to)
Callback for node iteration functions.
Returns: boolean - return true to stop traversal early
| Param | Type | Default | Description |
|---|---|---|---|
to |
string | `` | The node id visited |
hasNode(from)
Checks whether a node exists in the graph.
Returns: boolean - true if the node is present in the graph
| Param | Type | Default | Description |
|---|---|---|---|
from |
string | `` | The node id |
loopEdges(thisArg, onEdge)
Iterates over all edges in the graph.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
object | `` | Execution context for the callback |
onEdge |
onEdgeCallback | `` | Callback invoked for each edge |
| Callbacks |
onEdgeCallback(from, to, edge)
Callback invoked for each edge during iteration.
| Param | Type | Default | Description |
|---|---|---|---|
from |
string | `` | The start node id |
to |
string | `` | The end node id |
edge |
Object | `` | The edge context object |
loopNodeEdges(thisArg, itemid, onEdge)
Iterates over all edges connected to a specific node.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
object | `` | Execution context for the callback |
itemid |
string | `` | The node id whose edges to iterate |
onEdge |
onEdgeCallback | `` | Callback invoked for each connected edge |
| Callbacks |
onEdgeCallback(from, to, edge)
Callback invoked for each edge during iteration.
| Param | Type | Default | Description |
|---|---|---|---|
from |
string | `` | The start node id |
to |
string | `` | The end node id |
edge |
Object | `` | The edge context object |
loopNodes(thisArg, startNode, onItem)
Traverses all connected nodes starting from the given node. If no start node is provided, traversal begins with the first available node.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
object | `` | Execution context for the callback |
startNode |
string | `` | Optional starting node id |
onItem |
onNodeCallback | `` | Callback invoked for each visited node |
| Callbacks |
onNodeCallback(to)
Callback for node iteration functions.
Returns: boolean - return true to stop traversal early
| Param | Type | Default | Description |
|---|---|---|---|
to |
string | `` | The node id visited |
Creates Lowest Common Ancestor Structure for the given tree
LCA
LCA(tree)
Creates Lowest Common Ancestor Structure for the given tree
Returns: LCA - returns lowest common ancestor structure
| Param | Type | Default | Description |
|---|---|---|---|
tree |
Tree | `` | The tree structure |
getLowestCommonAncestor(from, to)
Returns lowest common ancestor for the given pair of tree nodes
Returns: string - returns the lowest common ancestor tree node id
| Param | Type | Default | Description |
|---|---|---|---|
from |
string | `` | The first tree node id |
to |
string | `` | The second tree node id |
Creates linked hash list collection.
LinkedHashItems
LinkedHashItems()
Creates linked hash list collection.
Returns: LinkedHashItems - returns linked hash list structure
add(key, item)
Adds new item to collection
| Param | Type | Default | Description |
|---|---|---|---|
key |
string | `` | The new item key |
item |
object | `` | The new item context object value |
attach(list)
Appends one list to another
| Param | Type | Default | Description |
|---|---|---|---|
list |
LinkedHashItems | `` | A list to append to the end of the current list |
empty()
Empties collection
endKey()
Last collection item key
Returns: string - returns key of the last item in the collection
insertAfter(afterKey, key, item)
Inserts new item into the list after the given key
| Param | Type | Default | Description |
|---|---|---|---|
afterKey |
string | `` | The key that the new element is placed after |
key |
string | `` | The new item key |
item |
object | `` | The new item context object value |
insertBefore(beforeKey, key, item)
Inserts new item into the list before the given key
| Param | Type | Default | Description |
|---|---|---|---|
beforeKey |
string | `` | The key that the new element is placed before |
key |
string | `` | The new item key |
item |
object | `` | The new item context object value |
isEmpty()
Checks if collection is empty
Returns: boolean - returns true if collection is empty
item(key)
Item context object
Returns: object - returns context object
| Param | Type | Default | Description |
|---|---|---|---|
key |
string | `` | The item's key |
iterate(onItem, startKey, endKey)
Loops items of the collection
| Param | Type | Default | Description |
|---|---|---|---|
onItem |
onLinkedHashItemsCallback | `` | Callback function for iterating collection items |
startKey |
string | `` | The key to start iteration from |
endKey |
string | `` | The key to end iteration at |
| Callbacks |
onLinkedHashItemsCallback(item, key)
Callback function for iterating list items
Returns: boolean - returns true to break the iteration process
| Param | Type | Default | Description |
|---|---|---|---|
item |
object | `` | The item context object |
key |
string | `` | The item key |
iterateBack(onItem, startKey, endKey)
Loops items of the collection backward
| Param | Type | Default | Description |
|---|---|---|---|
onItem |
onLinkedHashItemsCallback | `` | Callback function for iterating collection items |
startKey |
string | `` | The key to start iteration from |
endKey |
string | `` | The key to end iteration at |
| Callbacks |
onLinkedHashItemsCallback(item, key)
Callback function for iterating list items
Returns: boolean - returns true to break the iteration process
| Param | Type | Default | Description |
|---|---|---|---|
item |
object | `` | The item context object |
key |
string | `` | The item key |
nextKey(key)
Gets next key
Returns: string - returns key of the next collection item
| Param | Type | Default | Description |
|---|---|---|---|
key |
string | `` | The item key |
prevKey(key)
Gets previous key
Returns: string - returns key of the previous collection item
| Param | Type | Default | Description |
|---|---|---|---|
key |
string | `` | The item key |
remove(key)
Removes item
| Param | Type | Default | Description |
|---|---|---|---|
key |
string | `` | The key of the item |
startKey()
First collection item key
Returns: string - returns the key of the first item in the collection
toArray()
Returns a regular javascript array of collection items
Returns: object[] - returns array containing items of the collection
unshift(key, item)
Adds new item to the head of the list
Returns: string - returns key of the last item in the collection
| Param | Type | Default | Description |
|---|---|---|---|
key |
string | `` | The new item key |
item |
object | `` | The new item context object value |
validate(info)
Validates internal data consistency of the structure
Returns: boolean - returns true if it pass validation
Creates pile structure used to sort and stack segments on top of each other so they occupy minimum number of rows.
Pile
Pile()
Creates pile structure used to sort and stack segments on top of each other so they occupy minimum number of rows.
Returns: Pile - returns pile structure
add(from, to, context)
Adds new segment to pile object.
| Param | Type | Default | Description |
|---|---|---|---|
from |
number | `` | Left margin of segment. |
to |
number | `` | Right margin of segment. |
context |
object | `` | Any reference to user object. It is returned as parameter in callback function of resolve method. |
resolve(thisArg, onItem)
Sorts and stack segments on top of each other so they occupy minimum number of rows.
Returns: number - number of stacked rows in pile.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
object | `` | A context object of the callback function invocation. |
onItem |
onPileItemCallback | `` | Callback function for setting segments offsets in the pile. |
| Callbacks |
onPileItemCallback(from, to, context, offset)
Callback function or iterating result offsets of the pile items in the stack.
| Param | Type | Default | Description |
|---|---|---|---|
from |
number | `` | The left margin of the segment |
to |
number | `` | The right margin of the segment |
context |
object | `` | The context of the pile item |
offset |
number | `` | Index of the pile item in the stack |
Creates Quad Tree data structure. It distributes points into equal quadrants. So it is equivalent to 2 dimensional binary search tree.
QuadTree
QuadTree(minimalSize)
Creates Quad Tree data structure. It distributes points into equal quadrants. So it is equivalent to 2 dimensional binary search tree.
Returns: QuadTree - returns quad tree data structure.
| Param | Type | Default | Description |
|---|---|---|---|
minimalSize |
number | `` | Defines minimal size of the quadrant. This protects structure against unnecessary depth. |
addPoint(point)
Adds point
| Param | Type | Default | Description |
|---|---|---|---|
point |
Point | `` | Point |
getPositions(selection)
Returns collection of quadrants created in the data structure Quadrants exists only when elements exists in them. This method is used for visual debugging of the structure.
Returns: Rect[] - returns collection of available quadrants. quadrants containing points within selection area have context.highlight property set to true.
| Param | Type | Default | Description |
|---|---|---|---|
selection |
React | `` | Rectangular test area to highlight quadrants |
loopArea(thisArg, rect, onItem)
Loops rectangular area of quad tree structure
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
object | `` | The callback function invocation context |
rect |
Rect | `` | Rectangular search area |
onItem |
onQuadTreePointCallback | `` | Callback function to call for every point within the search area |
| Callbacks |
onQuadTreePointCallback(point)
Callback function for iteration of points
Returns: boolean - returns true to break iteration process.
| Param | Type | Default | Description |
|---|---|---|---|
point |
Point | `` | Rectangle |
validate()
Validates internal data consistency of quad tree data structure
Returns: boolean - returns true if structure pass validation
Creates range minimum query structure
RMQ
RMQ(items)
Creates range minimum query structure
Returns: RMQ - returns range minimum query structure
| Param | Type | Default | Description |
|---|---|---|---|
items |
number[] | `` | Collection of numbers |
getRangeMinimum(from, to)
Return minimum value for the given range
Returns: number - returns minimum value in the range
| Param | Type | Default | Description |
|---|---|---|---|
from |
number | `` | The left index of the range |
to |
number | `` | The right index of the range |
getRangeMinimumIndex(from, to)
Returns index of minimum item for the given range of items
Returns: number - returns index of the minimum item
| Param | Type | Default | Description |
|---|---|---|---|
from |
number | `` | The left margin index |
to |
number | `` | The right margin index |
Creates self-balancing binary search tree structure.
SortedList
SortedList()
Creates self-balancing binary search tree structure.
Returns: SortedList - returns sorted list collection.
add(value, context, thisArg, onDuplicate)
Adds value to sorted list collection
| Param | Type | Default | Description |
|---|---|---|---|
value |
number | `` | The value |
context |
object | `` | The value context object |
thisArg |
object | `` | The callback function invocation context |
onDuplicate |
onSortedListDuplicateCallback | `` | Callback function for duplicates values notification |
| Callbacks |
onSortedListDuplicateCallback(context)
Callback function to notify about duplicate values
| Param | Type | Default | Description |
|---|---|---|---|
context |
object | `` | The context object of the duplicate value |
loopBackward(thisArg, fromValue, onItem)
Loops sorted list values backward
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
object | `` | The callback function invocation context |
fromValue |
number | `` | The start value to loop items of sorted list |
onItem |
onSortedListItemCallback | `` | Callback function to iterate over sorted list values |
| Callbacks |
onSortedListItemCallback(value, context)
Callback function for iterating values of the sorted list
Returns: boolean - returns true to break loop operation
| Param | Type | Default | Description |
|---|---|---|---|
value |
number | `` | The value |
context |
object | `` | The value context object |
loopForward(thisArg, fromValue, onItem)
Loops sorted list values
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
object | `` | The callback function invocation context |
fromValue |
number | `` | The start value to loop items of sorted list |
onItem |
onSortedListItemCallback | `` | Callback function to iterate over sorted list values |
| Callbacks |
onSortedListItemCallback(value, context)
Callback function for iterating values of the sorted list
Returns: boolean - returns true to break loop operation
| Param | Type | Default | Description |
|---|---|---|---|
value |
number | `` | The value |
context |
object | `` | The value context object |
nextContext(fromValue)
Returns context object of the next value following the given one
Returns: object - returns context object of the first value in sorted list greater than the start value.
| Param | Type | Default | Description |
|---|---|---|---|
fromValue |
number | `` | The value to start search from |
previousContext(fromValue)
Returns context object of the previous value preceding the given one
Returns: object - returns context object of the first value in sorted list less than the start value.
| Param | Type | Default | Description |
|---|---|---|---|
fromValue |
number | `` | The value to start search from |
remove(value)
Removes value from the sorted list
| Param | Type | Default | Description |
|---|---|---|---|
value |
number | `` | The removed value |
validate()
Validate internal data consistency of the self-balancing binary search tree structure
Returns: boolean - returns true if structure pass validation
Create spatial index structure. It uses collection of sizes to distribute rectangles into buckets of similar size elements. Elements of the same bucket are approximated to points. The search of rectangles is transformed to search of points within given range plus offset for maximum linear rectangle size.
SpatialIndex
SpatialIndex(sizes)
Create spatial index structure. It uses collection of sizes to distribute rectangles into buckets of similar size elements. Elements of the same bucket are approximated to points. The search of rectangles is transformed to search of points within given range plus offset for maximum linear rectangle size.
Returns: SpatialIndex - returns spacial index data structure.
| Param | Type | Default | Description |
|---|---|---|---|
sizes |
Array | `` | Reference to optional collection of possible sizes of items we plan to store in the index |
addRect(rect)
Adds rectangle to spacial index
| Param | Type | Default | Description |
|---|---|---|---|
rect |
Rect | `` | Rectangle |
loopArea(thisArg, rect, onItem)
Loops rectangular area of spacial index
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
object | `` | The callback function invocation context |
rect |
Rect | `` | Rectangular search area |
onItem |
onSpatialIndexItemCallback | `` | Callback function to call for every rectangle intersecting given rectangular search area |
| Callbacks |
onSpatialIndexItemCallback(rect)
Callback function for iteration of spacial index rectangles
Returns: boolean - returns true to break iteration process.
| Param | Type | Default | Description |
|---|---|---|---|
rect |
React | `` | Rectangle |
Creates tree structure
Tree
Tree(source)
Creates tree structure
Returns: Tree - returns new tree structure
| Param | Type | Default | Description |
|---|---|---|---|
source |
Tree | `` | A source tree structure to clone properties from |
| Name | Type | Default | Description |
|---|---|---|---|
BREAK |
number | 1 |
B R E A K |
SKIP |
number | 2 |
S K I P |
add(parentid, nodeid, node, position)
Adds new tree item
| Param | Type | Default | Description |
|---|---|---|---|
parentid |
string | `` | Parent id |
nodeid |
string | `` | New node id |
node |
object | `` | Context object of the new node |
position |
number | `` | Position of the new node in the collection of children |
adopt(parentid, nodeid)
Adds existing node to the children of the parent node
| Param | Type | Default | Description |
|---|---|---|---|
parentid |
string | `` | Parent Node id |
nodeid |
string | `` | Node id |
arrangeChildren(nodeid, children)
Orders children of the given node
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | The node id of the parent node which children should be ordered in the tree structure |
children |
string[] | `` | Collection of ordered children |
clone()
Clones tree structure
Returns: tree - returns clone of the tree
countChildren(nodeid)
Returns number of children
Returns: number - returns number of child nodes
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | Node id |
countSiblings(nodeid)
Returns number of siblings
Returns: number - returns number of siblings
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | Node id |
getChild(parentid, index)
Returns child node by index in the children's collection
Returns: object - returns child node
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | Node id |
index |
number | `` | Child index |
hasChildren(nodeid)
Returns true if node has children
Returns: boolean - returns true if node has children
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | Node id |
hasNodes()
Return true if structure has nodes
Returns: boolean - returns true if structure has nodes
indexOf(nodeid)
Returns index of the node in the children's collection
Returns: number - returns node index
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | Node id |
insert(nodeid, bundleid, bundle)
Inserts bundle node into the tree structure. The new bundle node becomes only child node of the parent node. All immediate children of the parent node become children of the inserted bundle node.
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | Parent node id |
bundleid |
string | `` | New bundle node id |
bundle |
object | `` | Context object of the bundle node |
loop(thisArg, onItem)
Loops through nodes of tree structure
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
onItem |
onTreeItemCallback | `` | Callback function to call for every tree node |
| Callbacks |
onTreeItemCallback(itemid, item)
Callback for iterating tree nodes
Returns: boolean - returns true to break the loop
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | The node id |
item |
object | `` | The node |
loopChildren(thisArg, nodeid, onItem)
Loops immediate children of the given node. Breaks iteration if callback function returns true.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
nodeid |
string | `` | The parent node id to loop children of |
onItem |
onTreeChildItemCallback | `` | Callback function to call for every child node |
| Callbacks |
onTreeChildItemCallback(nodeid, node, index, lastIndex)
Callback function to loop through children of the given node
Returns: boolean - returns true to break the iteration of nodes and exit.
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | Child node id |
node |
object | `` | Context object of the child node |
index |
number | `` | Index of the child node |
lastIndex |
number | `` | Index of the last child |
loopChildrenRange(thisArg, nodeid, fromIndex, toIndex, onItem)
Loops range of immediate children of the given node. Breaks iteration if callback function returns true.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
nodeid |
string | `` | The parent node id to loop children of |
fromIndex |
number | `` | Start index of iteration |
toIndex |
number | `` | End index of iteration |
onItem |
onTreeNodeWithIndexItemCallback | `` | Callback function to call for every child node |
| Callbacks |
onTreeNodeWithIndexItemCallback(nodeid, node, index)
Callback function to loop through range of children for the given node
Returns: boolean - returns true to break the iteration of nodes and exit.
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | Child node id |
node |
object | `` | Context object of the child node |
index |
number | `` | Index of the child node |
loopChildrenReversed(thisArg, nodeid, onItem)
Loops immediate children of the given node in reversed order. Breaks iteration if callback function returns true.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
nodeid |
string | `` | The parent node id to loop children of |
onItem |
onTreeChildItemCallback | `` | Callback function to call for every child node |
| Callbacks |
onTreeChildItemCallback(nodeid, node, index, lastIndex)
Callback function to loop through children of the given node
Returns: boolean - returns true to break the iteration of nodes and exit.
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | Child node id |
node |
object | `` | Context object of the child node |
index |
number | `` | Index of the child node |
lastIndex |
number | `` | Index of the last child |
loopEulerWalk(thisArg, onItem)
Loops tree nodes in "Euler Walk" order
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
onItem |
onItemEulerWalkCallback | `` | Callback function to call for every node |
| Callbacks |
onItemEulerWalkCallback(nodeid, node, level)
Callback for iterating nodes in euler walk order
Returns: boolean - returns true to break the iteration of nodes and exit.
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | The node id |
node |
object | `` | Context object of the node |
level |
number | `` | The node's level |
loopLevels(thisArg, arg0, arg1)
Loops through child nodes of the tree structure level by level
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
arg0 |
string | `` | The node id to start children traversing |
arg1 |
onTreeItemWithLevelCallback | `` | Callback function to call for every child node |
| Callbacks |
onTreeItemWithLevelCallback(nodeid, node, levelIndex)
Callback for iterating the tree nodes level by level
Returns: number - returns break to break the loop and exit. returns skip to skip node's branch traversing.
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | The node id |
node |
object | `` | The node context object |
levelIndex |
number | `` | The node level index |
loopNeighbours(thisArg, itemid, distance, onItem)
Loops through the node neighbours of the tree structure level by level
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
itemid |
string | `` | The node id to start traversing neighbour nodes |
distance |
number | `` | Stop iteration of neighbours when distance exceeds the given value |
onItem |
onTreeItemNeighbourCallback | `` | A callback function to call for every neighbour node |
| Callbacks |
onTreeItemNeighbourCallback(itemid, item, distance)
Callback for iterating tree node neighbours level by level
Returns: number - returns true to skip further neighbous traversing.
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | The node id |
item |
object | `` | The node |
distance |
number | `` | The neigbour node distance from the start node |
loopParents(thisArg, nodeid, onItem, includingStartItem)
Loops parents up to the root of the hierarchy starting with the given node. Breaks iteration if callback function returns true.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
nodeid |
string | `` | The node id to start iteration from |
onItem |
onTreeItemCallback | `` | Callback function to call for every parent node |
includingStartItem |
boolean | `` | If true the first call to callback function is made with start node id |
| Callbacks |
onTreeItemCallback(itemid, item)
Callback for iterating tree nodes
Returns: boolean - returns true to break the loop
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | The node id |
item |
object | `` | The node |
loopPostOrder(thisArg, onItem)
Traverse tree structure in post order. Children first - parent last
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
onItem |
onTreeItemWithParentCallback | `` | Callback function to call for every node |
| Callbacks |
onTreeItemWithParentCallback(nodeid, node, parentid, parent)
Callback for iterating nodes and providing parent in parameters
Returns: number - returns break to break the loop and exit. returns skip to skip node's branch traversing.
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | The node id |
node |
object | `` | The node context object |
parentid |
string | `` | The parent node id |
parent |
object | `` | The parent node context object |
loopPreOrder(thisArg, arg0, arg1)
Traverse tree structure in pre order. Parent first - children next
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
arg0 |
string | `` | The node id to start traversing |
arg1 |
onTreeItemWithParentCallback | `` | A callback function to call for every node |
| Callbacks |
onTreeItemWithParentCallback(nodeid, node, parentid, parent)
Callback for iterating nodes and providing parent in parameters
Returns: number - returns break to break the loop and exit. returns skip to skip node's branch traversing.
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | The node id |
node |
object | `` | The node context object |
parentid |
string | `` | The parent node id |
parent |
object | `` | The parent node context object |
moveChildren(fromNodeid, toNodeId)
Moves children form one node to another.
| Param | Type | Default | Description |
|---|---|---|---|
fromNodeid |
string | `` | Source node node id |
toNodeId |
string | `` | Destination node id |
node(nodeid)
Returns context object
Returns: object - context object of the node
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | Node id |
parent(nodeid)
Returns context object of the parent node
Returns: object - returns context object of the parent node
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | Node id |
parentid(nodeid)
Returns parent node id
Returns: string - returns parent node id
| Param | Type | Default | Description |
|---|---|---|---|
nodeid |
string | `` | Node id |
validate()
Validates internal data integrity of the structure
Returns: boolean - returns true if structure pass validation
zipUp(thisArg, firstNodeId, secondNodeid, onZip)
Iterates hierarchy nodes by pairs starting with given pair of start and second nodes and up to the root of the hierarchy. Breaks iteration when callback function returns true.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
firstNodeId |
string | `` | The first node to start iteration |
secondNodeid |
string | `` | The second node to start iteration |
onZip |
onZipUpPairCallback | `` | Callback function to call for every pair of nodes on the way up in the tree structure |
| Callbacks |
onZipUpPairCallback(firstNodeId, firstParentId, secondNodeid, secondParentId)
Callback function to return pairs of nodes
Returns: boolean - returns true to break the iteration of nodes and exit.
| Param | Type | Default | Description |
|---|---|---|---|
firstNodeId |
string | `` | First node id |
firstParentId |
string | `` | Parent id of the first node |
secondNodeid |
string | `` | Second node id |
secondParentId |
string | `` | Parent id of the second node |
Creates Tree Levels structure. It is diagraming specific auxiliary structure that keeps tree nodes order level by level.
TreeLevels
TreeLevels(source)
Creates Tree Levels structure. It is diagraming specific auxiliary structure that keeps tree nodes order level by level.
Returns: TreeLevels - returns tree levels structure.
| Param | Type | Default | Description |
|---|---|---|---|
source |
TreeLevels | undefined |
Optional source object to clone content from into the new instance of the structure. |
addItem(levelIndex, itemid, context)
Adds element
| Param | Type | Default | Description |
|---|---|---|---|
levelIndex |
number | `` | Level index |
itemid |
string | `` | New element id |
context |
object | `` | Context object |
addLevel(level, context)
Adds new level. Structure keeps levels sorted by their indexes. The level index can be positive and negative as well. Structure auto expands collection of levels in both directions and keeps them ordered.
| Param | Type | Default | Description |
|---|---|---|---|
level |
number | `` | New level index |
context |
object | `` | Context object |
binarySearch(thisArg, levelIndex, onGetDistance)
Searches element at level using binary search
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
levelIndex |
number | `` | Level index to search element at |
onGetDistance |
onTreeLevelDistanceCallback | `` | A callback function to measure distance for element |
| Callbacks |
onTreeLevelDistanceCallback(itemid, item)
Callback for finding distance for element
Returns: number - returns distance for the element
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
number | `` | Element id |
item |
object | `` | Context object |
clone()
Clones tree levels structure.
Returns: TreeLevels - returns cloned copy of the structure
createLevel(index)
Creates new level
Returns: object - returns new level empty context object
| Param | Type | Default | Description |
|---|---|---|---|
index |
index | `` | New level index |
getEndLevelIndex(itemid)
Returns element's end level index in the structure. Element may occupy multiple levels of the tree levels structure.
Returns: number - returns end level index
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | Element id |
getItemAtPosition(levelIndex, position)
Gets element at position
Returns: number - returns element id
| Param | Type | Default | Description |
|---|---|---|---|
levelIndex |
number | `` | Level index |
position |
number | `` | Item position |
getItemContext(itemid)
Gets element context object
Returns: object - returns context object of the element
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | Element id |
getItemPosition(itemid, level)
Gets element position at level
Returns: number - returns position of the element
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | Element id |
level |
number | `` | Level index |
getLevelLength(levelIndex)
Gets number of elements at level
Returns: number - returns number of elements at the level
| Param | Type | Default | Description |
|---|---|---|---|
levelIndex |
number | `` | Level index |
getNextItem(itemid, itemLevel)
Gets next element
Returns: number - returns next element id
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | Element id |
itemLevel |
number | `` | Level index |
getPrevItem(itemid, itemLevel)
Gets previous element
Returns: number - returns previous element id
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | Element id |
itemLevel |
number | `` | Level index |
getStartLevelIndex(itemid)
Returns element's start level index in the structure. Element may occupy multiple levels of the tree levels structure.
Returns: number - returns start level index
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | The element id |
hasItem(itemid)
Checks if structure contains element
Returns: boolean - returns true if structure contains given element id
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | Element id |
hasLevel(levelIndex)
Checks if structure contains level
Returns: boolean - returns true if structure contains given level index
| Param | Type | Default | Description |
|---|---|---|---|
levelIndex |
number | `` | Level index |
isEmpty()
Checks if structure has elements.
Returns: boolean - returns true if structure has elements.
length()
Number of levels
Returns: number - returns number of levels in structure.
loopFromItem(thisArg, itemid, isLeft, onItem, level)
Loops level elements starting with the given item
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
itemid |
string | `` | Start element id |
isLeft |
boolean | `` | If true then method loops leftward |
onItem |
onTreeLevelMergedItemCallback | `` | Callback function to call for every item |
level |
number | `` | Level index |
| Callbacks |
onTreeLevelMergedItemCallback(itemid, item)
Callback for iterating items
Returns: number - returns true to break iteration process.
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
number | `` | Element id |
item |
object | `` | Context object |
loopItems(thisArg, onItem)
Loops elements level by level
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
onItem |
onTreeLevelsItemCallback | `` | A callback function to call for every item |
| Callbacks |
onTreeLevelsItemCallback(itemid, item, position, levelIndex, level)
Callback function for iteration of elements level by level
Returns: boolean - returns true to break iteration process.
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | Element id |
item |
object | `` | Element context object |
position |
number | `` | Position of the element at level |
levelIndex |
number | `` | Level index |
level |
object | `` | Level context object |
loopLevelItems(thisArg, levelIndex, onItem)
Loops level elements
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
levelIndex |
number | `` | Level index |
onItem |
onTreeLevelItemCallback | `` | A callback function to call for every item |
| Callbacks |
onTreeLevelItemCallback(itemid, item, position)
Callback function for iteration of level elements
Returns: boolean - returns true to break iteration process.
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
string | `` | Element id |
item |
object | `` | Context object of the element |
position |
number | `` | Position of the element at level |
loopLevels(thisArg, onItem)
Loops levels
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
onItem |
onTreeLevelCallback | `` | A callback function to call for every level |
| Callbacks |
onTreeLevelCallback(levelIndex, level)
Callback function for iteration of levels
Returns: boolean - returns true to break iteration process.
| Param | Type | Default | Description |
|---|---|---|---|
levelIndex |
number | `` | Level index |
level |
object | `` | Context object |
loopLevelsFromItem(thisArg, itemid, isBelow, onItem)
Loops levels starting with the given element end level. Element may occupy multiple levels, so this method starts level iteration from next level after or before item levels.
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
itemid |
string | `` | Element id |
isBelow |
boolean | `` | If true then method loops levels backward |
onItem |
onTreeLevelCallback | `` | Callback function to call for every level |
| Callbacks |
onTreeLevelCallback(levelIndex, level)
Callback function for iteration of levels
Returns: boolean - returns true to break iteration process.
| Param | Type | Default | Description |
|---|---|---|---|
levelIndex |
number | `` | Level index |
level |
object | `` | Context object |
loopLevelsReversed(thisArg, onItem)
Loops levels in reversed order
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
onItem |
onTreeLevelCallback | `` | A callback function to call for every level |
| Callbacks |
onTreeLevelCallback(levelIndex, level)
Callback function for iteration of levels
Returns: boolean - returns true to break iteration process.
| Param | Type | Default | Description |
|---|---|---|---|
levelIndex |
number | `` | Level index |
level |
object | `` | Context object |
loopMerged(thisArg, getItemWeight, onItem)
Loops merged elements of tree level structure by weight
| Param | Type | Default | Description |
|---|---|---|---|
thisArg |
Object | `` | The callback function invocation context |
getItemWeight |
onTreeLevelItemWeightCallback | `` | Callback to measure weight of the element |
onItem |
onTreeLevelMergedItemCallback | `` | Callback to iterate merged elements |
| Callbacks |
onTreeLevelItemWeightCallback(itemid, item)
Callback for finding weight of element
Returns: number - returns distance for the element
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
number | `` | Element id |
item |
object | `` | Context object |
onTreeLevelMergedItemCallback(itemid, item)
Callback for iterating items
Returns: number - returns true to break iteration process.
| Param | Type | Default | Description |
|---|---|---|---|
itemid |
number | `` | Element id |
item |
object | `` | Context object |