more Dict to KW renaming

This commit is contained in:
Thomas Breloff 2016-03-17 22:11:29 -04:00
parent be5f71c123
commit 5efb0eb582
13 changed files with 107 additions and 109 deletions

View File

@ -18,7 +18,7 @@ end
# bokehcolor(cs::ColorScheme) = bokehcolor(getColor(cs)) # bokehcolor(cs::ColorScheme) = bokehcolor(getColor(cs))
const _glyphtypes = Dict( const _glyphtypes = KW(
:ellipse => :Circle, :ellipse => :Circle,
:rect => :Square, :rect => :Square,
:diamond => :Diamond, :diamond => :Diamond,
@ -34,7 +34,7 @@ const _glyphtypes = Dict(
) )
function bokeh_glyph_type(d::Dict) function bokeh_glyph_type(d::KW)
lt = d[:linetype] lt = d[:linetype]
mt = d[:markershape] mt = d[:markershape]
if lt == :scatter && mt == :none if lt == :scatter && mt == :none
@ -81,10 +81,10 @@ function _create_plot(pkg::BokehBackend; kw...)
yaxis_type = d[:yscale] == :log10 ? :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 = KW() # TODO: we'll put extra settings (xlim, etc) here
bplt = Bokeh.Plot(datacolumns, tools, filename, title, w, h, xaxis_type, yaxis_type, legend) #, extra_args) bplt = Bokeh.Plot(datacolumns, tools, filename, title, w, h, xaxis_type, yaxis_type, legend) #, extra_args)
Plot(bplt, pkg, 0, d, Dict[]) Plot(bplt, pkg, 0, d, KW[])
end end
@ -114,10 +114,10 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
# TODO: override this to update plot items (title, xlabel, etc) after creation # TODO: override this to update plot items (title, xlabel, etc) after creation
function _update_plot(plt::Plot{BokehBackend}, d::Dict) function _update_plot(plt::Plot{BokehBackend}, d::KW)
end end
function _update_plot_pos_size(plt::AbstractPlot{BokehBackend}, d::Dict) function _update_plot_pos_size(plt::AbstractPlot{BokehBackend}, d::KW)
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------

View File

@ -16,7 +16,7 @@ end
# Base.size(v::MissingVec) = (1,) # Base.size(v::MissingVec) = (1,)
# Base.getindex(v::MissingVec, i::Integer) = 0.0 # Base.getindex(v::MissingVec, i::Integer) = 0.0
function createGadflyPlotObject(d::Dict) function createGadflyPlotObject(d::KW)
gplt = Gadfly.Plot() gplt = Gadfly.Plot()
gplt.mapping = Dict() gplt.mapping = Dict()
gplt.data_source = Gadfly.DataFrames.DataFrame() gplt.data_source = Gadfly.DataFrames.DataFrame()
@ -31,7 +31,7 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function getLineGeom(d::Dict) function getLineGeom(d::KW)
lt = d[:linetype] lt = d[:linetype]
xbins, ybins = maketuple(d[:nbins]) xbins, ybins = maketuple(d[:nbins])
if lt == :hexb if lt == :hexb
@ -61,9 +61,9 @@ function getLineGeom(d::Dict)
end end
end end
function get_extra_theme_args(d::Dict, k::Symbol) function get_extra_theme_args(d::KW, k::Symbol)
# gracefully handles old Gadfly versions # gracefully handles old Gadfly versions
extra_theme_args = Dict() extra_theme_args = KW()
try try
extra_theme_args[:line_style] = Gadfly.get_stroke_vector(d[k]) extra_theme_args[:line_style] = Gadfly.get_stroke_vector(d[k])
catch err catch err
@ -76,7 +76,7 @@ function get_extra_theme_args(d::Dict, k::Symbol)
extra_theme_args extra_theme_args
end end
function getGadflyLineTheme(d::Dict) function getGadflyLineTheme(d::KW)
lc = convertColor(getColor(d[:linecolor]), d[:linealpha]) lc = convertColor(getColor(d[:linecolor]), d[:linealpha])
fc = convertColor(getColor(d[:fillcolor]), d[:fillalpha]) fc = convertColor(getColor(d[:fillcolor]), d[:fillalpha])
@ -92,10 +92,10 @@ function getGadflyLineTheme(d::Dict)
end end
# add a line as a new layer # add a line as a new layer
function addGadflyLine!(plt::Plot, numlayers::Int, d::Dict, geoms...) function addGadflyLine!(plt::Plot, numlayers::Int, d::KW, geoms...)
gplt = getGadflyContext(plt) gplt = getGadflyContext(plt)
gfargs = vcat(geoms..., getGadflyLineTheme(d)) gfargs = vcat(geoms..., getGadflyLineTheme(d))
kwargs = Dict() kwargs = KW()
lt = d[:linetype] lt = d[:linetype]
# add a fill? # add a fill?
@ -136,7 +136,7 @@ end
getMarkerGeom(shape::Shape) = gadflyshape(shape) getMarkerGeom(shape::Shape) = gadflyshape(shape)
getMarkerGeom(shape::Symbol) = gadflyshape(_shapes[shape]) getMarkerGeom(shape::Symbol) = gadflyshape(_shapes[shape])
getMarkerGeom(shapes::AVec) = map(getMarkerGeom, shapes) getMarkerGeom(shapes::AVec) = map(getMarkerGeom, shapes)
function getMarkerGeom(d::Dict) function getMarkerGeom(d::KW)
if d[:linetype] == :shape if d[:linetype] == :shape
Gadfly.Geom.polygon(fill = true, preserve_order = true) Gadfly.Geom.polygon(fill = true, preserve_order = true)
else else
@ -144,7 +144,7 @@ function getMarkerGeom(d::Dict)
end end
end end
function getGadflyMarkerTheme(d::Dict, plotargs::Dict) function getGadflyMarkerTheme(d::KW, plotargs::KW)
c = getColor(d[:markercolor]) c = getColor(d[:markercolor])
α = d[:markeralpha] α = d[:markeralpha]
if α != nothing if α != nothing
@ -177,9 +177,9 @@ function addGadflyContColorScale(plt::Plot{GadflyBackend}, c)
push!(getGadflyContext(plt).scales, Gadfly.Scale.ContinuousColorScale(p -> RGB(getColorZ(c, p)))) push!(getGadflyContext(plt).scales, Gadfly.Scale.ContinuousColorScale(p -> RGB(getColorZ(c, p))))
end end
function addGadflyMarker!(plt::Plot, numlayers::Int, d::Dict, plotargs::Dict, geoms...) function addGadflyMarker!(plt::Plot, numlayers::Int, d::KW, plotargs::KW, geoms...)
gfargs = vcat(geoms..., getGadflyMarkerTheme(d, plotargs), getMarkerGeom(d)) gfargs = vcat(geoms..., getGadflyMarkerTheme(d, plotargs), getMarkerGeom(d))
kwargs = Dict() kwargs = KW()
# handle continuous color scales for the markers # handle continuous color scales for the markers
zcolor = d[:zcolor] zcolor = d[:zcolor]
@ -194,7 +194,7 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function addToGadflyLegend(plt::Plot, d::Dict) function addToGadflyLegend(plt::Plot, d::KW)
if plt.plotargs[:legend] != :none && d[:label] != "" if plt.plotargs[:legend] != :none && d[:label] != ""
gplt = getGadflyContext(plt) gplt = getGadflyContext(plt)
@ -235,7 +235,7 @@ getGadflySmoothing(smooth::Bool) = smooth ? [Gadfly.Geom.smooth(method=:lm)] : A
getGadflySmoothing(smooth::Real) = [Gadfly.Geom.smooth(method=:loess, smoothing=float(smooth))] getGadflySmoothing(smooth::Real) = [Gadfly.Geom.smooth(method=:loess, smoothing=float(smooth))]
function addGadflySeries!(plt::Plot, d::Dict) function addGadflySeries!(plt::Plot, d::KW)
layers = Gadfly.Layer[] layers = Gadfly.Layer[]
gplt = getGadflyContext(plt) gplt = getGadflyContext(plt)
@ -336,7 +336,7 @@ continuousAndSameAxis(scale, isx::Bool) = isa(scale, Gadfly.Scale.ContinuousScal
filterGadflyScale(gplt, isx::Bool) = filter!(scale -> !continuousAndSameAxis(scale, isx), gplt.scales) filterGadflyScale(gplt, isx::Bool) = filter!(scale -> !continuousAndSameAxis(scale, isx), gplt.scales)
function getGadflyScaleFunction(d::Dict, isx::Bool) function getGadflyScaleFunction(d::KW, isx::Bool)
scalekey = isx ? :xscale : :yscale scalekey = isx ? :xscale : :yscale
hasScaleKey = haskey(d, scalekey) hasScaleKey = haskey(d, scalekey)
if hasScaleKey if hasScaleKey
@ -351,7 +351,7 @@ function getGadflyScaleFunction(d::Dict, isx::Bool)
end end
function addGadflyLimitsScale(gplt, d::Dict, isx::Bool) function addGadflyLimitsScale(gplt, d::KW, isx::Bool)
gfunc, hasScaleKey = getGadflyScaleFunction(d, isx) gfunc, hasScaleKey = getGadflyScaleFunction(d, isx)
# do we want to add min/max limits for the axis? # do we want to add min/max limits for the axis?
@ -380,7 +380,7 @@ function addGadflyLimitsScale(gplt, d::Dict, isx::Bool)
lims lims
end end
function updateGadflyAxisFlips(gplt, d::Dict, xlims, ylims) function updateGadflyAxisFlips(gplt, d::KW, xlims, ylims)
if isa(gplt.coord, Gadfly.Coord.Cartesian) if isa(gplt.coord, Gadfly.Coord.Cartesian)
gplt.coord = Gadfly.Coord.cartesian( gplt.coord = Gadfly.Coord.cartesian(
gplt.coord.xvars, gplt.coord.xvars,
@ -412,7 +412,7 @@ function findGuideAndSet(gplt, t::DataType, args...; kw...) #s::@compat(Abstract
end end
end end
function updateGadflyGuides(plt::Plot, d::Dict) function updateGadflyGuides(plt::Plot, d::KW)
gplt = getGadflyContext(plt) gplt = getGadflyContext(plt)
haskey(d, :title) && findGuideAndSet(gplt, Gadfly.Guide.title, string(d[:title])) haskey(d, :title) && findGuideAndSet(gplt, Gadfly.Guide.title, string(d[:title]))
haskey(d, :xlabel) && findGuideAndSet(gplt, Gadfly.Guide.xlabel, string(d[:xlabel])) haskey(d, :xlabel) && findGuideAndSet(gplt, Gadfly.Guide.xlabel, string(d[:xlabel]))
@ -437,8 +437,8 @@ function updateGadflyGuides(plt::Plot, d::Dict)
updateGadflyAxisFlips(gplt, d, xlims, ylims) updateGadflyAxisFlips(gplt, d, xlims, ylims)
end end
function updateGadflyPlotTheme(plt::Plot, d::Dict) function updateGadflyPlotTheme(plt::Plot, d::KW)
kwargs = Dict() kwargs = KW()
# # hide the legend? # # hide the legend?
leg = d[d[:legend] == :none ? :colorbar : :legend] leg = d[d[:legend] == :none ? :colorbar : :legend]
@ -510,7 +510,7 @@ end
function _create_plot(pkg::GadflyBackend; kw...) function _create_plot(pkg::GadflyBackend; kw...)
d = KW(kw) d = KW(kw)
gplt = createGadflyPlotObject(d) gplt = createGadflyPlotObject(d)
Plot(gplt, pkg, 0, d, Dict[]) Plot(gplt, pkg, 0, d, KW[])
end end
@ -530,7 +530,7 @@ end
function _update_plot(plt::Plot{GadflyBackend}, d::Dict) function _update_plot(plt::Plot{GadflyBackend}, d::KW)
updateGadflyGuides(plt, d) updateGadflyGuides(plt, d)
updateGadflyPlotTheme(plt, d) updateGadflyPlotTheme(plt, d)
end end

View File

@ -23,7 +23,7 @@ function _create_plot(pkg::GLVisualizeBackend; kw...)
# TODO: this should be moved to the display method? # TODO: this should be moved to the display method?
w=GLVisualize.glscreen() w=GLVisualize.glscreen()
@async GLVisualize.renderloop(w) @async GLVisualize.renderloop(w)
Plot(GLScreenWrapper(w), pkg, 0, d, Dict[]) Plot(GLScreenWrapper(w), pkg, 0, d, KW[])
end end
@ -49,10 +49,10 @@ function _before_update_plot(plt::Plot{GLVisualizeBackend})
end end
# TODO: override this to update plot items (title, xlabel, etc) after creation # TODO: override this to update plot items (title, xlabel, etc) after creation
function _update_plot(plt::Plot{GLVisualizeBackend}, d::Dict) function _update_plot(plt::Plot{GLVisualizeBackend}, d::KW)
end end
function _update_plot_pos_size(plt::AbstractPlot{GLVisualizeBackend}, d::Dict) function _update_plot_pos_size(plt::AbstractPlot{GLVisualizeBackend}, d::KW)
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------

View File

@ -9,7 +9,7 @@ function _initialize_backend(::ImmerseBackend; kw...)
end end
end end
function createImmerseFigure(d::Dict) function createImmerseFigure(d::KW)
w,h = d[:size] w,h = d[:size]
figidx = Immerse.figure(; name = d[:windowtitle], width = w, height = h) figidx = Immerse.figure(; name = d[:windowtitle], width = w, height = h)
Immerse.Figure(figidx) Immerse.Figure(figidx)
@ -26,7 +26,7 @@ function _create_plot(pkg::ImmerseBackend; kw...)
gplt = createGadflyPlotObject(d) gplt = createGadflyPlotObject(d)
# save both the Immerse.Figure and the Gadfly.Plot # save both the Immerse.Figure and the Gadfly.Plot
Plot((nothing,gplt), pkg, 0, d, Dict[]) Plot((nothing,gplt), pkg, 0, d, KW[])
end end
@ -39,7 +39,7 @@ function _add_series(::ImmerseBackend, plt::Plot; kw...)
end end
function _update_plot(plt::Plot{ImmerseBackend}, d::Dict) function _update_plot(plt::Plot{ImmerseBackend}, d::KW)
updateGadflyGuides(plt, d) updateGadflyGuides(plt, d)
updateGadflyPlotTheme(plt, d) updateGadflyPlotTheme(plt, d)
end end

View File

@ -13,15 +13,15 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _create_plot(pkg::PGFPlotsBackend; kw...) function _create_plot(pkg::PGFPlotsBackend; kw...)
d = Dict{Symbol,Any}(kw) d = KW(kw)
# TODO: create the window/canvas/context that is the plot within the backend (call it `o`) # TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# TODO: initialize the plot... title, xlabel, bgcolor, etc # TODO: initialize the plot... title, xlabel, bgcolor, etc
Plot(nothing, pkg, 0, d, Dict[]) Plot(nothing, pkg, 0, d, KW[])
end end
function _add_series(::PGFPlotsBackend, plt::Plot; kw...) function _add_series(::PGFPlotsBackend, plt::Plot; kw...)
d = Dict{Symbol,Any}(kw) d = KW(kw)
# TODO: add one series to the underlying package # TODO: add one series to the underlying package
push!(plt.seriesargs, d) push!(plt.seriesargs, d)
plt plt
@ -42,10 +42,10 @@ function _before_update_plot(plt::Plot{PGFPlotsBackend})
end end
# TODO: override this to update plot items (title, xlabel, etc) after creation # TODO: override this to update plot items (title, xlabel, etc) after creation
function _update_plot(plt::Plot{PGFPlotsBackend}, d::Dict) function _update_plot(plt::Plot{PGFPlotsBackend}, d::KW)
end end
function _update_plot_pos_size(plt::AbstractPlot{PGFPlotsBackend}, d::Dict) function _update_plot_pos_size(plt::AbstractPlot{PGFPlotsBackend}, d::KW)
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------

View File

@ -38,15 +38,15 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _create_plot(pkg::PlotlyBackend; kw...) function _create_plot(pkg::PlotlyBackend; kw...)
d = Dict{Symbol,Any}(kw) d = KW(kw)
# TODO: create the window/canvas/context that is the plot within the backend (call it `o`) # TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# TODO: initialize the plot... title, xlabel, bgcolor, etc # TODO: initialize the plot... title, xlabel, bgcolor, etc
Plot(nothing, pkg, 0, d, Dict[]) Plot(nothing, pkg, 0, d, KW[])
end end
function _add_series(::PlotlyBackend, plt::Plot; kw...) function _add_series(::PlotlyBackend, plt::Plot; kw...)
d = Dict{Symbol,Any}(kw) d = KW(kw)
# TODO: add one series to the underlying package # TODO: add one series to the underlying package
push!(plt.seriesargs, d) push!(plt.seriesargs, d)
plt plt
@ -67,10 +67,10 @@ function _before_update_plot(plt::Plot{PlotlyBackend})
end end
# TODO: override this to update plot items (title, xlabel, etc) after creation # TODO: override this to update plot items (title, xlabel, etc) after creation
function _update_plot(plt::Plot{PlotlyBackend}, d::Dict) function _update_plot(plt::Plot{PlotlyBackend}, d::KW)
end end
function _update_plot_pos_size(plt::AbstractPlot{PlotlyBackend}, d::Dict) function _update_plot_pos_size(plt::AbstractPlot{PlotlyBackend}, d::KW)
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
@ -117,7 +117,7 @@ end
# _plotDefaults[:yflip] = false # _plotDefaults[:yflip] = false
function plotlyfont(font::Font, color = font.color) function plotlyfont(font::Font, color = font.color)
Dict{Symbol,Any}( KW(
:family => font.family, :family => font.family,
:size => round(Int, font.pointsize*1.4), :size => round(Int, font.pointsize*1.4),
:color => webcolor(color), :color => webcolor(color),
@ -125,7 +125,7 @@ function plotlyfont(font::Font, color = font.color)
end end
function get_annotation_dict(x, y, val::Union{AbstractString,Symbol}) function get_annotation_dict(x, y, val::Union{AbstractString,Symbol})
Dict{Symbol,Any}( KW(
:text => val, :text => val,
:xref => "x", :xref => "x",
:x => x, :x => x,
@ -136,7 +136,7 @@ function get_annotation_dict(x, y, val::Union{AbstractString,Symbol})
end end
function get_annotation_dict(x, y, ptxt::PlotText) function get_annotation_dict(x, y, ptxt::PlotText)
merge(get_annotation_dict(x, y, ptxt.str), Dict{Symbol,Any}( merge(get_annotation_dict(x, y, ptxt.str), KW(
:font => plotlyfont(ptxt.font), :font => plotlyfont(ptxt.font),
:xanchor => ptxt.font.halign == :hcenter ? :center : ptxt.font.halign, :xanchor => ptxt.font.halign == :hcenter ? :center : ptxt.font.halign,
:yanchor => ptxt.font.valign == :vcenter ? :middle : ptxt.font.valign, :yanchor => ptxt.font.valign == :vcenter ? :middle : ptxt.font.valign,
@ -160,8 +160,8 @@ flipsym(isx::Bool) = symbol((isx ? "x" : "y") * "flip")
scalesym(isx::Bool) = symbol((isx ? "x" : "y") * "scale") scalesym(isx::Bool) = symbol((isx ? "x" : "y") * "scale")
labelsym(isx::Bool) = symbol((isx ? "x" : "y") * "label") labelsym(isx::Bool) = symbol((isx ? "x" : "y") * "label")
function plotlyaxis(d::Dict, isx::Bool) function plotlyaxis(d::KW, isx::Bool)
ax = Dict{Symbol,Any}( ax = KW(
:title => d[labelsym(isx)], :title => d[labelsym(isx)],
:showgrid => d[:grid], :showgrid => d[:grid],
:zeroline => false, :zeroline => false,
@ -212,8 +212,8 @@ end
# function get_plot_json(plt::Plot{PlotlyBackend}) # function get_plot_json(plt::Plot{PlotlyBackend})
# d = plt.plotargs # d = plt.plotargs
function plotly_layout(d::Dict) function plotly_layout(d::KW)
d_out = Dict{Symbol,Any}() d_out = KW()
bgcolor = webcolor(d[:background_color]) bgcolor = webcolor(d[:background_color])
fgcolor = webcolor(d[:foreground_color]) fgcolor = webcolor(d[:foreground_color])
@ -221,7 +221,7 @@ function plotly_layout(d::Dict)
# 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], fgcolor) d_out[:titlefont] = plotlyfont(d[:guidefont], fgcolor)
d_out[:margin] = Dict{Symbol,Any}(:l=>35, :b=>30, :r=>8, :t=>20) d_out[:margin] = KW(:l=>35, :b=>30, :r=>8, :t=>20)
d_out[:plot_bgcolor] = bgcolor d_out[:plot_bgcolor] = bgcolor
d_out[:paper_bgcolor] = bgcolor d_out[:paper_bgcolor] = bgcolor
@ -232,7 +232,7 @@ function plotly_layout(d::Dict)
# legend # legend
d_out[:showlegend] = d[:legend] != :none d_out[:showlegend] = d[:legend] != :none
if d[:legend] != :none if d[:legend] != :none
d_out[:legend] = Dict{Symbol,Any}( d_out[:legend] = KW(
:bgcolor => bgcolor, :bgcolor => bgcolor,
:bordercolor => fgcolor, :bordercolor => fgcolor,
:font => plotlyfont(d[:legendfont]), :font => plotlyfont(d[:legendfont]),
@ -258,7 +258,7 @@ function plotly_colorscale(grad::ColorGradient, alpha = nothing)
end end
plotly_colorscale(c, alpha = nothing) = plotly_colorscale(ColorGradient(:bluesreds), alpha) plotly_colorscale(c, alpha = nothing) = plotly_colorscale(ColorGradient(:bluesreds), alpha)
const _plotly_markers = Dict{Symbol,Any}( const _plotly_markers = KW(
:rect => "square", :rect => "square",
:xcross => "x", :xcross => "x",
:utriangle => "triangle-up", :utriangle => "triangle-up",
@ -269,8 +269,8 @@ const _plotly_markers = Dict{Symbol,Any}(
) )
# get a dictionary representing the series params (d is the Plots-dict, d_out is the Plotly-dict) # get a dictionary representing the series params (d is the Plots-dict, d_out is the Plotly-dict)
function plotly_series(d::Dict; plot_index = nothing) function plotly_series(d::KW; plot_index = nothing)
d_out = Dict{Symbol,Any}() d_out = KW()
x, y = collect(d[:x]), collect(d[:y]) x, y = collect(d[:x]), collect(d[:y])
d_out[:name] = d[:label] d_out[:name] = d[:label]
@ -332,7 +332,7 @@ function plotly_series(d::Dict; plot_index = nothing)
d_out[:z] = d[:z].surf d_out[:z] = d[:z].surf
# d_out[:showscale] = d[:colorbar] != :none # d_out[:showscale] = d[:colorbar] != :none
d_out[:ncontours] = d[:levels] d_out[:ncontours] = d[:levels]
d_out[:contours] = Dict{Symbol,Any}(:coloring => d[:fillrange] != nothing ? "fill" : "lines") d_out[:contours] = KW(:coloring => d[:fillrange] != nothing ? "fill" : "lines")
d_out[:colorscale] = plotly_colorscale(d[:linecolor], d[:linealpha]) d_out[:colorscale] = plotly_colorscale(d[:linecolor], d[:linealpha])
elseif lt in (:surface, :wireframe) elseif lt in (:surface, :wireframe)
@ -359,17 +359,17 @@ function plotly_series(d::Dict; plot_index = nothing)
else else
warn("Plotly: linetype $lt isn't supported.") warn("Plotly: linetype $lt isn't supported.")
return Dict{Symbol,Any}() return KW()
end end
# add "marker" # add "marker"
if hasmarker if hasmarker
d_out[:marker] = Dict{Symbol,Any}( d_out[:marker] = KW(
:symbol => get(_plotly_markers, d[:markershape], string(d[:markershape])), :symbol => get(_plotly_markers, d[:markershape], string(d[:markershape])),
:opacity => d[:markeralpha], :opacity => d[:markeralpha],
:size => 2 * d[:markersize], :size => 2 * d[:markersize],
:color => webcolor(d[:markercolor], d[:markeralpha]), :color => webcolor(d[:markercolor], d[:markeralpha]),
:line => Dict{Symbol,Any}( :line => KW(
:color => webcolor(d[:markerstrokecolor], d[:markerstrokealpha]), :color => webcolor(d[:markerstrokecolor], d[:markerstrokealpha]),
:width => d[:markerstrokewidth], :width => d[:markerstrokewidth],
), ),
@ -389,7 +389,7 @@ function plotly_series(d::Dict; plot_index = nothing)
# add "line" # add "line"
if hasline if hasline
d_out[:line] = Dict{Symbol,Any}( d_out[:line] = KW(
:color => webcolor(d[:linecolor], d[:linealpha]), :color => webcolor(d[:linecolor], d[:linealpha]),
:width => d[:linewidth], :width => d[:linewidth],
:shape => if lt == :steppre :shape => if lt == :steppre
@ -419,7 +419,7 @@ function get_series_json(plt::Plot{PlotlyBackend})
end end
function get_series_json(subplt::Subplot{PlotlyBackend}) function get_series_json(subplt::Subplot{PlotlyBackend})
ds = Dict[] ds = KW[]
for (i,plt) in enumerate(subplt.plts) for (i,plt) in enumerate(subplt.plts)
for d in plt.seriesargs for d in plt.seriesargs
push!(ds, plotly_series(d, plot_index = i)) push!(ds, plotly_series(d, plot_index = i))

View File

@ -29,7 +29,7 @@ function _create_plot(pkg::PlotlyJSBackend; kw...)
# o = T(PlotlyJS.Plot()) # o = T(PlotlyJS.Plot())
o = PlotlyJS.plot() o = PlotlyJS.plot()
Plot(o, pkg, 0, d, Dict[]) Plot(o, pkg, 0, d, KW[])
end end
@ -68,7 +68,7 @@ function _before_update_plot(plt::Plot{PlotlyJSBackend})
end end
# TODO: override this to update plot items (title, xlabel, etc) after creation # TODO: override this to update plot items (title, xlabel, etc) after creation
function _update_plot(plt::Plot{PlotlyJSBackend}, d::Dict) function _update_plot(plt::Plot{PlotlyJSBackend}, d::KW)
pdict = plotly_layout(d) pdict = plotly_layout(d)
# dumpdict(pdict, "pdict updateplot", true) # dumpdict(pdict, "pdict updateplot", true)
syncplot = plt.o syncplot = plt.o
@ -78,7 +78,7 @@ function _update_plot(plt::Plot{PlotlyJSBackend}, d::Dict)
end end
function _update_plot_pos_size(plt::AbstractPlot{PlotlyJSBackend}, d::Dict) function _update_plot_pos_size(plt::AbstractPlot{PlotlyJSBackend}, d::KW)
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
@ -95,7 +95,7 @@ function Base.setindex!(plt::Plot{PlotlyJSBackend}, xy::Tuple, i::Integer)
d[:x], d[:y] = xy d[:x], d[:y] = xy
# TODO: this is likely ineffecient... we should make a call that ONLY changes the plot data # TODO: this is likely ineffecient... we should make a call that ONLY changes the plot data
# PlotlyJS.restyle!(plt.o, i, plotly_series(d)) # PlotlyJS.restyle!(plt.o, i, plotly_series(d))
PlotlyJS.restyle!(plt.o, i, Dict(:x=>(d[:x],), :y=>(d[:y],))) PlotlyJS.restyle!(plt.o, i, KW(:x=>(d[:x],), :y=>(d[:y],)))
plt plt
end end

View File

@ -164,7 +164,7 @@ function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol)
# in the 2-axis case we need to get: <rightaxis>[:<func>] # in the 2-axis case we need to get: <rightaxis>[:<func>]
ax = getAxis(plt, axis) ax = getAxis(plt, axis)
# ax[:set_ylabel](plt.plotargs[:yrightlabel]) # ax[:set_ylabel](plt.plotargs[:yrightlabel])
fmap = @compat Dict( fmap = KW(
:hist => :hist, :hist => :hist,
:density => :hist, :density => :hist,
:sticks => :bar, :sticks => :bar,
@ -196,7 +196,7 @@ function updateAxisColors(ax, fgcolor)
end end
function handleSmooth(plt::Plot{PyPlotBackend}, ax, d::Dict, smooth::Bool) function handleSmooth(plt::Plot{PyPlotBackend}, ax, d::KW, smooth::Bool)
if smooth if smooth
xs, ys = regressionXY(d[:x], d[:y]) xs, ys = regressionXY(d[:x], d[:y])
ax[:plot](xs, ys, ax[:plot](xs, ys,
@ -206,7 +206,7 @@ function handleSmooth(plt::Plot{PyPlotBackend}, ax, d::Dict, smooth::Bool)
) )
end end
end end
handleSmooth(plt::Plot{PyPlotBackend}, ax, d::Dict, smooth::Real) = handleSmooth(plt, ax, d, true) handleSmooth(plt::Plot{PyPlotBackend}, ax, d::KW, smooth::Real) = handleSmooth(plt, ax, d, true)
@ -224,7 +224,7 @@ end
# ------------------------------------------------------------------ # ------------------------------------------------------------------
function pyplot_figure(plotargs::Dict) function pyplot_figure(plotargs::KW)
w,h = map(px2inch, plotargs[:size]) w,h = map(px2inch, plotargs[:size])
bgcolor = getPyPlotColor(plotargs[:background_color]) bgcolor = getPyPlotColor(plotargs[:background_color])
@ -284,7 +284,7 @@ function _create_plot(pkg::PyPlotBackend; kw...)
pyplot_3d_setup!(wrap, d) pyplot_3d_setup!(wrap, d)
end end
plt = Plot(wrap, pkg, 0, d, Dict[]) plt = Plot(wrap, pkg, 0, d, KW[])
plt plt
end end
@ -337,7 +337,7 @@ function _add_series(pkg::PyPlotBackend, plt::Plot; kw...)
end end
# lt = d[:linetype] # lt = d[:linetype]
extra_kwargs = Dict() extra_kwargs = KW()
plotfunc = getPyPlotFunction(plt, d[:axis], lt) plotfunc = getPyPlotFunction(plt, d[:axis], lt)
@ -609,7 +609,7 @@ end
usingRightAxis(plt::Plot{PyPlotBackend}) = any(args -> args[:axis] in (:right,:auto), plt.seriesargs) usingRightAxis(plt::Plot{PyPlotBackend}) = any(args -> args[:axis] in (:right,:auto), plt.seriesargs)
function _update_plot(plt::Plot{PyPlotBackend}, d::Dict) function _update_plot(plt::Plot{PyPlotBackend}, d::KW)
figorax = plt.o figorax = plt.o
ax = getLeftAxis(figorax) ax = getLeftAxis(figorax)
# PyPlot.sca(ax) # PyPlot.sca(ax)
@ -745,7 +745,7 @@ end
# this will be called internally, when creating a subplot from existing plots # this will be called internally, when creating a subplot from existing plots
# NOTE: if I ever need to "Rebuild a "ubplot from individual Plot's"... this is what I should use! # NOTE: if I ever need to "Rebuild a "ubplot from individual Plot's"... this is what I should use!
function subplot(plts::AVec{Plot{PyPlotBackend}}, layout::SubplotLayout, d::Dict) function subplot(plts::AVec{Plot{PyPlotBackend}}, layout::SubplotLayout, d::KW)
validateSubplotSupported() validateSubplotSupported()
p = length(layout) p = length(layout)
@ -786,7 +786,7 @@ end
# ----------------------------------------------------------------- # -----------------------------------------------------------------
const _pyplot_legend_pos = Dict( const _pyplot_legend_pos = KW(
:right => "right", :right => "right",
:left => "center left", :left => "center left",
:top => "upper center", :top => "upper center",
@ -877,7 +877,7 @@ end
# end # end
# end # end
const _pyplot_mimeformats = @compat Dict( const _pyplot_mimeformats = Dict(
"application/eps" => "eps", "application/eps" => "eps",
"image/eps" => "eps", "image/eps" => "eps",
"application/pdf" => "pdf", "application/pdf" => "pdf",

View File

@ -11,7 +11,7 @@ end
# ------------------------------- # -------------------------------
@compat const _qwtAliases = Dict( @compat const _qwtAliases = KW(
:nbins => :heatmap_n, :nbins => :heatmap_n,
:fillrange => :fillto, :fillrange => :fillto,
:linewidth => :width, :linewidth => :width,
@ -24,7 +24,7 @@ end
:star8 => :star2, :star8 => :star2,
) )
function fixcolors(d::Dict) function fixcolors(d::KW)
for (k,v) in d for (k,v) in d
if typeof(v) <: ColorScheme if typeof(v) <: ColorScheme
d[k] = getColor(v) d[k] = getColor(v)
@ -82,7 +82,7 @@ function _create_plot(pkg::QwtBackend; kw...)
fixcolors(d) fixcolors(d)
dumpdict(d,"\n\n!!! plot") dumpdict(d,"\n\n!!! plot")
o = Qwt.plot(zeros(0,0); d..., show=false) o = Qwt.plot(zeros(0,0); d..., show=false)
plt = Plot(o, pkg, 0, d, Dict[]) plt = Plot(o, pkg, 0, d, KW[])
plt plt
end end
@ -98,7 +98,7 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function updateLimsAndTicks(plt::Plot{QwtBackend}, d::Dict, isx::Bool) function updateLimsAndTicks(plt::Plot{QwtBackend}, d::KW, isx::Bool)
lims = get(d, isx ? :xlims : :ylims, nothing) lims = get(d, isx ? :xlims : :ylims, nothing)
ticks = get(d, isx ? :xticks : :yticks, nothing) ticks = get(d, isx ? :xticks : :yticks, nothing)
w = plt.o.widget w = plt.o.widget
@ -138,7 +138,7 @@ function updateLimsAndTicks(plt::Plot{QwtBackend}, d::Dict, isx::Bool)
end end
function _update_plot(plt::Plot{QwtBackend}, d::Dict) function _update_plot(plt::Plot{QwtBackend}, d::KW)
haskey(d, :title) && Qwt.title(plt.o, d[:title]) haskey(d, :title) && Qwt.title(plt.o, d[:title])
haskey(d, :xlabel) && Qwt.xlabel(plt.o, d[:xlabel]) haskey(d, :xlabel) && Qwt.xlabel(plt.o, d[:xlabel])
haskey(d, :ylabel) && Qwt.ylabel(plt.o, d[:ylabel]) haskey(d, :ylabel) && Qwt.ylabel(plt.o, d[:ylabel])
@ -146,7 +146,7 @@ function _update_plot(plt::Plot{QwtBackend}, d::Dict)
updateLimsAndTicks(plt, d, false) updateLimsAndTicks(plt, d, false)
end end
function _update_plot_pos_size(plt::AbstractPlot{QwtBackend}, d::Dict) function _update_plot_pos_size(plt::AbstractPlot{QwtBackend}, d::KW)
haskey(d, :size) && Qwt.resizewidget(plt.o, d[:size]...) haskey(d, :size) && Qwt.resizewidget(plt.o, d[:size]...)
haskey(d, :pos) && Qwt.movewidget(plt.o, d[:pos]...) haskey(d, :pos) && Qwt.movewidget(plt.o, d[:pos]...)
end end
@ -155,7 +155,7 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
# curve.setPen(Qt.QPen(Qt.QColor(color), linewidth, self.getLineStyle(linestyle))) # curve.setPen(Qt.QPen(Qt.QColor(color), linewidth, self.getLineStyle(linestyle)))
function addLineMarker(plt::Plot{QwtBackend}, d::Dict) function addLineMarker(plt::Plot{QwtBackend}, d::KW)
for yi in d[:y] for yi in d[:y]
marker = Qwt.QWT.QwtPlotMarker() marker = Qwt.QWT.QwtPlotMarker()
ishorizontal = (d[:linetype] == :hline) ishorizontal = (d[:linetype] == :hline)
@ -279,4 +279,3 @@ function Base.display(::PlotsDisplay, subplt::Subplot{QwtBackend})
end end
Qwt.showwidget(subplt.o) Qwt.showwidget(subplt.o)
end end

View File

@ -18,7 +18,7 @@ function _create_plot(pkg::[PkgName]AbstractBackend; kw...)
d = KW(kw) d = KW(kw)
# TODO: create the window/canvas/context that is the plot within the backend (call it `o`) # TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# TODO: initialize the plot... title, xlabel, bgcolor, etc # TODO: initialize the plot... title, xlabel, bgcolor, etc
Plot(nothing, pkg, 0, d, Dict[]) Plot(nothing, pkg, 0, d, KW[])
end end
@ -41,10 +41,10 @@ function _before_update_plot(plt::Plot{[PkgName]AbstractBackend})
end end
# TODO: override this to update plot items (title, xlabel, etc) after creation # TODO: override this to update plot items (title, xlabel, etc) after creation
function _update_plot(plt::Plot{[PkgName]AbstractBackend}, d::Dict) function _update_plot(plt::Plot{[PkgName]AbstractBackend}, d::KW)
end end
function _update_plot_pos_size(plt::AbstractPlot{[PkgName]AbstractBackend}, d::Dict) function _update_plot_pos_size(plt::AbstractPlot{[PkgName]AbstractBackend}, d::KW)
end end
# ---------------------------------------------------------------- # ----------------------------------------------------------------

View File

@ -68,7 +68,7 @@ end
# add a single series # add a single series
function addUnicodeSeries!(o, d::Dict, addlegend::Bool, xlim, ylim) function addUnicodeSeries!(o, d::KW, addlegend::Bool, xlim, ylim)
# get the function, or special handling for step/bar/hist # get the function, or special handling for step/bar/hist
lt = d[:linetype] lt = d[:linetype]
@ -111,7 +111,7 @@ function addUnicodeSeries!(o, d::Dict, addlegend::Bool, xlim, ylim)
end end
function handlePlotColors(::UnicodePlotsBackend, d::Dict) function handlePlotColors(::UnicodePlotsBackend, d::KW)
# TODO: something special for unicodeplots, since it doesn't take kindly to people messing with its color palette # TODO: something special for unicodeplots, since it doesn't take kindly to people messing with its color palette
d[:color_palette] = [RGB(0,0,0)] d[:color_palette] = [RGB(0,0,0)]
end end
@ -120,7 +120,7 @@ end
function _create_plot(pkg::UnicodePlotsBackend; kw...) function _create_plot(pkg::UnicodePlotsBackend; kw...)
plt = Plot(nothing, pkg, 0, KW(kw), Dict[]) plt = Plot(nothing, pkg, 0, KW(kw), KW[])
# do we want to give a new default size? # do we want to give a new default size?
if !haskey(plt.plotargs, :size) || plt.plotargs[:size] == _plotDefaults[:size] if !haskey(plt.plotargs, :size) || plt.plotargs[:size] == _plotDefaults[:size]
@ -142,7 +142,7 @@ function _add_series(::UnicodePlotsBackend, plt::Plot; kw...)
end end
function _update_plot(plt::Plot{UnicodePlotsBackend}, d::Dict) function _update_plot(plt::Plot{UnicodePlotsBackend}, d::KW)
for k in (:title, :xlabel, :ylabel, :xlims, :ylims) for k in (:title, :xlabel, :ylabel, :xlims, :ylims)
if haskey(d, k) if haskey(d, k)
plt.plotargs[k] = d[k] plt.plotargs[k] = d[k]
@ -200,4 +200,3 @@ function Base.display(::PlotsDisplay, subplt::Subplot{UnicodePlotsBackend})
gui(plt) gui(plt)
end end
end end

View File

@ -16,13 +16,13 @@ end
## dictionaries for conversion of Plots.jl names to Winston ones. ## dictionaries for conversion of Plots.jl names to Winston ones.
@compat const winston_linestyle = Dict(:solid=>"solid", @compat const winston_linestyle = KW(:solid=>"solid",
:dash=>"dash", :dash=>"dash",
:dot=>"dotted", :dot=>"dotted",
:dashdot=>"dotdashed" :dashdot=>"dotdashed"
) )
@compat const winston_marker = Dict(:none=>".", @compat const winston_marker = KW(:none=>".",
:rect => "square", :rect => "square",
:ellipse=>"circle", :ellipse=>"circle",
:diamond=>"diamond", :diamond=>"diamond",
@ -44,12 +44,12 @@ function _create_plot(pkg::WinstonBackend; kw...)
d = KW(kw) d = KW(kw)
wplt = Winston.FramedPlot(title = d[:title], xlabel = d[:xlabel], ylabel = d[:ylabel]) wplt = Winston.FramedPlot(title = d[:title], xlabel = d[:xlabel], ylabel = d[:ylabel])
Plot(wplt, pkg, 0, d, Dict[]) Plot(wplt, pkg, 0, d, KW[])
end end
copy_remove(d::Dict, s::Symbol) = delete!(copy(d), s) copy_remove(d::KW, s::Symbol) = delete!(copy(d), s)
function addRegressionLineWinston(d::Dict, wplt) function addRegressionLineWinston(d::KW, wplt)
xs, ys = regressionXY(d[:x], d[:y]) xs, ys = regressionXY(d[:x], d[:y])
Winston.add(wplt, Winston.Curve(xs, ys, kind="dotted")) Winston.add(wplt, Winston.Curve(xs, ys, kind="dotted"))
end end
@ -75,7 +75,7 @@ function _add_series(::WinstonBackend, plt::Plot; kw...)
end end
e = Dict() e = KW()
e[:color] = getColor(d[:linecolor]) e[:color] = getColor(d[:linecolor])
e[:linewidth] = d[:linewidth] e[:linewidth] = d[:linewidth]
e[:kind] = winston_linestyle[d[:linestyle]] e[:kind] = winston_linestyle[d[:linestyle]]
@ -158,14 +158,14 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
@compat const _winstonNames = Dict( @compat const _winstonNames = KW(
:xlims => :xrange, :xlims => :xrange,
:ylims => :yrange, :ylims => :yrange,
:xscale => :xlog, :xscale => :xlog,
:yscale => :ylog, :yscale => :ylog,
) )
function _update_plot(plt::Plot{WinstonBackend}, d::Dict) function _update_plot(plt::Plot{WinstonBackend}, d::KW)
window, canvas, wplt = getWinstonItems(plt) window, canvas, wplt = getWinstonItems(plt)
for k in (:xlabel, :ylabel, :title, :xlims, :ylims) for k in (:xlabel, :ylabel, :title, :xlims, :ylims)
if haskey(d, k) if haskey(d, k)

View File

@ -73,7 +73,7 @@ function makecross(; offset = -0.5, radius = 1.0)
end end
const _shapes = @compat Dict( const _shapes = KW(
:ellipse => makeshape(20), :ellipse => makeshape(20),
:rect => makeshape(4, offset=-0.25), :rect => makeshape(4, offset=-0.25),
:diamond => makeshape(4), :diamond => makeshape(4),