diff --git a/CHANGELOG.md b/CHANGELOG.md index 07563ca0f63..dcc10b2d144 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/CairoMakie/src/infrastructure.jl b/CairoMakie/src/infrastructure.jl index 341dcbc4a5f..0f70934682b 100644 --- a/CairoMakie/src/infrastructure.jl +++ b/CairoMakie/src/infrastructure.jl @@ -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) diff --git a/ReferenceTests/src/tests/examples3d.jl b/ReferenceTests/src/tests/examples3d.jl index 3ef2e8fd14e..63c096f2898 100644 --- a/ReferenceTests/src/tests/examples3d.jl +++ b/ReferenceTests/src/tests/examples3d.jl @@ -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)] diff --git a/ReferenceTests/src/tests/short_tests.jl b/ReferenceTests/src/tests/short_tests.jl index d0415f5de25..f05977e1324 100644 --- a/ReferenceTests/src/tests/short_tests.jl +++ b/ReferenceTests/src/tests/short_tests.jl @@ -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 diff --git a/src/makielayout/lineaxis.jl b/src/makielayout/lineaxis.jl index d90122093d5..853c0d23408 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, lab),) -> x != 0 ? lab : "0", zip(multiples, 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 8c118ee8c71..b6a3aac85a7 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; strip_zero = false) = MultiplesTicks(n_ideal, multiple, suffix, strip_zero) + """ AngularTicks(label_factor, suffix[, n_ideal::Vector{Vec2f}]) @@ -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." @@ -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." diff --git a/test/PolarAxis.jl b/test/PolarAxis.jl index fadd71beae5..c05b24c0289 100644 --- a/test/PolarAxis.jl +++ b/test/PolarAxis.jl @@ -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 \ No newline at end of file diff --git a/test/makielayout.jl b/test/makielayout.jl index bff143e1c89..6c266f0b2a2 100644 --- a/test/makielayout.jl +++ b/test/makielayout.jl @@ -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))