From c91f08ed4dcfb33b3f278afe239808c8225034c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tun=C3=A7=20Ba=C5=9Far=20K=C3=B6se?= Date: Tue, 17 Sep 2024 08:57:18 +0300 Subject: [PATCH] Add option `strip_zero` for MultiplesTicks --- CHANGELOG.md | 1 + src/makielayout/lineaxis.jl | 8 +++++++- src/makielayout/types.jl | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f2c7af9a3d..4d84c3b0fa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased] - Show DataInspector tooltip on NaN values if `nan_color` has been set to other than `:transparent` [#4310](https://github.com/MakieOrg/Makie.jl/pull/4310) +- `MultiplesTicks` accepts new option `strip_zero=true`, allowing labels of the form `0x` to be `0` [#4372](https://github.com/MakieOrg/Makie.jl/pull/4372) ## [0.21.11] - 2024-09-13 diff --git a/src/makielayout/lineaxis.jl b/src/makielayout/lineaxis.jl index d90122093d5..17f08a775a5 100644 --- a/src/makielayout/lineaxis.jl +++ b/src/makielayout/lineaxis.jl @@ -667,7 +667,13 @@ function get_ticks(m::MultiplesTicks, any_scale, ::Automatic, vmin, vmax) dvmax = vmax / m.multiple multiples = Makie.get_tickvalues(LinearTicks(m.n_ideal), dvmin, dvmax) - multiples .* m.multiple, showoff_minus(multiples) .* m.suffix + locs = multiples .* m.multiple + labs = showoff_minus(multiples) .* m.suffix + if m.strip_zero + labs = map(x -> x[1] != '0' ? x : "0", labs) + end + + return locs, labs end function get_ticks(m::AngularTicks, any_scale, ::Automatic, vmin, vmax) diff --git a/src/makielayout/types.jl b/src/makielayout/types.jl index fda5d43bdac..0faa69b0b92 100644 --- a/src/makielayout/types.jl +++ b/src/makielayout/types.jl @@ -66,13 +66,20 @@ that are multiples of pi, printed like "1π", "2π", etc.: ``` MultiplesTicks(5, pi, "π") ``` + +If `strip_zero == true`, then the resulting labels +will be checked and any label that is a multiple of 0 +will be set to "0". """ struct MultiplesTicks n_ideal::Int multiple::Float64 suffix::String + strip_zero::Bool end +MultiplesTicks(n_ideal, multiple, suffix) = MultiplesTicks(n_ideal, multiple, suffix, false) + """ AngularTicks(label_factor, suffix[, n_ideal::Vector{Vec2f}])