Dynamically calculate horizontal legend position