Weave.jl/src/gadfly.jl

42 lines
1.1 KiB
Julia
Raw Normal View History

2014-12-03 14:41:53 +01:00
using Gadfly
Gadfly.set_default_plot_format(:png)
2014-12-04 15:14:07 +01:00
#Captures figures
function Base.display(report::Report, m::MIME"image/png", p::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
w = chunk.options[:fig_width]inch
h = chunk.options[:fig_height]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
draw(PNG(full_name, w, h, dpi=dpi), p)
2014-12-18 12:44:37 +01:00
catch
draw(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"
draw(PDF(full_name, w, h), p)
elseif format == ".ps"
draw(PS(full_name, w, h), p)
elseif format == ".svg"
draw(SVG(full_name, w, h), p)
elseif format == ".js.svg"
draw(SVGJS(full_name, w, h), p)
elseif format == ".tex"
draw(PGF(full_name, w, h, true ), p)
else:
warn("Can't save figure. Unsupported format")
end
2014-12-03 14:41:53 +01:00
end