Merge 85068d82d9ff9502fb79e8d9deee883a43b6ab62 into 8b2a83838894dc6d7f903a75e209362137e4d237
This commit is contained in:
commit
af7f02788a
@ -85,11 +85,24 @@ end
|
|||||||
|
|
||||||
################# This is the important method to implement!!! #################
|
################# This is the important method to implement!!! #################
|
||||||
function _make_pgf_plot(plt::Plot{PGFPlotsBackend})
|
function _make_pgf_plot(plt::Plot{PGFPlotsBackend})
|
||||||
|
line_type = plt.seriesargs[1][:linetype]
|
||||||
|
if line_type == :path
|
||||||
|
plt.o = PGFPlots.Linear(plt.seriesargs[1][:x], plt.seriesargs[1][:y])
|
||||||
|
elseif line_type == :scatter
|
||||||
|
plt.o = PGFPlots.Scatter(plt.seriesargs[1][:x], plt.seriesargs[1][:y])
|
||||||
|
elseif line_type == :steppost
|
||||||
|
plt.o = PGFPlots.Linear(plt.seriesargs[1][:x], plt.seriesargs[1][:y], style="const plot")
|
||||||
|
elseif line_type == :hist
|
||||||
|
plt_hist = hist(plt.seriesargs[1][:y])
|
||||||
|
plt.o = PGFPlots.Linear(plt_hist[1][1:end-1], plt_hist[2], style="ybar,fill=green", mark="none")
|
||||||
|
elseif line_type == :bar
|
||||||
|
plt.o = PGFPlots.Linear(plt.seriesargs[1][:x], plt.seriesargs[1][:y], style="ybar,fill=green", mark="none")
|
||||||
|
end
|
||||||
# TODO: convert plt.plotargs and plt.seriesargs into PGFPlots calls
|
# TODO: convert plt.plotargs and plt.seriesargs into PGFPlots calls
|
||||||
# TODO: return the PGFPlots object
|
# TODO: return the PGFPlots object
|
||||||
end
|
end
|
||||||
|
|
||||||
function Base.writemime(io::IO, mime::MIME"image/png", plt::AbstractPlot{PGFPlotsBackend})
|
function Base.writemime(io::IO, mime::MIME"image/svg+xml", plt::AbstractPlot{PGFPlotsBackend})
|
||||||
plt.o = _make_pgf_plot(plt)
|
plt.o = _make_pgf_plot(plt)
|
||||||
writemime(io, mime, plt.o)
|
writemime(io, mime, plt.o)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -8,25 +8,34 @@ function _initialize_backend(::PlotlyBackend; kw...)
|
|||||||
|
|
||||||
############################
|
############################
|
||||||
# borrowed from https://github.com/spencerlyon2/Plotlyjs.jl/blob/master/src/display.jl
|
# borrowed from https://github.com/spencerlyon2/Plotlyjs.jl/blob/master/src/display.jl
|
||||||
_js_path = joinpath(Pkg.dir("Plots"), "deps", "plotly-latest.min.js")
|
_js_path = Pkg.dir("Plots", "deps", "plotly-latest.min.js")
|
||||||
|
|
||||||
|
_js_code = open(readall, _js_path, "r")
|
||||||
|
|
||||||
|
_js_script = """
|
||||||
|
<script type="text/javascript">
|
||||||
|
require=requirejs=define=undefined;
|
||||||
|
</script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(_js_code)
|
||||||
|
</script>
|
||||||
|
"""
|
||||||
|
|
||||||
# if we're in IJulia call setupnotebook to load js and css
|
# if we're in IJulia call setupnotebook to load js and css
|
||||||
if isijulia()
|
if isijulia()
|
||||||
# the first script is some hack I needed to do in order for the notebook
|
# the first script is some hack I needed to do in order for the notebook
|
||||||
# to not complain about Plotly being undefined
|
# to not complain about Plotly being undefined
|
||||||
display("text/html", """
|
display("text/html", _js_script)
|
||||||
<script type="text/javascript">
|
|
||||||
require=requirejs=define=undefined;
|
|
||||||
</script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
$(open(readall, _js_path, "r"))
|
|
||||||
</script>
|
|
||||||
""")
|
|
||||||
# display("text/html", "<p>Plotly javascript loaded.</p>")
|
# display("text/html", "<p>Plotly javascript loaded.</p>")
|
||||||
end
|
end
|
||||||
# end borrowing (thanks :)
|
# end borrowing (thanks :)
|
||||||
###########################
|
###########################
|
||||||
|
|
||||||
|
# if isatom()
|
||||||
|
# import Atom
|
||||||
|
# Atom.@msg evaljs(_js_code)
|
||||||
|
# end
|
||||||
|
|
||||||
end
|
end
|
||||||
# TODO: other initialization
|
# TODO: other initialization
|
||||||
end
|
end
|
||||||
@ -436,15 +445,23 @@ function html_body(plt::Plot{PlotlyBackend}, style = nothing)
|
|||||||
style = "width:$(w)px;height:$(h)px;"
|
style = "width:$(w)px;height:$(h)px;"
|
||||||
end
|
end
|
||||||
uuid = Base.Random.uuid4()
|
uuid = Base.Random.uuid4()
|
||||||
"""
|
html = """
|
||||||
<div id=\"$(uuid)\" style=\"$(style)\"></div>
|
<div id=\"$(uuid)\" style=\"$(style)\"></div>
|
||||||
<script>
|
<script>
|
||||||
PLOT = document.getElementById('$(uuid)');
|
PLOT = document.getElementById('$(uuid)');
|
||||||
Plotly.plot(PLOT, $(get_series_json(plt)), $(get_plot_json(plt)));
|
Plotly.plot(PLOT, $(get_series_json(plt)), $(get_plot_json(plt)));
|
||||||
</script>
|
</script>
|
||||||
"""
|
"""
|
||||||
|
# @show html
|
||||||
|
html
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function js_body(plt::Plot{PlotlyBackend}, uuid)
|
||||||
|
js = """
|
||||||
|
PLOT = document.getElementById('$(uuid)');
|
||||||
|
Plotly.plot(PLOT, $(get_series_json(plt)), $(get_plot_json(plt)));
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function html_body(subplt::Subplot{PlotlyBackend})
|
function html_body(subplt::Subplot{PlotlyBackend})
|
||||||
@ -480,6 +497,7 @@ end
|
|||||||
|
|
||||||
function Base.writemime(io::IO, ::MIME"text/html", plt::AbstractPlot{PlotlyBackend})
|
function Base.writemime(io::IO, ::MIME"text/html", plt::AbstractPlot{PlotlyBackend})
|
||||||
write(io, html_head(plt) * html_body(plt))
|
write(io, html_head(plt) * html_body(plt))
|
||||||
|
# write(io, html_body(plt))
|
||||||
end
|
end
|
||||||
|
|
||||||
function Base.display(::PlotsDisplay, plt::AbstractPlot{PlotlyBackend})
|
function Base.display(::PlotsDisplay, plt::AbstractPlot{PlotlyBackend})
|
||||||
|
|||||||
@ -44,6 +44,7 @@ function _add_series(::PlotlyJSBackend, plt::Plot; kw...)
|
|||||||
typ = pop!(pdict, :type)
|
typ = pop!(pdict, :type)
|
||||||
gt = PlotlyJS.GenericTrace(typ; pdict...)
|
gt = PlotlyJS.GenericTrace(typ; pdict...)
|
||||||
PlotlyJS.addtraces!(syncplot, gt)
|
PlotlyJS.addtraces!(syncplot, gt)
|
||||||
|
# PlotlyJS.addtraces!(syncplot.plot, gt)
|
||||||
|
|
||||||
push!(plt.seriesargs, d)
|
push!(plt.seriesargs, d)
|
||||||
plt
|
plt
|
||||||
@ -73,6 +74,7 @@ function _update_plot(plt::Plot{PlotlyJSBackend}, d::Dict)
|
|||||||
syncplot = plt.o
|
syncplot = plt.o
|
||||||
w,h = d[:size]
|
w,h = d[:size]
|
||||||
PlotlyJS.relayout!(syncplot, pdict, width = w, height = h)
|
PlotlyJS.relayout!(syncplot, pdict, width = w, height = h)
|
||||||
|
# PlotlyJS.relayout!(syncplot.plot, pdict, width = w, height = h)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -125,4 +127,3 @@ end
|
|||||||
function Base.display(::PlotsDisplay, plt::Subplot{PlotlyJSBackend})
|
function Base.display(::PlotsDisplay, plt::Subplot{PlotlyJSBackend})
|
||||||
error()
|
error()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -723,7 +723,7 @@ supportedArgs(::PGFPlotsBackend) = [
|
|||||||
# :legend,
|
# :legend,
|
||||||
# :linecolor,
|
# :linecolor,
|
||||||
# :linestyle,
|
# :linestyle,
|
||||||
# :linetype,
|
:linetype,
|
||||||
# :linewidth,
|
# :linewidth,
|
||||||
# :linealpha,
|
# :linealpha,
|
||||||
# :markershape,
|
# :markershape,
|
||||||
@ -743,11 +743,11 @@ supportedArgs(::PGFPlotsBackend) = [
|
|||||||
# :size,
|
# :size,
|
||||||
# :title,
|
# :title,
|
||||||
# :windowtitle,
|
# :windowtitle,
|
||||||
# :x,
|
:x,
|
||||||
# :xlabel,
|
# :xlabel,
|
||||||
# :xlims,
|
# :xlims,
|
||||||
# :xticks,
|
# :xticks,
|
||||||
# :y,
|
:y,
|
||||||
# :ylabel,
|
# :ylabel,
|
||||||
# :ylims,
|
# :ylims,
|
||||||
# :yrightlabel,
|
# :yrightlabel,
|
||||||
@ -765,9 +765,8 @@ supportedArgs(::PGFPlotsBackend) = [
|
|||||||
# :levels,
|
# :levels,
|
||||||
]
|
]
|
||||||
supportedAxes(::PGFPlotsBackend) = [:auto, :left]
|
supportedAxes(::PGFPlotsBackend) = [:auto, :left]
|
||||||
supportedTypes(::PGFPlotsBackend) = [:contour] #, :path, :scatter ,:steppre, :steppost, :sticks, :hist2d, :hexbin, :hist, :bar, :hline, :vline, :contour]
|
supportedTypes(::PGFPlotsBackend) = [:path, :scatter, :line, :steppost, :hist, :bar] #, :steppre, :sticks, :hist2d, :hexbin, :bar, :hline, :vline, :contour]
|
||||||
supportedStyles(::PGFPlotsBackend) = [:auto, :solid] #, :dash, :dot, :dashdot, :dashdotdot]
|
supportedStyles(::PGFPlotsBackend) = [:auto, :solid] #, :dash, :dot, :dashdot, :dashdotdot]
|
||||||
supportedMarkers(::PGFPlotsBackend) = [:none, :auto, :ellipse] #, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape)
|
supportedMarkers(::PGFPlotsBackend) = [:none, :auto, :ellipse] #, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape)
|
||||||
supportedScales(::PGFPlotsBackend) = [:identity] #, :log, :log2, :log10, :asinh, :sqrt]
|
supportedScales(::PGFPlotsBackend) = [:identity] #, :log, :log2, :log10, :asinh, :sqrt]
|
||||||
subplotSupported(::PGFPlotsBackend) = false
|
subplotSupported(::PGFPlotsBackend) = false
|
||||||
|
|
||||||
|
|||||||
@ -124,18 +124,23 @@ end
|
|||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
function setup_atom()
|
function setup_atom()
|
||||||
# @require Atom begin
|
@require Atom begin
|
||||||
# @eval begin
|
import Atom, Media
|
||||||
# import Atom
|
|
||||||
#
|
# connects the render function
|
||||||
|
Media.media{T <: Union{GadflyBackend,ImmerseBackend,PyPlotBackend,GRBackend}}(Plot{T}, Media.Plot)
|
||||||
|
|
||||||
# Atom.displaysize(::AbstractPlot) = (535, 379)
|
# Atom.displaysize(::AbstractPlot) = (535, 379)
|
||||||
# Atom.displaytitle(::AbstractPlot) = "Plots.jl"
|
# Atom.displaytitle(plt::AbstractPlot) = "Plots.jl (backend: $(backend(plt)))"
|
||||||
#
|
|
||||||
# Atom.@render Atom.PlotPane p::Plot begin
|
# this is like "display"... sends an html div with the plot to the PlotPane
|
||||||
# x, y = Atom.@rpc Atom.plotsize()
|
function Media.render(pane::Atom.PlotPane, plt::Plot)
|
||||||
# plot!(p, size=(x,y)) # changes the size of the Plots.Plot
|
Media.render(pane, Atom.div(Atom.d(), Atom.HTML(stringmime(MIME("text/html"), plt))))
|
||||||
# Atom.div(Dict(:style=>"background: white"), Atom.HTML(stringmime("text/html", p)))
|
end
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
# function Media.render(pane::Atom.PlotPane, plt::Plot{PlotlyBackend})
|
||||||
|
# html = Media.render(pane, Atom.div(Atom.d(), Atom.HTML(stringmime(MIME("text/html"), plt))))
|
||||||
# end
|
# end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|||||||
@ -198,6 +198,7 @@ function fakedata(sz...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
isijulia() = isdefined(Main, :IJulia) && Main.IJulia.inited
|
isijulia() = isdefined(Main, :IJulia) && Main.IJulia.inited
|
||||||
|
isatom() = isdefined(Main, :Atom) && Atom.isconnected()
|
||||||
|
|
||||||
istuple(::Tuple) = true
|
istuple(::Tuple) = true
|
||||||
istuple(::Any) = false
|
istuple(::Any) = false
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user