working on colors

This commit is contained in:
Thomas Breloff 2015-09-09 12:53:25 -04:00
parent fe87e985ec
commit 88a4b5cd12
2 changed files with 53 additions and 18 deletions

View File

@ -23,7 +23,7 @@ PLOT_DEFAULTS[:width] = 1
PLOT_DEFAULTS[:linetype] = :line PLOT_DEFAULTS[:linetype] = :line
PLOT_DEFAULTS[:linestyle] = :solid PLOT_DEFAULTS[:linestyle] = :solid
PLOT_DEFAULTS[:marker] = :none PLOT_DEFAULTS[:marker] = :none
PLOT_DEFAULTS[:markercolor] = :auto PLOT_DEFAULTS[:markercolor] = :match
PLOT_DEFAULTS[:markersize] = 10 PLOT_DEFAULTS[:markersize] = 10
PLOT_DEFAULTS[:heatmap_n] = 100 PLOT_DEFAULTS[:heatmap_n] = 100
PLOT_DEFAULTS[:heatmap_c] = (0.15, 0.5) PLOT_DEFAULTS[:heatmap_c] = (0.15, 0.5)
@ -54,6 +54,31 @@ makeplural(s::Symbol) = Symbol(string(s,"s"))
autocolor(idx::Integer) = COLORS[mod1(idx,NUMCOLORS)] autocolor(idx::Integer) = COLORS[mod1(idx,NUMCOLORS)]
# converts a symbol or string into a colorant (Colors.RGB), and assigns a color automatically
# note: if plt is nothing, we aren't doing anything with the color anyways
function getRGBColor(c, plt)
# auto-assign a color based on plot index
if c == :auto
c = autocolor(plt.n)
end
# convert it from a symbol/string
if isa(c, Symbol)
c = string(c)
end
if isa(c, String)
c = parse(Colorant, c)
end
# should be a RGB now... either it was passed in, generated automatically, or created from a string
@assert isa(c, RGB)
# return the RGB
c
end
function getPlotKeywordArgs(kw, i::Int, plt = nothing) function getPlotKeywordArgs(kw, i::Int, plt = nothing)
d = Dict(kw) d = Dict(kw)
outd = Dict() outd = Dict()
@ -69,16 +94,26 @@ function getPlotKeywordArgs(kw, i::Int, plt = nothing)
end end
end end
# auto assign a color
if plt != nothing if plt != nothing
if outd[:color] == :auto # update color
outd[:color] = autocolor(plt.n) outd[:color] = getRGBColor(outd[:color], plt)
end
if outd[:markercolor] == :auto # update markercolor
outd[:markercolor] = outd[:color] mc = outd[:markercolor]
end mc = (mc == :match ? outd[:color] : getRGBColor(mc, plt))
outd[:markercolor] = mc
end end
# # auto assign a color
# if plt != nothing
# if outd[:color] == :auto
# outd[:color] = autocolor(plt.n)
# end
# if outd[:markercolor] == :auto
# outd[:markercolor] = outd[:color]
# end
# end
outd outd
end end

View File

@ -43,16 +43,16 @@ function plot!(::GadflyPackage, plt::Plot; kw...)
# linestyle # linestyle
# label # label
# color # # color
c = d[:color] # c = d[:color]
if isa(c, Symbol) # if isa(c, Symbol)
c = string(c) # c = string(c)
end # end
if isa(c, String) # if isa(c, String)
c = parse(Colorant, c) # c = parse(Colorant, c)
end # end
@assert isa(c, RGB) # @assert isa(c, RGB)
push!(gfargs, Gadfly.Theme(default_color=c)) push!(gfargs, Gadfly.Theme(default_color = d[:color]))
# legend # legend
# guides (x/y labels, title, background, ticks) # guides (x/y labels, title, background, ticks)