Skip to content

Commit d010700

Browse files
Merge pull request #33 from BasicPrimitives/loops
Loops Optimization
2 parents 3e620ad + bf88bb0 commit d010700

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+7134
-4983
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"no-unused-vars": 0,
1919
"no-fallthrough": 0,
2020
"no-control-regex": 0,
21-
"no-empty": 0
21+
"no-empty": 0,
22+
"no-constant-condition": 0
2223
}
2324
}

ReferenceControlsProcessingDiagram.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@
8484
default:
8585
controlOptions = primitives.famdiagram.getProcessDiagramConfig();
8686
primitives.common.mergeObjects(viewOptions, {
87-
'AddLabelAnnotationsTask': { primaryParent: 'LogicalFamilyTask' },
88-
'RemoveLoopsTask': { primaryParent: 'AddLabelAnnotationsTask' },
89-
'AddSpousesTask': { primaryParent: 'RemoveLoopsTask' },
87+
'RemoveLoopsOptionTask': { relativeItem: 'ItemsOptionTask', placementType: primitives.common.AdviserPlacementType.Right, position: 1 },
88+
89+
'RemoveLoopsTask': { primaryParent: 'LogicalFamilyTask' },
90+
'AddLabelAnnotationsTask': { primaryParent: 'RemoveLoopsTask' },
91+
'AddSpousesTask': { primaryParent: 'AddLabelAnnotationsTask' },
9092
'HideGrandParentsConnectorsTask': { primaryParent: 'AddSpousesTask' },
9193
'NormalizeLogicalFamilyTask': { primaryParent: 'HideGrandParentsConnectorsTask' },
9294
'OrderFamilyNodesTask': { primaryParent: 'NormalizeLogicalFamilyTask' },

apireference/algorithms.md

Lines changed: 130 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,28 @@ Eliminates direct relations between grand parent nodes.
146146
Returns: `family` - returns family structure without direct grand parent relations.
147147

148148

149-
`getGraph()`
149+
`getGraph(thisArg, onEdge)`
150150

151151
Creates graph structure out of the family structure.
152152

153153
Returns: `graph` - returns graph structure of the family.
154154

155+
| Param | Type | Default | Description |
156+
| --- | --- | --- | --- |
157+
| `thisArg` | Object | `` | The callback function invocation context |
158+
| `onEdge` | onFamilyEdgeCallback | `` | A callback function to call for every new edge added to the final graph |
159+
**Callbacks**
160+
161+
`onFamilyEdgeCallback(from, to)`
162+
163+
Callback for getting default edge value
164+
165+
Returns: `object` - returns new edge object.
166+
167+
| Param | Type | Default | Description |
168+
| --- | --- | --- | --- |
169+
| `from` | string | `` | From node id |
170+
| `to` | string | `` | The node |
155171

156172
`getPlanarFamily(treeLevels)`
157173

@@ -189,7 +205,7 @@ Returns true if structure has nodes.
189205

190206
`loop(thisArg, onItem)`
191207

192-
Loops through nodes of family struture
208+
Loops through nodes of family structure
193209

194210
| Param | Type | Default | Description |
195211
| --- | --- | --- | --- |
@@ -210,7 +226,7 @@ Callback for iterating family nodes
210226

211227
`loopChildren(thisArg, nodeid, onItem)`
212228

213-
Loops through child nodes of family struture level by level
229+
Loops through child nodes of family structure level by level
214230

215231
| Param | Type | Default | Description |
216232
| --- | --- | --- | --- |
@@ -233,7 +249,7 @@ Callback for iterating family nodes level by level
233249

234250
`loopLevels(thisArg, parentAligned, onItem)`
235251

236-
Loops through nodes of family struture level by level. This function aligns nodes top or bottom.
252+
Loops through nodes of family structure level by level. This function aligns nodes top or bottom.
237253

238254
| Param | Type | Default | Description |
239255
| --- | --- | --- | --- |
@@ -256,7 +272,7 @@ Callback for iterating family nodes level by level
256272

257273
`loopNeighbours(thisArg, itemid, onItem)`
258274

259-
Loops through the node neighbours of the family struture level by level
275+
Loops through the node neighbours of the family structure level by level
260276

261277
| Param | Type | Default | Description |
262278
| --- | --- | --- | --- |
@@ -279,7 +295,7 @@ Callback for iterating family node neighbours level by level
279295

280296
`loopParents(thisArg, nodeid, onItem)`
281297

282-
Loops through parent nodes of family struture level by level
298+
Loops through parent nodes of family structure level by level
283299

284300
| Param | Type | Default | Description |
285301
| --- | --- | --- | --- |
@@ -323,7 +339,7 @@ Callback for iterating family nodes
323339

324340
`loopTopo(thisArg, onItem)`
325341

326-
Loops through topologically sorted nodes of family struture
342+
Loops through topologically sorted nodes of family structure
327343

328344
| Param | Type | Default | Description |
329345
| --- | --- | --- | --- |
@@ -345,7 +361,7 @@ Callback for iterating family nodes in topological sort order
345361

346362
`loopTopoReversed(thisArg, onItem)`
347363

348-
Loops through reversed order topologically sorted nodes of family struture
364+
Loops through reversed order topologically sorted nodes of family structure
349365

350366
| Param | Type | Default | Description |
351367
| --- | --- | --- | --- |
@@ -391,6 +407,17 @@ Callback function for cretion of new family nodes
391407
Returns: `object` - returns new family node.
392408

393409

410+
`removeChildRelation(parentid, childid)`
411+
412+
Removes child relation
413+
414+
Returns: `true` - if relation was broken
415+
416+
| Param | Type | Default | Description |
417+
| --- | --- | --- | --- |
418+
| `parentid` | string | `` | The parent node id |
419+
| `childid` | string | `` | The child node id |
420+
394421
`removeNode(nodeid)`
395422

396423
Removes node
@@ -401,14 +428,14 @@ Removes node
401428

402429
`removeRelation(fromid, toid)`
403430

404-
Remove parent child relation
431+
Removes first available parent child or child parent relation
405432

406433
Returns: `true` - if relation was broken
407434

408435
| Param | Type | Default | Description |
409436
| --- | --- | --- | --- |
410-
| `fromid` | string | `` | The parent node id |
411-
| `toid` | string | `` | The child node id |
437+
| `fromid` | string | `` | From node id |
438+
| `toid` | string | `` | To node id |
412439

413440
`validate(info)`
414441

@@ -469,11 +496,6 @@ Creates Fibonacci Heap structure
469496

470497
### Functions
471498

472-
`Result(node)`
473-
474-
undefined
475-
476-
477499
`add(key, priority, item)`
478500

479501
Adds a new item into the heap
@@ -558,6 +580,64 @@ Adds edge to the graph
558580
| `to` | string | `` | The id of the end node |
559581
| `edge` | object | `` | The edge contextual object |
560582

583+
`dfsLoop(thisArg, startNode, onEdge, onNode)`
584+
585+
Depth first search loop
586+
587+
| Param | Type | Default | Description |
588+
| --- | --- | --- | --- |
589+
| `thisArg` | object | `` | The callback function invocation context |
590+
| `startNode` | string | `` | The start node id |
591+
| `onEdge` | onPathEdgeCallback | `` | A callback function to call for every edge of the graph |
592+
| `onNode` | onNodeCallback | `` | A callback function to be called for every neighbouring node |
593+
**Callbacks**
594+
595+
`onPathEdgeCallback(from, to, edge)`
596+
597+
Callback for iterating path edges
598+
599+
Returns: `boolean` - returns true if edge is usable
600+
601+
| Param | Type | Default | Description |
602+
| --- | --- | --- | --- |
603+
| `from` | string | `` | The from node id |
604+
| `to` | string | `` | The to node id |
605+
| `edge` | Object | `` | The edge's context object |
606+
607+
`onNodeCallback(to)`
608+
609+
Callback function for iterating graphs nodes
610+
611+
Returns: `boolean` - returns true to break loop
612+
613+
| Param | Type | Default | Description |
614+
| --- | --- | --- | --- |
615+
| `to` | string | `` | The next neighbouring node id |
616+
617+
`dfsPath(thisArg, startNode, endNode, onEdge)`
618+
619+
Search any path from node to node using depth first search
620+
621+
| Param | Type | Default | Description |
622+
| --- | --- | --- | --- |
623+
| `thisArg` | object | `` | The callback function invocation context |
624+
| `startNode` | string | `` | The start node id |
625+
| `endNode` | string | `` | The end node id. |
626+
| `onEdge` | onPathEdgeCallback | `` | A callback function to call for every edge of the node |
627+
**Callbacks**
628+
629+
`onPathEdgeCallback(from, to, edge)`
630+
631+
Callback for iterating path edges
632+
633+
Returns: `boolean` - returns true if edge is usable
634+
635+
| Param | Type | Default | Description |
636+
| --- | --- | --- | --- |
637+
| `from` | string | `` | The from node id |
638+
| `to` | string | `` | The to node id |
639+
| `edge` | Object | `` | The edge's context object |
640+
561641
`edge(from, to)`
562642

563643
Returns edge context object
@@ -569,6 +649,29 @@ Returns edge context object
569649
| `from` | string | `` | The edge's from node id |
570650
| `to` | string | `` | The edge's to node id |
571651

652+
`getLevelGraph(thisArg, startNode, onEdge)`
653+
654+
Get Level Graph starting with `startNode`
655+
656+
| Param | Type | Default | Description |
657+
| --- | --- | --- | --- |
658+
| `thisArg` | object | `` | The callback function invocation context |
659+
| `startNode` | string | `` | The start node id |
660+
| `onEdge` | onPathEdgeCallback | `` | A callback function to call for every edge of the graph |
661+
**Callbacks**
662+
663+
`onPathEdgeCallback(from, to, edge)`
664+
665+
Callback for iterating path edges
666+
667+
Returns: `boolean` - returns true if edge is usable
668+
669+
| Param | Type | Default | Description |
670+
| --- | --- | --- | --- |
671+
| `from` | string | `` | The from node id |
672+
| `to` | string | `` | The to node id |
673+
| `edge` | Object | `` | The edge's context object |
674+
572675
`getMinimumWeightGrowthSequence(thisArg, startNode, onEdgeWeight, onItem)`
573676

574677
Get minimum weight graph growth sequence. The sequence of the traversing order of the graph nodes.
@@ -597,6 +700,8 @@ Callback for finding edge weight
597700

598701
Callback function for iterating graphs nodes
599702

703+
Returns: `boolean` - returns true to break loop
704+
600705
| Param | Type | Default | Description |
601706
| --- | --- | --- | --- |
602707
| `to` | string | `` | The next neighbouring node id |
@@ -611,7 +716,6 @@ Get shortest path between two nodes in graph. The start and the end nodes are su
611716
| `startNode` | string | `` | The start node id |
612717
| `endNodes` | string[] | `` | The array of end node ids. |
613718
| `getWeightFunc` | getGraphEdgeWeightCallback | `` | Callback function to get weight of an edge. |
614-
| `onItem` | onNodeCallback | `` | A callback function to be called for every node of the growth sequence |
615719
| `onPathFound` | onPathFoundCallback | `` | A callback function to be called for every end node with the optimal connection path |
616720
**Callbacks**
617721

@@ -627,14 +731,6 @@ Callback for finding edge weight
627731
| `fromItem` | string | `` | The edge's start node id |
628732
| `toItem` | string | `` | The edge's end node id |
629733

630-
`onNodeCallback(to)`
631-
632-
Callback function for iterating graphs nodes
633-
634-
| Param | Type | Default | Description |
635-
| --- | --- | --- | --- |
636-
| `to` | string | `` | The next neighbouring node id |
637-
638734
`onPathFoundCallback(path, to)`
639735

640736
Callback for returning optimal connection path for every end node.
@@ -695,6 +791,8 @@ Callback for finding edge weight
695791

696792
Callback function for iterating graphs nodes
697793

794+
Returns: `boolean` - returns true to break loop
795+
698796
| Param | Type | Default | Description |
699797
| --- | --- | --- | --- |
700798
| `to` | string | `` | The next neighbouring node id |
@@ -744,6 +842,8 @@ Loop nodes of the graph
744842

745843
Callback function for iterating graphs nodes
746844

845+
Returns: `boolean` - returns true to break loop
846+
747847
| Param | Type | Default | Description |
748848
| --- | --- | --- | --- |
749849
| `to` | string | `` | The next neighbouring node id |
@@ -1389,7 +1489,7 @@ Inserts bundle node into the tree structure. The new budnle node becomes only ch
13891489

13901490
`loop(thisArg, onItem)`
13911491

1392-
Loops through nodes of tree struture
1492+
Loops through nodes of tree structure
13931493

13941494
| Param | Type | Default | Description |
13951495
| --- | --- | --- | --- |
@@ -1505,7 +1605,7 @@ Callback for iterating nodes in euler walk order
15051605

15061606
`loopLevels(thisArg, arg0, arg1)`
15071607

1508-
Loops through child nodes of the tree struture level by level
1608+
Loops through child nodes of the tree structure level by level
15091609

15101610
| Param | Type | Default | Description |
15111611
| --- | --- | --- | --- |
@@ -1528,7 +1628,7 @@ Callback for iterating the tree nodes level by level
15281628

15291629
`loopNeighbours(thisArg, itemid, distance, onItem)`
15301630

1531-
Loops through the node neighbours of the tree struture level by level
1631+
Loops through the node neighbours of the tree structure level by level
15321632

15331633
| Param | Type | Default | Description |
15341634
| --- | --- | --- | --- |
@@ -1853,7 +1953,7 @@ Returns element's start level index in the structure. Element may occupy multipl
18531953

18541954
`hasItem(itemid)`
18551955

1856-
Checks if struture contains element
1956+
Checks if structure contains element
18571957

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

@@ -1863,7 +1963,7 @@ Checks if struture contains element
18631963

18641964
`hasLevel(levelIndex)`
18651965

1866-
Checks if struture contains level
1966+
Checks if structure contains level
18671967

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

apireference/enums.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ Line style of connection lines.
160160
| `Dotted` | number | `1` | Dotted |
161161
| `Solid` | number | `0` | Solid |
162162

163+
## <a name="primitives.common.LoopsLayoutMode" id="primitives.common.LoopsLayoutMode">LoopsLayoutMode</a>
164+
Loops layout mode. Configuration may contain loop references between items, so control tries to find layout minimizing number of loops between levels, so majority of references ideally should go in one direction. This option disables optimization and forces items levels order to match their order in `items` collection. For example if you have two nodes `A` and `B` referencing each other as a parent, then it is not defined which one is going to be on the top of the diagram. Set this option to `KeepItemsOrder`, if you need the first item in your collection to be on the top, otherwise control will optimize loops layout in order to minimize number of loops in diagram.
165+
166+
`primitives.common.LoopsLayoutMode`
167+
168+
| Name | Type | Value | Description |
169+
| --- | --- | --- | --- |
170+
| `KeepItemsOrder` | number | `1` | Keeps order of items on levels, the same as in `items` collection property. |
171+
| `Optimized` | number | `0` | Optimized. Control searches for layout producing minimal number of feedback loops in the diagram. |
172+
163173
## <a name="primitives.common.NavigationMode" id="primitives.common.NavigationMode">NavigationMode</a>
164174
Interactivity mode. Control implements standard behaivour of classic desktop UI controls. It supports single selected node - cursor. It supports on mouse over node visual feedback - highlight. It supports selection of group of nodes - selected items. All that functionality can be disabled depending on your application requirements.
165175

apireference/famdiagram.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Family Chart configuration object. Use this object as a reference for available
4040
| `enableMatrixLayout` | boolean | `false` | This option enables automatic layout of nodes sharing the same set of parents and children in form of matrix. |
4141
| `groupByType` | GroupByType | `2` | This property sets loose nodes alignment between rows. Nodes can be placed close towards parents or children. |
4242
| `hideGrandParentsConnectors` | boolean | `false` | Set this property to enable hiding of direct connectors to grand parents. It helps to reduce diagrams connectors layout complexity. |
43+
| `loopsLayoutMode` | LoopsLayoutMode | `primitives.common.LoopsLayoutMode.Optimized` | Loops layout mode. Configuration may contain loop references between items, so control tries to find layout minimizing number of loops between levels, so majority of references ideally should go in one direction. This option disables optimization and forces items levels order to match their order in `items` collection. For example if you have two nodes `A` and `B` referencing each other as a parent, then it is not defined which one is going to be on the top of the diagram. Set this option to `KeepItemsOrder`, if you need the first item in your collection to be on the top, otherwise control will optimize loops layout in order to minimize number of loops in diagram. |
4344
| `maximumColumnsInMatrix` | number | `6` | Sets maximum number of columns in the matrix formation. The matrix formation stays squared as long as total number of columns does not exceed this property value. In order to shape nodes into matrix formation they should share the same set of parents and children. See `enableMatrixLayout` property. |
4445
| `minimalVisibility` | Visibility | `2` | Minimal nodes visibility in the diagram. If auto fit of the diagram into current page size is enabled, then this option controls minimum allowed size of the diagram nodes. |
4546
| `minimumMatrixSize` | number | `4` | Sets Minimum number of nodes needed to be shaped into matrix formtion. In order to shape nodes in form of matrix they should share the same set of parents and children. See `enableMatrixLayout` property. |

apireference/functions.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ Callback function to iterate over pairs of crosssing rectangles
109109
| `rect1` | Rect | `` | First rectangle |
110110
| `rect2` | Rect | `` | Second rectangle |
111111

112+
## <a name="primitives.common.getFamilyLoops" id="primitives.common.getFamilyLoops">getFamilyLoops</a>
113+
114+
This function finds [optimal collection of feedback edges](https://en.wikipedia.org/wiki/Feedback_arc_set) needed to be cut in order to eliminate loops in family structure.
115+
116+
Returns: `Edge[]` - returns optimal collection of feedback loops
117+
118+
| Param | Type | Default | Description |
119+
| --- | --- | --- | --- |
120+
| `family` | Family | `` | Family structure |
121+
112122
## <a name="primitives.common.getGreen" id="primitives.common.getGreen">getGreen</a>
113123

114124
Gets green value of HEX color string.

0 commit comments

Comments
 (0)