Refactor calculateScalingFactor so that it takes into account when the x position is off the screen