@neo4j-nvl/layout-workers 0.3.4 → 0.3.5-4ba40ad3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -70,14 +70,6 @@ const createGraph = (pixelRatio) => {
70
70
  g.graph().ranksep = 75 * pixelRatio;
71
71
  return g;
72
72
  };
73
- const findParent = (id, layoutGraph) => {
74
- // predecessors uses inEdges, successors uses outEdges
75
- let pId = findParentForEdges(id, layoutGraph.predecessors(id), layoutGraph);
76
- if (pId === null) {
77
- pId = findParentForEdges(id, layoutGraph.successors(id), layoutGraph);
78
- }
79
- return pId;
80
- };
81
73
  const findParentForEdges = (id, connectedNodes, layoutGraph) => {
82
74
  const { rank: currentRank } = layoutGraph.node(id);
83
75
  let pRank = null;
@@ -99,6 +91,14 @@ const findParentForEdges = (id, connectedNodes, layoutGraph) => {
99
91
  }
100
92
  return pId;
101
93
  };
94
+ const findParent = (id, layoutGraph) => {
95
+ // predecessors uses inEdges, successors uses outEdges
96
+ let pId = findParentForEdges(id, layoutGraph.predecessors(id), layoutGraph);
97
+ if (pId === null) {
98
+ pId = findParentForEdges(id, layoutGraph.successors(id), layoutGraph);
99
+ }
100
+ return pId;
101
+ };
102
102
  const getConnectedSubGraphs = (g, pixelRatio) => {
103
103
  const subGraphs = [];
104
104
  const components = graphlib.alg.components(g);
@@ -126,9 +126,9 @@ const getConnectedSubGraphs = (g, pixelRatio) => {
126
126
  const layoutGraph = (g, direction, parents) => {
127
127
  g.graph().ranker = Ranker;
128
128
  g.graph().rankdir = Directions[direction];
129
- const layoutGraph = dagre.layout(g);
130
- for (const id of layoutGraph.nodes()) {
131
- const pId = findParent(id, layoutGraph);
129
+ const dagreLayoutGraph = dagre.layout(g);
130
+ for (const id of dagreLayoutGraph.nodes()) {
131
+ const pId = findParent(id, dagreLayoutGraph);
132
132
  if (pId !== null) {
133
133
  parents[id] = pId;
134
134
  }
@@ -189,8 +189,8 @@ export const layout = (nodes, nodeIds, idToPosition, rels, direction, packing, p
189
189
  subGraphs.forEach((subGraph) => layoutGraph(subGraph, direction, parents));
190
190
  const isVertical = isDirectionVertical(direction);
191
191
  const isNatural = isDirectionNatural(direction);
192
- const singleNodeGraphs = subGraphs.filter((g) => g.nodeCount() === 1);
193
- const multiNodeGraphs = subGraphs.filter((g) => g.nodeCount() !== 1);
192
+ const singleNodeGraphs = subGraphs.filter((sg) => sg.nodeCount() === 1);
193
+ const multiNodeGraphs = subGraphs.filter((sg) => sg.nodeCount() !== 1);
194
194
  if (packing === PackingBin) {
195
195
  multiNodeGraphs.sort((a, b) => b.nodeCount() - a.nodeCount());
196
196
  const adjustDimensionPaddingNormal = ({ width, height, ...rest }) => ({
@@ -214,10 +214,12 @@ export const layout = (nodes, nodeIds, idToPosition, rels, direction, packing, p
214
214
  if (!isNatural) {
215
215
  const positionProp = isVertical ? 'y' : 'x';
216
216
  const extentProp = isVertical ? 'height' : 'width';
217
- const min = bins.reduce((min, d) => (min === null ? d[positionProp] : Math.min(d[positionProp], min[extentProp] || 0)), null);
218
- const max = bins.reduce((max, d) => max === null
219
- ? d[positionProp] + d[extentProp]
220
- : Math.max(d[positionProp] + d[extentProp], max[extentProp] || 0), null);
217
+ const min = bins.reduce((minBin, d) => (minBin === null ? d[positionProp] : Math.min(d[positionProp], minBin[extentProp] || 0)), null);
218
+ const max = bins.reduce((maxBin, d) => {
219
+ return maxBin === null
220
+ ? d[positionProp] + d[extentProp]
221
+ : Math.max(d[positionProp] + d[extentProp], maxBin[extentProp] || 0);
222
+ }, null);
221
223
  bins.forEach((d) => {
222
224
  d[positionProp] = min + (max - (d[positionProp] + d[extentProp]));
223
225
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neo4j-nvl/layout-workers",
3
- "version": "0.3.4",
3
+ "version": "0.3.5-4ba40ad3",
4
4
  "license": "SEE LICENSE IN 'LICENSE.txt'",
5
5
  "description": "Layout workers for the Neo4j Visualization Library",
6
6
  "keywords": [
@@ -18,11 +18,11 @@
18
18
  "lib"
19
19
  ],
20
20
  "scripts": {
21
- "build": "tsc",
22
- "watch": "tsc -w",
21
+ "build": "yarn global:tsc",
22
+ "watch": "yarn global:tsc -w",
23
23
  "prepack": "cp ../../LICENSE.txt ./",
24
24
  "postpack": "rm LICENSE.txt",
25
- "eslint": "eslint ./src/ --ext .js,.mjs --plugin only-warn"
25
+ "eslint": "yarn global:eslint ./src/ --ext .js,.mjs"
26
26
  },
27
27
  "typedoc": {
28
28
  "entryPoint": "./src/index.js",
@@ -38,12 +38,7 @@
38
38
  "graphlib": "^2.1.8"
39
39
  },
40
40
  "devDependencies": {
41
- "@types/node": "^18.11.11",
42
- "eslint": "8.38.0",
43
- "typescript": "^5.4.5"
41
+ "@types/node": "^18.11.11"
44
42
  },
45
- "peerDependencies": {
46
- "eslint": "*",
47
- "typescript": "*"
48
- }
43
+ "stableVersion": "0.3.5"
49
44
  }