Font and tick/guide/legend fonts

This commit is contained in:
Thomas Breloff 2015-10-16 10:52:36 -04:00
parent 47f21b1652
commit a7da999bd7
4 changed files with 54 additions and 28 deletions

View File

@ -100,7 +100,7 @@ const examples = PlotExample[
[
:(y = rand(10)),
:(plot(y, ann=(3,y[3],text("this is #3",:left)))),
:(annotate!([(5,y[5],text("this is #5",16,:red,:center)),(10,y[10],text("this is #10",:right,20,:Helvitica))]))
:(annotate!([(5,y[5],text("this is #5",16,:red,:center)),(10,y[10],text("this is #10",:right,20,"courier"))]))
]),
]

View File

@ -160,7 +160,9 @@ _plotDefaults[:link] = false
_plotDefaults[:linkx] = false
_plotDefaults[:linky] = false
_plotDefaults[:linkfunc] = nothing
# _plotDefaults[:dataframe] = nothing
_plotDefaults[:tickfont] = font(13)
_plotDefaults[:guidefont] = font(16)
_plotDefaults[:legendfont] = font(10)

View File

@ -56,6 +56,9 @@ supportedArgs(::GadflyPackage) = [
:z,
# :linkx,
# :linky,
:tickfont,
:guidefont,
:legendfont,
]
supportedAxes(::GadflyPackage) = [:auto, :left]
supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc]
@ -83,24 +86,33 @@ function createGadflyPlotObject(d::Dict)
Gadfly.Guide.ylabel(d[:ylabel]),
Gadfly.Guide.title(d[:title])]
kwargs = Dict()
# hide the legend
if get(d, :legend, true)
extra_theme_args = Any[]
else
extra_theme_args = Any[(:key_position, :none)]
# hide the legend?
if !get(d, :legend, true)
kwargs[:key_position] = :none
end
# fonts
tfont, gfont, lfont = d[:tickfont], d[:guidefont], d[:legendfont]
fg = getColor(d[:foreground_color])
gplt.theme = Gadfly.Theme(;
background_color = getColor(d[:background_color]),
# grid_color = fg,
minor_label_color = fg,
minor_label_font = tfont.family,
minor_label_font_size = tfont.pointsize * Gadfly.pt,
major_label_color = fg,
major_label_font = gfont.family,
major_label_font_size = gfont.pointsize * Gadfly.pt,
key_title_color = fg,
key_title_font = gfont.family,
key_title_font_size = gfont.pointsize * Gadfly.pt,
key_label_color = fg,
key_label_font = lfont.family,
key_label_font_size = lfont.pointsize * Gadfly.pt,
plot_padding = 1 * Gadfly.mm,
extra_theme_args...
kwargs...
)
gplt
end
@ -661,16 +673,16 @@ function createGadflyAnnotationObject(x, y, val::@compat(AbstractString))
end
function createGadflyAnnotationObject(x, y, txt::PlotText)
halign = (txt.halign == :hcenter ? Compose.hcenter : (txt.halign == :left ? Compose.hleft : Compose.hright))
valign = (txt.valign == :vcenter ? Compose.vcenter : (txt.valign == :top ? Compose.vtop : Compose.vbottom))
rotations = (txt.rotation == 0.0 ? [] : [Compose.Rotation(txt.rotation, Compose.Point(Compose.x_measure(x), Compose.y_measure(y)))])
halign = (txt.font.halign == :hcenter ? Compose.hcenter : (txt.font.halign == :left ? Compose.hleft : Compose.hright))
valign = (txt.font.valign == :vcenter ? Compose.vcenter : (txt.font.valign == :top ? Compose.vtop : Compose.vbottom))
rotations = (txt.font.rotation == 0.0 ? [] : [Compose.Rotation(txt.font.rotation, Compose.Point(Compose.x_measure(x), Compose.y_measure(y)))])
Gadfly.Guide.annotation(Compose.compose(
Compose.context(),
Compose.text(x, y, txt.str, halign, valign, rotations...),
Compose.font(string(txt.family)),
Compose.fontsize(txt.pointsize * Gadfly.pt),
Compose.stroke(txt.color),
Compose.fill(txt.color)
Compose.font(string(txt.font.family)),
Compose.fontsize(txt.font.pointsize * Gadfly.pt),
Compose.stroke(txt.font.color),
Compose.fill(txt.font.color)
))
end

View File

@ -121,10 +121,9 @@ end
# -----------------------------------------------------------------------
"Wrap a string with font info"
immutable PlotText
str::@compat(AbstractString)
family::Symbol
immutable Font
family::AbstractString
pointsize::Int
halign::Symbol
valign::Symbol
@ -132,18 +131,20 @@ immutable PlotText
color::Colorant
end
function text(str, args...)
"Create a Font from a list of unordered features"
function font(args...)
# defaults
family = :courier
pointsize = 12
family = "Helvetica"
pointsize = 14
halign = :hcenter
valign = :vcenter
rotation = 0.0
color = colorant"black"
for arg in args
T = typeof(arg)
if arg == :center
halign = :hcenter
valign = :vcenter
@ -151,13 +152,13 @@ function text(str, args...)
halign = arg
elseif arg in (:vcenter, :top, :bottom)
valign = arg
elseif typeof(arg) <: Colorant
elseif T <: Colorant
color = arg
elseif isa(arg, Symbol)
elseif T <: @compat Union{Symbol,AbstractString}
try
color = parse(Colorant, string(arg))
catch
family = arg
family = string(arg)
end
elseif typeof(arg) <: Integer
pointsize = arg
@ -168,9 +169,20 @@ function text(str, args...)
end
end
PlotText(string(str), family, pointsize, halign, valign, rotation, color)
Font(family, pointsize, halign, valign, rotation, color)
end
"Wrap a string with font info"
immutable PlotText
str::@compat(AbstractString)
font::Font
end
function text(str, args...)
PlotText(string(str), font(args...))
end
# -----------------------------------------------------------------------
type OHLC{T<:Real}