Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

entitree-flex

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

entitree-flex - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

dist/getNextAfters.d.ts

8

dist/addRootSpousesPositions.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addRootSpousesPositions = void 0;
var getNodeBottomY_1 = require("./getNodeBottomY");
var getNodeRightX_1 = require("./getNodeRightX");
var getFromMap_1 = require("./getFromMap");

@@ -10,4 +12,3 @@ var addRootSpousesPositions = function (root, settings, map) {

if (settings.orientation === "vertical") {
currentNode.x =
previousNode.x + previousNode.width + previousNode.marginRight;
currentNode.x = getNodeRightX_1.getNodeRightX(previousNode);
// align vertically

@@ -22,4 +23,3 @@ currentNode.y = root.y + root.height / 2 - currentNode.height / 2;

else {
currentNode.y =
previousNode.y + previousNode.height + previousNode.marginBottom;
currentNode.y = getNodeBottomY_1.getNodeBottomY(previousNode);
// align horizontally

@@ -26,0 +26,0 @@ currentNode.x = root.x + root.width / 2 - currentNode.width / 2;

@@ -8,2 +8,4 @@ "use strict";

firstDegreeSpacing: 15,
groupTargetsByNextAfters: false,
idAccessor: "id",
nextAfterAccessor: "spouses",

@@ -10,0 +12,0 @@ nextAfterSpacing: 10,

@@ -1,1 +0,4 @@

export declare function drillChildren(subtree: any, settings: any, map: any): void;
import { TreeMap } from "./TreeMap";
import { Settings } from "./Settings";
import { TreeNode } from "./TreeNode";
export declare function drillChildren(subtree: TreeNode, settings: Settings, map: TreeMap): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.drillChildren = void 0;
var getNextAfters_1 = require("./getNextAfters");
var getNextBefores_1 = require("./getNextBefores");
var addGroupBottomY_1 = require("./addGroupBottomY");

@@ -16,68 +18,93 @@ var addGroupRightX_1 = require("./addGroupRightX");

function drillChildren(subtree, settings, map) {
var _a;
var children = getFromMap_1.getFromMap(subtree[settings.targetsAccessor], map);
if (!(children === null || children === void 0 ? void 0 : children.length))
return;
children.forEach(function (child) {
child.isDescendant = true;
child.isTarget = true;
});
addLevelNodesSizes_1.addLevelNodesSizes(children, settings, map);
if (settings.orientation === "vertical") {
var initialShiftLeft = getInitialTargetsShiftLeft_1.getInitialTargetsShiftLeft(subtree, children, settings, map);
var currentX_1 = subtree.x - initialShiftLeft;
children.forEach(function (child) {
var _a;
var midVerticalY = subtree.groupBottomY + child.groupMaxHeight / 2;
/////////////////// BEFORES ///////////////////
var siblings = getFromMap_1.getFromMap(child[settings.nextBeforeAccessor], map);
siblings === null || siblings === void 0 ? void 0 : siblings.forEach(function (sibling) {
sibling.x = currentX_1;
sibling.y = midVerticalY - sibling.height / 2;
checkContourOverlap_1.checkContourOverlap(descendantsContour, sibling, settings);
currentX_1 = getNodeRightX_1.getNodeRightX(sibling);
var childrenClusters = new Map();
if (settings.groupTargetsByNextAfters) {
(_a = getNextAfters_1.getNextAfters(subtree, map, settings)) === null || _a === void 0 ? void 0 : _a.forEach(function (nextAfter) {
var nextAfterId = nextAfter[settings.idAccessor];
console.log({ nextAfter: nextAfter });
children.forEach(function (child) {
var _a;
if ((_a = child["sourceIds"]) === null || _a === void 0 ? void 0 : _a.includes(nextAfter["id"])) {
child.virtualSourceId = nextAfterId;
childrenClusters.set(nextAfterId, (childrenClusters.get(nextAfterId) || []).concat(child));
}
});
/////////////////// GROUP MAIN NODE
//Set positions
child.x = currentX_1;
child.y = midVerticalY - child.height / 2;
checkContourOverlap_1.checkContourOverlap(descendantsContour, child, settings);
currentX_1 = getNodeRightX_1.getNodeRightX(child);
/////////////////// AFTERS ///////////////////
(_a = getFromMap_1.getFromMap(child[settings.nextAfterAccessor], map)) === null || _a === void 0 ? void 0 : _a.forEach(function (partner) {
partner.x = currentX_1;
partner.y = midVerticalY - partner.height / 2;
checkContourOverlap_1.checkContourOverlap(descendantsContour, partner, settings);
currentX_1 = getNodeRightX_1.getNodeRightX(partner);
});
addGroupBottomY_1.addGroupBottomY(child, settings, map);
drillChildren(child, settings, map);
});
}
else {
var initialShiftTop = getInitialTargetsShiftTop_1.getInitialTargetsShiftTop(subtree, children, settings, map);
var currentY_1 = subtree.y - initialShiftTop;
children.forEach(function (child) {
var midPointX = subtree.groupRightX + child.groupMaxWidth / 2;
/////////////////// SIBLING
var siblings = getFromMap_1.getFromMap(child[settings.nextBeforeAccessor], map);
siblings === null || siblings === void 0 ? void 0 : siblings.forEach(function (sibling) {
sibling.y = currentY_1;
sibling.x = midPointX - sibling.width / 2;
checkContourOverlap_1.checkContourOverlap(descendantsContour, sibling, settings);
currentY_1 = getNodeBottomY_1.getNodeBottomY(sibling);
childrenClusters.set(subtree[settings.idAccessor], children);
}
childrenClusters.forEach(function (children, virtualSourceId) {
if (settings.orientation === "vertical") {
var initialShiftLeft = getInitialTargetsShiftLeft_1.getInitialTargetsShiftLeft(subtree, children, settings, map);
var currentX_1 = settings.groupTargetsByNextAfters
? map[virtualSourceId].x - initialShiftLeft // minus something more...
: subtree.x - initialShiftLeft;
children.forEach(function (child) {
var _a, _b;
var midVerticalY = subtree.groupBottomY + child.groupMaxHeight / 2;
/////////////////// BEFORES ///////////////////
(_a = getNextBefores_1.getNextBefores(child, map, settings)) === null || _a === void 0 ? void 0 : _a.forEach(function (sibling) {
sibling.x = currentX_1;
sibling.y = midVerticalY - sibling.height / 2;
checkContourOverlap_1.checkContourOverlap(descendantsContour, sibling, settings);
currentX_1 = getNodeRightX_1.getNodeRightX(sibling);
});
/////////////////// GROUP MAIN NODE
//Set positions
child.x = currentX_1;
child.y = midVerticalY - child.height / 2;
checkContourOverlap_1.checkContourOverlap(descendantsContour, child, settings);
currentX_1 = getNodeRightX_1.getNodeRightX(child);
/////////////////// AFTERS ///////////////////
(_b = getFromMap_1.getFromMap(child[settings.nextAfterAccessor], map)) === null || _b === void 0 ? void 0 : _b.forEach(function (partner) {
partner.x = currentX_1;
partner.y = midVerticalY - partner.height / 2;
checkContourOverlap_1.checkContourOverlap(descendantsContour, partner, settings);
currentX_1 = getNodeRightX_1.getNodeRightX(partner);
});
addGroupBottomY_1.addGroupBottomY(child, settings, map);
drillChildren(child, settings, map);
});
/////////////////// CHILD
//Set positions
child.y = currentY_1;
child.x = midPointX - child.width / 2;
checkContourOverlap_1.checkContourOverlap(descendantsContour, child, settings);
currentY_1 = getNodeBottomY_1.getNodeBottomY(child);
/////////////////// partners
var partners = getFromMap_1.getFromMap(child[settings.nextAfterAccessor], map);
partners === null || partners === void 0 ? void 0 : partners.forEach(function (partner) {
partner.y = currentY_1;
partner.x = midPointX - partner.width / 2;
checkContourOverlap_1.checkContourOverlap(descendantsContour, partner, settings);
currentY_1 = getNodeBottomY_1.getNodeBottomY(partner);
}
else {
var initialShiftTop = getInitialTargetsShiftTop_1.getInitialTargetsShiftTop(subtree, children, settings, map);
var currentY_1 = subtree.y - initialShiftTop;
children.forEach(function (child) {
var _a;
var midPointX = subtree.groupRightX + child.groupMaxWidth / 2;
/////////////////// SIBLING
(_a = getNextBefores_1.getNextBefores(child, map, settings)) === null || _a === void 0 ? void 0 : _a.forEach(function (sibling) {
sibling.y = currentY_1;
sibling.x = midPointX - sibling.width / 2;
checkContourOverlap_1.checkContourOverlap(descendantsContour, sibling, settings);
currentY_1 = getNodeBottomY_1.getNodeBottomY(sibling);
});
/////////////////// CHILD
//Set positions
child.y = currentY_1;
child.x = midPointX - child.width / 2;
checkContourOverlap_1.checkContourOverlap(descendantsContour, child, settings);
currentY_1 = getNodeBottomY_1.getNodeBottomY(child);
/////////////////// partners
var partners = getFromMap_1.getFromMap(child[settings.nextAfterAccessor], map);
partners === null || partners === void 0 ? void 0 : partners.forEach(function (partner) {
partner.y = currentY_1;
partner.x = midPointX - partner.width / 2;
checkContourOverlap_1.checkContourOverlap(descendantsContour, partner, settings);
currentY_1 = getNodeBottomY_1.getNodeBottomY(partner);
});
addGroupRightX_1.addGroupRightX(child, settings, map);
drillChildren(child, settings, map);
});
addGroupRightX_1.addGroupRightX(child, settings, map);
drillChildren(child, settings, map);
});
}
}
});
centerSourceToTargets_1.centerSourceToTargets(subtree, children, settings, map);

@@ -84,0 +111,0 @@ }

@@ -19,2 +19,5 @@ "use strict";

return;
parents.forEach(function (parent) {
parent.isAncestor = true;
});
addLevelNodesSizes_1.addLevelNodesSizes(parents, settings, map);

@@ -21,0 +24,0 @@ if (settings.orientation === "vertical") {

@@ -52,3 +52,9 @@ "use strict";

nodes.push(child);
rels.push({ source: subtree, target: child });
rels.push({
virtualSource: child.virtualSourceId
? map[child.virtualSourceId]
: undefined,
source: subtree,
target: child,
});
drill(child, "children");

@@ -55,0 +61,0 @@ });

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInitialTargetsShiftLeft = void 0;
var getFromMap_1 = require("./getFromMap");
var getNextBefores_1 = require("./getNextBefores");
var getNextAfters_1 = require("./getNextAfters");
// o -> siblings

@@ -10,10 +11,9 @@ // p -> Partners

// THE Os and Ps should not be counted!
//because parent will center itself on the REAL children
// because parent will center itself on the REAL children
var getInitialTargetsShiftLeft = function (source, targets, settings, map) {
return (targets.reduce(function (totalWidth, target, index) {
var siblings = getFromMap_1.getFromMap(target[settings.nextBeforeAccessor], map);
var partners = getFromMap_1.getFromMap(target[settings.nextAfterAccessor], map);
var _a, _b;
//for the first child, we don't care about the padding (siblings) left
if (index !== 0) {
siblings === null || siblings === void 0 ? void 0 : siblings.forEach(function (node) {
(_a = getNextBefores_1.getNextBefores(target, map, settings)) === null || _a === void 0 ? void 0 : _a.forEach(function (node) {
totalWidth += node.width + node.marginRight;

@@ -26,3 +26,3 @@ });

if (index !== targets.length - 1) {
partners === null || partners === void 0 ? void 0 : partners.forEach(function (partner) {
(_b = getNextAfters_1.getNextAfters(target, map, settings)) === null || _b === void 0 ? void 0 : _b.forEach(function (partner) {
totalWidth += partner.width + partner.marginRight;

@@ -29,0 +29,0 @@ });

export * from "./layoutFromMap";
export * from "./TreeNode";
export * from "./TreeMap";

@@ -15,2 +15,3 @@ "use strict";

__exportStar(require("./TreeNode"), exports);
__exportStar(require("./TreeMap"), exports);
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeTree = void 0;
var getNodeCenterY_1 = require("./getNodeCenterY");
var getNodeCenterX_1 = require("./getNodeCenterX");
var getFromMap_1 = require("./getFromMap");

@@ -10,14 +12,44 @@ var last_1 = require("./last");

return;
var firstTargetSiblings = getFromMap_1.getFromMap(targets[0][settings.nextBeforeAccessor], map);
var firstMostNode = (firstTargetSiblings === null || firstTargetSiblings === void 0 ? void 0 : firstTargetSiblings[0]) || targets[0];
var firstTargetNextBefore = getFromMap_1.getFromMap(targets[0][settings.nextBeforeAccessor], map);
var firstMostNode = (firstTargetNextBefore === null || firstTargetNextBefore === void 0 ? void 0 : firstTargetNextBefore[0]) || targets[0];
var lastTarget = last_1.last(targets);
var lastTargetPartner = last_1.last(getFromMap_1.getFromMap(lastTarget[settings.nextAfterAccessor], map));
var lastMostNode = lastTargetPartner || lastTarget;
var lastTargetNextAfter = last_1.last(getFromMap_1.getFromMap(lastTarget[settings.nextAfterAccessor], map));
var lastMostNode = lastTargetNextAfter || 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);
if (settings.groupTargetsByNextAfters) {
var groups = targets.reduce(function (groups, target, index) {
if (!target.virtualSourceId) {
groups[root[settings.idAccessor]] =
groups[root[settings.idAccessor]] || [];
groups[root[settings.idAccessor]].push(target);
}
else {
if (!targets[index - 1] ||
target.virtualSourceId !== targets[index - 1].virtualSourceId) {
groups[target.virtualSourceId] = [target];
}
else {
groups[target.virtualSourceId].push(target);
}
}
return groups;
}, {});
console.log({ groups: groups });
var centerPointX = Object.values(groups).reduce(function (acc, group) {
acc += (group[0].x + last_1.last(group).x + last_1.last(group).width) / 2;
return acc;
}, 0) / Object.keys(groups).length;
var virtualCenterPointX = Object.keys(groups).reduce(function (acc, virtualSourceId) {
acc += getNodeCenterX_1.getNodeCenterX(map[virtualSourceId]);
return acc;
}, 0) / Object.keys(groups).length;
shift = centerPointX - virtualCenterPointX;
}
else {
var centerPointX = (firstMostNode.x + lastMostNode.x + lastMostNode.width) / 2;
shift = centerPointX - getNodeCenterX_1.getNodeCenterX(root);
}
targets.forEach(function (target) {
normalizeTargetsX(target);
});

@@ -27,6 +59,5 @@ }

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);
shift = centerPointY - getNodeCenterY_1.getNodeCenterY(root);
targets.forEach(function (target) {
normalizeTargetsY(target);
});

@@ -37,7 +68,7 @@ }

subtree.x -= shift;
(_a = getFromMap_1.getFromMap(subtree[settings.nextBeforeAccessor], map)) === null || _a === void 0 ? void 0 : _a.forEach(function (sibling) {
sibling.x -= shift;
(_a = getFromMap_1.getFromMap(subtree[settings.nextBeforeAccessor], map)) === null || _a === void 0 ? void 0 : _a.forEach(function (nextBefore) {
nextBefore.x -= shift;
});
(_b = getFromMap_1.getFromMap(subtree[settings.nextAfterAccessor], map)) === null || _b === void 0 ? void 0 : _b.forEach(function (partner) {
partner.x -= shift;
(_b = getFromMap_1.getFromMap(subtree[settings.nextAfterAccessor], map)) === null || _b === void 0 ? void 0 : _b.forEach(function (nextAfter) {
nextAfter.x -= shift;
});

@@ -51,7 +82,7 @@ (_c = getFromMap_1.getFromMap(subtree[accessor], map)) === null || _c === void 0 ? void 0 : _c.forEach(function (node) {

subtree.y -= shift;
(_a = getFromMap_1.getFromMap(subtree[settings.nextBeforeAccessor], map)) === null || _a === void 0 ? void 0 : _a.forEach(function (sibling) {
sibling.y -= shift;
(_a = getFromMap_1.getFromMap(subtree[settings.nextBeforeAccessor], map)) === null || _a === void 0 ? void 0 : _a.forEach(function (nextBefore) {
nextBefore.y -= shift;
});
(_b = getFromMap_1.getFromMap(subtree[settings.nextAfterAccessor], map)) === null || _b === void 0 ? void 0 : _b.forEach(function (partner) {
partner.y -= shift;
(_b = getFromMap_1.getFromMap(subtree[settings.nextAfterAccessor], map)) === null || _b === void 0 ? void 0 : _b.forEach(function (nextAfter) {
nextAfter.y -= shift;
});

@@ -58,0 +89,0 @@ (_c = getFromMap_1.getFromMap(subtree[accessor], map)) === null || _c === void 0 ? void 0 : _c.forEach(function (node) {

export declare type Settings = {
clone: boolean;
enableFlex: boolean;
firstDegreeSpacing: number;
secondDegreeSpacing: number;
enableFlex: boolean;
groupTargetsByNextAfters: boolean;
idAccessor: string;
nextAfterAccessor: string;

@@ -14,2 +15,3 @@ nextAfterSpacing: number;

rootY: number;
secondDegreeSpacing: number;
sourcesAccessor: string;

@@ -16,0 +18,0 @@ sourceTargetSpacing: number;

export declare type TreeNode<T extends {} = {}> = T & {
groupBottomY: number;
groupLeftX: number;
groupMaxHeight: number;
groupMaxWidth: number;
groupRightX: number;
groupTopY: number;
height: number;
isAncestor?: boolean;
isDescendant?: boolean;
isNext?: boolean;
isNextAfter?: boolean;
isNextBefore?: boolean;
isRoot?: boolean;
isSource?: boolean;
isTarget?: boolean;
marginBottom: number;
marginRight: number;
groupTopY: number;
groupBottomY: number;
groupLeftX: number;
groupRightX: number;
groupMaxHeight: number;
groupMaxWidth: number;
height: number;
width: number;
virtualSourceId?: number | string;
sourceId?: number | string;
x: number;
y: number;
};
import { TreeNode } from "./TreeNode";
export declare type TreeRel<T> = {
virtualSource?: TreeNode<T>;
source: TreeNode<T>;
target: TreeNode<T>;
};
{
"name": "entitree-flex",
"version": "0.4.0",
"version": "0.4.1",
"description": "Flexible Tree layout supporting ancestors, descendants and side nodes in all 4 orientations",

@@ -8,7 +8,7 @@ "main": "dist/index.js",

"scripts": {
"test": "jest",
"browser": "open playground/index.html && watchify playground/source.js -p [ tsify ] -o playground/bundle.js",
"build": "tsc",
"dev": "tsc --watch",
"prepublishOnly": "yarn build",
"dev": "tsc --watch",
"browser": "watchify playground/source.js -p [ tsify ] -o playground/bundle.js"
"test": "jest"
},

@@ -23,3 +23,2 @@ "files": [

},
"license": "ISC",
"dependencies": {},

@@ -26,0 +25,0 @@ "devDependencies": {

@@ -96,1 +96,7 @@ # entitree-flex

- https://github.com/Klortho/d3-flextree no bidirectional, no side nodes
## License
GNU General Public License v3.0
Copyright (c) 2022, Codeledge

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc