mirror of https://github.com/mpastell/Weave.jl
Fixes to Winston support
parent
2b83abd264
commit
c4ab398ac3
11
README.md
11
README.md
|
@ -1,6 +1,7 @@
|
||||||
# JuliaReport
|
# JuliaReport
|
||||||
|
|
||||||
[![Build Status](https://travis-ci.org/mpastell/JuliaReport.jl.svg?branch=master)](https://travis-ci.org/mpastell/JuliaReport.jl)
|
[![Build Status](https://travis-ci.org/mpastell/JuliaReport.jl.svg?branch=master)](https://travis-ci.org/mpastell/JuliaReport.jl)
|
||||||
|
|
||||||
JuliaReport is a scientific report generator/literate programming tool
|
JuliaReport is a scientific report generator/literate programming tool
|
||||||
for Julia. It resembles [Pweave](http://mpastell.com/pweave) and, Knitr
|
for Julia. It resembles [Pweave](http://mpastell.com/pweave) and, Knitr
|
||||||
and Sweave.
|
and Sweave.
|
||||||
|
@ -10,7 +11,7 @@ and Sweave.
|
||||||
|
|
||||||
* Noweb syntax for documents.
|
* Noweb syntax for documents.
|
||||||
* Execute code as terminal or "script" chunks.
|
* Execute code as terminal or "script" chunks.
|
||||||
* Capture PyPlot or Winston figures.
|
* Capture PyPlot, Gadfly or Winston figures.
|
||||||
* Supports latex and pandoc markdown output
|
* Supports latex and pandoc markdown output
|
||||||
|
|
||||||
**Not implemented**
|
**Not implemented**
|
||||||
|
@ -33,11 +34,15 @@ using ";" and need to be valid Julia expressions. e.g.
|
||||||
Run from julia:
|
Run from julia:
|
||||||
|
|
||||||
using JuliaReport
|
using JuliaReport
|
||||||
weave(Pkg.dir("JuliaReport","examples","julia_sample.mdw"))
|
weave(Pkg.dir("JuliaReport","examples","julia_sample.mdw")
|
||||||
|
|
||||||
Or using Winston for plots (Julia 0.3 only):
|
Using Winston for plots (Julia 0.3 only):
|
||||||
|
|
||||||
weave(Pkg.dir("JuliaReport","examples","winston_sample.mdw"),
|
weave(Pkg.dir("JuliaReport","examples","winston_sample.mdw"),
|
||||||
plotlib="Winston", doctype="pandoc")
|
plotlib="Winston", doctype="pandoc")
|
||||||
|
|
||||||
|
Using Gadfly (Julia 0.3 only):
|
||||||
|
|
||||||
|
weave(Pkg.dir("JuliaReport","examples","gadfly_sample.mdw"), plotlib="Gadfly")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,18 +25,19 @@ y = [2, 4 ,8]
|
||||||
|
|
||||||
The figures and code can be included in the output.
|
The figures and code can be included in the output.
|
||||||
|
|
||||||
<<>>=
|
<<term=true>>=
|
||||||
using Winston
|
using Winston
|
||||||
t = linspace(0, 2*pi, 100)
|
t = linspace(0, 2*pi, 100)
|
||||||
plot(t, sinc(t))
|
p = plot(t, sinc(t))
|
||||||
xlabel("x")
|
|
||||||
ylabel("sinc(x)")
|
|
||||||
@
|
@
|
||||||
|
|
||||||
You can also include a plot with caption and hide the code:
|
You can also include a plot with caption and hide the code:
|
||||||
|
|
||||||
<<echo=false; caption="Random walk."; label="random">>=
|
<<echo=false; caption="Random walk."; label="random">>=
|
||||||
plot(cumsum(randn(1000, 1)))
|
p = plot(cumsum(randn(1000, 1)))
|
||||||
|
xlabel("x")
|
||||||
|
ylabel("sinc(x)")
|
||||||
|
display(p)
|
||||||
@
|
@
|
||||||
|
|
||||||
<<>>=
|
<<>>=
|
||||||
|
@ -44,7 +45,6 @@ x = linspace(0, 3pi, 100)
|
||||||
c = cos(x)
|
c = cos(x)
|
||||||
s = sin(x)
|
s = sin(x)
|
||||||
|
|
||||||
figure()
|
|
||||||
p = FramedPlot(
|
p = FramedPlot(
|
||||||
title="title!",
|
title="title!",
|
||||||
xlabel="\\Sigma x^2_i",
|
xlabel="\\Sigma x^2_i",
|
||||||
|
@ -53,4 +53,5 @@ p = FramedPlot(
|
||||||
add(p, FillBetween(x, c, x, s))
|
add(p, FillBetween(x, c, x, s))
|
||||||
add(p, Curve(x, c, color="red"))
|
add(p, Curve(x, c, color="red"))
|
||||||
add(p, Curve(x, s, color="blue"))
|
add(p, Curve(x, s, color="blue"))
|
||||||
|
display(p)
|
||||||
@
|
@
|
||||||
|
|
Binary file not shown.
|
@ -61,7 +61,7 @@ function weave(source ; doctype = "pandoc", plotlib="PyPlot", informat="noweb",
|
||||||
report.basename = basename
|
report.basename = basename
|
||||||
report.figdir = figdir
|
report.figdir = figdir
|
||||||
report.formatdict = formatdict
|
report.formatdict = formatdict
|
||||||
pushdisplay(report)
|
|
||||||
|
|
||||||
if plotlib == nothing
|
if plotlib == nothing
|
||||||
rcParams[:chunk][:defaultoptions][:fig] = false
|
rcParams[:chunk][:defaultoptions][:fig] = false
|
||||||
|
@ -74,13 +74,12 @@ function weave(source ; doctype = "pandoc", plotlib="PyPlot", informat="noweb",
|
||||||
eval(Expr(:using, :PyPlot))
|
eval(Expr(:using, :PyPlot))
|
||||||
rcParams[:plotlib] = "PyPlot"
|
rcParams[:plotlib] = "PyPlot"
|
||||||
elseif l_plotlib == "gadfly"
|
elseif l_plotlib == "gadfly"
|
||||||
println("GadFly")
|
|
||||||
eval(parse("""include(Pkg.dir("JuliaReport","src","gadfly.jl"))"""))
|
eval(parse("""include(Pkg.dir("JuliaReport","src","gadfly.jl"))"""))
|
||||||
rcParams[:plotlib] = "Gadfly"
|
rcParams[:plotlib] = "Gadfly"
|
||||||
#pushdisplay(doc)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
pushdisplay(report)
|
||||||
parsed = read_noweb(source)
|
parsed = read_noweb(source)
|
||||||
executed = run(parsed)
|
executed = run(parsed)
|
||||||
popdisplay(report)
|
popdisplay(report)
|
||||||
|
@ -98,24 +97,32 @@ end
|
||||||
|
|
||||||
function run_block(code_str)
|
function run_block(code_str)
|
||||||
oldSTDOUT = STDOUT
|
oldSTDOUT = STDOUT
|
||||||
|
result = ""
|
||||||
|
|
||||||
|
rw, wr = redirect_stdout()
|
||||||
#If there is nothing to read code will hang
|
#If there is nothing to read code will hang
|
||||||
println()
|
println()
|
||||||
rw, wr = redirect_stdout()
|
|
||||||
#include_string(code_str)
|
|
||||||
|
|
||||||
n = length(code_str)
|
|
||||||
pos = 2 #The first character is extra line end
|
try
|
||||||
while pos < n
|
n = length(code_str)
|
||||||
oldpos = pos
|
pos = 2 #The first character is extra line end
|
||||||
code, pos = parse(code_str, pos)
|
while pos < n
|
||||||
s = eval(ReportSandBox, code)
|
oldpos = pos
|
||||||
s != nothing && display(s)
|
code, pos = parse(code_str, pos)
|
||||||
|
s = eval(ReportSandBox, code)
|
||||||
|
if rcParams[:plotlib] == "Gadfly"
|
||||||
|
s != nothing && display(s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
finally
|
||||||
|
|
||||||
|
redirect_stdout(oldSTDOUT)
|
||||||
|
close(wr)
|
||||||
|
result = readall(rw)
|
||||||
|
close(rw)
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_stdout(oldSTDOUT)
|
|
||||||
close(wr)
|
|
||||||
result = readall(rw)
|
|
||||||
close(rw)
|
|
||||||
return string("\n", result)
|
return string("\n", result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ function display(report::Report, m::MIME"image/png", data)
|
||||||
chunk[:figure] = [rel_name]
|
chunk[:figure] = [rel_name]
|
||||||
report.cur_result *= "\n" * report.formatdict[:codeend]
|
report.cur_result *= "\n" * report.formatdict[:codeend]
|
||||||
report.cur_result *= formatfigures(chunk, docformat)
|
report.cur_result *= formatfigures(chunk, docformat)
|
||||||
report.cur_result *= "\n\n" * report.formatdict[:codestart]
|
report.cur_result *= "\n\n" * report.formatdict[:codestart] * "\n"
|
||||||
chunk[:figure] = String[]
|
chunk[:figure] = String[]
|
||||||
else
|
else
|
||||||
push!(report.figures, rel_name)
|
push!(report.figures, rel_name)
|
||||||
|
|
Loading…
Reference in New Issue