custom implementation for pgfplotsx backend
This commit is contained in:
parent
f02b38a02c
commit
65368aac22
@ -331,6 +331,7 @@ const _series_defaults = KW(
|
|||||||
|
|
||||||
const _plot_defaults = KW(
|
const _plot_defaults = KW(
|
||||||
:plot_title => "",
|
:plot_title => "",
|
||||||
|
:plot_titleindex => 0,
|
||||||
:plot_titlefontsize => 16,
|
:plot_titlefontsize => 16,
|
||||||
:plot_titlelocation => :center, # also :left or :right
|
:plot_titlelocation => :center, # also :left or :right
|
||||||
:plot_titlefontfamily => :match,
|
:plot_titlefontfamily => :match,
|
||||||
@ -1365,6 +1366,7 @@ const _match_map = KW(
|
|||||||
:colorbar_tickfontcolor => :foreground_color_subplot,
|
:colorbar_tickfontcolor => :foreground_color_subplot,
|
||||||
:plot_titlefontfamily => :fontfamily,
|
:plot_titlefontfamily => :fontfamily,
|
||||||
:plot_titlefontcolor => :foreground_color,
|
:plot_titlefontcolor => :foreground_color,
|
||||||
|
:plot_titleindex => 0,
|
||||||
:tickfontcolor => :foreground_color_text,
|
:tickfontcolor => :foreground_color_text,
|
||||||
:guidefontcolor => :foreground_color_guide,
|
:guidefontcolor => :foreground_color_guide,
|
||||||
:annotationfontfamily => :fontfamily_subplot,
|
:annotationfontfamily => :fontfamily_subplot,
|
||||||
|
|||||||
@ -118,11 +118,24 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
end
|
end
|
||||||
|
|
||||||
for sp in plt.subplots
|
for sp in plt.subplots
|
||||||
bb1 = sp.plotarea
|
|
||||||
bb2 = bbox(sp)
|
bb2 = bbox(sp)
|
||||||
|
dx, dy = bb2.x0
|
||||||
|
sp_width = width(bb2)
|
||||||
|
sp_height = height(bb2)
|
||||||
|
if sp[:subplot_index] == plt[:plot_titleindex]
|
||||||
|
x = dx + sp_width / 2 - 10mm # FIXME: get rid of magic constant
|
||||||
|
y = dy + sp_height / 2
|
||||||
|
@show width(bbox(plt.layout.grid[2]))
|
||||||
|
@show sp_width
|
||||||
|
pgfx_add_annotation!(the_plot, x, y, PlotText(plt[:plot_title], plottitlefont(plt)), pgfx_thickness_scaling(plt);
|
||||||
|
cs = "",
|
||||||
|
options = PGFPlotsX.Options("anchor" => "center")
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
|
||||||
sp_width = width(bb2)
|
sp_width = width(bb2)
|
||||||
sp_height = height(bb2)
|
sp_height = height(bb2)
|
||||||
dx, dy = bb2.x0
|
|
||||||
lpad = leftpad(sp) + sp[:left_margin]
|
lpad = leftpad(sp) + sp[:left_margin]
|
||||||
rpad = rightpad(sp) + sp[:right_margin]
|
rpad = rightpad(sp) + sp[:right_margin]
|
||||||
tpad = toppad(sp) + sp[:top_margin]
|
tpad = toppad(sp) + sp[:top_margin]
|
||||||
@ -131,7 +144,6 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
dy += tpad
|
dy += tpad
|
||||||
axis_height = sp_height - (tpad + bpad)
|
axis_height = sp_height - (tpad + bpad)
|
||||||
axis_width = sp_width - (rpad + lpad)
|
axis_width = sp_width - (rpad + lpad)
|
||||||
|
|
||||||
title_cstr = plot_color(sp[:titlefontcolor])
|
title_cstr = plot_color(sp[:titlefontcolor])
|
||||||
title_a = alpha(title_cstr)
|
title_a = alpha(title_cstr)
|
||||||
title_loc = sp[:titlelocation]
|
title_loc = sp[:titlelocation]
|
||||||
@ -999,24 +1011,27 @@ function pgfx_marker(plotattributes, i = 1)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pgfx_add_annotation!(o, x, y, val, thickness_scaling = 1)
|
function pgfx_add_annotation!(o, x, y, val, thickness_scaling = 1; cs = "axis cs:", options = PGFPlotsX.Options())
|
||||||
# Construct the style string.
|
# Construct the style string.
|
||||||
cstr = val.font.color
|
cstr = val.font.color
|
||||||
a = alpha(cstr)
|
a = alpha(cstr)
|
||||||
push!(
|
push!(
|
||||||
o,
|
o,
|
||||||
[
|
join([
|
||||||
"\\node",
|
"\\node",
|
||||||
|
sprint(PGFPlotsX.print_tex, merge(
|
||||||
PGFPlotsX.Options(
|
PGFPlotsX.Options(
|
||||||
get((center = "", left = "right", right = "left"), val.font.halign, "") =>
|
get((hcenter = "", left = "right", right = "left"), val.font.halign, "") =>
|
||||||
nothing,
|
nothing,
|
||||||
"color" => cstr,
|
"color" => cstr,
|
||||||
"draw opacity" => convert(Float16, a),
|
"draw opacity" => convert(Float16, a),
|
||||||
"rotate" => val.font.rotation,
|
"rotate" => val.font.rotation,
|
||||||
"font" => pgfx_font(val.font.pointsize, thickness_scaling),
|
"font" => pgfx_font(val.font.pointsize, thickness_scaling),
|
||||||
),
|
),
|
||||||
" at (axis cs:$x, $y) {$(val.str)};",
|
options
|
||||||
],
|
)),
|
||||||
|
string(" at (", cs, x, ",", y, ") {", val.str, "};"),
|
||||||
|
]),
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -287,11 +287,6 @@ function _add_plot_title!(plt)
|
|||||||
if plot_title != ""
|
if plot_title != ""
|
||||||
the_layout = plt.layout
|
the_layout = plt.layout
|
||||||
vspan = plt[:plot_titlevspan]
|
vspan = plt[:plot_titlevspan]
|
||||||
if plt.backend isa PGFPlotsXBackend
|
|
||||||
# FIXME: we hit a 45pt height limit:
|
|
||||||
# https://github.com/pgf-tikz/pgfplots/blob/3bc2f42258fbfac9fe50b2978459da7e76fc046c/tex/generic/pgfplots/pgfplots.scaling.code.tex#L153
|
|
||||||
vspan = max(vspan, .16)
|
|
||||||
end
|
|
||||||
plt.layout = grid(2, 1, heights=(vspan, 1 - vspan))
|
plt.layout = grid(2, 1, heights=(vspan, 1 - vspan))
|
||||||
plt.layout.grid[1, 1] = subplot = Subplot(plt.backend, parent=plt.layout[1, 1])
|
plt.layout.grid[1, 1] = subplot = Subplot(plt.backend, parent=plt.layout[1, 1])
|
||||||
plt.layout.grid[2, 1] = the_layout
|
plt.layout.grid[2, 1] = the_layout
|
||||||
@ -302,6 +297,7 @@ function _add_plot_title!(plt)
|
|||||||
end
|
end
|
||||||
plt[:force_minpad] = nothing, 0px, nothing, 0px
|
plt[:force_minpad] = nothing, 0px, nothing, 0px
|
||||||
subplot[:subplot_index] = last(plt.subplots)[:subplot_index] + 1
|
subplot[:subplot_index] = last(plt.subplots)[:subplot_index] + 1
|
||||||
|
plt[:plot_titleindex] = subplot[:subplot_index]
|
||||||
subplot[:framestyle] = :none
|
subplot[:framestyle] = :none
|
||||||
subplot[:margin] = 0px
|
subplot[:margin] = 0px
|
||||||
push!(plt.subplots, subplot)
|
push!(plt.subplots, subplot)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user