If this would be a 2D char, then i would set it up as a 4 directional char, where the left/right and down or down-left/down-right use the same flipbooks/animations. Then only the upward movements get your diagonal animations.
I guess, for checking, i would use 2 enums (bools are fine too, but i find enums easier to read ^.^), one with the two entries “left” and “right” (for saving, if your current or last direction was in any shape way or form into the left or right direction), and one with “upward” and “sideways” (or “horizontal”); and maybe “downward”, if you ever want add a diagonal downward animation.
Then, whenever you move upward, sideways or downward, you check, what you have currently in the left-right enum, and play the fitting animation.
The left-right movement would have a “Compare” node, and only set the left-right enum to left or right, if there is an input value greater or smaller than Zero (or maybe even 0.1 or 0.2 to have a deadzone for your stick), for your left-right axis (Y).
With that you avoid your char snapping back, if you let your stick go and it snaps into it´s zero position.
For your upward movement, you could use a compare node, that checks, if your vertical value is greater than your 0.5 on your up axis (X+) to get your 45 degree angle, and only then switch from sideways to upward, and if its lower, then it switches back to sideways.
Downward wouldn´t matter, because sideways and downward use the same animation, but if you want it, then you just check for -0.5 or less, to switch to downward.