entitree-flex
Advanced tools
Comparing version 0.3.4 to 0.4.0
import { Settings } from "./Settings"; | ||
import { TreeMap } from "./TreeMap"; | ||
import { TreeNode } from "./TreeNode"; | ||
export declare const centerSourceToTargets: <T = void>(source: TreeNode<T>, targets: TreeNode<T>[], settings: Settings, map?: TreeMap<T>) => void; | ||
export declare const centerSourceToTargets: (source: TreeNode, targets: TreeNode[], settings: Settings, map: TreeMap) => void; |
@@ -9,19 +9,29 @@ "use strict"; | ||
//center only on actual children, not all generational nodes | ||
var leftMostTarget = targets[0]; | ||
var rightMostTarget = last_1.last(targets); | ||
if (leftMostTarget && rightMostTarget) { | ||
var newSourceX = (leftMostTarget.x + rightMostTarget.x + rightMostTarget.width) / 2 - | ||
source.width / 2; | ||
var delta_1 = newSourceX - source.x; | ||
if (newSourceX !== source.x) { | ||
source.x += delta_1; | ||
var siblings = map | ||
? getFromMap_1.getFromMap(source[settings.nextBeforeAccessor], map) | ||
: source[settings.nextBeforeAccessor]; | ||
siblings === null || siblings === void 0 ? void 0 : siblings.forEach(function (sibling) { return (sibling.x += delta_1); }); | ||
var partners = map | ||
? getFromMap_1.getFromMap(source[settings.nextAfterAccessor], map) | ||
: source[settings.nextAfterAccessor]; | ||
partners === null || partners === void 0 ? void 0 : partners.forEach(function (partner) { return (partner.x += delta_1); }); | ||
var firstTarget = targets[0]; | ||
var lastTarget = last_1.last(targets); | ||
if (firstTarget && lastTarget) { | ||
if (settings.orientation === "vertical") { | ||
var newSourceX = (firstTarget.x + lastTarget.x + lastTarget.width) / 2 - | ||
source.width / 2; | ||
var delta_1 = newSourceX - source.x; | ||
if (newSourceX !== source.x) { | ||
source.x += delta_1; | ||
var siblings = getFromMap_1.getFromMap(source[settings.nextBeforeAccessor], map); | ||
siblings === null || siblings === void 0 ? void 0 : siblings.forEach(function (sibling) { return (sibling.x += delta_1); }); | ||
var partners = getFromMap_1.getFromMap(source[settings.nextAfterAccessor], map); | ||
partners === null || partners === void 0 ? void 0 : partners.forEach(function (partner) { return (partner.x += delta_1); }); | ||
} | ||
} | ||
else { | ||
var newSourceY = (firstTarget.y + lastTarget.y + lastTarget.height) / 2 - | ||
source.height / 2; | ||
var delta_2 = newSourceY - source.y; | ||
if (newSourceY !== source.y) { | ||
source.y += delta_2; | ||
var siblings = getFromMap_1.getFromMap(source[settings.nextBeforeAccessor], map); | ||
siblings === null || siblings === void 0 ? void 0 : siblings.forEach(function (sibling) { return (sibling.y += delta_2); }); | ||
var partners = getFromMap_1.getFromMap(source[settings.nextAfterAccessor], map); | ||
partners === null || partners === void 0 ? void 0 : partners.forEach(function (partner) { return (partner.y += delta_2); }); | ||
} | ||
} | ||
} | ||
@@ -28,0 +38,0 @@ } |
@@ -0,2 +1,3 @@ | ||
import { Settings } from "./Settings"; | ||
import { TreeNode } from "./TreeNode"; | ||
export declare function checkContourOverlap<T>(contourSet: TreeNode<T>[], node: TreeNode<T>): void; | ||
export declare function checkContourOverlap<T>(contourSet: TreeNode<T>[], node: TreeNode<T>, settings: Settings): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.checkContourOverlap = void 0; | ||
var shiftFromCountour_1 = require("./shiftFromCountour"); | ||
function checkContourOverlap(contourSet, node) { | ||
var getNodeBottomY_1 = require("./getNodeBottomY"); | ||
var getNodeRightX_1 = require("./getNodeRightX"); | ||
function checkContourOverlap(contourSet, node, settings) { | ||
contourSet.forEach(function (contourNode) { | ||
shiftFromCountour_1.shiftFromCountour(contourNode, node); | ||
if (settings.orientation === "vertical") { | ||
var nodeBottomY = getNodeBottomY_1.getNodeBottomY(node); | ||
var contourRightX = getNodeRightX_1.getNodeRightX(contourNode); | ||
var contourTopY = contourNode.y; | ||
var contourBottomY = getNodeBottomY_1.getNodeBottomY(contourNode); | ||
var coversCountour = node.y <= contourTopY && nodeBottomY >= contourBottomY; | ||
var traspassHorizontal = node.x < contourRightX; | ||
// if (coversCountour) { | ||
// //todo: if it covers the whole box, remove box from contour array | ||
// } | ||
if (traspassHorizontal && | ||
((node.y > contourTopY && node.y < contourBottomY) || | ||
(nodeBottomY > contourTopY && nodeBottomY < contourBottomY) || | ||
coversCountour)) { | ||
node.x += contourRightX - node.x; | ||
} | ||
} | ||
else { | ||
var nodeRightX = getNodeRightX_1.getNodeRightX(node); | ||
var contourBottomY = getNodeBottomY_1.getNodeBottomY(contourNode); | ||
var contourLeftX = contourNode.x; | ||
var contourRightX = getNodeRightX_1.getNodeRightX(contourNode); | ||
var coversCountour = node.x <= contourLeftX && nodeRightX >= contourRightX; | ||
var traspassVertical = node.y < contourBottomY; | ||
// if (coversCountour) { | ||
// //todo: if it covers the whole box, remove box from contour array | ||
// } | ||
if (traspassVertical && | ||
((node.x > contourLeftX && node.x < contourRightX) || | ||
(nodeRightX > contourLeftX && nodeRightX < contourRightX) || | ||
coversCountour)) { | ||
node.y += contourBottomY - node.y; | ||
} | ||
} | ||
}); | ||
@@ -9,0 +43,0 @@ contourSet.push(node); |
@@ -8,3 +8,3 @@ "use strict"; | ||
firstDegreeSpacing: 15, | ||
nextAfterAccessor: "partners", | ||
nextAfterAccessor: "spouses", | ||
nextAfterSpacing: 10, | ||
@@ -15,2 +15,3 @@ nextBeforeAccessor: "siblings", | ||
nodeWidth: 40, | ||
orientation: "vertical", | ||
rootX: 0, | ||
@@ -17,0 +18,0 @@ rootY: 0, |
@@ -5,10 +5,10 @@ import { Settings } from "./Settings"; | ||
import { TreeRel } from "./TreeRel"; | ||
export declare const getElements: <T>(root: TreeNode<T>, settings: Settings, map?: TreeMap<T>) => { | ||
export declare const getElements: <T>(root: TreeNode<T>, settings: Settings, map: TreeMap<T>) => { | ||
map: TreeMap<T>; | ||
maxBottom: number; | ||
maxLeft: number; | ||
maxRight: number; | ||
maxTop: number; | ||
nodes: TreeNode<T>[]; | ||
rels: TreeRel<T>[]; | ||
maxRight: number; | ||
maxLeft: number; | ||
maxBottom: number; | ||
maxTop: number; | ||
}; |
@@ -19,5 +19,3 @@ "use strict"; | ||
function processNextBefores(subtree) { | ||
var nextBefores = map | ||
? getFromMap_1.getFromMap(subtree[settings.nextBeforeAccessor], map) | ||
: subtree[settings.nextBeforeAccessor]; | ||
var nextBefores = getFromMap_1.getFromMap(subtree[settings.nextBeforeAccessor], map); | ||
nextBefores === null || nextBefores === void 0 ? void 0 : nextBefores.forEach(function (sibling) { | ||
@@ -30,5 +28,3 @@ compare(sibling); | ||
function processNextAfters(subtree) { | ||
var nextAfters = map | ||
? getFromMap_1.getFromMap(subtree[settings.nextAfterAccessor], map) | ||
: subtree[settings.nextAfterAccessor]; | ||
var nextAfters = getFromMap_1.getFromMap(subtree[settings.nextAfterAccessor], map); | ||
nextAfters === null || nextAfters === void 0 ? void 0 : nextAfters.forEach(function (spouse) { | ||
@@ -45,5 +41,3 @@ compare(spouse); | ||
if (!direction || direction === "parents") { | ||
var parents = map | ||
? getFromMap_1.getFromMap(subtree[settings.sourcesAccessor], map) | ||
: subtree[settings.sourcesAccessor]; | ||
var parents = getFromMap_1.getFromMap(subtree[settings.sourcesAccessor], map); | ||
parents === null || parents === void 0 ? void 0 : parents.forEach(function (parent) { | ||
@@ -57,5 +51,3 @@ compare(parent); | ||
if (!direction || direction === "children") { | ||
var children = map | ||
? getFromMap_1.getFromMap(subtree[settings.targetsAccessor], map) | ||
: subtree[settings.targetsAccessor]; | ||
var children = getFromMap_1.getFromMap(subtree[settings.targetsAccessor], map); | ||
children === null || children === void 0 ? void 0 : children.forEach(function (child) { | ||
@@ -62,0 +54,0 @@ compare(child); |
import { Settings } from "./Settings"; | ||
import { TreeMap } from "./TreeMap"; | ||
import { TreeNode } from "./TreeNode"; | ||
export declare const getInitialTargetsShiftLeft: <T>(source: TreeNode<T>, targets: TreeNode<T>[], settings: Settings, map?: TreeMap<T>) => number; | ||
export declare const getInitialTargetsShiftLeft: (source: TreeNode, targets: TreeNode[], settings: Settings, map: TreeMap) => number; |
@@ -13,8 +13,4 @@ "use strict"; | ||
return (targets.reduce(function (totalWidth, target, index) { | ||
var siblings = map | ||
? getFromMap_1.getFromMap(target[settings.nextBeforeAccessor], map) | ||
: target[settings.nextBeforeAccessor]; | ||
var partners = map | ||
? getFromMap_1.getFromMap(target[settings.nextAfterAccessor], map) | ||
: target[settings.nextAfterAccessor]; | ||
var siblings = getFromMap_1.getFromMap(target[settings.nextBeforeAccessor], map); | ||
var partners = getFromMap_1.getFromMap(target[settings.nextAfterAccessor], map); | ||
//for the first child, we don't care about the padding (siblings) left | ||
@@ -21,0 +17,0 @@ if (index !== 0) { |
@@ -1,6 +0,2 @@ | ||
export * from "./defaultSettings"; | ||
export * from "./getElements"; | ||
export * from "./getSizes"; | ||
export * from "./layoutFromMap"; | ||
export * from "./layoutFromNested"; | ||
export * from "./TreeNode"; |
@@ -13,8 +13,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./defaultSettings"), exports); | ||
__exportStar(require("./getElements"), exports); | ||
__exportStar(require("./getSizes"), exports); | ||
__exportStar(require("./layoutFromMap"), exports); | ||
__exportStar(require("./layoutFromNested"), exports); | ||
__exportStar(require("./TreeNode"), exports); | ||
//# sourceMappingURL=index.js.map |
import { Settings } from "./Settings"; | ||
import { TreeMap } from "./TreeMap"; | ||
import { TreeNode } from "./TreeNode"; | ||
export declare function layoutFromMap<T>(rootId: string, originalMap: Record<string, T>, customSettings?: Partial<Settings>): { | ||
export declare function layoutFromMap<T>(rootId: string | number, originalMap: Record<string | number, T>, customSettings?: Partial<Settings>): { | ||
map: TreeMap<T>; | ||
nodes: TreeNode<T>[]; | ||
rels: import("./TreeRel").TreeRel<T>[]; | ||
maxBottom: number; | ||
maxLeft: number; | ||
maxRight: number; | ||
maxLeft: number; | ||
maxBottom: number; | ||
maxTop: number; | ||
nodes: import("./TreeNode").TreeNode<T>[]; | ||
rels: import("./TreeRel").TreeRel<T>[]; | ||
}; |
@@ -15,12 +15,13 @@ "use strict"; | ||
exports.layoutFromMap = void 0; | ||
var addGenerationSizes_1 = require("./addGenerationSizes"); | ||
var centerSourceToTargets_1 = require("./centerSourceToTargets"); | ||
var checkContourOverlap_1 = require("./checkContourOverlap"); | ||
var addGroupBottomY_1 = require("./addGroupBottomY"); | ||
var addGroupLeftX_1 = require("./addGroupLeftX"); | ||
var addGroupRightX_1 = require("./addGroupRightX"); | ||
var addGroupTopY_1 = require("./addGroupTopY"); | ||
var addLevelNodesSizes_1 = require("./addLevelNodesSizes"); | ||
var addRootSiblingsPositions_1 = require("./addRootSiblingsPositions"); | ||
var addRootSpousesPositions_1 = require("./addRootSpousesPositions"); | ||
var defaultSettings_1 = require("./defaultSettings"); | ||
var drillChildren_1 = require("./drillChildren"); | ||
var drillParents_1 = require("./drillParents"); | ||
var getElements_1 = require("./getElements"); | ||
var getFromMap_1 = require("./getFromMap"); | ||
var getGenerationBottomLineY_1 = require("./getGenerationBottomLineY"); | ||
var getGenerationMaxHeight_1 = require("./getGenerationMaxHeight"); | ||
var getGenerationTopLineY_1 = require("./getGenerationTopLineY"); | ||
var getInitialTargetsShiftLeft_1 = require("./getInitialTargetsShiftLeft"); | ||
var makeRoot_1 = require("./makeRoot"); | ||
@@ -35,114 +36,12 @@ var normalizeTree_1 = require("./normalizeTree"); | ||
var root = makeRoot_1.makeRoot(map[rootId], settings); | ||
addGenerationSizes_1.addGenerationSizes([root], settings, map); | ||
root.topLineY = root.y; | ||
root.bottomLineY = root.y + root.height + root.marginBottom; | ||
if (root[settings.nextBeforeAccessor]) | ||
getFromMap_1.getFromMap(root[settings.nextBeforeAccessor], map) | ||
.reverse() | ||
.forEach(function (sibling, siblingIndex, rootSiblings) { | ||
var nextNode = rootSiblings[siblingIndex - 1] || root; | ||
sibling.x = nextNode.x - sibling.width - sibling.marginRight; | ||
//align vertically | ||
sibling.y = root.y + root.height / 2 - sibling.height / 2; | ||
var outerBottomY = sibling.y + sibling.height + sibling.marginBottom; | ||
if (sibling.y < root.topLineY) | ||
root.topLineY = sibling.y; | ||
if (outerBottomY > root.bottomLineY) | ||
root.bottomLineY = outerBottomY; | ||
}); | ||
if (root[settings.nextAfterAccessor]) | ||
getFromMap_1.getFromMap(root[settings.nextAfterAccessor], map).forEach(function (partner, partnerIndex, rootPartners) { | ||
var previousPartner = rootPartners[partnerIndex - 1] || root; | ||
partner.x = | ||
previousPartner.x + | ||
previousPartner.width + | ||
previousPartner.marginRight; | ||
partner.y = root.y + root.height / 2 - partner.height / 2; | ||
var outerBottomY = partner.y + partner.height + partner.marginBottom; | ||
if (partner.y < root.topLineY) | ||
root.topLineY = partner.y; | ||
if (outerBottomY > root.bottomLineY) | ||
root.bottomLineY = outerBottomY; | ||
}); | ||
var descendantsContour = []; | ||
drillChildren(root); | ||
function drillChildren(subtree) { | ||
var children = getFromMap_1.getFromMap(subtree[settings.targetsAccessor], map); | ||
if (!children || !children.length) | ||
return; | ||
//rename to addGenerationSizes | ||
addGenerationSizes_1.addGenerationSizes(children, settings, map); | ||
var initialShiftLeft = getInitialTargetsShiftLeft_1.getInitialTargetsShiftLeft(subtree, children, settings, map); | ||
var currentX = subtree.x - initialShiftLeft; | ||
var topLineY = getGenerationBottomLineY_1.getGenerationBottomLineY(subtree, settings, map); | ||
children.forEach(function (child) { | ||
var maxHeight = getGenerationMaxHeight_1.getGenerationMaxHeight(child, settings, map); | ||
var midVerticalY = topLineY + maxHeight / 2; | ||
/////////////////// SIBLING | ||
var siblings = getFromMap_1.getFromMap(child[settings.nextBeforeAccessor], map); | ||
siblings === null || siblings === void 0 ? void 0 : siblings.forEach(function (sibling) { | ||
sibling.x = currentX; | ||
sibling.y = midVerticalY - sibling.height / 2; | ||
checkContourOverlap_1.checkContourOverlap(descendantsContour, sibling); | ||
currentX = sibling.x + sibling.width + sibling.marginRight; | ||
}); | ||
/////////////////// CHILD | ||
//Set positions | ||
child.x = currentX; | ||
child.y = midVerticalY - child.height / 2; | ||
checkContourOverlap_1.checkContourOverlap(descendantsContour, child); | ||
currentX = child.x + child.width + child.marginRight; | ||
/////////////////// partners | ||
var partners = getFromMap_1.getFromMap(child[settings.nextAfterAccessor], map); | ||
partners === null || partners === void 0 ? void 0 : partners.forEach(function (partner) { | ||
partner.x = currentX; | ||
partner.y = midVerticalY - partner.height / 2; | ||
checkContourOverlap_1.checkContourOverlap(descendantsContour, partner); | ||
currentX = partner.x + partner.width + partner.marginRight; | ||
}); | ||
drillChildren(child); | ||
}); | ||
centerSourceToTargets_1.centerSourceToTargets(subtree, children, settings, map); | ||
} | ||
addLevelNodesSizes_1.addLevelNodesSizes([root], settings, map); | ||
addRootSiblingsPositions_1.addRootSiblingsPositions(root, settings, map); | ||
addRootSpousesPositions_1.addRootSpousesPositions(root, settings, map); | ||
addGroupBottomY_1.addGroupBottomY(root, settings, map); | ||
addGroupRightX_1.addGroupRightX(root, settings, map); | ||
addGroupLeftX_1.addGroupLeftX(root, settings, map); | ||
addGroupTopY_1.addGroupTopY(root, settings, map); | ||
drillChildren_1.drillChildren(root, settings, map); | ||
normalizeTree_1.normalizeTree(root, settings.targetsAccessor, settings, map); | ||
var parentsContour = []; | ||
drillParents(root); | ||
function drillParents(subtree) { | ||
var parents = getFromMap_1.getFromMap(subtree[settings.sourcesAccessor], map); | ||
if (!(parents === null || parents === void 0 ? void 0 : parents.length)) | ||
return; | ||
addGenerationSizes_1.addGenerationSizes(parents, settings, map); | ||
var initialShiftLeft = getInitialTargetsShiftLeft_1.getInitialTargetsShiftLeft(subtree, parents, settings, map); | ||
var currentX = subtree.x - initialShiftLeft; | ||
var bottomLineY = getGenerationTopLineY_1.getGenerationTopLineY(subtree, settings, map); | ||
parents.forEach(function (parent) { | ||
var _a; | ||
var maxHeight = getGenerationMaxHeight_1.getGenerationMaxHeight(parent, settings, map); | ||
var midVerticalY = bottomLineY - settings.sourceTargetSpacing - maxHeight / 2; | ||
/////////////////// SIBLING | ||
var siblings = getFromMap_1.getFromMap(parent[settings.nextBeforeAccessor], map); | ||
siblings === null || siblings === void 0 ? void 0 : siblings.forEach(function (sibling) { | ||
sibling.x = currentX; | ||
sibling.y = midVerticalY - sibling.height / 2; | ||
checkContourOverlap_1.checkContourOverlap(parentsContour, sibling); | ||
currentX = sibling.x + sibling.width + sibling.marginRight; | ||
}); | ||
///////////// PARENT | ||
//set positions | ||
parent.x = currentX; | ||
parent.y = midVerticalY - parent.height / 2; | ||
//check if touches one of the contours | ||
checkContourOverlap_1.checkContourOverlap(parentsContour, parent); | ||
currentX = parent.x + parent.width + parent.marginRight; | ||
/////////////////// partners | ||
(_a = parent[settings.nextAfterAccessor]) === null || _a === void 0 ? void 0 : _a.forEach(function (partner) { | ||
partner.x = currentX; | ||
partner.y = midVerticalY - partner.height / 2; | ||
checkContourOverlap_1.checkContourOverlap(parentsContour, partner); | ||
currentX = partner.x + partner.width + partner.marginRight; | ||
}); | ||
drillParents(parent); | ||
}); | ||
centerSourceToTargets_1.centerSourceToTargets(subtree, parents, settings, map); | ||
} | ||
drillParents_1.drillParents(root, settings, map); | ||
normalizeTree_1.normalizeTree(root, settings.sourcesAccessor, settings, map); | ||
@@ -149,0 +48,0 @@ return getElements_1.getElements(root, settings, map); |
@@ -8,2 +8,4 @@ "use strict"; | ||
root.y = settings.rootY; | ||
root.groupTopY = root.y; | ||
root.groupLeftX = root.x; | ||
root.isRoot = true; | ||
@@ -10,0 +12,0 @@ return root; |
import { Settings } from "./Settings"; | ||
import { TreeMap } from "./TreeMap"; | ||
import { TreeNode } from "./TreeNode"; | ||
export declare const normalizeTree: <T>(root: TreeNode<T>, accessor: string, settings: Settings, map?: TreeMap<T>) => void; | ||
export declare const normalizeTree: (root: TreeNode, accessor: string, settings: Settings, map: TreeMap) => void; |
@@ -7,45 +7,55 @@ "use strict"; | ||
var normalizeTree = function (root, accessor, settings, map) { | ||
var targets = map | ||
? getFromMap_1.getFromMap(root[accessor], map) | ||
: root[accessor]; | ||
var targets = getFromMap_1.getFromMap(root[accessor], map); | ||
if (!targets || !targets.length) | ||
return; | ||
var rootCenter = root.x + root.width / 2; | ||
var firstTargetSiblings = map | ||
? getFromMap_1.getFromMap(targets[0][settings.nextBeforeAccessor], map) | ||
: targets[0][settings.nextBeforeAccessor]; | ||
var leftMostNode = (firstTargetSiblings === null || firstTargetSiblings === void 0 ? void 0 : firstTargetSiblings[0]) | ||
? firstTargetSiblings === null || firstTargetSiblings === void 0 ? void 0 : firstTargetSiblings[0] | ||
: targets[0]; | ||
var firstTargetSiblings = getFromMap_1.getFromMap(targets[0][settings.nextBeforeAccessor], map); | ||
var firstMostNode = (firstTargetSiblings === null || firstTargetSiblings === void 0 ? void 0 : firstTargetSiblings[0]) || targets[0]; | ||
var lastTarget = last_1.last(targets); | ||
var lastTargetPartner = map | ||
? last_1.last(getFromMap_1.getFromMap(lastTarget[settings.nextAfterAccessor], map)) | ||
: last_1.last(lastTarget[settings.nextAfterAccessor]); | ||
var rightMostNode = lastTargetPartner ? lastTargetPartner : lastTarget; | ||
var centerPoint = (leftMostNode.x + rightMostNode.x + rightMostNode.width) / 2; | ||
var shift = centerPoint - rootCenter; | ||
targets.forEach(function (node) { | ||
drillTargets(node); | ||
}); | ||
function drillTargets(subtree) { | ||
var lastTargetPartner = last_1.last(getFromMap_1.getFromMap(lastTarget[settings.nextAfterAccessor], map)); | ||
var lastMostNode = lastTargetPartner || lastTarget; | ||
var shift; | ||
if (settings.orientation === "vertical") { | ||
var centerPointX = (firstMostNode.x + lastMostNode.x + lastMostNode.width) / 2; | ||
var rootCenterX = root.x + root.width / 2; | ||
shift = centerPointX - rootCenterX; | ||
targets.forEach(function (node) { | ||
normalizeTargetsX(node); | ||
}); | ||
} | ||
else { | ||
var centerPointY = (firstMostNode.y + lastMostNode.y + lastMostNode.height) / 2; | ||
var rootCenterY = root.y + root.height / 2; | ||
shift = centerPointY - rootCenterY; | ||
targets.forEach(function (node) { | ||
normalizeTargetsY(node); | ||
}); | ||
} | ||
function normalizeTargetsX(subtree) { | ||
var _a, _b, _c; | ||
subtree.x -= shift; | ||
var siblings = map | ||
? getFromMap_1.getFromMap(subtree[settings.nextBeforeAccessor], map) | ||
: subtree[settings.nextBeforeAccessor]; | ||
siblings === null || siblings === void 0 ? void 0 : siblings.forEach(function (sibling) { | ||
(_a = getFromMap_1.getFromMap(subtree[settings.nextBeforeAccessor], map)) === null || _a === void 0 ? void 0 : _a.forEach(function (sibling) { | ||
sibling.x -= shift; | ||
}); | ||
var partners = map | ||
? getFromMap_1.getFromMap(subtree[settings.nextAfterAccessor], map) | ||
: subtree[settings.nextAfterAccessor]; | ||
partners === null || partners === void 0 ? void 0 : partners.forEach(function (partner) { | ||
(_b = getFromMap_1.getFromMap(subtree[settings.nextAfterAccessor], map)) === null || _b === void 0 ? void 0 : _b.forEach(function (partner) { | ||
partner.x -= shift; | ||
}); | ||
var next = map ? getFromMap_1.getFromMap(subtree[accessor], map) : subtree[accessor]; | ||
next === null || next === void 0 ? void 0 : next.forEach(function (node) { | ||
drillTargets(node); | ||
(_c = getFromMap_1.getFromMap(subtree[accessor], map)) === null || _c === void 0 ? void 0 : _c.forEach(function (node) { | ||
normalizeTargetsX(node); | ||
}); | ||
} | ||
function normalizeTargetsY(subtree) { | ||
var _a, _b, _c; | ||
subtree.y -= shift; | ||
(_a = getFromMap_1.getFromMap(subtree[settings.nextBeforeAccessor], map)) === null || _a === void 0 ? void 0 : _a.forEach(function (sibling) { | ||
sibling.y -= shift; | ||
}); | ||
(_b = getFromMap_1.getFromMap(subtree[settings.nextAfterAccessor], map)) === null || _b === void 0 ? void 0 : _b.forEach(function (partner) { | ||
partner.y -= shift; | ||
}); | ||
(_c = getFromMap_1.getFromMap(subtree[accessor], map)) === null || _c === void 0 ? void 0 : _c.forEach(function (node) { | ||
normalizeTargetsY(node); | ||
}); | ||
} | ||
}; | ||
exports.normalizeTree = normalizeTree; | ||
//# sourceMappingURL=normalizeTree.js.map |
@@ -17,2 +17,3 @@ export declare type Settings = { | ||
targetsAccessor: string; | ||
orientation: "vertical" | "horizontal"; | ||
}; |
import { TreeNode } from "TreeNode"; | ||
export declare type TreeMap<T> = Record<string, TreeNode<T>>; | ||
export declare type TreeMap<T = {}> = Record<string, TreeNode<T>>; |
@@ -1,5 +0,2 @@ | ||
export declare type TreeNode<T extends {}> = T & { | ||
bottomLineY: number; | ||
children?: TreeNode<T>[]; | ||
height: number; | ||
export declare type TreeNode<T extends {} = {}> = T & { | ||
isAncestor?: boolean; | ||
@@ -10,6 +7,9 @@ isDescendant?: boolean; | ||
marginRight: number; | ||
parents?: TreeNode<T>[]; | ||
partners?: TreeNode<T>[]; | ||
siblings?: TreeNode<T>[]; | ||
topLineY: number; | ||
groupTopY: number; | ||
groupBottomY: number; | ||
groupLeftX: number; | ||
groupRightX: number; | ||
groupMaxHeight: number; | ||
groupMaxWidth: number; | ||
height: number; | ||
width: number; | ||
@@ -16,0 +16,0 @@ x: number; |
{ | ||
"name": "entitree-flex", | ||
"version": "0.3.4", | ||
"description": "Flexible Tree layout supporting ancestors, descendants and side nodes", | ||
"version": "0.4.0", | ||
"description": "Flexible Tree layout supporting ancestors, descendants and side nodes in all 4 orientations", | ||
"main": "dist/index.js", | ||
@@ -12,3 +12,3 @@ "types": "dist/index.d.ts", | ||
"dev": "tsc --watch", | ||
"browser": "watchify playground/example.js -p [ tsify ] -o playground/bundle.js" | ||
"browser": "watchify playground/source.js -p [ tsify ] -o playground/bundle.js" | ||
}, | ||
@@ -15,0 +15,0 @@ "files": [ |
100
README.md
@@ -34,71 +34,2 @@ # entitree-flex | ||
## Usage from nested object | ||
``` | ||
const { layoutFromNested } = require("entitree-flex") | ||
//or | ||
import { layoutFromNested } from "entitree-flex" | ||
const tree = { | ||
name: "root", | ||
width: 60, | ||
height: 20, | ||
siblings: [ | ||
{ name: "rootSibling1" }, | ||
{ name: "rootSibling2"}, | ||
], | ||
partners: [{ name: "rootPartner1" }, { name: "rootPartner2" }], | ||
children: [ | ||
{ | ||
name: "child1", | ||
width: 20, | ||
height: 50, | ||
partners: [ | ||
{ | ||
name: "child1partner1", | ||
}, | ||
], | ||
children: [ | ||
{ | ||
name: "grandchild1", | ||
children: [ | ||
{ | ||
name: "grandGrandchild1", | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "grandchild2", | ||
}, | ||
], | ||
}, | ||
], | ||
parents: [ | ||
{ | ||
name: "parent1", | ||
parents: [ | ||
{ | ||
name: "grandParent1", | ||
}, | ||
{ | ||
name: "grandParent2", | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "parent1", | ||
parents: [ | ||
{ | ||
name: "grandparent1", | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
layoutFromNested(tree [, settings]) | ||
``` | ||
and the object will be populated with all the coordinates for a flexible, bidirectional, side-nodes supporting tree | ||
## Usage from flat object | ||
@@ -115,23 +46,34 @@ | ||
width: 14, | ||
childrenIds: [2, 3], | ||
children: [2, 3], | ||
parents: [7] | ||
}, | ||
2: { name: "child2" }, | ||
3: { name: "child3", childrenIds: [4, 5], spousesIds: [6] }, | ||
3: { name: "child3", children: [4, 5], spouses: [6] }, | ||
4: { name: "grandChild4" }, | ||
5: { name: "grandChild5" }, | ||
6: { name: "spouse of child 3" }, | ||
7: { name: "parent of root" }, | ||
}; | ||
layoutFromMap(1, flatTree [, settings]) | ||
const { map, maxBottom, maxLeft, maxRight, maxTop, nodes, rels } = layoutFromMap(1, flatTree [, settings]) | ||
``` | ||
## Playground | ||
You can play live in your browser with random trees or make your own tree for testing. | ||
Just run `yarn browser` and then open the file `playground/index.html` in your broser and see the results. | ||
Edit the `playground/source.js` file to see changes. | ||
## Settings | ||
Structure and defaults of the settings | ||
``` | ||
defaultSettings = { | ||
clone: false, // returns a copy of the input, if your application does not allow editing the original object | ||
enableFlex: true, // has slightly better perfomance if turned off (node.width, node.height will not be read) | ||
firstDegreeSpacing: 15, // spacing in px between nodes belonging to the same source, eg children with same parent | ||
secondDegreeSpacing: 20, // spacing in px between nodes not belonging to same parent eg "cousin" nodes | ||
enableFlex: true, // has slightly better perfomance if turned off (node.width, node.height will not be read) | ||
nextAfterAccessor: "partners", // the side node prop used to go sideways, AFTER the current node | ||
nextAfterAccessor: "spouses", // the side node prop used to go sideways, AFTER the current node | ||
nextAfterSpacing: 10, // the spacing of the "side" nodes AFTER the current node | ||
@@ -142,7 +84,9 @@ nextBeforeAccessor: "siblings", // the side node prop used to go sideways, BEFORE the current node | ||
nodeWidth: 40, // default node width in px | ||
orientation: "vertical", // "vertical" to see parents top and children bottom, "horizontal" to see parents left and | ||
rootX: 0, // set root position if other than 0 | ||
rootY: 0, // set root position if other than 0 | ||
sourcesAccessor: "parents", // the prop used to go up the ancestors | ||
sourceTargetSpacing: 10, // the "vertical" spacing in vertical layout | ||
targetsAccessor: "children", // what prop to use to pick up children | ||
secondDegreeSpacing: 20, // spacing in px between nodes not belonging to same parent eg "cousin" nodes | ||
sourcesAccessor: "parents", // the prop used as the array of ancestors ids | ||
sourceTargetSpacing: 10, // the "vertical" spacing between nodes in vertical orientation, horizontal otherwise | ||
targetsAccessor: "children", // the prop used as the array of children ids | ||
}; | ||
@@ -149,0 +93,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
133606
113
1548
96