Skip to content

Commit

Permalink
Improvements to GeoAxis and docs + upgrade to Makie 0.21 (#207)
Browse files Browse the repository at this point in the history
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
asinghvi17 authored Jun 6, 2024
2 parents 681fca7 + 81fef58 commit ec75bed
Show file tree
Hide file tree
Showing 72 changed files with 2,262 additions and 652 deletions.
5 changes: 0 additions & 5 deletions .devcontainer/Dockerfile

This file was deleted.

7 changes: 0 additions & 7 deletions .devcontainer/devcontainer.json

This file was deleted.

19 changes: 16 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
branches:
- master
tags: '*'
# needed to allow julia-actions/cache to delete old caches that it has created
permissions:
actions: write
contents: read
jobs:
test:
name: Tests, Julia ${{ matrix.version }} - ${{ matrix.os }}
Expand Down Expand Up @@ -37,6 +41,10 @@ jobs:
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
env:
DISPLAY: ':0'
with:
prefix: xvfb-run -s '-screen 0 1024x768x24'
- uses: actions/upload-artifact@v4
if: always()
with:
Expand All @@ -55,13 +63,18 @@ jobs:
with:
version: '1'
- uses: julia-actions/cache@v2
- run: |
julia --project=docs -e '
- name: Install documentation dependencies
run: |
xvfb-run -s '-screen 0 1024x768x24' julia --project=docs -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.add([PackageSpec(name = "DocumenterVitepress", rev = "master"), PackageSpec(name = "Makie", rev = "master"), PackageSpec(name = "MakieCore", rev = "master"), PackageSpec(name = "CairoMakie", rev = "master")])
Pkg.instantiate()'
env:
DISPLAY: ':0'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # If authenticating with GitHub Actions token
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # If authenticating with SSH deploy key
run: DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=docs/ docs/make.jl deploy
DISPLAY: ':0'
run: xvfb-run -s '-screen 0 1024x768x24' julia --project=docs/ docs/make.jl deploy
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/dev/
/docs/build/
/docs/site/
/docs/src/examples.md
/docs/src/examples
/docs/Manifest.toml
stuff.jl
.vscode
Expand All @@ -16,5 +16,9 @@ src/oldsrc
src/experimental

docs/src/images
docs/src/examples
docs/src/examples/
docs/node_modules
docs/build/
node_modules/
docs/package-lock.json
test_images/
7 changes: 7 additions & 0 deletions CHANGELOG.md
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.
12 changes: 9 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
name = "GeoMakie"
uuid = "db073c08-6b98-4ee5-b6a4-5efafb3259c6"
authors = ["Makie.jl Contributors"]
version = "0.6.5"
version = "0.7.0-DEV"

[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
GeoFormatTypes = "68eda718-8dee-11e9-39e7-89f7f65f511f"
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
GeoJSON = "61d90e0f-e114-555e-ac52-39dfb47a3ef9"
Geodesy = "0ef565a4-170c-5f04-8de2-149903a85f3d"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
GeometryOps = "3251bfac-6a57-4b6d-aa61-ac1fef2975ab"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
NaturalEarth = "436b0209-26ab-4e65-94a9-6526d86fea76"
Proj = "c94c279d-25a6-4763-9509-64d165bea63e"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand All @@ -21,13 +24,16 @@ StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
[compat]
Colors = "0.12"
Downloads = "1"
GeoFormatTypes = "0.4"
GeoInterface = "0.5, 1.0"
GeoJSON = "0.6,0.7, 0.8"
GeoJSON = "0.6, 0.7, 0.8"
Geodesy = "1.1.0"
GeometryBasics = "0.4.11"
GeometryOps = "0.1.4"
ImageIO = "0.6"
LinearAlgebra = "1"
Makie = "0.20.8"
Makie = "0.21"
NaturalEarth = "0.1"
Proj = "1"
Reexport = "1"
Statistics = "1"
Expand Down
22 changes: 21 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,42 @@ Animations = "27a7e980-b3e6-11e9-2bcd-0b925532e340"
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DemoCards = "311a05b2-6137-4a5a-b473-18580a3d38b5"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterVitepress = "4710194d-e776-4893-9690-8d956a29c365"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
GADM = "a8dd9ffe-31dc-4cf5-a379-ea69100a8233"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
GMT = "5752ebe1-31b9-557e-87aa-f909b540aa54"
GeoFormatTypes = "68eda718-8dee-11e9-39e7-89f7f65f511f"
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
GeoInterfaceMakie = "0edc0954-3250-4c18-859d-ec71c1660c08"
GeoJSON = "61d90e0f-e114-555e-ac52-39dfb47a3ef9"
GeoMakie = "db073c08-6b98-4ee5-b6a4-5efafb3259c6"
Geodesy = "0ef565a4-170c-5f04-8de2-149903a85f3d"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
GeometryOps = "3251bfac-6a57-4b6d-aa61-ac1fef2975ab"
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
LibGEOS = "a90b1aa1-3769-5649-ba7e-abc5a9d163eb"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
MakieCore = "20f20a25-4f0e-4fdf-b5d1-57303727442b"
MakieThemes = "e296ed71-da82-5faf-88ab-0034a9761098"
NaturalEarth = "436b0209-26ab-4e65-94a9-6526d86fea76"
Polylabel = "49a44318-e865-4b63-9842-695152d634c1"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Proj = "c94c279d-25a6-4763-9509-64d165bea63e"
RasterDataSources = "3cb90ccd-e1b6-4867-9617-4276c8b2ca36"
Rasters = "a3a2b9e3-a471-40c9-b274-f788e487c689"
Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4"
WGLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008"
ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"

[compat]
Documenter = "0.27"
Documenter = "1"
Makie = "0.21"
MakieThemes = "0.1.1"
99 changes: 99 additions & 0 deletions docs/documenter_figure_block.jl
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
51 changes: 51 additions & 0 deletions docs/gallery_setup.jl
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
42 changes: 42 additions & 0 deletions docs/logo.jl
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)
Loading

0 comments on commit ec75bed

Please sign in to comment.