working on aliases
This commit is contained in:
parent
031058cd0c
commit
86a56e487a
@ -51,7 +51,7 @@ const examples = PlotExample[
|
||||
[:(heatmap(randn(10000),randn(10000); nbins=100))]),
|
||||
PlotExample("Line types",
|
||||
"",
|
||||
[:(types = intersect(supportedTypes(), [:line, :step, :stepinverted, :sticks, :scatter])),
|
||||
[:(types = intersect(supportedTypes(), [:line, :path, :steppre, :steppost, :sticks, :scatter])),
|
||||
:(n = length(types)),
|
||||
:(x = Vector[sort(rand(20)) for i in 1:n]),
|
||||
:(y = rand(20,n)),
|
||||
|
||||
0
docs/readme_template.md
Normal file
0
docs/readme_template.md
Normal file
@ -38,6 +38,7 @@ export
|
||||
savepng,
|
||||
|
||||
backends,
|
||||
aliases,
|
||||
|
||||
supportedArgs,
|
||||
supportedAxes,
|
||||
|
||||
124
src/args.jl
124
src/args.jl
@ -1,10 +1,73 @@
|
||||
|
||||
|
||||
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]
|
||||
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 _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 _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
|
||||
supportedTypes(::PlottingPackage) = _allTypes
|
||||
@ -27,7 +90,7 @@ _seriesDefaults[:axis] = :left
|
||||
_seriesDefaults[:color] = :auto
|
||||
_seriesDefaults[:label] = "AUTO"
|
||||
_seriesDefaults[:width] = 1
|
||||
_seriesDefaults[:linetype] = :line
|
||||
_seriesDefaults[:linetype] = :path
|
||||
_seriesDefaults[:linestyle] = :solid
|
||||
_seriesDefaults[:marker] = :none
|
||||
_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(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
|
||||
|
||||
const _keyAliases = Dict(
|
||||
:c => :color,
|
||||
:l => :label,
|
||||
:lab => :label,
|
||||
:w => :width,
|
||||
:linewidth => :width,
|
||||
:type => :linetype,
|
||||
:lt => :linetype,
|
||||
:t => :linetype,
|
||||
:style => :linestyle,
|
||||
:s => :linestyle,
|
||||
:ls => :linestyle,
|
||||
:m => :marker,
|
||||
:mc => :markercolor,
|
||||
:mcolor => :markercolor,
|
||||
@ -130,14 +207,14 @@ for arg in keys(_seriesDefaults)
|
||||
end
|
||||
|
||||
|
||||
function replaceAliases!(d::Dict)
|
||||
for (k,v) in d
|
||||
if haskey(_keyAliases, k)
|
||||
d[_keyAliases[k]] = v
|
||||
delete!(d, k)
|
||||
end
|
||||
end
|
||||
end
|
||||
# function replaceAliases!(d::Dict)
|
||||
# for (k,v) in d
|
||||
# if haskey(_keyAliases, k)
|
||||
# d[_keyAliases[k]] = v
|
||||
# delete!(d, k)
|
||||
# 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
|
||||
function getSeriesArgs(pkg::PlottingPackage, initargs::Dict, kw, commandIndex::Int, plotIndex::Int, globalIndex::Int) # TODO, pass in initargs, not plt
|
||||
d = Dict(kw)
|
||||
@ -221,16 +299,20 @@ function getSeriesArgs(pkg::PlottingPackage, initargs::Dict, kw, commandIndex::I
|
||||
end
|
||||
end
|
||||
|
||||
# auto-pick
|
||||
if d[:axis] == :auto
|
||||
d[:axis] = autopick_ignore_none_auto(supportedAxes(pkg), plotIndex)
|
||||
end
|
||||
if d[:linestyle] == :auto
|
||||
d[:linestyle] = autopick_ignore_none_auto(supportedStyles(pkg), plotIndex)
|
||||
end
|
||||
if d[:marker] == :auto
|
||||
d[:marker] = autopick_ignore_none_auto(supportedMarkers(pkg), plotIndex)
|
||||
end
|
||||
aliasesAndAutopick(d, :axis, _axesAliases, supportedAxes(pkg), plotIndex)
|
||||
aliasesAndAutopick(d, :linestyle, _styleAliases, supportedStyles(pkg), plotIndex)
|
||||
aliasesAndAutopick(d, :marker, _markerAliases, supportedMarkers(pkg), plotIndex)
|
||||
|
||||
# # auto-pick
|
||||
# if d[:axis] == :auto
|
||||
# d[:axis] = autopick_ignore_none_auto(supportedAxes(pkg), plotIndex)
|
||||
# end
|
||||
# if d[:linestyle] == :auto
|
||||
# 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
|
||||
d[:color] = getSeriesRGBColor(d[:color], initargs, plotIndex)
|
||||
|
||||
@ -6,19 +6,27 @@ immutable QwtPackage <: PlottingPackage end
|
||||
export 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...)
|
||||
d = Dict(kw)
|
||||
if !iscreating
|
||||
d[:heatmap_n] = d[:nbins]
|
||||
end
|
||||
replaceAliases!(d, _qwtAliases)
|
||||
# if !iscreating
|
||||
# d[:heatmap_n] = d[:nbins]
|
||||
# end
|
||||
|
||||
if d[:linetype] == :hexbin
|
||||
d[:linetype] = :heatmap
|
||||
elseif d[:linetype] == :scatter
|
||||
# if d[:linetype] == :hexbin
|
||||
# d[:linetype] = :heatmap
|
||||
# elseif d[:linetype] == :scatter
|
||||
if d[:linetype] == :scatter
|
||||
d[:linetype] = :none
|
||||
if d[:marker] == :none
|
||||
d[:marker] = :ellipse
|
||||
|
||||
@ -91,7 +91,7 @@ When plotting multiple lines, you can give every line the same trait by using th
|
||||
function plot(args...; kw...)
|
||||
pkg = plotter()
|
||||
d = Dict(kw)
|
||||
replaceAliases!(d)
|
||||
replaceAliases!(d, _keyAliases)
|
||||
|
||||
# # ensure we're passing in an RGB
|
||||
# if haskey(d, :background_color)
|
||||
@ -125,7 +125,7 @@ end
|
||||
function plot!(plt::Plot, args...; kw...)
|
||||
|
||||
d = Dict(kw)
|
||||
replaceAliases!(d)
|
||||
replaceAliases!(d, _keyAliases)
|
||||
|
||||
# TODO: handle a "group by" mechanism.
|
||||
# will probably want to check for the :group kw param, and split into
|
||||
|
||||
@ -60,7 +60,7 @@ Create a series of plots:
|
||||
"""
|
||||
function subplot(args...; kw...)
|
||||
d = Dict(kw)
|
||||
replaceAliases!(d)
|
||||
replaceAliases!(d, _keyAliases)
|
||||
|
||||
# figure out the layout
|
||||
if haskey(d, :layout)
|
||||
@ -117,7 +117,7 @@ function subplot!(subplt::Subplot, args...; kw...)
|
||||
end
|
||||
|
||||
d = Dict(kw)
|
||||
replaceAliases!(d)
|
||||
replaceAliases!(d, _keyAliases)
|
||||
for k in keys(_plotDefaults)
|
||||
delete!(d, k)
|
||||
end
|
||||
|
||||
10
src/utils.jl
10
src/utils.jl
@ -108,6 +108,16 @@ makevec(v::AVec) = 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)
|
||||
# regress
|
||||
β, α = [x ones(length(x))] \ y
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user