-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more examples + a basic metadata framework (#233)
* Update index.md * Add a histogram example Datashader won't work, but this is a good approximation * Fix link in the rasters example * Enable plotting MultiLineStrings * Update the contour example to show all features * Better theming for contour example * Add the "annotation" and "Hurricane Katrina" examples from Cartopy More to come soon * Bugfixes for docs * Remove individual activations from examples * First foray into example card block * Fully implement the example meta block * Clean up make.jl * add the Cartopy example for Vesta * Fix the projection in is_it_a_plane * Templates for new examples * Change docs to the new way of doing things * Add arrows example * add params and data to vestaa3d * add TopoPlots to docs/Project * Fix errors in the examples * set RDS_PATH in makedocs also * actually deploy docs * add ImageTransformations to the project for `imresize` mainly. * Fix cardmeta blocks not being commented This sounds like a mistake I will keep making :D * Add a streamplot example on geoaxis
- Loading branch information
1 parent
905c607
commit dc70cc3
Showing
40 changed files
with
536 additions
and
100 deletions.
There are no files selected for viewing
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,78 @@ | ||
using Documenter | ||
using ImageTransformations # for resize | ||
|
||
abstract type CardMetaBlocks <: Documenter.Expanders.ExpanderPipeline end | ||
|
||
# Order doesn't really matter, because the expansion is done based on page location first. | ||
Documenter.Selectors.order(::Type{CardMetaBlocks}) = 12.0 | ||
Documenter.Selectors.matcher(::Type{CardMetaBlocks}, node, page, doc) = Documenter.iscode(node, r"^@cardmeta") | ||
|
||
GALLERY_DICT = Dict{String, Any}() | ||
|
||
function Documenter.Selectors.runner(::Type{CardMetaBlocks}, node, page, doc) | ||
# Bail early if in draft mode | ||
if Documenter.is_draft(doc, page) | ||
@debug "Skipping evaluation of @example block in draft mode:\n$(x.code)" | ||
Documenter.create_draft_result!(node; blocktype="@example") | ||
return | ||
end | ||
|
||
# Literate.jl uses the page filename as an "environment name" for the example block, | ||
# so we need to extract that from the page. The code in the meta block has | ||
# to be evaluated in the same module in order to have access to local variables. | ||
page_name = first(splitext(last(splitdir(page.source)))) | ||
page_link_path = first(splitext(relpath(page.build, doc.user.build))) | ||
|
||
meta = Dict{Symbol, Any}() | ||
|
||
global GALLERY_DICT | ||
GALLERY_DICT[page_link_path] = meta | ||
|
||
# The sandboxed module -- either a new one or a cached one from this page. | ||
current_mod = Documenter.get_sandbox_module!(page.globals.meta, "atexample", page_name) | ||
|
||
x = node.element | ||
lines = Documenter.find_block_in_file(x.code, page.source) | ||
@debug "Evaluating @cardmeta block:\n$(x.code)" | ||
# @infiltrate | ||
|
||
for (ex, str) in Documenter.parseblock(x.code, doc, page) | ||
# If not `isassign`, this might be a comment, or any code that the user | ||
# wants to hide. We should probably warn, but it is common enough that | ||
# we will silently skip for now. | ||
if Documenter.isassign(ex) | ||
if !(ex.args[1] in (:Title, :Description, :Cover, :Authors, :Date)) | ||
source = Documenter.locrepr(page.source, lines) | ||
@warn( | ||
"In $source: `@cardmeta` block has an unsupported " * | ||
"keyword argument: $(ex.args[1])", | ||
) | ||
end | ||
try | ||
meta[ex.args[1]] = Core.eval(current_mod, ex.args[2]) | ||
catch err | ||
Documenter.@docerror(doc, :meta_block, | ||
""" | ||
failed to evaluate `$(strip(str))` in `@cardmeta` block in $(Documenter.locrepr(page.source, lines)) | ||
```$(x.info) | ||
$(x.code) | ||
``` | ||
""", exception = err) | ||
end | ||
end | ||
end | ||
|
||
# TODO: get defaults | ||
# How? | ||
# Title: get the first heading node on the page as DocumenterVitepress does | ||
# Description: empty string as default | ||
# Cover: no image as default | ||
# Author: Default should be hardcoded to `["Anshul Singhvi"](https://github.com/asinghvi17)` | ||
# Date: nothing, don't include it if nothing | ||
|
||
# Authors and Date are for the transformer and can be applied within this block, the first four | ||
# params need to go to the gallery/card object though. | ||
|
||
node.element = Documenter.MetaNode(x, page.globals.meta) | ||
|
||
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
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
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,34 @@ | ||
# # Annotated plot | ||
# This example is translated from [this Cartopy example](https://scitools.org.uk/cartopy/docs/latest/gallery/lines_and_polygons/feature_creation.html#sphx-glr-gallery-lines-and-polygons-feature-creation-py). | ||
|
||
using CairoMakie, GeoMakie, Makie | ||
using Makie: GeometryBasics | ||
using NaturalEarth | ||
|
||
states_fc = naturalearth("admin_1_states_provinces_lines", 50) | ||
|
||
|
||
fig = Figure() | ||
ga = GeoAxis(fig[1, 1]; limits = ((80, 170), (-45, 30)), dest = "+proj=longlat +datum=WGS84") | ||
image!(ga, -180..180, -90..90, GeoMakie.earth() |> rotr90; interpolate = false) | ||
poly!(ga, GeoMakie.land(); color = :lightyellow, strokecolor = :black, strokewidth = 1) | ||
lines!(ga, GeoMakie.to_multilinestring.(states_fc.geometry); color = :gray) | ||
fig | ||
# Now to add the annotation: | ||
const DATASOURCE = "Natural Earth" | ||
const LICENSE = "public domain" | ||
annotation_text = text!( | ||
ga.scene, Point2f(0.05, 0.05); # plotting in relative coordinates - (0, 0) is bottom left, (1, 1) is top right | ||
space = :relative, text = "© $DATASOURCE ($LICENSE)" | ||
) | ||
fig | ||
|
||
_pad_rect(rect, padding::Real) = Rect(rect.origin .- padding, rect.widths .+ 2 * padding) | ||
text_bbox = Makie.boundingbox(last(plots(ga.scene))) | ||
|
||
annotation_box = poly!(ga.scene, _pad_rect(text_bbox, 4); space = :pixel, color = :white, strokecolor = :black, strokewidth = 2) | ||
annotation_box.transformation.transform_func[] = identity | ||
translate!(annotation_text, 0, 0, 110) | ||
translate!(annotation_box, 0, 0, 109) | ||
fig | ||
|
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,38 @@ | ||
# # Gridded arrows | ||
# This example was taken from the [Cartopy gridded arrow example]. | ||
|
||
# The big idea is to plot arrows from one CRS in another! | ||
|
||
using GeoMakie, CairoMakie | ||
|
||
xs = LinRange(311.9, 391.1, 30) | ||
ys = LinRange(-23.6, 24.8, 20) | ||
|
||
us = @. 1 * (2 * cos(2 * deg2rad(xs) + 3 * deg2rad(ys' + 30)) ^ 2) | ||
vs = @. 2 * cos(6 * deg2rad(xs)) .+ ys' * 0 # that last part is just to establish the shape | ||
|
||
pole_longitude=177.5 | ||
pole_latitude=37.5 | ||
arrow_crs = "+proj=ob_tran +o_proj=latlon +o_lon_p=0 +o_lat_p=$(pole_latitude) +lon_0=$(180+pole_longitude) +to_meter=$(deg2rad(1) * 6378137.0)" | ||
|
||
f, a, p = arrows( | ||
xs, ys, us, vs; | ||
arrowsize = 4, | ||
source = arrow_crs, | ||
axis = (; type = GeoAxis, dest = "+proj=ortho +lon_0=-10 +lat_0=45") | ||
) | ||
# Now we plot the background: | ||
ep = surface!(a, | ||
-180..180, -90..90, | ||
zeros(axes(rotr90(GeoMakie.earth()))); | ||
shading = NoShading, color = rotr90(GeoMakie.earth()) | ||
) | ||
translate!(ep, 0, 0, -1) | ||
f | ||
|
||
# ```@cardmeta | ||
# Title = "Arrows" | ||
# Description = "Gridded arrows" | ||
# Cover = f | ||
# ``` | ||
|
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,8 @@ | ||
# Plotting the aurora | ||
|
||
aurora_colormap = cgrad( | ||
[RGBAf(0.1725, 0.9294, 0.3843, 0), RGBAf(0.1725, 0.9294, 0.3843, 1), RGBAf(0.8353, 0.8235, 0.6549)], | ||
[0, 0.5, 1]; | ||
categorical = false | ||
) | ||
|
Oops, something went wrong.