working on color schemes
This commit is contained in:
parent
78045fd2ab
commit
1de3decede
@ -76,60 +76,265 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 25,
|
"execution_count": 12,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false
|
"collapsed": false
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
|
"image/svg+xml": [
|
||||||
|
"<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
|
||||||
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
|
||||||
|
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
|
||||||
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
|
||||||
|
" width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
|
||||||
|
" <rect width=\"1\" height=\"1\"\n",
|
||||||
|
" fill=\"#0000FF\" stroke=\"none\"/>\n",
|
||||||
|
"</svg>\n"
|
||||||
|
],
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"9-element Array{Symbol,1}:\n",
|
"RGB{U8}(0.0,0.0,1.0)"
|
||||||
" :layers \n",
|
|
||||||
" :data_source\n",
|
|
||||||
" :data \n",
|
|
||||||
" :scales \n",
|
|
||||||
" :statistics \n",
|
|
||||||
" :coord \n",
|
|
||||||
" :guides \n",
|
|
||||||
" :theme \n",
|
|
||||||
" :mapping "
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 25,
|
"metadata": {},
|
||||||
|
"output_type": "display_data"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"image/svg+xml": [
|
||||||
|
"<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
|
||||||
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
|
||||||
|
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
|
||||||
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
|
||||||
|
" width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
|
||||||
|
" <rect width=\"1\" height=\"1\"\n",
|
||||||
|
" fill=\"#4B35D0\" stroke=\"none\"/>\n",
|
||||||
|
"</svg>\n"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
"RGB{Float64}(0.29284122574765004,0.20616016088988381,0.8154590567565114)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "display_data"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"image/svg+xml": [
|
||||||
|
"<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
|
||||||
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
|
||||||
|
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
|
||||||
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
|
||||||
|
" width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
|
||||||
|
" <rect width=\"1\" height=\"1\"\n",
|
||||||
|
" fill=\"#584DA2\" stroke=\"none\"/>\n",
|
||||||
|
"</svg>\n"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
"RGB{Float64}(0.34473316201852744,0.30261169288286327,0.6359164489679165)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "display_data"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"image/svg+xml": [
|
||||||
|
"<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
|
||||||
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
|
||||||
|
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
|
||||||
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
|
||||||
|
" width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
|
||||||
|
" <rect width=\"1\" height=\"1\"\n",
|
||||||
|
" fill=\"#556075\" stroke=\"none\"/>\n",
|
||||||
|
"</svg>\n"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
"RGB{Float64}(0.3320652279465807,0.37816870085640947,0.4597207917942931)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "display_data"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"image/svg+xml": [
|
||||||
|
"<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
|
||||||
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
|
||||||
|
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
|
||||||
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
|
||||||
|
" width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
|
||||||
|
" <rect width=\"1\" height=\"1\"\n",
|
||||||
|
" fill=\"#427147\" stroke=\"none\"/>\n",
|
||||||
|
"</svg>\n"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
"RGB{Float64}(0.2606854798779104,0.4433586313880962,0.27940782734210995)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "display_data"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"image/svg+xml": [
|
||||||
|
"<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
|
||||||
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
|
||||||
|
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
|
||||||
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
|
||||||
|
" width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
|
||||||
|
" <rect width=\"1\" height=\"1\"\n",
|
||||||
|
" fill=\"#008000\" stroke=\"none\"/>\n",
|
||||||
|
"</svg>\n"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
"RGB{Float64}(2.135658170401844e-7,0.5019607992717322,0.0)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "display_data"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"image/svg+xml": [
|
||||||
|
"<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
|
||||||
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
|
||||||
|
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
|
||||||
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
|
||||||
|
" width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
|
||||||
|
" <rect width=\"1\" height=\"1\"\n",
|
||||||
|
" fill=\"#5F7B00\" stroke=\"none\"/>\n",
|
||||||
|
"</svg>\n"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
"RGB{Float64}(0.37220781950534426,0.4811025938574362,0.0)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "display_data"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"image/svg+xml": [
|
||||||
|
"<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
|
||||||
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
|
||||||
|
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
|
||||||
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
|
||||||
|
" width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
|
||||||
|
" <rect width=\"1\" height=\"1\"\n",
|
||||||
|
" fill=\"#8D7200\" stroke=\"none\"/>\n",
|
||||||
|
"</svg>\n"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
"RGB{Float64}(0.5528978474402565,0.445996276949532,0.0)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "display_data"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"image/svg+xml": [
|
||||||
|
"<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
|
||||||
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
|
||||||
|
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
|
||||||
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
|
||||||
|
" width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
|
||||||
|
" <rect width=\"1\" height=\"1\"\n",
|
||||||
|
" fill=\"#B56300\" stroke=\"none\"/>\n",
|
||||||
|
"</svg>\n"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
"RGB{Float64}(0.709264766923926,0.3896484083057615,0.0)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "display_data"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"image/svg+xml": [
|
||||||
|
"<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
|
||||||
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
|
||||||
|
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
|
||||||
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
|
||||||
|
" width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
|
||||||
|
" <rect width=\"1\" height=\"1\"\n",
|
||||||
|
" fill=\"#DA4B00\" stroke=\"none\"/>\n",
|
||||||
|
"</svg>\n"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
"RGB{Float64}(0.8565683200929008,0.294237959040753,0.0)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "display_data"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"image/svg+xml": [
|
||||||
|
"<?xml version\"1.0\" encoding=\"UTF-8\"?>\n",
|
||||||
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
|
||||||
|
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
|
||||||
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n",
|
||||||
|
" width=\"25mm\" height=\"25mm\" viewBox=\"0 0 1 1\">\n",
|
||||||
|
" <rect width=\"1\" height=\"1\"\n",
|
||||||
|
" fill=\"#FF0000\" stroke=\"none\"/>\n",
|
||||||
|
"</svg>\n"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
"RGB{Float64}(0.9999999006125039,2.0222806256020575e-6,0.0)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "display_data"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"11-element Array{Void,1}:\n",
|
||||||
|
" nothing\n",
|
||||||
|
" nothing\n",
|
||||||
|
" nothing\n",
|
||||||
|
" nothing\n",
|
||||||
|
" nothing\n",
|
||||||
|
" nothing\n",
|
||||||
|
" nothing\n",
|
||||||
|
" nothing\n",
|
||||||
|
" nothing\n",
|
||||||
|
" nothing\n",
|
||||||
|
" nothing"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 12,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"fieldnames(p.o[2])"
|
"using Plots\n",
|
||||||
|
"grad = Plots.ColorGradient([colorant\"blue\", colorant\"green\", colorant\"red\"], [0,0.5,1])\n",
|
||||||
|
"map(display, [Plots.getColor(grad, x) for x in 0:0.1:1])"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 32,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false
|
"collapsed": true
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
"source": []
|
||||||
"data": {
|
},
|
||||||
"text/plain": [
|
{
|
||||||
"4-element Array{Gadfly.GuideElement,1}:\n",
|
"cell_type": "code",
|
||||||
" Gadfly.Guide.ManualColorKey{ColorTypes.Color{T,N}}(\"\",AbstractString[\"y1\"],ColorTypes.Color[RGB{Float64}(0.0,0.0,0.0)])\n",
|
"execution_count": null,
|
||||||
" Gadfly.Guide.XLabel(\"\",:auto) \n",
|
"metadata": {
|
||||||
" Gadfly.Guide.YLabel(\"\",:auto) \n",
|
"collapsed": true
|
||||||
" Gadfly.Guide.Title(\"\") "
|
},
|
||||||
]
|
"outputs": [],
|
||||||
},
|
"source": []
|
||||||
"execution_count": 32,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"p.o[2].guides"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -69,12 +69,81 @@ const _masterColorList = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
convertColor(c::Union{AbstractString, Symbol}) = parse(Colorant, string(c))
|
convertColor(c::Union{AbstractString, Symbol}) = parse(Colorant, string(c))
|
||||||
convertColor(c::Colorant) = c
|
convertColor(c::Colorant) = c
|
||||||
convertColor(cvec::AbstractVector) = map(convertColor, cvec)
|
convertColor(cvec::AbstractVector) = map(convertColor, cvec)
|
||||||
|
|
||||||
|
# --------------------------------------------------------------
|
||||||
|
|
||||||
|
abstract ColorScheme
|
||||||
|
|
||||||
|
# --------------------------------------------------------------
|
||||||
|
|
||||||
|
"Continuous gradient between values. Wraps a list of bounding colors and the values they represent."
|
||||||
|
type ColorGradient <: ColorScheme
|
||||||
|
colors::Vector{Colorant}
|
||||||
|
values::Vector{Float64}
|
||||||
|
end
|
||||||
|
|
||||||
|
function getColor(gradient::ColorGradient, z::Real, idx::Int)
|
||||||
|
cs = gradient.colors
|
||||||
|
vs = gradient.values
|
||||||
|
n = length(cs)
|
||||||
|
@assert n > 0 && n == length(vs)
|
||||||
|
|
||||||
|
# can we just return the first color?
|
||||||
|
if z <= vs[1] || n == 1
|
||||||
|
return cs[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
# find the bounding colors and interpolate
|
||||||
|
for i in 2:n
|
||||||
|
if z <= vs[i]
|
||||||
|
return interpolateColor(cs[i-1], cs[i], (z - vs[i-1]) / (vs[i] - vs[i-1]))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# if we get here, return the last color
|
||||||
|
cs[end]
|
||||||
|
end
|
||||||
|
|
||||||
|
function interpolateColor(c1::Colorant, c2::Colorant, w::Real)
|
||||||
|
lab1 = Lab(c1)
|
||||||
|
lab2 = Lab(c2)
|
||||||
|
l = (1-w) * lab1.l + w * lab2.l
|
||||||
|
a = (1-w) * lab1.a + w * lab2.a
|
||||||
|
b = (1-w) * lab1.b + w * lab2.b
|
||||||
|
RGB(Lab(l, a, b))
|
||||||
|
end
|
||||||
|
|
||||||
|
# --------------------------------------------------------------
|
||||||
|
|
||||||
|
"Wraps a function, taking a z-value and index and returning a Colorant"
|
||||||
|
type ColorFunction <: ColorScheme
|
||||||
|
f::Function
|
||||||
|
end
|
||||||
|
|
||||||
|
typealias CFun ColorFunction
|
||||||
|
|
||||||
|
getColor(grad::ColorFunction, z::Real, idx::Int) = grad.f(z, idx)
|
||||||
|
|
||||||
|
# --------------------------------------------------------------
|
||||||
|
|
||||||
|
"Wraps a vector of colors... may be Symbol/String or a Colorant"
|
||||||
|
type ColorVector{V<:AbstractVector} <: ColorScheme
|
||||||
|
v::V
|
||||||
|
end
|
||||||
|
|
||||||
|
typealias CVec ColorVector
|
||||||
|
|
||||||
|
getColor(grad::ColorVector, z::Real, idx::Int) = convertColor(grad.v[mod1(idx, length(grad.v))])
|
||||||
|
|
||||||
|
# --------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
isbackgrounddark(bgcolor::Color) = Lab(bgcolor).l < 0.5
|
isbackgrounddark(bgcolor::Color) = Lab(bgcolor).l < 0.5
|
||||||
|
|
||||||
# move closer to lighter/darker depending on background value
|
# move closer to lighter/darker depending on background value
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user