function positionNode(node, previousNode, indent, dropCap) {
  //  caculate the node's horizontal offset DX, dx's type might be number or function
  var displacementX = typeof indent === 'function' ? indent(node) : indent * node.depth;

  if (!dropCap) {
    try {
      if (node.id === node.parent.children[0].id) {
        node.x += displacementX;
        node.y = previousNode ? previousNode.y : 0;
        return;
      }
    } catch (e) {// skip to normal when a node has no parent
    }
  }

  node.x += displacementX;
  node.y = previousNode ? previousNode.y + previousNode.height : 0;
  return;
}

module.exports = function (root, indent, dropCap) {
  var previousNode = null;
  root.eachNode(function (node) {
    positionNode(node, previousNode, indent, dropCap);
    previousNode = node;
  });
};