Skip to content

Commit

Permalink
fixes + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch committed Jul 21, 2023
1 parent cada133 commit e233cc8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
1 change: 0 additions & 1 deletion GLMakie/src/screen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ function apply_config!(screen::Screen, config::ScreenConfig; start_renderloop::B
replace_processor!(config.fxaa ? fxaa_postprocessor : empty_postprocessor, 3)
# Set the config
screen.config = config
@show start_renderloop
if start_renderloop
start_renderloop!(screen)
else
Expand Down
25 changes: 25 additions & 0 deletions ReferenceTests/src/tests/short_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,31 @@ end
f
end

@reference_test "colorbuffer for axis" begin
fig = Figure()
ax1 = Axis(fig[1, 1])
ax2 = Axis(fig[1, 2])
ax3 = Axis(fig[2, 2])
ax4 = Axis(fig[2, 1])
scatter!(ax1, 1:10, 1:10; markersize=50, color=1:10)
scatter!(ax2, 1:10, 1:10; markersize=50, color=:red)
heatmap!(ax3, -8:0.1:8, 8:0.1:8, (x, y) -> sin(x) + cos(y))
meshscatter!(ax4, 1:10, 1:10; markersize=1, color=:red)
img1 = colorbuffer(ax1; include_decorations=true)
img2 = colorbuffer(ax2; include_decorations=false)
img3 = colorbuffer(ax3; include_decorations=true)
img4 = colorbuffer(ax4; include_decorations=false)
f, ax5, pl = image(rotr90(img1); axis=(; aspect=DataAspect()))
ax6, pl = image(f[1, 2], rotr90(img2); axis=(; aspect=DataAspect()))
ax7, pl = image(f[2, 2], rotr90(img3); axis=(; aspect=DataAspect()))
ax8, pl = image(f[2, 1], rotr90(img4); axis=(; aspect=DataAspect()))
hidedecorations!(ax5)
hidedecorations!(ax6)
hidedecorations!(ax7)
hidedecorations!(ax8)
f
end


# Needs a way to disable autolimits on show
# @reference_test "interactions after close" begin
Expand Down
11 changes: 0 additions & 11 deletions src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -417,17 +417,6 @@ function get_sub_picture(image, format::ImageStorageFormat, rect)
return image[start:stop, xmin:xmax]
end

function colorbuffer(ax::Axis; include_decorations=true, update=true)
bb = if include_decorations
bb = Makie.boundingbox(ax.blockscene)
Rect2{Int}(round.(Int, minimum(bb)) .+ 1, round.(Int, widths(bb)))
else
pixelarea(ax.scene)[]
end
img = colorbuffer(root(ax.scene); update=update)
return get_sub_picture(img, JuliaNative, bb)
end

"""
colorbuffer(scene, format::ImageStorageFormat = JuliaNative; update=true, backend=current_backend(), screen_config...)
Expand Down
27 changes: 27 additions & 0 deletions src/makielayout/blocks/axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1785,3 +1785,30 @@ function attribute_examples(::Type{Axis})
],
)
end

function axis_bounds_with_decoration(axis::Axis)
# Filter out the zoomrect + background plot
lims = Makie.data_limits(axis.blockscene.plots, p -> p isa Mesh || p isa Poly)
return Makie.parent_transform(axis.blockscene) * lims
end

"""
colorbuffer(ax::Axis; include_decorations=true, colorbuffer_kws...)
Gets the colorbuffer of the `Axis` in `JuliaNative` image format.
If `include_decorations=false`, only the inside of the axis is fetched.
"""
function colorbuffer(ax::Axis; include_decorations=true, update=true, colorbuffer_kws...)
if update
update_state_before_display!(ax)
end
bb = if include_decorations
bb = axis_bounds_with_decoration(ax)
Rect2{Int}(round.(Int, minimum(bb)) .+ 1, round.(Int, widths(bb)))
else
pixelarea(ax.scene)[]
end

img = colorbuffer(root(ax.scene); update=false, colorbuffer_kws...)
return get_sub_picture(img, JuliaNative, bb)
end

0 comments on commit e233cc8

Please sign in to comment.