diff --git a/src/winston.jl b/src/winston.jl index 868c781..88b2f63 100644 --- a/src/winston.jl +++ b/src/winston.jl @@ -1,4 +1,4 @@ -using Winston +import Winston function Base.display(report::Report, m::MIME"image/png", data) @@ -26,9 +26,9 @@ function Base.display(report::Report, m::MIME"image/png", data) #Don't use dpi for vector formats if chunk[:fig_ext] in vector_fmts - savefig(data, full_name, width=chunk[:fig_width]*100, height=chunk[:fig_height]*100) + Winston.savefig(data, full_name, width=chunk[:fig_width]*100, height=chunk[:fig_height]*100) else - savefig(data, full_name, width=chunk[:fig_width]*chunk[:dpi], height=chunk[:fig_height]*chunk[:dpi]) + Winston.savefig(data, full_name, width=chunk[:fig_width]*chunk[:dpi], height=chunk[:fig_height]*chunk[:dpi]) end report.fignum += 1 diff --git a/test/documents/winston_formats.txt b/test/documents/winston_formats.txt new file mode 100644 index 0000000..177a418 --- /dev/null +++ b/test/documents/winston_formats.txt @@ -0,0 +1,59 @@ + +<>= +using Winston +t = linspace(0, 2*pi, 100) +plot(t, sinc(t)) +s = 1:10 +plot(s, "r*") +@ + + + +<>= +p = plot(cumsum(randn(1000, 1))) +xlabel("x") +ylabel("sinc(x)") +display(p) +@ + + +<>= +x = linspace(0, 3pi, 100) +c = cos(x) +s = sin(x) + +p = FramedPlot( + title="title!", + xlabel="\\Sigma x^2_i", + ylabel="\\Theta_i") + +add(p, FillBetween(x, c, x, s)) +add(p, Curve(x, c, color="red")) +add(p, Curve(x, s, color="blue")) +display(p) + +p = FramedPlot( + aspect_ratio=1, + xrange=(0,100), + yrange=(0,100)) + +n = 21 +x = linspace(0, 100, n) +yA = 40 .+ 10randn(n) +yB = x .+ 5randn(n) + +a = Points(x, yA, kind="circle") +setattr(a, label="a points") + +b = Points(x, yB) +setattr(b, label="b points") +style(b, kind="filled circle") + +s = Slope(1, (0,0), kind="dotted") +setattr(s, label="slope") + +l = Legend(.1, .9, {a,b,s}) + +add(p, s, a, b, l) +display(p) +@ diff --git a/test/documents/winston_formats_ref.md b/test/documents/winston_formats_ref.md new file mode 100644 index 0000000..dcabb7a --- /dev/null +++ b/test/documents/winston_formats_ref.md @@ -0,0 +1,117 @@ + + +````julia +julia> using Winston + +julia> t = linspace(0, 2*pi, 100) +100-element Array{Float64,1}: + 0.0 + 0.0634665 + 0.126933 + 0.1904 + 0.253866 + 0.317333 + 0.380799 + 0.444266 + 0.507732 + 0.571199 + ⋮ + 5.77545 + 5.83892 + 5.90239 + 5.96585 + 6.02932 + 6.09279 + 6.15625 + 6.21972 + 6.28319 + +julia> plot(t, sinc(t)) + +```` + + +![](figures/winston_formats_1_1.png) + +````julia +FramedPlot(...) + +```` + + + + +````julia +julia> s = 1:10 +1:10 + +julia> plot(s, "r*") + +```` + + +![](figures/winston_formats_1_2.png) + +````julia +FramedPlot(...) + +```` + + + + + + + + +![Random walk.](figures/winston_formats_random_1.png) + + + + +````julia +x = linspace(0, 3pi, 100) +c = cos(x) +s = sin(x) + +p = FramedPlot( + title="title!", + xlabel="\\Sigma x^2_i", + ylabel="\\Theta_i") + +add(p, FillBetween(x, c, x, s)) +add(p, Curve(x, c, color="red")) +add(p, Curve(x, s, color="blue")) +display(p) + +p = FramedPlot( + aspect_ratio=1, + xrange=(0,100), + yrange=(0,100)) + +n = 21 +x = linspace(0, 100, n) +yA = 40 .+ 10randn(n) +yB = x .+ 5randn(n) + +a = Points(x, yA, kind="circle") +setattr(a, label="a points") + +b = Points(x, yB) +setattr(b, label="b points") +style(b, kind="filled circle") + +s = Slope(1, (0,0), kind="dotted") +setattr(s, label="slope") + +l = Legend(.1, .9, {a,b,s}) + +add(p, s, a, b, l) +display(p) +```` + + +![](figures/winston_formats_3_1.png) +![](figures/winston_formats_3_2.png) + + diff --git a/test/documents/winston_formats_ref.rst b/test/documents/winston_formats_ref.rst new file mode 100644 index 0000000..fed5b57 --- /dev/null +++ b/test/documents/winston_formats_ref.rst @@ -0,0 +1,134 @@ + + +.. code-block:: julia + + julia> using Winston + + julia> t = linspace(0, 2*pi, 100) + 100-element Array{Float64,1}: + 0.0 + 0.0634665 + 0.126933 + 0.1904 + 0.253866 + 0.317333 + 0.380799 + 0.444266 + 0.507732 + 0.571199 + ⋮ + 5.77545 + 5.83892 + 5.90239 + 5.96585 + 6.02932 + 6.09279 + 6.15625 + 6.21972 + 6.28319 + + julia> plot(t, sinc(t)) + + + + +.. image:: figures/winston_formats_1_1.png + :width: 15 cm + + +.. code-block:: julia + + FramedPlot(...) + + + + + + +.. code-block:: julia + + julia> s = 1:10 + 1:10 + + julia> plot(s, "r*") + + + + +.. image:: figures/winston_formats_1_2.png + :width: 15 cm + + +.. code-block:: julia + + FramedPlot(...) + + + + + + + + + + +.. figure:: figures/winston_formats_random_1.png + :width: 15 cm + + Random walk. + + + + + +.. code-block:: julia + + x = linspace(0, 3pi, 100) + c = cos(x) + s = sin(x) + + p = FramedPlot( + title="title!", + xlabel="\\Sigma x^2_i", + ylabel="\\Theta_i") + + add(p, FillBetween(x, c, x, s)) + add(p, Curve(x, c, color="red")) + add(p, Curve(x, s, color="blue")) + display(p) + + p = FramedPlot( + aspect_ratio=1, + xrange=(0,100), + yrange=(0,100)) + + n = 21 + x = linspace(0, 100, n) + yA = 40 .+ 10randn(n) + yB = x .+ 5randn(n) + + a = Points(x, yA, kind="circle") + setattr(a, label="a points") + + b = Points(x, yB) + setattr(b, label="b points") + style(b, kind="filled circle") + + s = Slope(1, (0,0), kind="dotted") + setattr(s, label="slope") + + l = Legend(.1, .9, {a,b,s}) + + add(p, s, a, b, l) + display(p) + + + +.. image:: figures/winston_formats_3_1.png + :width: 15 cm + +.. image:: figures/winston_formats_3_2.png + :width: 15 cm + + + diff --git a/test/documents/winston_formats_ref.tex b/test/documents/winston_formats_ref.tex new file mode 100644 index 0000000..5f392ea --- /dev/null +++ b/test/documents/winston_formats_ref.tex @@ -0,0 +1,112 @@ + + +\begin{juliaterm} +julia> using Winston + +julia> t = linspace(0, 2*pi, 100) +100-element Array{Float64,1}: + 0.0 + 0.0634665 + 0.126933 + 0.1904 + 0.253866 + 0.317333 + 0.380799 + 0.444266 + 0.507732 + 0.571199 + ⋮ + 5.77545 + 5.83892 + 5.90239 + 5.96585 + 6.02932 + 6.09279 + 6.15625 + 6.21972 + 6.28319 + +julia> plot(t, sinc(t)) + +\end{juliacode} +\includegraphics[width=\linewidth]{figures/winston_formats_1_1.pdf} + +\begin{juliacode} +FramedPlot(...) + +\end{juliacode} + + +\begin{juliacode} +julia> s = 1:10 +1:10 + +julia> plot(s, "r*") + +\end{juliacode} +\includegraphics[width=\linewidth]{figures/winston_formats_1_2.pdf} + +\begin{juliacode} +FramedPlot(...) + +\end{juliacode} + + + + + + +\begin{figure}[htpb] +\center +\includegraphics[width=\linewidth]{figures/winston_formats_random_1.pdf} +\caption{Random walk.} +\label{fig:random} +\end{figure} + + + + +\begin{juliacode} +x = linspace(0, 3pi, 100) +c = cos(x) +s = sin(x) + +p = FramedPlot( + title="title!", + xlabel="\\Sigma x^2_i", + ylabel="\\Theta_i") + +add(p, FillBetween(x, c, x, s)) +add(p, Curve(x, c, color="red")) +add(p, Curve(x, s, color="blue")) +display(p) + +p = FramedPlot( + aspect_ratio=1, + xrange=(0,100), + yrange=(0,100)) + +n = 21 +x = linspace(0, 100, n) +yA = 40 .+ 10randn(n) +yB = x .+ 5randn(n) + +a = Points(x, yA, kind="circle") +setattr(a, label="a points") + +b = Points(x, yB) +setattr(b, label="b points") +style(b, kind="filled circle") + +s = Slope(1, (0,0), kind="dotted") +setattr(s, label="slope") + +l = Legend(.1, .9, {a,b,s}) + +add(p, s, a, b, l) +display(p) +\end{juliacode} +\includegraphics[width=\linewidth]{figures/winston_formats_3_1.pdf} +\includegraphics[width=\linewidth]{figures/winston_formats_3_2.pdf} + + diff --git a/test/documents/winston_formats_svg_ref.md b/test/documents/winston_formats_svg_ref.md new file mode 100644 index 0000000..4750cec --- /dev/null +++ b/test/documents/winston_formats_svg_ref.md @@ -0,0 +1,117 @@ + + +~~~~{.julia} +julia> using Winston + +julia> t = linspace(0, 2*pi, 100) +100-element Array{Float64,1}: + 0.0 + 0.0634665 + 0.126933 + 0.1904 + 0.253866 + 0.317333 + 0.380799 + 0.444266 + 0.507732 + 0.571199 + ⋮ + 5.77545 + 5.83892 + 5.90239 + 5.96585 + 6.02932 + 6.09279 + 6.15625 + 6.21972 + 6.28319 + +julia> plot(t, sinc(t)) + +~~~~~~~~~~~~~ + + +![](figures/winston_formats_1_1.svg) + +~~~~{.julia} +FramedPlot(...) + +~~~~~~~~~~~~~ + + + + +~~~~{.julia} +julia> s = 1:10 +1:10 + +julia> plot(s, "r*") + +~~~~~~~~~~~~~ + + +![](figures/winston_formats_1_2.svg) + +~~~~{.julia} +FramedPlot(...) + +~~~~~~~~~~~~~ + + + + + + + + +![Random walk.](figures/winston_formats_random_1.svg) + + + + +~~~~{.julia} +x = linspace(0, 3pi, 100) +c = cos(x) +s = sin(x) + +p = FramedPlot( + title="title!", + xlabel="\\Sigma x^2_i", + ylabel="\\Theta_i") + +add(p, FillBetween(x, c, x, s)) +add(p, Curve(x, c, color="red")) +add(p, Curve(x, s, color="blue")) +display(p) + +p = FramedPlot( + aspect_ratio=1, + xrange=(0,100), + yrange=(0,100)) + +n = 21 +x = linspace(0, 100, n) +yA = 40 .+ 10randn(n) +yB = x .+ 5randn(n) + +a = Points(x, yA, kind="circle") +setattr(a, label="a points") + +b = Points(x, yB) +setattr(b, label="b points") +style(b, kind="filled circle") + +s = Slope(1, (0,0), kind="dotted") +setattr(s, label="slope") + +l = Legend(.1, .9, {a,b,s}) + +add(p, s, a, b, l) +display(p) +~~~~~~~~~~~~~ + + +![](figures/winston_formats_3_1.svg) +![](figures/winston_formats_3_2.svg) + + diff --git a/test/runtests.jl b/test/runtests.jl index f074a4d..bf1454e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -33,5 +33,6 @@ if VERSION.minor == 3 ref = readall(open("documents/gadfly_markdown_test_ref.md")) @test result == ref - include("gadfly_formats.jl") + include("winston_formats.jl") + include("gadfly_formats.jl") end diff --git a/test/winston_formats.jl b/test/winston_formats.jl new file mode 100644 index 0000000..76b8968 --- /dev/null +++ b/test/winston_formats.jl @@ -0,0 +1,24 @@ +using Weave +using Base.Test + + +weave("documents/winston_formats.txt", plotlib="Winston", doctype="tex") +result = readall(open("documents/winston_formats.tex")) +ref = readall(open("documents/winston_formats_ref.tex")) +@test result == ref + + +weave("documents/winston_formats.txt", plotlib="Winston", doctype="github") +result = readall(open("documents/winston_formats.md")) +ref = readall(open("documents/winston_formats_ref.md")) +@test result == ref + +weave("documents/winston_formats.txt", plotlib="Winston", doctype="pandoc", fig_ext=".svg") +result = readall(open("documents/winston_formats.md")) +ref = readall(open("documents/winston_formats_svg_ref.md")) +@test result == ref + +weave("documents/winston_formats.txt", plotlib="Winston", doctype="rst") +result = readall(open("documents/winston_formats.rst")) +ref = readall(open("documents/winston_formats_ref.rst")) +@test result == ref