Skip to content

Commit 24fd01a

Browse files
Cleaned up FamilyBalance task
1 parent bd0a014 commit 24fd01a

File tree

1 file changed

+19
-63
lines changed
  • src.primitives/Controls/FamDiagram/Tasks/Transformations/FamilyTransformations

1 file changed

+19
-63
lines changed

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

Lines changed: 19 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,12 @@
2525
In the way when groups having maximum mutual links placed close to each other.
2626
*/
2727
primitives.famdiagram.FamilyBalance = function () {
28-
this.properties = [
29-
'title', 'description', 'image',
30-
'itemTitleColor', 'groupTitle', 'groupTitleColor',
31-
'isActive', 'hasSelectorCheckbox', 'hasButtons',
32-
'templateName', 'showCallout', 'calloutTemplateName',
33-
'label', 'showLabel', 'labelSize', 'labelOrientation', 'labelPlacement',
34-
'minimizedItemShapeType'
35-
];
28+
3629
};
3730

3831
//var params = {
3932
// logicalFamily,
4033
// maximumId,
41-
// defaultItemConfig,
4234
// items
4335
//};
4436
primitives.famdiagram.FamilyBalance.prototype.balance = function (params) {
@@ -62,12 +54,13 @@ primitives.famdiagram.FamilyBalance.prototype.balance = function (params) {
6254

6355
var currentLevelIndex, index = -1;
6456
data.orgTree.loopLevels(this, function (treeItemId, treeItem, levelIndex) {
65-
if (params.logicalFamily.node(treeItemId) != null) {
57+
var familyItem = params.logicalFamily.node(treeItemId);
58+
if (familyItem != null) {
6659
if (currentLevelIndex !== levelIndex) {
6760
currentLevelIndex = levelIndex;
6861
index += 1;
6962
}
70-
result.treeLevels.addItem(index, treeItemId, treeItem);
63+
result.treeLevels.addItem(index, treeItemId, familyItem);
7164
}
7265
});
7366

@@ -130,7 +123,7 @@ primitives.famdiagram.FamilyBalance.prototype.createOrgTree = function (params,
130123
/* extractOrgChart method extracts hiearchy of family members starting from grandParent and takes only non extracted family items
131124
* For every extracted item it assigns its familyId, it is used for building families relations graph and finding cross family links
132125
*/
133-
this.extractOrgChart(grandParentId, params.logicalFamily, params.primaryParents, params.defaultItemConfig, data.orgTree, data.orgPartners, data.itemByChildrenKey, famItemsExtracted, family);
126+
this.extractOrgChart(grandParentId, params.logicalFamily, params.primaryParents, data.orgTree, data.orgPartners, data.itemByChildrenKey, famItemsExtracted, family);
134127
families.push(family);
135128
families2.push(family);
136129
familyId += 1;
@@ -219,14 +212,8 @@ primitives.famdiagram.FamilyBalance.prototype.createOrgTree = function (params,
219212

220213
/* create chart root */
221214
data.maximumId += 1;
222-
orgItemRoot = this.createOrgItem(data.orgTree, params.defaultItemConfig, data.maximumId, null /*parent id*/, null, data.minimumLevel - 1, null /* userItem */);
223-
orgItemRoot.hideParentConnection = true;
224-
orgItemRoot.hideChildrenConnection = true;
225-
orgItemRoot.title = "internal root";
226-
orgItemRoot.isVisible = false;
227-
orgItemRoot.isActive = false;
228-
orgItemRoot.childIndex = 0;
229-
215+
orgItemRoot = new primitives.famdiagram.FamilyBalanceItem(data.maximumId, null, data.minimumLevel - 1);
216+
data.orgTree.add(null, orgItemRoot.id, orgItemRoot);
230217

231218
/* Place family roots to organizational chart */
232219
attachedFamilies = {};
@@ -271,7 +258,7 @@ primitives.famdiagram.FamilyBalance.prototype.createOrgTree = function (params,
271258

272259
}
273260

274-
this.attachFamilyToOrgChart(data, params.defaultItemConfig, bestRootItem, family);
261+
this.attachFamilyToOrgChart(data, bestRootItem, family);
275262

276263
attachedFamilies[family.id] = true;
277264
}
@@ -723,7 +710,7 @@ primitives.famdiagram.FamilyBalance.prototype.addExtraGravityForItem = function
723710
extraGravities[id][extraGravity.level].push(extraGravity);
724711
};
725712

726-
primitives.famdiagram.FamilyBalance.prototype.attachFamilyToOrgChart = function (data, defaultItemConfig, parent, family) {
713+
primitives.famdiagram.FamilyBalance.prototype.attachFamilyToOrgChart = function (data, parent, family) {
727714
var levelIndex,
728715
familyRoot = family.items[0],
729716
newOrgItem = null,
@@ -732,12 +719,8 @@ primitives.famdiagram.FamilyBalance.prototype.attachFamilyToOrgChart = function
732719
// fill in levels between parent and family root with invisible items
733720
for (levelIndex = parent.level + 1; levelIndex < familyRoot.level; levelIndex += 1) {
734721
data.maximumId += 1;
735-
newOrgItem = this.createOrgItem(data.orgTree, defaultItemConfig, data.maximumId, rootItem.id, null, levelIndex, null /* userItem */);
736-
newOrgItem.title = "shift";
737-
newOrgItem.isVisible = false;
738-
newOrgItem.isActive = false;
739-
newOrgItem.hideParentConnection = true;
740-
newOrgItem.hideChildrenConnection = true;
722+
newOrgItem = new primitives.famdiagram.FamilyBalanceItem(data.maximumId, null, levelIndex);
723+
data.orgTree.add(rootItem.id, newOrgItem.id, newOrgItem);
741724
family.items.push(newOrgItem);
742725

743726
rootItem = newOrgItem;
@@ -748,7 +731,7 @@ primitives.famdiagram.FamilyBalance.prototype.attachFamilyToOrgChart = function
748731
data.orgTree.adopt(rootItem.id, familyRoot.id, familyRoot);
749732
};
750733

751-
primitives.famdiagram.FamilyBalance.prototype.extractOrgChart = function (grandParentId, logicalFamily, primaryParentsPath, defaultItemConfig, orgTree, orgPartners, itemByChildrenKey, famItemsExtracted, family) {
734+
primitives.famdiagram.FamilyBalance.prototype.extractOrgChart = function (grandParentId, logicalFamily, primaryParentsPath, orgTree, orgPartners, itemByChildrenKey, famItemsExtracted, family) {
752735
var index, len,
753736
children = [], tempChildren,
754737
childItem,
@@ -757,32 +740,28 @@ primitives.famdiagram.FamilyBalance.prototype.extractOrgChart = function (grandP
757740
grandParent = logicalFamily.node(grandParentId);
758741

759742
/* extract root item */
760-
newOrgItem = this.createOrgItem(orgTree, defaultItemConfig, grandParent.id, rootItem, family.id, grandParent.level, grandParent.itemConfig);
761-
newOrgItem.hideParentConnection = true;
762-
newOrgItem.isVisible = grandParent.isVisible;
763-
newOrgItem.isActive = grandParent.isActive;
764-
newOrgItem.hideParentConnection = grandParent.hideParentConnection;
765-
newOrgItem.hideChildrenConnection = grandParent.hideChildrenConnection;
743+
newOrgItem = new primitives.famdiagram.FamilyBalanceItem(grandParent.id, family.id, grandParent.level);
744+
orgTree.add(rootItem, newOrgItem.id, newOrgItem);
766745
family.items.push(newOrgItem);
767746

768747
famItemsExtracted[grandParent.id] = grandParent;
769748
grandParent.familyId = family.id;
770749

771750
/* extract its children */
772-
children = this.extractChildren(grandParent, logicalFamily, primaryParentsPath, defaultItemConfig, orgTree, orgPartners, itemByChildrenKey, famItemsExtracted, family);
751+
children = this.extractChildren(grandParent, logicalFamily, primaryParentsPath, orgTree, orgPartners, itemByChildrenKey, famItemsExtracted, family);
773752

774753
while (children.length > 0) {
775754
tempChildren = [];
776755
for (index = 0, len = children.length; index < len; index += 1) {
777756
childItem = children[index];
778-
tempChildren = tempChildren.concat(this.extractChildren(childItem, logicalFamily, primaryParentsPath, defaultItemConfig, orgTree, orgPartners, itemByChildrenKey, famItemsExtracted, family));
757+
tempChildren = tempChildren.concat(this.extractChildren(childItem, logicalFamily, primaryParentsPath, orgTree, orgPartners, itemByChildrenKey, famItemsExtracted, family));
779758
}
780759

781760
children = tempChildren;
782761
}
783762
};
784763

785-
primitives.famdiagram.FamilyBalance.prototype.extractChildren = function (parentItem, logicalFamily, primaryParentsPath, defaultItemConfig, orgTree, orgPartners, itemByChildrenKey, famItemsExtracted, family) {
764+
primitives.famdiagram.FamilyBalance.prototype.extractChildren = function (parentItem, logicalFamily, primaryParentsPath, orgTree, orgPartners, itemByChildrenKey, famItemsExtracted, family) {
786765
var result = [],
787766
firstChild = null,
788767
partnerItem = null,
@@ -824,11 +803,8 @@ primitives.famdiagram.FamilyBalance.prototype.extractChildren = function (parent
824803
}
825804
result.push(childItem);
826805

827-
newOrgItem = this.createOrgItem(orgTree, defaultItemConfig, childItem.id, parentItem.id, family.id, childItem.level, childItem.itemConfig);
828-
newOrgItem.hideParentConnection = childItem.hideParentConnection;
829-
newOrgItem.hideChildrenConnection = childItem.hideChildrenConnection;
830-
newOrgItem.isVisible = childItem.isVisible;
831-
newOrgItem.isActive = childItem.isActive;
806+
newOrgItem = new primitives.famdiagram.FamilyBalanceItem(childItem.id, family.id, childItem.level);
807+
orgTree.add(parentItem.id, newOrgItem.id, newOrgItem);
832808
family.items.push(newOrgItem);
833809

834810
famItemsExtracted[childItem.id] = true;
@@ -840,26 +816,6 @@ primitives.famdiagram.FamilyBalance.prototype.extractChildren = function (parent
840816
return result;
841817
};
842818

843-
primitives.famdiagram.FamilyBalance.prototype.createOrgItem = function (orgTree, defaultItemConfig, id, parentId, familyId, level, userItem) {
844-
var orgItem = new primitives.orgdiagram.OrgItem({}),
845-
index, len,
846-
property;
847-
848-
// OrgItem id coinsides with ItemConfig id since we don't add any new org items to user's org chart definition
849-
orgItem.id = id;
850-
orgItem.familyId = familyId;
851-
orgItem.level = level;
852-
853-
for (index = 0, len = this.properties.length; index < len; index += 1) {
854-
property = this.properties[index];
855-
856-
orgItem[property] = (userItem != null && userItem[property] !== undefined) ? userItem[property] : defaultItemConfig[property];
857-
}
858-
orgTree.add(parentId, orgItem.id, orgItem);
859-
860-
return orgItem;
861-
};
862-
863819
primitives.famdiagram.FamilyBalance.prototype.recalcLevelsDepth = function (bundles, connectorStacks, treeLevels, logicalFamily) {
864820
var index2, len2,
865821
index3, len3,

0 commit comments

Comments
 (0)