Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix spurious minor tick #3505

Merged
merged 3 commits into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ReferenceTests/src/tests/examples2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ function ppu_test_plot(resolution, px_per_unit, scalefactor)
fig, ax, pl = scatter(1:4, markersize=100, color=1:4, figure=(; size=resolution), axis=(; titlesize=50, title="ppu: $px_per_unit, sf: $scalefactor"))
DataInspector(ax)
hidedecorations!(ax)
return fig
fig
end

@reference_test "px_per_unit and scalefactor" begin
Expand All @@ -1373,3 +1373,10 @@ end
st
end
end

@reference_test "spurious minor tick (#3487)" begin
fig = Figure(size=(227, 170))
ax = Axis(fig[1, 1]; yticks = 0:.2:1, yminorticksvisible = true)
ylims!(ax, 0, 1)
fig
end
15 changes: 8 additions & 7 deletions src/makielayout/lineaxis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ function update_tick_obs(tick_obs, horizontal::Observable{Bool}, flipped::Observ
return
end

# if labels are given manually, it's possible that some of them are outside the displayed limits
# we only check approximately because otherwise because of floating point errors, ticks can be dismissed sometimes
is_within_limits(tv, limits) = (limits[1] ≤ tv || limits[1] ≈ tv) && (tv ≤ limits[2] || tv ≈ limits[2])

function update_tickpos_string(closure_args, tickvalues_labels_unfiltered, reversed::Bool, scale)

tickstrings, tickpositions, tickvalues, pos_extents_horizontal, limits_obs = closure_args
Expand All @@ -204,12 +208,7 @@ function update_tickpos_string(closure_args, tickvalues_labels_unfiltered, rever
lim_o = limits[1]
lim_w = limits[2] - limits[1]

# if labels are given manually, it's possible that some of them are outside the displayed limits
# we only check approximately because otherwise because of floating point errors, ticks can be dismissed sometimes
i_values_within_limits = findall(tickvalues_unfiltered) do tv
return (limits[1] <= tv || limits[1] ≈ tv) &&
(tv <= limits[2] || tv ≈ limits[2])
end
i_values_within_limits = findall(tv -> is_within_limits(tv, limits), tickvalues_unfiltered)

tickvalues[] = tickvalues_unfiltered[i_values_within_limits]

Expand All @@ -231,14 +230,16 @@ function update_tickpos_string(closure_args, tickvalues_labels_unfiltered, rever
return
end

function update_minor_ticks(minortickpositions, limits::NTuple{2, Float32}, pos_extents_horizontal, minortickvalues, scale, reversed::Bool)
function update_minor_ticks(minortickpositions, limits::NTuple{2, Float32}, pos_extents_horizontal, minortickvalues_unfiltered, scale, reversed::Bool)
position::Float32, extents_uncorrected::NTuple{2, Float32}, horizontal::Bool = pos_extents_horizontal

extents = reversed ? reverse(extents_uncorrected) : extents_uncorrected

px_o = extents[1]
px_width = extents[2] - extents[1]

minortickvalues = filter(tv -> is_within_limits(tv, limits), minortickvalues_unfiltered)

tickvalues_scaled = scale.(minortickvalues)

tick_fractions = (tickvalues_scaled .- scale(limits[1])) ./ (scale(limits[2]) - scale(limits[1]))
Expand Down
Loading