minimal working gnuplot

This commit is contained in:
zhanibek 2020-12-03 14:55:32 +09:00
parent edb86ff238
commit fba9791769

View File

@ -1,40 +1,67 @@
# https://github.com/mbaz/Gaston. # https://github.com/mbaz/Gaston.
const G = Gaston const G = Gaston
const GastonSubplot = G.Plot
# --------------------------------------------
# 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})
plt.o = G.newfigure(G.gnuplot_state.current) state_handle = G.nexthandle() # for now all the figures will be kept
plt.o = G.newfigure(state_handle)
end end
# # this is called early in the pipeline, use it to make the plot current or something
# function _prepare_plot_object(plt::Plot{GastonBackend})
# end
# Set up the subplot within the backend object.
function gaston_init_subplot(plt::Plot{GastonBackend}, sp::Subplot{GastonBackend})
sp.o = plt.o.subplots[1]
empty!(sp.o.curves)
end
function _before_layout_calcs(plt::Plot{GastonBackend}) function _before_layout_calcs(plt::Plot{GastonBackend})
# Initialize all the subplots first
plt.o.subplots = G.SubPlot[]
grid = size(plt.layout)
plt.o.layout = grid
for sp in plt.subplots for sp in plt.subplots
gaston_init_subplot(plt, sp) gaston_init_subplot(plt, sp)
end end
# add the series # 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
end end
function gaston_add_series(plt::Plot{GastonBackend}, series::Series) function _update_min_padding!(sp::Subplot{GastonBackend})
st = series[:seriestype] sp.minpad = (20mm, 5mm, 2mm, 10mm)
sp = series[:subplot] end
g_sp = sp.o
gnuplot_args = gaston_parse_series_args(series) function _update_plot_object(plt::Plot{GastonBackend})
c = G.Curve(series[:x], series[:y], nothing, nothing, gnuplot_args) end
function _show(io::IO, ::MIME"image/png", plt::Plot{GastonBackend})
end
function _display(plt::Plot{GastonBackend})
display(plt.o)
end
# --------------------------------------------
# These functions are called gaston specific
# --------------------------------------------
function gaston_init_subplot(plt::Plot{GastonBackend}, sp::Subplot{GastonBackend})
dims = RecipesPipeline.is3d(sp) ? 3 : 2
axesconf = gaston_parse_axes_args(plt, sp) # Gnuplot string
sp.o = GastonSubplot(dims=dims, axesconf = axesconf, curves = [])
push!(plt.o.subplots, sp.o)
end
function gaston_add_series(plt::Plot{GastonBackend}, series::Series)
# Gaston.Curve = Plots.Series
sp = series[:subplot]
g_sp = sp.o # Gaston subplot object
seriesconf = gaston_parse_series_args(series) # Gnuplot string
c = G.Curve(series[:x], series[:y], nothing, nothing, seriesconf )
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)
@ -50,7 +77,7 @@ function gaston_parse_series_args(series::Series)
elseif st == :steppre elseif st == :steppre
push!(curveconf, """with steps""") push!(curveconf, """with steps""")
elseif st == :steppost elseif st == :steppost
push!(curveconf, """with fsteps""") # Not sure if not 'steps' push!(curveconf, """with fsteps""") # Not sure if not the other way
end end
# line color # line color
@ -62,18 +89,32 @@ function gaston_parse_series_args(series::Series)
return join(curveconf, " ") return join(curveconf, " ")
end end
# Set the (left, top, right, bottom) minimum padding around the plot area function gaston_parse_axes_args(plt::Plot{GastonBackend}, sp::Subplot{GastonBackend})
# to fit ticks, tick labels, guides, colorbars, etc. axesconf = String[]
function _update_min_padding!(sp::Subplot{GastonBackend}) # Standard 2d axis
sp.minpad = (20mm, 5mm, 2mm, 10mm) if !ispolar(sp) && !RecipesPipeline.is3d(sp)
end # TODO
# configure grid, axis spines, thickness
end
function _update_plot_object(plt::Plot{GastonBackend}) for letter in (:x, :y, :z)
end axis_attr = sp.attr[Symbol(letter, :axis)]
# label names
push!(axesconf, """set $(letter)label "$(axis_attr[:guide])" """)
push!(axesconf, """set $(letter)label font "$(axis_attr[:guidefontfamily]), $(axis_attr[:guidefontsize])" """)
function _show(io::IO, ::MIME"image/png", plt::Plot{GastonBackend}) # tick font
end push!(axesconf, """set $(letter)tics font "$(axis_attr[:tickfontfamily]), $(axis_attr[:tickfontsize])" """)
function _display(plt::Plot{GastonBackend}) push!(axesconf, """set $(letter)tics textcolor rgb "#$(hex(axis_attr[:tickfontcolor], :rrggbb))" """)
display(plt.o)
push!(axesconf, """set $(letter)tics $(axis_attr[:tick_direction])""")
mirror = axis_attr[:mirror] ? "nomirror" : "mirror"
push!(axesconf, """set $(letter)tics $(mirror) """)
# set xtics (1,2,5,10,20,50)
# TODO logscale, explicit tick location, range,
end
return join(axesconf, "\n")
end end