From 42fe91c8bb56c43b7d6df3d8bc4ad3705fa8e702 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Sun, 29 Aug 2021 17:08:55 -0400 Subject: [PATCH] gr tick rotations --- src/backends/gr.jl | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index e9de8630..e279e74f 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -672,16 +672,38 @@ end function gr_set_tickfont(sp, letter) axis = sp[Symbol(letter, :axis)] - # invalidate alignment changes for small rotations (|θ| < 45°) - trigger(rot) = abs(sind(rot)) < abs(cosd(rot)) ? 0 : sign(rot) - - rot = axis[:rotation] + rot = axis[:rotation] % 360 if letter === :x || (RecipesPipeline.is3d(sp) && letter === :y) - halign = (:left, :hcenter, :right)[trigger(rot) + 2] - valign = (axis[:mirror] ? :bottom : :top, :vcenter)[trigger(abs(rot)) + 1] + valign = if -90 < rot < 90 || rot < -270 || rot > 270 + axis[:mirror] ? :bottom : :top + elseif abs(rot) % 90 == 0 # -270, -90, 90, 270 + :vcenter + else + axis[:mirror] ? :top : :bottom + end + halign = if abs(rot) % 180 == 0 # -180, 0, 180 + :hcenter + elseif 0 < rot < 180 || -360 < rot < -180 + axis[:mirror] ? :left : :right + else # 180 < rot < 360 || -180 < rot < 0 + axis[:mirror] ? :right : :left + end else - halign = (axis[:mirror] ? :left : :right, :hcenter)[trigger(abs(rot)) + 1] - valign = (:top, :vcenter, :bottom)[trigger(rot) + 2] + valign = if rot % 180 == 0 + :vcenter + elseif 0 < rot < 180 || -360 < rot < -180 + axis[:mirror] ? :top : :bottom + else # rot < 0 + axis[:mirror] ? :bottom : :top + end + + halign = if -90 < rot < 90 || rot < -270 || rot > 270 + axis[:mirror] ? :left : :right + elseif abs(rot) == 90 || abs(rot) == 270 + :hcenter + else # 90 < rot < 270; -270 < rot < -90 + axis[:mirror] ? :right : :left + end end gr_set_font( tickfont(axis),