explicit function return, decl - add comments - cleanup
This commit is contained in:
parent
c0e35f2358
commit
b801b2b272
@ -4,11 +4,11 @@ const GastonSubplot = G.Plot
|
|||||||
const GASTON_MARKER_SCALING = 1.3 / 5.0
|
const GASTON_MARKER_SCALING = 1.3 / 5.0
|
||||||
const GNUPLOT_DPI = 72 # Compensate for DPI with increased resolution
|
const GNUPLOT_DPI = 72 # Compensate for DPI with increased resolution
|
||||||
|
|
||||||
#
|
|
||||||
# --------------------------------------------
|
# --------------------------------------------
|
||||||
# These functions are called by Plots
|
# These functions are called by Plots
|
||||||
# --------------------------------------------
|
# --------------------------------------------
|
||||||
#
|
|
||||||
# Create the window/figure for this backend.
|
# Create the window/figure for this backend.
|
||||||
function _create_backend_figure(plt::Plot{GastonBackend})
|
function _create_backend_figure(plt::Plot{GastonBackend})
|
||||||
xsize, ysize = plt.attr[:size]
|
xsize, ysize = plt.attr[:size]
|
||||||
@ -26,20 +26,23 @@ function _before_layout_calcs(plt::Plot{GastonBackend})
|
|||||||
n, sps = gaston_get_subplots(plt, 0, plt.layout)
|
n, sps = gaston_get_subplots(plt, 0, plt.layout)
|
||||||
@assert n == length(plt.subplots)
|
@assert n == length(plt.subplots)
|
||||||
|
|
||||||
|
# FIXME: find a way to support nested layouts
|
||||||
|
# e.g. figures spanning multiple rows/cols
|
||||||
plt.o.layout = gaston_init_subplots(plt, sps)
|
plt.o.layout = gaston_init_subplots(plt, sps)
|
||||||
|
|
||||||
# Then add the series (curves in gaston)
|
# Then add the series (curves in gaston)
|
||||||
for series in plt.series_list
|
for series in plt.series_list
|
||||||
gaston_add_series(plt, series)
|
gaston_add_series(plt, series)
|
||||||
end
|
end
|
||||||
|
nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
function _update_min_padding!(sp::Subplot{GastonBackend})
|
function _update_min_padding!(sp::Subplot{GastonBackend})
|
||||||
|
# FIXME: make this more flexible
|
||||||
sp.minpad = (20mm, 5mm, 2mm, 10mm)
|
sp.minpad = (20mm, 5mm, 2mm, 10mm)
|
||||||
end
|
end
|
||||||
|
|
||||||
function _update_plot_object(plt::Plot{GastonBackend})
|
_update_plot_object(plt::Plot{GastonBackend}) = nothing
|
||||||
end
|
|
||||||
|
|
||||||
for (mime, term) in (
|
for (mime, term) in (
|
||||||
"application/eps" => "epscairo", # NEED fixing TODO
|
"application/eps" => "epscairo", # NEED fixing TODO
|
||||||
@ -56,7 +59,6 @@ for (mime, term) in (
|
|||||||
termopts = """size $xsize,$ysize"""
|
termopts = """size $xsize,$ysize"""
|
||||||
|
|
||||||
tmpfile = G.tempname() * "." * $term
|
tmpfile = G.tempname() * "." * $term
|
||||||
|
|
||||||
G.save(
|
G.save(
|
||||||
term=$term,
|
term=$term,
|
||||||
output=tmpfile,
|
output=tmpfile,
|
||||||
@ -67,7 +69,6 @@ for (mime, term) in (
|
|||||||
write(io, read(tmpfile))
|
write(io, read(tmpfile))
|
||||||
rm(tmpfile, force=true)
|
rm(tmpfile, force=true)
|
||||||
nothing
|
nothing
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -79,7 +80,6 @@ function _show(io::IO, mime::MIME{Symbol("image/png")}, plt::Plot{GastonBackend}
|
|||||||
termopts = """size $xsize,$ysize fontscale $scaling lw $scaling dl $scaling ps $scaling"""
|
termopts = """size $xsize,$ysize fontscale $scaling lw $scaling dl $scaling ps $scaling"""
|
||||||
|
|
||||||
tmpfile = G.tempname()
|
tmpfile = G.tempname()
|
||||||
|
|
||||||
G.save(
|
G.save(
|
||||||
term="pngcairo",
|
term="pngcairo",
|
||||||
output=tmpfile,
|
output=tmpfile,
|
||||||
@ -92,16 +92,13 @@ function _show(io::IO, mime::MIME{Symbol("image/png")}, plt::Plot{GastonBackend}
|
|||||||
nothing
|
nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
|
_display(plt::Plot{GastonBackend}) = display(plt.o)
|
||||||
function _display(plt::Plot{GastonBackend})
|
|
||||||
display(plt.o)
|
|
||||||
end
|
|
||||||
|
|
||||||
# --------------------------------------------
|
# --------------------------------------------
|
||||||
# These functions are gaston specific
|
# These functions are gaston specific
|
||||||
# --------------------------------------------
|
# --------------------------------------------
|
||||||
|
|
||||||
gaston_get_subplots(plt, n, layout, level) = begin
|
function gaston_get_subplots(plt, n, layout, level)
|
||||||
nr, nc = size(layout)
|
nr, nc = size(layout)
|
||||||
sps = Array{Any}(undef, nr, nc)
|
sps = Array{Any}(undef, nr, nc)
|
||||||
for r ∈ 1:nr, c ∈ 1:nc # NOTE: col major
|
for r ∈ 1:nr, c ∈ 1:nc # NOTE: col major
|
||||||
@ -113,10 +110,10 @@ gaston_get_subplots(plt, n, layout, level) = begin
|
|||||||
sps[r, c] = get(l.attr, :blank, false) ? nothing : plt.subplots[n += 1]
|
sps[r, c] = get(l.attr, :blank, false) ? nothing : plt.subplots[n += 1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
n, sps
|
return n, sps
|
||||||
end
|
end
|
||||||
|
|
||||||
gaston_init_subplots(plt, sps, level) = begin
|
function gaston_init_subplots(plt, sps, level)
|
||||||
sz = nr, nc = size(sps)
|
sz = nr, nc = size(sps)
|
||||||
for c ∈ 1:nc, r ∈ 1:nr # NOTE: row major
|
for c ∈ 1:nc, r ∈ 1:nr # NOTE: row major
|
||||||
sp = sps[r, c]
|
sp = sps[r, c]
|
||||||
@ -127,7 +124,7 @@ gaston_init_subplots(plt, sps, level) = begin
|
|||||||
sz = max.(sz, size(sp))
|
sz = max.(sz, size(sp))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sz
|
return sz
|
||||||
end
|
end
|
||||||
|
|
||||||
function gaston_init_subplot(plt::Plot{GastonBackend}, sp::Subplot{GastonBackend})
|
function gaston_init_subplot(plt::Plot{GastonBackend}, sp::Subplot{GastonBackend})
|
||||||
@ -139,9 +136,9 @@ function gaston_init_subplot(plt::Plot{GastonBackend}, sp::Subplot{GastonBackend
|
|||||||
axesconf=gaston_parse_axes_args(plt, sp), # Gnuplot string
|
axesconf=gaston_parse_axes_args(plt, sp), # Gnuplot string
|
||||||
curves=[]
|
curves=[]
|
||||||
)
|
)
|
||||||
|
|
||||||
push!(plt.o.subplots, sp.o)
|
push!(plt.o.subplots, sp.o)
|
||||||
end
|
end
|
||||||
|
nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
function gaston_add_series(plt::Plot{GastonBackend}, series::Series)
|
function gaston_add_series(plt::Plot{GastonBackend}, series::Series)
|
||||||
@ -150,7 +147,7 @@ function gaston_add_series(plt::Plot{GastonBackend}, series::Series)
|
|||||||
g_sp = sp.o # Gaston subplot object
|
g_sp = sp.o # Gaston subplot object
|
||||||
|
|
||||||
if series[:seriestype] ∈ (:heatmap, :contour) && g_sp.dims == 2
|
if series[:seriestype] ∈ (:heatmap, :contour) && g_sp.dims == 2
|
||||||
g_sp.dims = 3 # FIXME: this is ugly, we need heatmap to use splot, not plot
|
g_sp.dims = 3 # FIXME: this is ugly, we need heatmap/contour to use splot, not plot
|
||||||
end
|
end
|
||||||
|
|
||||||
x = series[:x]
|
x = series[:x]
|
||||||
@ -166,27 +163,7 @@ function gaston_add_series(plt::Plot{GastonBackend}, series::Series)
|
|||||||
isfirst = length(g_sp.curves) == 0 ? true : false
|
isfirst = length(g_sp.curves) == 0 ? true : false
|
||||||
push!(g_sp.curves, c)
|
push!(g_sp.curves, c)
|
||||||
G.write_data(c, g_sp.dims, g_sp.datafile, append = isfirst ? false : true)
|
G.write_data(c, g_sp.dims, g_sp.datafile, append = isfirst ? false : true)
|
||||||
end
|
nothing
|
||||||
|
|
||||||
gaston_lc_ls_lw(series::Series) = (
|
|
||||||
gaston_color(series[:linecolor], series[:linealpha]),
|
|
||||||
gaston_linestyle(series[:linestyle]),
|
|
||||||
series[:linewidth],
|
|
||||||
)
|
|
||||||
|
|
||||||
gaston_mk_ms_mc(series::Series) = (
|
|
||||||
gaston_marker(series[:markershape]),
|
|
||||||
series[:markersize] * GASTON_MARKER_SCALING,
|
|
||||||
gaston_color(series[:markercolor], series[:markeralpha]),
|
|
||||||
)
|
|
||||||
|
|
||||||
gaston_palette(gradient) = begin
|
|
||||||
palette = String[]
|
|
||||||
n = -1
|
|
||||||
for rgba ∈ gradient # FIXME: naive conversion, inefficient ?
|
|
||||||
push!(palette, "$(n += 1) $(rgba.r) $(rgba.g) $(rgba.b)")
|
|
||||||
end
|
|
||||||
'(' * join(palette, ", ") * ')'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function gaston_seriesconf!(sp, series::Series)
|
function gaston_seriesconf!(sp, series::Series)
|
||||||
@ -238,7 +215,6 @@ function gaston_seriesconf!(sp, series::Series)
|
|||||||
|
|
||||||
# label
|
# label
|
||||||
push!(curveconf, """title "$(series[:label])" """)
|
push!(curveconf, """title "$(series[:label])" """)
|
||||||
|
|
||||||
return join(curveconf, " ")
|
return join(curveconf, " ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -246,8 +222,7 @@ function gaston_parse_axes_args(plt::Plot{GastonBackend}, sp::Subplot{GastonBack
|
|||||||
axesconf = String[]
|
axesconf = String[]
|
||||||
# Standard 2d axis
|
# Standard 2d axis
|
||||||
if !ispolar(sp) && !RecipesPipeline.is3d(sp)
|
if !ispolar(sp) && !RecipesPipeline.is3d(sp)
|
||||||
# TODO
|
# TODO: configure grid, axis spines, thickness
|
||||||
# configure grid, axis spines, thickness
|
|
||||||
end
|
end
|
||||||
|
|
||||||
for letter in (:x, :y, :z)
|
for letter in (:x, :y, :z)
|
||||||
@ -301,9 +276,8 @@ function gaston_parse_axes_args(plt::Plot{GastonBackend}, sp::Subplot{GastonBack
|
|||||||
end
|
end
|
||||||
|
|
||||||
function gaston_set_ticks!(axesconf, ticks, letter)
|
function gaston_set_ticks!(axesconf, ticks, letter)
|
||||||
|
|
||||||
ticks == :auto && return
|
ticks == :auto && return
|
||||||
if ticks == :none || ticks === nothing || ticks == false
|
if ticks ∈ (:none, nothing, false)
|
||||||
push!(axesconf, """unset $(letter)tics """)
|
push!(axesconf, """unset $(letter)tics """)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -320,7 +294,6 @@ function gaston_set_ticks!(axesconf, ticks, letter)
|
|||||||
axesconf,
|
axesconf,
|
||||||
"set $(letter)tics (" * join(gaston_tick_string, ", ") * ")"
|
"set $(letter)tics (" * join(gaston_tick_string, ", ") * ")"
|
||||||
)
|
)
|
||||||
|
|
||||||
elseif ttype == :ticks_and_labels
|
elseif ttype == :ticks_and_labels
|
||||||
tick_locations = @view ticks[1][:]
|
tick_locations = @view ticks[1][:]
|
||||||
tick_labels = @view ticks[2][:]
|
tick_labels = @view ticks[2][:]
|
||||||
@ -334,10 +307,10 @@ function gaston_set_ticks!(axesconf, ticks, letter)
|
|||||||
axesconf,
|
axesconf,
|
||||||
"set $(letter)tics (" * join(gaston_tick_string, ", ") * ")"
|
"set $(letter)tics (" * join(gaston_tick_string, ", ") * ")"
|
||||||
)
|
)
|
||||||
|
|
||||||
else
|
else
|
||||||
error("Invalid input for $(letter)ticks: $ticks")
|
error("Invalid input for $(letter)ticks: $ticks")
|
||||||
end
|
end
|
||||||
|
nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
function gaston_set_legend!(axesconf, sp)
|
function gaston_set_legend!(axesconf, sp)
|
||||||
@ -370,7 +343,32 @@ function gaston_set_legend!(axesconf, sp)
|
|||||||
push!(axesconf, "set key off")
|
push!(axesconf, "set key off")
|
||||||
|
|
||||||
end
|
end
|
||||||
|
nothing
|
||||||
|
end
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Helpers
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
|
gaston_lc_ls_lw(series::Series) = (
|
||||||
|
gaston_color(series[:linecolor], series[:linealpha]),
|
||||||
|
gaston_linestyle(series[:linestyle]),
|
||||||
|
series[:linewidth],
|
||||||
|
)
|
||||||
|
|
||||||
|
gaston_mk_ms_mc(series::Series) = (
|
||||||
|
gaston_marker(series[:markershape]),
|
||||||
|
series[:markersize] * GASTON_MARKER_SCALING,
|
||||||
|
gaston_color(series[:markercolor], series[:markeralpha]),
|
||||||
|
)
|
||||||
|
|
||||||
|
function gaston_palette(gradient)
|
||||||
|
palette = String[]
|
||||||
|
n = -1
|
||||||
|
for rgba ∈ gradient # FIXME: naive conversion, inefficient ?
|
||||||
|
push!(palette, "$(n += 1) $(rgba.r) $(rgba.g) $(rgba.b)")
|
||||||
|
end
|
||||||
|
return '(' * join(palette, ", ") * ')'
|
||||||
end
|
end
|
||||||
|
|
||||||
function gaston_marker(marker)
|
function gaston_marker(marker)
|
||||||
@ -390,10 +388,10 @@ function gaston_marker(marker)
|
|||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
gaston_color(color, alpha=0.) = begin
|
function gaston_color(color, alpha=0.)
|
||||||
col = single_color(color) # in case of gradients
|
col = single_color(color) # in case of gradients
|
||||||
col = alphacolor(col, alpha == nothing ? 0. : alpha) # add a default alpha if non existent
|
col = alphacolor(col, alpha == nothing ? 0. : alpha) # add a default alpha if non existent
|
||||||
"""rgb "#$(hex(col, :aarrggbb))" """
|
return """rgb "#$(hex(col, :aarrggbb))" """
|
||||||
end
|
end
|
||||||
|
|
||||||
function gaston_linestyle(style)
|
function gaston_linestyle(style)
|
||||||
|
|||||||
@ -1243,12 +1243,19 @@ _backend_skips = Dict(
|
|||||||
:inspectdr => [4, 6, 10, 22, 24, 28, 30, 38, 43, 45, 47, 48, 49, 50, 51, 55],
|
:inspectdr => [4, 6, 10, 22, 24, 28, 30, 38, 43, 45, 47, 48, 49, 50, 51, 55],
|
||||||
:unicodeplots => [6, 10, 22, 24, 28, 38, 43, 45, 47, 49, 50, 51, 55],
|
:unicodeplots => [6, 10, 22, 24, 28, 38, 43, 45, 47, 49, 50, 51, 55],
|
||||||
:gaston => [
|
:gaston => [
|
||||||
2, 4, 6,
|
2, # animations
|
||||||
|
4, # colors/palette issues
|
||||||
|
6, # TODO: support embedded images
|
||||||
16, # TODO: support nested layouts
|
16, # TODO: support nested layouts
|
||||||
27, # TODO: support polar
|
27, # TODO: support polar
|
||||||
30, 31, 47, 48,
|
30, # uses StatsPlots, deprecated ?
|
||||||
|
31, # animations
|
||||||
|
47, # TODO: support mesh3d
|
||||||
|
48, # TODO: vector of shapes, ...
|
||||||
49, # TODO: support polar
|
49, # TODO: support polar
|
||||||
50, 51, 55
|
50, # TODO: 1D data not supported for pm3d
|
||||||
|
51, # TODO: support embedded images
|
||||||
|
55, # TODO: scaling is ugly
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user