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 # push the limits out slightly
function widen(lmin, lmax) function widen(lmin, lmax, scale)
span = lmax - lmin sf = scalefunc(scale)
# eps = NaNMath.max(1e-16, min(1e-2span, 1e-10)) isf = invscalefunc(scale)
eps = NaNMath.max(1e-16, 0.03span) span = sf(lmax) - sf(lmin)
lmin-eps, lmax+eps # eps = max(1e-16, min(1e-2span, 1e-10))
eps = max(1e-16, 0.03span)
isf(lmin-eps), isf(lmax+eps)
end end
# figure out if widening is a good idea. if there's a scale set it's too tricky, # 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 # so lazy out and don't widen
function default_should_widen(axis::Axis) function default_should_widen(axis::Axis)
should_widen = false 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 sp in axis.sps
for series in series_list(sp) for series in series_list(sp)
if series.d[:seriestype] in (:scatter,) || series.d[:markershape] != :none 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) if !isfinite(amin) && !isfinite(amax)
amin, amax = 0.0, 1.0 amin, amax = 0.0, 1.0
end end
if should_widen if should_widen
widen(amin, amax) widen(amin, amax, axis[:scale])
else else
amin, amax amin, amax
end end

View File

@ -366,7 +366,9 @@ end
end end
# widen limits out a bit # 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 # switch back
if !isvertical(d) if !isvertical(d)