added scales globally and to gadfly/immerse

This commit is contained in:
Thomas Breloff 2015-09-30 09:18:16 -04:00
parent a027fdded7
commit 69d574c587
9 changed files with 124 additions and 16 deletions

View File

@ -73,16 +73,24 @@ const _markerAliases = Dict(
:oct => :octagon,
)
const _allScales = [:identity, :log, :log2, :log10, :asinh, :sqrt]
const _scaleAliases = Dict(
:none => :identity,
:ln => :log,
)
supportedAxes(::PlottingPackage) = _allAxes
supportedTypes(::PlottingPackage) = _allTypes
supportedStyles(::PlottingPackage) = _allStyles
supportedMarkers(::PlottingPackage) = _allMarkers
supportedScales(::PlottingPackage) = _allScales
subplotSupported(::PlottingPackage) = true
supportedAxes() = supportedAxes(backend())
supportedTypes() = supportedTypes(backend())
supportedStyles() = supportedStyles(backend())
supportedMarkers() = supportedMarkers(backend())
supportedScales() = supportedScales(backend())
subplotSupported() = subplotSupported(backend())
# -----------------------------------------------------------------------------
@ -125,6 +133,8 @@ _plotDefaults[:xlims] = :auto
_plotDefaults[:ylims] = :auto
_plotDefaults[:xticks] = :auto
_plotDefaults[:yticks] = :auto
_plotDefaults[:xscale] = :identity
_plotDefaults[:yscale] = :identity
_plotDefaults[:size] = (800,600)
_plotDefaults[:pos] = (0,0)
_plotDefaults[:windowtitle] = "Plots.jl"
@ -376,6 +386,12 @@ function getSeriesArgs(pkg::PlottingPackage, initargs::Dict, kw, commandIndex::I
d[:linetype] = _typeAliases[d[:linetype]]
end
for k in (:xscale, :yscale)
if haskey(_scaleAliases, d[k])
d[k] = _scaleAliases[d[k]]
end
end
aliasesAndAutopick(d, :axis, _axesAliases, supportedAxes(pkg), plotIndex)
aliasesAndAutopick(d, :linestyle, _styleAliases, supportedStyles(pkg), plotIndex)
aliasesAndAutopick(d, :marker, _markerAliases, supportedMarkers(pkg), plotIndex)

View File

@ -48,11 +48,14 @@ supportedArgs(::GadflyPackage) = [
:ylims,
# :yrightlabel,
:yticks,
:xscale,
:yscale,
]
supportedAxes(::GadflyPackage) = [:auto, :left]
supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc]
supportedStyles(::GadflyPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
supportedMarkers(::GadflyPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon, :octagon]
supportedScales(::GadflyPackage) = [:identity, :log, :log2, :log10, :asinh, :sqrt]
include("gadfly_shapes.jl")
@ -131,6 +134,37 @@ function addGadflyFixedLines!(gplt, d::Dict, theme)
end
# # const x_continuous = continuous_scale_partial(x_vars, identity_transform)
# # const y_continuous = continuous_scale_partial(y_vars, identity_transform)
# # const x_log10 = continuous_scale_partial(x_vars, log10_transform)
# # const y_log10 = continuous_scale_partial(y_vars, log10_transform)
# # const x_log2 = continuous_scale_partial(x_vars, log2_transform)
# # const y_log2 = continuous_scale_partial(y_vars, log2_transform)
# # const x_log = continuous_scale_partial(x_vars, ln_transform)
# # const y_log = continuous_scale_partial(y_vars, ln_transform)
# # const x_asinh = continuous_scale_partial(x_vars, asinh_transform)
# # const y_asinh = continuous_scale_partial(y_vars, asinh_transform)
# # const x_sqrt = continuous_scale_partial(x_vars, sqrt_transform)
# # const y_sqrt = continuous_scale_partial(y_vars, sqrt_transform)
# function addGadflyScales(gplt, d::Dict)
# for k in (:xscale, :yscale)
# isx = k == :xscale
# scale = d[k]
# if scale == :log
# push!(gplt.scales, isx ? Gadfly.Scale.x_log : Gadfly.Scale.y_log)
# elseif scale == :log2
# push!(gplt.scales, isx ? Gadfly.Scale.x_log2 : Gadfly.Scale.y_log2)
# elseif scale == :log10
# push!(gplt.scales, isx ? Gadfly.Scale.x_log2 : Gadfly.Scale.y_log10)
# elseif scale == :asinh
# push!(gplt.scales, isx ? Gadfly.Scale.x_asinh : Gadfly.Scale.y_asinh)
# elseif scale == :sqrt
# push!(gplt.scales, isx ? Gadfly.Scale.x_sqrt : Gadfly.Scale.y_sqrt)
# end
# end
# end
# function getGadflyStrokeVector(linestyle::Symbol)
# dash = 12 * Compose.mm
# dot = 3 * Compose.mm
@ -237,6 +271,9 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict)
append!(gfargs, geoms)
append!(gplt.guides, guides)
# # add scales
# addGadflyScales(gplt, d)
# add a regression line?
if d[:reg]
push!(gfargs, Gadfly.Geom.smooth(method=:lm))
@ -298,18 +335,55 @@ end
# isContinuousScale(scale, isx::Bool) = isa(scale, Gadfly.Scale.ContinuousScale) && scale.vars[1] == (isx ? :x : :y)
filterGadflyScale(gplt, isx::Bool) = filter!(scale -> scale.vars[1] != (isx ? :x : :y), gplt.scales)
function addGadflyLimitsScale(gplt, lims, isx::Bool)
lims == :auto && return
ltype = limsType(lims)
if ltype == :limits
# remove any existing scales, then add a new one
filterGadflyScale(gplt, isx)
gfunc = isx ? Gadfly.Scale.x_continuous : Gadfly.Scale.y_continuous
# filter!(scale -> !isContinuousScale(scale,isx), gplt.scales)
push!(gplt.scales, gfunc(minvalue = min(lims...), maxvalue = max(lims...)))
else
error("Invalid input for $(isx ? "xlims" : "ylims"): ", lims)
function getGadflyScaleFunction(d::Dict, isx::Bool)
scalekey = isx ? :xscale : :yscale
hasScaleKey = haskey(d, scalekey)
if hasScaleKey
scale = d[scalekey]
scale == :log && 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 == :log10 && return isx ? Gadfly.Scale.x_log2 : Gadfly.Scale.y_log10, hasScaleKey
scale == :asinh && return isx ? Gadfly.Scale.x_asinh : Gadfly.Scale.y_asinh, hasScaleKey
scale == :sqrt && return isx ? Gadfly.Scale.x_sqrt : Gadfly.Scale.y_sqrt, hasScaleKey
end
isx ? Gadfly.Scale.x_continuous : Gadfly.Scale.y_continuous, hasScaleKey
end
function addGadflyLimitsScale(gplt, d::Dict, isx::Bool)
# get the correct scale function
gfunc, hasScaleKey = getGadflyScaleFunction(d, isx)
@show d gfunc hasScaleKey
# do we want to add min/max limits for the axis?
limsym = isx ? :xlims : :ylims
limargs = []
if haskey(d, limsym)
lims = d[limsym]
lims == :auto && return
if limsType(lims) == :limits
# remove any existing scales, then add a new one
# filterGadflyScale(gplt, isx)
# gfunc = isx ? Gadfly.Scale.x_continuous : Gadfly.Scale.y_continuous
# filter!(scale -> !isContinuousScale(scale,isx), gplt.scales)
# push!(gplt.scales, gfunc(minvalue = min(lims...), maxvalue = max(lims...)))
push!(limargs, (:minvalue, min(lims...)))
push!(limargs, (:maxvalue, max(lims...)))
else
error("Invalid input for $(isx ? "xlims" : "ylims"): ", lims)
end
end
@show limargs
# replace any current scales with this one
if hasScaleKey || !isempty(limargs)
filterGadflyScale(gplt, isx)
push!(gplt.scales, gfunc(; limargs...))
end
@show gplt.scales
return
end
@ -346,8 +420,8 @@ function updateGadflyGuides(gplt, d::Dict)
haskey(d, :xlabel) && findGuideAndSet(gplt, Gadfly.Guide.xlabel, d[:xlabel])
haskey(d, :ylabel) && findGuideAndSet(gplt, Gadfly.Guide.ylabel, d[:ylabel])
haskey(d, :xlims) && addGadflyLimitsScale(gplt, d[:xlims], true)
haskey(d, :ylims) && addGadflyLimitsScale(gplt, d[:ylims], false)
addGadflyLimitsScale(gplt, d, true)
addGadflyLimitsScale(gplt, d, false)
haskey(d, :xticks) && addGadflyTicksGuide(gplt, d[:xticks], true)
haskey(d, :yticks) && addGadflyTicksGuide(gplt, d[:yticks], false)
end

View File

@ -12,6 +12,7 @@ supportedAxes(::ImmersePackage) = supportedAxes(GadflyPackage())
supportedTypes(::ImmersePackage) = supportedTypes(GadflyPackage())
supportedStyles(::ImmersePackage) = supportedStyles(GadflyPackage())
supportedMarkers(::ImmersePackage) = supportedMarkers(GadflyPackage())
supportedScales(::ImmersePackage) = supportedScales(GadflyPackage())
function createImmerseFigure(d::Dict)

View File

@ -49,11 +49,14 @@ supportedArgs(::PyPlotPackage) = [
:ylims,
:yrightlabel,
:yticks,
# :xscale,
# :yscale,
]
supportedAxes(::PyPlotPackage) = _allAxes
supportedTypes(::PyPlotPackage) = [:none, :line, :path, :step, :stepinverted, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline]
supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot]
supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :hexagon]
supportedScales(::PyPlotPackage) = [:identity]
subplotSupported(::PyPlotPackage) = false
# convert colorant to 4-tuple RGBA

View File

@ -47,9 +47,12 @@ supportedArgs(::QwtPackage) = [
:ylims,
:yrightlabel,
:yticks,
# :xscale,
# :yscale,
]
supportedTypes(::QwtPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline]
supportedMarkers(::QwtPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon]
supportedScales(::QwtPackage) = [:identity]
# -------------------------------

View File

@ -51,11 +51,14 @@ supportedArgs(::[PkgName]Package) = [
:ylims,
# :yrightlabel,
:yticks,
# :xscale,
# :yscale,
]
supportedAxes(::[PkgName]Package) = _allAxes
supportedTypes(::[PkgName]Package) = _allTypes
supportedStyles(::[PkgName]Package) = _allStyles
supportedMarkers(::[PkgName]Package) = _allMarkers
supportedScales(::[PkgName]Package) = _allScales
subplotSupported(::[PkgName]Package) = false
# ---------------------------------------------------------------------------

View File

@ -49,11 +49,14 @@ supportedArgs(::UnicodePlotsPackage) = [
:ylims,
# :yrightlabel,
# :yticks,
# :xscale,
# :yscale,
]
supportedAxes(::UnicodePlotsPackage) = [:auto, :left]
supportedTypes(::UnicodePlotsPackage) = [:none, :line, :path, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline]
supportedStyles(::UnicodePlotsPackage) = [:auto, :solid]
supportedMarkers(::UnicodePlotsPackage) = [:none, :auto, :ellipse]
supportedScales(::UnicodePlotsPackage) = [:identity]
function expandLimits!(lims, x)

View File

@ -71,11 +71,14 @@ supportedArgs(::WinstonPackage) = [
:ylims,
# :yrightlabel,
# :yticks,
# :xscale,
# :yscale,
]
supportedAxes(::WinstonPackage) = [:auto, :left]
supportedTypes(::WinstonPackage) = [:none, :line, :path, :sticks, :scatter, :hist, :bar]
supportedStyles(::WinstonPackage) = [:auto, :solid, :dash, :dot, :dashdot] # intersect(_allStyles, collect(keys(winston_linestyle)))
supportedMarkers(::WinstonPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1] # intersect(_allMarkers, collect(keys(winston_marker)))
supportedStyles(::WinstonPackage) = [:auto, :solid, :dash, :dot, :dashdot]
supportedMarkers(::WinstonPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1]
supportedScales(::WinstonPackage) = [:identity]
subplotSupported(::WinstonPackage) = false

View File

@ -240,10 +240,12 @@ supportGraphArgs() = supportGraph(_allArgs, supportedArgs)
supportGraphTypes() = supportGraph(_allTypes, supportedTypes)
supportGraphStyles() = supportGraph(_allStyles, supportedStyles)
supportGraphMarkers() = supportGraph(_allMarkers, supportedMarkers)
supportGraphScales() = supportGraph(_allScales, supportedScales)
supportGraphAxes() = supportGraph(_allAxes, supportedAxes)
function dumpSupportGraphs()
for func in (supportGraphArgs, supportGraphTypes, supportGraphStyles, supportGraphMarkers, supportGraphAxes)
for func in (supportGraphArgs, supportGraphTypes, supportGraphStyles,
supportGraphMarkers, supportGraphScales, supportGraphAxes)
plt = func()
png(IMG_DIR * "/supported/$(string(func))")
end