-
Notifications
You must be signed in to change notification settings - Fork 626
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
Conditions in color encodings are not reflected in legend #9497
Comments
I see how this seems like a bug at first, but it may be a feature request as this isn't a regression, it was just not built before. Conditions were added independently of legends, and can be expressed in many forms. Since this form is using an expression test rather than a field predicate , Vega-lite is not readily aware that "origin" is being used in the test and that one of dots can be recolored. I would suggest to think of the current legend as the color to use as long as no conditions are met. We could implement legends for conditional rules as a future enhancement, but it's currently not doable. If you wish to change the color for a specific country in a graph and have that reflected in the legend, you can do so with a custom (scale.range) instead of using a condition. Would that work for your case? |
Yeah, I figure it might not be exactly a bug. I've gotten around it so far by fully specifying the scale's domain/range, rather than using a condition. But that requires me to consume the entire dataset to build out those arrays. If there's a better way to do that, I'd be very curious how (I'm not familiar with scale.scheme.range, so if you have an example, I'd be thankful!). |
I should also add that I've used (I think) the field predicate version of the condition, and seen the same issue. |
It sounds like you might already have tried this if you've already set a custom range, but just in case here's a custom range example {
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"url": "data/cars.json"},
"mark": "point",
"encoding": {
"x": {"field": "Horsepower", "type": "quantitative"},
"y": {"field": "Miles_per_Gallon", "type": "quantitative"},
"color": {"field": "Origin", "type": "nominal", "scale": {
"range": [
"orange",
"blue",
"lightgray"
]
}}
}
} RE: field predicate: we don't use the conditions in any form for the legends, but thanks for linking that too. I made the point about the condition form mainly to say that if we were to implement it, it may be easier to label with the predicate form than the "arbitrary expression" form. |
Yeah in that case it doesn't pin the color to specific values right? We're essentially using conditions as "these values should map to these colors, but the rest can come from the scheme". |
I think domain and range are linked (first domain value, first color), the
order matters. As long as you know all the domain values up front, you can
pin color to data values.
…On Wed, Jan 22, 2025 at 9:20 AM Rob Miller ***@***.***> wrote:
Yeah in that case it doesn't pin the color to specific values right? We're
essentially using conditions as "these values should map to these colors,
but the rest can come from the scheme".
—
Reply to this email directly, view it on GitHub
<#9497 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACE2MM26NGA6EYO64WWUIVT2L6SKXAVCNFSM6AAAAABTQJ7L4SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMBXGM3TKOJSHA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Yeah, that's actually what I wound up doing to fix legends. So we now define explicit domains / ranges. The problem with that is having to iterate large data sets to generate those arrays, and vega-lite seems to struggle when they get in to the thousands / tens of thousands. But I can work with that for now. |
Thanks for the feedback - being able to set explicit colors for categories
and have those reflected in the legend is a reasonable use case.
For these large datasets, how many entries do you end up displaying in the
legend?
…On Wed, Jan 22, 2025 at 11:06 AM Rob Miller ***@***.***> wrote:
Yeah, that's actually what I wound up doing to fix legends. So we now
define explicit domains / ranges. The problem with that is having to
iterate large data sets to generate those arrays, and vega-lite seems to
struggle when they get in to the thousands / tens of thousands.
But I can work with that for now.
—
Reply to this email directly, view it on GitHub
<#9497 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACE2MM3M665PKPFMGQKC35L2L66ZNAVCNFSM6AAAAABTQJ7L4SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMBXGY2TANJRGM>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
All of them, so thousands. This is likely not a realistic use case, as coloring by even 1000 values would likely not be a very useful visualization, and at that point we'd take it back to design. So in general, I'd expect the number to be generally small. |
Ah I see. I’m not sure how much screen space your graphs get, but the
legend size will be limited by the size of the graph surface since
currently the legends are not expandable.
…On Thu, Jan 23, 2025 at 7:14 AM Rob Miller ***@***.***> wrote:
All of them, so thousands. This is likely not a realistic use case, as
coloring by even 1000 values would likely not be a very useful
visualization, and at that point we'd take it back to design. So in
general, I'd expect the number to be generally small.
—
Reply to this email directly, view it on GitHub
<#9497 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACE2MMYPCCLXDOKYDP6EGJT2MDMKHAVCNFSM6AAAAABTQJ7L4SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMBZGY2TONZQGY>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Bug Description
If you have a color encoding with a conditional re-coloring on it for particular values, those re-colorings are not reflected in the legend.
Produces:
Repro
Checklist
The text was updated successfully, but these errors were encountered: