From 5efb0eb58250802cbad6b1056111ab3b3798fbbb Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Thu, 17 Mar 2016 22:11:29 -0400 Subject: [PATCH] more Dict to KW renaming --- src/backends/bokeh.jl | 22 ++++++++--------- src/backends/gadfly.jl | 42 ++++++++++++++++---------------- src/backends/glvisualize.jl | 6 ++--- src/backends/immerse.jl | 6 ++--- src/backends/pgfplots.jl | 10 ++++---- src/backends/plotly.jl | 46 ++++++++++++++++++------------------ src/backends/plotlyjs.jl | 8 +++---- src/backends/pyplot.jl | 20 ++++++++-------- src/backends/qwt.jl | 21 ++++++++-------- src/backends/template.jl | 6 ++--- src/backends/unicodeplots.jl | 9 ++++--- src/backends/winston.jl | 18 +++++++------- src/components.jl | 2 +- 13 files changed, 107 insertions(+), 109 deletions(-) diff --git a/src/backends/bokeh.jl b/src/backends/bokeh.jl index 3bf86195..db309f6a 100644 --- a/src/backends/bokeh.jl +++ b/src/backends/bokeh.jl @@ -18,23 +18,23 @@ end # bokehcolor(cs::ColorScheme) = bokehcolor(getColor(cs)) -const _glyphtypes = Dict( +const _glyphtypes = KW( :ellipse => :Circle, :rect => :Square, :diamond => :Diamond, :utriangle => :Triangle, :dtriangle => :InvertedTriangle, - # :pentagon => - # :hexagon => - # :heptagon => - # :octagon => + # :pentagon => + # :hexagon => + # :heptagon => + # :octagon => :cross => :Cross, :xcross => :X, :star5 => :Asterisk, ) -function bokeh_glyph_type(d::Dict) +function bokeh_glyph_type(d::KW) lt = d[:linetype] mt = d[:markershape] if lt == :scatter && mt == :none @@ -81,10 +81,10 @@ function _create_plot(pkg::BokehBackend; kw...) yaxis_type = d[:yscale] == :log10 ? :log : :auto # legend = d[:legend] ? xxxx : 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) - Plot(bplt, pkg, 0, d, Dict[]) + Plot(bplt, pkg, 0, d, KW[]) end @@ -94,7 +94,7 @@ function _add_series(::BokehBackend, plt::Plot; kw...) # dumpdict(d, "plot!", true) bdata = Dict{Symbol, Vector}(:x => collect(d[:x]), :y => collect(d[:y])) - + glyph = Bokeh.Bokehjs.Glyph( glyphtype = bokeh_glyph_type(d), linecolor = webcolor(d[:linecolor]), # shape's stroke or line color @@ -114,10 +114,10 @@ end # ---------------------------------------------------------------- # 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 -function _update_plot_pos_size(plt::AbstractPlot{BokehBackend}, d::Dict) +function _update_plot_pos_size(plt::AbstractPlot{BokehBackend}, d::KW) end # ---------------------------------------------------------------- diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index b2d4da35..d074620e 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -16,7 +16,7 @@ end # Base.size(v::MissingVec) = (1,) # Base.getindex(v::MissingVec, i::Integer) = 0.0 -function createGadflyPlotObject(d::Dict) +function createGadflyPlotObject(d::KW) gplt = Gadfly.Plot() gplt.mapping = Dict() gplt.data_source = Gadfly.DataFrames.DataFrame() @@ -31,7 +31,7 @@ end # --------------------------------------------------------------------------- -function getLineGeom(d::Dict) +function getLineGeom(d::KW) lt = d[:linetype] xbins, ybins = maketuple(d[:nbins]) if lt == :hexb @@ -61,9 +61,9 @@ function getLineGeom(d::Dict) 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 - extra_theme_args = Dict() + extra_theme_args = KW() try extra_theme_args[:line_style] = Gadfly.get_stroke_vector(d[k]) catch err @@ -76,7 +76,7 @@ function get_extra_theme_args(d::Dict, k::Symbol) extra_theme_args end -function getGadflyLineTheme(d::Dict) +function getGadflyLineTheme(d::KW) lc = convertColor(getColor(d[:linecolor]), d[:linealpha]) fc = convertColor(getColor(d[:fillcolor]), d[:fillalpha]) @@ -92,10 +92,10 @@ function getGadflyLineTheme(d::Dict) end # 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) gfargs = vcat(geoms..., getGadflyLineTheme(d)) - kwargs = Dict() + kwargs = KW() lt = d[:linetype] # add a fill? @@ -136,7 +136,7 @@ end getMarkerGeom(shape::Shape) = gadflyshape(shape) getMarkerGeom(shape::Symbol) = gadflyshape(_shapes[shape]) getMarkerGeom(shapes::AVec) = map(getMarkerGeom, shapes) -function getMarkerGeom(d::Dict) +function getMarkerGeom(d::KW) if d[:linetype] == :shape Gadfly.Geom.polygon(fill = true, preserve_order = true) else @@ -144,7 +144,7 @@ function getMarkerGeom(d::Dict) end end -function getGadflyMarkerTheme(d::Dict, plotargs::Dict) +function getGadflyMarkerTheme(d::KW, plotargs::KW) c = getColor(d[:markercolor]) α = d[:markeralpha] if α != nothing @@ -177,9 +177,9 @@ function addGadflyContColorScale(plt::Plot{GadflyBackend}, c) push!(getGadflyContext(plt).scales, Gadfly.Scale.ContinuousColorScale(p -> RGB(getColorZ(c, p)))) 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)) - kwargs = Dict() + kwargs = KW() # handle continuous color scales for the markers 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] != "" 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))] -function addGadflySeries!(plt::Plot, d::Dict) +function addGadflySeries!(plt::Plot, d::KW) layers = Gadfly.Layer[] 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) -function getGadflyScaleFunction(d::Dict, isx::Bool) +function getGadflyScaleFunction(d::KW, isx::Bool) scalekey = isx ? :xscale : :yscale hasScaleKey = haskey(d, scalekey) if hasScaleKey @@ -351,7 +351,7 @@ function getGadflyScaleFunction(d::Dict, isx::Bool) end -function addGadflyLimitsScale(gplt, d::Dict, isx::Bool) +function addGadflyLimitsScale(gplt, d::KW, isx::Bool) gfunc, hasScaleKey = getGadflyScaleFunction(d, isx) # do we want to add min/max limits for the axis? @@ -380,7 +380,7 @@ function addGadflyLimitsScale(gplt, d::Dict, isx::Bool) lims end -function updateGadflyAxisFlips(gplt, d::Dict, xlims, ylims) +function updateGadflyAxisFlips(gplt, d::KW, xlims, ylims) if isa(gplt.coord, Gadfly.Coord.Cartesian) gplt.coord = Gadfly.Coord.cartesian( gplt.coord.xvars, @@ -412,7 +412,7 @@ function findGuideAndSet(gplt, t::DataType, args...; kw...) #s::@compat(Abstract end end -function updateGadflyGuides(plt::Plot, d::Dict) +function updateGadflyGuides(plt::Plot, d::KW) gplt = getGadflyContext(plt) haskey(d, :title) && findGuideAndSet(gplt, Gadfly.Guide.title, string(d[:title])) 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) end -function updateGadflyPlotTheme(plt::Plot, d::Dict) - kwargs = Dict() +function updateGadflyPlotTheme(plt::Plot, d::KW) + kwargs = KW() # # hide the legend? leg = d[d[:legend] == :none ? :colorbar : :legend] @@ -510,7 +510,7 @@ end function _create_plot(pkg::GadflyBackend; kw...) d = KW(kw) gplt = createGadflyPlotObject(d) - Plot(gplt, pkg, 0, d, Dict[]) + Plot(gplt, pkg, 0, d, KW[]) 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) updateGadflyPlotTheme(plt, d) end diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index 590c83f0..61202590 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -23,7 +23,7 @@ function _create_plot(pkg::GLVisualizeBackend; kw...) # TODO: this should be moved to the display method? w=GLVisualize.glscreen() @async GLVisualize.renderloop(w) - Plot(GLScreenWrapper(w), pkg, 0, d, Dict[]) + Plot(GLScreenWrapper(w), pkg, 0, d, KW[]) end @@ -49,10 +49,10 @@ function _before_update_plot(plt::Plot{GLVisualizeBackend}) end # 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 -function _update_plot_pos_size(plt::AbstractPlot{GLVisualizeBackend}, d::Dict) +function _update_plot_pos_size(plt::AbstractPlot{GLVisualizeBackend}, d::KW) end # ---------------------------------------------------------------- diff --git a/src/backends/immerse.jl b/src/backends/immerse.jl index b921a89a..da72ebbb 100644 --- a/src/backends/immerse.jl +++ b/src/backends/immerse.jl @@ -9,7 +9,7 @@ function _initialize_backend(::ImmerseBackend; kw...) end end -function createImmerseFigure(d::Dict) +function createImmerseFigure(d::KW) w,h = d[:size] figidx = Immerse.figure(; name = d[:windowtitle], width = w, height = h) Immerse.Figure(figidx) @@ -26,7 +26,7 @@ function _create_plot(pkg::ImmerseBackend; kw...) gplt = createGadflyPlotObject(d) # save both the Immerse.Figure and the Gadfly.Plot - Plot((nothing,gplt), pkg, 0, d, Dict[]) + Plot((nothing,gplt), pkg, 0, d, KW[]) end @@ -39,7 +39,7 @@ function _add_series(::ImmerseBackend, plt::Plot; kw...) end -function _update_plot(plt::Plot{ImmerseBackend}, d::Dict) +function _update_plot(plt::Plot{ImmerseBackend}, d::KW) updateGadflyGuides(plt, d) updateGadflyPlotTheme(plt, d) end diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 1b71568a..94a12642 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -13,15 +13,15 @@ end # --------------------------------------------------------------------------- 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: initialize the plot... title, xlabel, bgcolor, etc - Plot(nothing, pkg, 0, d, Dict[]) + Plot(nothing, pkg, 0, d, KW[]) end function _add_series(::PGFPlotsBackend, plt::Plot; kw...) - d = Dict{Symbol,Any}(kw) + d = KW(kw) # TODO: add one series to the underlying package push!(plt.seriesargs, d) plt @@ -42,10 +42,10 @@ function _before_update_plot(plt::Plot{PGFPlotsBackend}) end # 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 -function _update_plot_pos_size(plt::AbstractPlot{PGFPlotsBackend}, d::Dict) +function _update_plot_pos_size(plt::AbstractPlot{PGFPlotsBackend}, d::KW) end # ---------------------------------------------------------------- diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 4fed40db..a8ed9bb4 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -38,15 +38,15 @@ end # --------------------------------------------------------------------------- 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: initialize the plot... title, xlabel, bgcolor, etc - Plot(nothing, pkg, 0, d, Dict[]) + Plot(nothing, pkg, 0, d, KW[]) end function _add_series(::PlotlyBackend, plt::Plot; kw...) - d = Dict{Symbol,Any}(kw) + d = KW(kw) # TODO: add one series to the underlying package push!(plt.seriesargs, d) plt @@ -67,10 +67,10 @@ function _before_update_plot(plt::Plot{PlotlyBackend}) end # 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 -function _update_plot_pos_size(plt::AbstractPlot{PlotlyBackend}, d::Dict) +function _update_plot_pos_size(plt::AbstractPlot{PlotlyBackend}, d::KW) end # ---------------------------------------------------------------- @@ -117,7 +117,7 @@ end # _plotDefaults[:yflip] = false function plotlyfont(font::Font, color = font.color) - Dict{Symbol,Any}( + KW( :family => font.family, :size => round(Int, font.pointsize*1.4), :color => webcolor(color), @@ -125,7 +125,7 @@ function plotlyfont(font::Font, color = font.color) end function get_annotation_dict(x, y, val::Union{AbstractString,Symbol}) - Dict{Symbol,Any}( + KW( :text => val, :xref => "x", :x => x, @@ -136,7 +136,7 @@ function get_annotation_dict(x, y, val::Union{AbstractString,Symbol}) end 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), :xanchor => ptxt.font.halign == :hcenter ? :center : ptxt.font.halign, :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") labelsym(isx::Bool) = symbol((isx ? "x" : "y") * "label") -function plotlyaxis(d::Dict, isx::Bool) - ax = Dict{Symbol,Any}( +function plotlyaxis(d::KW, isx::Bool) + ax = KW( :title => d[labelsym(isx)], :showgrid => d[:grid], :zeroline => false, @@ -212,8 +212,8 @@ end # function get_plot_json(plt::Plot{PlotlyBackend}) # d = plt.plotargs -function plotly_layout(d::Dict) - d_out = Dict{Symbol,Any}() +function plotly_layout(d::KW) + d_out = KW() bgcolor = webcolor(d[:background_color]) fgcolor = webcolor(d[:foreground_color]) @@ -221,7 +221,7 @@ function plotly_layout(d::Dict) # set the fields for the plot d_out[:title] = d[:title] 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[:paper_bgcolor] = bgcolor @@ -232,7 +232,7 @@ function plotly_layout(d::Dict) # legend d_out[:showlegend] = d[:legend] != :none if d[:legend] != :none - d_out[:legend] = Dict{Symbol,Any}( + d_out[:legend] = KW( :bgcolor => bgcolor, :bordercolor => fgcolor, :font => plotlyfont(d[:legendfont]), @@ -258,7 +258,7 @@ function plotly_colorscale(grad::ColorGradient, alpha = nothing) end plotly_colorscale(c, alpha = nothing) = plotly_colorscale(ColorGradient(:bluesreds), alpha) -const _plotly_markers = Dict{Symbol,Any}( +const _plotly_markers = KW( :rect => "square", :xcross => "x", :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) -function plotly_series(d::Dict; plot_index = nothing) - d_out = Dict{Symbol,Any}() +function plotly_series(d::KW; plot_index = nothing) + d_out = KW() x, y = collect(d[:x]), collect(d[:y]) 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[:showscale] = d[:colorbar] != :none 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]) elseif lt in (:surface, :wireframe) @@ -359,17 +359,17 @@ function plotly_series(d::Dict; plot_index = nothing) else warn("Plotly: linetype $lt isn't supported.") - return Dict{Symbol,Any}() + return KW() end # add "marker" if hasmarker - d_out[:marker] = Dict{Symbol,Any}( + d_out[:marker] = KW( :symbol => get(_plotly_markers, d[:markershape], string(d[:markershape])), :opacity => d[:markeralpha], :size => 2 * d[:markersize], :color => webcolor(d[:markercolor], d[:markeralpha]), - :line => Dict{Symbol,Any}( + :line => KW( :color => webcolor(d[:markerstrokecolor], d[:markerstrokealpha]), :width => d[:markerstrokewidth], ), @@ -389,7 +389,7 @@ function plotly_series(d::Dict; plot_index = nothing) # add "line" if hasline - d_out[:line] = Dict{Symbol,Any}( + d_out[:line] = KW( :color => webcolor(d[:linecolor], d[:linealpha]), :width => d[:linewidth], :shape => if lt == :steppre @@ -419,7 +419,7 @@ function get_series_json(plt::Plot{PlotlyBackend}) end function get_series_json(subplt::Subplot{PlotlyBackend}) - ds = Dict[] + ds = KW[] for (i,plt) in enumerate(subplt.plts) for d in plt.seriesargs push!(ds, plotly_series(d, plot_index = i)) diff --git a/src/backends/plotlyjs.jl b/src/backends/plotlyjs.jl index 64cd0cf2..cf7719c4 100644 --- a/src/backends/plotlyjs.jl +++ b/src/backends/plotlyjs.jl @@ -29,7 +29,7 @@ function _create_plot(pkg::PlotlyJSBackend; kw...) # o = T(PlotlyJS.Plot()) o = PlotlyJS.plot() - Plot(o, pkg, 0, d, Dict[]) + Plot(o, pkg, 0, d, KW[]) end @@ -68,7 +68,7 @@ function _before_update_plot(plt::Plot{PlotlyJSBackend}) end # 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) # dumpdict(pdict, "pdict updateplot", true) syncplot = plt.o @@ -78,7 +78,7 @@ function _update_plot(plt::Plot{PlotlyJSBackend}, d::Dict) end -function _update_plot_pos_size(plt::AbstractPlot{PlotlyJSBackend}, d::Dict) +function _update_plot_pos_size(plt::AbstractPlot{PlotlyJSBackend}, d::KW) end # ---------------------------------------------------------------- @@ -95,7 +95,7 @@ function Base.setindex!(plt::Plot{PlotlyJSBackend}, xy::Tuple, i::Integer) d[:x], d[:y] = xy # 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, Dict(:x=>(d[:x],), :y=>(d[:y],))) + PlotlyJS.restyle!(plt.o, i, KW(:x=>(d[:x],), :y=>(d[:y],))) plt end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 6ec70367..c4a664a4 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -164,7 +164,7 @@ function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol) # in the 2-axis case we need to get: [:] ax = getAxis(plt, axis) # ax[:set_ylabel](plt.plotargs[:yrightlabel]) - fmap = @compat Dict( + fmap = KW( :hist => :hist, :density => :hist, :sticks => :bar, @@ -196,7 +196,7 @@ function updateAxisColors(ax, fgcolor) end -function handleSmooth(plt::Plot{PyPlotBackend}, ax, d::Dict, smooth::Bool) +function handleSmooth(plt::Plot{PyPlotBackend}, ax, d::KW, smooth::Bool) if smooth xs, ys = regressionXY(d[:x], d[:y]) ax[:plot](xs, ys, @@ -206,7 +206,7 @@ function handleSmooth(plt::Plot{PyPlotBackend}, ax, d::Dict, smooth::Bool) ) 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]) bgcolor = getPyPlotColor(plotargs[:background_color]) @@ -284,7 +284,7 @@ function _create_plot(pkg::PyPlotBackend; kw...) pyplot_3d_setup!(wrap, d) end - plt = Plot(wrap, pkg, 0, d, Dict[]) + plt = Plot(wrap, pkg, 0, d, KW[]) plt end @@ -337,7 +337,7 @@ function _add_series(pkg::PyPlotBackend, plt::Plot; kw...) end # lt = d[:linetype] - extra_kwargs = Dict() + extra_kwargs = KW() plotfunc = getPyPlotFunction(plt, d[:axis], lt) @@ -609,7 +609,7 @@ end 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 ax = getLeftAxis(figorax) # PyPlot.sca(ax) @@ -745,7 +745,7 @@ end # 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! -function subplot(plts::AVec{Plot{PyPlotBackend}}, layout::SubplotLayout, d::Dict) +function subplot(plts::AVec{Plot{PyPlotBackend}}, layout::SubplotLayout, d::KW) validateSubplotSupported() p = length(layout) @@ -786,7 +786,7 @@ end # ----------------------------------------------------------------- -const _pyplot_legend_pos = Dict( +const _pyplot_legend_pos = KW( :right => "right", :left => "center left", :top => "upper center", @@ -877,7 +877,7 @@ end # end # end -const _pyplot_mimeformats = @compat Dict( +const _pyplot_mimeformats = Dict( "application/eps" => "eps", "image/eps" => "eps", "application/pdf" => "pdf", diff --git a/src/backends/qwt.jl b/src/backends/qwt.jl index 466b5620..bbd6a9ba 100644 --- a/src/backends/qwt.jl +++ b/src/backends/qwt.jl @@ -11,7 +11,7 @@ end # ------------------------------- -@compat const _qwtAliases = Dict( +@compat const _qwtAliases = KW( :nbins => :heatmap_n, :fillrange => :fillto, :linewidth => :width, @@ -24,7 +24,7 @@ end :star8 => :star2, ) -function fixcolors(d::Dict) +function fixcolors(d::KW) for (k,v) in d if typeof(v) <: ColorScheme d[k] = getColor(v) @@ -73,7 +73,7 @@ function adjustQwtKeywords(plt::Plot{QwtBackend}, iscreating::Bool; kw...) d[:x] = collect(d[:x]) d[:y] = collect(d[:y]) - + d end @@ -82,7 +82,7 @@ function _create_plot(pkg::QwtBackend; kw...) fixcolors(d) dumpdict(d,"\n\n!!! plot") o = Qwt.plot(zeros(0,0); d..., show=false) - plt = Plot(o, pkg, 0, d, Dict[]) + plt = Plot(o, pkg, 0, d, KW[]) plt end @@ -98,12 +98,12 @@ 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) ticks = get(d, isx ? :xticks : :yticks, nothing) w = plt.o.widget - axisid = Qwt.QWT.QwtPlot[isx ? :xBottom : :yLeft] - + axisid = Qwt.QWT.QwtPlot[isx ? :xBottom : :yLeft] + if typeof(lims) <: @compat(Union{Tuple,AVec}) && length(lims) == 2 if isx plt.o.autoscale_x = false @@ -138,7 +138,7 @@ function updateLimsAndTicks(plt::Plot{QwtBackend}, d::Dict, isx::Bool) 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, :xlabel) && Qwt.xlabel(plt.o, d[:xlabel]) 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) 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, :pos) && Qwt.movewidget(plt.o, d[:pos]...) end @@ -155,7 +155,7 @@ end # ---------------------------------------------------------------- # 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] marker = Qwt.QWT.QwtPlotMarker() ishorizontal = (d[:linetype] == :hline) @@ -279,4 +279,3 @@ function Base.display(::PlotsDisplay, subplt::Subplot{QwtBackend}) end Qwt.showwidget(subplt.o) end - diff --git a/src/backends/template.jl b/src/backends/template.jl index 48edf7cf..21c225ca 100644 --- a/src/backends/template.jl +++ b/src/backends/template.jl @@ -18,7 +18,7 @@ function _create_plot(pkg::[PkgName]AbstractBackend; kw...) d = KW(kw) # TODO: create the window/canvas/context that is the plot within the backend (call it `o`) # TODO: initialize the plot... title, xlabel, bgcolor, etc - Plot(nothing, pkg, 0, d, Dict[]) + Plot(nothing, pkg, 0, d, KW[]) end @@ -41,10 +41,10 @@ function _before_update_plot(plt::Plot{[PkgName]AbstractBackend}) end # 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 -function _update_plot_pos_size(plt::AbstractPlot{[PkgName]AbstractBackend}, d::Dict) +function _update_plot_pos_size(plt::AbstractPlot{[PkgName]AbstractBackend}, d::KW) end # ---------------------------------------------------------------- diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index c62456f5..8c3b5d2d 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -68,7 +68,7 @@ end # 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 lt = d[:linetype] @@ -111,7 +111,7 @@ function addUnicodeSeries!(o, d::Dict, addlegend::Bool, xlim, ylim) 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 d[:color_palette] = [RGB(0,0,0)] end @@ -120,7 +120,7 @@ end 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? if !haskey(plt.plotargs, :size) || plt.plotargs[:size] == _plotDefaults[:size] @@ -142,7 +142,7 @@ function _add_series(::UnicodePlotsBackend, plt::Plot; kw...) 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) if haskey(d, k) plt.plotargs[k] = d[k] @@ -200,4 +200,3 @@ function Base.display(::PlotsDisplay, subplt::Subplot{UnicodePlotsBackend}) gui(plt) end end - diff --git a/src/backends/winston.jl b/src/backends/winston.jl index bea15099..fd55fd8f 100644 --- a/src/backends/winston.jl +++ b/src/backends/winston.jl @@ -16,13 +16,13 @@ end ## 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", :dot=>"dotted", :dashdot=>"dotdashed" ) -@compat const winston_marker = Dict(:none=>".", +@compat const winston_marker = KW(:none=>".", :rect => "square", :ellipse=>"circle", :diamond=>"diamond", @@ -43,13 +43,13 @@ end function _create_plot(pkg::WinstonBackend; kw...) d = KW(kw) 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 -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]) Winston.add(wplt, Winston.Curve(xs, ys, kind="dotted")) end @@ -75,7 +75,7 @@ function _add_series(::WinstonBackend, plt::Plot; kw...) end - e = Dict() + e = KW() e[:color] = getColor(d[:linecolor]) e[:linewidth] = d[:linewidth] e[:kind] = winston_linestyle[d[:linestyle]] @@ -158,14 +158,14 @@ end # ---------------------------------------------------------------- -@compat const _winstonNames = Dict( +@compat const _winstonNames = KW( :xlims => :xrange, :ylims => :yrange, :xscale => :xlog, :yscale => :ylog, ) -function _update_plot(plt::Plot{WinstonBackend}, d::Dict) +function _update_plot(plt::Plot{WinstonBackend}, d::KW) window, canvas, wplt = getWinstonItems(plt) for k in (:xlabel, :ylabel, :title, :xlims, :ylims) if haskey(d, k) diff --git a/src/components.jl b/src/components.jl index 9a676336..71e9f0b9 100644 --- a/src/components.jl +++ b/src/components.jl @@ -73,7 +73,7 @@ function makecross(; offset = -0.5, radius = 1.0) end -const _shapes = @compat Dict( +const _shapes = KW( :ellipse => makeshape(20), :rect => makeshape(4, offset=-0.25), :diamond => makeshape(4),