format code

This commit is contained in:
Simon Christ 2020-01-14 13:16:45 +01:00
parent 01207b9721
commit 2bb6bf991c

View File

@ -77,7 +77,8 @@ end
function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
if !pgfx_plot.is_created if !pgfx_plot.is_created
the_plot = PGFPlotsX.TikzPicture(PGFPlotsX.Options()) the_plot = PGFPlotsX.TikzPicture(PGFPlotsX.Options())
bgc = plt.attr[:background_color_outside] == :match ? plt.attr[:background_color] : plt.attr[:background_color_outside] bgc = plt.attr[:background_color_outside] == :match ?
plt.attr[:background_color] : plt.attr[:background_color_outside]
if bgc isa Colors.Colorant if bgc isa Colors.Colorant
cstr = plot_color(bgc) cstr = plot_color(bgc)
a = alpha(cstr) a = alpha(cstr)
@ -219,54 +220,36 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
PGFPlotsX.Axis PGFPlotsX.Axis
end end
axis = axisf(axis_opt) axis = axisf(axis_opt)
push!(axis_opt, "colorbar style" => PGFPlotsX.Options(
"title" => sp[:colorbar_title],
"point meta max" => get_clims(sp)[2],
"point meta min" => get_clims(sp)[1]
)
)
if is3d(sp)
azim, elev = sp[:camera]
push!( axis_opt, "view" => (azim, elev) )
end
axisf = if sp[:projection] == :polar
# push!(axis_opt, "xmin" => 90)
# push!(axis_opt, "xmax" => 450)
PGFPlotsX.PolarAxis
else
PGFPlotsX.Axis
end
axis = axisf(
axis_opt
)
for (series_index, series) in enumerate(series_list(sp)) for (series_index, series) in enumerate(series_list(sp))
opt = series.plotattributes opt = series.plotattributes
st = series[:seriestype] st = series[:seriestype]
series_opt = PGFPlotsX.Options( series_opt = PGFPlotsX.Options("color" => single_color(opt[:linecolor]),)
"color" => single_color(opt[:linecolor]),
)
if is3d(series) || st == :heatmap if is3d(series) || st == :heatmap
series_func = PGFPlotsX.Plot3 series_func = PGFPlotsX.Plot3
else else
series_func = PGFPlotsX.Plot series_func = PGFPlotsX.Plot
end end
if series[:fillrange] !== nothing && !isfilledcontour(series) && series[:ribbon] === nothing if series[:fillrange] !== nothing &&
!isfilledcontour(series) && series[:ribbon] === nothing
push!(series_opt, "area legend" => nothing) push!(series_opt, "area legend" => nothing)
end end
if st == :heatmap if st == :heatmap
push!(axis.options, push!(axis.options, "view" => "{0}{90}")
"view" => "{0}{90}",
)
end end
# treat segments # treat segments
segments = if st in (:wireframe, :heatmap, :contour, :surface, :contour3d) segments =
iter_segments(surface_to_vecs(series[:x], series[:y], series[:z])...) if st in (:wireframe, :heatmap, :contour, :surface, :contour3d)
iter_segments(surface_to_vecs(
series[:x],
series[:y],
series[:z],
)...)
else else
iter_segments(series) iter_segments(series)
end end
for (i, rng) in enumerate(segments) for (i, rng) in enumerate(segments)
segment_opt = PGFPlotsX.Options() segment_opt = PGFPlotsX.Options()
segment_opt = merge( segment_opt, pgfx_linestyle(opt, i) ) segment_opt = merge(segment_opt, pgfx_linestyle(opt, i))
if opt[:markershape] != :none if opt[:markershape] != :none
marker = opt[:markershape] marker = opt[:markershape]
if marker isa Shape if marker isa Shape
@ -274,34 +257,53 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
y = marker.y y = marker.y
scale_factor = 0.025 scale_factor = 0.025
mark_size = opt[:markersize] * scale_factor mark_size = opt[:markersize] * scale_factor
path = join(["($(x[i] * mark_size), $(y[i] * mark_size))" for i in eachindex(x)], " -- ") path = join(
["($(x[i] * mark_size), $(y[i] * mark_size))" for i in eachindex(x)],
" -- ",
)
c = get_markercolor(series, i) c = get_markercolor(series, i)
a = get_markeralpha(series, i) a = get_markeralpha(series, i)
PGFPlotsX.push_preamble!(pgfx_plot.the_plot, PGFPlotsX.push_preamble!(
pgfx_plot.the_plot,
""" """
\\pgfdeclareplotmark{PlotsShape$(series_index)}{ \\pgfdeclareplotmark{PlotsShape$(series_index)}{
\\filldraw \\filldraw
$path; $path;
} }
""" """,
) )
end end
segment_opt = merge( segment_opt, pgfx_marker(opt, i) ) segment_opt = merge(segment_opt, pgfx_marker(opt, i))
end end
if st == :shape || if st == :shape || isfilledcontour(series)
isfilledcontour(series) segment_opt = merge(segment_opt, pgfx_fillstyle(opt, i))
segment_opt = merge( segment_opt, pgfx_fillstyle(opt, i) )
end end
# add fillrange # add fillrange
if series[:fillrange] !== nothing && !isfilledcontour(series) && series[:ribbon] === nothing if series[:fillrange] !== nothing &&
pgfx_fillrange_series!( axis, series, series_func, i, _cycle(series[:fillrange], rng), rng) !isfilledcontour(series) && series[:ribbon] === nothing
if i == 1 && opt[:label] != "" && sp[:legend] != :none && should_add_to_legend(series) pgfx_fillrange_series!(
axis,
series,
series_func,
i,
_cycle(series[:fillrange], rng),
rng,
)
if i == 1 &&
opt[:label] != "" &&
sp[:legend] != :none && should_add_to_legend(series)
pgfx_filllegend!(series_opt, opt) pgfx_filllegend!(series_opt, opt)
end end
end end
# series # series
# #
coordinates = pgfx_series_coordinates!( sp, series, segment_opt, opt, rng ) coordinates = pgfx_series_coordinates!(
sp,
series,
segment_opt,
opt,
rng,
)
segment_plot = series_func( segment_plot = series_func(
merge(series_opt, segment_opt), merge(series_opt, segment_opt),
coordinates, coordinates,
@ -310,30 +312,50 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
# add ribbons? # add ribbons?
ribbon = series[:ribbon] ribbon = series[:ribbon]
if ribbon !== nothing if ribbon !== nothing
pgfx_add_ribbons!( axis, series, segment_plot, series_func, series_index ) pgfx_add_ribbons!(
axis,
series,
segment_plot,
series_func,
series_index,
)
end end
# add to legend? # add to legend?
if i == 1 && opt[:label] != "" && sp[:legend] != :none && should_add_to_legend(series) if i == 1 &&
opt[:label] != "" &&
sp[:legend] != :none && should_add_to_legend(series)
leg_opt = PGFPlotsX.Options() leg_opt = PGFPlotsX.Options()
if ribbon !== nothing if ribbon !== nothing
pgfx_filllegend!(axis.contents[end-3].options, opt) pgfx_filllegend!(axis.contents[end-3].options, opt)
end end
legend = PGFPlotsX.LegendEntry(leg_opt, opt[:label], false) legend = PGFPlotsX.LegendEntry(leg_opt, opt[:label], false)
push!( axis, legend ) push!(axis, legend)
end end
# add series annotations # add series annotations
anns = series[:series_annotations] anns = series[:series_annotations]
for (xi,yi,str,fnt) in EachAnn(anns, series[:x], series[:y]) for (xi, yi, str, fnt) in EachAnn(anns, series[:x], series[:y])
pgfx_add_annotation!(axis, xi, yi, PlotText(str, fnt), pgfx_thickness_scaling(series)) pgfx_add_annotation!(
axis,
xi,
yi,
PlotText(str, fnt),
pgfx_thickness_scaling(series),
)
end end
end end
# add subplot annotations # add subplot annotations
anns = sp.attr[:annotations] anns = sp.attr[:annotations]
for (xi,yi,txt) in anns for (xi, yi, txt) in anns
pgfx_add_annotation!(axis, xi, yi, txt, pgfx_thickness_scaling(sp)) pgfx_add_annotation!(
axis,
xi,
yi,
txt,
pgfx_thickness_scaling(sp),
)
end end
end end
push!( the_plot, axis ) push!(the_plot, axis)
if length(plt.o.the_plot.elements) > 0 if length(plt.o.the_plot.elements) > 0
plt.o.the_plot.elements[1] = the_plot plt.o.the_plot.elements[1] = the_plot
else else