mirror of https://github.com/mpastell/Weave.jl
commit
244cb9ab17
|
@ -26,9 +26,10 @@ const default_mime_types = ["image/svg+xml", "image/png", "text/html", "text/pla
|
||||||
function Base.display(report::Report, data)
|
function Base.display(report::Report, data)
|
||||||
#Set preferred mimetypes for report based on format
|
#Set preferred mimetypes for report based on format
|
||||||
for m in report.mimetypes
|
for m in report.mimetypes
|
||||||
|
info(m)
|
||||||
if mimewritable(m, data)
|
if mimewritable(m, data)
|
||||||
display(report, m, data)
|
display(report, m, data)
|
||||||
#Always use plain text for term mode
|
#Always show plain text as well for term mode
|
||||||
if m ≠ "text/plain" && report.cur_chunk.options[:term]
|
if m ≠ "text/plain" && report.cur_chunk.options[:term]
|
||||||
display(report, "text/plain", data)
|
display(report, "text/plain", data)
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,8 @@ using Gadfly
|
||||||
|
|
||||||
Gadfly.set_default_plot_format(:svg)
|
Gadfly.set_default_plot_format(:svg)
|
||||||
|
|
||||||
#Captures figures
|
#Gadfly doesn't call the default display methods, this catches
|
||||||
|
#all Gadfly plots
|
||||||
function Base.display(report::Report, m::MIME"image/svg+xml", p::Plot)
|
function Base.display(report::Report, m::MIME"image/svg+xml", p::Plot)
|
||||||
|
|
||||||
chunk = report.cur_chunk
|
chunk = report.cur_chunk
|
||||||
|
|
|
@ -1,21 +1,47 @@
|
||||||
import Winston
|
import Winston
|
||||||
|
import Base.mimewritable
|
||||||
|
|
||||||
|
function save_winston(report, data)
|
||||||
|
chunk = report.cur_chunk
|
||||||
|
full_name, rel_name = get_figname(report, chunk)
|
||||||
|
|
||||||
|
docformat = formats[report.formatdict[:doctype]]
|
||||||
|
push!(report.figures, rel_name)
|
||||||
|
report.fignum += 1
|
||||||
|
vector_fmts = [".pdf"; ".svg"]
|
||||||
|
#Don't use dpi for vector formats
|
||||||
|
if chunk.options[:fig_ext] in vector_fmts
|
||||||
|
Winston.savefig(data, full_name, width=chunk.options[:fig_width]*100,
|
||||||
|
height=chunk.options[:fig_height]*100)
|
||||||
|
else
|
||||||
|
Winston.savefig(data, full_name,
|
||||||
|
width=chunk.options[:fig_width]*chunk.options[:dpi],
|
||||||
|
height=chunk.options[:fig_height]*chunk.options[:dpi])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Base.display(report::Report, m::MIME"image/svg+xml", data::Winston.FramedPlot)
|
function Base.display(report::Report, m::MIME"image/svg+xml", data::Winston.FramedPlot)
|
||||||
|
save_winston(report, data)
|
||||||
chunk = report.cur_chunk
|
end
|
||||||
full_name, rel_name = get_figname(report, chunk)
|
|
||||||
|
function Base.mimewritable(m::MIME"application/pdf", data::Winston.FramedPlot)
|
||||||
docformat = formats[report.formatdict[:doctype]]
|
return true
|
||||||
push!(report.figures, rel_name)
|
end
|
||||||
report.fignum += 1
|
|
||||||
vector_fmts = [".pdf"; ".svg"]
|
function Base.mimewritable(m::MIME"image/svg+xml", data::Winston.FramedPlot)
|
||||||
#Don't use dpi for vector formats
|
return true
|
||||||
if chunk.options[:fig_ext] in vector_fmts
|
end
|
||||||
Winston.savefig(data, full_name, width=chunk.options[:fig_width]*100,
|
|
||||||
height=chunk.options[:fig_height]*100)
|
|
||||||
else
|
|
||||||
Winston.savefig(data, full_name,
|
function Base.display(report::Report, m::MIME"application/pdf", data::Winston.FramedPlot)
|
||||||
width=chunk.options[:fig_width]*chunk.options[:dpi],
|
save_winston(report, data)
|
||||||
height=chunk.options[:fig_height]*chunk.options[:dpi])
|
end
|
||||||
end
|
|
||||||
|
function Base.display(report::Report, m::MIME"image/png", data::Winston.FramedPlot)
|
||||||
|
save_winston(report, data)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Base.display(report::Report, m::MIME"image/jpg", data::Winston.FramedPlot)
|
||||||
|
save_winston(report, data)
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,11 +51,6 @@ display(p)
|
||||||
````
|
````
|
||||||
|
|
||||||
|
|
||||||
````
|
|
||||||
warning: sub-optimal solution for plot
|
|
||||||
````
|
|
||||||
|
|
||||||
|
|
||||||
![](figures/winston_formats_3_1.png)
|
![](figures/winston_formats_3_1.png)
|
||||||
|
|
||||||
````julia
|
````julia
|
||||||
|
|
|
@ -62,12 +62,6 @@ Winston.FramedPlot(...)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
::
|
|
||||||
|
|
||||||
warning: sub-optimal solution for plot
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.. image:: figures/winston_formats_3_1.png
|
.. image:: figures/winston_formats_3_1.png
|
||||||
:width: 15 cm
|
:width: 15 cm
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ julia> plot(t, sinc(t))
|
||||||
|
|
||||||
Winston.FramedPlot(...)
|
Winston.FramedPlot(...)
|
||||||
\end{juliaterm}
|
\end{juliaterm}
|
||||||
\includegraphics[width=\linewidth]{figures/winston_formats_1_1.png}
|
\includegraphics[width=\linewidth]{figures/winston_formats_1_1.pdf}
|
||||||
|
|
||||||
\begin{juliaterm}
|
\begin{juliaterm}
|
||||||
julia> s = 1:10
|
julia> s = 1:10
|
||||||
|
@ -18,7 +18,7 @@ julia> s = 1:10
|
||||||
julia> plot(s, "r*")
|
julia> plot(s, "r*")
|
||||||
Winston.FramedPlot(...)
|
Winston.FramedPlot(...)
|
||||||
\end{juliaterm}
|
\end{juliaterm}
|
||||||
\includegraphics[width=\linewidth]{figures/winston_formats_1_2.png}
|
\includegraphics[width=\linewidth]{figures/winston_formats_1_2.pdf}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ Winston.FramedPlot(...)
|
||||||
|
|
||||||
\begin{figure}[htpb]
|
\begin{figure}[htpb]
|
||||||
\center
|
\center
|
||||||
\includegraphics[width=\linewidth]{figures/winston_formats_random_1.png}
|
\includegraphics[width=\linewidth]{figures/winston_formats_random_1.pdf}
|
||||||
\caption{Random walk.}
|
\caption{Random walk.}
|
||||||
\label{fig:random}
|
\label{fig:random}
|
||||||
\end{figure}
|
\end{figure}
|
||||||
|
@ -50,10 +50,7 @@ add(p, Curve(x, s, color="blue"))
|
||||||
display(p)
|
display(p)
|
||||||
|
|
||||||
\end{juliacode}
|
\end{juliacode}
|
||||||
\begin{juliaout}
|
\includegraphics[width=\linewidth]{figures/winston_formats_3_1.pdf}
|
||||||
warning: sub-optimal solution for plot
|
|
||||||
\end{juliaout}
|
|
||||||
\includegraphics[width=\linewidth]{figures/winston_formats_3_1.png}
|
|
||||||
|
|
||||||
\begin{juliacode}
|
\begin{juliacode}
|
||||||
|
|
||||||
|
@ -82,4 +79,4 @@ l = Legend(.1, .9, {a,b,s})
|
||||||
add(p, s, a, b, l)
|
add(p, s, a, b, l)
|
||||||
display(p)
|
display(p)
|
||||||
\end{juliacode}
|
\end{juliacode}
|
||||||
\includegraphics[width=\linewidth]{figures/winston_formats_3_2.png}
|
\includegraphics[width=\linewidth]{figures/winston_formats_3_2.pdf}
|
||||||
|
|
|
@ -11,7 +11,7 @@ Winston.FramedPlot(...)
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
![](figures/winston_formats_1_1.png)\
|
![](figures/winston_formats_1_1.svg)\
|
||||||
|
|
||||||
|
|
||||||
~~~~{.julia}
|
~~~~{.julia}
|
||||||
|
@ -23,14 +23,14 @@ Winston.FramedPlot(...)
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
![](figures/winston_formats_1_2.png)\
|
![](figures/winston_formats_1_2.svg)\
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
![Random walk.](figures/winston_formats_random_1.png)
|
![Random walk.](figures/winston_formats_random_1.svg)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,12 +53,7 @@ display(p)
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
~~~~
|
![](figures/winston_formats_3_1.svg)\
|
||||||
warning: sub-optimal solution for plot
|
|
||||||
~~~~
|
|
||||||
|
|
||||||
|
|
||||||
![](figures/winston_formats_3_1.png)\
|
|
||||||
|
|
||||||
|
|
||||||
~~~~{.julia}
|
~~~~{.julia}
|
||||||
|
@ -90,5 +85,5 @@ display(p)
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
![](figures/winston_formats_3_2.png)\
|
![](figures/winston_formats_3_2.svg)\
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@ if VERSION < v"0.5-dev"
|
||||||
include("chunk_opts_gadfly.jl")
|
include("chunk_opts_gadfly.jl")
|
||||||
|
|
||||||
#Fails on travis, works locally.
|
#Fails on travis, works locally.
|
||||||
#info("Test: Weaving with Winston")
|
info("Test: Weaving with Winston")
|
||||||
#include("winston_formats.jl")
|
include("winston_formats.jl")
|
||||||
|
|
||||||
info("Test: Weaving with Gadfly")
|
info("Test: Weaving with Gadfly")
|
||||||
include("gadfly_formats.jl")
|
include("gadfly_formats.jl")
|
||||||
|
|
Loading…
Reference in New Issue