Merge pull request #1255 from daschw/fonts

Allow setting fonts in recipes (fix #555)
This commit is contained in:
Daniel Schwabeneder 2017-11-20 15:17:33 +01:00 committed by GitHub
commit f2e2ffa170
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 252 additions and 85 deletions

View File

@ -66,11 +66,17 @@ const _arg_desc = KW(
:dpi => "Number. Dots Per Inch of output figures", :dpi => "Number. Dots Per Inch of output figures",
:display_type => "Symbol (`:auto`, `:gui`, or `:inline`). When supported, `display` will either open a GUI window or plot inline.", :display_type => "Symbol (`:auto`, `:gui`, or `:inline`). When supported, `display` will either open a GUI window or plot inline.",
:extra_kwargs => "KW (Dict{Symbol,Any}). Pass a map of extra keyword args which may be specific to a backend.", :extra_kwargs => "KW (Dict{Symbol,Any}). Pass a map of extra keyword args which may be specific to a backend.",
:fontfamily => "String or Symbol. Default font family for title, legend entries, tick labels and guides",
# subplot args # subplot args
:title => "String. Subplot title.", :title => "String. Subplot title.",
:title_location => "Symbol. Position of subplot title. Values: `:left`, `:center`, `:right`", :title_location => "Symbol. Position of subplot title. Values: `:left`, `:center`, `:right`",
:titlefont => "Font. Font of subplot title.", :titlefontfamily => "String or Symbol. Font family of subplot title.",
:titlefontsize => "Integer. Font pointsize of subplot title.",
:titlefonthalign => "Symbol. Font horizontal alignment of subplot title: :hcenter, :left, :right or :center",
:titlefontvalign => "Symbol. Font vertical alignment of subplot title: :vcenter, :top, :bottom or :center",
:titlefontrotation => "Real. Font rotation of subplot title",
:titlefontcolor => "Color Type. Font color of subplot title",
:background_color_subplot => "Color Type or `:match` (matches `:background_color`). Base background color of the subplot.", :background_color_subplot => "Color Type or `:match` (matches `:background_color`). Base background color of the subplot.",
:background_color_legend => "Color Type or `:match` (matches `:background_color_subplot`). Background color of the legend.", :background_color_legend => "Color Type or `:match` (matches `:background_color_subplot`). Background color of the legend.",
:background_color_inside => "Color Type or `:match` (matches `:background_color_subplot`). Background color inside the plot area (under the grid).", :background_color_inside => "Color Type or `:match` (matches `:background_color_subplot`). Background color inside the plot area (under the grid).",
@ -79,7 +85,12 @@ const _arg_desc = KW(
:foreground_color_title => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of subplot title.", :foreground_color_title => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of subplot title.",
:color_palette => "Vector of colors (cycle through) or color gradient (generate list from gradient) or `:auto` (generate a color list using `Colors.distiguishable_colors` and custom seed colors chosen to contrast with the background). The color palette is a color list from which series colors are automatically chosen.", :color_palette => "Vector of colors (cycle through) or color gradient (generate list from gradient) or `:auto` (generate a color list using `Colors.distiguishable_colors` and custom seed colors chosen to contrast with the background). The color palette is a color list from which series colors are automatically chosen.",
:legend => "Bool (show the legend?) or Symbol (legend position). Symbol values: `:none`, `:best`, `:right`, `:left`, `:top`, `:bottom`, `:inside`, `:legend`, `:topright`, `:topleft`, `:bottomleft`, `:bottomright` (note: only some may be supported in each backend)", :legend => "Bool (show the legend?) or Symbol (legend position). Symbol values: `:none`, `:best`, `:right`, `:left`, `:top`, `:bottom`, `:inside`, `:legend`, `:topright`, `:topleft`, `:bottomleft`, `:bottomright` (note: only some may be supported in each backend)",
:legendtitle => "String or nothing (default). Sets the legend title.", :legendfontfamily => "String or Symbol. Font family of legend entries.",
:legendfontsize => "Integer. Font pointsize of legend entries.",
:legendfonthalign => "Symbol. Font horizontal alignment of legend entries: :hcenter, :left, :right or :center",
:legendfontvalign => "Symbol. Font vertical alignment of legend entries: :vcenter, :top, :bottom or :center",
:legendfontrotation => "Real. Font rotation of legend entries",
:legendfontcolor => "Color Type. Font color of legend entries",
:colorbar => "Bool (show the colorbar?) or Symbol (colorbar position). Symbol values: `:none`, `:best`, `:right`, `:left`, `:top`, `:bottom`, `:legend` (matches legend value) (note: only some may be supported in each backend)", :colorbar => "Bool (show the colorbar?) or Symbol (colorbar position). Symbol values: `:none`, `:best`, `:right`, `:left`, `:top`, `:bottom`, `:legend` (matches legend value) (note: only some may be supported in each backend)",
:clims => "`:auto` or NTuple{2,Number}. Fixes the limits of the colorbar.", :clims => "`:auto` or NTuple{2,Number}. Fixes the limits of the colorbar.",
:legendfont => "Font. Font of legend items.", :legendfont => "Font. Font of legend items.",
@ -104,8 +115,18 @@ const _arg_desc = KW(
:rotation => "Number. Degrees rotation of tick labels.", :rotation => "Number. Degrees rotation of tick labels.",
:flip => "Bool. Should we flip (reverse) the axis?", :flip => "Bool. Should we flip (reverse) the axis?",
:formatter => "Function, :scientific, or :auto. A method which converts a number to a string for tick labeling.", :formatter => "Function, :scientific, or :auto. A method which converts a number to a string for tick labeling.",
:tickfont => "Font. Font of axis tick labels.", :tickfontfamily => "String or Symbol. Font family of tick labels.",
:guidefont => "Font. Font of axis guide (label).", :tickfontsize => "Integer. Font pointsize of tick labels.",
:tickfonthalign => "Symbol. Font horizontal alignment of tick labels: :hcenter, :left, :right or :center",
:tickfontvalign => "Symbol. Font vertical alignment of tick labels: :vcenter, :top, :bottom or :center",
:tickfontrotation => "Real. Font rotation of tick labels",
:tickfontcolor => "Color Type. Font color of tick labels",
:guidefontfamily => "String or Symbol. Font family of axes guides.",
:guidefontsize => "Integer. Font pointsize of axes guides.",
:guidefonthalign => "Symbol. Font horizontal alignment of axes guides: :hcenter, :left, :right or :center",
:guidefontvalign => "Symbol. Font vertical alignment of axes guides: :vcenter, :top, :bottom or :center",
:guidefontrotation => "Real. Font rotation of axes guides",
:guidefontcolor => "Color Type. Font color of axes guides",
:foreground_color_axis => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of axis ticks.", :foreground_color_axis => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of axis ticks.",
:foreground_color_border => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of plot area border (spines).", :foreground_color_border => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of plot area border (spines).",
:foreground_color_text => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of tick labels.", :foreground_color_text => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of tick labels.",

View File

@ -273,6 +273,7 @@ const _plot_defaults = KW(
:background_color => colorant"white", # default for all backgrounds, :background_color => colorant"white", # default for all backgrounds,
:background_color_outside => :match, # background outside grid, :background_color_outside => :match, # background outside grid,
:foreground_color => :auto, # default for all foregrounds, and title color, :foreground_color => :auto, # default for all foregrounds, and title color,
:fontfamily => "sans-serif",
:size => (600,400), :size => (600,400),
:pos => (0,0), :pos => (0,0),
:window_title => "Plots.jl", :window_title => "Plots.jl",
@ -292,7 +293,13 @@ const _plot_defaults = KW(
const _subplot_defaults = KW( const _subplot_defaults = KW(
:title => "", :title => "",
:title_location => :center, # also :left or :right :title_location => :center, # also :left or :right
:titlefont => font(14), :fontfamily_subplot => :match,
:titlefontfamily => :match,
:titlefontsize => 14,
:titlefonthalign => :hcenter,
:titlefontvalign => :vcenter,
:titlefontrotation => 0.0,
:titlefontcolor => :match,
:background_color_subplot => :match, # default for other bg colors... match takes plot default :background_color_subplot => :match, # default for other bg colors... match takes plot default
:background_color_legend => :match, # background of legend :background_color_legend => :match, # background of legend
:background_color_inside => :match, # background inside grid :background_color_inside => :match, # background inside grid
@ -304,7 +311,12 @@ const _subplot_defaults = KW(
:legendtitle => nothing, :legendtitle => nothing,
:colorbar => :legend, :colorbar => :legend,
:clims => :auto, :clims => :auto,
:legendfont => font(8), :legendfontfamily => :match,
:legendfontsize => 8,
:legendfonthalign => :hcenter,
:legendfontvalign => :vcenter,
:legendfontrotation => 0.0,
:legendfontcolor => :match,
:annotations => [], # annotation tuples... list of (x,y,annotation) :annotations => [], # annotation tuples... list of (x,y,annotation)
:projection => :none, # can also be :polar or :3d :projection => :none, # can also be :polar or :3d
:aspect_ratio => :none, # choose from :none or :equal :aspect_ratio => :none, # choose from :none or :equal
@ -327,8 +339,18 @@ const _axis_defaults = KW(
:rotation => 0, :rotation => 0,
:flip => false, :flip => false,
:link => [], :link => [],
:tickfont => font(8), :tickfontfamily => :match,
:guidefont => font(11), :tickfontsize => 8,
:tickfonthalign => :hcenter,
:tickfontvalign => :vcenter,
:tickfontrotation => 0.0,
:tickfontcolor => :match,
:guidefontfamily => :match,
:guidefontsize => 11,
:guidefonthalign => :hcenter,
:guidefontvalign => :vcenter,
:guidefontrotation => 0.0,
:guidefontcolor => :match,
:foreground_color_axis => :match, # axis border/tick colors, :foreground_color_axis => :match, # axis border/tick colors,
:foreground_color_border => :match, # plot area border/spines, :foreground_color_border => :match, # plot area border/spines,
:foreground_color_text => :match, # tick text color, :foreground_color_text => :match, # tick text color,
@ -397,10 +419,10 @@ const _all_defaults = KW[
const _initial_defaults = deepcopy(_all_defaults) const _initial_defaults = deepcopy(_all_defaults)
# to be able to reset font sizes to initial values # to be able to reset font sizes to initial values
const _initial_fontsizes = Dict(:titlefont => _subplot_defaults[:titlefont].pointsize, const _initial_fontsizes = Dict(:titlefont => _subplot_defaults[:titlefontsize],
:legendfont => _subplot_defaults[:legendfont].pointsize, :legendfont => _subplot_defaults[:legendfontsize],
:tickfont => _axis_defaults[:tickfont].pointsize, :tickfont => _axis_defaults[:tickfontsize],
:guidefont => _axis_defaults[:guidefont].pointsize) :guidefont => _axis_defaults[:guidefontsize])
const _all_args = sort(collect(union(map(keys, _all_defaults)...))) const _all_args = sort(collect(union(map(keys, _all_defaults)...)))
@ -743,6 +765,38 @@ function processGridArg!(d::KW, arg, letter)
end end
end end
function processFontArg!(d::KW, fontname::Symbol, arg)
T = typeof(arg)
if T <: Font
d[Symbol(fontname, :family)] = arg.family
d[Symbol(fontname, :size)] = arg.pointsize
d[Symbol(fontname, :halign)] = arg.halign
d[Symbol(fontname, :valign)] = arg.valign
d[Symbol(fontname, :rotation)] = arg.rotation
d[Symbol(fontname, :color)] = arg.color
elseif arg == :center
d[Symbol(fontname, :halign)] = :hcenter
d[Symbol(fontname, :valign)] = :vcenter
elseif arg in (:hcenter, :left, :right)
d[Symbol(fontname, :halign)] = arg
elseif arg in (:vcenter, :top, :bottom)
d[Symbol(fontname, :valign)] = arg
elseif T <: Colorant
d[Symbol(fontname, :color)] = arg
elseif T <: Symbol || T <: AbstractString
try
d[Symbol(fontname, :color)] = parse(Colorant, string(arg))
catch
d[Symbol(fontname, :family)] = string(arg)
end
elseif typeof(arg) <: Integer
d[Symbol(fontname, :size)] = arg
elseif typeof(arg) <: Real
d[Symbol(fontname, :rotation)] = convert(Float64, arg)
else
warn("Skipped font arg: $arg ($(typeof(arg)))")
end
end
_replace_markershape(shape::Symbol) = get(_markerAliases, shape, shape) _replace_markershape(shape::Symbol) = get(_markerAliases, shape, shape)
_replace_markershape(shapes::AVec) = map(_replace_markershape, shapes) _replace_markershape(shapes::AVec) = map(_replace_markershape, shapes)
@ -811,6 +865,32 @@ function preprocessArgs!(d::KW)
end end
end end
# fonts
for fontname in (:titlefont, :legendfont)
args = pop!(d, fontname, ())
for arg in wraptuple(args)
processFontArg!(d, fontname, arg)
end
end
# handle font args common to all axes
for fontname in (:tickfont, :guidefont)
args = pop!(d, fontname, ())
for arg in wraptuple(args)
for letter in (:x, :y, :z)
processFontArg!(d, Symbol(letter, fontname), arg)
end
end
end
# handle individual axes font args
for letter in (:x, :y, :z)
for fontname in (:tickfont, :guidefont)
args = pop!(d, Symbol(letter, fontname), ())
for arg in wraptuple(args)
processFontArg!(d, Symbol(letter, fontname), arg)
end
end
end
# handle line args # handle line args
for arg in wraptuple(pop!(d, :line, ())) for arg in wraptuple(pop!(d, :line, ()))
processLineArg(d, arg) processLineArg(d, arg)
@ -1084,6 +1164,12 @@ const _match_map = KW(
:top_margin => :margin, :top_margin => :margin,
:right_margin => :margin, :right_margin => :margin,
:bottom_margin => :margin, :bottom_margin => :margin,
:titlefontfamily => :fontfamily_subplot,
:legendfontfamily => :fontfamily_subplot,
:titlefontcolor => :foreground_color_subplot,
:legendfontcolor => :foreground_color_subplot,
:tickfontcolor => :foreground_color_text,
:guidefontcolor => :foreground_color_guide,
) )
# these can match values from the parent container (axis --> subplot --> plot) # these can match values from the parent container (axis --> subplot --> plot)
@ -1095,6 +1181,9 @@ const _match_map2 = KW(
:foreground_color_grid => :foreground_color_subplot, :foreground_color_grid => :foreground_color_subplot,
:foreground_color_guide => :foreground_color_subplot, :foreground_color_guide => :foreground_color_subplot,
:foreground_color_text => :foreground_color_subplot, :foreground_color_text => :foreground_color_subplot,
:fontfamily_subplot => :fontfamily,
:tickfontfamily => :fontfamily_subplot,
:guidefontfamily => :fontfamily_subplot,
) )
# properly retrieve from plt.attr, passing `:match` to the correct key # properly retrieve from plt.attr, passing `:match` to the correct key

View File

@ -51,8 +51,8 @@ _series_updated(plt::Plot, series::Series) = nothing
_before_layout_calcs(plt::Plot) = nothing _before_layout_calcs(plt::Plot) = nothing
title_padding(sp::Subplot) = sp[:title] == "" ? 0mm : sp[:titlefont].pointsize * pt title_padding(sp::Subplot) = sp[:title] == "" ? 0mm : sp[:titlefontsize] * pt
guide_padding(axis::Axis) = axis[:guide] == "" ? 0mm : axis[:guidefont].pointsize * pt guide_padding(axis::Axis) = axis[:guide] == "" ? 0mm : axis[:guidefontsize] * pt
"Returns the (width,height) of a text label." "Returns the (width,height) of a text label."
function text_size(lablen::Int, sz::Number, rot::Number = 0) function text_size(lablen::Int, sz::Number, rot::Number = 0)
@ -93,7 +93,7 @@ function tick_padding(axis::Axis)
# hgt # hgt
# get the height of the rotated label # get the height of the rotated label
text_size(longest_label, axis[:tickfont].pointsize, rot)[2] text_size(longest_label, axis[:tickfontsize], rot)[2]
end end
end end

View File

@ -24,10 +24,13 @@ const _glvisualize_attr = merge_with_base_supported([
:markerstrokewidth, :markerstrokecolor, :markerstrokealpha, :markerstrokewidth, :markerstrokecolor, :markerstrokealpha,
:fillrange, :fillcolor, :fillalpha, :fillrange, :fillcolor, :fillalpha,
:bins, :bar_width, :bar_edges, :bar_position, :bins, :bar_width, :bar_edges, :bar_position,
:title, :title_location, :titlefont, :title, :title_location,
:window_title, :window_title,
:guide, :lims, :ticks, :scale, :flip, :rotation, :guide, :lims, :ticks, :scale, :flip, :rotation,
:tickfont, :guidefont, :legendfont, :titlefontsize, :titlefontcolor,
:legendfontsize, :legendfontcolor,
:tickfontsize,
:guidefontsize, :guidefontcolor,
:grid, :gridalpha, :gridstyle, :gridlinewidth, :grid, :gridalpha, :gridstyle, :gridlinewidth,
:legend, :colorbar, :legend, :colorbar,
:marker_z, :marker_z,
@ -612,7 +615,7 @@ function draw_ticks(
axis, ticks, isx, isorigin, lims, m, text = "", axis, ticks, isx, isorigin, lims, m, text = "",
positions = Point2f0[], offsets=Vec2f0[] positions = Point2f0[], offsets=Vec2f0[]
) )
sz = pointsize(axis[:tickfont]) sz = pointsize(tickfont(axis))
atlas = GLVisualize.get_texture_atlas() atlas = GLVisualize.get_texture_atlas()
font = GLVisualize.defaultfont() font = GLVisualize.defaultfont()
@ -745,7 +748,7 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are
:position => map(x-> x[2], ticklabels), :position => map(x-> x[2], ticklabels),
:offset => map(last, ticklabels), :offset => map(last, ticklabels),
:color => fcolor, :color => fcolor,
:relative_scale => pointsize(xaxis[:tickfont]), :relative_scale => pointsize(tickfont(xaxis)),
:scale_primitive => false :scale_primitive => false
) )
push!(axis_vis, visualize(map(first, ticklabels), Style(:default), kw_args)) push!(axis_vis, visualize(map(first, ticklabels), Style(:default), kw_args))
@ -760,7 +763,7 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are
:position => map(x-> x[2], ticklabels), :position => map(x-> x[2], ticklabels),
:offset => map(last, ticklabels), :offset => map(last, ticklabels),
:color => fcolor, :color => fcolor,
:relative_scale => pointsize(xaxis[:tickfont]), :relative_scale => pointsize(tickfont(xaxis)),
:scale_primitive => false :scale_primitive => false
) )
push!(axis_vis, visualize(map(first, ticklabels), Style(:default), kw_args)) push!(axis_vis, visualize(map(first, ticklabels), Style(:default), kw_args))
@ -777,8 +780,8 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are
area_w = GeometryTypes.widths(area) area_w = GeometryTypes.widths(area)
if sp[:title] != "" if sp[:title] != ""
tf = sp[:titlefont]; color = gl_color(sp[:foreground_color_title]) tf = titlefont(sp)
font = Plots.Font(tf.family, tf.pointsize, :hcenter, :top, tf.rotation, color) font = Plots.Font(tf.family, tf.pointsize, :hcenter, :top, tf.rotation, tf.color)
xy = Point2f0(area.w/2, area_w[2] + pointsize(tf)/2) xy = Point2f0(area.w/2, area_w[2] + pointsize(tf)/2)
kw = Dict(:model => text_model(font, xy), :scale_primitive => true) kw = Dict(:model => text_model(font, xy), :scale_primitive => true)
extract_font(font, kw) extract_font(font, kw)
@ -786,9 +789,9 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are
push!(axis_vis, glvisualize_text(xy, t, kw)) push!(axis_vis, glvisualize_text(xy, t, kw))
end end
if xaxis[:guide] != "" if xaxis[:guide] != ""
tf = xaxis[:guidefont]; color = gl_color(xaxis[:foreground_color_guide]) tf = guidefont(xaxis)
xy = Point2f0(area.w/2, - pointsize(tf)/2) xy = Point2f0(area.w/2, - pointsize(tf)/2)
font = Plots.Font(tf.family, tf.pointsize, :hcenter, :bottom, tf.rotation, color) font = Plots.Font(tf.family, tf.pointsize, :hcenter, :bottom, tf.rotation, tf.color)
kw = Dict(:model => text_model(font, xy), :scale_primitive => true) kw = Dict(:model => text_model(font, xy), :scale_primitive => true)
t = PlotText(xaxis[:guide], font) t = PlotText(xaxis[:guide], font)
extract_font(font, kw) extract_font(font, kw)
@ -796,8 +799,8 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are
end end
if yaxis[:guide] != "" if yaxis[:guide] != ""
tf = yaxis[:guidefont]; color = gl_color(yaxis[:foreground_color_guide]) tf = guidefont(yaxis)
font = Plots.Font(tf.family, tf.pointsize, :hcenter, :top, 90f0, color) font = Plots.Font(tf.family, tf.pointsize, :hcenter, :top, 90f0, tf.color)
xy = Point2f0(-pointsize(tf)/2, area.h/2) xy = Point2f0(-pointsize(tf)/2, area.h/2)
kw = Dict(:model => text_model(font, xy), :scale_primitive=>true) kw = Dict(:model => text_model(font, xy), :scale_primitive=>true)
t = PlotText(yaxis[:guide], font) t = PlotText(yaxis[:guide], font)
@ -1483,9 +1486,8 @@ function make_label(sp, series, i)
else else
series[:label] series[:label]
end end
color = sp[:foreground_color_legend] ft = legendfont(sp)
ft = sp[:legendfont] font = Plots.Font(ft.family, ft.pointsize, :left, :bottom, 0.0, ft.color)
font = Plots.Font(ft.family, ft.pointsize, :left, :bottom, 0.0, color)
xy = Point2f0(w+gap, 0.0) xy = Point2f0(w+gap, 0.0)
kw = Dict(:model => text_model(font, xy), :scale_primitive=>false) kw = Dict(:model => text_model(font, xy), :scale_primitive=>false)
extract_font(font, kw) extract_font(font, kw)

View File

@ -22,7 +22,14 @@ const _gr_attr = merge_with_base_supported([
:layout, :layout,
:title, :window_title, :title, :window_title,
:guide, :lims, :ticks, :scale, :flip, :guide, :lims, :ticks, :scale, :flip,
:tickfont, :guidefont, :legendfont, :titlefontfamily, :titlefontsize, :titlefonthalign, :titlefontvalign,
:titlefontrotation, :titlefontcolor,
:legendfontfamily, :legendfontsize, :legendfonthalign, :legendfontvalign,
:legendfontrotation, :legendfontcolor,
:tickfontfamily, :tickfontsize, :tickfonthalign, :tickfontvalign,
:tickfontrotation, :tickfontcolor,
:guidefontfamily, :guidefontsize, :guidefonthalign, :guidefontvalign,
:guidefontrotation, :guidefontcolor,
:grid, :gridalpha, :gridstyle, :gridlinewidth, :grid, :gridalpha, :gridstyle, :gridlinewidth,
:legend, :legendtitle, :colorbar, :legend, :legendtitle, :colorbar,
:fill_z, :line_z, :marker_z, :levels, :fill_z, :line_z, :marker_z, :levels,
@ -583,10 +590,9 @@ end
function gr_set_xticks_font(sp) function gr_set_xticks_font(sp)
flip = sp[:yaxis][:flip] flip = sp[:yaxis][:flip]
mirror = sp[:xaxis][:mirror] mirror = sp[:xaxis][:mirror]
gr_set_font(sp[:xaxis][:tickfont], gr_set_font(tickfont(sp[:xaxis]),
halign = (:left, :hcenter, :right)[sign(sp[:xaxis][:rotation]) + 2], halign = (:left, :hcenter, :right)[sign(sp[:xaxis][:rotation]) + 2],
valign = (mirror ? :bottom : :top), valign = (mirror ? :bottom : :top),
color = sp[:xaxis][:foreground_color_axis],
rotation = sp[:xaxis][:rotation]) rotation = sp[:xaxis][:rotation])
return flip, mirror return flip, mirror
end end
@ -595,10 +601,9 @@ end
function gr_set_yticks_font(sp) function gr_set_yticks_font(sp)
flip = sp[:xaxis][:flip] flip = sp[:xaxis][:flip]
mirror = sp[:yaxis][:mirror] mirror = sp[:yaxis][:mirror]
gr_set_font(sp[:yaxis][:tickfont], gr_set_font(tickfont(sp[:yaxis]),
halign = (mirror ? :left : :right), halign = (mirror ? :left : :right),
valign = (:top, :vcenter, :bottom)[sign(sp[:yaxis][:rotation]) + 2], valign = (:top, :vcenter, :bottom)[sign(sp[:yaxis][:rotation]) + 2],
color = sp[:yaxis][:foreground_color_axis],
rotation = sp[:yaxis][:rotation]) rotation = sp[:yaxis][:rotation])
return flip, mirror return flip, mirror
end end
@ -759,8 +764,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
end end
# draw the axes # draw the axes
gr_set_font(xaxis[:tickfont]) gr_set_font(tickfont(xaxis))
gr_set_textcolor(xaxis[:foreground_color_text])
GR.setlinewidth(1) GR.setlinewidth(1)
if is3d(sp) if is3d(sp)
@ -887,7 +891,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
# add the guides # add the guides
GR.savestate() GR.savestate()
if sp[:title] != "" if sp[:title] != ""
gr_set_font(sp[:titlefont]) gr_set_font(titlefont(sp))
loc = sp[:title_location] loc = sp[:title_location]
if loc == :left if loc == :left
xpos = viewport_plotarea[1] xpos = viewport_plotarea[1]
@ -900,27 +904,24 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
halign = GR.TEXT_HALIGN_CENTER halign = GR.TEXT_HALIGN_CENTER
end end
GR.settextalign(halign, GR.TEXT_VALIGN_TOP) GR.settextalign(halign, GR.TEXT_VALIGN_TOP)
gr_set_textcolor(sp[:foreground_color_title])
gr_text(xpos, viewport_subplot[4], sp[:title]) gr_text(xpos, viewport_subplot[4], sp[:title])
end end
if xaxis[:guide] != "" if xaxis[:guide] != ""
gr_set_font(xaxis[:guidefont]) gr_set_font(guidefont(xaxis))
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_BOTTOM) GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_BOTTOM)
gr_set_textcolor(xaxis[:foreground_color_guide])
gr_text(gr_view_xcenter(), viewport_subplot[3], xaxis[:guide]) gr_text(gr_view_xcenter(), viewport_subplot[3], xaxis[:guide])
end end
if yaxis[:guide] != "" if yaxis[:guide] != ""
gr_set_font(yaxis[:guidefont]) gr_set_font(guidefont(yaxis))
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_TOP) GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_TOP)
GR.setcharup(-1, 0) GR.setcharup(-1, 0)
gr_set_textcolor(yaxis[:foreground_color_guide])
gr_text(viewport_subplot[1], gr_view_ycenter(), yaxis[:guide]) gr_text(viewport_subplot[1], gr_view_ycenter(), yaxis[:guide])
end end
GR.restorestate() GR.restorestate()
gr_set_font(xaxis[:tickfont]) gr_set_font(tickfont(xaxis))
# this needs to be here to point the colormap to the right indices # this needs to be here to point the colormap to the right indices
GR.setcolormap(1000 + GR.COLORMAP_COOLWARM) GR.setcolormap(1000 + GR.COLORMAP_COOLWARM)
@ -1193,7 +1194,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
GR.savestate() GR.savestate()
GR.selntran(0) GR.selntran(0)
GR.setscale(0) GR.setscale(0)
gr_set_font(sp[:legendfont]) gr_set_font(legendfont(sp))
w = 0 w = 0
i = 0 i = 0
n = 0 n = 0
@ -1215,7 +1216,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
w = max(w, tbx[3] - tbx[1]) w = max(w, tbx[3] - tbx[1])
end end
if w > 0 if w > 0
dy = _gr_point_mult[1] * sp[:legendfont].pointsize * 1.75 dy = _gr_point_mult[1] * sp[:legendfontsize] * 1.75
h = dy*n h = dy*n
(xpos,ypos) = gr_legend_pos(sp[:legend],w,h) (xpos,ypos) = gr_legend_pos(sp[:legend],w,h)
GR.setfillintstyle(GR.INTSTYLE_SOLID) GR.setfillintstyle(GR.INTSTYLE_SOLID)
@ -1227,7 +1228,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
i = 0 i = 0
if sp[:legendtitle] != nothing if sp[:legendtitle] != nothing
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF) GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF)
gr_set_textcolor(sp[:foreground_color_legend]) gr_set_textcolor(sp[:legendfontcolor])
GR.settransparency(1) GR.settransparency(1)
gr_text(xpos - 0.03 + 0.5*w, ypos, string(sp[:legendtitle])) gr_text(xpos - 0.03 + 0.5*w, ypos, string(sp[:legendtitle]))
ypos -= dy ypos -= dy
@ -1269,7 +1270,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
lab = series[:label] lab = series[:label]
end end
GR.settextalign(GR.TEXT_HALIGN_LEFT, GR.TEXT_VALIGN_HALF) GR.settextalign(GR.TEXT_HALIGN_LEFT, GR.TEXT_VALIGN_HALF)
gr_set_textcolor(sp[:foreground_color_legend]) gr_set_textcolor(sp[:legendfontcolor])
gr_text(xpos, ypos, lab) gr_text(xpos, ypos, lab)
ypos -= dy ypos -= dy
end end

View File

@ -32,10 +32,13 @@ const _inspectdr_attr = merge_with_base_supported([
:markerstrokestyle, #Causes warning not to have it... what is this? :markerstrokestyle, #Causes warning not to have it... what is this?
:fillcolor, :fillalpha, #:fillrange, :fillcolor, :fillalpha, #:fillrange,
# :bins, :bar_width, :bar_edges, :bar_position, # :bins, :bar_width, :bar_edges, :bar_position,
:title, :title_location, :titlefont, :title, :title_location,
:window_title, :window_title,
:guide, :lims, :scale, #:ticks, :flip, :rotation, :guide, :lims, :scale, #:ticks, :flip, :rotation,
:tickfont, :guidefont, :legendfont, :titlefontfamily, :titlefontsize, :titlefontcolor,
:legendfontfamily, :legendfontsize, :legendfontcolor,
:tickfontfamily, :tickfontsize, :tickfontcolor,
:guidefontfamily, :guidefontsize, :guidefontcolor,
:grid, :legend, #:colorbar, :grid, :legend, #:colorbar,
# :marker_z, # :marker_z,
# :line_z, # :line_z,
@ -373,24 +376,24 @@ function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend})
l[:frame_canvas].fillcolor = _inspectdr_mapcolor(sp[:background_color_subplot]) l[:frame_canvas].fillcolor = _inspectdr_mapcolor(sp[:background_color_subplot])
l[:frame_data].fillcolor = _inspectdr_mapcolor(sp[:background_color_inside]) l[:frame_data].fillcolor = _inspectdr_mapcolor(sp[:background_color_inside])
l[:frame_data].line.color = _inspectdr_mapcolor(xaxis[:foreground_color_axis]) l[:frame_data].line.color = _inspectdr_mapcolor(xaxis[:foreground_color_axis])
l[:font_title] = InspectDR.Font(sp[:titlefont].family, l[:font_title] = InspectDR.Font(sp[:titlefontfamily],
_inspectdr_mapptsize(sp[:titlefont].pointsize), _inspectdr_mapptsize(sp[:titlefontsize]),
color = _inspectdr_mapcolor(sp[:foreground_color_title]) color = _inspectdr_mapcolor(sp[:titlefontcolor])
) )
#Cannot independently control fonts of axes with InspectDR: #Cannot independently control fonts of axes with InspectDR:
l[:font_axislabel] = InspectDR.Font(xaxis[:guidefont].family, l[:font_axislabel] = InspectDR.Font(xaxis[:guidefontfamily],
_inspectdr_mapptsize(xaxis[:guidefont].pointsize), _inspectdr_mapptsize(xaxis[:guidefontsize]),
color = _inspectdr_mapcolor(xaxis[:foreground_color_guide]) color = _inspectdr_mapcolor(xaxis[:guidefontcolor])
) )
l[:font_ticklabel] = InspectDR.Font(xaxis[:tickfont].family, l[:font_ticklabel] = InspectDR.Font(xaxis[:tickfontfamily],
_inspectdr_mapptsize(xaxis[:tickfont].pointsize), _inspectdr_mapptsize(xaxis[:tickfontsize]),
color = _inspectdr_mapcolor(xaxis[:foreground_color_text]) color = _inspectdr_mapcolor(xaxis[:tickfontcolor])
) )
l[:enable_legend] = (sp[:legend] != :none) l[:enable_legend] = (sp[:legend] != :none)
#l[:halloc_legend] = 150 #TODO: compute??? #l[:halloc_legend] = 150 #TODO: compute???
l[:font_legend] = InspectDR.Font(sp[:legendfont].family, l[:font_legend] = InspectDR.Font(sp[:legendfontfamily],
_inspectdr_mapptsize(sp[:legendfont].pointsize), _inspectdr_mapptsize(sp[:legendfontsize]),
color = _inspectdr_mapcolor(sp[:foreground_color_legend]) color = _inspectdr_mapcolor(sp[:legendfontcolor])
) )
l[:frame_legend].fillcolor = _inspectdr_mapcolor(sp[:background_color_legend]) l[:frame_legend].fillcolor = _inspectdr_mapcolor(sp[:background_color_legend])
end end

View File

@ -19,7 +19,12 @@ const _plotly_attr = merge_with_base_supported([
:markerstrokewidth, :markerstrokecolor, :markerstrokealpha, :markerstrokestyle, :markerstrokewidth, :markerstrokecolor, :markerstrokealpha, :markerstrokestyle,
:fillrange, :fillcolor, :fillalpha, :fillrange, :fillcolor, :fillalpha,
:bins, :bins,
:title, :title_location, :titlefont, :title, :title_location,
:titlefontfamily, :titlefontsize, :titlefonthalign, :titlefontvalign,
:titlefontcolor,
:legendfontfamily, :legendfontsize, :legendfontcolor,
:tickfontfamily, :tickfontsize, :tickfontcolor,
:guidefontfamily, :guidefontsize, :guidefontcolor,
:window_title, :window_title,
:guide, :lims, :ticks, :scale, :flip, :rotation, :guide, :lims, :ticks, :scale, :flip, :rotation,
:tickfont, :guidefont, :legendfont, :tickfont, :guidefont, :legendfont,
@ -256,9 +261,9 @@ function plotly_axis(axis::Axis, sp::Subplot)
ax[:range] = map(scalefunc(axis[:scale]), lims) ax[:range] = map(scalefunc(axis[:scale]), lims)
if !(axis[:ticks] in (nothing, :none)) if !(axis[:ticks] in (nothing, :none))
ax[:titlefont] = plotly_font(axis[:guidefont], axis[:foreground_color_guide]) ax[:titlefont] = plotly_font(guidefont(axis))
ax[:type] = plotly_scale(axis[:scale]) ax[:type] = plotly_scale(axis[:scale])
ax[:tickfont] = plotly_font(axis[:tickfont], axis[:foreground_color_text]) ax[:tickfont] = plotly_font(tickfont(axis))
ax[:tickcolor] = framestyle in (:zerolines, :grid) || !axis[:showaxis] ? rgba_string(invisible()) : rgb_string(axis[:foreground_color_axis]) ax[:tickcolor] = framestyle in (:zerolines, :grid) || !axis[:showaxis] ? rgba_string(invisible()) : rgb_string(axis[:foreground_color_axis])
ax[:linecolor] = rgba_string(axis[:foreground_color_axis]) ax[:linecolor] = rgba_string(axis[:foreground_color_axis])
@ -331,8 +336,8 @@ function plotly_layout(plt::Plot)
0.5 * (left(bb) + right(bb)) 0.5 * (left(bb) + right(bb))
end end
titlex, titley = xy_mm_to_pcts(xmm, top(bbox(sp)), w*px, h*px) titlex, titley = xy_mm_to_pcts(xmm, top(bbox(sp)), w*px, h*px)
titlefont = font(sp[:titlefont], :top, sp[:foreground_color_title]) title_font = font(titlefont(sp), :top)
push!(d_out[:annotations], plotly_annotation_dict(titlex, titley, text(sp[:title], titlefont))) push!(d_out[:annotations], plotly_annotation_dict(titlex, titley, text(sp[:title], title_font)))
end end
d_out[:plot_bgcolor] = rgba_string(sp[:background_color_inside]) d_out[:plot_bgcolor] = rgba_string(sp[:background_color_inside])
@ -373,7 +378,7 @@ function plotly_layout(plt::Plot)
d_out[:legend] = KW( d_out[:legend] = KW(
:bgcolor => rgba_string(sp[:background_color_legend]), :bgcolor => rgba_string(sp[:background_color_legend]),
:bordercolor => rgba_string(sp[:foreground_color_legend]), :bordercolor => rgba_string(sp[:foreground_color_legend]),
:font => plotly_font(sp[:legendfont], sp[:foreground_color_legend]), :font => plotly_font(legendfont(sp)),
:x => xpos, :x => xpos,
:y => ypos :y => ypos
) )

View File

@ -19,7 +19,10 @@ const _pyplot_attr = merge_with_base_supported([
:title, :title_location, :titlefont, :title, :title_location, :titlefont,
:window_title, :window_title,
:guide, :lims, :ticks, :scale, :flip, :rotation, :guide, :lims, :ticks, :scale, :flip, :rotation,
:tickfont, :guidefont, :legendfont, :titlefontfamily, :titlefontsize, :titlefontcolor,
:legendfontfamily, :legendfontsize, :legendfontcolor,
:tickfontfamily, :tickfontsize, :tickfontcolor,
:guidefontfamily, :guidefontsize, :guidefontcolor,
:grid, :gridalpha, :gridstyle, :gridlinewidth, :grid, :gridalpha, :gridstyle, :gridlinewidth,
:legend, :legendtitle, :colorbar, :legend, :legendtitle, :colorbar,
:marker_z, :line_z, :fill_z, :marker_z, :line_z, :fill_z,
@ -128,6 +131,7 @@ end
# # anything else just gets a bluesred gradient # # anything else just gets a bluesred gradient
# py_colormap(c, α=nothing) = py_colormap(default_gradient(), α) # py_colormap(c, α=nothing) = py_colormap(default_gradient(), α)
py_color(s) = py_color(parse(Colorant, string(s)))
py_color(c::Colorant) = (red(c), green(c), blue(c), alpha(c)) py_color(c::Colorant) = (red(c), green(c), blue(c), alpha(c))
py_color(cs::AVec) = map(py_color, cs) py_color(cs::AVec) = map(py_color, cs)
py_color(grad::ColorGradient) = py_color(grad.colors) py_color(grad::ColorGradient) = py_color(grad.colors)
@ -923,8 +927,8 @@ function py_set_axis_colors(sp, ax, a::Axis)
tickcolor = sp[:framestyle] == :zerolines ? py_color(plot_color(a[:foreground_color_grid], a[:gridalpha])) : py_color(a[:foreground_color_axis]) tickcolor = sp[:framestyle] == :zerolines ? py_color(plot_color(a[:foreground_color_grid], a[:gridalpha])) : py_color(a[:foreground_color_axis])
ax[:tick_params](axis=string(a[:letter]), which="both", ax[:tick_params](axis=string(a[:letter]), which="both",
colors=tickcolor, colors=tickcolor,
labelcolor=py_color(a[:foreground_color_text])) labelcolor=py_color(a[:tickfontcolor]))
ax[axissym][:label][:set_color](py_color(a[:foreground_color_guide])) ax[axissym][:label][:set_color](py_color(a[:guidefontcolor]))
end end
end end
@ -978,9 +982,9 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
:title :title
end end
ax[func][:set_text](sp[:title]) ax[func][:set_text](sp[:title])
ax[func][:set_fontsize](py_dpi_scale(plt, sp[:titlefont].pointsize)) ax[func][:set_fontsize](py_dpi_scale(plt, sp[:titlefontsize]))
ax[func][:set_family](sp[:titlefont].family) ax[func][:set_family](sp[:titlefontfamily])
ax[func][:set_color](py_color(sp[:foreground_color_title])) ax[func][:set_color](py_color(sp[:titlefontcolor]))
# ax[:set_title](sp[:title], loc = loc) # ax[:set_title](sp[:title], loc = loc)
end end
@ -1005,10 +1009,11 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
fig = plt.o fig = plt.o
cbax = fig[:add_axes]([0.8,0.1,0.03,0.8], label = string(gensym())) cbax = fig[:add_axes]([0.8,0.1,0.03,0.8], label = string(gensym()))
cb = fig[:colorbar](handle; cax = cbax, kw...) cb = fig[:colorbar](handle; cax = cbax, kw...)
cb[:set_label](sp[:colorbar_title],size=py_dpi_scale(plt, sp[:yaxis][:guidefont].pointsize),family=sp[:yaxis][:guidefont].family) cb[:set_label](sp[:colorbar_title],size=py_dpi_scale(plt, sp[:yaxis][:guidefontsize]),family=sp[:yaxis][:guidefontamily], color = py_color(sp[:yaxis][:guidefontcolor]))
for lab in cb[:ax][:yaxis][:get_ticklabels]() for lab in cb[:ax][:yaxis][:get_ticklabels]()
lab[:set_fontsize](py_dpi_scale(plt, sp[:yaxis][:tickfont].pointsize)) lab[:set_fontsize](py_dpi_scale(plt, sp[:yaxis][:tickfontsize]))
lab[:set_family](sp[:yaxis][:tickfont].family) lab[:set_family](sp[:yaxis][:tickfontfamily])
lab[:set_color](py_color(sp[:yaxis][:tickfontcolor]))
end end
sp.attr[:cbar_handle] = cb sp.attr[:cbar_handle] = cb
sp.attr[:cbar_ax] = cbax sp.attr[:cbar_ax] = cbax
@ -1068,11 +1073,11 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
if get(axis.d, :flip, false) if get(axis.d, :flip, false)
ax[Symbol("invert_", letter, "axis")]() ax[Symbol("invert_", letter, "axis")]()
end end
pyaxis[:label][:set_fontsize](py_dpi_scale(plt, axis[:guidefont].pointsize)) pyaxis[:label][:set_fontsize](py_dpi_scale(plt, axis[:guidefontsize]))
pyaxis[:label][:set_family](axis[:guidefont].family) pyaxis[:label][:set_family](axis[:guidefontfamily])
for lab in ax[Symbol("get_", letter, "ticklabels")]() for lab in ax[Symbol("get_", letter, "ticklabels")]()
lab[:set_fontsize](py_dpi_scale(plt, axis[:tickfont].pointsize)) lab[:set_fontsize](py_dpi_scale(plt, axis[:tickfontsize]))
lab[:set_family](axis[:tickfont].family) lab[:set_family](axis[:tickfontfamily])
lab[:set_rotation](axis[:rotation]) lab[:set_rotation](axis[:rotation])
end end
if axis[:grid] && !(ticks in (:none, nothing, false)) if axis[:grid] && !(ticks in (:none, nothing, false))
@ -1248,7 +1253,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
labels, labels,
loc = get(_pyplot_legend_pos, leg, "best"), loc = get(_pyplot_legend_pos, leg, "best"),
scatterpoints = 1, scatterpoints = 1,
fontsize = py_dpi_scale(plt, sp[:legendfont].pointsize) fontsize = py_dpi_scale(plt, sp[:legendfontsize])
# family = sp[:legendfont].family # family = sp[:legendfont].family
# framealpha = 0.6 # framealpha = 0.6
) )
@ -1256,8 +1261,9 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
sp[:legendtitle] != nothing && leg[:set_title](sp[:legendtitle]) sp[:legendtitle] != nothing && leg[:set_title](sp[:legendtitle])
fgcolor = py_color(sp[:foreground_color_legend]) fgcolor = py_color(sp[:foreground_color_legend])
lfcolor = py_color(sp[:legendfontcolor])
for txt in leg[:get_texts]() for txt in leg[:get_texts]()
PyPlot.plt[:setp](txt, color = fgcolor, family = sp[:legendfont].family) PyPlot.plt[:setp](txt, color = lfcolor, family = sp[:legendfontfamily])
end end
# set some legend properties # set some legend properties

View File

@ -1007,3 +1007,43 @@ xmax(plt::Plot) = ignorenan_maximum([ignorenan_maximum(series.d[:x]) for series
"Extrema of x-values in plot" "Extrema of x-values in plot"
ignorenan_extrema(plt::Plot) = (xmin(plt), xmax(plt)) ignorenan_extrema(plt::Plot) = (xmin(plt), xmax(plt))
# ---------------------------------------------------------------
# get fonts from objects:
titlefont(sp::Subplot) = font(
sp[:titlefontfamily],
sp[:titlefontsize],
sp[:titlefontvalign],
sp[:titlefonthalign],
sp[:titlefontrotation],
sp[:titlefontcolor],
)
legendfont(sp::Subplot) = font(
sp[:legendfontfamily],
sp[:legendfontsize],
sp[:legendfontvalign],
sp[:legendfonthalign],
sp[:legendfontrotation],
sp[:legendfontcolor],
)
tickfont(ax::Axis) = font(
ax[:tickfontfamily],
ax[:tickfontsize],
ax[:tickfontvalign],
ax[:tickfonthalign],
ax[:tickfontrotation],
ax[:tickfontcolor],
)
guidefont(ax::Axis) = font(
ax[:guidefontfamily],
ax[:guidefontsize],
ax[:guidefontvalign],
ax[:guidefonthalign],
ax[:guidefontrotation],
ax[:guidefontcolor],
)