Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Dec 25, 2023
1 parent 3ce0f7b commit d9a3328
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 29 deletions.
1 change: 0 additions & 1 deletion .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
always_for_in = false
import_to_using = false
align_pair_arrow = true
align_assignment = true
Expand Down
20 changes: 9 additions & 11 deletions src/ticks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function optimize_ticks_typed(
# try to favor integer exponents for log scales
(nice_scale = !is_log_scale || isinteger(tickspan)) || (qscore = F(0))

while r * tickspan <= x_min
while r * tickspan x_min
# Filter or expand ticks
if extend_ticks
for i 0:(3k - 1)
Expand Down Expand Up @@ -287,7 +287,7 @@ function optimize_ticks_typed(
# we do this because it saves allocations and leaves S type stable
counter = 0
for i 1:imax
if (viewmin - buf) <= S[i] <= (viewmax + buf)
if (viewmin - buf) S[i] (viewmax + buf)
counter += 1
S[counter] = S[i]
end
Expand All @@ -298,7 +298,7 @@ function optimize_ticks_typed(
end

# evaluate quality of ticks
has_zero = r <= 0 && abs(r) < k
has_zero = r 0 && abs(r) < k

# simplicity
s = has_zero && nice_scale ? 1 : 0
Expand All @@ -324,11 +324,11 @@ function optimize_ticks_typed(
if strict_span && span > xspan
score -= 10000
end
if span >= 2xspan
if span 2xspan
score -= 1000
end

if score > high_score && (k_min <= len <= k_max)
if score > high_score && (k_min len k_max)
viewmin_best, viewmax_best = viewmin, viewmax
high_score, len_S_best = score, len
copyto!(S_best, view(S, 1:len))
Expand Down Expand Up @@ -382,10 +382,8 @@ function optimize_ticks(
x_max += Second(1)
end

if year(x_max) - year(x_min) <= 1 && scale :year
if year(x_max) == year(x_min) &&
month(x_max) - month(x_min) <= 1 &&
scale :month
if year(x_max) - year(x_min) 1 && scale :year
if year(x_max) == year(x_min) && month(x_max) - month(x_min) 1 && scale :month
ticks = DateTime[]

scales = [
Expand All @@ -407,7 +405,7 @@ function optimize_ticks(
push!(ticks, ticks[end] + Week(1))
end
push!(ticks, next_month)
if next_month >= x_max
if next_month x_max
break
end
end
Expand Down Expand Up @@ -596,7 +594,7 @@ function optimize_datetime_ticks(a_min, a_max; k_min = 2, k_max = 4)
Dates.Year,
]
i = findfirst(period_hierarchy .== P)
showtype = i >= 5 ? Date : DateTime
showtype = i 5 ? Date : DateTime
start = DateTime((PH(x_min) for PH period_hierarchy[end:-1:i])...) + P(1)
ticks = collect(start:steplength:x_max)
labels = string.(showtype.(ticks))
Expand Down
4 changes: 2 additions & 2 deletions test/adaptive_test_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const test_funcs = [
]

main() = begin
plots = [plot(func...) for func in test_funcs]
plots = [plot(func...) for func test_funcs]

pitchfork = plot(x -> sqrt(x), 0, 10)
plot!(pitchfork, x -> -sqrt(x), 0, 10)
Expand All @@ -38,7 +38,7 @@ main() = begin
m = ceil(Int, (np)) + 1
n, r = divrem(np, m)
r == 0 || (n += 1)
append!(plots, [plot() for _ in 1:(m * n - np)])
append!(plots, [plot() for _ 1:(m * n - np)])

@assert length(plots) == m * n

Expand Down
40 changes: 27 additions & 13 deletions test/downstream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ TOML = Pkg.TOML

failsafe_clone_checkout(versions, path, url) = begin
local repo
for i in 1:6
for i 1:6
try
repo = Pkg.GitTools.ensure_clone(
stdout,
path,
url,
)
repo = Pkg.GitTools.ensure_clone(stdout, path, url)
break
catch err
@warn err
Expand All @@ -30,7 +26,8 @@ end
fake_supported_version!(path) = begin
toml = joinpath(path, "Project.toml")
# fake the supported PlotUtils version for testing (for `Pkg.develop`)
PlotUtils_version = Pkg.Types.read_package(normpath(@__DIR__, "..", "Project.toml")).version
PlotUtils_version =
Pkg.Types.read_package(normpath(@__DIR__, "..", "Project.toml")).version
parsed_toml = TOML.parse(read(toml, String))
parsed_toml["compat"]["PlotUtils"] = string(PlotUtils_version)
open(toml, "w") do io
Expand All @@ -43,7 +40,14 @@ deploy_Plots() = begin
tmpd = mktempdir()
Plots_jl = joinpath(tmpd, "Plots.jl")
Plots_toml = joinpath(Plots_jl, "Project.toml")
versions = joinpath(first(DEPOT_PATH), "registries", "General", "P", "Plots", "Versions.toml")
versions = joinpath(
first(DEPOT_PATH),
"registries",
"General",
"P",
"Plots",
"Versions.toml",
)

failsafe_clone_checkout(versions, Plots_jl, "https://github.com/JuliaPlots/Plots.jl")
fake_supported_version!(Plots_jl)
Expand All @@ -53,10 +57,17 @@ deploy_Plots() = begin
nothing
end

deploy_Makie(extended=false) = begin
deploy_Makie(extended = false) = begin
tmpd = mktempdir()
Makie_jl = joinpath(tmpd, "Makie.jl")
versions = joinpath(first(DEPOT_PATH), "registries", "General", "M", "Makie", "Versions.toml")
versions = joinpath(
first(DEPOT_PATH),
"registries",
"General",
"M",
"Makie",
"Versions.toml",
)

failsafe_clone_checkout(versions, Makie_jl, "https://github.com/MakieOrg/Makie.jl")
fake_supported_version!(Makie_jl)
Expand All @@ -66,7 +77,7 @@ deploy_Makie(extended=false) = begin
if extended # too costly ?
Pkg.develop(path = joinpath(tmpd, "Makie.jl", "ReferenceTests"))
Pkg.develop(path = joinpath(tmpd, "Makie.jl", "CairoMakie"))
# Pkg.develop(path = joinpath(tmpd, "Makie.jl", "GLMakie"))
Pkg.develop(path = joinpath(tmpd, "Makie.jl", "GLMakie"))
end
Pkg.status(["PlotUtils", "MakieCore", "Makie"])
nothing
Expand All @@ -77,14 +88,17 @@ using Plots

@testset "downstream Plots" begin
# test basic plots creation & display (Plots tests are too long to run)
true && @time for i in 1:length(Plots._examples)
true && @time for i 1:length(Plots._examples)
i Plots._backend_skips[:gr] && continue # skip unsupported examples
Plots._examples[i].imports nothing || continue # skip examples requiring optional test deps
show(devnull, Plots.test_examples(:gr, i; disp = false)) # trigger display logic
end
end

deploy_Makie()
extended = tryparse(Bool, get(ENV, "CI", "false")) === false # extended test locally

deploy_Makie(extended)
@testset "downstream Makie" begin
Pkg.test("Makie")
extended && Pkg.test(["CairoMakie", "GLMakie"])
end
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function test_ticks(x, y, ticks)
@test issorted(ticks)
@test all(x .≤ ticks .≤ y)
if x < y
@test length(ticks) >= 2
@test length(ticks) 2
@test is_uniformly_spaced(ticks)
end
end
Expand Down Expand Up @@ -228,7 +228,7 @@ end
end

@testset "PlotUtils.jl/issues/156" begin
for c cgrad([:black, RGBA{Float64}(1,1,1,1)], 5; categorical=true)
for c cgrad([:black, RGBA{Float64}(1, 1, 1, 1)], 5; categorical = true)
@test 0 alpha(c) 1
end
end
Expand Down

0 comments on commit d9a3328

Please sign in to comment.