Evolution of charge order topology across a magnetic phase transition in cuprate superconductors