From 2b97ce77a34a14367edc24f8942d9d09ee014042 Mon Sep 17 00:00:00 2001 From: Frederic Freyer Date: Wed, 24 Jan 2024 13:48:55 +0100 Subject: [PATCH 1/6] Fix CairoMakie transforms (#3552) * use plot transform_func * maybe improve compile time * use plot transform_func for the other overrides too * update NEWS * add refimg test --------- Co-authored-by: Simon --- CairoMakie/src/overrides.jl | 10 +++++----- CairoMakie/src/primitives.jl | 6 +++--- CairoMakie/src/utils.jl | 8 ++++---- NEWS.md | 2 ++ ReferenceTests/src/tests/primitives.jl | 27 ++++++++++++++++++++++++++ 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/CairoMakie/src/overrides.jl b/CairoMakie/src/overrides.jl index 8bccdca5d3c..ec84e83444d 100644 --- a/CairoMakie/src/overrides.jl +++ b/CairoMakie/src/overrides.jl @@ -45,7 +45,7 @@ end function draw_poly(scene::Scene, screen::Screen, poly, points::Vector{<:Point2}, color::Union{Colorant, Cairo.CairoPattern}, model, strokecolor, strokestyle, strokewidth) space = to_value(get(poly, :space, :data)) - points = project_position.(Ref(scene), space, points, Ref(model)) + points = project_position.(Ref(poly), space, points, Ref(model)) Cairo.move_to(screen.context, points[1]...) for p in points[2:end] Cairo.line_to(screen.context, p...) @@ -78,7 +78,7 @@ draw_poly(scene::Scene, screen::Screen, poly, bezierpath::BezierPath) = draw_pol function draw_poly(scene::Scene, screen::Screen, poly, shapes::Vector{<:Union{Rect2,BezierPath}}) model = poly.model[] space = to_value(get(poly, :space, :data)) - projected_shapes = project_shape.(Ref(scene), space, shapes, Ref(model)) + projected_shapes = project_shape.(Ref(poly), space, shapes, Ref(model)) color = to_cairo_color(poly.color[], poly) @@ -175,7 +175,7 @@ end function draw_poly(scene::Scene, screen::Screen, poly, polygons::AbstractArray{<: MultiPolygon}) model = poly.model[] space = to_value(get(poly, :space, :data)) - projected_polys = project_multipolygon.(Ref(scene), space, polygons, Ref(model)) + projected_polys = project_multipolygon.(Ref(poly), space, polygons, Ref(model)) color = to_cairo_color(poly.color[], poly) strokecolor = to_cairo_color(poly.strokecolor[], poly) @@ -211,7 +211,7 @@ function draw_plot(scene::Scene, screen::Screen, points = vcat(lowerpoints, reverse(upperpoints)) model = band.model[] space = to_value(get(band, :space, :data)) - points = project_position.(Ref(scene), space, points, Ref(model)) + points = project_position.(Ref(band), space, points, Ref(model)) Cairo.move_to(screen.context, points[1]...) for p in points[2:end] Cairo.line_to(screen.context, p...) @@ -249,7 +249,7 @@ function draw_plot(scene::Scene, screen::Screen, tric::Tricontourf) polygons = pol[1][] model = pol.model[] space = to_value(get(pol, :space, :data)) - projected_polys = project_polygon.(Ref(scene), space, polygons, Ref(model)) + projected_polys = project_polygon.(Ref(tric), space, polygons, Ref(model)) function draw_tripolys(polys, colornumbers, colors) for (i, (pol, colnum, col)) in enumerate(zip(polys, colornumbers, colors)) diff --git a/CairoMakie/src/primitives.jl b/CairoMakie/src/primitives.jl index a37415d761b..b1c14e648c9 100644 --- a/CairoMakie/src/primitives.jl +++ b/CairoMakie/src/primitives.jl @@ -50,7 +50,7 @@ function draw_atomic(scene::Scene, screen::Screen, @nospecialize(primitive::Unio end if primitive isa Lines && to_value(primitive.args[1]) isa BezierPath - return draw_bezierpath_lines(ctx, to_value(primitive.args[1]), scene, color, space, model, linewidth) + return draw_bezierpath_lines(ctx, to_value(primitive.args[1]), primitive, color, space, model, linewidth) end if color isa AbstractArray || linewidth isa AbstractArray @@ -728,8 +728,8 @@ function draw_atomic(scene::Scene, screen::Screen, @nospecialize(primitive::Unio # find projected image corners # this already takes care of flipping the image to correct cairo orientation space = to_value(get(primitive, :space, :data)) - xy = project_position(scene, space, Point2f(first.(imsize)), model) - xymax = project_position(scene, space, Point2f(last.(imsize)), model) + xy = project_position(primitive, space, Point2f(first.(imsize)), model) + xymax = project_position(primitive, space, Point2f(last.(imsize)), model) w, h = xymax .- xy can_use_fast_path = !(is_vector && !interpolate) && regular_grid && identity_transform && diff --git a/CairoMakie/src/utils.jl b/CairoMakie/src/utils.jl index e22b8938dc0..9f87e61af9d 100644 --- a/CairoMakie/src/utils.jl +++ b/CairoMakie/src/utils.jl @@ -24,7 +24,7 @@ function _project_position(scene::Scene, space, point, model, yflip::Bool) return p_0_to_1 .* res end -function project_position(scenelike, space, point, model, yflip::Bool = true) +function project_position(@nospecialize(scenelike), space, point, model, yflip::Bool = true) scene = Makie.get_scene(scenelike) project_position(scene, Makie.transform_func(scenelike), space, point, model, yflip) end @@ -47,13 +47,13 @@ function project_scale(scene::Scene, space, s, model = Mat4f(I)) end end -function project_shape(scenelike, space, rect::Rect, model) +function project_shape(@nospecialize(scenelike), space, rect::Rect, model) mini = project_position(scenelike, space, minimum(rect), model) maxi = project_position(scenelike, space, maximum(rect), model) return Rect(mini, maxi .- mini) end -function project_polygon(scenelike, space, poly::P, model) where P <: Polygon +function project_polygon(@nospecialize(scenelike), space, poly::P, model) where P <: Polygon ext = decompose(Point2f, poly.exterior) interiors = decompose.(Point2f, poly.interiors) Polygon( @@ -62,7 +62,7 @@ function project_polygon(scenelike, space, poly::P, model) where P <: Polygon ) end -function project_multipolygon(scenelike, space, multipoly::MP, model) where MP <: MultiPolygon +function project_multipolygon(@nospecialize(scenelike), space, multipoly::MP, model) where MP <: MultiPolygon return MultiPolygon(project_polygon.(Ref(scenelike), Ref(space), multipoly.polygons, Ref(model))) end diff --git a/NEWS.md b/NEWS.md index 093b9c07d0f..43043985961 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ ## master +- Use plot plot instead of scene transform functions in CairoMakie, fixing missplaced h/vspan. [#3552](https://github.com/MakieOrg/Makie.jl/pull/3552) + ## 0.20.4 - Changes for Bonito rename and WGLMakie docs improvements [#3477](https://github.com/MakieOrg/Makie.jl/pull/3477). diff --git a/ReferenceTests/src/tests/primitives.jl b/ReferenceTests/src/tests/primitives.jl index 7e6083f7c9c..79e495b0dbd 100644 --- a/ReferenceTests/src/tests/primitives.jl +++ b/ReferenceTests/src/tests/primitives.jl @@ -474,3 +474,30 @@ end fig end + +@reference_test "Plot transform overwrite" begin + # Tests that (primitive) plots can have different transform function to their + # parent scene (identity in this case) + fig = Figure() + + ax = Axis(fig[1, 1], xscale = log10, yscale = log10, backgroundcolor = :transparent) + xlims!(ax, 1, 10) + ylims!(ax, 1, 10) + empty!(ax.scene.lights) + hidedecorations!(ax) + + heatmap!(ax, 0..0.5, 0..0.5, [i+j for i in 1:10, j in 1:10], transformation = Transformation()) + image!(ax, 0..0.5, 0.5..1, [i+j for i in 1:10, j in 1:10], transformation = Transformation()) + mesh!(ax, Rect2f(0.5, 0.0, 1.0, 0.25), transformation = Transformation(), color = :green) + p = surface!(ax, 0.5..1, 0.25..0.75, [i+j for i in 1:10, j in 1:10], transformation = Transformation()) + translate!(p, Vec3f(0, 0, -20)) + poly!(ax, Rect2f(0.5, 0.75, 1.0, 1.0), transformation = Transformation(), color = :blue) + + lines!(ax, [0, 1], [0, 0.1], linewidth = 10, color = :red, transformation = Transformation()) + linesegments!(ax, [0, 1], [0.2, 0.3], linewidth = 10, color = :red, transformation = Transformation()) + scatter!(ax, [0.1, 0.9], [0.4, 0.5], markersize = 50, color = :red, transformation = Transformation()) + text!(ax, Point2f(0.5, 0.45), text = "Test", fontsize = 50, color = :red, align = (:center, :center), transformation = Transformation()) + meshscatter!(ax, [0.1, 0.9], [0.6, 0.7], markersize = 0.05, color = :red, transformation = Transformation()) + + fig +end \ No newline at end of file From 67c32ce0c99888bff4ae4a96e45afd78437c3208 Mon Sep 17 00:00:00 2001 From: Sagnac <83491030+Sagnac@users.noreply.github.com> Date: Wed, 24 Jan 2024 12:49:42 +0000 Subject: [PATCH 2/6] Fix a DataInspector bug if `inspector_label` is used with RGB images (#3468) If the creation of a custom tooltip was attempted with RGB type images the inspector would error after attempting to convert the Colorant to a Float32 using the Point3f constructor for the position parameter. For cases in which RGB values are being plotted we now call the inspector_label function using a Tuple for its third argument instead, avoiding the error and allowing the RGB values to be used in the construction of the custom string. --- src/interaction/inspector.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/interaction/inspector.jl b/src/interaction/inspector.jl index f2a25b52cc2..5a536e4c56e 100644 --- a/src/interaction/inspector.jl +++ b/src/interaction/inspector.jl @@ -658,7 +658,8 @@ function show_imagelike(inspector, plot, name, edge_based) end if haskey(plot, :inspector_label) - tt.text[] = plot[:inspector_label][](plot, (i, j), Point3f(pos[1], pos[2], z)) + ins_p = z isa Colorant ? (pos[1], pos[2], z) : Point3f(pos[1], pos[2], z) + tt.text[] = plot[:inspector_label][](plot, (i, j), ins_p) else tt.text[] = color2text(name, x, y, z) end From 20c35ddcc6b806d92af10e0d43ed77493fc261d6 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 24 Jan 2024 15:04:18 +0100 Subject: [PATCH 3/6] add interpolate keyword for Surface (#3541) add ninterpolate keyword for Surface --- GLMakie/src/drawing_primitives.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/GLMakie/src/drawing_primitives.jl b/GLMakie/src/drawing_primitives.jl index 9a66f835321..704e456b927 100644 --- a/GLMakie/src/drawing_primitives.jl +++ b/GLMakie/src/drawing_primitives.jl @@ -743,8 +743,9 @@ function draw_atomic(screen::Screen, scene::Scene, plot::Surface) end space = plot.space - - gl_attributes[:image] = img + interp = to_value(pop!(gl_attributes, :interpolate, true)) + interp = interp ? :linear : :nearest + gl_attributes[:image] = Texture(img; minfilter=interp) @assert to_value(plot[3]) isa AbstractMatrix types = map(v -> typeof(to_value(v)), plot[1:2]) From 5c8d07c6a48e294f1fff1ea4b8a6d27bbb10e933 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 25 Jan 2024 13:56:11 +0100 Subject: [PATCH 4/6] prepare 0.20.5 release (#3566) * prepare 0.20.5 release * up makiecore for docchange --- CairoMakie/Project.toml | 4 ++-- GLMakie/Project.toml | 4 ++-- MakieCore/Project.toml | 2 +- NEWS.md | 8 ++++++++ Project.toml | 4 ++-- RPRMakie/Project.toml | 4 ++-- WGLMakie/Project.toml | 4 ++-- 7 files changed, 19 insertions(+), 11 deletions(-) diff --git a/CairoMakie/Project.toml b/CairoMakie/Project.toml index 25b296dc428..519423d3795 100644 --- a/CairoMakie/Project.toml +++ b/CairoMakie/Project.toml @@ -1,7 +1,7 @@ name = "CairoMakie" uuid = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" author = ["Simon Danisch "] -version = "0.11.5" +version = "0.11.6" [deps] CRC32c = "8bf52ea8-c179-5cab-976a-9e18b702a9bc" @@ -24,7 +24,7 @@ FileIO = "1.1" FreeType = "3, 4.0" GeometryBasics = "0.4.1" LinearAlgebra = "1.0, 1.6" -Makie = "=0.20.4" +Makie = "=0.20.5" PrecompileTools = "1.0" julia = "1.3" diff --git a/GLMakie/Project.toml b/GLMakie/Project.toml index e6efdd42b99..ad3498e25a6 100644 --- a/GLMakie/Project.toml +++ b/GLMakie/Project.toml @@ -1,6 +1,6 @@ name = "GLMakie" uuid = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a" -version = "0.9.5" +version = "0.9.6" [deps] ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" @@ -30,7 +30,7 @@ FreeTypeAbstraction = "0.10" GLFW = "3.3" GeometryBasics = "0.4.1" LinearAlgebra = "1.0, 1.6" -Makie = "=0.20.4" +Makie = "=0.20.5" Markdown = "1.0, 1.6" MeshIO = "0.4" ModernGL = "1" diff --git a/MakieCore/Project.toml b/MakieCore/Project.toml index e510242ce42..275e64d33c2 100644 --- a/MakieCore/Project.toml +++ b/MakieCore/Project.toml @@ -1,7 +1,7 @@ name = "MakieCore" uuid = "20f20a25-4f0e-4fdf-b5d1-57303727442b" authors = ["Simon Danisch"] -version = "0.7.2" +version = "0.7.3" [deps] Observables = "510215fc-4207-5dde-b226-833fc4488ee2" diff --git a/NEWS.md b/NEWS.md index 43043985961..6f345ef6a6a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,15 @@ ## master +## 0.20.5 + - Use plot plot instead of scene transform functions in CairoMakie, fixing missplaced h/vspan. [#3552](https://github.com/MakieOrg/Makie.jl/pull/3552) +- Fix error printing on shader error [#3530](https://github.com/MakieOrg/Makie.jl/pull/3530). +- Update pagefind to 1.0.4 for better headline search [#3534](https://github.com/MakieOrg/Makie.jl/pull/3534). +- Remove unecessary deps, e.g. Setfield [3546](https://github.com/MakieOrg/Makie.jl/pull/3546). +- Don't clear args, rely on delete deregister_callbacks [#3543](https://github.com/MakieOrg/Makie.jl/pull/3543). +- Add interpolate keyword for Surface [#3541](https://github.com/MakieOrg/Makie.jl/pull/3541). +- Fix a DataInspector bug if inspector_label is used with RGB images [#3468](https://github.com/MakieOrg/Makie.jl/pull/3468). ## 0.20.4 diff --git a/Project.toml b/Project.toml index 9ed94f8ec23..79536af1d99 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Makie" uuid = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" authors = ["Simon Danisch", "Julius Krumbiegel"] -version = "0.20.4" +version = "0.20.5" [deps] Animations = "27a7e980-b3e6-11e9-2bcd-0b925532e340" @@ -88,7 +88,7 @@ KernelDensity = "0.5, 0.6" LaTeXStrings = "1.2" LinearAlgebra = "1.0, 1.6" MacroTools = "0.5" -MakieCore = "=0.7.2" +MakieCore = "=0.7.3" Markdown = "1.0, 1.6" MathTeXEngine = "0.5" Observables = "0.5.5" diff --git a/RPRMakie/Project.toml b/RPRMakie/Project.toml index e44588c1ca8..9ac77834f4d 100644 --- a/RPRMakie/Project.toml +++ b/RPRMakie/Project.toml @@ -1,7 +1,7 @@ name = "RPRMakie" uuid = "22d9f318-5e34-4b44-b769-6e3734a732a6" authors = ["Simon Danisch"] -version = "0.6.4" +version = "0.6.5" [deps] Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" @@ -16,7 +16,7 @@ RadeonProRender = "27029320-176d-4a42-b57d-56729d2ad457" Colors = "0.9, 0.10, 0.11, 0.12" FileIO = "1.6" GeometryBasics = "0.4.1" -Makie = "=0.20.4" +Makie = "=0.20.5" RadeonProRender = "0.3.0" julia = "1.3" LinearAlgebra = "1.0, 1.6" diff --git a/WGLMakie/Project.toml b/WGLMakie/Project.toml index bff242e1309..adb639020c4 100644 --- a/WGLMakie/Project.toml +++ b/WGLMakie/Project.toml @@ -1,7 +1,7 @@ name = "WGLMakie" uuid = "276b4fcb-3e11-5398-bf8b-a0c2d153d008" authors = ["SimonDanisch "] -version = "0.9.4" +version = "0.9.5" [deps] Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" @@ -27,7 +27,7 @@ GeometryBasics = "0.4.1" Hyperscript = "0.0.3, 0.0.4, 0.0.5" Bonito = "3.0.0" LinearAlgebra = "1.0, 1.6" -Makie = "=0.20.4" +Makie = "=0.20.5" Observables = "0.5.1" PNGFiles = "0.3, 0.4" PrecompileTools = "1.0" From 6bba224dca04435874b60ab1982a4300da613f28 Mon Sep 17 00:00:00 2001 From: Sagnac <83491030+Sagnac@users.noreply.github.com> Date: Sat, 27 Jan 2024 17:54:13 +0000 Subject: [PATCH 5/6] Fix a hang due to `limits!` being called recursively (#3570) Fixes #3564 Restricting the sans axis arguments to the expected types prevents the method from being called in a non-terminating loop which was the case if, for example, the function was called with an indexed Figure instead of an Axis; calling limits! without a current axis also resulted in a stack overflow. --- src/makielayout/blocks/axis.jl | 6 ++++-- test/makielayout.jl | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/makielayout/blocks/axis.jl b/src/makielayout/blocks/axis.jl index 8248577fbb8..53ec8ebe000 100644 --- a/src/makielayout/blocks/axis.jl +++ b/src/makielayout/blocks/axis.jl @@ -1372,8 +1372,10 @@ function limits!(ax::Axis, rect::Rect2) Makie.ylims!(ax, ymin, ymax) end -function limits!(args...) - limits!(current_axis(), args...) +function limits!(args::Union{Nothing, Real, HyperRectangle}...) + axis = current_axis() + axis isa Nothing && error("There is no currently active axis!") + limits!(axis, args...) end Makie.transform_func(ax::Axis) = Makie.transform_func(ax.scene) diff --git a/test/makielayout.jl b/test/makielayout.jl index 33611f38f2a..5c50e90632c 100644 --- a/test/makielayout.jl +++ b/test/makielayout.jl @@ -113,6 +113,7 @@ end @test ax.limits[] == (nothing, [5, 7]) @test ax.targetlimits[] == BBox(-5, 11, 5, 7) @test ax.finallimits[] == BBox(-5, 11, 5, 7) + @test_throws MethodError limits!(f[1,1], -1, 1, -1, 1) end # issue 3240 From 6b7377bb296bb4738744201bf28892d0812f7c2e Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 29 Jan 2024 16:35:44 +0100 Subject: [PATCH 6/6] fix redisplaying figures on same screen (#3573) --- GLMakie/src/display.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/GLMakie/src/display.jl b/GLMakie/src/display.jl index 5135fa1f1b5..c8cb5a85064 100644 --- a/GLMakie/src/display.jl +++ b/GLMakie/src/display.jl @@ -2,6 +2,10 @@ function Base.display(screen::Screen, scene::Scene; connect=true) # So, the GLFW window events are not guarantee to fire # when we close a window, so we ensure this here! if !Makie.is_displayed(screen, scene) + if !isnothing(screen.root_scene) + delete!(screen, screen.root_scene) + screen.root_scene = nothing + end display_scene!(screen, scene) else @assert screen.root_scene === scene "internal error. Scene already displayed by screen but not as root scene"