working on ticks/lims
This commit is contained in:
parent
646b88c5be
commit
273996aa91
@ -116,6 +116,8 @@ _plotDefaults[:yrightlabel] = ""
|
||||
_plotDefaults[:legend] = true
|
||||
_plotDefaults[:background_color] = colorant"white"
|
||||
_plotDefaults[:foreground_color] = :auto
|
||||
_plotDefaults[:xlims] = :auto
|
||||
_plotDefaults[:ylims] = :auto
|
||||
_plotDefaults[:xticks] = :auto
|
||||
_plotDefaults[:yticks] = :auto
|
||||
_plotDefaults[:size] = (800,600)
|
||||
@ -198,8 +200,10 @@ const _keyAliases = Dict(
|
||||
:fgcolor => :foreground_color,
|
||||
:fg_color => :foreground_color,
|
||||
:foreground => :foreground_color,
|
||||
:xlim => :xticks,
|
||||
:ylim => :yticks,
|
||||
:xlim => :xlims,
|
||||
:ylim => :ylims,
|
||||
:xtick => :xticks,
|
||||
:ytick => :yticks,
|
||||
:windowsize => :size,
|
||||
:wsize => :size,
|
||||
:wtitle => :windowtitle,
|
||||
|
||||
@ -200,32 +200,57 @@ function addGadflySeries!(gplt, d::Dict, initargs::Dict)
|
||||
nothing
|
||||
end
|
||||
|
||||
function addTicksGuideOrScale(gplt, ticks, isx::Bool)
|
||||
# function addTicksGuideOrScale(gplt, ticks, isx::Bool)
|
||||
# ticks == :auto && return
|
||||
# ttype = ticksType(ticks)
|
||||
# if ttype == :limits
|
||||
# minvalue = min(ticks...)
|
||||
# maxvalue = max(ticks...)
|
||||
# scale = (isx ? Gadfly.Scale.x_continuous : Gadfly.Scale.y_continuous)(minvalue=minvalue, maxvalue=maxvalue)
|
||||
# push!(gplt.scales, scale)
|
||||
# elseif ttype == :ticks
|
||||
# # if isx
|
||||
# # ticks = map(Compose.x_measure, sort(collect(ticks)))
|
||||
# # push!(gplt.statistics, Gadfly.Stat.xticks(ticks=ticks))
|
||||
# # else
|
||||
# # ticks = map(Compose.y_measure, sort(collect(ticks)))
|
||||
# # push!(gplt.statistics, Gadfly.Stat.yticks(ticks=ticks))
|
||||
# # end
|
||||
# ticks = sort(ticks)
|
||||
# guide = (isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks)(ticks=ticks)
|
||||
# push!(gplt.guides, guide)
|
||||
# # stat = (isx ? Gadfly.Stat.xticks : Gadfly.Stat.yticks)(ticks=ticks)
|
||||
# # push!(gplt.statistics, stat)
|
||||
# else
|
||||
# error("Invalid input for $(isx ? "xticks" : "yticks"): ", ticks)
|
||||
# end
|
||||
# end
|
||||
|
||||
function addTicksGuide(gplt, ticks, isx::Bool)
|
||||
ticks == :auto && return
|
||||
ttype = ticksType(ticks)
|
||||
if ttype == :limits
|
||||
minvalue = min(ticks...)
|
||||
maxvalue = max(ticks...)
|
||||
scale = (isx ? Gadfly.Scale.x_continuous : Gadfly.Scale.y_continuous)(minvalue=minvalue, maxvalue=maxvalue)
|
||||
push!(gplt.scales, scale)
|
||||
elseif ttype == :ticks
|
||||
if isx
|
||||
ticks = map(Compose.x_measure, sort(collect(ticks)))
|
||||
push!(gplt.statistics, Gadfly.Stat.xticks(ticks=ticks))
|
||||
else
|
||||
ticks = map(Compose.y_measure, sort(collect(ticks)))
|
||||
push!(gplt.statistics, Gadfly.Stat.yticks(ticks=ticks))
|
||||
end
|
||||
# ticks = map(Composesort(ticks)
|
||||
# # guide = (isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks)(ticks=ticks)
|
||||
# # push!(gplt.guides, guide)
|
||||
# stat = (isx ? Gadfly.Stat.xticks : Gadfly.Stat.yticks)(ticks=ticks)
|
||||
# push!(gplt.statistics, stat)
|
||||
if ttype == :ticks
|
||||
gtype = isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks
|
||||
filter!(x -> !isa(x, gtype), gplt.guides)
|
||||
push!(gplt.guides, gtype(ticks = sort(collect(ticks))))
|
||||
else
|
||||
error("Invalid input for $(isx ? "xticks" : "yticks"): ", ticks)
|
||||
end
|
||||
end
|
||||
|
||||
function addLimitsScale(gplt, lims, isx::Bool)
|
||||
lims == :auto && return
|
||||
ltype = limsType(lims)
|
||||
if ltype == :limits
|
||||
gtype = isx ? Gadfly.Scale.x_continuous : Gadfly.Scale.y_continuous
|
||||
filter!(x -> !isa(x, gtype), gplt.scales)
|
||||
push!(gplt.scales, gtype(minvalue = min(lims...), maxvalue = max(lims...)))
|
||||
else
|
||||
error("Invalid input for $(isx ? "xlims" : "ylims"): ", lims)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# create a blank Gadfly.Plot object
|
||||
@ -258,8 +283,10 @@ function updateGadflyGuides(gplt, d::Dict)
|
||||
haskey(d, :title) && findGuideAndSet(gplt, Gadfly.Guide.title, d[:title])
|
||||
haskey(d, :xlabel) && findGuideAndSet(gplt, Gadfly.Guide.xlabel, d[:xlabel])
|
||||
haskey(d, :ylabel) && findGuideAndSet(gplt, Gadfly.Guide.ylabel, d[:ylabel])
|
||||
haskey(d, :xticks) && addTicksGuideOrScale(gplt, d[:xticks], true)
|
||||
haskey(d, :yticks) && addTicksGuideOrScale(gplt, d[:yticks], true)
|
||||
haskey(d, :xlims) && addLimitsScale(gplt, d[:xlims], true)
|
||||
haskey(d, :ylims) && addLimitsScale(gplt, d[:ylims], false)
|
||||
haskey(d, :xticks) && addTicksGuide(gplt, d[:xticks], true)
|
||||
haskey(d, :yticks) && addTicksGuide(gplt, d[:yticks], false)
|
||||
end
|
||||
|
||||
function updatePlotItems(plt::Plot{GadflyPackage}, d::Dict)
|
||||
|
||||
@ -128,10 +128,13 @@ function regressionXY(x, y)
|
||||
regx, regy
|
||||
end
|
||||
|
||||
ticksType{T<:Real,S<:Real}(ticks::Tuple{T,S}) = :limits
|
||||
# ticksType{T<:Real,S<:Real}(ticks::Tuple{T,S}) = :limits
|
||||
ticksType{T<:Real}(ticks::AVec{T}) = :ticks
|
||||
ticksType(ticks) = :invalid
|
||||
|
||||
limsType{T<:Real,S<:Real}(lims::Tuple{T,S}) = :limits
|
||||
limsType(lims) = :invalid
|
||||
|
||||
|
||||
# Some conversion functions
|
||||
# note: I borrowed these conversion constants from Compose.jl's Measure
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user