Skip to content

Commit

Permalink
Fix PolarAxis tick align (#3151)
Browse files Browse the repository at this point in the history
* consider polar direction in tick align

* also fix rtick padding
  • Loading branch information
ffreyer authored Aug 14, 2023
1 parent cee376e commit d551d3c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/makielayout/blocks/polaraxis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/makielayout/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit d551d3c

Please sign in to comment.