Skip to content

Commit

Permalink
add :none formatter (#4483)
Browse files Browse the repository at this point in the history
* add `:none` formatter

* bump cov
  • Loading branch information
t-bltg authored Oct 30, 2022
1 parent 48a53a0 commit d723222
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/arg_desc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const _arg_desc = KW(
:colorbar_tickfontsize => "Integer. Font pointsize of colorbar tick entries.",
:colorbar_tickfontcolor => "Color Type. Font color of colorbar tick entries",
:colorbar_scale => "Symbol. Scale of the colorbar axis: `:none`, `:ln`, `:log2`, `:log10`",
:colorbar_formatter => "Function, :scientific, :plain or :auto. A method which converts a number to a string for tick labeling.",
:colorbar_formatter => "Function, :scientific, :plain, :none, :auto. A method which converts a number to a string for tick labeling.",
:legend_font => "Font. Font of legend items.",
:legend_titlefont => "Font. Font of the legend title.",
:annotations => "(x,y,text) tuple(s). Can be a single tuple or a list of them. Text can be String, PlotText (created with `text(args...)`), or a tuple of arguments to `text` (e.g., `(\"Label\", 8, :red, :top)`). Add one-off text annotations at the x,y coordinates.",
Expand Down
7 changes: 3 additions & 4 deletions src/axes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ function optimal_ticks_and_labels(ticks, alims, scale, formatter)
x -> string("\$", replace(convert_sci_unicode(x), '×' => "\\times"), "\$"),
Showoff.showoff(unscaled_ticks, :auto),
)
elseif formatter === :none
String[]
else
# there was an override for the formatter... use that on the unscaled ticks
map(formatter, unscaled_ticks)
Expand All @@ -196,12 +198,9 @@ function optimal_ticks_and_labels(ticks, alims, scale, formatter)
# end
end
else
# no finite ticks to show...
String[]
String[] # no finite ticks to show...
end

# @show unscaled_ticks labels
# labels = Showoff.showoff(unscaled_ticks, scale === :log10 ? :scientific : :auto)
unscaled_ticks, labels
end

Expand Down
19 changes: 8 additions & 11 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function series_segments(series::Series, seriestype::Symbol = :path; check = fal
(scale = get(series, scales[n], :identity)) _logScales || continue
for (i, v) in enumerate(s)
if v <= 0
@warn "Invalid negative or zero value $v found at series index $i for $(scale) based $(scales[n])"
@warn "Invalid negative or zero value $v found at series index $i for $scale based $(scales[n])"
@debug "" exception = (DomainError(v), stacktrace())
break
end
Expand Down Expand Up @@ -153,16 +153,15 @@ anynan(istart::Int, iend::Int, args::Tuple) = any(anynan(args), istart:iend)
allnan(istart::Int, iend::Int, args::Tuple) = all(anynan(args), istart:iend)

function Base.iterate(itr::NaNSegmentsIterator, nextidx::Int = itr.n1)
i = findfirst(!anynan(itr.args), nextidx:(itr.n2))
i === nothing && return
(i = findfirst(!anynan(itr.args), nextidx:(itr.n2))) === nothing && return
nextval = nextidx + i - 1

j = findfirst(anynan(itr.args), nextval:(itr.n2))
nextnan = j === nothing ? itr.n2 + 1 : nextval + j - 1

nextval:(nextnan - 1), nextnan
end
Base.IteratorSize(::NaNSegmentsIterator) = Base.SizeUnknown()
Base.IteratorSize(::NaNSegmentsIterator) = Base.SizeUnknown() # COV_EXCL_LINE

# Find minimal type that can contain NaN and x
# To allow use of NaN separated segments with categorical x axis
Expand Down Expand Up @@ -197,7 +196,7 @@ makevec(v::T) where {T} = T[v]
maketuple(x::Real) = (x, x)
maketuple(x::Tuple) = x

RecipesPipeline.unzip(v) = unzip(v)
RecipesPipeline.unzip(v) = unzip(v) # COV_EXCL_LINE

replaceAlias!(plotattributes::AKW, k::Symbol, aliases::Dict{Symbol,Symbol}) =
if haskey(aliases, k)
Expand All @@ -215,7 +214,7 @@ function _heatmap_edges(v::AVec, isedges::Bool = false, ispolar::Bool = false)
vmin, vmax = ignorenan_extrema(v)
extra_min = ispolar ? min(v[1], (v[2] - v[1]) / 2) : (v[2] - v[1]) / 2
extra_max = (v[end] - v[end - 1]) / 2
vcat(vmin - extra_min, 0.5 * (v[1:(end - 1)] + v[2:end]), vmax + extra_max)
vcat(vmin - extra_min, 0.5(v[1:(end - 1)] + v[2:end]), vmax + extra_max)
end

"create an (n+1) list of the outsides of heatmap rectangles"
Expand Down Expand Up @@ -268,7 +267,7 @@ fakedata(sz::Int...) = fakedata(Random.seed!(PLOTS_SEED), sz...)
function fakedata(rng::AbstractRNG, sz...)
y = zeros(sz...)
for r in 2:size(y, 1)
y[r, :] = 0.95 * vec(y[r - 1, :]) + randn(rng, size(y, 2))
y[r, :] = 0.95vec(y[r - 1, :]) + randn(rng, size(y, 2))
end
y
end
Expand Down Expand Up @@ -706,10 +705,8 @@ end
function copy_series!(series, letter)
plt = series[:plot_object]
for s in plt.series_list, l in (:x, :y, :z)
if s !== series || l !== letter
if s[l] === series[letter]
series[letter] = copy(series[letter])
end
if (s !== series || l !== letter) && s[l] === series[letter]
series[letter] = copy(series[letter])
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions test/test_axes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,9 @@ end
@test Plots.expand_extrema!(ax, nothing) == ax[:extrema]
@test Plots.expand_extrema!(ax, true) == ax[:extrema]
end

@testset "no labels" begin
# github.com/JuliaPlots/Plots.jl/issues/4475
pl = plot(100:100:300, hcat([1, 2, 4], [-1, -2, -4]); yformatter = :none)
@test pl[1][:yaxis][:formatter] === :none
end
7 changes: 7 additions & 0 deletions test/test_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ end
@test segments([nan10; 1:15], [1:15; nan10]) == [11:15]
end

@testset "Invalid scale values" begin
@test_logs match_mode = :any (:warn, r"Invalid negative or zero value.*") png(
plot([0, 1], yscale = :log10),
tempname(),
)
end

@testset "Triangulation" begin
x = [0, 1, 2, 0]
y = [0, 0, 1, 2]
Expand Down

0 comments on commit d723222

Please sign in to comment.