Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/display_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mutable struct Report <: AbstractDisplay
basename::String
format::WeaveFormat
rich_output::String
fignum::Int
chunk_fignums::Dict{Int,Int}
figures::Vector{String}
cur_chunk::Union{Nothing,CodeChunk}
mimetypes::Vector{String}
Expand All @@ -15,7 +15,7 @@ mutable struct Report <: AbstractDisplay
end

Report(cwd, basename, format, mimetypes) =
Report(cwd, basename, format, "", 1, String[], nothing, mimetypes, true, "")
Report(cwd, basename, format, "", Dict(0 => 1), String[], nothing, mimetypes, true, "")

# Default mimetypes in order, can be overridden for some inside `run method` formats
const default_mime_types = ["image/svg+xml", "image/png", "text/html", "text/plain"]
Expand Down Expand Up @@ -127,7 +127,11 @@ function add_figure(report::Report, data, m, ext)
end
end

push!(report.figures, rel_name)
report.fignum += 1
register_chunk_fig!(report, chunk, rel_name)
return full_name
end

function register_chunk_fig!(report::Report, chunk::CodeChunk, rel_name::AbstractString)
push!(report.figures, rel_name)
report.chunk_fignums[chunk.number] = get(report.chunk_fignums, chunk.number, 0) + 1
end
3 changes: 1 addition & 2 deletions src/gadfly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ function Base.display(report::Weave.Report, m::MIME"image/svg+xml", p::Gadfly.Pl

full_name, rel_name = Weave.get_figname(report, chunk, ext = format)

push!(report.figures, rel_name)
report.fignum += 1
Weave.register_chunk_fig!(report, chunk, rel_name)

if format == ".svg"
Gadfly.draw(Gadfly.SVG(full_name, w, h), p)
Expand Down
3 changes: 1 addition & 2 deletions src/plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ function add_plots_figure(report::Weave.Report, plot::Plots.Plot, ext)
full_name, rel_name = Weave.get_figname(report, chunk, ext = ext)

Plots.savefig(plot, full_name)
push!(report.figures, rel_name)
report.fignum += 1
Weave.register_chunk_fig!(report, chunk, rel_name)
return full_name
end

Expand Down
3 changes: 1 addition & 2 deletions src/run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ function eval_chunk(doc::WeaveDoc, chunk::CodeChunk, report::Report, mod::Module

execute_prehooks!(chunk)

report.fignum = 1
report.cur_chunk = chunk

if hasproperty(report.format, :out_width) && isnothing(chunk.options[:out_width])
Expand Down Expand Up @@ -325,7 +324,7 @@ end

function get_figname(report::Report, chunk; fignum = nothing, ext = nothing)
isnothing(ext) && (ext = chunk.options[:fig_ext])
isnothing(fignum) && (fignum = report.fignum)
isnothing(fignum) && (fignum = get(report.chunk_fignums, chunk.number, 1))

chunkid = isnothing(chunk.options[:label]) ? chunk.number : chunk.options[:label]
basename = string(report.basename, '_', chunkid, '_', fignum, ext)
Expand Down