Allow widen on log axes

This commit is contained in:
Michael K. Borregaard 2017-05-17 14:07:01 +02:00
parent 89a5e5d57a
commit 5060bb97d5
2 changed files with 13 additions and 8 deletions

View File

@ -366,18 +366,20 @@ end
# -------------------------------------------------------------------------
# push the limits out slightly
function widen(lmin, lmax)
span = lmax - lmin
# eps = NaNMath.max(1e-16, min(1e-2span, 1e-10))
eps = NaNMath.max(1e-16, 0.03span)
lmin-eps, lmax+eps
function widen(lmin, lmax, scale)
sf = scalefunc(scale)
isf = invscalefunc(scale)
span = sf(lmax) - sf(lmin)
# eps = max(1e-16, min(1e-2span, 1e-10))
eps = max(1e-16, 0.03span)
isf(lmin-eps), isf(lmax+eps)
end
# figure out if widening is a good idea. if there's a scale set it's too tricky,
# so lazy out and don't widen
function default_should_widen(axis::Axis)
should_widen = false
if axis[:scale] == :identity && !is_2tuple(axis[:lims])
if (!(axis[:scale] in _logScales && axis[:extrema].emin <= 0)) && !is_2tuple(axis[:lims])
for sp in axis.sps
for series in series_list(sp)
if series.d[:seriestype] in (:scatter,) || series.d[:markershape] != :none
@ -408,8 +410,9 @@ function axis_limits(axis::Axis, should_widen::Bool = default_should_widen(axis)
if !isfinite(amin) && !isfinite(amax)
amin, amax = 0.0, 1.0
end
if should_widen
widen(amin, amax)
widen(amin, amax, axis[:scale])
else
amin, amax
end

View File

@ -366,7 +366,9 @@ end
end
# widen limits out a bit
expand_extrema!(axis, widen(ignorenan_extrema(xseg.pts)...))
if !(axis[:scale] in _logScales && extrema(xseg.pts)[1] <= 0)
expand_extrema!(axis, widen(extrema(xseg.pts)..., axis[:scale]))
end
# switch back
if !isvertical(d)