Skip to content

Commit c49d61a

Browse files
Cleaned up family balance task
1 parent 24fd01a commit c49d61a

File tree

8 files changed

+137
-143
lines changed

8 files changed

+137
-143
lines changed

src.primitives/Controls/FamDiagram/TaskManagerFactory.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src.primitives/Controls/FamDiagram/Tasks/Transformations/FamilyTransformations/FamilyBalance.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -831,13 +831,11 @@ primitives.famdiagram.FamilyBalance.prototype.recalcLevelsDepth = function (bund
831831

832832
bundlesToStack = [];
833833

834-
treeLevels.loopLevelItems(this, levelIndex, function (itemid, treeItem, position) {
834+
treeLevels.loopLevelItems(this, levelIndex, function (itemid, familyItem, position) {
835835
var fromItems = [],
836836
toItems = [];
837837
if (!processed.hasOwnProperty(itemid)) {
838838
processed[itemid] = true;
839-
var familyItem = logicalFamily.node(itemid);
840-
841839
if (!familyItem.hideChildrenConnection) {
842840
fromItems.push(itemid);
843841
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
primitives.famdiagram.FamilyBalanceItem = function (id, familyId, level) {
2+
this.id = id;
3+
this.familyId = familyId;
4+
this.level = level;
5+
this.childIndex = 0;
6+
}

src.primitives/Controls/FamDiagram/Tasks/Transformations/FamilyTransformations/FamilyNormalizer.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,6 @@ primitives.famdiagram.FamilyNormalizer.prototype.normalize = function (options,
106106
itemConfig: { title: "extension #" + maximumId, description: "This is item used to fill gaps in levels." }
107107
});
108108

109-
if (famItem.isFakeParent) {
110-
result.isFakeParent = true;
111-
}
112-
if (famItem.isFakeChild) {
113-
result.isFakeChild = true;
114-
}
115-
116109
return result;
117110
} //ignore jslint
118111
);

src.primitives/Controls/FamDiagram/Tasks/Transformations/OrderFamilyNodesTask.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Balance family tree so parents sharing the most children stay close to each other
22
Account for users position and primnaryParent options
33
*/
4-
primitives.famdiagram.OrderFamilyNodesTask = function (orderFamilyNodesOptionTask, userDefinedNodesOrderTask, normalizeLogicalFamilyTask, defaultItemConfig) {
4+
primitives.famdiagram.OrderFamilyNodesTask = function (orderFamilyNodesOptionTask, userDefinedNodesOrderTask, normalizeLogicalFamilyTask) {
55
var _data = {
66
maximumId: null, /* maximum of OrgItem.id */
77
logicalFamily: null,
@@ -42,7 +42,6 @@ primitives.famdiagram.OrderFamilyNodesTask = function (orderFamilyNodesOptionTas
4242
var balanceParams = {
4343
logicalFamily: logicalFamily,
4444
maximumId: maximumId,
45-
defaultItemConfig: defaultItemConfig,
4645
itemsPositions: userDefinedNodesOrderTask.getPositions(),
4746
itemsGroups: userDefinedNodesOrderTask.getGroups(),
4847
primaryParents: _userDefinedPrimaryParents.getUserDefinedPrimaryParents(orderFamilyNodesOptions.items, logicalFamily)

src.primitives/Controls/FamDiagram/Tasks/Transformations/RemoveLoopsTask.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
id: (maximumId),
7575
isVisible: false,
7676
isActive: false,
77-
isFakeParent: true,
7877
isLevelNeutral: true,
7978
hideParentConnection: isConnectionsVisible,
8079
hideChildrenConnection: isConnectionsVisible,
@@ -97,7 +96,6 @@
9796
id: (maximumId),
9897
isVisible: false,
9998
isActive: false,
100-
isFakeChild: true,
10199
isLevelNeutral: true,
102100
hideParentConnection: true,
103101
hideChildrenConnection: true,
Lines changed: 127 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,135 @@
1-
primitives.common.VerticalConnectorBundle = function (fromItems, toItems) {
2-
this.fromItems = fromItems;
3-
this.toItems = toItems;
1+
primitives.common.VerticalConnectorBundle = function (fromItems, toItems, oppositeFlowItems) {
2+
this.fromItems = fromItems;
3+
this.toItems = toItems;
44

5-
this.childConnectorId = {};
5+
this.oppositeFlowItems = oppositeFlowItems || [];
66

7-
this.fromOffset = 0;
8-
this.fromStackSize = 0;
7+
this.fromOffset = 0;
8+
this.fromStackSize = 0;
99
};
1010

1111
primitives.common.VerticalConnectorBundle.prototype = new primitives.common.BaseConnectorBundle();
1212

1313
primitives.common.VerticalConnectorBundle.prototype.trace = function (data, params, options) {
14-
var points,
15-
parents, children, items,
16-
treeItem, treeItemId, treeItemPosition, treeItemHighlightPath,
17-
index, len,
18-
isSquared, hasSquared,
19-
parentHorizontalCenter,
20-
parentsConnectorOffset,
21-
childrenConnectorOffset,
22-
connectorPoint,
23-
connectorStep,
24-
chartHasSquaredConnectors = (options.connectorType === primitives.common.ConnectorType.Squared),
25-
paletteItem, polyline;
26-
27-
/* Draw fork for parents */
28-
parents = [];
29-
if (this.fromItems.length > 0) {
30-
items = this.fromItems;
31-
for (index = 0, len = items.length; index < len; index += 1) {
32-
treeItemId = items[index];
33-
treeItemPosition = params.treeItemsPositions[treeItemId];
34-
35-
connectorPoint = new this.ConnectorDestination({
36-
id: params.nestedLayoutBottomConnectorIds.hasOwnProperty(treeItemId) ? params.nestedLayoutBottomConnectorIds[treeItemId] : treeItemId,
37-
bundleid: this.getId(data),
38-
x: treeItemPosition.actualPosition.horizontalCenter(),
39-
y: treeItemPosition.actualPosition.bottom(),
40-
isSquared: true,
41-
visibility: treeItemPosition.actualVisibility
42-
});
43-
parents.push(connectorPoint);
44-
}
45-
parents.sort(function (a, b) { return a.x - b.x; });
46-
47-
/* Find offset of horizontal connector line between parents */
48-
parentsConnectorOffset = treeItemPosition.bottomConnectorShift - treeItemPosition.bottomConnectorInterval * (this.fromStackSize - this.fromOffset + 1);
49-
}
50-
51-
children = [];
52-
if (this.toItems.length > 0) {
53-
hasSquared = false;
54-
55-
items = this.toItems;
56-
for (index = 0; index < items.length; index += 1) {
57-
treeItemId = items[index];
58-
treeItemPosition = params.treeItemsPositions[treeItemId];
59-
60-
isSquared = true;
61-
if (params.hasGraphics) {
62-
switch (treeItemPosition.actualVisibility) {
63-
case primitives.common.Visibility.Dot:
64-
case primitives.common.Visibility.Line:
65-
isSquared = chartHasSquaredConnectors;
66-
break;
67-
}
68-
}
69-
connectorStep = 0;
70-
connectorPoint = new this.ConnectorDestination({
71-
id: treeItemId,
72-
bundleid: this.getId(data),
73-
x: (treeItemPosition.actualPosition.horizontalCenter() + connectorStep),
74-
y: treeItemPosition.actualPosition.top(),
75-
isSquared: isSquared,
76-
visibility: treeItemPosition.actualVisibility
77-
});
78-
children.push(connectorPoint);
79-
80-
/* is true if any child point has squared connector */
81-
hasSquared = hasSquared || connectorPoint.isSquared;
82-
}
83-
children.sort(function (a, b) { return a.x - b.x; });
84-
85-
/* Find offset of horizontal connector line between children */
86-
childrenConnectorOffset = treeItemPosition.topConnectorShift;
87-
}
88-
89-
if (children.length == 1) {
90-
parentHorizontalCenter = children[0].x;
91-
} else if (parents.length == 1) {
92-
parentHorizontalCenter = parents[0].x;
93-
} else if (children.length > 0 && parents.length > 0) {
94-
parentHorizontalCenter = (parents[0].x + parents[parents.length - 1].x + children[0].x + children[children.length - 1].x) / 4.0;
95-
} else if (children.length > 0) {
96-
parentHorizontalCenter = (children[0].x + children[children.length - 1].x) / 2.0;
97-
} else {
98-
parentHorizontalCenter = (parents[0].x + parents[parents.length - 1].x) / 2.0;
99-
}
100-
101-
var topCenterPoint = null;
102-
if (parents.length > 0) {
103-
topCenterPoint = new this.ConnectorDestination({
104-
id: this.getId(data),
105-
x: parentHorizontalCenter,
106-
y: parentsConnectorOffset
107-
});
108-
this.traceFork(data, params, options, topCenterPoint, parents, true, true, this.fromOffset, options.showExtraArrows && (children.length > 0));
109-
}
110-
111-
var bottomCenterPoint = null;
112-
if (children.length > 0) {
113-
bottomCenterPoint = new this.ConnectorDestination({
114-
id: this.getId(data),
115-
x: parentHorizontalCenter,
116-
y: childrenConnectorOffset
117-
});
118-
if (topCenterPoint != null && bottomCenterPoint.y == topCenterPoint.y) {
119-
bottomCenterPoint = topCenterPoint;
120-
}
121-
this.traceFork(data, params, options, bottomCenterPoint, children, hasSquared, false, 0, options.showExtraArrows && (parents.length > 0));
122-
}
123-
124-
/* draw connector line between children and parents */
125-
if (topCenterPoint != null && bottomCenterPoint != null && topCenterPoint.id != bottomCenterPoint.id) {
126-
params.transform.transformPoints(topCenterPoint.x, topCenterPoint.y, bottomCenterPoint.x, bottomCenterPoint.y,
127-
true, this, function (fromX, fromY, toX, toY) {
128-
var polyline = new primitives.common.Polyline();
129-
polyline.addSegment(new primitives.common.MoveSegment(fromX, fromY));
130-
polyline.addSegment(new primitives.common.LineSegment(toX, toY));
131-
132-
data.graph.addEdge(topCenterPoint.id, bottomCenterPoint.id, new this.ConnectorEdge(topCenterPoint.id, bottomCenterPoint.id, polyline, null, null, null, 0/* weight */));
133-
});
134-
}
14+
var points,
15+
parents, children, items,
16+
treeItem, treeItemId, treeItemPosition, treeItemHighlightPath,
17+
index, len,
18+
isSquared, hasSquared,
19+
parentHorizontalCenter,
20+
parentsConnectorOffset,
21+
childrenConnectorOffset,
22+
connectorPoint,
23+
connectorStep,
24+
chartHasSquaredConnectors = (options.connectorType === primitives.common.ConnectorType.Squared),
25+
paletteItem, polyline;
26+
27+
/* Draw fork for parents */
28+
parents = [];
29+
if (this.fromItems.length > 0) {
30+
items = this.fromItems;
31+
for (index = 0, len = items.length; index < len; index += 1) {
32+
treeItemId = items[index];
33+
treeItemPosition = params.treeItemsPositions[treeItemId];
34+
35+
connectorPoint = new this.ConnectorDestination({
36+
id: params.nestedLayoutBottomConnectorIds.hasOwnProperty(treeItemId) ? params.nestedLayoutBottomConnectorIds[treeItemId] : treeItemId,
37+
bundleid: this.getId(data),
38+
x: treeItemPosition.actualPosition.horizontalCenter(),
39+
y: treeItemPosition.actualPosition.bottom(),
40+
isSquared: true,
41+
visibility: treeItemPosition.actualVisibility
42+
});
43+
parents.push(connectorPoint);
44+
}
45+
parents.sort(function (a, b) { return a.x - b.x; });
46+
47+
/* Find offset of horizontal connector line between parents */
48+
parentsConnectorOffset = treeItemPosition.bottomConnectorShift - treeItemPosition.bottomConnectorInterval * (this.fromStackSize - this.fromOffset + 1);
49+
}
50+
51+
children = [];
52+
if (this.toItems.length > 0) {
53+
hasSquared = false;
54+
55+
items = this.toItems;
56+
for (index = 0; index < items.length; index += 1) {
57+
treeItemId = items[index];
58+
treeItemPosition = params.treeItemsPositions[treeItemId];
59+
60+
isSquared = true;
61+
if (params.hasGraphics) {
62+
switch (treeItemPosition.actualVisibility) {
63+
case primitives.common.Visibility.Dot:
64+
case primitives.common.Visibility.Line:
65+
isSquared = chartHasSquaredConnectors;
66+
break;
67+
}
68+
}
69+
connectorStep = 0;
70+
connectorPoint = new this.ConnectorDestination({
71+
id: treeItemId,
72+
bundleid: this.getId(data),
73+
x: (treeItemPosition.actualPosition.horizontalCenter() + connectorStep),
74+
y: treeItemPosition.actualPosition.top(),
75+
isSquared: isSquared,
76+
visibility: treeItemPosition.actualVisibility
77+
});
78+
children.push(connectorPoint);
79+
80+
/* is true if any child point has squared connector */
81+
hasSquared = hasSquared || connectorPoint.isSquared;
82+
}
83+
children.sort(function (a, b) { return a.x - b.x; });
84+
85+
/* Find offset of horizontal connector line between children */
86+
childrenConnectorOffset = treeItemPosition.topConnectorShift;
87+
}
88+
89+
if (children.length == 1) {
90+
parentHorizontalCenter = children[0].x;
91+
} else if (parents.length == 1) {
92+
parentHorizontalCenter = parents[0].x;
93+
} else if (children.length > 0 && parents.length > 0) {
94+
parentHorizontalCenter = (parents[0].x + parents[parents.length - 1].x + children[0].x + children[children.length - 1].x) / 4.0;
95+
} else if (children.length > 0) {
96+
parentHorizontalCenter = (children[0].x + children[children.length - 1].x) / 2.0;
97+
} else {
98+
parentHorizontalCenter = (parents[0].x + parents[parents.length - 1].x) / 2.0;
99+
}
100+
101+
var topCenterPoint = null;
102+
if (parents.length > 0) {
103+
topCenterPoint = new this.ConnectorDestination({
104+
id: this.getId(data),
105+
x: parentHorizontalCenter,
106+
y: parentsConnectorOffset
107+
});
108+
this.traceFork(data, params, options, topCenterPoint, parents, true, true, this.fromOffset, options.showExtraArrows && (children.length > 0));
109+
}
110+
111+
var bottomCenterPoint = null;
112+
if (children.length > 0) {
113+
bottomCenterPoint = new this.ConnectorDestination({
114+
id: this.getId(data),
115+
x: parentHorizontalCenter,
116+
y: childrenConnectorOffset
117+
});
118+
if (topCenterPoint != null && bottomCenterPoint.y == topCenterPoint.y) {
119+
bottomCenterPoint = topCenterPoint;
120+
}
121+
this.traceFork(data, params, options, bottomCenterPoint, children, hasSquared, false, 0, options.showExtraArrows && (parents.length > 0));
122+
}
123+
124+
/* draw connector line between children and parents */
125+
if (topCenterPoint != null && bottomCenterPoint != null && topCenterPoint.id != bottomCenterPoint.id) {
126+
params.transform.transformPoints(topCenterPoint.x, topCenterPoint.y, bottomCenterPoint.x, bottomCenterPoint.y,
127+
true, this, function (fromX, fromY, toX, toY) {
128+
var polyline = new primitives.common.Polyline();
129+
polyline.addSegment(new primitives.common.MoveSegment(fromX, fromY));
130+
polyline.addSegment(new primitives.common.LineSegment(toX, toY));
131+
132+
data.graph.addEdge(topCenterPoint.id, bottomCenterPoint.id, new this.ConnectorEdge(topCenterPoint.id, bottomCenterPoint.id, polyline, null, null, null, 0/* weight */));
133+
});
134+
}
135135
};

src.primitives/pdf/FamDiagram/Plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ primitives.pdf.famdiagram.Plugin = function (options) {
101101
tasks.addTask('AddSpousesTask', ['SpousesOptionTask', 'AddLabelAnnotationsTask'], primitives.famdiagram.AddSpousesTask, primitives.common.Colors.Red);
102102
tasks.addTask('HideGrandParentsConnectorsTask', ['HideGrandParentsConnectorsOptionTask', 'AddSpousesTask'], primitives.famdiagram.HideGrandParentsConnectorsTask, primitives.common.Colors.Red);
103103
tasks.addTask('NormalizeLogicalFamilyTask', ['NormalizeOptionTask', 'HideGrandParentsConnectorsTask'], primitives.famdiagram.NormalizeLogicalFamilyTask, primitives.common.Colors.Red);
104-
tasks.addTask('OrderFamilyNodesTask', ['OrderFamilyNodesOptionTask', 'UserDefinedNodesOrderTask', 'NormalizeLogicalFamilyTask', 'defaultItemConfig'], primitives.famdiagram.OrderFamilyNodesTask, primitives.common.Colors.Red);
104+
tasks.addTask('OrderFamilyNodesTask', ['OrderFamilyNodesOptionTask', 'UserDefinedNodesOrderTask', 'NormalizeLogicalFamilyTask'], primitives.famdiagram.OrderFamilyNodesTask, primitives.common.Colors.Red);
105105

106106
// Transformations / Templates
107107
tasks.addTask('ReadTemplatesTask', ['TemplatesOptionTask'], primitives.pdf.orgdiagram.ReadTemplatesTask, primitives.common.Colors.Cyan);

0 commit comments

Comments
 (0)