This commit is contained in:
Simon Christ 2020-01-09 22:14:49 +01:00
parent 84a8039022
commit 68c1eb2e3c

View File

@ -93,6 +93,23 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
) )
end end
# the combination of groupplot and polaraxis is broken in pgfplots
if !any( sp -> ispolar(sp), plt.subplots )
pl_height, pl_width = plt.attr[:size]
push!( the_plot, PGFPlotsX.GroupPlot(
PGFPlotsX.Options(
"group style" => PGFPlotsX.Options(
"group size" => string(cols)*" by "*string(rows),
"horizontal sep" => string(maximum(sp -> sp.minpad[1], plt.subplots)),
"vertical sep" => string(maximum(sp -> sp.minpad[2], plt.subplots)),
),
"height" => pl_height > 0 ? string(pl_height * px) : "{}",
"width" => pl_width > 0 ? string(pl_width * px) : "{}",
)
))
end
inset_subplots = plt.inset_subplots
parents = getproperty.(inset_subplots, :parent)
for sp in plt.subplots for sp in plt.subplots
bb = bbox(sp) bb = bbox(sp)
sp_width = width(bb) sp_width = width(bb)
@ -220,148 +237,145 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
PGFPlotsX.Axis PGFPlotsX.Axis
end end
axis = axisf(axis_opt) axis = axisf(axis_opt)
for (series_index, series) in enumerate(series_list(sp)) push!(axis_opt, "colorbar style" => PGFPlotsX.Options(
opt = series.plotattributes "title" => sp[:colorbar_title],
st = series[:seriestype] "point meta max" => get_clims(sp)[2],
series_opt = PGFPlotsX.Options("color" => single_color(opt[:linecolor]),) "point meta min" => get_clims(sp)[1]
if is3d(series) || st == :heatmap )
series_func = PGFPlotsX.Plot3 )
else if is3d(sp)
series_func = PGFPlotsX.Plot azim, elev = sp[:camera]
end push!( axis_opt, "view" => (azim, elev) )
if series[:fillrange] !== nothing && end
!isfilledcontour(series) && series[:ribbon] === nothing axisf = if sp[:projection] == :polar
push!(series_opt, "area legend" => nothing) # push!(axis_opt, "xmin" => 90)
end # push!(axis_opt, "xmax" => 450)
if st == :heatmap PGFPlotsX.PolarAxis
push!(axis.options, "view" => "{0}{90}") else
end PGFPlotsX.Axis
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 = segments = if st in (:wireframe, :heatmap, :contour, :surface, :contour3d)
if st in (:wireframe, :heatmap, :contour, :surface, :contour3d) iter_segments(surface_to_vecs(series[:x], series[:y], series[:z])...)
iter_segments(surface_to_vecs( else
series[:x], iter_segments(series)
series[:y], end
series[:z], for (i, rng) in enumerate(segments)
)...) segment_opt = PGFPlotsX.Options()
else segment_opt = merge( segment_opt, pgfx_linestyle(opt, i) )
iter_segments(series) if opt[:markershape] != :none
end marker = opt[:markershape]
for (i, rng) in enumerate(segments) if marker isa Shape
segment_opt = PGFPlotsX.Options() x = marker.x
segment_opt = merge(segment_opt, pgfx_linestyle(opt, i)) y = marker.y
if opt[:markershape] != :none scale_factor = 0.025
marker = opt[:markershape] mark_size = opt[:markersize] * scale_factor
if marker isa Shape path = join(["($(x[i] * mark_size), $(y[i] * mark_size))" for i in eachindex(x)], " -- ")
x = marker.x c = get_markercolor(series, i)
y = marker.y a = get_markeralpha(series, i)
scale_factor = 0.025 PGFPlotsX.push_preamble!(pgfx_plot.the_plot,
mark_size = opt[:markersize] * scale_factor """
path = join( \\pgfdeclareplotmark{PlotsShape$(series_index)}{
["($(x[i] * mark_size), $(y[i] * mark_size))" for i in eachindex(x)], \\filldraw
" -- ", $path;
) }
c = get_markercolor(series, i) """
a = get_markeralpha(series, i) )
PGFPlotsX.push_preamble!( end
pgfx_plot.the_plot, segment_opt = merge( segment_opt, pgfx_marker(opt, i) )
""" end
\\pgfdeclareplotmark{PlotsShape$(series_index)}{ if st == :shape ||
\\filldraw isfilledcontour(series)
$path; segment_opt = merge( segment_opt, pgfx_fillstyle(opt, i) )
} 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 && if series[:fillrange] !== nothing && !isfilledcontour(series) && series[:ribbon] === nothing
!isfilledcontour(series) && series[:ribbon] === nothing pgfx_fillrange_series!( axis, series, series_func, i, _cycle(series[:fillrange], rng), rng)
pgfx_fillrange_series!( if i == 1 && opt[:label] != "" && sp[:legend] != :none && should_add_to_legend(series)
axis, pgfx_filllegend!(series_opt, opt)
series, end
series_func, end
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!( coordinates = pgfx_series_coordinates!( sp, series, segment_opt, opt, rng )
sp, segment_plot = series_func(
series, merge(series_opt, segment_opt),
segment_opt, coordinates,
opt, )
rng, push!(axis, segment_plot)
)
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!( pgfx_add_ribbons!( axis, series, segment_plot, series_func, series_index )
axis, end
series,
segment_plot,
series_func,
series_index,
)
end
# add to legend? # add to legend?
if i == 1 && if i == 1 && opt[:label] != "" && sp[:legend] != :none && should_add_to_legend(series)
opt[:label] != "" && leg_opt = PGFPlotsX.Options()
sp[:legend] != :none && should_add_to_legend(series) if ribbon !== nothing
leg_opt = PGFPlotsX.Options() pgfx_filllegend!(axis.contents[end-3].options, opt)
if ribbon !== nothing end
pgfx_filllegend!(axis.contents[end-3].options, opt) legend = PGFPlotsX.LegendEntry(leg_opt, opt[:label], false)
end push!( axis, legend )
legend = PGFPlotsX.LegendEntry(leg_opt, opt[:label], false) end
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!( pgfx_add_annotation!(axis, xi, yi, PlotText(str, fnt), pgfx_thickness_scaling(series))
axis, end
xi, end
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!( pgfx_add_annotation!(axis, xi, yi, txt, pgfx_thickness_scaling(sp))
axis, end
xi, end
yi, if ispolar(sp)
txt, axes = the_plot
pgfx_thickness_scaling(sp), else
) axes = the_plot.elements[1]
end end
end ##< handle insets
push!(the_plot, axis) # TODO: build id map for subplots like for series
if length(plt.o.the_plot.elements) > 0 if sp in parents
plt.o.the_plot.elements[1] = the_plot sp_id = uuid4()
else push!(axis, "\\coordinate ($sp_id) at (rel axis cs:$())") # TODO: compute rel coordinates from bboxes
push!(plt.o, the_plot) end
end if sp in inset_subplots
end push!(axis.options, PGFPlotsX.Options(
"at" => "($())", # TODO: insert correct ID here
"anchor" => "outer south west", # TODO: check this
))
end
##>
push!( axes, 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