Skip to content

Commit

Permalink
use poly in axis background, test that no rasterization happens in ba…
Browse files Browse the repository at this point in the history
…sic svgs (#1734)

* use poly in axis background, test that no rasterization happens in basic svgs

* add notice
  • Loading branch information
jkrumbiegel authored and SimonDanisch committed Mar 15, 2022
1 parent 4827f7f commit 68d69c4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CairoMakie/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Pkg.develop(PackageSpec(path = path))
end
end

include(joinpath(@__DIR__, "svg_tests.jl"))

using ReferenceTests
using ReferenceTests: database_filtered

Expand Down
20 changes: 20 additions & 0 deletions CairoMakie/test/svg_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# guard against some future changes silently making simple vector graphics be
# rasterized if they are using features unsupported by the SVG spec
function svg_isnt_rasterized(x)
mktempdir() do path
path = joinpath(path, "test.svg")
save(path, x)
# this is rough but an easy way to catch rasterization,
# if an image element is present in the svg
return !occursin("<image id=", read(path, String))
end
end

@testset "SVG rasterization" begin
@test svg_isnt_rasterized(Scene())
@test svg_isnt_rasterized(begin f = Figure(); Axis(f[1, 1]); f end)
@test svg_isnt_rasterized(scatter(1:3))
@test svg_isnt_rasterized(lines(1:3))
@test svg_isnt_rasterized(heatmap(rand(5, 5)))
@test !svg_isnt_rasterized(image(rand(5, 5)))
end
4 changes: 3 additions & 1 deletion src/makielayout/layoutables/axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ function layoutable(::Type{<:Axis}, fig_or_scene::Union{Figure, Scene}; bbox = n

scene = Scene(topscene, px_area=scenearea)

background = mesh!(topscene, scenearea, color = backgroundcolor, inspectable = false, shading=false)
# TODO: replace with mesh, however, CairoMakie needs a poly path for this signature
# so it doesn't rasterize the scene
background = poly!(topscene, scenearea, color = backgroundcolor, inspectable = false, shading = false, strokecolor = :transparent)
translate!(background, 0, 0, -100)
decorations[:background] = background

Expand Down

0 comments on commit 68d69c4

Please sign in to comment.