After 5 years now, this problem is still present and your workaround does not work with the version 3.22
if (roomToTheRight && roomAbove) { horAnchor = "Left"; verAnchor = "bottom"; } else if (roomToTheRight && roomBelow) { horAnchor = "Left"; verAnchor = "top"; } else if (roomToTheLeft && roomBelow) { horAnchor = "Right"; verAnchor = "top"; } else if (roomToTheLeft && roomAbove) { horAnchor = "Right"; verAnchor = "bottom"; } else { // No room in any direcion, choose anchor that gives most room var horCoverages = []; horCoverages.push({ "anchor": "", "overflow": Math.max(0, (contentBox.w / 2) - (absoluteX - left)) + Math.max(0, (contentBox.w / 2) - (right - absoluteX + 1)) }); horCoverages.push({ "anchor": "Right", "overflow": Math.max(0, contentBox.w - (absoluteX - left)) }); horCoverages.push({ "anchor": "Left", "overflow": Math.max(0, contentBox.w - (right - absoluteX + 1)) }); var verCoverages = []; verCoverages.push({ "anchor": "", "overflow": Math.max(0, (heightNeeded / 2) - (absoluteY - top)) + Math.max(0, (heightNeeded / 2) - (bottom - absoluteY + 1)) }); verCoverages.push({ "anchor": "bottom", "overflow": Math.max(0, heightNeeded - (absoluteY - top)) }); verCoverages.push({ "anchor": "top", "overflow": Math.max(0, heightNeeded - (bottom - absoluteY + 1)) }); var sortFunction = function (a, b) { return a.overflow > b.overflow; }; horCoverages.sort(sortFunction); verCoverages.sort(sortFunction); horAnchor = horCoverages[0].anchor; verAnchor = verCoverages[0].anchor; console.log("There's no room for the popup, chose most optimal anchoring " + verAnchor + horAnchor + "..."); }
I have trouble understanding your solution Is it possible to have the full code of your _setPosition function?