optimized legend position