Skip to content

Commit

Permalink
Merge branch 'master' into jk/checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrumbiegel authored Oct 1, 2024
2 parents 7ae8f32 + 4f2971d commit 1e3a198
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

## [Unreleased]

- Fixed issue with CairoMakie rendering scene backgrounds at the wrong position [#4425](https://github.com/MakieOrg/Makie.jl/pull/4425)
- Fix incorrect inverse transformation in `position_on_plot` for lines, causing incorrect tooltip placement in DataInspector [#4402](https://github.com/MakieOrg/Makie.jl/pull/4402)
- Added new `Checkbox` block [#4336](https://github.com/MakieOrg/Makie.jl/pull/4336).
- `PolarAxis` font size now defaults to global figure `fontsize` in the absence of specific `Axis` theming [#4314](https://github.com/MakieOrg/Makie.jl/pull/4314)
- `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.12] - 2024-09-28

Expand Down
12 changes: 10 additions & 2 deletions CairoMakie/src/infrastructure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,25 @@ function prepare_for_scene(screen::Screen, scene::Scene)
end

function draw_background(screen::Screen, scene::Scene)
w, h = Makie.widths(viewport(Makie.root(scene))[])
return draw_background(screen, scene, h)
end

function draw_background(screen::Screen, scene::Scene, root_h)
cr = screen.context
Cairo.save(cr)
if scene.clear[]
bg = scene.backgroundcolor[]
Cairo.set_source_rgba(cr, red(bg), green(bg), blue(bg), alpha(bg));
r = viewport(scene)[]
Cairo.rectangle(cr, origin(r)..., widths(r)...) # background
# Makie has (0,0) at bottom left, Cairo at top left. Makie extends up,
# Cairo down. Negative height breaks other backgrounds
x, y = origin(r); w, h = widths(r)
Cairo.rectangle(cr, x, root_h - y - h, w, h) # background
fill(cr)
end
Cairo.restore(cr)
foreach(child_scene-> draw_background(screen, child_scene), scene.children)
foreach(child_scene-> draw_background(screen, child_scene, root_h), scene.children)
end

function draw_plot(scene::Scene, screen::Screen, primitive::Plot)
Expand Down
3 changes: 2 additions & 1 deletion ReferenceTests/src/tests/examples3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ end
meshscatter(positions, color=colS, markersize=sizesS)
end

@reference_test "Ellipsoid marker sizes" begin # see PR #3722
@reference_test "Basic Shading" begin
f = Figure(size = (500, 300))

# see PR #3722
pts = Point3f[[0, 0, 0], [1, 0, 0]]
markersize = Vec3f[[0.5, 0.2, 0.5], [0.5, 0.2, 0.5]]
rotation = [qrotation(Vec3f(1, 0, 0), 0), qrotation(Vec3f(1, 1, 0), π / 4)]
Expand Down
9 changes: 9 additions & 0 deletions ReferenceTests/src/tests/short_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,15 @@ end
f
end

@reference_test "Scene backgroundcolor" begin
root = Scene(size = (500, 500))
Scene(root, viewport = Rect2f(0,0,250,250), backgroundcolor = :red, clear = true)
Scene(root, viewport = Rect2f(250,0,250,250), backgroundcolor = :blue, clear = true)
Scene(root, viewport = Rect2f(50,300,300,50), backgroundcolor = :cyan, clear = true)
Scene(root, viewport = Rect2f(350,400,50,200), backgroundcolor = :orange, clear = true)
root
end


# Needs a way to disable autolimits on show
# @reference_test "interactions after close" begin
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, lab),) -> x != 0 ? lab : "0", zip(multiples, labs))
end

return locs, labs
end

function get_ticks(m::AngularTicks, any_scale, ::Automatic, vmin, vmax)
Expand Down
11 changes: 9 additions & 2 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; strip_zero = false) = MultiplesTicks(n_ideal, multiple, suffix, strip_zero)

"""
AngularTicks(label_factor, suffix[, n_ideal::Vector{Vec2f}])
Expand Down Expand Up @@ -1924,7 +1931,7 @@ end
"The formatter for the `r` ticks"
rtickformat = Makie.automatic
"The fontsize of the `r` tick labels."
rticklabelsize::Float32 = inherit(scene, (:Axis, :xticklabelsize), 16)
rticklabelsize::Float32 = inherit(scene, (:Axis, :yticklabelsize), inherit(scene, :fontsize, 16))
"The font of the `r` tick labels."
rticklabelfont = inherit(scene, (:Axis, :xticklabelfont), inherit(scene, :font, Makie.defaultfont()))
"The color of the `r` tick labels."
Expand Down Expand Up @@ -1960,7 +1967,7 @@ end
"The formatter for the `theta` ticks."
thetatickformat = Makie.automatic
"The fontsize of the `theta` tick labels."
thetaticklabelsize::Float32 = inherit(scene, (:Axis, :yticklabelsize), 16)
thetaticklabelsize::Float32 = inherit(scene, (:Axis, :xticklabelsize), inherit(scene, :fontsize, 16))
"The font of the `theta` tick labels."
thetaticklabelfont = inherit(scene, (:Axis, :yticklabelfont), inherit(scene, :font, Makie.defaultfont()))
"The color of the `theta` tick labels."
Expand Down
24 changes: 24 additions & 0 deletions test/PolarAxis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,28 @@
ax = PolarAxis(fig[1, 1], radius_at_origin = -1.0, rlimits = (0, 10))
@test ax.scene.transformation.transform_func[].r0 == -1.0
end

@testset "PolarAxis fontsize from Figure()" begin
fig = Figure(fontsize = 50)
ax = PolarAxis(fig[1, 1])
@test ax.rticklabelsize[] == 50
@test ax.thetaticklabelsize[] == 50
end

@testset "PolarAxis fontsize from :Axis" begin
fig = Figure(; Axis = (; xticklabelsize = 35, yticklabelsize = 65))
ax = PolarAxis(fig[1, 1])
@test ax.thetaticklabelsize[] == 35
@test ax.rticklabelsize[] == 65
end

@testset "PolarAxis fontsize from Theme()" begin
fontsize_theme = Theme(fontsize = 10)
with_theme(fontsize_theme) do
fig = Figure()
ax = PolarAxis(fig[1, 1])
@test ax.rticklabelsize[] == 10
@test ax.thetaticklabelsize[] == 10
end
end
end
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 == ""
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

0 comments on commit 1e3a198

Please sign in to comment.