This commit is contained in:
Simon Christ 2020-01-09 22:14:49 +01:00
parent dd70192de4
commit 80903a2789

View File

@ -94,6 +94,8 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
) )
)) ))
end 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)
@ -165,151 +167,145 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
end end
@label colorbar_end @label colorbar_end
push!(axis_opt, "colorbar style" => PGFPlotsX.Options( push!(axis_opt, "colorbar style" => PGFPlotsX.Options(
"title" => sp[:colorbar_title], "title" => sp[:colorbar_title],
"point meta max" => get_clims(sp)[2], "point meta max" => get_clims(sp)[2],
"point meta min" => get_clims(sp)[1] "point meta min" => get_clims(sp)[1]
) )
) )
if is3d(sp) if is3d(sp)
azim, elev = sp[:camera] azim, elev = sp[:camera]
push!( axis_opt, "view" => (azim, elev) ) push!( axis_opt, "view" => (azim, elev) )
end end
axisf = if sp[:projection] == :polar axisf = if sp[:projection] == :polar
# push!(axis_opt, "xmin" => 90) # push!(axis_opt, "xmin" => 90)
# push!(axis_opt, "xmax" => 450) # push!(axis_opt, "xmax" => 450)
PGFPlotsX.PolarAxis PGFPlotsX.PolarAxis
else else
PGFPlotsX.Axis PGFPlotsX.Axis
end end
axis = axisf( axis = axisf(
axis_opt axis_opt
) )
for (series_index, series) in enumerate(series_list(sp)) for (series_index, series) in enumerate(series_list(sp))
# give each series a uuid for fillbetween opt = series.plotattributes
series_id = uuid4() st = series[:seriestype]
_pgfplotsx_series_ids[Symbol("$series_index")] = series_id series_opt = PGFPlotsX.Options(
opt = series.plotattributes "color" => single_color(opt[:linecolor]),
st = series[:seriestype] )
sf = series[:fillrange] if is3d(series) || st == :heatmap
series_opt = PGFPlotsX.Options( series_func = PGFPlotsX.Plot3
"color" => single_color(opt[:linecolor]), else
"name path" => string(series_id) series_func = PGFPlotsX.Plot
) end
if is3d(series) || st == :heatmap if series[:fillrange] !== nothing && !isfilledcontour(series) && series[:ribbon] === nothing
series_func = PGFPlotsX.Plot3 push!(series_opt, "area legend" => nothing)
else end
series_func = PGFPlotsX.Plot if st == :heatmap
end push!(axis.options,
if sf !== nothing && !isfilledcontour(series) && series[:ribbon] === nothing "view" => "{0}{90}",
push!(series_opt, "area legend" => nothing) )
end end
if st == :heatmap # treat segments
push!(axis.options, segments = if st in (:wireframe, :heatmap, :contour, :surface, :contour3d)
"view" => "{0}{90}", iter_segments(surface_to_vecs(series[:x], series[:y], series[:z])...)
) else
end iter_segments(series)
# treat segments end
segments = if st in (:wireframe, :heatmap, :contour, :surface, :contour3d) for (i, rng) in enumerate(segments)
iter_segments(surface_to_vecs(series[:x], series[:y], series[:z])...) 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(["($(x[i] * mark_size), $(y[i] * mark_size))" for i in eachindex(x)], " -- ") \\pgfdeclareplotmark{PlotsShape$(series_index)}{
c = get_markercolor(series, i) \\filldraw
a = get_markeralpha(series, i) $path;
PGFPlotsX.push_preamble!(pgfx_plot.the_plot, }
""" """
\\pgfdeclareplotmark{PlotsShape$(series_index)}{ )
\\filldraw end
$path; segment_opt = merge( segment_opt, pgfx_marker(opt, i) )
} end
""" if st == :shape ||
) isfilledcontour(series)
end segment_opt = merge( segment_opt, pgfx_fillstyle(opt, i) )
segment_opt = merge( segment_opt, pgfx_marker(opt, i) ) end
end # add fillrange
if st == :shape || if series[:fillrange] !== nothing && !isfilledcontour(series) && series[:ribbon] === nothing
isfilledcontour(series) pgfx_fillrange_series!( axis, series, series_func, i, _cycle(series[:fillrange], rng), rng)
segment_opt = merge( segment_opt, pgfx_fillstyle(opt, i) ) if i == 1 && opt[:label] != "" && sp[:legend] != :none && should_add_to_legend(series)
end pgfx_filllegend!(series_opt, opt)
# add fillrange end
if sf !== nothing && !isfilledcontour(series) && series[:ribbon] === nothing end
if sf isa Number || sf isa AVec # series
pgfx_fillrange_series!( axis, series, series_func, i, _cycle(sf, rng), rng) #
end coordinates = pgfx_series_coordinates!( sp, series, segment_opt, opt, rng )
if i == 1 && opt[:label] != "" && sp[:legend] != :none && should_add_to_legend(series) segment_plot = series_func(
pgfx_filllegend!(series_opt, opt) merge(series_opt, segment_opt),
end coordinates,
end )
# series push!(axis, segment_plot)
# # add ribbons?
coordinates = pgfx_series_coordinates!( sp, series, segment_opt, opt, rng ) ribbon = series[:ribbon]
segment_plot = series_func( if ribbon !== nothing
merge(series_opt, segment_opt), pgfx_add_ribbons!( axis, series, segment_plot, series_func, series_index )
coordinates, end
) # add to legend?
push!(axis, segment_plot) if i == 1 && opt[:label] != "" && sp[:legend] != :none && should_add_to_legend(series)
# fill between functions leg_opt = PGFPlotsX.Options()
if sf isa Tuple && series[:ribbon] === nothing if ribbon !== nothing
sf1, sf2 = sf pgfx_filllegend!(axis.contents[end-3].options, opt)
@assert sf1 == series_index "First index of the tuple has to match the current series index." end
push!(axis, series_func( legend = PGFPlotsX.LegendEntry(leg_opt, opt[:label], false)
merge(pgfx_fillstyle(opt, series_index), PGFPlotsX.Options("forget plot" => nothing)), push!( axis, legend )
"fill between [of=$series_id and $(_pgfplotsx_series_ids[Symbol(string(sf2))])]" end
)) # add series annotations
end anns = series[:series_annotations]
# add ribbons? for (xi,yi,str,fnt) in EachAnn(anns, series[:x], series[:y])
ribbon = series[:ribbon] pgfx_add_annotation!(axis, xi, yi, PlotText(str, fnt), pgfx_thickness_scaling(series))
if ribbon !== nothing end
pgfx_add_ribbons!( axis, series, segment_plot, series_func, series_index ) end
end # add subplot annotations
# add to legend? anns = sp.attr[:annotations]
if i == 1 && opt[:label] != "" && sp[:legend] != :none && should_add_to_legend(series) for (xi,yi,txt) in anns
leg_opt = PGFPlotsX.Options() pgfx_add_annotation!(axis, xi, yi, txt, pgfx_thickness_scaling(sp))
if ribbon !== nothing end
pgfx_filllegend!(axis.contents[end-3].options, opt) end
end if ispolar(sp)
legend = PGFPlotsX.LegendEntry(leg_opt, opt[:label], false) axes = the_plot
push!( axis, legend ) else
end axes = the_plot.elements[1]
# add series annotations end
anns = series[:series_annotations] ##< handle insets
for (xi,yi,str,fnt) in EachAnn(anns, series[:x], series[:y]) # TODO: build id map for subplots like for series
pgfx_add_annotation!(axis, xi, yi, PlotText(str, fnt), pgfx_thickness_scaling(series)) if sp in parents
end sp_id = uuid4()
end push!(axis, "\\coordinate ($sp_id) at (rel axis cs:$())") # TODO: compute rel coordinates from bboxes
# add subplot annotations end
for ann in sp[:annotations] if sp in inset_subplots
pgfx_add_annotation!(axis, locate_annotation(sp, ann...)..., pgfx_thickness_scaling(sp)) push!(axis.options, PGFPlotsX.Options(
end "at" => "($())", # TODO: insert correct ID here
# anns = sp.attr[:annotations] "anchor" => "outer south west", # TODO: check this
# for (xi,yi,txt) in anns ))
# pgfx_add_annotation!(axis, xi, yi, txt, pgfx_thickness_scaling(sp)) end
# end ##>
end # for series push!( axes, axis )
if ispolar(sp) if length(plt.o.the_plot.elements) > 0
axes = the_plot plt.o.the_plot.elements[1] = the_plot
else else
axes = the_plot.elements[1] push!(plt.o, the_plot)
end end
push!( axes, axis ) end
if length(plt.o.the_plot.elements) > 0
plt.o.the_plot.elements[1] = the_plot
else
push!(plt.o, the_plot)
end
end # for subplots
pgfx_plot.is_created = true pgfx_plot.is_created = true
end # if end # if
return pgfx_plot return pgfx_plot