@neo4j-nvl/layout-workers 0.2.10 → 0.2.12
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.
|
@@ -18,7 +18,7 @@ export const layout = (elements, boundingBox, spacingFactor, nodeCenterPoint) =>
|
|
|
18
18
|
tile: false,
|
|
19
19
|
randomize: true,
|
|
20
20
|
stop: () => {
|
|
21
|
-
c.nodes().forEach(n => {
|
|
21
|
+
c.nodes().forEach((n) => {
|
|
22
22
|
positions[n.id()] = { ...n.position() };
|
|
23
23
|
positions[n.id()].x += nodeCenterPoint[0];
|
|
24
24
|
positions[n.id()].y += nodeCenterPoint[1];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import dagre from '@neo4j-bloom/dagre';
|
|
2
|
-
import graphlib from 'graphlib';
|
|
3
2
|
import binPack from 'bin-pack';
|
|
4
|
-
import
|
|
3
|
+
import graphlib from 'graphlib';
|
|
4
|
+
import { DefaultNodeSize, DirectionDown, DirectionRight, DirectionUp, Directions, GlAdjust, PackingBin, Ranker, SubGraphSpacing } from './constants.js';
|
|
5
5
|
const isDirectionVertical = (direction) => direction === DirectionUp || direction === DirectionDown;
|
|
6
6
|
const isDirectionNatural = (direction) => direction === DirectionDown || direction === DirectionRight;
|
|
7
7
|
const getGraphDimensions = (g) => {
|
|
@@ -28,16 +28,16 @@ const getGraphDimensions = (g) => {
|
|
|
28
28
|
maxCenterY = sn.y;
|
|
29
29
|
}
|
|
30
30
|
const halfSize = Math.ceil(sn.width / 2.0);
|
|
31
|
-
if (minX === null ||
|
|
31
|
+
if (minX === null || sn.x - halfSize < minX) {
|
|
32
32
|
minX = sn.x - halfSize;
|
|
33
33
|
}
|
|
34
|
-
if (minY === null ||
|
|
34
|
+
if (minY === null || sn.y - halfSize < minY) {
|
|
35
35
|
minY = sn.y - halfSize;
|
|
36
36
|
}
|
|
37
|
-
if (maxX === null ||
|
|
37
|
+
if (maxX === null || sn.x + halfSize > maxX) {
|
|
38
38
|
maxX = sn.x + halfSize;
|
|
39
39
|
}
|
|
40
|
-
if (maxY === null ||
|
|
40
|
+
if (maxY === null || sn.y + halfSize > maxY) {
|
|
41
41
|
maxY = sn.y + halfSize;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -186,15 +186,23 @@ export const layout = (nodes, nodeIds, idToPosition, rels, direction, packing, p
|
|
|
186
186
|
}
|
|
187
187
|
const subGraphs = getConnectedSubGraphs(g, pixelRatio);
|
|
188
188
|
if (subGraphs.length > 1) {
|
|
189
|
-
subGraphs.forEach(subGraph => layoutGraph(subGraph, direction, parents));
|
|
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((g) => g.nodeCount() === 1);
|
|
193
|
+
const multiNodeGraphs = subGraphs.filter((g) => g.nodeCount() !== 1);
|
|
194
194
|
if (packing === PackingBin) {
|
|
195
195
|
multiNodeGraphs.sort((a, b) => b.nodeCount() - a.nodeCount());
|
|
196
|
-
const adjustDimensionPaddingNormal = ({ width, height, ...rest }) => ({
|
|
197
|
-
|
|
196
|
+
const adjustDimensionPaddingNormal = ({ width, height, ...rest }) => ({
|
|
197
|
+
...rest,
|
|
198
|
+
width: width + SubGraphSpacing,
|
|
199
|
+
height: height + SubGraphSpacing
|
|
200
|
+
});
|
|
201
|
+
const adjustDimensionPaddingFlip = ({ width, height, ...rest }) => ({
|
|
202
|
+
...rest,
|
|
203
|
+
width: height + SubGraphSpacing,
|
|
204
|
+
height: width + SubGraphSpacing
|
|
205
|
+
});
|
|
198
206
|
const adjustDimensionPadding = isVertical ? adjustDimensionPaddingNormal : adjustDimensionPaddingFlip;
|
|
199
207
|
const multiGraphDimensions = multiNodeGraphs.map(getGraphDimensions).map(adjustDimensionPadding);
|
|
200
208
|
const singleGraphDimensions = singleNodeGraphs.map(getGraphDimensions).map(adjustDimensionPadding);
|
|
@@ -206,9 +214,11 @@ export const layout = (nodes, nodeIds, idToPosition, rels, direction, packing, p
|
|
|
206
214
|
if (!isNatural) {
|
|
207
215
|
const positionProp = isVertical ? 'y' : 'x';
|
|
208
216
|
const extentProp = isVertical ? 'height' : 'width';
|
|
209
|
-
const min = bins.reduce((min, d) => min === null ? d[positionProp] : Math.min(d[positionProp], min[extentProp] || 0), null);
|
|
210
|
-
const max = bins.reduce((max, d) => max === null
|
|
211
|
-
|
|
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);
|
|
221
|
+
bins.forEach((d) => {
|
|
212
222
|
d[positionProp] = min + (max - (d[positionProp] + d[extentProp]));
|
|
213
223
|
});
|
|
214
224
|
}
|
|
@@ -246,7 +256,9 @@ export const layout = (nodes, nodeIds, idToPosition, rels, direction, packing, p
|
|
|
246
256
|
for (let i = 0; i < multiNodeGraphs.length; i++) {
|
|
247
257
|
const subGraph = multiNodeGraphs[i];
|
|
248
258
|
const dimensions = multiGraphDimensions[i];
|
|
249
|
-
const centerOffset = isVertical
|
|
259
|
+
const centerOffset = isVertical
|
|
260
|
+
? Math.floor((graphWidth - dimensions.width) / 2.0)
|
|
261
|
+
: Math.floor((graphHeight - dimensions.height) / 2.0);
|
|
250
262
|
for (const id of subGraph.nodes()) {
|
|
251
263
|
const sn = subGraph.node(id);
|
|
252
264
|
const n = g.node(id);
|