working on aliases

This commit is contained in:
Thomas Breloff 2015-09-21 14:38:03 -04:00
parent 031058cd0c
commit 86a56e487a
8 changed files with 177 additions and 76 deletions

View File

@ -51,7 +51,7 @@ const examples = PlotExample[
[:(heatmap(randn(10000),randn(10000); nbins=100))]), [:(heatmap(randn(10000),randn(10000); nbins=100))]),
PlotExample("Line types", PlotExample("Line types",
"", "",
[:(types = intersect(supportedTypes(), [:line, :step, :stepinverted, :sticks, :scatter])), [:(types = intersect(supportedTypes(), [:line, :path, :steppre, :steppost, :sticks, :scatter])),
:(n = length(types)), :(n = length(types)),
:(x = Vector[sort(rand(20)) for i in 1:n]), :(x = Vector[sort(rand(20)) for i in 1:n]),
:(y = rand(20,n)), :(y = rand(20,n)),

0
docs/readme_template.md Normal file
View File

View File

@ -38,6 +38,7 @@ export
savepng, savepng,
backends, backends,
aliases,
supportedArgs, supportedArgs,
supportedAxes, supportedAxes,

View File

@ -1,10 +1,73 @@
const _allAxes = [:auto, :left, :right] const _allAxes = [:auto, :left, :right]
const _allTypes = [:none, :line, :step, :stepinverted, :sticks, :scatter, const _axesAliases = Dict(
:a => :auto,
:l => :left,
:r => :right
)
const _allTypes = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter,
:heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc] :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc]
const _typeAliases = Dict(
:n => :none,
:no => :none,
:l => :line,
:p => :path,
:stepinv => :steppre,
:stepinverted => :steppre,
:step => :steppost,
:step => :steppost,
:stair => :steppost,
:stairs => :steppost,
:stem => :sticks,
:dots => :scatter,
:histogram => :hist,
)
const _allStyles = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] const _allStyles = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
const _styleAliases = Dict(
:a => :auto,
:s => :solid,
:d => :dash,
:dd => :dashdot,
:ddd => :dashdotdot,
)
const _allMarkers = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon, :octagon] const _allMarkers = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon, :octagon]
const _markerAliases = Dict(
:n => :none,
:no => :none,
:a => :auto,
:circle => :ellipse,
:c => :ellipse,
:square => :rect,
:sq => :rect,
:r => :rect,
:d => :diamond,
:^ => :utriangle,
:ut => :utriangle,
:utri => :utriangle,
:uptri => :utriangle,
:uptriangle => :utriangle,
:v => :dtriangle,
:V => :dtriangle,
:dt => :dtriangle,
:dtri => :dtriangle,
:downtri => :dtriangle,
:downtriangle => :dtriangle,
:+ => :cross,
:plus => :cross,
:x => :xcross,
:X => :xcross,
:star => :star1,
:s => :star1,
:s2 => :star2,
:h => :hexagon,
:hex => :hexagon,
:o => :octagon,
:oct => :octagon,
)
supportedAxes(::PlottingPackage) = _allAxes supportedAxes(::PlottingPackage) = _allAxes
supportedTypes(::PlottingPackage) = _allTypes supportedTypes(::PlottingPackage) = _allTypes
@ -27,7 +90,7 @@ _seriesDefaults[:axis] = :left
_seriesDefaults[:color] = :auto _seriesDefaults[:color] = :auto
_seriesDefaults[:label] = "AUTO" _seriesDefaults[:label] = "AUTO"
_seriesDefaults[:width] = 1 _seriesDefaults[:width] = 1
_seriesDefaults[:linetype] = :line _seriesDefaults[:linetype] = :path
_seriesDefaults[:linestyle] = :solid _seriesDefaults[:linestyle] = :solid
_seriesDefaults[:marker] = :none _seriesDefaults[:marker] = :none
_seriesDefaults[:markercolor] = :match _seriesDefaults[:markercolor] = :match
@ -77,19 +140,33 @@ autopick(notarr, idx::Integer) = notarr
autopick_ignore_none_auto(arr::AVec, idx::Integer) = autopick(setdiff(arr, [:none, :auto]), idx) autopick_ignore_none_auto(arr::AVec, idx::Integer) = autopick(setdiff(arr, [:none, :auto]), idx)
autopick_ignore_none_auto(notarr, idx::Integer) = notarr autopick_ignore_none_auto(notarr, idx::Integer) = notarr
function aliasesAndAutopick(d::Dict, sym::Symbol, aliases::Dict, options::AVec, plotIndex::Int)
if d[sym] == :auto
d[sym] = autopick_ignore_none_auto(options, plotIndex)
elseif haskey(aliases, d[sym])
d[sym] = aliases[d[sym]]
end
end
function aliases(aliasMap::Dict, val)
sort(vcat(val, collect(keys(filter((k,v)-> v==val, aliasMap)))))
end
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Alternate args # Alternate args
const _keyAliases = Dict( const _keyAliases = Dict(
:c => :color, :c => :color,
:l => :label, :lab => :label,
:w => :width, :w => :width,
:linewidth => :width, :linewidth => :width,
:type => :linetype, :type => :linetype,
:lt => :linetype,
:t => :linetype, :t => :linetype,
:style => :linestyle, :style => :linestyle,
:s => :linestyle, :s => :linestyle,
:ls => :linestyle,
:m => :marker, :m => :marker,
:mc => :markercolor, :mc => :markercolor,
:mcolor => :markercolor, :mcolor => :markercolor,
@ -130,14 +207,14 @@ for arg in keys(_seriesDefaults)
end end
function replaceAliases!(d::Dict) # function replaceAliases!(d::Dict)
for (k,v) in d # for (k,v) in d
if haskey(_keyAliases, k) # if haskey(_keyAliases, k)
d[_keyAliases[k]] = v # d[_keyAliases[k]] = v
delete!(d, k) # delete!(d, k)
end # end
end # end
end # end
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -204,6 +281,7 @@ end
# note: idx is the index of this series within this call, n is the index of the series from all calls to plot/subplot # note: idx is the index of this series within this call, n is the index of the series from all calls to plot/subplot
function getSeriesArgs(pkg::PlottingPackage, initargs::Dict, kw, commandIndex::Int, plotIndex::Int, globalIndex::Int) # TODO, pass in initargs, not plt function getSeriesArgs(pkg::PlottingPackage, initargs::Dict, kw, commandIndex::Int, plotIndex::Int, globalIndex::Int) # TODO, pass in initargs, not plt
d = Dict(kw) d = Dict(kw)
@ -221,16 +299,20 @@ function getSeriesArgs(pkg::PlottingPackage, initargs::Dict, kw, commandIndex::I
end end
end end
# auto-pick aliasesAndAutopick(d, :axis, _axesAliases, supportedAxes(pkg), plotIndex)
if d[:axis] == :auto aliasesAndAutopick(d, :linestyle, _styleAliases, supportedStyles(pkg), plotIndex)
d[:axis] = autopick_ignore_none_auto(supportedAxes(pkg), plotIndex) aliasesAndAutopick(d, :marker, _markerAliases, supportedMarkers(pkg), plotIndex)
end
if d[:linestyle] == :auto # # auto-pick
d[:linestyle] = autopick_ignore_none_auto(supportedStyles(pkg), plotIndex) # if d[:axis] == :auto
end # d[:axis] = autopick_ignore_none_auto(supportedAxes(pkg), plotIndex)
if d[:marker] == :auto # end
d[:marker] = autopick_ignore_none_auto(supportedMarkers(pkg), plotIndex) # if d[:linestyle] == :auto
end # d[:linestyle] = autopick_ignore_none_auto(supportedStyles(pkg), plotIndex)
# end
# if d[:marker] == :auto
# d[:marker] = autopick_ignore_none_auto(supportedMarkers(pkg), plotIndex)
# end
# update color # update color
d[:color] = getSeriesRGBColor(d[:color], initargs, plotIndex) d[:color] = getSeriesRGBColor(d[:color], initargs, plotIndex)

View File

@ -6,19 +6,27 @@ immutable QwtPackage <: PlottingPackage end
export qwt! export qwt!
qwt!() = plotter!(:qwt) qwt!() = plotter!(:qwt)
supportedTypes(::QwtPackage) = [:none, :line, :step, :stepinverted, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar] supportedTypes(::QwtPackage) = [:none, :path, :step, :stepinverted, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar]
# ------------------------------- # -------------------------------
const _qwtAliases = Dict(
:nbins => :heatmap_n,
:hexbin => :heatmap,
:path => :line,
)
function adjustQwtKeywords(iscreating::Bool; kw...) function adjustQwtKeywords(iscreating::Bool; kw...)
d = Dict(kw) d = Dict(kw)
if !iscreating replaceAliases!(d, _qwtAliases)
d[:heatmap_n] = d[:nbins] # if !iscreating
end # d[:heatmap_n] = d[:nbins]
# end
if d[:linetype] == :hexbin # if d[:linetype] == :hexbin
d[:linetype] = :heatmap # d[:linetype] = :heatmap
elseif d[:linetype] == :scatter # elseif d[:linetype] == :scatter
if d[:linetype] == :scatter
d[:linetype] = :none d[:linetype] = :none
if d[:marker] == :none if d[:marker] == :none
d[:marker] = :ellipse d[:marker] = :ellipse

View File

@ -91,7 +91,7 @@ When plotting multiple lines, you can give every line the same trait by using th
function plot(args...; kw...) function plot(args...; kw...)
pkg = plotter() pkg = plotter()
d = Dict(kw) d = Dict(kw)
replaceAliases!(d) replaceAliases!(d, _keyAliases)
# # ensure we're passing in an RGB # # ensure we're passing in an RGB
# if haskey(d, :background_color) # if haskey(d, :background_color)
@ -125,7 +125,7 @@ end
function plot!(plt::Plot, args...; kw...) function plot!(plt::Plot, args...; kw...)
d = Dict(kw) d = Dict(kw)
replaceAliases!(d) replaceAliases!(d, _keyAliases)
# TODO: handle a "group by" mechanism. # TODO: handle a "group by" mechanism.
# will probably want to check for the :group kw param, and split into # will probably want to check for the :group kw param, and split into

View File

@ -60,7 +60,7 @@ Create a series of plots:
""" """
function subplot(args...; kw...) function subplot(args...; kw...)
d = Dict(kw) d = Dict(kw)
replaceAliases!(d) replaceAliases!(d, _keyAliases)
# figure out the layout # figure out the layout
if haskey(d, :layout) if haskey(d, :layout)
@ -117,7 +117,7 @@ function subplot!(subplt::Subplot, args...; kw...)
end end
d = Dict(kw) d = Dict(kw)
replaceAliases!(d) replaceAliases!(d, _keyAliases)
for k in keys(_plotDefaults) for k in keys(_plotDefaults)
delete!(d, k) delete!(d, k)
end end

View File

@ -108,6 +108,16 @@ makevec(v::AVec) = v
makevec{T}(v::T) = T[v] makevec{T}(v::T) = T[v]
function replaceAliases!(d::Dict, aliases::Dict)
for (k,v) in d
if haskey(aliases, k)
d[aliases[k]] = v
delete!(d, k)
end
end
end
function regressionXY(x, y) function regressionXY(x, y)
# regress # regress
β, α = [x ones(length(x))] \ y β, α = [x ones(length(x))] \ y