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)
@ -93,14 +94,14 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
end end
for sp in plt.subplots for sp in plt.subplots
bb = bbox(sp) bb = bbox(sp)
sp_width = width(bb) sp_width = width(bb)
sp_height = height(bb) sp_height = height(bb)
dx, dy = bb.x0 dx, dy = bb.x0
# TODO: does this hold at every scale? # TODO: does this hold at every scale?
if sp[:legend] in (:outertopright, nothing) if sp[:legend] in (:outertopright, nothing)
dx *= 1.2 dx *= 1.2
end end
cstr = plot_color(sp[:background_color_legend]) cstr = plot_color(sp[:background_color_legend])
a = alpha(cstr) a = alpha(cstr)
fg_alpha = alpha(plot_color(sp[:foreground_color_legend])) fg_alpha = alpha(plot_color(sp[:foreground_color_legend]))
@ -219,127 +220,148 @@ 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( for (series_index, series) in enumerate(series_list(sp))
"title" => sp[:colorbar_title], opt = series.plotattributes
"point meta max" => get_clims(sp)[2], st = series[:seriestype]
"point meta min" => get_clims(sp)[1] series_opt = PGFPlotsX.Options("color" => single_color(opt[:linecolor]),)
) if is3d(series) || st == :heatmap
) series_func = PGFPlotsX.Plot3
if is3d(sp) else
azim, elev = sp[:camera] series_func = PGFPlotsX.Plot
push!( axis_opt, "view" => (azim, elev) ) end
end if series[:fillrange] !== nothing &&
axisf = if sp[:projection] == :polar !isfilledcontour(series) && series[:ribbon] === nothing
# push!(axis_opt, "xmin" => 90) push!(series_opt, "area legend" => nothing)
# push!(axis_opt, "xmax" => 450) end
PGFPlotsX.PolarAxis if st == :heatmap
else push!(axis.options, "view" => "{0}{90}")
PGFPlotsX.Axis end
end
axis = axisf(
axis_opt
)
for (series_index, series) in enumerate(series_list(sp))
opt = series.plotattributes
st = series[:seriestype]
series_opt = PGFPlotsX.Options(
"color" => single_color(opt[:linecolor]),
)
if is3d(series) || st == :heatmap
series_func = PGFPlotsX.Plot3
else
series_func = PGFPlotsX.Plot
end
if series[:fillrange] !== nothing && !isfilledcontour(series) && series[:ribbon] === nothing
push!(series_opt, "area legend" => nothing)
end
if st == :heatmap
push!(axis.options,
"view" => "{0}{90}",
)
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)
else iter_segments(surface_to_vecs(
iter_segments(series) series[:x],
end series[:y],
for (i, rng) in enumerate(segments) series[:z],
segment_opt = PGFPlotsX.Options() )...)
segment_opt = merge( segment_opt, pgfx_linestyle(opt, i) ) else
if opt[:markershape] != :none iter_segments(series)
marker = opt[:markershape] end
if marker isa Shape for (i, rng) in enumerate(segments)
x = marker.x segment_opt = PGFPlotsX.Options()
y = marker.y segment_opt = merge(segment_opt, pgfx_linestyle(opt, i))
scale_factor = 0.025 if opt[:markershape] != :none
mark_size = opt[:markersize] * scale_factor marker = opt[:markershape]
path = join(["($(x[i] * mark_size), $(y[i] * mark_size))" for i in eachindex(x)], " -- ") if marker isa Shape
c = get_markercolor(series, i) x = marker.x
a = get_markeralpha(series, i) y = marker.y
PGFPlotsX.push_preamble!(pgfx_plot.the_plot, scale_factor = 0.025
""" mark_size = opt[:markersize] * scale_factor
\\pgfdeclareplotmark{PlotsShape$(series_index)}{ path = join(
\\filldraw ["($(x[i] * mark_size), $(y[i] * mark_size))" for i in eachindex(x)],
$path; " -- ",
} )
""" c = get_markercolor(series, i)
) a = get_markeralpha(series, i)
end PGFPlotsX.push_preamble!(
segment_opt = merge( segment_opt, pgfx_marker(opt, i) ) pgfx_plot.the_plot,
end """
if st == :shape || \\pgfdeclareplotmark{PlotsShape$(series_index)}{
isfilledcontour(series) \\filldraw
segment_opt = merge( segment_opt, pgfx_fillstyle(opt, i) ) $path;
end }
""",
)
end
segment_opt = merge(segment_opt, pgfx_marker(opt, i))
end
if st == :shape || isfilledcontour(series)
segment_opt = merge(segment_opt, pgfx_fillstyle(opt, i))
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!(
pgfx_filllegend!(series_opt, opt) axis,
end series,
end 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)
end
end
# series # series
# #
coordinates = pgfx_series_coordinates!( sp, series, segment_opt, opt, rng ) coordinates = pgfx_series_coordinates!(
segment_plot = series_func( sp,
merge(series_opt, segment_opt), series,
coordinates, segment_opt,
) opt,
push!(axis, segment_plot) rng,
)
segment_plot = series_func(
merge(series_opt, segment_opt),
coordinates,
)
push!(axis, segment_plot)
# 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!(
end axis,
series,
segment_plot,
series_func,
series_index,
)
end
# add to legend? # add to legend?
if i == 1 && opt[:label] != "" && sp[:legend] != :none && should_add_to_legend(series) if i == 1 &&
leg_opt = PGFPlotsX.Options() opt[:label] != "" &&
if ribbon !== nothing sp[:legend] != :none && should_add_to_legend(series)
pgfx_filllegend!(axis.contents[end-3].options, opt) leg_opt = PGFPlotsX.Options()
end if ribbon !== nothing
legend = PGFPlotsX.LegendEntry(leg_opt, opt[:label], false) pgfx_filllegend!(axis.contents[end-3].options, opt)
push!( axis, legend ) end
end legend = PGFPlotsX.LegendEntry(leg_opt, opt[:label], false)
push!(axis, legend)
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!(
end axis,
end xi,
yi,
PlotText(str, fnt),
pgfx_thickness_scaling(series),
)
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!(
end axis,
end xi,
push!( the_plot, axis ) yi,
if length(plt.o.the_plot.elements) > 0 txt,
plt.o.the_plot.elements[1] = the_plot pgfx_thickness_scaling(sp),
else )
push!(plt.o, the_plot) end
end end
end push!(the_plot, axis)
if length(plt.o.the_plot.elements) > 0
plt.o.the_plot.elements[1] = the_plot
else
push!(plt.o, the_plot)
end
end
pgfx_plot.is_created = true pgfx_plot.is_created = true
end # if end # if
return pgfx_plot return pgfx_plot