Makie - transformation of coordinates when using PolarAxis vs Axis

Is there a way to check in a makie plotting recipe what type of axis is being plotted on?

I am trying to work on a plotting recipe for AbstractTrees with both ‘dendrogram’ layouts

and circular layouts

Ideally, any user has access to a treeplot(tree, layout=:dendrogram) or treeplot(tree, layout=:circular)
with the coordinate transformations happening under the hood. But I am not sure how to setup the recipe to check which type of axis it is using, or perhaps dispatch differently based on different types of Axis.

for the dendrogram layout, I can plot

import CairoMakie as CM
using AbstractTrees

tree = ((:a, ((:b, :c), :d)), (:e, ((:f, :g), :h)), :i)
# dictionary of nodes with (x, y) coords as values
nodedict = nodepositions(tree)

# make Vector{Vector{Point2f}} 
# segments for each line going from parent node to child node
segs = makesegments(nodedict, tree)

fig = CM.Figure(size=(500,500))
ax = CM.Axis(fig[1,1])
CM.series!(ax, segs, solid_color=:black)
fig

Then I need to manually convert the xy coordinates to (angle,radius) coords with

nleaves = leafcount(t)
toangle(y) = 2pi * (y / (nleaves))
psegs = map(segs) do seg
    [(toangle(y), x) for (x, y) in seg]
end

and can plot in a PolarAxis with

fig = CM.Figure(size=(500,500))
pax = CM.PolarAxis(fig[1,1])
CM.series!(pax, psegs, solid_color=:black)
fig

but I am not sure where to put this behavior in a recipe

You could check plot.transformation.transform_func which will tell you which nonlinear transformation is applied to the axis!

I had to do a bit of a hack with

occursin("Polar", string(plot.transformation.transform_func[]))

because Makie.Polar is not defined in MakieCore, but this does work for checking if the plotting axis is polar or not.

Thanks!

1 Like