Algorithms

family

Creates a family object

primitives.common.family

Constructor

family(source)

Creates a family object

Returns: family - returns new instance of family structure

ParamTypeDefaultDescription
sourcefamilyundefinedReference to optional family object to clone properties from

Constants

NameTypeDefaultDescription
BREAKnumber1B R E A K
SKIPnumber2S K I P

Functions

add(parents, nodeid, node)

Adds new family member

ParamTypeDefaultDescription
parentsstring[]A collection of parents ids
nodeidstringAn id of the new node
nodeobjectA reference to the new node

adopt(parents, nodeid)

Makes node to be a child of every parent in the collection of parents

ParamTypeDefaultDescription
parentsstring[]A collection of parents ids
nodeidstringAn id of the new node

bundleChildren(parent, children, bundleItemId, bundleItem)

Adds extra budnle 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

ParamTypeDefaultDescription
parentstringThe parent node id
childrenstring[]The collection of child nodes ids
bundleItemIdstringThe bundle node id
bundleItemobjectThe bundle item context object

bundleParents(child, parents, bundleItemId, bundleItem)

Adds extra budnle 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

ParamTypeDefaultDescription
childstringThe parent node id
parentsstring[]The collection of child nodes ids
bundleItemIdstringThe bundle node id
bundleItemobjectThe 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

ParamTypeDefaultDescription
parentstringThe parent node id

countParents(child)

Returns number of parents

Returns: number - number of parents

ParamTypeDefaultDescription
childstringThe child node id

eliminateManyToMany(onNewBundleItem)

Eliminates many to many relations in family structure It is needed to simplify layout process of the diagram

ParamTypeDefaultDescription
onNewBundleItemonNewFamilyNodeCallbackCallback function for creation of new bundle node

Callbacks

onNewFamilyNodeCallback()

Callback function for cretion of new family nodes

Returns: object - returns new family node.

findLargestRoot()

Finds root node having largest number of nodes in its hierachy

Returns: string - returns largest sub-hierarchy root node id.

firstChild(parent)

First available child

Returns: string - returns first available child id or null.

ParamTypeDefaultDescription
parentstringThe parent node id

firstParent(child)

First available parent

Returns: string - returns first available parent id or null.

ParamTypeDefaultDescription
childstringThe child node id

getFamilyWithoutGrandParentsRelations()

Eliminates direct relations between grand parent nodes.

Returns: family - returns family structure without direct grand parent relations.

getGraph()

Creates graph structure out of the family structure.

Returns: graph - returns graph structure of the family.

getPlanarFamily(treeLevels)

Eliminates crossing parent child relations between nodes based of nodes order in treeLevels structure.

Returns: family - returns planar family structure.

ParamTypeDefaultDescription
treeLevelstreeLevelsTree levels structure keeps orders of nodes level by level.

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.

ParamTypeDefaultDescription
parentsstring[]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 struture

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
onItemonFamilyItemCallbackA 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

ParamTypeDefaultDescription
itemidstringThe node id
itemobjectThe node

loopChildren(thisArg, nodeid, onItem)

Loops through child nodes of family struture level by level

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
nodeidstringThe node id to start children traversing
onItemonFamilyItemWithLevelCallbackA 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.

ParamTypeDefaultDescription
itemidstringThe node id
itemobjectThe node
levelIndexnumberThe node level index

loopLevels(thisArg, parentAligned, onItem)

Loops through nodes of family struture level by level. This function aligns nodes top or bottom.

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
parentAlignedbooleanTrue if nodes should be placed at the next level after their parents level, otherwise nodes placed at levels close to their children.
onItemonFamilyItemWithLevelCallbackA 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.

ParamTypeDefaultDescription
itemidstringThe node id
itemobjectThe node
levelIndexnumberThe node level index

loopNeighbours(thisArg, itemid, onItem)

Loops through the node neighbours of the family struture level by level

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
itemidstringThe node id to start traversing neighbour nodes
onItemonFamilyItemNeighbourCallbackA 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.

ParamTypeDefaultDescription
itemidstringThe node id
itemobjectThe node
levelIndexnumberThe neigbour node distance from the start node

loopParents(thisArg, nodeid, onItem)

Loops through parent nodes of family struture level by level

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
nodeidstringThe node id to start parents traversing
onItemonFamilyItemWithLevelCallbackA 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.

ParamTypeDefaultDescription
itemidstringThe node id
itemobjectThe node
levelIndexnumberThe node level index

loopRoots(thisArg, onItem)

Loops root nodes of family structure.

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
onItemonFamilyItemCallbackA 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

ParamTypeDefaultDescription
itemidstringThe node id
itemobjectThe node

loopTopo(thisArg, onItem)

Loops through topologically sorted nodes of family struture

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
onItemonFamilyTopoCallbackA 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.

ParamTypeDefaultDescription
itemidstringThe node id
itemobjectThe node
positionnumberThe node position in the sequence

loopTopoReversed(thisArg, onItem)

Loops through reversed order topologically sorted nodes of family struture

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
onItemonFamilyTopoCallbackA 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.

ParamTypeDefaultDescription
itemidstringThe node id
itemobjectThe node
positionnumberThe 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

ParamTypeDefaultDescription
nodeidstringThe id of the node

optimizeReferences(onNewBundleItem)

Optimizes references between family members. It creates bundles eliminating excessive intersecions between nodes relations.

ParamTypeDefaultDescription
onNewBundleItemonNewFamilyNodeCallbackCallback function to create a new family node context object.

Callbacks

onNewFamilyNodeCallback()

Callback function for cretion of new family nodes

Returns: object - returns new family node.

removeNode(nodeid)

Removes node

ParamTypeDefaultDescription
nodeidstringThe id of the node

removeRelation(fromid, toid)

Remove parent child relation

Returns: true - if relation was broken

ParamTypeDefaultDescription
fromidstringThe parent node id
toidstringThe child node id

validate(info)

Validates internal data structure consitency of the family.

ParamTypeDefaultDescription
infoobjectOptional validation object.

FamilyAlignment

Creates family alignment data structure. This structure aligns horizontaly planar family of nodes.

primitives.common.FamilyAlignment

Constructor

FamilyAlignment(thisArg, family, treeLevels, onItemSize)

Creates family alignment data structure. This structure aligns horizontaly planar family of nodes.

Returns: FamilyAlignment - returns family alignment structure

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
familyfamilyFamily data structure
treeLevelsTreeLevelsThree levels data structure
onItemSizeonFamilyAlignmentItemSizeCallbackCallback function to measure family node width

Functions

getOffset(nodeid)

Returns horizontal node offset from left margin of the family daigram

Returns: number - node offset

ParamTypeDefaultDescription
nodeidstringFamily node id

FibonacciHeap

Creates Fibonacci Heap structure

primitives.common.FibonacciHeap

Constructor

FibonacciHeap(isMaximum)

Creates Fibonacci Heap structure

Returns: FibonacciHeap - returns new fibonacciheap object

ParamTypeDefaultDescription
isMaximumbooleanIs maximum heap

Functions

Result(node)

undefined

add(key, priority, item)

Adds a new item into the heap

ParamTypeDefaultDescription
keystringA key of the new element
prioritynumberA priority of the new element
itemobjectA context object of the new element

deleteKey(key)

Deletes heap element by key

ParamTypeDefaultDescription
keystringThe 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

ParamTypeDefaultDescription
keystringThe 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

ParamTypeDefaultDescription
keystringThe key of the element
prioritynumberPriority

validate()

Validates internal structure consistency.

Returns: boolean - returns true if structure pass data consistency check.

graph

Creates graph structure

primitives.common.graph

Constructor

graph()

Creates graph structure

Returns: graph - returns graph object

Functions

addEdge(from, to, edge)

Adds edge to the graph

ParamTypeDefaultDescription
fromstringThe id of the start node
tostringThe id of the end node
edgeobjectThe edge contextual object

edge(from, to)

Returns edge context object

Returns: object - the edge's context object

ParamTypeDefaultDescription
fromstringThe edge's from node id
tostringThe edge's to node id

getMinimumWeightGrowthSequence(thisArg, startNode, onEdgeWeight, onItem)

Get minimum weight graph growth sequence. The sequence of the traversing order of the graph nodes.

ParamTypeDefaultDescription
thisArgobjectThe callback function invocation context
startNodestringundefinedThe optional start node id
onEdgeWeightgetGraphEdgeWeightCallbackCallback function to get weight of an edge.
onItemonNodeCallbackA callback function to be called for every node of the growth sequence

Callbacks

getGraphEdgeWeightCallback(edge, fromItem, toItem)

Callback for finding edge weight

Returns: number - returns weight of the edge

ParamTypeDefaultDescription
edgeobjectThe edge context object
fromItemstringThe edge's start node id
toItemstringThe edge's end node id

onNodeCallback(to)

Callback function for iterating graphs nodes

ParamTypeDefaultDescription
tostringThe next neighbouring node id

getShortestPath(thisArg, startNode, endNodes, getWeightFunc, onPathFound)

Get shortest path between two nodes in graph. The start and the end nodes are supposed to have connection path.

ParamTypeDefaultDescription
thisArgobjectThe callback function invocation context
startNodestringThe start node id
endNodesstring[]The array of end node ids.
getWeightFuncgetGraphEdgeWeightCallbackCallback function to get weight of an edge.
onItemonNodeCallbackA callback function to be called for every node of the growth sequence
onPathFoundonPathFoundCallbackA callback function to be called for every end node with the optimal connection path

Callbacks

getGraphEdgeWeightCallback(edge, fromItem, toItem)

Callback for finding edge weight

Returns: number - returns weight of the edge

ParamTypeDefaultDescription
edgeobjectThe edge context object
fromItemstringThe edge's start node id
toItemstringThe edge's end node id

onNodeCallback(to)

Callback function for iterating graphs nodes

ParamTypeDefaultDescription
tostringThe next neighbouring node id

onPathFoundCallback(path, to)

Callback for returning optimal connection path for every end node.

ParamTypeDefaultDescription
pathstring[]An array of connection path node ids.
tostringThe end node id, the connection path is found for.

getSpanningTree(startNode, getWeightFunc)

Get maximum spanning tree. Graph may have disconnected sub graphs, so start node is nessasary.

Returns: tree - returns tree structure containing maximum spanning tree of the graph

ParamTypeDefaultDescription
startNodestringThe node to start searching for maximum spanning tree. Graph is not nessasary connected
getWeightFuncgetGraphEdgeWeightCallbackCallback function to get weight of an edge.

Callbacks

getGraphEdgeWeightCallback(edge, fromItem, toItem)

Callback for finding edge weight

Returns: number - returns weight of the edge

ParamTypeDefaultDescription
edgeobjectThe edge context object
fromItemstringThe edge's start node id
toItemstringThe edge's end node id

getTotalWeightGrowthSequence(thisArg, onEdgeWeight, onItem)

Get graph growth sequence. The sequence of graph traversing order.

ParamTypeDefaultDescription
thisArgobjectThe callback function invocation context
getWeightFuncgetGraphEdgeWeightCallbackCallback function to get weight of an edge.
onItemonNodeCallbackA callback function to be called for every node of the growth sequence

Callbacks

getGraphEdgeWeightCallback(edge, fromItem, toItem)

Callback for finding edge weight

Returns: number - returns weight of the edge

ParamTypeDefaultDescription
edgeobjectThe edge context object
fromItemstringThe edge's start node id
toItemstringThe edge's end node id

onNodeCallback(to)

Callback function for iterating graphs nodes

ParamTypeDefaultDescription
tostringThe next neighbouring node id

hasNode(from)

Returns true if node exists in the graph

Returns: boolean - returns true if node exists

ParamTypeDefaultDescription
fromstringThe node id

loopNodeEdges(thisArg, itemid, onEdge)

Loop edges of the node

ParamTypeDefaultDescription
thisArgobjectThe callback function invocation context
itemidstringThe node id
onEdgeonEdgeCallbackA callback function to call for every edge of the node

Callbacks

onEdgeCallback(to, edge)

Callback for iterating edges of the graph's node

ParamTypeDefaultDescription
tostringThe neighbouring node id
edgeObjectThe edge's context object

loopNodes(thisArg, startNode, onItem)

Loop nodes of the graph

ParamTypeDefaultDescription
thisArgobjectThe callback function invocation context
itemidstringundefinedThe optional start node id. If start node is undefined, function loops graphs node starting from first available node
onItemonNodeCallbackA callback function to be called for every neighbouring node

Callbacks

onNodeCallback(to)

Callback function for iterating graphs nodes

ParamTypeDefaultDescription
tostringThe next neighbouring node id

LCA

Creates Lowest Common Ancestor Structure for the given tree

primitives.common.LCA

Constructor

LCA(tree)

Creates Lowest Common Ancestor Structure for the given tree

Returns: LCA - returns lowest common ancestor structure

ParamTypeDefaultDescription
treetreeThe tree structure

Functions

getLowestCommonAncestor(from, to)

Returns lowest common ancestor for the given pair of tree nodes

Returns: string - returns the lowest common ancestor tree node id

ParamTypeDefaultDescription
fromstringThe first tree node id
tostringThe second tree node id

LinkedHashItems

Creates linked hash list collection.

primitives.common.LinkedHashItems

Constructor

LinkedHashItems()

Creates linked hash list collection.

Returns: LinkedHashItems - returns linked hash list structure

Functions

add(key, item)

Adds new item to collection

ParamTypeDefaultDescription
keystringThe new item key
itemobjectThe new item context object value

attach(list)

Appends one list to another

ParamTypeDefaultDescription
listLinkedHashItemsA 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

ParamTypeDefaultDescription
afterKeystringThe key that the new element is placed after
keystringThe new item key
itemobjectThe new item context object value

insertBefore(beforeKey, key, item)

Inserts new item into the list before the given key

ParamTypeDefaultDescription
beforeKeystringThe key that the new element is placed before
keystringThe new item key
itemobjectThe 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

ParamTypeDefaultDescription
keystringThe item's key

iterate(onItem, startKey, endKey)

Loops items of the collection

ParamTypeDefaultDescription
onItemonLinkedHashItemsCallbackCallback function for iterating collection items
startKeystringThe key to start iteration from
endKeystringThe key to end iteration at

Callbacks

onLinkedHashItemsCallback(item, key)

Callback function for iterating list items

Returns: boolean - returns true to break the iteration process

ParamTypeDefaultDescription
itemobjectThe item context object
keystringThe item key

iterateBack(onItem, startKey, endKey)

Loops items of the collection backward

ParamTypeDefaultDescription
onItemonLinkedHashItemsCallbackCallback function for iterating collection items
startKeystringThe key to start iteration from
endKeystringThe key to end iteration at

Callbacks

onLinkedHashItemsCallback(item, key)

Callback function for iterating list items

Returns: boolean - returns true to break the iteration process

ParamTypeDefaultDescription
itemobjectThe item context object
keystringThe item key

nextKey(key)

Gets next key

Returns: string - returns key of the next collection item

ParamTypeDefaultDescription
keystringThe item key

prevKey(key)

Gets previous key

Returns: string - returns key of the previous collection item

ParamTypeDefaultDescription
keystringThe item key

remove(key)

Removes item

ParamTypeDefaultDescription
keystringThe 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

ParamTypeDefaultDescription
keystringThe new item key
itemobjectThe new item context object value

validate(info)

Validates internal data consistensy of the structure

Returns: boolean - returns true if it pass validation

pile

Creates pile structure used to sort and stack segments on top of each other so they occupy minimum number of rows.

primitives.common.pile

Constructor

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

Functions

add(from, to, context)

Adds new segment to pile object.

ParamTypeDefaultDescription
fromnumberLeft margin of segment.
tonumberRight margin of segment.
contextobjectAny 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.

ParamTypeDefaultDescription
thisArgobjctA context object of the callback function invocation.
onItemonPileItemCallbackCallback 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.

ParamTypeDefaultDescription
fromnumberThe left margin of the segment
tonumberThe right margin of the segment
contextobjectThe context of the pile item
offsetnumberIndex of the pile item in the stack

QuadTree

Creates Quad Tree data structure. It distributes points into equal quadrants. So it is equivalent to 2 dimensional binary search tree.

primitives.common.QuadTree

Constructor

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.

ParamTypeDefaultDescription
minimalSizenumberDefines minimal size of the quadrant. This protects structure against unnecessary depth.

Functions

addPoint(point)

Adds point

ParamTypeDefaultDescription
pointPointPoint

getPositions(selection)

Returns collection of quadrands 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.

ParamTypeDefaultDescription
selectionReactRectangular test area to highlight quadrants

loopArea(thisArg, rect, onItem)

Loops rectangular area of quad tree structure

ParamTypeDefaultDescription
thisArgobjectThe callback function invocation context
rectRectRectangular search area
onItemonQuadTreePointCallbackCallback 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.

ParamTypeDefaultDescription
pointPointRectangle

validate()

Validates internal data consistency of quad tree data structure

Returns: boolean - returns true if structure pass validation

RMQ

Creates range minimum query structure

primitives.common.RMQ

Constructor

RMQ(items)

Creates range minimum query structure

Returns: rmq - returns range minimum query structure

ParamTypeDefaultDescription
itemsnumber[]Collection of numbers

Functions

getRangeMinimum(from, to)

Return minimum value for the given range

Returns: number - returns minimum value in the range

ParamTypeDefaultDescription
fromnumberThe left index of the range
tonumberThe 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

ParamTypeDefaultDescription
fromnumberThe left margin index
tonumberThe right margin index

SortedList

Creates self-balancing binary search tree structure.

primitives.common.SortedList

Constructor

SortedList()

Creates self-balancing binary search tree structure.

Returns: SortedList - returns sorted list collection.

Functions

add(value, context, thisArg, onDuplicate)

Adds value to sorted list collection

ParamTypeDefaultDescription
valuenumberThe value
contextobjectThe value context object
thisArgobjectThe callback function invocation context
onDuplicateonSortedListDuplicateCallbackCallback function for duplicates values notification

Callbacks

onSortedListDuplicateCallback(context)

Callback function to notify about duplicate values

ParamTypeDefaultDescription
contextobjctThe context object of the duplicate value

loopBackward(thisArg, fromValue, onItem)

Loops sorted list values backward

ParamTypeDefaultDescription
thisArgobjectThe callback function invocation context
fromValuenumberThe start value to loop items of sorted list
onItemonSortedListItemCallbackCallback 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

ParamTypeDefaultDescription
valuenumberThe value
contextobjectThe value context object

loopForward(thisArg, fromValue, onItem)

Loops sorted list values

ParamTypeDefaultDescription
thisArgobjectThe callback function invocation context
fromValuenumberThe start value to loop items of sorted list
onItemonSortedListItemCallbackCallback 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

ParamTypeDefaultDescription
valuenumberThe value
contextobjectThe 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.

ParamTypeDefaultDescription
fromValuenumberThe 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.

ParamTypeDefaultDescription
fromValuenumberThe value to start search from

remove(value)

Removes value from the sorted list

ParamTypeDefaultDescription
valuenumberThe removed value

validate()

Validate internal data consistency of the self-balancing binary search tree structure

Returns: boolean - returns true if structure pass validation

SpatialIndex

Create spatial index structure. It uses collection of sizes to distribute rectangles into buckets of similar size elements. Elements of the same bucket are aproximated to points. The search of rectangles is transformed to search of points within given range plus offset for maximum linear rectangle size.

primitives.common.SpatialIndex

Constructor

SpatialIndex()

Create spatial index structure. It uses collection of sizes to distribute rectangles into buckets of similar size elements. Elements of the same bucket are aproximated 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.

Functions

addRect(rect)

Adds rectangle to spacial index

ParamTypeDefaultDescription
rectRectRectangle

tree

Creates tree structure

primitives.common.tree

Constructor

tree(source)

Creates tree structure

Returns: tree - returns new tree structure

ParamTypeDefaultDescription
sourcetreeA source tree structure to clone properties from

Constants

NameTypeDefaultDescription
BREAKnumber1B R E A K
SKIPnumber2S K I P

Functions

add(parentid, nodeid, node, position)

Adds new tree item

ParamTypeDefaultDescription
parentidstringParent id
nodeidstringNew node id
nodeobjectContext object of the new node
positionnumberPosition of the new node in the collection of children

adopt(parentid, nodeid)

Adds existing node to the children of the parent node

ParamTypeDefaultDescription
parentidstringParent Node id
nodeidstringNode id

arrangeChildren(nodeid, children)

Orders children of the given node

ParamTypeDefaultDescription
nodeidstringThe node id of the parent node which children should be ordered in the tree structure
childrenstring[]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

ParamTypeDefaultDescription
nodeidstringNode id

countSiblings(nodeid)

Returns number of siblings

Returns: number - returns number of siblings

ParamTypeDefaultDescription
nodeidstringNode id

getChild(parentid, index)

Returns child node by index in the children's collection

Returns: object - returns child node

ParamTypeDefaultDescription
nodeidstringNode id
indexnumberChild index

hasChildren(nodeid)

Returns true if node has children

Returns: boolean - returns true if node has children

ParamTypeDefaultDescription
nodeidstringNode 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

ParamTypeDefaultDescription
nodeidstringNode id

insert(nodeid, bundleid, bundle)

Inserts bundle node into the tree structure. The new budnle node becomes only child node of the parent node. All imediate children of the parent node become children of the inserted bundle node.

ParamTypeDefaultDescription
nodeidstringParent node id
bundleidstringNew bundle node id
bundleobjectContext object of the bundle node

loop(thisArg, onItem)

Loops through nodes of tree struture

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
onItemonTreeItemCallbackCallback function to call for every tree node

Callbacks

onTreeItemCallback(itemid, item)

Callback for iterating tree nodes

Returns: boolean - returns true to break the loop

ParamTypeDefaultDescription
itemidstringThe node id
itemobjectThe node

loopChildren(thisArg, nodeid, onItem)

Loops immediate children of the given node. Breaks iteration if callback function returns true.

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
nodeidstringThe parent node id to loop children of
onItemonTreeChildItemCallbackCallback 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.

ParamTypeDefaultDescription
nodeidstringChild node id
nodeobjectContext object of the child node
indexnumberIndex of the child node
lastIndexnumberIndex 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.

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
nodeidstringThe parent node id to loop children of
fromIndexnumberStart index of iteration
toIndexnumberEnd index of iteration
onItemonTreeNodeWithIndexItemCallbackCallback function to call for every child node

Callbacks

onTreeNodeWithIndexItemCallback(nodeid, node, index)

Callback function to loop theough range of children for the given node

Returns: boolean - returns true to break the iteration of nodes and exit.

ParamTypeDefaultDescription
nodeidstringChild node id
nodeobjectContext object of the child node
indexnumberIndex 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.

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
nodeidstringThe parent node id to loop children of
onItemonTreeChildItemCallbackCallback 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.

ParamTypeDefaultDescription
nodeidstringChild node id
nodeobjectContext object of the child node
indexnumberIndex of the child node
lastIndexnumberIndex of the last child

loopEulerWalk(thisArg, onItem)

Loops tree nodes in "Euler Walk" order

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
onItemonItemEulerWalkCallbackCallback 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.

ParamTypeDefaultDescription
nodeidstringThe node id
nodeobjectContext object of the node
levelnumberThe node's level

loopLevels(thisArg, arg0, arg1)

Loops through child nodes of the tree struture level by level

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
arg0stringThe node id to start children traversing
arg1onTreeItemWithLevelCallbackCallback 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.

ParamTypeDefaultDescription
nodeidstringThe node id
nodeobjectThe node context object
levelIndexnumberThe node level index

loopNeighbours(thisArg, itemid, distance, onItem)

Loops through the node neighbours of the tree struture level by level

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
itemidstringThe node id to start traversing neighbour nodes
distancenumberStop iteration of neighbours when distance exceeds the given value
onItemonTreeItemNeighbourCallbackA 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.

ParamTypeDefaultDescription
itemidstringThe node id
itemobjectThe node
distancenumberThe 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.

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
nodeidstringThe node id to start iteration from
onItemonTreeItemCallbackCallback function to call for every parent node
includingStartItembooleanIf 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

ParamTypeDefaultDescription
itemidstringThe node id
itemobjectThe node

loopPostOrder(thisArg, onItem)

Traverse tree structure in post order. Children first - parent last

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
onItemonTreeItemWithParentCallbackCallback 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.

ParamTypeDefaultDescription
nodeidstringThe node id
nodeobjectThe node context object
parentidstringThe parent node id
parentobjectThe parent node context object

loopPreOrder(thisArg, onItem)

Traverse tree structure in pre order. Parent first - children next

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
onItemonTreeItemWithParentCallbackA 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.

ParamTypeDefaultDescription
nodeidstringThe node id
nodeobjectThe node context object
parentidstringThe parent node id
parentobjectThe parent node context object

moveChildren(fromNodeid, toNodeId)

Moves children form one node to another.

ParamTypeDefaultDescription
fromNodeidstringSource node node id
toNodeIdstringDestination node id

node(nodeid)

Returns context obect

Returns: object - context object of the node

ParamTypeDefaultDescription
nodeidstringNode id

parent(nodeid)

Returns context object of the parent node

Returns: object - returns context object of the parent node

ParamTypeDefaultDescription
nodeidstringNode id

parentid(nodeid)

Returns parent node id

Returns: string - returns parent node id

ParamTypeDefaultDescription
nodeidstringNode 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.

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
firstNodeIdstringThe first node to start iteration
secondNodeidstringThe second node to start iteration
onZiponZipUpPairCallbackCallback 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.

ParamTypeDefaultDescription
firstNodeIdstringFirst node id
firstParentIdstringParent id of the first node
secondNodeidstringSecond node id
secondParentIdstringParent id of the second node

TreeLevels

Creates Tree Levels structure. It is diagraming specific auxiliary structure that keeps tree nodes order level by level.

primitives.common.TreeLevels

Constructor

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.

ParamTypeDefaultDescription
sourceTreeLevelsundefinedOptional source object to clone content from into the new instance of the structure.

Functions

addItem(levelIndex, itemid, context)

Adds element

ParamTypeDefaultDescription
levelIndexnumberLevel index
itemidstringNew element id
contextobjectContext 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.

ParamTypeDefaultDescription
levelnumberNew level index
contextobjectContext object

binarySearch(thisArg, levelIndex, onGetDistance)

Searchs element at level using binary search

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
levelIndexnumberLevel index to search element at
onGetDistanceonTreeLevelDistanceCallbackA callback function to measure distance for element

Callbacks

onTreeLevelDistanceCallback(itemid, item)

Callback for finding distance for element

Returns: number - returns distance for the element

ParamTypeDefaultDescription
itemidnumberElement id
itemobjectConext 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

ParamTypeDefaultDescription
indexindexNew 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

ParamTypeDefaultDescription
itemidstringElement id

getItemAtPosition(levelIndex, position)

Gets element at position

Returns: number - returns element id

ParamTypeDefaultDescription
levelIndexnumberLevel index
positionnumberItem position

getItemContext(itemid)

Gets element context object

Returns: object - returns context object of the element

ParamTypeDefaultDescription
itemidstringElement id

getItemPosition(itemid, level)

Gets element position at level

Returns: number - returns position of the element

ParamTypeDefaultDescription
itemidstringElement id
levelnumberLevel index

getLevelLength(levelIndex)

Gets number of elements at level

Returns: number - returns number of elements at the level

ParamTypeDefaultDescription
levelIndexnumberLevel index

getNextItem(itemid, itemLevel)

Gets next element

Returns: number - returns next element id

ParamTypeDefaultDescription
itemidstringElement id
itemLevelnumberLevel index

getPrevItem(itemid, itemLevel)

Gets previous element

Returns: number - returns previous element id

ParamTypeDefaultDescription
itemidstringElement id
itemLevelnumberLevel 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

ParamTypeDefaultDescription
itemidstringThe element id

hasItem(itemid)

Checks if struture contains element

Returns: boolean - returns true if structure contains given element id

ParamTypeDefaultDescription
itemidstringElement id

hasLevel(levelIndex)

Checks if struture contains level

Returns: boolean - returns true if structure contains given level index

ParamTypeDefaultDescription
levelIndexnumberLevel index

isEmpty()

Chckes 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

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
itemidstringStart element id
isLeftbooleanIf true thenmethod loops leftward
onItemonTreeLevelMergedItemCallbackCallback function to call for every item
levelnumberLevel index

Callbacks

onTreeLevelMergedItemCallback(itemid, item)

Callback for iterating items

Returns: number - returns true to break iteration process.

ParamTypeDefaultDescription
itemidnumberElement id
itemobjectConext object

loopItems(thisArg, onItem)

Loops elements level by level

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
onItemonTreeLevelsItemCallbackA 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.

ParamTypeDefaultDescription
itemidstringElement id
itemobjectElement context object
positionnumberPosition of the element at level
levelIndexnumberLevel index
levelobjectLevel context object

loopLevelItems(thisArg, levelIndex, onItem)

Loops level elements

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
levelIndexnumberLevel index
onItemonTreeLevelItemCallbackA 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.

ParamTypeDefaultDescription
itemidstringElement id
itemobjectContext object of the element
positionnumberPosition of the element at level

loopLevels(thisArg, onItem)

Loops levels

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
onItemonTreeLevelCallbackA 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.

ParamTypeDefaultDescription
levelIndexnumberLevel index
levelobjectContext 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.

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
itemidstringElement id
isBelowbooleanIf true then method loops levels backward
onItemonTreeLevelCallbackCallback function to call for every level

Callbacks

onTreeLevelCallback(levelIndex, level)

Callback function for iteration of levels

Returns: boolean - returns true to break iteration process.

ParamTypeDefaultDescription
levelIndexnumberLevel index
levelobjectContext object

loopLevelsReversed(thisArg, onItem)

Loops levels in reversed order

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
onItemonTreeLevelCallbackA 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.

ParamTypeDefaultDescription
levelIndexnumberLevel index
levelobjectContext object

loopMerged(thisArg, getItemWeight, onItem)

Loops merged elements of tree level structure by weight

ParamTypeDefaultDescription
thisArgObjectThe callback function invocation context
getItemWeightonTreeLevelItemWeightCallbackCallback to measure weight of the element
onItemonTreeLevelMergedItemCallbackCallback to iterate merged elements

Callbacks

onTreeLevelItemWeightCallback(itemid, item)

Callback for finding weight of element

Returns: number - returns distance for the element

ParamTypeDefaultDescription
itemidnumberElement id
itemobjectConext object

onTreeLevelMergedItemCallback(itemid, item)

Callback for iterating items

Returns: number - returns true to break iteration process.

ParamTypeDefaultDescription
itemidnumberElement id
itemobjectConext object
Have questions? Ask for help on Github.