free shapes

This commit is contained in:
Simon Christ 2019-11-23 20:10:08 +01:00
parent 607640ce73
commit 2bbaf9d504

View File

@ -89,31 +89,31 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
end end
end end
# Search series for any gradient. In case one series uses a gradient set # Search series for any gradient. In case one series uses a gradient set
# the colorbar and colomap. # the colorbar and colomap.
# The reasoning behind doing this on the axis level is that pgfplots # The reasoning behind doing this on the axis level is that pgfplots
# colorbar seems to only works on axis level and needs the proper colormap for # colorbar seems to only works on axis level and needs the proper colormap for
# correctly displaying it. # correctly displaying it.
# It's also possible to assign the colormap to the series itself but # It's also possible to assign the colormap to the series itself but
# then the colormap needs to be added twice, once for the axis and once for the # then the colormap needs to be added twice, once for the axis and once for the
# series. # series.
# As it is likely that all series within the same axis use the same # As it is likely that all series within the same axis use the same
# colormap this should not cause any problem. # colormap this should not cause any problem.
for series in series_list(sp) for series in series_list(sp)
for col in (:markercolor, :fillcolor, :linecolor) for col in (:markercolor, :fillcolor, :linecolor)
if typeof(series.plotattributes[col]) == ColorGradient if typeof(series.plotattributes[col]) == ColorGradient
PGFPlotsX.push_preamble!(pgfx_plot.the_plot, """\\pgfplotsset{ PGFPlotsX.push_preamble!(pgfx_plot.the_plot, """\\pgfplotsset{
colormap={plots$(sp.attr[:subplot_index])}{$(pgfx_colormap(series.plotattributes[col]))}, colormap={plots$(sp.attr[:subplot_index])}{$(pgfx_colormap(series.plotattributes[col]))},
}""") }""")
push!(axis_opt, push!(axis_opt,
"colorbar" => nothing, "colorbar" => nothing,
"colormap name" => "plots$(sp.attr[:subplot_index])", "colormap name" => "plots$(sp.attr[:subplot_index])",
) )
# goto is needed to break out of col and series for # goto is needed to break out of col and series for
@goto colorbar_end @goto colorbar_end
end
end end
end end
@label colorbar_end 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],
@ -158,8 +158,8 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
) )
end end
# treat segments # treat segments
segments = if iscontour(series) || st == :heatmap segments = if st in (:wireframe, :heatmap, :contour, :surface)
iter_segments(series[:x], series[:y]) iter_segments(surface_to_vecs(series[:x], series[:y], series[:z])...)
else else
iter_segments(series) iter_segments(series)
end end
@ -167,6 +167,21 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
for (i, rng) in enumerate(segments) for (i, rng) in enumerate(segments)
segment_opt = merge( segment_opt, pgfx_linestyle(opt, i) ) segment_opt = merge( segment_opt, pgfx_linestyle(opt, i) )
if opt[:markershape] != :none #|| !iscontour(series) && !(st == :heatmap) if opt[:markershape] != :none #|| !iscontour(series) && !(st == :heatmap)
marker = opt[:markershape]
if marker isa Shape
x = marker.x
y = marker.y
scale_factor = 0.025
mark_size = opt[:markersize] * scale_factor
path = join(["($(x[i] * mark_size), $(y[i] * mark_size))" for i in eachindex(x)], " -- ")
PGFPlotsX.push_preamble!(pgfx_plot.the_plot,
"""
\\pgfdeclareplotmark{PlotsShape}{
\\draw $path;
}
"""
)
end
segment_opt = merge( segment_opt, pgfx_marker(opt, i) ) segment_opt = merge( segment_opt, pgfx_marker(opt, i) )
end end
if st == :shape || series[:fillrange] !== nothing if st == :shape || series[:fillrange] !== nothing
@ -300,8 +315,11 @@ function pgfx_series_coordinates!(st_val::Val{:xsticks}, segment_opt, opt, args)
return PGFPlotsX.Coordinates(args...) return PGFPlotsX.Coordinates(args...)
end end
function pgfx_series_coordinates!(st_val::Val{:surface}, segment_opt, opt, args) function pgfx_series_coordinates!(st_val::Val{:surface}, segment_opt, opt, args)
@show collect(args)[3] |> length
@show args
push!( segment_opt, "surf" => nothing, push!( segment_opt, "surf" => nothing,
"mesh/rows" => length(opt[:x]) "mesh/rows" => length(opt[:x]),
"mesh/cols" => length(opt[:y]),
) )
return PGFPlotsX.Coordinates(args...) return PGFPlotsX.Coordinates(args...)
end end
@ -316,7 +334,7 @@ function pgfx_series_coordinates!(st_val::Val{:wireframe}, segment_opt, opt, arg
return PGFPlotsX.Coordinates(args...) return PGFPlotsX.Coordinates(args...)
end end
function pgfx_series_coordinates!(st_val::Val{:shape}, segment_opt, opt, args) function pgfx_series_coordinates!(st_val::Val{:shape}, segment_opt, opt, args)
push!( segment_opt, "area legends" => nothing, "patch" => nothing ) push!( segment_opt, "area legends" => nothing )
return PGFPlotsX.Coordinates(args...) return PGFPlotsX.Coordinates(args...)
end end
function pgfx_series_coordinates!(st_val::Val{:contour}, segment_opt, opt, args) function pgfx_series_coordinates!(st_val::Val{:contour}, segment_opt, opt, args)
@ -459,9 +477,10 @@ function pgfx_marker(plotattributes, i = 1)
a = alpha(cstr) a = alpha(cstr)
cstr_stroke = plot_color(get_markerstrokecolor(plotattributes, i), get_markerstrokealpha(plotattributes, i)) cstr_stroke = plot_color(get_markerstrokecolor(plotattributes, i), get_markerstrokealpha(plotattributes, i))
a_stroke = alpha(cstr_stroke) a_stroke = alpha(cstr_stroke)
mark_size = pgfx_thickness_scaling(plotattributes) * 0.5 * _cycle(plotattributes[:markersize], i)
return PGFPlotsX.Options( return PGFPlotsX.Options(
"mark" => get(_pgfplotsx_markers, shape, "*"), "mark" => shape isa Shape ? "PlotsShape" : get(_pgfplotsx_markers, shape, "*"),
"mark size" => pgfx_thickness_scaling(plotattributes) * 0.5 * _cycle(plotattributes[:markersize], i), "mark size" => "$mark_size pt",
"mark options" => PGFPlotsX.Options( "mark options" => PGFPlotsX.Options(
"color" => cstr_stroke, "color" => cstr_stroke,
"draw opacity" => a_stroke, "draw opacity" => a_stroke,