-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Plots and Makie (#116)
- Loading branch information
1 parent
fc49409
commit 5a42853
Showing
9 changed files
with
107 additions
and
4 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
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,36 @@ | ||
@debug "Loading Makie.jl support into Books via Requires" | ||
|
||
using CairoMakie | ||
import Makie | ||
|
||
function convert_output(path, p::Makie.FigureAxisPlot; caption=nothing, label=nothing) | ||
im_dir = joinpath(BUILD_DIR, "im") | ||
mkpath(im_dir) | ||
|
||
if isnothing(path) | ||
# Not determining some random name here, because it would require cleanups too. | ||
msg = """ | ||
It is not possible to write an image without specifying a path. | ||
Use `Options(p; filename=filename)` where `p` is a Makie.jl plot. | ||
""" | ||
throw(ErrorException(msg)) | ||
end | ||
file, _ = method_name(path) | ||
|
||
println("Writing plot images for $file") | ||
svg_filename = "$file.svg" | ||
svg_path = joinpath(im_dir, svg_filename) | ||
# Explicit rm due to https://github.com/JuliaIO/FileIO.jl/issues/338. | ||
rm(svg_path; force=true) | ||
Makie.FileIO.save(svg_path, p) | ||
|
||
png_filename = "$file.png" | ||
png_path = joinpath(im_dir, png_filename) | ||
rm(png_path; force=true) | ||
px_per_unit = 3 # Ensure high resolution. | ||
Makie.FileIO.save(png_path, p; px_per_unit) | ||
|
||
im_link = joinpath("im", svg_filename) | ||
caption, label = caption_label(path, caption, label) | ||
pandoc_image(file, png_path; caption, label) | ||
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,31 @@ | ||
@debug "Loading Plots.jl support into Books via Requires" | ||
|
||
import Plots | ||
|
||
function convert_output(path, p::Plots.Plot; caption=nothing, label=nothing) | ||
im_dir = joinpath(BUILD_DIR, "im") | ||
mkpath(im_dir) | ||
|
||
if isnothing(path) | ||
# Not determining some random name here, because it would require cleanups too. | ||
msg = """ | ||
It is not possible to write an image without specifying a path or filename. | ||
Use `Options(p; filename=filename)` where `p` is a Plots.jl plot. | ||
""" | ||
throw(ErrorException(msg)) | ||
end | ||
file, _ = method_name(path) | ||
|
||
println("Writing plot images for $file") | ||
svg_filename = "$file.svg" | ||
svg_path = joinpath(im_dir, svg_filename) | ||
Plots.savefig(p, svg_path) | ||
|
||
png_filename = "$file.png" | ||
png_path = joinpath(im_dir, png_filename) | ||
Plots.savefig(p, png_path) | ||
|
||
im_link = joinpath("im", svg_filename) | ||
caption, label = caption_label(path, caption, label) | ||
pandoc_image(file, png_path; caption, label) | ||
end |