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

Add option strip_zero for MultiplesTicks #4372

Merged
merged 6 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

- Fix NaN handling in WGLMakie [#4282](https://github.com/MakieOrg/Makie.jl/pull/4282).
- 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)
- Fix `linestyle` not being used in `triplot` [#4332](https://github.com/MakieOrg/Makie.jl/pull/4332)
- Fix voxel clipping not being based on voxel centers [#4397](https://github.com/MakieOrg/Makie.jl/pull/4397)
- Parsing `Q` and `q` commands in svg paths with `BezierPath` is now supported [#4413](https://github.com/MakieOrg/Makie.jl/pull/4413)
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 @@
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, lab),) -> x != 0 ? lab : "0", zip(multiples, 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 @@
```
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; strip_zero = false) = MultiplesTicks(n_ideal, multiple, suffix, strip_zero)

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
12 changes: 12 additions & 0 deletions test/makielayout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ end
end
end

@testset "MultiplesTicks strip_zero" begin
default = MultiplesTicks(5, pi, "π")
strip = MultiplesTicks(5, pi, "π"; strip_zero=true)
no_strip = MultiplesTicks(5, pi, "π"; strip_zero=false)

@test default == no_strip
zero_default = Makie.get_ticks(default, nothing, Makie.Automatic(), -7, 7)[2][3]
@test zero_default == "0π"
zero_stripped = Makie.get_ticks(strip, nothing, Makie.Automatic(), -7, 7)[2][3]
@test zero_stripped == "0"
end

@testset "Colorbars" begin
fig = Figure()
hmap = heatmap!(Axis(fig[1, 1]), rand(4, 4))
Expand Down
Loading