Weave.jl/src/gadfly.jl

52 lines
1.5 KiB
Julia
Raw Normal View History

module GadflyPlots
using ..Weave, ..Gadfly
Gadfly.set_default_plot_format(:svg)
2014-12-03 14:41:53 +01:00
Base.showable(m::MIME"application/pdf", p::Gadfly.Plot) = true
Base.showable(m::MIME"application/png", p::Gadfly.Plot) = true
function Base.display(report::Weave.Report, m::MIME"application/pdf", p::Gadfly.Plot)
display(report, MIME("image/svg+xml"), p)
end
function Base.display(report::Weave.Report, m::MIME"image/png", p::Gadfly.Plot)
2017-05-15 16:13:18 +02:00
display(report, MIME("image/svg+xml"), p)
end
2020-05-08 16:39:17 +02:00
# Gadfly doesn't call the default display methods, this catches
# all Gadfly plots
function Base.display(report::Weave.Report, m::MIME"image/svg+xml", p::Gadfly.Plot)
chunk = report.cur_chunk
2020-05-08 16:39:17 +02:00
w = chunk.options[:fig_width] * Gadfly.inch
h = chunk.options[:fig_height] * Gadfly.inch
format = chunk.options[:fig_ext]
dpi = chunk.options[:dpi]
full_name, rel_name = Weave.get_figname(report, chunk, ext = format)
push!(report.figures, rel_name)
report.fignum += 1
if format == ".svg"
Gadfly.draw(Gadfly.SVG(full_name, w, h), p)
elseif format == ".js.svg"
Gadfly.draw(Gadfly.SVGJS(full_name, w, h), p)
elseif format == ".png"
2020-05-08 16:39:17 +02:00
Gadfly.draw(Gadfly.PNG(full_name, w, h, dpi = dpi), p)
elseif format == ".pdf"
2017-03-14 08:27:16 +01:00
Gadfly.draw(Gadfly.PDF(full_name, w, h), p)
elseif format == ".ps"
2017-03-14 08:27:16 +01:00
Gadfly.draw(Gadfly.PS(full_name, w, h), p)
elseif format == ".tex"
2020-05-08 16:39:17 +02:00
Gadfly.draw(Gadfly.PGF(full_name, w, h, true), p)
2016-12-20 21:21:50 +01:00
else
@warn("Can't save figure. Unsupported format, $format")
end
2014-12-03 14:41:53 +01:00
end
end