MakieOrg / GraphMakie.jl

Plotting graphs with Makie
https://graph.makie.org
MIT License
135 stars 23 forks source link

ilabels not inside nodes in 3D #192

Open kockahonza opened 2 weeks ago

kockahonza commented 2 weeks ago

Pretty much as the title says, when I try to use ilabels in 3D layouts the graph works and I do get labels but they're seemingly all offset by a large amount in the z direction. Maybe I'm just not using something correctly but it at least looks like a bug, I'm attaching an image with the resulting plot.

Example plot

hexaeder commented 2 weeks ago

Ah yes, the problem is the following: the text plot is drawn before the scatter plot, because the scatter plot markersize depends on the glyph size of the ilabels. Since the node plot is defined later, its markers would overdraw the labels. To circumvent this, we translate the ilabels plot +1 in z direction

https://github.com/MakieOrg/GraphMakie.jl/blob/85d4a582cceb4b5358302cc92a7c92bcdc9dff48/src/recipes.jl#L254

which is essentially taken from the docs. Not a problem in 2d but quite the problem in 3d... So we need a better way of reordering the plots without actually touching the z coordinate.

asinghvi17 commented 2 weeks ago

Hmm, maybe define a depth_shift? But that might not work in Cairo...would have to investigate. FerriteViz.jl does this.

hexaeder commented 2 weeks ago

depth_shift does not seem to affect different 2d billboards within the same plane, see below example... maybe its possible to reorder the the plots array at the end of the recipe?

using Pkg
pkg"activate --temp"
pkg"add GLMakie"
using GLMakie

pos = Point3{Float32}[(0,0,0),(1,0,0),(0,1,0),(0,0,1)]
labels = ["o", "x", "y", "z"]

fig = Figure()
ax = LScene(fig[1,1])
text!(ax, pos; text=labels, align=(:center,:center), depth_shift=1)
scatter!(ax, pos; markersize=50, depth_shift=-1)