widen most seriestypes including logscales

This commit is contained in:
Daniel Schwabeneder 2018-06-24 11:03:56 +02:00
parent 440622830a
commit 61a2d962c0
3 changed files with 14 additions and 10 deletions

View File

@ -140,5 +140,6 @@ const _arg_desc = KW(
:gridstyle => "Symbol. Style of the grid lines. Choose from $(_allStyles)", :gridstyle => "Symbol. Style of the grid lines. Choose from $(_allStyles)",
:gridlinewidth => "Number. Width of the grid lines (in pixels)", :gridlinewidth => "Number. Width of the grid lines (in pixels)",
:tick_direction => "Symbol. Direction of the ticks. `:in` or `:out`", :tick_direction => "Symbol. Direction of the ticks. `:in` or `:out`",
:showaxis => "Bool, Symbol or String. Show the axis. `true`, `false`, `:show`, `:hide`, `:yes`, `:no`, `:x`, `:y`, `:z`, `:xy`, ..., `:all`, `:off`" :showaxis => "Bool, Symbol or String. Show the axis. `true`, `false`, `:show`, `:hide`, `:yes`, `:no`, `:x`, `:y`, `:z`, `:xy`, ..., `:all`, `:off`",
:widen => "Bool. Widen the axis limits by a small factor to avoid cut-off markers and lines at the borders. Defaults to `true`.",
) )

View File

@ -382,6 +382,7 @@ const _axis_defaults = KW(
:gridlinewidth => 0.5, :gridlinewidth => 0.5,
:tick_direction => :in, :tick_direction => :in,
:showaxis => true, :showaxis => true,
:widen => true,
) )
const _suppress_warnings = Set{Symbol}([ const _suppress_warnings = Set{Symbol}([

View File

@ -418,21 +418,23 @@ end
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# push the limits out slightly # push the limits out slightly
function widen(lmin, lmax) function widen(lmin, lmax, scale = :identity)
span = lmax - lmin f, invf = scalefunc(scale), invscalefunc(scale)
span = f(lmax) - f(lmin)
# eps = NaNMath.max(1e-16, min(1e-2span, 1e-10)) # eps = NaNMath.max(1e-16, min(1e-2span, 1e-10))
eps = NaNMath.max(1e-16, 0.03span) eps = NaNMath.max(1e-16, 0.03span)
lmin-eps, lmax+eps invf(f(lmin)-eps), invf(f(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.
# so lazy out and don't widen const _widen_seriestypes = (:line, :path, :steppre, :steppost, :sticks, :scatter, :barbins, :barhist, :histogram, :scatterbins, :scatterhist, :stepbins, :stephist, :bins2d, :histogram2d, :bar, :shape, :path3d, :scatter3d)
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 !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 _widen_seriestypes
should_widen = true should_widen = true
end end
end end
@ -476,8 +478,8 @@ function axis_limits(axis::Axis, should_widen::Bool = default_should_widen(axis)
else else
amin, amax amin, amax
end end
elseif should_widen elseif should_widen && axis[:widen]
widen(amin, amax) widen(amin, amax, axis[:scale])
elseif lims == :round elseif lims == :round
round_limits(amin,amax) round_limits(amin,amax)
else else