From c50e2dcc76baabf905dea1388bfbf0fe85b0c5b7 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Thu, 12 Oct 2023 11:04:12 +0200 Subject: [PATCH] Revert "Add "How to get a transparent background" page (#3236)" This reverts commit ed836a05a4a99285db28ce26d1d8ababbee80771. --- docs/_layout/masthead.html | 1 - docs/explanations.md | 2 +- docs/how-to.md | 5 -- docs/how-to/save-figure-with-transparency.md | 79 -------------------- src/figures.jl | 2 +- 5 files changed, 2 insertions(+), 87 deletions(-) delete mode 100644 docs/how-to.md delete mode 100644 docs/how-to/save-figure-with-transparency.md diff --git a/docs/_layout/masthead.html b/docs/_layout/masthead.html index 665d52fa67a..a8e5492f125 100644 --- a/docs/_layout/masthead.html +++ b/docs/_layout/masthead.html @@ -12,7 +12,6 @@
  • Reference
  • Tutorials
  • -
  • How-Tos
  • Explanations
  • API
  • News
  • diff --git a/docs/explanations.md b/docs/explanations.md index eae0ca075fa..3542f41c3d7 100644 --- a/docs/explanations.md +++ b/docs/explanations.md @@ -1,4 +1,4 @@ -@def order = 4 +@def order = 3 # Explanations diff --git a/docs/how-to.md b/docs/how-to.md deleted file mode 100644 index 9423ac5e16a..00000000000 --- a/docs/how-to.md +++ /dev/null @@ -1,5 +0,0 @@ -@def order = 3 - -# How-Tos - -{{list_folder how-to}} diff --git a/docs/how-to/save-figure-with-transparency.md b/docs/how-to/save-figure-with-transparency.md deleted file mode 100644 index aec0522f3a1..00000000000 --- a/docs/how-to/save-figure-with-transparency.md +++ /dev/null @@ -1,79 +0,0 @@ -# How to save a `Figure` with transparency - -## CairoMakie - -In CairoMakie, set the background color to `:transparent` (converts to `RGBAf(0, 0, 0, 0)`) to get a fully transparent background. -In the following examples, I use a partially transparent blue because a transparent background is indistinguishable from the usual white on a white page. - -\begin{examplefigure}{svg = true} -```julia -using CairoMakie -CairoMakie.activate!() # hide - -f = Figure(backgroundcolor = (:blue, 0.4)) -Axis(f[1, 1], backgroundcolor = (:tomato, 0.5)) -f -``` -\end{examplefigure} - -## GLMakie - -For technical reasons, GLMakie's color buffer does not have an alpha component: - -\begin{examplefigure}{} -```julia -using GLMakie -GLMakie.activate!() # hide -Makie.inline!(true) # hide - -f = Figure(backgroundcolor = (:blue, 0.4)) -Axis(f[1, 1], backgroundcolor = (:tomato, 0.5)) -f -``` -\end{examplefigure} - - -With the following trick you can still save an image with transparent background. -It works by setting two different background colors and calculating the foreground color with alpha from the difference. - -```julia:transparent-glmakie -using GLMakie -GLMakie.activate!() # hide -Makie.inline!(true) # hide - -function calculate_rgba(rgb1, rgb2, rgba_bg)::RGBAf - rgb1 == rgb2 && return RGBAf(rgb1.r, rgb1.g, rgb1.b, 1) - c1 = Float64.((rgb1.r, rgb1.g, rgb1.b)) - c2 = Float64.((rgb2.r, rgb2.g, rgb2.b)) - alphas_fg = 1 .+ c1 .- c2 - alpha_fg = clamp(sum(alphas_fg) / 3, 0, 1) - alpha_fg == 0 && return rgba_bg - rgb_fg = clamp.((c1 ./ alpha_fg), 0, 1) - rgb_bg = Float64.((rgba_bg.r, rgba_bg.g, rgba_bg.b)) - alpha_final = alpha_fg + (1 - alpha_fg) * rgba_bg.alpha - rgb_final = @. 1 / alpha_final * (alpha_fg * rgb_fg + (1 - alpha_fg) * rgba_bg.alpha * rgb_bg) - return RGBAf(rgb_final..., alpha_final) -end - -function alpha_colorbuffer(figure) - scene = figure.scene - bg = scene.backgroundcolor[] - scene.backgroundcolor[] = RGBAf(0, 0, 0, 1) - b1 = copy(colorbuffer(scene)) - scene.backgroundcolor[] = RGBAf(1, 1, 1, 1) - b2 = colorbuffer(scene) - scene.backgroundcolor[] = bg - return map(b1, b2) do b1, b2 - calculate_rgba(b1, b2, bg) - end -end - -f = Figure(backgroundcolor = (:blue, 0.4)) -Axis(f[1, 1], backgroundcolor = (:tomato, 0.5)) -f - -save(joinpath(@OUTPUT, "transparent.png"), alpha_colorbuffer(f)) # hide -save("transparent.png", alpha_colorbuffer(f)) -``` - -\fig{transparent.png} \ No newline at end of file diff --git a/src/figures.jl b/src/figures.jl index 6590571dfec..b7d60ac8c6d 100644 --- a/src/figures.jl +++ b/src/figures.jl @@ -98,7 +98,7 @@ function Figure(; kwargs...) kwargs_dict = Dict(kwargs) padding = pop!(kwargs_dict, :figure_padding, theme(:figure_padding)) - scene = Scene(; camera=campixel!, clear = true, kwargs_dict...) + scene = Scene(; camera=campixel!, kwargs_dict...) padding = convert(Observable{Any}, padding) alignmode = lift(Outside ∘ to_rectsides, padding)