Skip to content
This repository was archived by the owner on Jul 13, 2021. It is now read-only.

Commit 0601c06

Browse files
authored
Merge pull request #504 from timholy/teh/infer_update_limits
Improve inference in `update_limits!`
2 parents 37f8c19 + 6eef5c9 commit 0601c06

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

src/layouting/data_limits.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function data_limits(plots::Vector)
131131
# axis shouldn't be part of the data limit
132132
isaxis(plot) && continue
133133
isa(plot, Legend) && continue
134-
bb2 = data_limits(plot)
134+
bb2 = data_limits(plot)::FRect3D
135135
isfinite(bb) || (bb = bb2)
136136
isfinite(bb2) || continue
137137
bb = union(bb, bb2)

src/scenes.jl

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -511,29 +511,33 @@ it will not update the limits. Call update_limits!(scene, automatic) for that.
511511
"""
512512
update_limits!(scene::Scene) = update_limits!(scene, scene.limits[])
513513

514-
function update_limits!(scene::Scene, limits::Automatic, padding = scene.padding[])
514+
function update_limits!(scene::Scene, limits::Automatic, padding::Vec3f0 = scene.padding[])
515515
# for when scene is empty
516516
dlimits = data_limits(scene)
517517
dlimits === nothing && return #nothing to limit if there isn't anything
518518
tlims = (minimum(dlimits), maximum(dlimits))
519-
if !all(x-> all(isfinite, x), tlims)
520-
@warn "limits of scene contain non finite values: $(tlims[1]) .. $(tlims[2])"
521-
mini = map(x-> ifelse(isfinite(x), x, 0.0), tlims[1])
522-
maxi = Vec3f0(ntuple(3) do i
523-
x = tlims[2][i]
524-
ifelse(isfinite(x), x, tlims[1][i] + 1f0)
525-
end)
519+
let avec = tlims[1], bvec = tlims[2]
520+
if !all(x-> all(isfinite, x), (avec, bvec))
521+
@warn "limits of scene contain non finite values: $(avec) .. $(bvec)"
522+
mini = map(x-> ifelse(isfinite(x), x, zero(x)), avec)
523+
maxi = Vec3f0(ntuple(3) do i
524+
x = bvec[i]
525+
ifelse(isfinite(x), x, avec[i] + oneunit(avec[i]))
526+
end)
527+
end
526528
tlims = (mini, maxi)
527529
end
528-
new_widths = Vec3f0(ntuple(3) do i
529-
a = tlims[1][i]; b = tlims[2][i]
530-
w = b - a
531-
# check for widths == 0.0... 3rd dimension is allowed to be 0 though.
532-
# TODO maybe we should allow any one dimension to be 0, and then use the other 2 as 2D
533-
with0 = (i != 3) && (w 0.0)
534-
with0 && @warn "Founds 0 width in scene limits: $(tlims[1]) .. $(tlims[2])"
535-
ifelse(with0, 1f0, w)
536-
end)
530+
let avec = tlims[1], bvec = tlims[2]
531+
new_widths = Vec3f0(ntuple(3) do i
532+
a = avec[i]; b = bvec[i]
533+
w = b - a
534+
# check for widths == 0.0... 3rd dimension is allowed to be 0 though.
535+
# TODO maybe we should allow any one dimension to be 0, and then use the other 2 as 2D
536+
with0 = (i != 3) && (w 0.0)
537+
with0 && @warn "Founds 0 width in scene limits: $(avec) .. $(bvec)"
538+
ifelse(with0, 1f0, w)
539+
end)
540+
end
537541
update_limits!(scene, FRect3D(tlims[1], new_widths), padding)
538542
end
539543

@@ -550,7 +554,7 @@ and in three dimensions as a vector of the width (x-axis), breadth (y-axis), and
550554
Such a `Rect` can be constructed using the `FRect` or `FRect3D` functions that are exported by
551555
`AbstractPlotting.jl`. See their documentation for more information.
552556
"""
553-
function update_limits!(scene::Scene, new_limits::Rect, padding = scene.padding[])
557+
function update_limits!(scene::Scene, new_limits::Rect, padding::Vec3f0 = scene.padding[])
554558
lims = FRect3D(new_limits)
555559
lim_w = widths(lims)
556560
# use the smallest widths for scaling, to have a consistently wide padding for all sides

0 commit comments

Comments
 (0)