changed :log to map to :log10, switched :log to :ln; better support for plotly axis attributes, ticks, scale, etc; fix plotly bg/fg colors
This commit is contained in:
parent
002603c388
commit
fe0f22dfc0
@ -94,10 +94,10 @@ const _allMarkers = vcat(:none, :auto, sort(collect(keys(_shapes))))
|
|||||||
:spike => :vline,
|
:spike => :vline,
|
||||||
)
|
)
|
||||||
|
|
||||||
const _allScales = [:identity, :log, :log2, :log10, :asinh, :sqrt]
|
const _allScales = [:identity, :ln, :log2, :log10, :asinh, :sqrt]
|
||||||
@compat const _scaleAliases = Dict(
|
@compat const _scaleAliases = Dict(
|
||||||
:none => :identity,
|
:none => :identity,
|
||||||
:ln => :log,
|
:log => :log10,
|
||||||
)
|
)
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|||||||
@ -68,8 +68,8 @@ function _create_plot(pkg::BokehPackage; kw...)
|
|||||||
filename = tempname() * ".html"
|
filename = tempname() * ".html"
|
||||||
title = d[:title]
|
title = d[:title]
|
||||||
w, h = d[:size]
|
w, h = d[:size]
|
||||||
xaxis_type = d[:xscale] == :log ? :log : :auto
|
xaxis_type = d[:xscale] == :log10 ? :log : :auto
|
||||||
yaxis_type = d[:yscale] == :log ? :log : :auto
|
yaxis_type = d[:yscale] == :log10 ? :log : :auto
|
||||||
# legend = d[:legend] ? xxxx : nothing
|
# legend = d[:legend] ? xxxx : nothing
|
||||||
legend = nothing
|
legend = nothing
|
||||||
extra_args = Dict() # TODO: we'll put extra settings (xlim, etc) here
|
extra_args = Dict() # TODO: we'll put extra settings (xlim, etc) here
|
||||||
|
|||||||
@ -375,7 +375,7 @@ function getGadflyScaleFunction(d::Dict, isx::Bool)
|
|||||||
hasScaleKey = haskey(d, scalekey)
|
hasScaleKey = haskey(d, scalekey)
|
||||||
if hasScaleKey
|
if hasScaleKey
|
||||||
scale = d[scalekey]
|
scale = d[scalekey]
|
||||||
scale == :log && return isx ? Gadfly.Scale.x_log : Gadfly.Scale.y_log, hasScaleKey
|
scale == :ln && return isx ? Gadfly.Scale.x_log : Gadfly.Scale.y_log, hasScaleKey
|
||||||
scale == :log2 && return isx ? Gadfly.Scale.x_log2 : Gadfly.Scale.y_log2, hasScaleKey
|
scale == :log2 && return isx ? Gadfly.Scale.x_log2 : Gadfly.Scale.y_log2, hasScaleKey
|
||||||
scale == :log10 && return isx ? Gadfly.Scale.x_log10 : Gadfly.Scale.y_log10, hasScaleKey
|
scale == :log10 && return isx ? Gadfly.Scale.x_log10 : Gadfly.Scale.y_log10, hasScaleKey
|
||||||
scale == :asinh && return isx ? Gadfly.Scale.x_asinh : Gadfly.Scale.y_asinh, hasScaleKey
|
scale == :asinh && return isx ? Gadfly.Scale.x_asinh : Gadfly.Scale.y_asinh, hasScaleKey
|
||||||
|
|||||||
@ -82,11 +82,11 @@ end
|
|||||||
# _plotDefaults[:xflip] = false
|
# _plotDefaults[:xflip] = false
|
||||||
# _plotDefaults[:yflip] = false
|
# _plotDefaults[:yflip] = false
|
||||||
|
|
||||||
function plotlyfont(font::Font)
|
function plotlyfont(font::Font, color = font.color)
|
||||||
Dict(
|
Dict(
|
||||||
:family => font.family,
|
:family => font.family,
|
||||||
:size => round(Int, font.pointsize*1.4),
|
:size => round(Int, font.pointsize*1.4),
|
||||||
:color => webcolor(font.color),
|
:color => webcolor(color),
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ function get_annotation_dict(x, y, ptxt::PlotText)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function plotlyscale(scale::Symbol)
|
function plotlyscale(scale::Symbol)
|
||||||
if scale == :log
|
if scale == :log10
|
||||||
"log"
|
"log"
|
||||||
else
|
else
|
||||||
"-"
|
"-"
|
||||||
@ -120,6 +120,62 @@ end
|
|||||||
|
|
||||||
use_axis_field(ticks) = !(ticks in (nothing, :none))
|
use_axis_field(ticks) = !(ticks in (nothing, :none))
|
||||||
|
|
||||||
|
tickssym(isx::Bool) = symbol((isx ? "x" : "y") * "ticks")
|
||||||
|
limssym(isx::Bool) = symbol((isx ? "x" : "y") * "lims")
|
||||||
|
flipsym(isx::Bool) = symbol((isx ? "x" : "y") * "flip")
|
||||||
|
scalesym(isx::Bool) = symbol((isx ? "x" : "y") * "scale")
|
||||||
|
labelsym(isx::Bool) = symbol((isx ? "x" : "y") * "label")
|
||||||
|
|
||||||
|
function plotlyaxis(d::Dict, isx::Bool)
|
||||||
|
ax = Dict(
|
||||||
|
:title => d[labelsym(isx)],
|
||||||
|
:showgrid => d[:grid],
|
||||||
|
:zeroline => false,
|
||||||
|
)
|
||||||
|
|
||||||
|
fgcolor = webcolor(d[:foreground_color])
|
||||||
|
tsym = tickssym(isx)
|
||||||
|
|
||||||
|
if use_axis_field(d[tsym])
|
||||||
|
ax[:titlefont] = plotlyfont(d[:guidefont], fgcolor)
|
||||||
|
ax[:type] = plotlyscale(d[scalesym(isx)])
|
||||||
|
ax[:tickfont] = plotlyfont(d[:tickfont], fgcolor)
|
||||||
|
ax[:tickcolor] = fgcolor
|
||||||
|
ax[:linecolor] = fgcolor
|
||||||
|
|
||||||
|
# xlims
|
||||||
|
lims = d[limssym(isx)]
|
||||||
|
if lims != :auto && limsType(lims) == :limits
|
||||||
|
ax[:range] = lims
|
||||||
|
end
|
||||||
|
|
||||||
|
# xflip
|
||||||
|
if d[flipsym(isx)]
|
||||||
|
ax[:autorange] = "reversed"
|
||||||
|
end
|
||||||
|
|
||||||
|
# xticks
|
||||||
|
ticks = d[tsym]
|
||||||
|
if ticks != :auto
|
||||||
|
ttype = ticksType(ticks)
|
||||||
|
if ttype == :ticks
|
||||||
|
ax[:tickmode] = "array"
|
||||||
|
ax[:tickvals] = ticks
|
||||||
|
elseif ttype == :ticks_and_labels
|
||||||
|
ax[:tickmode] = "array"
|
||||||
|
ax[:tickvals], ax[:ticktext] = ticks
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ax
|
||||||
|
else
|
||||||
|
ax[:showticklabels] = false
|
||||||
|
ax[:showgrid] = false
|
||||||
|
end
|
||||||
|
|
||||||
|
ax
|
||||||
|
end
|
||||||
|
|
||||||
function get_plot_json(plt::Plot{PlotlyPackage})
|
function get_plot_json(plt::Plot{PlotlyPackage})
|
||||||
d = plt.plotargs
|
d = plt.plotargs
|
||||||
d_out = Dict()
|
d_out = Dict()
|
||||||
@ -129,64 +185,92 @@ function get_plot_json(plt::Plot{PlotlyPackage})
|
|||||||
|
|
||||||
# set the fields for the plot
|
# set the fields for the plot
|
||||||
d_out[:title] = d[:title]
|
d_out[:title] = d[:title]
|
||||||
d_out[:titlefont] = plotlyfont(d[:guidefont])
|
d_out[:titlefont] = plotlyfont(d[:guidefont], fgcolor)
|
||||||
d_out[:margin] = Dict(:l=>35, :b=>30, :r=>8, :t=>20)
|
d_out[:margin] = Dict(:l=>35, :b=>30, :r=>8, :t=>20)
|
||||||
d_out[:plot_bgcolor] = bgcolor
|
d_out[:plot_bgcolor] = bgcolor
|
||||||
|
d_out[:paper_bgcolor] = bgcolor
|
||||||
|
|
||||||
# TODO: x/y axis tick values/labels
|
# TODO: x/y axis tick values/labels
|
||||||
# TODO: x/y axis range
|
d_out[:xaxis] = plotlyaxis(d, true)
|
||||||
|
d_out[:yaxis] = plotlyaxis(d, false)
|
||||||
|
|
||||||
# x-axis
|
# # x-axis
|
||||||
d_out[:xaxis] = Dict(
|
# d_out[:xaxis] = Dict(
|
||||||
:title => d[:xlabel],
|
# :title => d[:xlabel],
|
||||||
:showgrid => d[:grid],
|
# :showgrid => d[:grid],
|
||||||
:zeroline => false,
|
# :zeroline => false,
|
||||||
)
|
# )
|
||||||
merge!(d_out[:xaxis], if use_axis_field(d[:xticks])
|
# merge!(d_out[:xaxis], if use_axis_field(d[:xticks])
|
||||||
Dict(
|
# ax = Dict(
|
||||||
:titlefont => plotlyfont(d[:guidefont]),
|
# :titlefont => plotlyfont(d[:guidefont]),
|
||||||
:type => plotlyscale(d[:xscale]),
|
# :type => plotlyscale(d[:xscale]),
|
||||||
:tickfont => plotlyfont(d[:tickfont]),
|
# :tickfont => plotlyfont(d[:tickfont]),
|
||||||
:tickcolor => fgcolor,
|
# :tickcolor => fgcolor,
|
||||||
:linecolor => fgcolor,
|
# :linecolor => fgcolor,
|
||||||
)
|
# )
|
||||||
else
|
|
||||||
Dict(
|
|
||||||
:showticklabels => false,
|
|
||||||
:showgrid => false,
|
|
||||||
)
|
|
||||||
end)
|
|
||||||
|
|
||||||
lims = d[:xlims]
|
# # xlims
|
||||||
if lims != :auto && limsType(lims) == :limits
|
# lims = d[:xlims]
|
||||||
d_out[:xaxis][:range] = lims
|
# if lims != :auto && limsType(lims) == :limits
|
||||||
end
|
# ax[:range] = lims
|
||||||
|
# end
|
||||||
|
|
||||||
# y-axis
|
# # xflip
|
||||||
d_out[:yaxis] = Dict(
|
# if d[:xflip]
|
||||||
:title => d[:ylabel],
|
# ax[:autorange] = "reversed"
|
||||||
:showgrid => d[:grid],
|
# end
|
||||||
:zeroline => false,
|
|
||||||
)
|
|
||||||
merge!(d_out[:yaxis], if use_axis_field(d[:yticks])
|
|
||||||
Dict(
|
|
||||||
:titlefont => plotlyfont(d[:guidefont]),
|
|
||||||
:type => plotlyscale(d[:yscale]),
|
|
||||||
:tickfont => plotlyfont(d[:tickfont]),
|
|
||||||
:tickcolor => fgcolor,
|
|
||||||
:linecolor => fgcolor,
|
|
||||||
)
|
|
||||||
else
|
|
||||||
Dict(
|
|
||||||
:showticklabels => false,
|
|
||||||
:showgrid => false,
|
|
||||||
)
|
|
||||||
end)
|
|
||||||
|
|
||||||
lims = d[:ylims]
|
# # xticks
|
||||||
if lims != :auto && limsType(lims) == :limits
|
# ticks = d[:xticks]
|
||||||
d_out[:yaxis][:range] = lims
|
# if ticks != :auto
|
||||||
end
|
# ttype = ticksType(ticks)
|
||||||
|
# if ttype == :ticks
|
||||||
|
# ax[:tickmode] = "array"
|
||||||
|
# ax[:tickvals] = ticks
|
||||||
|
# elseif ttype == :ticks_and_labels
|
||||||
|
# ax[:tickmode] = "array"
|
||||||
|
# ax[:tickvals], ax[:ticktext] = ticks
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
# ax
|
||||||
|
# else
|
||||||
|
# Dict(
|
||||||
|
# :showticklabels => false,
|
||||||
|
# :showgrid => false,
|
||||||
|
# )
|
||||||
|
# end)
|
||||||
|
|
||||||
|
|
||||||
|
# # y-axis
|
||||||
|
# d_out[:yaxis] = Dict(
|
||||||
|
# :title => d[:ylabel],
|
||||||
|
# :showgrid => d[:grid],
|
||||||
|
# :zeroline => false,
|
||||||
|
# )
|
||||||
|
# merge!(d_out[:yaxis], if use_axis_field(d[:yticks])
|
||||||
|
# Dict(
|
||||||
|
# :titlefont => plotlyfont(d[:guidefont]),
|
||||||
|
# :type => plotlyscale(d[:yscale]),
|
||||||
|
# :tickfont => plotlyfont(d[:tickfont]),
|
||||||
|
# :tickcolor => fgcolor,
|
||||||
|
# :linecolor => fgcolor,
|
||||||
|
# )
|
||||||
|
# else
|
||||||
|
# Dict(
|
||||||
|
# :showticklabels => false,
|
||||||
|
# :showgrid => false,
|
||||||
|
# )
|
||||||
|
# end)
|
||||||
|
|
||||||
|
# lims = d[:ylims]
|
||||||
|
# if lims != :auto && limsType(lims) == :limits
|
||||||
|
# d_out[:yaxis][:range] = lims
|
||||||
|
# end
|
||||||
|
|
||||||
|
# if d[:yflip]
|
||||||
|
# d_out[:yaxis][:autorange] = "reversed"
|
||||||
|
# end
|
||||||
|
|
||||||
# legend
|
# legend
|
||||||
d_out[:showlegend] = d[:legend]
|
d_out[:showlegend] = d[:legend]
|
||||||
@ -304,7 +388,8 @@ function get_series_json(d::Dict; plot_index = nothing)
|
|||||||
d_out[:z] = collect(d[:z])
|
d_out[:z] = collect(d[:z])
|
||||||
|
|
||||||
else
|
else
|
||||||
error("Plotly: linetype $lt isn't supported.")
|
warn("Plotly: linetype $lt isn't supported.")
|
||||||
|
return Dict()
|
||||||
end
|
end
|
||||||
|
|
||||||
# add "marker"
|
# add "marker"
|
||||||
|
|||||||
@ -523,7 +523,7 @@ end
|
|||||||
function applyPyPlotScale(ax, scaleType::Symbol, isx::Bool)
|
function applyPyPlotScale(ax, scaleType::Symbol, isx::Bool)
|
||||||
func = ax[isx ? :set_xscale : :set_yscale]
|
func = ax[isx ? :set_xscale : :set_yscale]
|
||||||
scaleType == :identity && return func("linear")
|
scaleType == :identity && return func("linear")
|
||||||
scaleType == :log && return func("log", basex = e, basey = e)
|
scaleType == :ln && return func("log", basex = e, basey = e)
|
||||||
scaleType == :log2 && return func("log", basex = 2, basey = 2)
|
scaleType == :log2 && return func("log", basex = 2, basey = 2)
|
||||||
scaleType == :log10 && return func("log", basex = 10, basey = 10)
|
scaleType == :log10 && return func("log", basex = 10, basey = 10)
|
||||||
warn("Unhandled scaleType: ", scaleType)
|
warn("Unhandled scaleType: ", scaleType)
|
||||||
|
|||||||
@ -82,7 +82,7 @@ supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppre, :steppost, :st
|
|||||||
:hline, :vline, :contour]
|
:hline, :vline, :contour]
|
||||||
supportedStyles(::GadflyPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
supportedStyles(::GadflyPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
||||||
supportedMarkers(::GadflyPackage) = vcat(_allMarkers, Shape)
|
supportedMarkers(::GadflyPackage) = vcat(_allMarkers, Shape)
|
||||||
supportedScales(::GadflyPackage) = [:identity, :log, :log2, :log10, :asinh, :sqrt]
|
supportedScales(::GadflyPackage) = [:identity, :ln, :log2, :log10, :asinh, :sqrt]
|
||||||
subplotSupported(::GadflyPackage) = true
|
subplotSupported(::GadflyPackage) = true
|
||||||
|
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, :st
|
|||||||
supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot]
|
supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot]
|
||||||
# supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon]
|
# supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon]
|
||||||
supportedMarkers(::PyPlotPackage) = vcat(_allMarkers, Shape)
|
supportedMarkers(::PyPlotPackage) = vcat(_allMarkers, Shape)
|
||||||
supportedScales(::PyPlotPackage) = [:identity, :log, :log2, :log10]
|
supportedScales(::PyPlotPackage) = [:identity, :ln, :log2, :log10]
|
||||||
subplotSupported(::PyPlotPackage) = true
|
subplotSupported(::PyPlotPackage) = true
|
||||||
|
|
||||||
|
|
||||||
@ -419,7 +419,7 @@ supportedAxes(::BokehPackage) = [:auto, :left]
|
|||||||
supportedTypes(::BokehPackage) = [:none, :path, :scatter] #,:steppre, :steppost, :sticks, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :contour]
|
supportedTypes(::BokehPackage) = [:none, :path, :scatter] #,:steppre, :steppost, :sticks, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :contour]
|
||||||
supportedStyles(::BokehPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
supportedStyles(::BokehPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
||||||
supportedMarkers(::BokehPackage) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape)
|
supportedMarkers(::BokehPackage) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape)
|
||||||
supportedScales(::BokehPackage) = [:identity, :log] #, :log, :log2, :log10, :asinh, :sqrt]
|
supportedScales(::BokehPackage) = [:identity, :ln] #, :ln, :log2, :log10, :asinh, :sqrt]
|
||||||
subplotSupported(::BokehPackage) = false
|
subplotSupported(::BokehPackage) = false
|
||||||
|
|
||||||
|
|
||||||
@ -471,8 +471,8 @@ supportedArgs(::PlotlyPackage) = [
|
|||||||
:yticks,
|
:yticks,
|
||||||
:xscale,
|
:xscale,
|
||||||
:yscale,
|
:yscale,
|
||||||
# :xflip,
|
:xflip,
|
||||||
# :yflip,
|
:yflip,
|
||||||
:z,
|
:z,
|
||||||
:zcolor,
|
:zcolor,
|
||||||
:tickfont,
|
:tickfont,
|
||||||
@ -488,7 +488,7 @@ supportedTypes(::PlotlyPackage) = [:none, :line, :path, :scatter, :steppre, :ste
|
|||||||
supportedStyles(::PlotlyPackage) = [:auto, :solid, :dash, :dot, :dashdot]
|
supportedStyles(::PlotlyPackage) = [:auto, :solid, :dash, :dot, :dashdot]
|
||||||
supportedMarkers(::PlotlyPackage) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross,
|
supportedMarkers(::PlotlyPackage) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross,
|
||||||
:pentagon, :hexagon, :octagon, :vline, :hline] #vcat(_allMarkers, Shape)
|
:pentagon, :hexagon, :octagon, :vline, :hline] #vcat(_allMarkers, Shape)
|
||||||
supportedScales(::PlotlyPackage) = [:identity, :log] #, :log, :log2, :log10, :asinh, :sqrt]
|
supportedScales(::PlotlyPackage) = [:identity, :log10] #, :ln, :log2, :log10, :asinh, :sqrt]
|
||||||
subplotSupported(::PlotlyPackage) = true
|
subplotSupported(::PlotlyPackage) = true
|
||||||
stringsSupported(::PlotlyPackage) = true
|
stringsSupported(::PlotlyPackage) = true
|
||||||
|
|
||||||
|
|||||||
@ -335,6 +335,7 @@ function webcolor(c::TransparentColor)
|
|||||||
@sprintf("rgba(%d, %d, %d, %1.3f)", [make255(f(c)) for f in [red,green,blue]]..., alpha(c))
|
@sprintf("rgba(%d, %d, %d, %1.3f)", [make255(f(c)) for f in [red,green,blue]]..., alpha(c))
|
||||||
end
|
end
|
||||||
webcolor(cs::ColorScheme) = webcolor(getColor(cs))
|
webcolor(cs::ColorScheme) = webcolor(getColor(cs))
|
||||||
|
webcolor(c) = webcolor(convertColor(c))
|
||||||
webcolor(c, α) = webcolor(convertColor(getColor(c), α))
|
webcolor(c, α) = webcolor(convertColor(getColor(c), α))
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user