Skip to content

text bounding box in an axis #2424

@dgleich

Description

@dgleich

There appear to be some issues with text bounding boxes when used within an axis. Especially when the axis is scaled by a transform.

Expected behavior

using CairoMakie, StableRNGs
x = cumsum(randn(StableRNG(1), 100).^2)
f = lines(x,  axis=(yscale=log10,))
lbl = text!(f.axis, text="Direct Labels are Great!", 50, 50, align=(:right,:bottom))
bb = boundingbox(lbl)
wireframe!(f.axis, bb, color=:red, space=:data)
f

shows a bounding box around the text string.

Instead, this shows:
download

Changing wireframe!(f.axis, bb, color=:red, space=:data) to wireframe!(f.axis.scene, bb, color=:red, space=:pixel) shows no bounding box. Adding campixel(f.axis.scene) does not work either. Plotting text! into f.axis.scene also made no difference.

Where we do see somewhat expected behavior

using CairoMakie, StableRNGs                                                                                                                                                                                                 
x = cumsum(randn(StableRNG(1), 100).^2)
f = lines(x) # CHANGE, no log10 scale...
scene = campixel(f.axis.scene) # CHANGE
lbl = text!(scene, 200, 200, text="Direct Labels are Great!", align=(:right,:bottom),space=:pixel)                 
bb = boundingbox(lbl)                                                                               
wireframe!(scene, bb, color=:red, space=:pixel)         
f

download

This does work, but requires pixel coordinates for the text rather than data coordinates.

This also fails with specifying a logscale y axis...

using CairoMakie, StableRNGs                                                                                                                                                                                                 
x = cumsum(randn(StableRNG(1), 100).^2)
f = lines(x, axis=(yscale=log10,)) # CHANGE, log10 scale...
scene = campixel(f.axis.scene) # CHANGE
lbl = text!(scene, 200, 200, text="Direct Labels are Great!", align=(:right,:bottom),space=:pixel)                 
bb = boundingbox(lbl)                                                                               
wireframe!(scene, bb, color=:red, space=:pixel)         
f

download

This was verified on the most recent versions I could update to of CairoMakie (CairoMakie v0.9.2) and Makie (Makie v0.18.2)

See origin of this discussion here:
https://discourse.julialang.org/t/automatic-direct-labels-for-makie-with-voronoi-tessellation/90247/4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions