Make plotting library autodetection work in first chunk

pull/44/head
= 2016-05-02 23:15:24 +03:00
parent a760def865
commit 5e929b7ef6
1 changed files with 10 additions and 6 deletions

View File

@ -45,7 +45,7 @@ function Base.run(doc::WeaveDoc; doctype = :auto, plotlib=:auto,
#Reset plotting #Reset plotting
rcParams[:plotlib_set] = false rcParams[:plotlib_set] = false
#plotlib == :auto || init_plotting(plotlib) plotlib == :auto || init_plotting(plotlib)
report = Report(doc.cwd, doc.basename, doc.format.formatdict, mimetypes) report = Report(doc.cwd, doc.basename, doc.format.formatdict, mimetypes)
pushdisplay(report) pushdisplay(report)
@ -67,7 +67,7 @@ function Base.run(doc::WeaveDoc; doctype = :auto, plotlib=:auto,
options = merge(rcParams[:chunk_defaults], chunk.options) options = merge(rcParams[:chunk_defaults], chunk.options)
merge!(chunk.options, options) merge!(chunk.options, options)
rcParams[:plotlib_set] || detect_plotlib() #Try to autodetect plotting library
end end
restore = (cache ==:user && typeof(chunk) == CodeChunk && chunk.options[:cache]) restore = (cache ==:user && typeof(chunk) == CodeChunk && chunk.options[:cache])
@ -133,6 +133,7 @@ function run_code(chunk::CodeChunk, report::Report, SandBox::Module)
for (str_expr, expr) = expressions for (str_expr, expr) = expressions
reset_report(report) reset_report(report)
lastline = (result_no == N) lastline = (result_no == N)
rcParams[:plotlib_set] || detect_plotlib(chunk) #Try to autodetect plotting library
(obj, out) = capture_output(expr, SandBox, chunk.options[:term], (obj, out) = capture_output(expr, SandBox, chunk.options[:term],
rcParams[:plotlib], lastline) rcParams[:plotlib], lastline)
figures = report.figures #Captured figures figures = report.figures #Captured figures
@ -290,7 +291,6 @@ function init_plotting(plotlib)
rcParams[:plotlib] = "Gadfly" rcParams[:plotlib] = "Gadfly"
end end
end end
info(rcParams[:plotlib])
return true return true
end end
@ -409,9 +409,13 @@ function collect_results(chunk::CodeChunk, fmt::CollectResult)
return [chunk] return [chunk]
end end
function detect_plotlib() function detect_plotlib(chunk::CodeChunk)
info("Detecting plotting library") if isdefined(:Plots)
isdefined(:Plots) && init_plotting("Plots") && return init_plotting("Plots")
#Need to set size before plots are created
plots_set_size(chunk)
return
end
isdefined(:PyPlot) && init_plotting("PyPlot") && return isdefined(:PyPlot) && init_plotting("PyPlot") && return
isdefined(:Gadfly) && init_plotting("Gadfly") && return isdefined(:Gadfly) && init_plotting("Gadfly") && return
isdefined(:Winston) && init_plotting("Winston") && return isdefined(:Winston) && init_plotting("Winston") && return