Skip to content

Commit

Permalink
partial base fix
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Nov 8, 2022
1 parent bb58d1a commit eedf8f9
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,15 @@ end

# create a bar plot as a filled step function
@recipe function f(::Type{Val{:bar}}, x, y, z) # COV_EXCL_LINE
@show x y
procx, procy, xscale, yscale, baseline = _preprocess_barlike(plotattributes, x, y)
nx, ny = length(procx), length(procy)
axis = plotattributes[:subplot][isvertical(plotattributes) ? :xaxis : :yaxis]
cv = [discrete_value!(plotattributes, :x, xi)[1] for xi in procx]
procx = if nx == ny
cv
elseif nx == ny + 1
0.5diff(cv) + cv[1:(end - 1)]
0.5diff(cv) + @view(cv[1:(end - 1)])
else
error(
"bar recipe: x must be same length as y (centers), or one more than y (edges).\n\t\tlength(x)=$(length(x)), length(y)=$(length(y))",
Expand All @@ -436,11 +437,12 @@ end
if (fillto = plotattributes[:fillrange]) === nothing
fillto = 0
end
@show x y
if yscale in _logScales && !all(_is_positive, fillto)
fillto = map(x -> _is_positive(x) ? typeof(baseline)(x) : baseline, fillto)
end

xseg, yseg = Segments(), Segments()
xseg, yseg = map(_ -> Segments(), 1:2)
for i in 1:ny
yi = procy[i]
if !isnan(yi)
Expand Down Expand Up @@ -539,7 +541,7 @@ RecipesPipeline.is_surface(::Type{Val{:hexbin}}) = true
# ---------------------------------------------------------------------------
# Histograms

_bin_centers(v::AVec) = (v[1:(end - 1)] + v[2:end]) / 2
_bin_centers(v::AVec) = (@view(v[1:(end - 1)]) + @view(v[2:end])) / 2

_is_positive(x) = (x > 0) && !(x 0)

Expand All @@ -550,15 +552,13 @@ _scale_adjusted_values(
V::AbstractVector,
scale::Symbol,
) where {T<:AbstractFloat} =
if scale in _logScales
[_positive_else_nan(T, x) for x in V]
else
[T(x) for x in V]
end
scale in _logScales ? _positive_else_nan.(T, V) : T.(V)

round_base(x, b) = b^floor(log(b, x))

_binbarlike_baseline(min_value::T, scale::Symbol) where {T<:Real} =
if scale in _logScales
isnan(min_value) ? T(1e-3) : min_value / T(_logScaleBases[scale]^log10(2))
isnan(min_value) ? T(1e-3) : round_base(min_value, _logScaleBases[scale])
else
zero(T)
end
Expand Down

0 comments on commit eedf8f9

Please sign in to comment.