Weave.jl/src/gadfly.jl

57 lines
1.5 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)
2014-12-03 22:34:29 +01:00
chunk = report.cur_chunk
#if chunk[:fig_ext] != ".png"
# chunk[:fig_ext]
# warn("Saving figures as .png with Gadfly")
#end
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]]
2014-12-04 15:14:07 +01:00
#Add to results for term chunks and store otherwise
2014-12-03 22:34:29 +01:00
if chunk[:term]
chunk[:figure] = [rel_name]
2014-12-05 10:28:55 +01:00
if report.term_state == :text
report.cur_result *= "\n" * report.formatdict[:codeend] * "\n"
2014-12-05 10:28:55 +01:00
end
2014-12-06 18:16:45 +01:00
2014-12-05 10:28:55 +01:00
2014-12-03 22:34:29 +01:00
report.cur_result *= formatfigures(chunk, docformat)
2014-12-05 10:28:55 +01:00
report.term_state = :fig
2014-12-03 22:34:29 +01:00
chunk[:figure] = String[]
else
2014-12-04 15:14:07 +01:00
push!(report.figures, rel_name)
2014-12-03 22:34:29 +01:00
end
2014-12-04 15:14:07 +01:00
report.fignum += 1
#TODO other formats
#Can't specify dpi in Gadfly? Opened Gadfly issue #504
w = chunk[:fig_width]inch
h = chunk[:fig_height]inch
format = chunk[:fig_ext]
#This is probably not the correct way to handle different formats, but it works.
if format == ".png"
draw(PNG(full_name, w, h), p)
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)
else:
warn("Can't save figure. Unsupported format")
end
2014-12-03 14:41:53 +01:00
end