-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to GeoAxis and docs + upgrade to Makie 0.21 (#207)
Updates to Makie v0.21 and adds a couple of improvements to GeoAxis. Also gets rid of `PROJ_RESCALE_FACTOR` since we can now use Float64 numbers. This PR requires Makie v0.21 and is only usable with those versions of Makie. View the docs at https://geo.makie.org/previews/PR207 ## Full changelog - Converted all internal computations to use `Float64` instead of `Float32` thanks to @ffreyer's and the Makie team's work in Makie.jl v0.21. - Consequently, the `PROJ_RESCALE_FACTOR` hack is also removed. - Zooming in close should also work now, with the correct ticks being shown. - Added the option to provide an integer `scale` in `coastlines` and `land`, which triggers GeoMakie to get data from [NaturalEarth.jl](https://github.com/JuliaGeo/NaturalEarth.jl) instead of using the bundled data. - Updated the `to_multipoly` function to use GeoInterface traits, so that it's more universal. - Added several new examples - `tissot.jl`, `source_crs.jl`, etc. - Added dependencies to Project.toml: - GeoFormatTypes.jl for possible integration / `GI.crs` on GeoAxis - NaturalEarth.jl as mentioned above - GeometryOps.jl for potential antimeridian cutting and other geometry routines (not used yet, but will be used soon)
- Loading branch information
Showing
72 changed files
with
2,262 additions
and
652 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# 0.6.3 | ||
- Converted all internal computations to use `Float64` instead of `Float32` thanks to @ffreyer's work in Makie.jl v0.21. | ||
- Consequently, the `PROJ_RESCALE_FACTOR` hack is also removed. | ||
- Zooming in close should also work now, with the correct ticks being shown. | ||
- Added the option to provide an integer `scale` in `coastlines` and `land`, which triggers GeoMakie to get data from [NaturalEarth.jl](https://github.com/JuliaGeo/NaturalEarth.jl) instead of using the bundled data. | ||
- Updated the `to_multipoly` function to use GeoInterface traits, so that it's more universal. | ||
- Added several new examples - `tissot.jl`, `source_crs.jl`, etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
abstract type FigureBlocks <: Documenter.Expanders.NestedExpanderPipeline end | ||
|
||
|
||
Documenter.Selectors.order(::Type{FigureBlocks}) = 8.0 # like @example | ||
Documenter.Selectors.matcher(::Type{FigureBlocks}, node, page, doc) = Documenter.iscode(node, r"^@figure") | ||
|
||
module MakieDocsHelpers | ||
struct AsMIME{M<:MIME,V} | ||
mime::M | ||
value::V | ||
end | ||
|
||
Base.show(io::IO, m::MIME"image/svg+xml", a::AsMIME{MIME"image/svg+xml"}) = show(io,m, a.value) | ||
Base.show(io::IO, m::MIME"image/png", a::AsMIME{MIME"image/png"}) = show(io,m, a.value) | ||
|
||
struct Image{M <: MIME, V} | ||
"The contents of the image encoded in base64." | ||
value::V | ||
"The desired size of the output image, in pixels." | ||
size::NTuple{2, Int} | ||
end | ||
|
||
Base.show(io::IO, m::MIME, a::Image{MIME}) where MIME = show(io, m, a.value) | ||
|
||
const current_figurelike = Ref{Any}(nothing) | ||
|
||
end | ||
|
||
|
||
|
||
function Documenter.Selectors.runner(::Type{FigureBlocks}, node, page, doc) | ||
el = node.element | ||
infoexpr = Meta.parse(el.info) | ||
args = infoexpr.args[3:end] | ||
if !isempty(args) && args[1] isa Symbol | ||
blockname = string(args[1]) | ||
kwargs = args[2:end] | ||
else | ||
blockname = "" | ||
kwargs = args | ||
end | ||
|
||
is_continued = false | ||
# check if any previous code block is an @example block and has the same name (previous @figure blocks are | ||
# already converted at this point) | ||
if blockname != "" | ||
# iterate all the previous siblings | ||
prev = node.previous | ||
while prev !== nothing | ||
if prev.element isa Documenter.MultiOutput && prev.element.codeblock.info == "@example $blockname" | ||
is_continued = true | ||
break | ||
end | ||
prev = prev.previous | ||
end | ||
end | ||
|
||
kwargs = Dict(map(kwargs) do expr | ||
if !(expr isa Expr) && expr.head !== :(=) && length(expr.args) == 2 && expr.args[1] isa Symbol && expr.args[2] isa Union{String,Number,Symbol} | ||
error("Invalid keyword arg expression: $expr") | ||
end | ||
expr.args[1] => expr.args[2] | ||
end) | ||
el.info = "@example $blockname" | ||
el.code = transform_figure_code(el.code; is_continued, kwargs...) | ||
Documenter.Selectors.runner(Documenter.Expanders.ExampleBlocks, node, page, doc) | ||
# interrogate the node, if it is PNG then we replace the png output | ||
# with an `Image` struct, which houses the base64 string as well as | ||
# the Figure's size information. | ||
# This allows images to retain high quality yet be sized appropriately. | ||
if MakieDocsHelpers.current_figurelike[] isa Makie.FigureLike | ||
mimesym = get(kwargs, :mime, :png) | ||
mime = mimesym == :svg ? MIME"image/svg+xml"() : mimesym == :png ? MIME"image/png"() : error("Unknown mimetype $mime") | ||
image = Image{mime}(MakieDocsHelpers.current_figurelike[], size(MakieDocsHelpers.current_figurelike[])) | ||
# Obtain the node's multi-output element | ||
md_output_element = last(node.children) # the node has already been edited here | ||
md_output_element.element.element[mime] = image | ||
end | ||
end | ||
|
||
function transform_figure_code(code::String; is_continued::Bool, backend::Symbol = :CairoMakie, mime=:png) | ||
backend in (:CairoMakie, :GLMakie) || error("Invalid backend $backend") | ||
mimetype = mime == :svg ? "image/svg+xml" : mime == :png ? "image/png" : error("Unknown mimetype $mime") | ||
|
||
(is_continued ? "" : """ | ||
using $backend | ||
$backend.activate!() # hide | ||
""") * | ||
""" | ||
import ..MakieDocsHelpers # hide | ||
var"#result" = begin # hide | ||
$code | ||
end # hide | ||
if var"#result" isa Makie.FigureLike # hide | ||
MakieDocsHelpers.current_figurelike[] = var"#result" # hide | ||
end # hide | ||
MakieDocsHelpers.AsMIME(MIME"$mimetype"(), var"#result") # hide | ||
""" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module Gallery | ||
using Base, Markdown | ||
|
||
struct Card | ||
href::String | ||
src::String | ||
caption::String | ||
desc::String | ||
end | ||
|
||
Card(; path = "", caption = "", desc = "", cover_ext = ".png") = Card(path, joinpath(splitdir(path)[1], "covers", path * cover_ext), caption, desc) | ||
|
||
function Base.show(io::IO, ::MIME"application/json", card::Card) | ||
print(io, | ||
""" | ||
{ | ||
"href": '$(card.href)', | ||
"src": '$(card.src)', | ||
"caption": '$(replace(card.caption, "'" => "\\'"))', | ||
"desc": '$(replace(card.desc, "'" => "\\'"))', | ||
}""") | ||
end | ||
|
||
function Base.show(io::IO, ::MIME"application/json", cards::Vector{Card}) | ||
println(io, "[") | ||
for card in cards | ||
show(io, MIME"application/json"(), card) | ||
println(io, ",") | ||
end | ||
println(io, "]") | ||
end | ||
|
||
function mdify(cards::Vector{Card}; name = "demos", ) | ||
iob = IOBuffer() | ||
show(iob, MIME"application/json"(), cards) | ||
card_json = String(take!(iob)) | ||
return Markdown.MD( | ||
Markdown.Paragraph( | ||
""" | ||
<script setup lang="ts"> | ||
import Gallery from "./components/Gallery.vue"; | ||
const $name = $card_json | ||
</script> | ||
<Gallery :images="$name" /> | ||
""" | ||
) | ||
) | ||
end | ||
|
||
export Card, mdify | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using GLMakie, GeoMakie, Makie | ||
using Makie.Colors | ||
|
||
function infer_alphacolor(rgb1, rgb2) | ||
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)) | ||
alpha = @. 1 - (c1 - c2) * -1 # ( / (0 - 1)) | ||
meanalpha = clamp(sum(alpha) / 3, 0, 1) | ||
meanalpha == 0 && return RGBAf(0, 0, 0, 0) | ||
c = @. clamp((c1 / meanalpha), 0, 1) | ||
return RGBAf(c..., meanalpha) | ||
end | ||
|
||
function alpha_colorbuffer(screen::MakieScreen) | ||
bg = screen.root_scene.backgroundcolor[] | ||
screen.root_scene.backgroundcolor[] = RGBAf(0, 0, 0, 1) | ||
b1 = deepcopy(colorbuffer(screen)) | ||
display(b1) | ||
screen.root_scene.backgroundcolor[] = RGBAf(1, 1, 1, 1) | ||
b2 = deepcopy(colorbuffer(screen)) | ||
screen.root_scene.backgroundcolor[] = bg | ||
return map(b1, b2) do b1, b2 | ||
infer_alphacolor(b1, b2) | ||
end | ||
end | ||
|
||
|
||
|
||
# generate the logo | ||
|
||
f, a, p = meshimage( | ||
-180..180, | ||
-90..90, | ||
GeoMakie.earth(); | ||
axis = (; type = GeoAxis, dest = "+proj=igh") | ||
) | ||
hidedecorations!(a; grid = false) | ||
ip = meshimage!(a, -180..180, -90..90, Makie.logo()) | ||
screen = display(f; px_per_unit=2) | ||
img = alpha_colorbuffer(screen) | ||
save(joinpath(@__DIR__, "src", "assets", "logo.png"), img) |
Oops, something went wrong.