Skip to content

Commit

Permalink
CLN: don't use show as method name for writing html file.
Browse files Browse the repository at this point in the history
  • Loading branch information
sglyon committed Sep 6, 2018
1 parent 2650ab4 commit 43d3b76
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ----------------------- #
const js_default = Ref(:local)

function Base.show(io::IO, ::MIME"text/html", p::Plot, js::Symbol=js_default[])
function savehtml(io::IO, p::Plot, js::Symbol=js_default[])

if js == :local
script_txt = "<script src=\"$(_js_path)\"></script>"
Expand Down Expand Up @@ -32,6 +32,37 @@ function Base.show(io::IO, ::MIME"text/html", p::Plot, js::Symbol=js_default[])

end

function savehtml(p::Plot, fn::AbstractString, js::Symbol=js_default[])
open(fn, "w") do f
savehtml(f, p, js)
end
end

"""
savehtml(io::IO, p::Union{Plot,SyncPlot}, js::Symbol=js_default[])
savehtml(p::Union{Plot,SyncPlot}, fn::AbstractString, js::Symbol=js_default[])
Save plot to standalone html file suitable for including in a website or
opening in a browser
Can either be written to an arbitrary IO stream, or saved to a file noted with
a string `fn`.
The `js` argument can be one of
- `:local`: Reference the local plotly.js file included in this Julia package
Pros: small file size, offline viewing. Cons: Can't share with others or
move to different machine..
- `:remote`: Reference plotly.js from a CDN. Pros small file size, move to
other machine. Cons: need internet access to fetch from CDN
- `:embed`: Embed the entirety of your local copy of plotly.js in the
outputted file. Pros: offline viewing, move to other machine. Con: large
file size (adds about 2.7 MB)
The default is `:local`
"""
savehtml

# juno integration
function Base.show(io::IO, ::MIME"application/juno+plotpane", p::Plot)
content = """
Expand Down Expand Up @@ -69,6 +100,8 @@ for mime in [
end
end
PlotlyBase.savejson(sp::SyncPlot, fn::String) = PlotlyBase.savejson(sp.plot, fn)
savehtml(io::IO, p::SyncPlot, js::Symbol=js_default[]) = savehtml(io, p, js)
savehtml(p::SyncPlot, fn::AbstractString, js::Symbol=js_default[]) = savehtml(io, fn, js)

Base.show(io::IO, mm::MIME"text/html", p::SyncPlot) = show(io, mm, p.scope)

Expand Down

1 comment on commit 43d3b76

@rjkat
Copy link

@rjkat rjkat commented on 43d3b76 Oct 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is the reason behind this issue in ORCA

Please sign in to comment.