Please check out the version I modified from the original one.
Now, you can rotate the magnet to any angle you want (including vertically).
What I did was make a transformation:
$x'=x \cos\theta+ y\sin\theta$
for all the coordinates (magnet, compass, field)
The magnetic field is also transformed by
$B'_x=B_x \cos\theta-B_y \sin\theta$
$B'_y=B_x \sin\theta+B_y \cos\theta$
The following is a picture shows magnetic field structure of a magnet.