Let $a=\min\{x,y\}$ and $b=\max\{x,y\}$.
The maximum length of a diagonal is limited by $a$, and there will be $1+(b-a)$ such diagonals. For each length $l\in\{1,2,\dots,a-1\}$ there will be two diagonals with length $l$, one before the diagonals of length $a$, and one afterwards. In other words, there are three 'sections':
$\,\,\,\,\,\,\,(\mathbf{1})$ Diagonals with increasing length, starting at $(0,0)$ with length $1$
$\,\,\,\,\,\,\,(\mathbf{2})$ Diagonals with maximum length ($a$), one after the other
$\,\,\,\,\,\,\,(\mathbf{3})$ Diagonals with decreasing length, like $(\mathbf{1})$ but after $(\mathbf{2})$
In $(\mathbf{1})$, a total of $1+2+\dots+(a-1)=\frac{a(a-1)}{2}$ points are crossed.
Hence, if $0\leq n < \frac{a(a-1)}{2}$, then $f(n)$ lies in $(\mathbf{1})$.
In this case, to which diagonal does it belong?
To answer this question, we must find the highest $m$ for which $1+2+\dots+m=\frac{m(m+1)}{2}\leq n$; then $n$ will be on the $(m+1)$-th diagonal.
Rewriting the inequality yields:
$$m^2+m-2n\leq 0$$
so that
$$\frac{-1-\sqrt{1+8n}}{2}\leq m \leq \frac{-1+\sqrt{1+8n}}{2}$$
In particular, the highest $m$ is
$$d(n)=\left\lfloor\frac{-1+\sqrt{1+8n}}{2}\right\rfloor,$$
and $n$ belongs to the diagonal of length $d(n)+1$.
Now, each diagonal crosses points with constant coordinate sum.
In $(\mathbf{1})$, the $(i+1)$-th diagonal crosses points whose coordinates sum to $i$, starting at $(0,i)$.
At each step along the diagonal, the $x$ coordinate increases by $1$ and the $y$ coordinates decreases by $1$.
Hence, we need only find how far along the diagonal $n$ is.
Since $1+2+\dots+d(n)=\frac12d(n)\big(d(n)+1\big)$ have been covered in previous diagonals, if we let
$$\Delta(n)=n-\frac12d(n)\big(d(n)+1\big),$$
then it follows that $f(n)=\Big(\Delta(n),d(n)-\Delta(n)\Big)$.
In $(\mathbf{2})$, a total of $a\cdot\big(1+(b-a)\big)=ab-a(a-1)$ points are crossed.
Hence, if $\frac{a(a-1)}{2}\leq n
Each diagonal here has length $a$, so its easier to find the diagonal to which $n$ belongs. Let
$$\delta(n)=\left\lfloor\frac{n-\frac{a(a-1)}{2}}{a}\right\rfloor;$$
then $n$ belongs to the $\big(\delta(n)+1\big)$-th diagonal of $(\mathbf{2})$. How far along that diagonal $n$ is?
Well, $\frac{a(a-1)}{2}$ points have been crossed in $(\mathbf{1})$, and $\delta(n)$ diagonals have been crossed in $(\mathbf{2})$, for a total of $a\cdot\delta(n)$ points croosed in $(\mathbf{2})$, before $f(n)$.
Therefore, if we let
$$\mathcal{D}(n)=n-\frac{a(a-1)}{2}-a\cdot\delta(n),$$
then it follows that $f(n)=\Big(\mathcal{D}(n),\delta(n)-\mathcal{D}(n)\Big)$.
The case where $f(n)$ lies in $(\mathbf{3})$ is handled similarly to when it lies in $(\mathbf{1})$. Notice that now diagonals start big (lenght $a-1$), getting smaller.