You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@alanedelman reminded me, that Makie still has no easy way to draw a boundingbox behind some text.
I took the chance to make a simple prototype, which wasn't as simple as I expected.
But this should work fairly well:
functionrounded_rect(bbox, r)
if r ==0returnBezierPath([
MoveTo(Makie.topright(bbox)),
LineTo(Makie.topleft(bbox)),
LineTo(Makie.bottomleft(bbox)),
LineTo(Makie.bottomright(bbox)),
ClosePath()
])
else
w, h =widths(bbox)
_max =min(w/2, h/2)
r1, r2, r3, r4 = r isa NTuple{4, Real} ? r : r isa Real ? (r, r, r, r) :throw(ArgumentError("Invalid cornerradius value $r. Must be a `Real` or a tuple with 4 `Real`s."))
r1, r2, r3, r4 =min.(_max, (r1, r2, r3, r4))
returnBezierPath([
MoveTo(bbox.origin +Point(w, h/2)),
EllipticalArc(Makie.topright(bbox) -Point2f(r1, r1), r1, r1, 0.0, 0, pi/2),
EllipticalArc(Makie.topleft(bbox) +Point2f(r4, -r4), r4, r4, 0.0, pi/2, pi),
EllipticalArc(Makie.bottomleft(bbox) +Point2f(r3, r3), r3, r3, 0.0, pi, 3/2*pi),
EllipticalArc(Makie.bottomright(bbox) +Point2f(-r2, r2), r2, r2, 0.0, 3/2*pi, 2pi),
ClosePath(),
])
endendfunctiontext_bb!(ax, position, text; padding=4, border_radius=0, backgroundcolor=:white, strokecolor=:black, strokewidth=0, text_kw...)
textscene =Scene(ax.blockscene) # needs own scene to not be obstructed by other plots
pos_pix =Observable(Point2f(0, 0))
t =text!(textscene, pos_pix, text=text, space=:pixel, text_kw...)
translate!(t, 0, 0, 10000) # move in front of everything
w, h =widths(boundingbox(t))
rect =Rect2f(-padding/2, -padding/2, w + padding, h + padding)
rrect =rounded_rect(rect, border_radius)
bb =poly!(textscene, rrect, color=backgroundcolor, strokecolor=strokecolor, space=:pixel, strokewidth=strokewidth)
map(ax.scene.camera.projectionview) do mvp
pix = Makie.project(ax.scene, pos)
translate!(bb, pix..., 10000-1)
pos_pix[] = pix
return pix
endreturn t
endbegin
f, ax, pl =scatter(rand(Point3f, 10), axis=(; type=Axis3))
pos =Point3f(0.5)
text_bb!(ax, pos, "MatrixSpace", strokecolor=:black, border_radius=10, padding=10, strokewidth=01)
f
end
The question is, how do we want to integrate this into Makie? @jkrumbiegel, @ffreyer, any API preferences?
I think we can make this a helper function almost like the above, a recipe (although I wonder how we do the thing with the subscene, or if we can get around that), or integrate it into text (I dont like that, this should work with any boundingbox).
The text was updated successfully, but these errors were encountered:
@alanedelman reminded me, that Makie still has no easy way to draw a boundingbox behind some text.
I took the chance to make a simple prototype, which wasn't as simple as I expected.
But this should work fairly well:
The question is, how do we want to integrate this into Makie?
@jkrumbiegel, @ffreyer, any API preferences?
I think we can make this a helper function almost like the above, a recipe (although I wonder how we do the thing with the subscene, or if we can get around that), or integrate it into text (I dont like that, this should work with any boundingbox).
The text was updated successfully, but these errors were encountered: