Source:
public double[] getNext(final CanvasHandler canvasHandler, final Node<View<?>, Edge> root, final Node<View<?>, Edge> newNode) { final double[] rootBounds = getBoundCoordinates(root.getContent()); final double[] size = GraphUtils.getNodeSize(root.getContent()); final double[] newNodeSize = GraphUtils.getNodeSize(newNode.getContent()); final Point2D newNodePosition = GraphUtils.getPosition(newNode.getContent()); final double[][] offset = new double[1][1]; final double[] offsetX = {0}; final double[] offsetY = {0}; final double[] parentOffsetX = {0}; final double[] parentOffsetY = {0}; final Node<View<?>, Edge> parent = (Node<View<?>, Edge>) GraphUtils.getParent(root); if ((parent != null) && (GraphUtils.hasChildren(parent))) { Point2D pos = GraphUtils.getPosition(parent.getContent()); parentOffsetY[0] = pos.getY() + newNodePosition.getY(); parentOffsetX[0] = pos.getX() + newNodePosition.getX() + PADDING_X; offsetX[0] = parentOffsetX[0]; } double maxNodeY[] = {0}; if (root.getOutEdges().size() > 0) { root.getOutEdges().forEach(n -> { final Node<View<?>, Edge> node = n.getTargetNode(); Point2D nodePos = GraphUtils.getPosition(node.getContent()); Point2D rootPos = GraphUtils.getPosition(root.getContent()); if (nodePos.getY() > maxNodeY[0]) { maxNodeY[0] = nodePos.getY(); offset[0] = GraphUtils.getNodeSize(node.getContent()); offsetY[0] = maxNodeY[0] + offset[0][1] - rootPos.getY(); } }); offsetY[0] = offsetY[0] + parentOffsetY[0] + PADDING_Y; } else { offsetY[0] = (parentOffsetY[0] - (newNodeSize[1] - size[1]) / 2); } offsetX[0] = offsetX[0] + PADDING_X; return getNext(canvasHandler, root, size[0], size[1], offsetX[0], offsetY[0], rootBounds[0], rootBounds[1]); }

Target:
public double[] getNext(final CanvasHandler canvasHandler, final Node<View<?>, Edge> root, final Node<View<?>, Edge> newNode) { final double[] rootBounds = getBoundCoordinates(root.getContent()); final double[] rootSize = GraphUtils.getNodeSize(root.getContent()); final double[] newNodeSize = GraphUtils.getNodeSize(newNode.getContent()); final Point2D newNodePosition = GraphUtils.getPosition(newNode.getContent()); Point2D[] offset = {new Point2D(0, 0)}; Point2D[] parentOffset = {new Point2D(0, 0)}; final Node<View<?>, Edge> parent = (Node<View<?>, Edge>) GraphUtils.getParent(root); if ((parent != null) && (GraphUtils.hasChildren(parent))) { final Point2D pos = GraphUtils.getPosition(parent.getContent()); parentOffset[0] = new Point2D(pos.getX() + newNodePosition.getX() + PADDING_X, pos.getY() + newNodePosition.getY()); offset[0].setX(parentOffset[0].getX()); } double maxNodeY[] = {0}; if (root.getOutEdges().size() > 0) { root.getOutEdges().forEach(n -> { final Node<View<?>, Edge> node = n.getTargetNode(); final Point2D nodePos = GraphUtils.getPosition(node.getContent()); final Point2D rootPos = GraphUtils.getPosition(root.getContent()); if (nodePos.getY() > maxNodeY[0]) { maxNodeY[0] = nodePos.getY(); final double[] nodeSize = GraphUtils.getNodeSize(node.getContent()); offset[0].setY(maxNodeY[0] + nodeSize[1] - rootPos.getY()); } }); offset[0].setY(offset[0].getY() + parentOffset[0].getY() + PADDING_Y); } else { offset[0].setY(parentOffset[0].getY() - (newNodeSize[1] - rootSize[1]) / 2); } offset[0].setX(offset[0].getX() + PADDING_X); final Point2D offsetCoordinates = new Point2D(offset[0].getX(), offset[0].getY()); final Point2D rootBoundsCoordinates = new Point2D(rootBounds[0], rootBounds[1]); return getNext(canvasHandler, root, rootSize[1], offsetCoordinates, rootBoundsCoordinates ); }