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

Add space=:transformed #2766

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions ReferenceTests/src/tests/short_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ end
lines!([50,50], [0, 100]; space=:pixel)
lines!([0,1], [0.25, 0.25]; space=:clip)
scatter!(Point2f(0.5, 0), space=:relative)
lines!([Point2f(50, 3), Point2f(55, 4)]; space=:transformed)
f
end

Expand Down
4 changes: 2 additions & 2 deletions src/camera/projection_math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ end

# project between different coordinate systems/spaces
function space_to_clip(cam::Camera, space::Symbol, projectionview::Bool=true)
if is_data_space(space)
if is_data_space(space) || is_transformed_space(space)
return projectionview ? cam.projectionview[] : cam.projection[]
elseif is_pixel_space(space)
return cam.pixel_space[]
Expand All @@ -330,7 +330,7 @@ function space_to_clip(cam::Camera, space::Symbol, projectionview::Bool=true)
end

function clip_to_space(cam::Camera, space::Symbol)
if is_data_space(space)
if is_data_space(space) || is_transformed_space(space)
return inv(cam.projectionview[])
elseif is_pixel_space(space)
w, h = cam.resolution[]
Expand Down
3 changes: 3 additions & 0 deletions src/layouting/data_limits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ function iterate_transformed(plot)
end

function iterate_transformed(points, model, space, trans_func)
if space != :data
tuple()
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should apply from the outside via exclude

function data_limits(scenelike, exclude=(p)-> false)
bb_ref = Base.RefValue(Rect3f())
foreach_plot(scenelike) do plot
if !exclude(plot)
update_boundingbox!(bb_ref, data_limits(plot))
end
end
return bb_ref[]
end

starting from

function getlimits(la::Axis, dim)
# find all plots that don't have exclusion attributes set
# for this dimension
if !(dim in (1, 2))
error("Dimension $dim not allowed. Only 1 or 2.")
end
function exclude(plot)
# only use plots with autolimits = true
to_value(get(plot, dim == 1 ? :xautolimits : :yautolimits, true)) || return true
# only if they use data coordinates
is_data_space(to_value(get(plot, :space, :data))) || return true
# only use visible plots for limits
return !to_value(get(plot, :visible, true))
end
# get all data limits, minus the excluded plots
boundingbox = Makie.data_limits(la.scene, exclude)
# if there are no bboxes remaining, `nothing` signals that no limits could be determined
Makie.isfinite_rect(boundingbox) || return nothing
# otherwise start with the first box
mini, maxi = minimum(boundingbox), maximum(boundingbox)
return (mini[dim], maxi[dim])
end

Scene should already be fine

Makie.jl/src/scenes.jl

Lines 571 to 583 in ffc31a0

function not_in_data_space(p)
!is_data_space(to_value(get(p, :space, :data)))
end
function center!(scene::Scene, padding=0.01, exclude = not_in_data_space)
bb = boundingbox(scene, exclude)
bb = transformationmatrix(scene)[] * bb
w = widths(bb)
padd = w .* padding
bb = Rect3f(minimum(bb) .- padd, w .+ 2padd)
update_cam!(scene, bb)
scene
end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually axis should be fine as is too, since it has is_data_space(to_value(get(plot, :space, :data))) || return true .

(to_ndim(Point3f, project(model, apply_transform(trans_func, point, space)), 0f0) for point in points)
end

Expand Down
3 changes: 2 additions & 1 deletion src/units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ export px

########################################

spaces() = (:data, :pixel, :relative, :clip)
spaces() = (:data, :pixel, :relative, :clip, :transformed)
is_data_space(space) = space === :data
is_pixel_space(space) = space === :pixel
is_relative_space(space) = space === :relative
is_clip_space(space) = space === :clip
is_transformed_space(space) = space === :transformed