Skip to content

Separate legends (including main axes) from marks. #299

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

Closed
wants to merge 1 commit into from

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Apr 5, 2021

This allows to add a global color or radius legend to the plot as in https://observablehq.com/@data-workflows/plot-radiuslegend (ref #23 and #236).

Legends have the same signature as marks, but they receive only scales (index and channels are empty).

An issue is that the axes are below the marks, but I would tend to put the color and radius legends above them.
(I kept "unshift" to maintain the exact same order as in the test plots)

plot with two legends

This allows to add a global color or radius legend to the plot as in https://observablehq.com/@data-workflows/plot-radiuslegend

An issue is that the axes are below the marks, but I would tend to put the color and radius legends above them.
I kept "unshift" to maintain the exact same order as in the test plots
@mbostock
Copy link
Member

mbostock commented Apr 5, 2021

Sorry if I’m misunderstanding, but is this just a z-order issue with respect to the axes, which are currently always drawn on the bottom? Or is it because you want the legends to be exempt from faceting? Or both?

@Fil
Copy link
Contributor Author

Fil commented Apr 5, 2021

The main reason to isolate the legends is that I want them to be exempt from faceting.
To respect the current z-order, I've put them below the marks, but for radius or color legends I think they should be above the marks, so they don't get polluted if a mark happens to cover them.

In that sense this PR is incomplete, but I'm not sure what to do next: do we want to have three levels (legends below, marks, legends above?), or an explicit z-index (which we'd have to sort ourselves since SVG doesn't)? Or another idea?

@mbostock
Copy link
Member

mbostock commented Apr 5, 2021

I wonder if a name like “decorations” would be less prescriptive about the meaning of these things. There’s no requirement that the thing that you put in the legends array is actually a legend. (I also thought about “guides”, since that’s the Vega term for axes & legends, although here we want the axis to be a “mark” because it’s repeated across facets.)

Edit: er, sorry, I guess axes are a “legend” (or decoration), since they handle faceting internally.

Edit 2: I guess axes are very special since the facet axes or non-faceted axes are handled as a “legend”, but the within-facet axes are handled specially by the facet mark.

@Fil
Copy link
Contributor Author

Fil commented Apr 5, 2021

guides would be a good name!

@Fil Fil mentioned this pull request Apr 6, 2021
@Fil
Copy link
Contributor Author

Fil commented May 31, 2021

see also #425

@mbostock
Copy link
Member

Related #1197.

@Fil Fil closed this Mar 23, 2023
@Fil Fil deleted the fil/legends-array branch March 23, 2023 09:25
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.

2 participants