Font and tick/guide/legend fonts
This commit is contained in:
parent
47f21b1652
commit
a7da999bd7
@ -100,7 +100,7 @@ const examples = PlotExample[
|
|||||||
[
|
[
|
||||||
:(y = rand(10)),
|
:(y = rand(10)),
|
||||||
:(plot(y, ann=(3,y[3],text("this is #3",:left)))),
|
:(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"))]))
|
||||||
]),
|
]),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|||||||
@ -160,7 +160,9 @@ _plotDefaults[:link] = false
|
|||||||
_plotDefaults[:linkx] = false
|
_plotDefaults[:linkx] = false
|
||||||
_plotDefaults[:linky] = false
|
_plotDefaults[:linky] = false
|
||||||
_plotDefaults[:linkfunc] = nothing
|
_plotDefaults[:linkfunc] = nothing
|
||||||
# _plotDefaults[:dataframe] = nothing
|
_plotDefaults[:tickfont] = font(13)
|
||||||
|
_plotDefaults[:guidefont] = font(16)
|
||||||
|
_plotDefaults[:legendfont] = font(10)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -56,6 +56,9 @@ supportedArgs(::GadflyPackage) = [
|
|||||||
:z,
|
:z,
|
||||||
# :linkx,
|
# :linkx,
|
||||||
# :linky,
|
# :linky,
|
||||||
|
:tickfont,
|
||||||
|
:guidefont,
|
||||||
|
:legendfont,
|
||||||
]
|
]
|
||||||
supportedAxes(::GadflyPackage) = [:auto, :left]
|
supportedAxes(::GadflyPackage) = [:auto, :left]
|
||||||
supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc]
|
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.ylabel(d[:ylabel]),
|
||||||
Gadfly.Guide.title(d[:title])]
|
Gadfly.Guide.title(d[:title])]
|
||||||
|
|
||||||
|
kwargs = Dict()
|
||||||
|
|
||||||
# hide the legend
|
# hide the legend?
|
||||||
if get(d, :legend, true)
|
if !get(d, :legend, true)
|
||||||
extra_theme_args = Any[]
|
kwargs[:key_position] = :none
|
||||||
else
|
|
||||||
extra_theme_args = Any[(:key_position, :none)]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# fonts
|
||||||
|
tfont, gfont, lfont = d[:tickfont], d[:guidefont], d[:legendfont]
|
||||||
|
|
||||||
fg = getColor(d[:foreground_color])
|
fg = getColor(d[:foreground_color])
|
||||||
gplt.theme = Gadfly.Theme(;
|
gplt.theme = Gadfly.Theme(;
|
||||||
background_color = getColor(d[:background_color]),
|
background_color = getColor(d[:background_color]),
|
||||||
# grid_color = fg,
|
|
||||||
minor_label_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_color = fg,
|
||||||
|
major_label_font = gfont.family,
|
||||||
|
major_label_font_size = gfont.pointsize * Gadfly.pt,
|
||||||
key_title_color = fg,
|
key_title_color = fg,
|
||||||
|
key_title_font = gfont.family,
|
||||||
|
key_title_font_size = gfont.pointsize * Gadfly.pt,
|
||||||
key_label_color = fg,
|
key_label_color = fg,
|
||||||
|
key_label_font = lfont.family,
|
||||||
|
key_label_font_size = lfont.pointsize * Gadfly.pt,
|
||||||
plot_padding = 1 * Gadfly.mm,
|
plot_padding = 1 * Gadfly.mm,
|
||||||
extra_theme_args...
|
kwargs...
|
||||||
)
|
)
|
||||||
gplt
|
gplt
|
||||||
end
|
end
|
||||||
@ -661,16 +673,16 @@ function createGadflyAnnotationObject(x, y, val::@compat(AbstractString))
|
|||||||
end
|
end
|
||||||
|
|
||||||
function createGadflyAnnotationObject(x, y, txt::PlotText)
|
function createGadflyAnnotationObject(x, y, txt::PlotText)
|
||||||
halign = (txt.halign == :hcenter ? Compose.hcenter : (txt.halign == :left ? Compose.hleft : Compose.hright))
|
halign = (txt.font.halign == :hcenter ? Compose.hcenter : (txt.font.halign == :left ? Compose.hleft : Compose.hright))
|
||||||
valign = (txt.valign == :vcenter ? Compose.vcenter : (txt.valign == :top ? Compose.vtop : Compose.vbottom))
|
valign = (txt.font.valign == :vcenter ? Compose.vcenter : (txt.font.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)))])
|
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(
|
Gadfly.Guide.annotation(Compose.compose(
|
||||||
Compose.context(),
|
Compose.context(),
|
||||||
Compose.text(x, y, txt.str, halign, valign, rotations...),
|
Compose.text(x, y, txt.str, halign, valign, rotations...),
|
||||||
Compose.font(string(txt.family)),
|
Compose.font(string(txt.font.family)),
|
||||||
Compose.fontsize(txt.pointsize * Gadfly.pt),
|
Compose.fontsize(txt.font.pointsize * Gadfly.pt),
|
||||||
Compose.stroke(txt.color),
|
Compose.stroke(txt.font.color),
|
||||||
Compose.fill(txt.color)
|
Compose.fill(txt.font.color)
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
36
src/types.jl
36
src/types.jl
@ -121,10 +121,9 @@ end
|
|||||||
|
|
||||||
# -----------------------------------------------------------------------
|
# -----------------------------------------------------------------------
|
||||||
|
|
||||||
"Wrap a string with font info"
|
|
||||||
immutable PlotText
|
immutable Font
|
||||||
str::@compat(AbstractString)
|
family::AbstractString
|
||||||
family::Symbol
|
|
||||||
pointsize::Int
|
pointsize::Int
|
||||||
halign::Symbol
|
halign::Symbol
|
||||||
valign::Symbol
|
valign::Symbol
|
||||||
@ -132,18 +131,20 @@ immutable PlotText
|
|||||||
color::Colorant
|
color::Colorant
|
||||||
end
|
end
|
||||||
|
|
||||||
|
"Create a Font from a list of unordered features"
|
||||||
function text(str, args...)
|
function font(args...)
|
||||||
|
|
||||||
# defaults
|
# defaults
|
||||||
family = :courier
|
family = "Helvetica"
|
||||||
pointsize = 12
|
pointsize = 14
|
||||||
halign = :hcenter
|
halign = :hcenter
|
||||||
valign = :vcenter
|
valign = :vcenter
|
||||||
rotation = 0.0
|
rotation = 0.0
|
||||||
color = colorant"black"
|
color = colorant"black"
|
||||||
|
|
||||||
for arg in args
|
for arg in args
|
||||||
|
T = typeof(arg)
|
||||||
|
|
||||||
if arg == :center
|
if arg == :center
|
||||||
halign = :hcenter
|
halign = :hcenter
|
||||||
valign = :vcenter
|
valign = :vcenter
|
||||||
@ -151,13 +152,13 @@ function text(str, args...)
|
|||||||
halign = arg
|
halign = arg
|
||||||
elseif arg in (:vcenter, :top, :bottom)
|
elseif arg in (:vcenter, :top, :bottom)
|
||||||
valign = arg
|
valign = arg
|
||||||
elseif typeof(arg) <: Colorant
|
elseif T <: Colorant
|
||||||
color = arg
|
color = arg
|
||||||
elseif isa(arg, Symbol)
|
elseif T <: @compat Union{Symbol,AbstractString}
|
||||||
try
|
try
|
||||||
color = parse(Colorant, string(arg))
|
color = parse(Colorant, string(arg))
|
||||||
catch
|
catch
|
||||||
family = arg
|
family = string(arg)
|
||||||
end
|
end
|
||||||
elseif typeof(arg) <: Integer
|
elseif typeof(arg) <: Integer
|
||||||
pointsize = arg
|
pointsize = arg
|
||||||
@ -168,9 +169,20 @@ function text(str, args...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
PlotText(string(str), family, pointsize, halign, valign, rotation, color)
|
Font(family, pointsize, halign, valign, rotation, color)
|
||||||
end
|
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}
|
type OHLC{T<:Real}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user