2019-02-07 18:28:06 +01:00
|
|
|
module GadflyPlots
|
|
|
|
|
2017-03-14 08:27:16 +01:00
|
|
|
import Gadfly
|
2019-02-07 18:28:06 +01:00
|
|
|
import Weave
|
|
|
|
try
|
|
|
|
import Cairo
|
|
|
|
catch
|
|
|
|
@warn("Cairo.jl is required to be installed to generate raster images")
|
|
|
|
end
|
2014-12-03 14:41:53 +01:00
|
|
|
|
2016-04-27 13:51:15 +02:00
|
|
|
Gadfly.set_default_plot_format(:svg)
|
2014-12-03 14:41:53 +01:00
|
|
|
|
2019-03-11 09:23:31 +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
|
|
|
|
|
2019-02-07 18:28:06 +01:00
|
|
|
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
|
|
|
|
|
2016-04-28 10:16:02 +02:00
|
|
|
#Gadfly doesn't call the default display methods, this catches
|
|
|
|
#all Gadfly plots
|
2019-02-07 18:28:06 +01:00
|
|
|
function Base.display(report::Weave.Report, m::MIME"image/svg+xml", p::Gadfly.Plot)
|
2016-04-20 19:23:00 +02:00
|
|
|
chunk = report.cur_chunk
|
2014-12-04 20:54:56 +01:00
|
|
|
|
2017-03-14 08:27:16 +01:00
|
|
|
w = chunk.options[:fig_width]Gadfly.inch
|
|
|
|
h = chunk.options[:fig_height]Gadfly.inch
|
2015-01-05 15:35:24 +01:00
|
|
|
format = chunk.options[:fig_ext]
|
|
|
|
dpi = chunk.options[:dpi]
|
2014-12-05 09:37:02 +01:00
|
|
|
|
2019-02-07 18:28:06 +01:00
|
|
|
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"
|
|
|
|
Gadfly.draw(Gadfly.PNG(full_name, w, h, dpi=dpi), p)
|
2015-01-08 18:06:43 +01:00
|
|
|
elseif format == ".pdf"
|
2017-03-14 08:27:16 +01:00
|
|
|
Gadfly.draw(Gadfly.PDF(full_name, w, h), p)
|
2015-01-08 18:06:43 +01:00
|
|
|
elseif format == ".ps"
|
2017-03-14 08:27:16 +01:00
|
|
|
Gadfly.draw(Gadfly.PS(full_name, w, h), p)
|
2015-01-08 18:06:43 +01:00
|
|
|
elseif format == ".tex"
|
2017-03-14 08:27:16 +01:00
|
|
|
Gadfly.draw(Gadfly.PGF(full_name, w, h, true ), p)
|
2016-12-20 21:21:50 +01:00
|
|
|
else
|
2019-02-07 18:28:06 +01:00
|
|
|
@warn("Can't save figure. Unsupported format, $format")
|
2014-12-05 09:37:02 +01:00
|
|
|
end
|
2014-12-03 14:41:53 +01:00
|
|
|
end
|
2019-03-11 09:23:31 +01:00
|
|
|
end
|