From 934a0e5329cae7907ba9c5c034158431eb28f271 Mon Sep 17 00:00:00 2001 From: Frederic Freyer Date: Mon, 30 Sep 2024 18:53:54 +0200 Subject: [PATCH 1/3] Fix position of scene background in CairoMakie (#4425) * fix yflip in CairoMakie background rendering * add refimg test * update changelog * fix test name --- CHANGELOG.md | 1 + CairoMakie/src/infrastructure.jl | 12 ++++++++++-- ReferenceTests/src/tests/examples3d.jl | 3 ++- ReferenceTests/src/tests/short_tests.jl | 9 +++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12021dedfcf..a3b5a4237e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [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) ## [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 From 808d09206476d33637da6edbf8f89e60ec06e972 Mon Sep 17 00:00:00 2001 From: tuncbkose <48298909+tuncbkose@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:04:30 +0300 Subject: [PATCH 2/3] Add option `strip_zero` for MultiplesTicks (#4372) * Add option `strip_zero` for MultiplesTicks * Add test for `MultiplesTicks` * Address feedback * move entry to unreleased [skip ci] --------- Co-authored-by: Simon Co-authored-by: Frederic Freyer --- CHANGELOG.md | 1 + src/makielayout/lineaxis.jl | 8 +++++++- src/makielayout/types.jl | 7 +++++++ test/makielayout.jl | 12 ++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3b5a4237e6..9835a273267 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - 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) +- `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/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 fda5d43bdac..6a721cd7eff 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}]) 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)) From 4f2971dc66fe51fc87ccbaa7f7058ba6d6e287b6 Mon Sep 17 00:00:00 2001 From: Timon Wellhausen <129331127+NeunMonde@users.noreply.github.com> Date: Mon, 30 Sep 2024 22:00:34 +0200 Subject: [PATCH 3/3] Added way for PolarAxis to pull fontsize attribute from Figure (#4314) * Added way for PolarAxis to pull fontsize attribute from Figure Adjusted the "rticklabelsize" and "thetaticklabelsize" properties in the "types.jl" file to fall back to inheriting the fontsize from the Figure, if the ticklabelsize is not defined. This fixes issue #3928 (https://github.com/MakieOrg/Makie.jl/issues/3928). * Added reference tests and changes to CHANGELOG.md for PR #4314 * Corrected and moved reference tests * Removed trailing whitespace * Changed frontsize inheritance according to discussion in PR #4314 yticklabelsize now propagates into rticklabelsize instead of thetaticklabelsize and xticklabelsize now propagates into thetaticklabelsize * Added unit tests similar to image reference tests for PolarAxis fontsize * Removed reference image tests > Actually I think this would be better as unit tests. There is already a refimg test for decorations that should confirm that changing r-/thetaticklabelsize has the desired effect. So here you just need to confirm that the PolarAxis is correctly inheriting values. * Made changelog entry message clearer to understand * Update testset (PolarAxis from Theme) to use correct code for theming * Fixed indentation issues * Update CHANGELOG.md --------- Co-authored-by: Simon Co-authored-by: Frederic Freyer --- CHANGELOG.md | 1 + src/makielayout/types.jl | 4 ++-- test/PolarAxis.jl | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9835a273267..6064c76b08f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - 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) +- `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/src/makielayout/types.jl b/src/makielayout/types.jl index 6a721cd7eff..a0f6ab3ddda 100644 --- a/src/makielayout/types.jl +++ b/src/makielayout/types.jl @@ -1880,7 +1880,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." @@ -1916,7 +1916,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