Skip to content

Commit

Permalink
Merge pull request #146 from odow/fix-visualize
Browse files Browse the repository at this point in the history
Fix plotting on *NIX machines
  • Loading branch information
odow authored Jun 17, 2018
2 parents ab81770 + 990ac40 commit 5c1d317
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/visualizer/visualize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

const ASSET_DIR = dirname(@__FILE__)

function launch_file(html_string, assets, outputfile=replace(tempname(), ".tmp", ".html"))
function launch_file(html_string, assets, outputfile)
for asset in assets
cp(joinpath(ASSET_DIR, asset), joinpath(dirname(outputfile), asset), remove_destination=true)
end
Expand Down
17 changes: 9 additions & 8 deletions src/visualizer/visualize_simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,22 @@ function addplot!(p::SimulationPlot, i::AbstractVector{Int}, t::AbstractVector{I
end
push!(p.data, plot_dict)
end

"""
show(p::SimulationPlot)
# Description
Launch a browser and render the SimulationPlot plot `p`.
"""
function Base.show(p::SimulationPlot)
html = prephtml(p)
launch_file(html, SIMULATION_ASSETS)
end
Base.show(p::SimulationPlot) = Base.show(joinpath(tempdir(), string(randstring(), ".html")), p)

"""
show(filename::String, p::SimulationPlot)
Launch a browser and render the SimulationPlot plot `p`. Save the resulting
HTML file to `filename`.
"""
function Base.show(filename::String, p::SimulationPlot)
html = prephtml(p)
launch_file(html, SIMULATION_ASSETS, filename)
launch_file(prephtml(p), SIMULATION_ASSETS, filename)
end

prephtml(p::SimulationPlot) = prephtml(SIMULATION_HTML_FILE, ("<!--DATA-->", json(p.data)))
4 changes: 2 additions & 2 deletions src/visualizer/visualize_value_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ At most two states can be vectors.
SDDP.plotvaluefunction(m, 2, 1, 0.0:0.1:1.0, 0.5, 0.0:0.1:1.0; label1="State 1", label2="State 3")
"""
function plotvaluefunction(m::SDDPModel, stage::Int, markovstate::Int, states::Union{Float64, AbstractVector{Float64}}...; label1="State 1", label2="State 2")
html = prepvaluefunctionplot(m, stage, markovstate, label1, label2, states...)
launch_file(html, PLOTLY_ASSETS)
filename = joinpath(tempdir(), string(randstring(), ".html"))
plotvaluefunction(filename, m, stage, markovstate, states...; label1=label1, label2=label2)
end

function plotvaluefunction(filename::String, m::SDDPModel, stage::Int, markovstate::Int, states::Union{Float64, AbstractVector{Float64}}...; label1="State 1", label2="State 2")
Expand Down

0 comments on commit 5c1d317

Please sign in to comment.