Weave.jl/src/gadfly.jl

43 lines
1.3 KiB
Julia
Raw Normal View History

2017-03-14 08:27:16 +01:00
import Gadfly
2014-12-03 14:41:53 +01:00
Gadfly.set_default_plot_format(:svg)
2014-12-03 14:41:53 +01:00
2016-04-28 10:16:02 +02:00
#Gadfly doesn't call the default display methods, this catches
#all Gadfly plots
2017-03-14 08:27:16 +01:00
function Base.display(report::Report, m::MIME"image/svg+xml", p::Gadfly.Plot)
chunk = report.cur_chunk
2014-12-04 15:14:07 +01:00
full_name, rel_name = get_figname(report, chunk)
2014-12-03 22:34:29 +01:00
docformat = formats[report.formatdict[:doctype]]
push!(report.figures, rel_name)
2014-12-03 22:34:29 +01:00
2014-12-04 15:14:07 +01:00
report.fignum += 1
2017-03-14 08:27:16 +01:00
w = chunk.options[:fig_width]Gadfly.inch
h = chunk.options[:fig_height]Gadfly.inch
format = chunk.options[:fig_ext]
dpi = chunk.options[:dpi]
#This is probably not the correct way to handle different formats, but it works.
if format == ".png"
2014-12-18 12:44:37 +01:00
try
2017-03-14 08:27:16 +01:00
Gadfly.draw(Gadfly.PNG(full_name, w, h, dpi=dpi), p)
2014-12-18 12:44:37 +01:00
catch
2017-03-14 08:27:16 +01:00
Gadfly.draw(Gadfly.PNG(full_name, w, h), p) #Compose < 0.3.1, Gadfly < 0.3.1
2014-12-18 12:44:37 +01:00
end
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 == ".svg"
2017-03-14 08:27:16 +01:00
Gadfly.draw(Gadfly.SVG(full_name, w, h), p)
elseif format == ".js.svg"
2017-03-14 08:27:16 +01:00
Gadfly.draw(Gadfly.SVGJS(full_name, w, h), p)
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
warn("Can't save figure. Unsupported format")
end
2014-12-03 14:41:53 +01:00
end