Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework adding legends #3732

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/args.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1656,12 +1656,13 @@ function _slice_series_args!(plotattributes::AKW, plt::Plot, sp::Subplot, comman
return plotattributes
end

label_auto(series_plotindex) = string("y", series_plotindex)
label_to_string(label::Bool, series_plotindex) = label ? label_to_string(:auto, series_plotindex) : ""
label_to_string(label::Nothing, series_plotindex) = ""
label_to_string(label::Missing, series_plotindex) = ""
function label_to_string(label::Symbol, series_plotindex)
if label==:auto
return string("y", series_plotindex)
return label_auto(series_plotindex)
elseif label==:none
return ""
else
Expand Down
10 changes: 7 additions & 3 deletions src/backends/pgfplotsx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ function pgfx_add_series!(::Val{:path}, axis, series_opt, series, series_func, o
end
end
if k == 1 &&
series[:subplot][:legend] != :none && pgfx_should_add_to_legend(series)
series[:subplot][:legend] != :none && pgfx_should_add_to_legend(series)
pgfx_filllegend!(series_opt, opt)
end
end
Expand Down Expand Up @@ -948,8 +948,12 @@ function pgfx_font(fontsize::Nothing, thickness_scaling = 1, font = "\\selectfon
return string("{", font, "}")
end

function pgfx_should_add_to_legend(series::Series)
pgfx_should_add_to_legend(series::Series) = (
series.plotattributes[:primary] &&
!(
length(series_list(series[:subplot])) == 1 &&
series.plotattributes[:label] == label_auto(series.plotattributes[:series_plotindex])
) &&
!(
series.plotattributes[:seriestype] in (
:hexbin,
Expand All @@ -964,7 +968,7 @@ function pgfx_should_add_to_legend(series::Series)
:image,
)
)
end
)

function pgfx_marker(plotattributes, i = 1)
shape = _cycle(plotattributes[:markershape], i)
Expand Down
8 changes: 6 additions & 2 deletions src/subplots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ get_subplot_index(plt::Plot, sp::Subplot) = findfirst(x -> x === sp, plt.subplot

series_list(sp::Subplot) = sp.series_list # filter(series -> series.plotattributes[:subplot] === sp, sp.plt.series_list)

function should_add_to_legend(series::Series)
should_add_to_legend(series::Series) = (
series.plotattributes[:primary] &&
series.plotattributes[:label] != "" &&
!(
length(series_list(series[:subplot])) == 1 &&
series.plotattributes[:label] == label_auto(series.plotattributes[:series_plotindex])
) &&
!(
series.plotattributes[:seriestype] in (
:hexbin,
Expand All @@ -60,6 +64,6 @@ function should_add_to_legend(series::Series)
:image,
)
)
end
)

# ----------------------------------------------------------------------