@neo4j-nvl/layout-workers
Advanced tools
Comparing version 0.2.11 to 0.2.12
@@ -21,3 +21,3 @@ import cytoscape from 'cytoscape'; | ||
stop: () => { | ||
c.nodes().forEach(n => { | ||
c.nodes().forEach((n) => { | ||
positions[n.id()] = { ...n.position() }; | ||
@@ -24,0 +24,0 @@ positions[n.id()].x += nodeCenterPoint[0]; |
import dagre from '@neo4j-bloom/dagre'; | ||
import binPack from 'bin-pack'; | ||
import graphlib from 'graphlib'; | ||
import binPack from 'bin-pack'; | ||
import { Ranker, SubGraphSpacing, DirectionUp, DirectionDown, DirectionRight, Directions, PackingBin, DefaultNodeSize, GlAdjust } from './constants.js'; | ||
import { DefaultNodeSize, DirectionDown, DirectionRight, DirectionUp, Directions, GlAdjust, PackingBin, Ranker, SubGraphSpacing } from './constants.js'; | ||
const isDirectionVertical = (direction) => direction === DirectionUp || direction === DirectionDown; | ||
@@ -31,12 +31,12 @@ const isDirectionNatural = (direction) => direction === DirectionDown || direction === DirectionRight; | ||
const halfSize = Math.ceil(sn.width / 2.0); | ||
if (minX === null || (sn.x - halfSize) < minX) { | ||
if (minX === null || sn.x - halfSize < minX) { | ||
minX = sn.x - halfSize; | ||
} | ||
if (minY === null || (sn.y - halfSize) < minY) { | ||
if (minY === null || sn.y - halfSize < minY) { | ||
minY = sn.y - halfSize; | ||
} | ||
if (maxX === null || (sn.x + halfSize) > maxX) { | ||
if (maxX === null || sn.x + halfSize > maxX) { | ||
maxX = sn.x + halfSize; | ||
} | ||
if (maxY === null || (sn.y + halfSize) > maxY) { | ||
if (maxY === null || sn.y + halfSize > maxY) { | ||
maxY = sn.y + halfSize; | ||
@@ -190,11 +190,19 @@ } | ||
if (subGraphs.length > 1) { | ||
subGraphs.forEach(subGraph => layoutGraph(subGraph, direction, parents)); | ||
subGraphs.forEach((subGraph) => layoutGraph(subGraph, direction, parents)); | ||
const isVertical = isDirectionVertical(direction); | ||
const isNatural = isDirectionNatural(direction); | ||
const singleNodeGraphs = subGraphs.filter(g => g.nodeCount() === 1); | ||
const multiNodeGraphs = subGraphs.filter(g => g.nodeCount() !== 1); | ||
const singleNodeGraphs = subGraphs.filter((g) => g.nodeCount() === 1); | ||
const multiNodeGraphs = subGraphs.filter((g) => g.nodeCount() !== 1); | ||
if (packing === PackingBin) { | ||
multiNodeGraphs.sort((a, b) => b.nodeCount() - a.nodeCount()); | ||
const adjustDimensionPaddingNormal = ({ width, height, ...rest }) => ({ ...rest, width: width + SubGraphSpacing, height: height + SubGraphSpacing }); | ||
const adjustDimensionPaddingFlip = ({ width, height, ...rest }) => ({ ...rest, width: height + SubGraphSpacing, height: width + SubGraphSpacing }); | ||
const adjustDimensionPaddingNormal = ({ width, height, ...rest }) => ({ | ||
...rest, | ||
width: width + SubGraphSpacing, | ||
height: height + SubGraphSpacing | ||
}); | ||
const adjustDimensionPaddingFlip = ({ width, height, ...rest }) => ({ | ||
...rest, | ||
width: height + SubGraphSpacing, | ||
height: width + SubGraphSpacing | ||
}); | ||
const adjustDimensionPadding = isVertical ? adjustDimensionPaddingNormal : adjustDimensionPaddingFlip; | ||
@@ -211,5 +219,7 @@ const multiGraphDimensions = multiNodeGraphs.map(getGraphDimensions).map(adjustDimensionPadding); | ||
const extentProp = isVertical ? 'height' : 'width'; | ||
const min = bins.reduce((min, d) => min === null ? d[positionProp] : Math.min(d[positionProp], min[extentProp] || 0), null); | ||
const max = bins.reduce((max, d) => max === null ? (d[positionProp] + d[extentProp]) : Math.max((d[positionProp] + d[extentProp]), max[extentProp] || 0), null); | ||
bins.forEach(d => { | ||
const min = bins.reduce((min, d) => (min === null ? d[positionProp] : Math.min(d[positionProp], min[extentProp] || 0)), null); | ||
const max = bins.reduce((max, d) => max === null | ||
? d[positionProp] + d[extentProp] | ||
: Math.max(d[positionProp] + d[extentProp], max[extentProp] || 0), null); | ||
bins.forEach((d) => { | ||
d[positionProp] = min + (max - (d[positionProp] + d[extentProp])); | ||
@@ -252,3 +262,5 @@ }); | ||
const dimensions = multiGraphDimensions[i]; | ||
const centerOffset = isVertical ? Math.floor((graphWidth - dimensions.width) / 2.0) : Math.floor((graphHeight - dimensions.height) / 2.0); | ||
const centerOffset = isVertical | ||
? Math.floor((graphWidth - dimensions.width) / 2.0) | ||
: Math.floor((graphHeight - dimensions.height) / 2.0); | ||
for (const id of subGraph.nodes()) { | ||
@@ -255,0 +267,0 @@ const sn = subGraph.node(id); |
{ | ||
"name": "@neo4j-nvl/layout-workers", | ||
"version": "0.2.11", | ||
"version": "0.2.12", | ||
"license": "SEE LICENSE IN 'Neo4j Early Access Agreement - Visualization Library.pdf'", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
217118
513