Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect limits in h/vlines and h/vspan #3427

Merged
merged 4 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## master

- Fixed a bug with h/vlines and h/vspan not correctly resolving transformations [#3418](https://github.com/MakieOrg/Makie.jl/pull/3418)
- Fixed a bug with h/vlines and h/vspan returning the wrong limits, causing an error in Axis [#3427](https://github.com/MakieOrg/Makie.jl/pull/3427)

## 0.20.1

Expand Down
18 changes: 18 additions & 0 deletions src/basic_recipes/hvlines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,21 @@ function Makie.plot!(p::Union{HLines, VLines})
linesegments!(p, line_attributes, points)
p
end

function data_limits(p::HLines)
scene = parent_scene(p)
limits = projview_to_2d_limits(scene.camera.projectionview[])
itf = inverse_transform(p.transformation.transform_func[])
xmin, xmax = apply_transform.(itf[1], first.(extrema(limits)))
ymin, ymax = extrema(p[1][])
return Rect3f(Point3f(xmin, ymin, 0), Vec3f(xmax - xmin, ymax - ymin, 0))
end

function data_limits(p::VLines)
scene = parent_scene(p)
limits = projview_to_2d_limits(scene.camera.projectionview[])
itf = inverse_transform(p.transformation.transform_func[])
xmin, xmax = extrema(p[1][])
ymin, ymax = apply_transform.(itf[2], getindex.(extrema(limits), 2))
return Rect3f(Point3f(xmin, ymin, 0), Vec3f(xmax - xmin, ymax - ymin, 0))
end
21 changes: 21 additions & 0 deletions src/basic_recipes/hvspan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,24 @@ _apply_x_transform(other, v) = error("x transform not defined for transform func
_apply_y_transform(t::Tuple, v) = apply_transform(t[2], v)
_apply_y_transform(other, v) = error("y transform not defined for transform function $(typeof(other))")
_apply_y_transform(::typeof(identity), v) = v


function data_limits(p::HSpan)
scene = parent_scene(p)
limits = projview_to_2d_limits(scene.camera.projectionview[])
itf = inverse_transform(p.transformation.transform_func[])
xmin, xmax = apply_transform.(itf[1], first.(extrema(limits)))
ymin = minimum(p[1][])
ymax = maximum(p[2][])
return Rect3f(Point3f(xmin, ymin, 0), Vec3f(xmax - xmin, ymax - ymin, 0))
end

function data_limits(p::VSpan)
scene = parent_scene(p)
limits = projview_to_2d_limits(scene.camera.projectionview[])
itf = inverse_transform(p.transformation.transform_func[])
xmin = minimum(p[1][])
xmax = maximum(p[2][])
ymin, ymax = apply_transform.(itf[2], getindex.(extrema(limits), 2))
return Rect3f(Point3f(xmin, ymin, 0), Vec3f(xmax - xmin, ymax - ymin, 0))
end
17 changes: 17 additions & 0 deletions test/boundingboxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ end

fig, ax, p = bracket(ps...)
@test data_limits(p) ≈ Rect3f(Point3f(0), Vec3f(1, 1, 0))

fig = Figure()
ax = Axis(fig[1, 1], yscale=log, xscale=log)
scatter!(ax, [0.5, 1, 2], [0.5, 1, 2])
p1 = vlines!(ax, [0.5])
p2 = hlines!(ax, [0.5])
p3 = vspan!(ax, [0.25], [0.75])
p4 = hspan!(ax, [0.25], [0.75])
Makie.reset_limits!(ax)

lims = ax.finallimits[]
x, y = minimum(lims); w, h = widths(lims)

@test data_limits(p1) ≈ Rect3f(Point3f(0.5, y, 0), Vec3f(0, h, 0))
@test data_limits(p2) ≈ Rect3f(Point3f(x, 0.5, 0), Vec3f(w, 0, 0))
@test data_limits(p3) ≈ Rect3f(Point3f(0.25, y, 0), Vec3f(0.5, h, 0))
@test data_limits(p4) ≈ Rect3f(Point3f(x, 0.25, 0), Vec3f(w, 0.5, 0))
end

@testset "boundingbox(plot)" begin
Expand Down
Loading