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

color legend entry #228

Closed
wants to merge 1 commit into from
Closed

color legend entry #228

wants to merge 1 commit into from

Conversation

SimonDanisch
Copy link
Member

Legend currently doesn't pick up an e.g. markercolor:

df = (
    x = 1:10,
    y = rand(10),
    attr = ["m $i" for i in 1:10],
)
draw(data(df) * mapping(:x, :y, marker=:attr) * visual(Scatter, color=:red))

image

This PR takes uses the color, if it's a single color:
image

if multiple colors are used, it defaults back to black:

draw(data(df) * (mapping(:x, :y, marker=:attr) * (visual(Scatter, color=:red, markersize=20) + visual(Scatter, color=:green, markersize=10))))

image

@greimel
Copy link
Collaborator

greimel commented Jul 7, 2021

I don't fully understand what the code does. But what happens if you use color for grouping but there happens to be just one group? (In my opinion, the legend for marker should be black despite there being just one color.)

What about a more general solution that adds all keywords from visual to options (which are then passed on to legend_element)?

(Not sure if that's easily doable, though)

@@ -88,6 +87,11 @@ function _Legend_(fg::FigureGrid)
labels = Vector{String}[]
elements_list = Vector{Vector{LegendElement}}[]

# search in attributes if a color is given for e.g. lines/scatter
legend_colors = unique([entry.attributes[:color] for entry in entries(grid) if haskey(entry.attributes, :color)])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not completely correct. What if one scatter layer has a color attribute, and another scatter layer has no color attribute, and is defaulting to the theme?

I think one should instead check that, for a given plottype, all the entries which use the marker scale (or whichever relevant scale is used in that legend group) also have a color attribute, and all the values agree. This may be not too hard to check, it should be all the entries where at least one of the label_attrs is in the keys of entry.primary.

I'm also not sure if it should only be done for color, or there are other attributes in visual that should be considered.

@piever
Copy link
Collaborator

piever commented Jul 8, 2021

I don't fully understand what the code does. But what happens if you use color for grouping but there happens to be just one group? (In my opinion, the legend for marker should be black despite there being just one color.)

I think this PR only considers colors that are given via visual. I confess I'm in two minds about this, I'm not completely sure which is a better default for the legend, whether it is the theme default or the values it encounters in visual (should they all agree). Do you have some intuition as to which is more natural?

Somehow, both things seem reasonable to me, and maybe it's not too bad to briefly change the theme to have red markers (maybe theme can be passed as a keyword to draw, and is merged to the default theme).

@piever piever mentioned this pull request May 14, 2023
@jkrumbiegel
Copy link
Member

this is fixed since 0.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants