Skip to content

Commit

Permalink
Use polys for axis3 (#4463)
Browse files Browse the repository at this point in the history
* use poly for axis3 panels so that svgs aren't rasterized

* add rasterization tests for Axis3 and PolarAxis

* disable stroke

* remove depth shift

* Update CHANGELOG.md

---------

Co-authored-by: Simon <[email protected]>
  • Loading branch information
jkrumbiegel and SimonDanisch authored Oct 21, 2024
1 parent 981d954 commit 814d8d5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Changed image, heatmap and surface picking indices to correctly index the relevant matrix arguments. [#4459](https://github.com/MakieOrg/Makie.jl/pull/4459)
- Improved performance of `record` by avoiding unnecessary copying in common cases [#4475](https://github.com/MakieOrg/Makie.jl/pull/4475).
- Fix usage of `AggMean()` and other aggregations operating on 3d data for `datashader` [#4346](https://github.com/MakieOrg/Makie.jl/pull/4346).
- Use polys for axis3 [#4463](https://github.com/MakieOrg/Makie.jl/pull/4463).
- Changed default for `circular_rotation` in Camera3D to false, so that the camera doesn't change rotation direction anymore [4492](https://github.com/MakieOrg/Makie.jl/pull/4492)
- Fixed `pick(scene, rect2)` in WGLMakie [#4488](https://github.com/MakieOrg/Makie.jl/pull/4488)

Expand Down
2 changes: 2 additions & 0 deletions CairoMakie/test/svg_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ 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(begin f = Figure(); Axis3(f[1, 1]); f end)
@test svg_isnt_rasterized(begin f = Figure(); PolarAxis(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)))
Expand Down
43 changes: 28 additions & 15 deletions src/makielayout/blocks/axis3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -664,29 +664,42 @@ function add_panel!(scene, ax, dim1, dim2, dim3, limits, min3)
string((:x, :y, :z)[dim2]) * string(sym))
attr(sym) = getproperty(ax, dimsym(sym))

vertices = lift(limits, min3) do lims, mi3

rect = lift(limits) do lims
mi = minimum(lims)
ma = maximum(lims)
Polygon([
Point2(mi[dim1], mi[dim2]),
Point2(ma[dim1], mi[dim2]),
Point2(ma[dim1], ma[dim2]),
Point2(mi[dim1], ma[dim2])
])
end

v3 = if mi3
mi[dim3] + 0.005 * (mi[dim3] - ma[dim3])
else
ma[dim3] + 0.005 * (ma[dim3] - mi[dim3])
end
plane_offset = lift(limits, min3) do lims, mi3
mi = minimum(lims)
ma = maximum(lims)

p1 = dim3point(dim1, dim2, dim3, mi[dim1], mi[dim2], v3)
p2 = dim3point(dim1, dim2, dim3, mi[dim1], ma[dim2], v3)
p3 = dim3point(dim1, dim2, dim3, ma[dim1], ma[dim2], v3)
p4 = dim3point(dim1, dim2, dim3, ma[dim1], mi[dim2], v3)
[p1, p2, p3, p4]
mi3 ? mi[dim3] : ma[dim3]
end

faces = [1 2 3; 3 4 1]
plane = Symbol((:x, :y, :z)[dim1], (:x, :y, :z)[dim2])

panel = mesh!(scene, vertices, faces, shading = NoShading, inspectable = false,
panel = poly!(scene, rect, inspectable = false,
xautolimits = false, yautolimits = false, zautolimits = false,
color = attr(:panelcolor), visible = attr(:panelvisible))
color = attr(:panelcolor), visible = attr(:panelvisible),
strokecolor = :transparent, strokewidth = 0,
transformation = (plane, 0),
)

on(plane_offset) do offset
translate!(
panel,
dim3 == 1 ? offset : zero(offset),
dim3 == 2 ? offset : zero(offset),
dim3 == 3 ? offset : zero(offset),
)
end

return panel
end

Expand Down

0 comments on commit 814d8d5

Please sign in to comment.