From b12d05fc507b6a65e7d472943b13ca4f7a722bff Mon Sep 17 00:00:00 2001 From: Eddie Groshev Date: Sat, 2 Nov 2024 10:20:14 -0700 Subject: [PATCH 1/9] fix: correctly render the tooltip triangle --- src/basic_recipes/tooltip.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/basic_recipes/tooltip.jl b/src/basic_recipes/tooltip.jl index 624073b54ab..a2315c2dc33 100644 --- a/src/basic_recipes/tooltip.jl +++ b/src/basic_recipes/tooltip.jl @@ -173,16 +173,16 @@ function plot!(p::Tooltip{<:Tuple{<:VecTypes}}) scale!(mp, s, s, s) if placement === :left - translate!(mp, Vec3f(o[1] + w[1], o[2] + align * w[2], o[3])) + translate!(mp, Vec3f(o[1] + w[1] - 0.5s, o[2] + align * w[2], o[3])) rotate!(mp, qrotation(Vec3f(0,0,1), 0.5pi)) elseif placement === :right - translate!(mp, Vec3f(o[1], o[2] + align * w[2], o[3])) + translate!(mp, Vec3f(o[1] + 0.5s, o[2] + align * w[2], o[3])) rotate!(mp, qrotation(Vec3f(0,0,1), -0.5pi)) elseif placement in (:below, :down, :bottom) - translate!(mp, Vec3f(o[1] + align * w[1], o[2] + w[2], o[3])) + translate!(mp, Vec3f(o[1] + align * w[1], o[2] + w[2] - 0.5s, o[3])) rotate!(mp, Quaternionf(0,0,1,0)) # pi elseif placement in (:above, :up, :top) - translate!(mp, Vec3f(o[1] + align * w[1], o[2], o[3])) + translate!(mp, Vec3f(o[1] + align * w[1], o[2] + 0.5s, o[3])) rotate!(mp, Quaternionf(0,0,0,1)) # 0 else @error "Tooltip placement $placement invalid. Assuming :above" From 49a1dd81fb6b521849f501f5eee23b532c4b13d9 Mon Sep 17 00:00:00 2001 From: Eddie Groshev Date: Sat, 2 Nov 2024 10:25:53 -0700 Subject: [PATCH 2/9] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b5e2b8f3a4..bd189ee1158 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased] +- Correctly render the tooltip triangle [#4560](https://github.com/MakieOrg/Makie.jl/pull/4560). - Added `subsup` and `left_subsup` functions that offer stacked sub- and superscripts for `rich` text which means this style can be used with arbitrary fonts and is not limited to fonts supported by MathTeXEngine.jl [#4489](https://github.com/MakieOrg/Makie.jl/pull/4489). - Added the `jitter_width` and `side_nudge` attributes to the `raincloud` plot definition, so that they can be used as kwargs [#4517]https://github.com/MakieOrg/Makie.jl/pull/4517) - Expand PlotList plots to expose their child plots to the legend interface, allowing `axislegend`show plots within PlotSpecs as individual entries. [#4546](https://github.com/MakieOrg/Makie.jl/pull/4546) From 0dfdbda63642ac2c2ef720d83e9ce97987aaacf1 Mon Sep 17 00:00:00 2001 From: Eddie Groshev Date: Sat, 2 Nov 2024 10:52:02 -0700 Subject: [PATCH 3/9] smaller offset --- src/basic_recipes/tooltip.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/basic_recipes/tooltip.jl b/src/basic_recipes/tooltip.jl index a2315c2dc33..b540d4d12d9 100644 --- a/src/basic_recipes/tooltip.jl +++ b/src/basic_recipes/tooltip.jl @@ -173,16 +173,16 @@ function plot!(p::Tooltip{<:Tuple{<:VecTypes}}) scale!(mp, s, s, s) if placement === :left - translate!(mp, Vec3f(o[1] + w[1] - 0.5s, o[2] + align * w[2], o[3])) + translate!(mp, Vec3f(o[1] + w[1] - 0.25s, o[2] + align * w[2], o[3])) rotate!(mp, qrotation(Vec3f(0,0,1), 0.5pi)) elseif placement === :right - translate!(mp, Vec3f(o[1] + 0.5s, o[2] + align * w[2], o[3])) + translate!(mp, Vec3f(o[1] + 0.25s, o[2] + align * w[2], o[3])) rotate!(mp, qrotation(Vec3f(0,0,1), -0.5pi)) elseif placement in (:below, :down, :bottom) - translate!(mp, Vec3f(o[1] + align * w[1], o[2] + w[2] - 0.5s, o[3])) + translate!(mp, Vec3f(o[1] + align * w[1], o[2] + w[2] - 0.25s, o[3])) rotate!(mp, Quaternionf(0,0,1,0)) # pi elseif placement in (:above, :up, :top) - translate!(mp, Vec3f(o[1] + align * w[1], o[2] + 0.5s, o[3])) + translate!(mp, Vec3f(o[1] + align * w[1], o[2] + 0.25s, o[3])) rotate!(mp, Quaternionf(0,0,0,1)) # 0 else @error "Tooltip placement $placement invalid. Assuming :above" From 1f02f907c466d4d839822b1823b0ac26fb7de7fa Mon Sep 17 00:00:00 2001 From: Eddie Groshev Date: Mon, 4 Nov 2024 09:33:51 -0800 Subject: [PATCH 4/9] adjust the z value instead --- src/basic_recipes/tooltip.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/basic_recipes/tooltip.jl b/src/basic_recipes/tooltip.jl index b540d4d12d9..0c54d4e6830 100644 --- a/src/basic_recipes/tooltip.jl +++ b/src/basic_recipes/tooltip.jl @@ -173,20 +173,20 @@ function plot!(p::Tooltip{<:Tuple{<:VecTypes}}) scale!(mp, s, s, s) if placement === :left - translate!(mp, Vec3f(o[1] + w[1] - 0.25s, o[2] + align * w[2], o[3])) + translate!(mp, Vec3f(o[1] + w[1], o[2] + align * w[2], 1)) rotate!(mp, qrotation(Vec3f(0,0,1), 0.5pi)) elseif placement === :right - translate!(mp, Vec3f(o[1] + 0.25s, o[2] + align * w[2], o[3])) + translate!(mp, Vec3f(o[1], o[2] + align * w[2], 1)) rotate!(mp, qrotation(Vec3f(0,0,1), -0.5pi)) elseif placement in (:below, :down, :bottom) - translate!(mp, Vec3f(o[1] + align * w[1], o[2] + w[2] - 0.25s, o[3])) + translate!(mp, Vec3f(o[1] + align * w[1], o[2] + w[2], 1)) rotate!(mp, Quaternionf(0,0,1,0)) # pi elseif placement in (:above, :up, :top) - translate!(mp, Vec3f(o[1] + align * w[1], o[2] + 0.25s, o[3])) + translate!(mp, Vec3f(o[1] + align * w[1], o[2], 1)) rotate!(mp, Quaternionf(0,0,0,1)) # 0 else @error "Tooltip placement $placement invalid. Assuming :above" - translate!(mp, Vec3f(o[1] + align * w[1], o[2], o[3])) + translate!(mp, Vec3f(o[1] + align * w[1], o[2], 1)) rotate!(mp, Quaternionf(0,0,0,1)) end return From 85f78e1109f2e40732f854bba91093621a64fef1 Mon Sep 17 00:00:00 2001 From: Eddie Groshev Date: Mon, 4 Nov 2024 12:38:44 -0800 Subject: [PATCH 5/9] translate outline up by 1 --- src/basic_recipes/tooltip.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/basic_recipes/tooltip.jl b/src/basic_recipes/tooltip.jl index 0c54d4e6830..e2404cddd36 100644 --- a/src/basic_recipes/tooltip.jl +++ b/src/basic_recipes/tooltip.jl @@ -173,20 +173,20 @@ function plot!(p::Tooltip{<:Tuple{<:VecTypes}}) scale!(mp, s, s, s) if placement === :left - translate!(mp, Vec3f(o[1] + w[1], o[2] + align * w[2], 1)) + translate!(mp, Vec3f(o[1] + w[1], o[2] + align * w[2], o[3])) rotate!(mp, qrotation(Vec3f(0,0,1), 0.5pi)) elseif placement === :right - translate!(mp, Vec3f(o[1], o[2] + align * w[2], 1)) + translate!(mp, Vec3f(o[1], o[2] + align * w[2], o[3])) rotate!(mp, qrotation(Vec3f(0,0,1), -0.5pi)) elseif placement in (:below, :down, :bottom) - translate!(mp, Vec3f(o[1] + align * w[1], o[2] + w[2], 1)) + translate!(mp, Vec3f(o[1] + align * w[1], o[2] + w[2], o[3])) rotate!(mp, Quaternionf(0,0,1,0)) # pi elseif placement in (:above, :up, :top) - translate!(mp, Vec3f(o[1] + align * w[1], o[2], 1)) + translate!(mp, Vec3f(o[1] + align * w[1], o[2], o[3])) rotate!(mp, Quaternionf(0,0,0,1)) # 0 else @error "Tooltip placement $placement invalid. Assuming :above" - translate!(mp, Vec3f(o[1] + align * w[1], o[2], 1)) + translate!(mp, Vec3f(o[1] + align * w[1], o[2], o[3])) rotate!(mp, Quaternionf(0,0,0,1)) end return @@ -247,7 +247,7 @@ function plot!(p::Tooltip{<:Tuple{<:VecTypes}}) ] end - return to_ndim.(Vec3f, shift, z) + return to_ndim.(Vec3f, shift, z + 1.0f0) end lines!( From 3840f2d91eb346593acc2270c12f34cfb9272f4d Mon Sep 17 00:00:00 2001 From: ffreyer Date: Mon, 4 Nov 2024 22:22:27 +0100 Subject: [PATCH 6/9] switch to string_boundingbox --- src/basic_recipes/tooltip.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic_recipes/tooltip.jl b/src/basic_recipes/tooltip.jl index e2404cddd36..3fb09053f3b 100644 --- a/src/basic_recipes/tooltip.jl +++ b/src/basic_recipes/tooltip.jl @@ -139,7 +139,7 @@ function plot!(p::Tooltip{<:Tuple{<:VecTypes}}) bbox = map( p, px_pos, p.text, text_align, text_offset, textpadding, p.align ) do p, s, _, o, pad, align - bb = boundingbox(tp, :pixel) + to_ndim(Vec3f, o, 0) + bb = string_boundingbox(tp) + to_ndim(Vec3f, o, 0) l, r, b, t = pad return Rect3f(origin(bb) .- (l, b, 0), widths(bb) .+ (l+r, b+t, 0)) end From 8f0b78d81efb89ebd541bf5be663d2ab125d60a9 Mon Sep 17 00:00:00 2001 From: ffreyer Date: Mon, 4 Nov 2024 23:12:18 +0100 Subject: [PATCH 7/9] reduce translation and fix render order --- src/basic_recipes/tooltip.jl | 70 ++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/src/basic_recipes/tooltip.jl b/src/basic_recipes/tooltip.jl index 3fb09053f3b..c833908be12 100644 --- a/src/basic_recipes/tooltip.jl +++ b/src/basic_recipes/tooltip.jl @@ -133,7 +133,7 @@ function plot!(p::Tooltip{<:Tuple{<:VecTypes}}) overdraw = p.overdraw, depth_shift = p.depth_shift, inspectable = p.inspectable, space = :pixel, transformation = Transformation() ) - translate!(tp, 0, 0, 1) + translate!(tp, 0, 0, 0.01) # must be larger than eps(1f4) to prevent float precision issues # TODO react to glyphcollection instead bbox = map( @@ -156,42 +156,51 @@ function plot!(p::Tooltip{<:Tuple{<:VecTypes}}) # Triangle mesh - triangle = GeometryBasics.Mesh( - Point2f[(-0.5, 0), (0.5, 0), (0, -1)], - GLTriangleFace[(1,2,3)] - ) - - mp = mesh!( - p, triangle, shading = NoShading, space = :pixel, - color = p.backgroundcolor, - transparency = p.transparency, visible = p.visible, - overdraw = p.overdraw, depth_shift = p.depth_shift, - inspectable = p.inspectable, transformation = Transformation() - ) - onany(p, bbox, p.triangle_size, p.placement, p.align) do bb, s, placement, align - o = origin(bb); w = widths(bb) - scale!(mp, s, s, s) - + tri_points = map(p, bbox, p.triangle_size, p.placement, p.align) do bb, s, placement, align + l, b, z = origin(bb); w, h, _ = widths(bb) + r, t = (l, b) .+ (w, h) if placement === :left - translate!(mp, Vec3f(o[1] + w[1], o[2] + align * w[2], o[3])) - rotate!(mp, qrotation(Vec3f(0,0,1), 0.5pi)) + return Point3f[ + (r, b + align * h + 0.5s, z), + (r + s, b + align * h, z), + (r, b + align * h - 0.5s, z), + ] elseif placement === :right - translate!(mp, Vec3f(o[1], o[2] + align * w[2], o[3])) - rotate!(mp, qrotation(Vec3f(0,0,1), -0.5pi)) + return Point3f[ + (l, b + align * h - 0.5s, z), + (l-s, b + align * h, z), + (l, b + align * h + 0.5s, z), + ] elseif placement in (:below, :down, :bottom) - translate!(mp, Vec3f(o[1] + align * w[1], o[2] + w[2], o[3])) - rotate!(mp, Quaternionf(0,0,1,0)) # pi + return Point3f[ + (l + align * w - 0.5s, t, z), + (l + align * w, t+s, z), + (l + align * w + 0.5s, t, z), + ] elseif placement in (:above, :up, :top) - translate!(mp, Vec3f(o[1] + align * w[1], o[2], o[3])) - rotate!(mp, Quaternionf(0,0,0,1)) # 0 + return Point3f[ + (l + align * w + 0.5s, b, z), + (l + align * w, b-s, z), + (l + align * w - 0.5s, b, z), + ] else @error "Tooltip placement $placement invalid. Assuming :above" - translate!(mp, Vec3f(o[1] + align * w[1], o[2], o[3])) - rotate!(mp, Quaternionf(0,0,0,1)) + return Point3f[ + (l + align * w + 0.5s, b, z), + (l + align * w, b-s, z), + (l + align * w - 0.5s, b, z), + ] end - return end + mesh!( + p, tri_points, [1 2 3], shading = NoShading, space = :pixel, + color = p.backgroundcolor, fxaa = false, + transparency = p.transparency, visible = p.visible, + overdraw = p.overdraw, depth_shift = p.depth_shift, + inspectable = p.inspectable, transformation = Transformation() + ) + # Outline outline = map(p, bbox, p.triangle_size, p.placement, p.align) do bb, s, placement, align @@ -247,10 +256,10 @@ function plot!(p::Tooltip{<:Tuple{<:VecTypes}}) ] end - return to_ndim.(Vec3f, shift, z + 1.0f0) + return to_ndim.(Vec3f, shift, z) end - lines!( + lp = lines!( p, outline, color = p.outline_color, space = :pixel, miter_limit = pi/18, linewidth = p.outline_linewidth, linestyle = p.outline_linestyle, @@ -258,6 +267,7 @@ function plot!(p::Tooltip{<:Tuple{<:VecTypes}}) overdraw = p.overdraw, depth_shift = p.depth_shift, inspectable = p.inspectable, transformation = Transformation() ) + translate!(lp, 0, 0, 0.01) notify(p[1]) From a1806b7844a3e8ba1233298d841945db70008ef9 Mon Sep 17 00:00:00 2001 From: ffreyer Date: Mon, 4 Nov 2024 23:12:42 +0100 Subject: [PATCH 8/9] extend refimg test --- ReferenceTests/src/tests/examples2d.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ReferenceTests/src/tests/examples2d.jl b/ReferenceTests/src/tests/examples2d.jl index 89ef03ce26a..ba4e4f79a51 100644 --- a/ReferenceTests/src/tests/examples2d.jl +++ b/ReferenceTests/src/tests/examples2d.jl @@ -706,6 +706,12 @@ end outline_linewidth = 5, offset = 30, triangle_size = 15, strokewidth = 2f0, strokecolor = :cyan ) + # Test depth (this part is expected to fail in CairoMakie) + p = tooltip!(ax, -5, -1, "test line\ntest line", backgroundcolor = :lightblue) + translate!(p, 0, 0, 100) + mesh!(ax, + Point3f.([-7, -7, -3, -3], [-1, 1, -1, 1], [99, 99, 101, 101]), [1 2 3; 2 3 4], + shading = NoShading, color = :orange) fig end From 7377cc24f9962f7f165876dda6ec124892cd0c03 Mon Sep 17 00:00:00 2001 From: ffreyer Date: Tue, 5 Nov 2024 14:47:29 +0100 Subject: [PATCH 9/9] avoid overlap in refimg --- ReferenceTests/src/tests/examples2d.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ReferenceTests/src/tests/examples2d.jl b/ReferenceTests/src/tests/examples2d.jl index ba4e4f79a51..8154d08f9be 100644 --- a/ReferenceTests/src/tests/examples2d.jl +++ b/ReferenceTests/src/tests/examples2d.jl @@ -707,10 +707,10 @@ end strokewidth = 2f0, strokecolor = :cyan ) # Test depth (this part is expected to fail in CairoMakie) - p = tooltip!(ax, -5, -1, "test line\ntest line", backgroundcolor = :lightblue) + p = tooltip!(ax, -5, -4, "test line\ntest line", backgroundcolor = :lightblue) translate!(p, 0, 0, 100) mesh!(ax, - Point3f.([-7, -7, -3, -3], [-1, 1, -1, 1], [99, 99, 101, 101]), [1 2 3; 2 3 4], + Point3f.([-7, -7, -3, -3], [-4, -2, -4, -2], [99, 99, 101, 101]), [1 2 3; 2 3 4], shading = NoShading, color = :orange) fig end