working on plotly
This commit is contained in:
parent
92ec093ed9
commit
b0c9dd44e9
@ -1,12 +1,12 @@
|
||||
|
||||
# https://github.com/bokeh/Bokeh.jl
|
||||
|
||||
make255(x) = round(Int, 255 * x)
|
||||
# make255(x) = round(Int, 255 * x)
|
||||
|
||||
function bokehcolor(c::Colorant)
|
||||
@sprintf("rgba(%d, %d, %d, %1.3f)", [make255(f(c)) for f in [red,green,blue]]..., alpha(c))
|
||||
end
|
||||
bokehcolor(cs::ColorScheme) = bokehcolor(getColor(cs))
|
||||
# function bokehcolor(c::Colorant)
|
||||
# @sprintf("rgba(%d, %d, %d, %1.3f)", [make255(f(c)) for f in [red,green,blue]]..., alpha(c))
|
||||
# end
|
||||
# bokehcolor(cs::ColorScheme) = bokehcolor(getColor(cs))
|
||||
|
||||
|
||||
const _glyphtypes = Dict(
|
||||
@ -88,9 +88,9 @@ function _add_series(::BokehPackage, plt::Plot; kw...)
|
||||
|
||||
glyph = Bokeh.Bokehjs.Glyph(
|
||||
glyphtype = bokeh_glyph_type(d),
|
||||
linecolor = bokehcolor(d[:linecolor]), # shape's stroke or line color
|
||||
linecolor = webcolor(d[:linecolor]), # shape's stroke or line color
|
||||
linewidth = d[:linewidth], # shape's stroke width or line width
|
||||
fillcolor = bokehcolor(d[:markercolor]),
|
||||
fillcolor = webcolor(d[:markercolor]),
|
||||
size = ceil(Int, d[:markersize] * 2.5), # magic number 2.5 to keep in same scale as other backends
|
||||
dash = get_stroke_vector(d[:linestyle])
|
||||
)
|
||||
|
||||
@ -68,13 +68,7 @@ end
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
|
||||
# _plotDefaults[:title] = ""
|
||||
# _plotDefaults[:xlabel] = ""
|
||||
# _plotDefaults[:ylabel] = ""
|
||||
# _plotDefaults[:yrightlabel] = ""
|
||||
# _plotDefaults[:legend] = true
|
||||
# _plotDefaults[:background_color] = colorant"white"
|
||||
# _plotDefaults[:foreground_color] = :auto
|
||||
# _plotDefaults[:xlims] = :auto
|
||||
# _plotDefaults[:ylims] = :auto
|
||||
# _plotDefaults[:xticks] = :auto
|
||||
@ -83,36 +77,71 @@ end
|
||||
# _plotDefaults[:yscale] = :identity
|
||||
# _plotDefaults[:xflip] = false
|
||||
# _plotDefaults[:yflip] = false
|
||||
# _plotDefaults[:size] = (600,400)
|
||||
# _plotDefaults[:pos] = (0,0)
|
||||
# _plotDefaults[:windowtitle] = "Plots.jl"
|
||||
# _plotDefaults[:show] = false
|
||||
# _plotDefaults[:layout] = nothing
|
||||
# _plotDefaults[:n] = -1
|
||||
# _plotDefaults[:nr] = -1
|
||||
# _plotDefaults[:nc] = -1
|
||||
# _plotDefaults[:color_palette] = :auto
|
||||
# _plotDefaults[:link] = false
|
||||
# _plotDefaults[:linkx] = false
|
||||
# _plotDefaults[:linky] = false
|
||||
# _plotDefaults[:linkfunc] = nothing
|
||||
# _plotDefaults[:tickfont] = font(8)
|
||||
# _plotDefaults[:guidefont] = font(11)
|
||||
# _plotDefaults[:legendfont] = font(8)
|
||||
# _plotDefaults[:grid] = true
|
||||
|
||||
function plotlyfont(font::Font)
|
||||
Dict(
|
||||
:family => font.family,
|
||||
:size => font.pointsize,
|
||||
:color => font.color,
|
||||
)
|
||||
end
|
||||
|
||||
function plotlyscale(scale::Symbol)
|
||||
if scale == :log
|
||||
"log"
|
||||
else
|
||||
"-"
|
||||
end
|
||||
end
|
||||
|
||||
function get_plot_html(plt::Plot{PlotlyPackage})
|
||||
d = plt.plotargs
|
||||
d_out = Dict()
|
||||
|
||||
bgcolor = webcolor(d[:background_color])
|
||||
fgcolor = webcolor(d[:foreground_color])
|
||||
|
||||
# TODO: set the fields for the plot
|
||||
d_out[:title] = d[:title]
|
||||
d_out[:width], d_out[:height] = d[:size]
|
||||
# d_out[:margin] = 0
|
||||
d_out[:showlegend] = d[:legend]
|
||||
d_out[:paper_bgcolor] = d_out[:plot_bgcolor] = plotlycolor(d[:background_color])
|
||||
d_out[:titlefont] = plotlyfont(d[:guidefont])
|
||||
d_out[:width], d_out[:height] = d[:size]
|
||||
d_out[:margin] = Dict(:l=>20, :b=>20, :r=>10, :t=>10)
|
||||
d_out[:paper_bgcolor] = bgcolor
|
||||
d_out[:plot_bgcolor] = bgcolor
|
||||
|
||||
# TODO: x/y axis tick values/labels
|
||||
# TODO: x/y axis range
|
||||
|
||||
d_out[:xaxis] = Dict(
|
||||
:title => d[:xlabel],
|
||||
:titlefont => plotlyfont(d[:guidefont]),
|
||||
:type => plotlyscale(d[:xscale]),
|
||||
:tickfont => plotlyfont(d[:tickfont]),
|
||||
:tickcolor => fgcolor,
|
||||
:linecolor => fgcolor,
|
||||
:showgrid => d[:grid],
|
||||
)
|
||||
d_out[:yaxis] = Dict(
|
||||
:title => d[:ylabel],
|
||||
:titlefont => plotlyfont(d[:guidefont]),
|
||||
:type => plotlyscale(d[:yscale]),
|
||||
:tickfont => plotlyfont(d[:tickfont]),
|
||||
:tickcolor => fgcolor,
|
||||
:linecolor => fgcolor,
|
||||
:showgrid => d[:grid],
|
||||
)
|
||||
|
||||
d_out[:showlegend] = d[:legend]
|
||||
if d[:legend]
|
||||
d_out[:legend] = Dict(
|
||||
:bgcolor => bgcolor,
|
||||
:bordercolor => fgcolor,
|
||||
:font => plotlyfont(d[:legendfont]),
|
||||
:yanchor => "middle",
|
||||
)
|
||||
end
|
||||
|
||||
# TODO: d_out[:annotations]
|
||||
|
||||
JSON.json(d_out)
|
||||
end
|
||||
@ -167,14 +196,6 @@ end
|
||||
|
||||
function html_body(plt::Plot{PlotlyPackage})
|
||||
w, h = plt.plotargs[:size]
|
||||
|
||||
# # TODO: get the real ones
|
||||
# seriesargs = [Dict(:x => collect(1:5), :y => rand(5))]
|
||||
# plotargs = Dict(:margin => 0)
|
||||
|
||||
# series_html = JSON.json(seriesargs)
|
||||
# plot_html = JSON.json(plotargs)
|
||||
|
||||
"""
|
||||
<div id=\"myplot\" style=\"width:$(w)px;height:$(h)px;\"></div>
|
||||
<script>
|
||||
|
||||
@ -19,8 +19,7 @@ using JSON
|
||||
# """
|
||||
|
||||
|
||||
function standalone_html(plt::PlottingObject; title::AbstractString = "Plots.jl ($(backend_name(plt.backend)))")
|
||||
# render(_html_template, title = title, body = html_body(plt), head = html_head(plt))
|
||||
function standalone_html(plt::PlottingObject; title::AbstractString = get(plt.plotargs, :window_title, "Plots.jl"))
|
||||
"""
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
@ -325,6 +325,16 @@ end
|
||||
|
||||
# ----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
make255(x) = round(Int, 255 * x)
|
||||
|
||||
function webcolor(c::Colorant)
|
||||
@sprintf("rgba(%d, %d, %d, %1.3f)", [make255(f(c)) for f in [red,green,blue]]..., alpha(c))
|
||||
end
|
||||
webcolor(cs::ColorScheme) = webcolor(getColor(cs))
|
||||
|
||||
# ----------------------------------------------------------------------------------
|
||||
|
||||
# TODO: allow the setting of the algorithm, either by passing a symbol (:colordiff, :fixed, etc) or a function?
|
||||
|
||||
# function getBackgroundRGBColor(c, d::Dict)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user