Skip to content

Commit

Permalink
Add option strip_zero for MultiplesTicks
Browse files Browse the repository at this point in the history
  • Loading branch information
tuncbkose committed Sep 17, 2024
1 parent 90b219a commit c91f08e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion src/makielayout/lineaxis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 673 in src/makielayout/lineaxis.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/lineaxis.jl#L670-L673

Added lines #L670 - L673 were not covered by tests
end

return locs, labs

Check warning on line 676 in src/makielayout/lineaxis.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/lineaxis.jl#L676

Added line #L676 was not covered by tests
end

function get_ticks(m::AngularTicks, any_scale, ::Automatic, vmin, vmax)
Expand Down
7 changes: 7 additions & 0 deletions src/makielayout/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 81 in src/makielayout/types.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/types.jl#L81

Added line #L81 was not covered by tests

"""
AngularTicks(label_factor, suffix[, n_ideal::Vector{Vec2f}])
Expand Down

0 comments on commit c91f08e

Please sign in to comment.