I am trying to build a graph using elk.js, and to be able to do that I need to have x value for each node. Nodes on the left should have x value smaller than those on the right.
x values.What I currently have:
x values on the right and on the leftx values of children in the same parent nodex values in each rowI have everything to make it work and in fact, it does work perfectly fine but my main issue is this code below. I am looking for a way to simplify this somehow and I am struggling a lot so any help would be appreciated.
If you have totally different approach than this one I will gladly know those.
if (allNodesFromCurrentRow.length === 0) {
newNode.nodeLayout.x = parentX + 10;
} else {
if (currentValue > 0 && rightValue === 0 && leftValue === 0) {
newNode.nodeLayout.x = currentValue + 1;
} else if (
currentValue === 0 &&
leftValue === 0 &&
rightValue > 0
) {
newNode.nodeLayout.x = rightValue - 1;
} else if (currentValue === 0 && leftValue > 0 && rightValue > 0) {
newNode.nodeLayout.x = (leftValue + rightValue) / 2;
} else if (currentValue > 0 && leftValue === 0 && rightValue > 0) {
newNode.nodeLayout.x = (rightValue + currentValue) / 2;
} else if (
leftValue > 0 &&
currentValue === 0 &&
rightValue === 0
) {
newNode.nodeLayout.x = leftValue + 1;
} else if (leftValue > 0 && currentValue > 0 && rightValue === 0) {
newNode.nodeLayout.x = currentValue + 1;
} else if (leftValue > 0 && currentValue > 0 && rightValue > 0) {
newNode.nodeLayout.x = (rightValue + currentValue) / 2;
}
}