From 13eb2eb5916f4cbc5dc25668e8c6c094b3ec9851 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Sat, 23 Dec 2023 21:50:50 +0100 Subject: [PATCH] fix minorticks out of limits --- src/makielayout/lineaxis.jl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/makielayout/lineaxis.jl b/src/makielayout/lineaxis.jl index 38ec8004042..7d585eb2698 100644 --- a/src/makielayout/lineaxis.jl +++ b/src/makielayout/lineaxis.jl @@ -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_valid_tick(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 @@ -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_valid_tick(tv, limits), tickvalues_unfiltered) tickvalues[] = tickvalues_unfiltered[i_values_within_limits] @@ -231,7 +230,7 @@ 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 @@ -239,6 +238,8 @@ function update_minor_ticks(minortickpositions, limits::NTuple{2, Float32}, pos_ px_o = extents[1] px_width = extents[2] - extents[1] + minortickvalues = filter(tv -> is_valid_tick(tv, limits), minortickvalues_unfiltered) + tickvalues_scaled = scale.(minortickvalues) tick_fractions = (tickvalues_scaled .- scale(limits[1])) ./ (scale(limits[2]) - scale(limits[1]))