Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fa720d6ad4 | |||
| 1ab681f509 | |||
| 0d776fd09d | |||
| 45e33f5b6f | |||
| 1c4910f90e | |||
| 2f4eb7b558 | |||
| 07ed5e7162 | |||
| 03716289c3 | |||
| 0d38f34e54 | |||
| 2544808000 | |||
| 02ca049bc6 | |||
| cd20518323 | |||
| ff7235e9b8 | |||
| 376fae0d79 | |||
| d036794576 |
+1
-1
@@ -1,7 +1,7 @@
|
||||
name = "Plots"
|
||||
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
|
||||
author = ["Tom Breloff (@tbreloff)"]
|
||||
version = "1.5.2"
|
||||
version = "1.5.4"
|
||||
|
||||
[deps]
|
||||
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
|
||||
|
||||
+32
-21
@@ -349,11 +349,13 @@ function gr_draw_markers(
|
||||
|
||||
shapes = series[:markershape]
|
||||
if shapes != :none
|
||||
for i in eachindex(x)
|
||||
for (i, rng) in enumerate(iter_segments(series))
|
||||
ms = get_thickness_scaling(series) * _cycle(msize, i)
|
||||
msw = get_thickness_scaling(series) * _cycle(strokewidth, i)
|
||||
shape = _cycle(shapes, i)
|
||||
gr_draw_marker(series, x[i], y[i], clims, i, ms, msw, shape)
|
||||
for j in rng
|
||||
gr_draw_marker(series, _cycle(x, j), _cycle(y, j), clims, i, ms, msw, shape)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -565,6 +567,8 @@ gr_view_xcenter(viewport_plotarea) = 0.5 * (viewport_plotarea[1] + viewport_plot
|
||||
gr_view_ycenter(viewport_plotarea) = 0.5 * (viewport_plotarea[3] + viewport_plotarea[4])
|
||||
|
||||
function gr_legend_pos(sp::Subplot, w, h, viewport_plotarea)
|
||||
legend_leftw, legend_rightw, legend_textw, x_legend_offset = w
|
||||
legend_dy, legendh, y_legend_offset = h
|
||||
s = sp[:legend]
|
||||
typeof(s) <: Symbol || return gr_legend_pos(s, w, h, viewport_plotarea)
|
||||
str = string(s)
|
||||
@@ -579,34 +583,34 @@ function gr_legend_pos(sp::Subplot, w, h, viewport_plotarea)
|
||||
if occursin("right", str)
|
||||
if occursin("outer", str)
|
||||
# As per https://github.com/jheinen/GR.jl/blob/master/src/jlgr.jl#L525
|
||||
xpos = viewport_plotarea[2] + 0.11 + ymirror * gr_axis_width(sp, sp[:yaxis])
|
||||
xpos = viewport_plotarea[2] + x_legend_offset + legend_leftw + ymirror * gr_axis_width(sp, sp[:yaxis])
|
||||
else
|
||||
xpos = viewport_plotarea[2] - 0.05 - w
|
||||
xpos = viewport_plotarea[2] - legend_rightw - legend_textw
|
||||
end
|
||||
elseif occursin("left", str)
|
||||
if occursin("outer", str)
|
||||
xpos = viewport_plotarea[1] - 0.05 - w - !ymirror * gr_axis_width(sp, sp[:yaxis])
|
||||
xpos = viewport_plotarea[1] - !ymirror * gr_axis_width(sp, sp[:yaxis]) - x_legend_offset * 2 - legend_rightw - legend_textw
|
||||
else
|
||||
xpos = viewport_plotarea[1] + 0.11
|
||||
xpos = viewport_plotarea[1] + legend_leftw + x_legend_offset
|
||||
end
|
||||
else
|
||||
xpos = (viewport_plotarea[2]-viewport_plotarea[1])/2 - w/2 +.04 + viewport_plotarea[1]
|
||||
xpos = (viewport_plotarea[2]-viewport_plotarea[1])/2 + viewport_plotarea[1] + legend_leftw - legend_rightw - legend_textw - x_legend_offset * 2
|
||||
end
|
||||
if occursin("top", str)
|
||||
if s == :outertop
|
||||
ypos = viewport_plotarea[4] + 0.02 + h + xmirror * gr_axis_height(sp, sp[:xaxis])
|
||||
ypos = viewport_plotarea[4] + y_legend_offset + legendh + xmirror * gr_axis_height(sp, sp[:xaxis])
|
||||
else
|
||||
ypos = viewport_plotarea[4] - 0.06
|
||||
ypos = viewport_plotarea[4] - y_legend_offset
|
||||
end
|
||||
elseif occursin("bottom", str)
|
||||
if s == :outerbottom
|
||||
ypos = viewport_plotarea[3] - 0.05 - !xmirror * gr_axis_height(sp, sp[:xaxis])
|
||||
ypos = viewport_plotarea[3] - y_legend_offset - legendh - !xmirror * gr_axis_height(sp, sp[:xaxis])
|
||||
else
|
||||
ypos = viewport_plotarea[3] + h + 0.06
|
||||
ypos = viewport_plotarea[3] + legendh + y_legend_offset
|
||||
end
|
||||
else
|
||||
# Adding min y to shift legend pos to correct graph (#2377)
|
||||
ypos = (viewport_plotarea[4]-viewport_plotarea[3])/2 + h/2 + viewport_plotarea[3]
|
||||
ypos = (viewport_plotarea[4]-viewport_plotarea[3])/2 + legendh/2 + viewport_plotarea[3]
|
||||
end
|
||||
(xpos,ypos)
|
||||
end
|
||||
@@ -1003,26 +1007,33 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
legendn += 1
|
||||
lab = series[:label]
|
||||
tbx, tby = gr_inqtext(0, 0, string(lab))
|
||||
legendw = max(legendw, tbx[3] - tbx[1])
|
||||
legendw = max(legendw, tbx[3] - tbx[1]) # Holds text width right now
|
||||
end
|
||||
|
||||
GR.setscale(1)
|
||||
GR.selntran(1)
|
||||
GR.restorestate()
|
||||
end
|
||||
legend_textw = legendw
|
||||
legend_rightw = 0.02 # To be made dynamic in a follow up PR
|
||||
legend_leftw = 0.08 # To be made dynamic in a follow up PR
|
||||
total_legendw = legend_textw + legend_leftw + legend_rightw
|
||||
|
||||
x_legend_offset = (viewport_plotarea[2] - viewport_plotarea[1]) / 30
|
||||
y_legend_offset = (viewport_plotarea[4] - viewport_plotarea[3]) / 30
|
||||
|
||||
dy = gr_point_mult(sp) * sp[:legendfontsize] * 1.75
|
||||
legendh = dy * legendn
|
||||
leg_str = string(sp[:legend])
|
||||
if occursin("outer", leg_str)
|
||||
if occursin("right", leg_str)
|
||||
viewport_plotarea[2] -= legendw + 0.12
|
||||
viewport_plotarea[2] -= total_legendw + x_legend_offset # Lessen plot max width to make space for outer legend
|
||||
elseif occursin("left", leg_str)
|
||||
viewport_plotarea[1] += legendw + 0.11
|
||||
viewport_plotarea[1] += total_legendw + x_legend_offset # Increase plot min width to make space for outer legend
|
||||
elseif occursin("top", leg_str)
|
||||
viewport_plotarea[4] -= legendh + 0.03
|
||||
viewport_plotarea[4] -= legendh + dy + y_legend_offset
|
||||
elseif occursin("bottom", leg_str)
|
||||
viewport_plotarea[3] += legendh + 0.04
|
||||
viewport_plotarea[3] += legendh + dy + y_legend_offset
|
||||
end
|
||||
end
|
||||
if sp[:legend] == :inline
|
||||
@@ -1840,17 +1851,17 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
||||
GR.selntran(0)
|
||||
GR.setscale(0)
|
||||
gr_set_font(legendfont(sp), sp)
|
||||
w = legendw
|
||||
w = legendw # This is the legend text width
|
||||
n = legendn
|
||||
if w > 0
|
||||
dy = gr_point_mult(sp) * sp[:legendfontsize] * 1.75
|
||||
h = dy*n
|
||||
xpos, ypos = gr_legend_pos(sp, w, h, viewport_plotarea)
|
||||
xpos, ypos = gr_legend_pos(sp, [legend_leftw, legend_rightw, legend_textw, x_legend_offset, y_legend_offset], [dy, h, y_legend_offset], viewport_plotarea) # Passing legend width components instead of legend text width
|
||||
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
||||
gr_set_fillcolor(sp[:background_color_legend])
|
||||
GR.fillrect(xpos - 0.08, xpos + w + 0.02, ypos + dy, ypos - dy * n)
|
||||
GR.fillrect(xpos - legend_leftw, xpos + legend_textw + legend_rightw, ypos + dy, ypos - dy * n) # Allocating white space for actual legend width here
|
||||
gr_set_line(1, :solid, sp[:foreground_color_legend], sp)
|
||||
GR.drawrect(xpos - 0.08, xpos + w + 0.02, ypos + dy, ypos - dy * n)
|
||||
GR.drawrect(xpos - legend_leftw, xpos + legend_textw + legend_rightw, ypos + dy, ypos - dy * n) # Drawing actual legend width here
|
||||
i = 0
|
||||
if sp[:legendtitle] !== nothing
|
||||
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF)
|
||||
|
||||
+14
-17
@@ -344,9 +344,8 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
end
|
||||
# add fillrange
|
||||
if sf !== nothing &&
|
||||
!isfilledcontour(series) &&
|
||||
series[:ribbon] === nothing
|
||||
if sf isa Number || sf isa AVec
|
||||
!isfilledcontour(series)
|
||||
if sf isa Number || sf isa AVec
|
||||
pgfx_fillrange_series!(
|
||||
axis,
|
||||
series,
|
||||
@@ -355,6 +354,17 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
_cycle(sf, rng),
|
||||
rng,
|
||||
)
|
||||
elseif sf isa Tuple
|
||||
for sfi in sf
|
||||
pgfx_fillrange_series!(
|
||||
axis,
|
||||
series,
|
||||
series_func,
|
||||
i,
|
||||
_cycle(sfi, rng),
|
||||
rng,
|
||||
)
|
||||
end
|
||||
end
|
||||
if i == 1 &&
|
||||
sp[:legend] != :none && pgfx_should_add_to_legend(series)
|
||||
@@ -384,17 +394,6 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
),
|
||||
)
|
||||
end
|
||||
# add ribbons?
|
||||
ribbon = series[:ribbon]
|
||||
if ribbon !== nothing
|
||||
pgfx_add_ribbons!(
|
||||
axis,
|
||||
series,
|
||||
segment_plot,
|
||||
series_func,
|
||||
series_index,
|
||||
)
|
||||
end
|
||||
# add to legend?
|
||||
if sp[:legend] != :none
|
||||
leg_entry = if opt[:label] isa AVec
|
||||
@@ -412,9 +411,6 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
push!(axis.contents[end].options, "forget plot" => nothing)
|
||||
else
|
||||
leg_opt = PGFPlotsX.Options()
|
||||
if ribbon !== nothing
|
||||
pgfx_filllegend!(axis.contents[end - 3].options, opt)
|
||||
end
|
||||
legend = PGFPlotsX.LegendEntry(leg_opt, leg_entry, false)
|
||||
push!(axis, legend)
|
||||
end
|
||||
@@ -558,6 +554,7 @@ function pgfx_series_coordinates!(st_val::Val{:surface}, segment_opt, opt, args)
|
||||
"surf" => nothing,
|
||||
"mesh/rows" => length(opt[:x]),
|
||||
"mesh/cols" => length(opt[:y]),
|
||||
"z buffer" => "sort",
|
||||
)
|
||||
return PGFPlotsX.Coordinates(args...)
|
||||
end
|
||||
|
||||
+2
-2
@@ -973,8 +973,8 @@ const _examples = PlotExample[
|
||||
surf = Measurement.((1:10) .* (1:10)', rand(10,10))
|
||||
|
||||
plot(
|
||||
scatter(x, [x y], msw = 0),
|
||||
scatter(x, y, z, msw = 0),
|
||||
scatter(x, [x y]),
|
||||
scatter(x, y, z),
|
||||
heatmap(x, y, surf),
|
||||
wireframe(x, y, surf),
|
||||
legend = :topleft
|
||||
|
||||
+17
-1
@@ -1027,8 +1027,24 @@ end
|
||||
# Error Bars
|
||||
|
||||
function error_style!(plotattributes::AKW)
|
||||
msc = plotattributes[:markerstrokecolor]
|
||||
msc = if msc === :match
|
||||
plotattributes[:subplot][:foreground_color_subplot]
|
||||
elseif msc === :auto
|
||||
get_series_color(
|
||||
plotattributes[:linecolor],
|
||||
plotattributes[:subplot],
|
||||
plotattributes[:series_plotindex],
|
||||
plotattributes[:seriestype],
|
||||
)
|
||||
else
|
||||
msc
|
||||
end
|
||||
|
||||
plotattributes[:seriestype] = :path
|
||||
plotattributes[:markercolor] = plotattributes[:markerstrokecolor]
|
||||
plotattributes[:markerstrokecolor] = msc
|
||||
plotattributes[:markercolor] = msc
|
||||
plotattributes[:linecolor] = msc
|
||||
plotattributes[:linewidth] = plotattributes[:markerstrokewidth]
|
||||
plotattributes[:label] = ""
|
||||
end
|
||||
|
||||
@@ -314,16 +314,12 @@ end
|
||||
Plots._update_plot_object(ribbon_plot)
|
||||
axis = Plots.pgfx_axes(ribbon_plot.o)[1]
|
||||
plots = filter(x -> x isa PGFPlotsX.Plot, axis.contents)
|
||||
@test length(plots) == 4
|
||||
@test !haskey(plots[1].options.dict, "fill")
|
||||
@test !haskey(plots[2].options.dict, "fill")
|
||||
@test length(plots) == 3
|
||||
@test haskey(plots[1].options.dict, "fill")
|
||||
@test haskey(plots[2].options.dict, "fill")
|
||||
@test !haskey(plots[3].options.dict, "fill")
|
||||
@test haskey(plots[4].options.dict, "fill")
|
||||
@test ribbon_plot.o !== nothing
|
||||
@test ribbon_plot.o.the_plot !== nothing
|
||||
# mktempdir() do path
|
||||
# @test_nowarn savefig(ribbon_plot, path*"ribbon.svg")
|
||||
# end
|
||||
end # testset
|
||||
end # testset
|
||||
|
||||
|
||||
Reference in New Issue
Block a user