From d551d3c8f7caadf7a36a83d676a9e8e0eb83ca74 Mon Sep 17 00:00:00 2001 From: Frederic Freyer Date: Mon, 14 Aug 2023 20:06:29 +0200 Subject: [PATCH] Fix PolarAxis tick align (#3151) * consider polar direction in tick align * also fix rtick padding --- src/makielayout/blocks/polaraxis.jl | 24 +++++++++++++++++------- src/makielayout/types.jl | 2 ++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/makielayout/blocks/polaraxis.jl b/src/makielayout/blocks/polaraxis.jl index 27997c40748..f536dfdbe53 100644 --- a/src/makielayout/blocks/polaraxis.jl +++ b/src/makielayout/blocks/polaraxis.jl @@ -107,13 +107,19 @@ function draw_axis!(po::PolarAxis, axis_radius) onany( po.blockscene, - po.rticks, po.rminorticks, po.rtickformat, + po.rticks, po.rminorticks, po.rtickformat, po.rticklabelpad, po.rtickangle, po.target_radius, axis_radius, po.sample_density, - ) do rticks, rminorticks, rtickformat, rtickangle, data_radius, axis_radius, sample_density + po.overlay.px_area + ) do rticks, rminorticks, rtickformat, px_pad, rtickangle, data_radius, axis_radius, sample_density, pixelarea _rtickvalues, _rticklabels = Makie.get_ticks(rticks, identity, rtickformat, 0, data_radius) _rtickpos = _rtickvalues .* (axis_radius / data_radius) # we still need the values - rtick_pos_lbl[] = tuple.(_rticklabels, Point2f.(_rtickpos, rtickangle)) + pad = let + w2, h2 = (0.5 .* widths(pixelarea)).^2 + s, c = sincos(rtickangle) + axis_radius * px_pad / sqrt(w2 * c * c + h2 * s * s) + end + rtick_pos_lbl[] = tuple.(_rticklabels, Point2f.(_rtickpos .+ pad, rtickangle)) thetas = LinRange(thetalims..., sample_density) rgridpoints[] = Makie.GeometryBasics.LineString.([Point2f.(r, thetas) for r in _rtickpos]) @@ -133,8 +139,8 @@ function draw_axis!(po::PolarAxis, axis_radius) onany( po.blockscene, po.thetaticks, po.thetaminorticks, po.thetatickformat, po.thetaticklabelpad, - po.theta_0, axis_radius, po.overlay.px_area - ) do thetaticks, thetaminorticks, thetatickformat, px_pad, theta_0, axis_radius, pixelarea + po.direction, po.theta_0, axis_radius, po.overlay.px_area + ) do thetaticks, thetaminorticks, thetatickformat, px_pad, dir, theta_0, axis_radius, pixelarea _thetatickvalues, _thetaticklabels = Makie.get_ticks(thetaticks, identity, thetatickformat, 0, 2pi) @@ -147,7 +153,7 @@ function draw_axis!(po::PolarAxis, axis_radius) end thetatick_align[] = map(_thetatickvalues) do angle - s, c = sincos(angle + theta_0) + s, c = sincos(dir * (angle + theta_0)) scale = 1 / max(abs(s), abs(c)) # point on ellipse -> point on bbox Point2f(0.5 - 0.5scale * c, 0.5 - 0.5scale * s) end @@ -249,7 +255,11 @@ function draw_axis!(po::PolarAxis, axis_radius) color = po.rticklabelcolor, strokewidth = po.rticklabelstrokewidth, strokecolor = rstrokecolor, - align = (:left, :bottom), + align = map(po.direction, po.theta_0, po.rtickangle) do dir, theta_0, angle + s, c = sincos(dir * (angle + theta_0)) + scale = 1 / max(abs(s), abs(c)) # point on ellipse -> point on bbox + Point2f(0.5 - 0.5scale * c, 0.5 - 0.5scale * s) + end ) thetastrokecolor = map(po.blockscene, clipcolor, po.thetaticklabelstrokecolor) do bg, sc diff --git a/src/makielayout/types.jl b/src/makielayout/types.jl index 47228158bed..3a4527d50c0 100644 --- a/src/makielayout/types.jl +++ b/src/makielayout/types.jl @@ -1679,6 +1679,8 @@ end rticklabelstrokewidth = 0.0 "The color of the outline of `r` ticks. By default this uses the background color." rticklabelstrokecolor = automatic + "Padding of the `r` ticks label." + rticklabelpad = 4f0 "Controls if the `r` ticks are visible." rticklabelsvisible = inherit(scene, (:Axis, :xticklabelsvisible), true) "The angle in radians along which the `r` ticks are printed."