Skip to content

Commit

Permalink
Merge branch 'master' into jk/legend-overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrumbiegel authored Oct 1, 2024
2 parents 35e252e + f1c1918 commit 2eea70c
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

## [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)
- Add `LegendOverride` object to override legend element attributes [#4427](https://github.com/MakieOrg/Makie.jl/pull/4427).
- Added ability to override legend element attributes by pairing labels or plots with override attributes [#4427](https://github.com/MakieOrg/Makie.jl/pull/4427).
- Added threshold before a drag starts which improves false negative rates for clicks. `Button` can now trigger on click and not mouse-down which is the canonical behavior in other GUI systems [#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
4 changes: 4 additions & 0 deletions src/makielayout/blocks/button.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ function initialize_block!(b::Button)

onmouseleftdown(mouseevents) do _
mousestate[] = :active
return Consume(true)
end

onmouseleftclick(mouseevents) do _
b.clicks[] = b.clicks[] + 1
return Consume(true)
end
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
5 changes: 4 additions & 1 deletion src/makielayout/mousestatemachine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ function _addmouseevents!(scene, is_mouse_over_relevant_area, priority)
mouse_downed_inside = Ref(false)
mouse_downed_button = Ref{Optional{Mouse.Button}}(nothing)
drag_ongoing = Ref(false)
mouse_downed_at = Ref(Point2d(0, 0)) # store the position of mouse down so drags only start after some threshold
drag_threshold = 2.0 # mouse needs to move this distance before a drag starts, otherwise it's easy to drag instead of click on trackpads
mouse_was_inside = Ref(false)
prev_t = Ref(0.0)
t_last_click = Ref(0.0)
Expand Down Expand Up @@ -231,7 +233,7 @@ function _addmouseevents!(scene, is_mouse_over_relevant_area, priority)
else
# mouse was downed inside but no drag is ongoing
# that means a drag started
if mouse_downed_inside[]
if mouse_downed_inside[] && norm(mouse_downed_at[] - px) >= drag_threshold
drag_ongoing[] = true
event = to_drag_start_event(mouse_downed_button[])
x = setindex!(mouseevent,
Expand Down Expand Up @@ -294,6 +296,7 @@ function _addmouseevents!(scene, is_mouse_over_relevant_area, priority)
mouse_downed_button[] = button

if mouse_was_inside[]
mouse_downed_at[] = px
event = to_down_event(mouse_downed_button[])
x = setindex!(mouseevent,
MouseEvent(event, t, data, px, prev_t[], prev_data[], prev_px[])
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 @@ -1873,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."
Expand Down Expand Up @@ -1909,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."
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
2 changes: 2 additions & 0 deletions test/events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ Base.:(==)(l::Or, r::Or) = l.left == r.left && l.right == r.right
for button in (:left, :middle, :right)
# click
e.mousebutton[] = MouseButtonEvent(getfield(Mouse, button), Mouse.press)
e.mouseposition[] = (301, 301) # small mouse deviations with pressed button shouldn't register as a drag and prohibit a click
e.mouseposition[] = (300, 300)
e.mousebutton[] = MouseButtonEvent(getfield(Mouse, button), Mouse.release)
@test length(eventlog) == 3
for (i, t) in enumerate((
Expand Down
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 2eea70c

Please sign in to comment.