-
-
Notifications
You must be signed in to change notification settings - Fork 677
fix: align stack order with color domain #9641
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
fix: align stack order with color domain #9641
Conversation
|
(This is a very exciting PR, thank you for pushing on this!) |
domoritz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
src/compile/unit.ts
Outdated
| offsetEncoding.sort = domain as []; | ||
| } else { | ||
| // align stacked bar and area order with color domain | ||
| const orderExpression = `indexof(${JSON.stringify(domain)}, datum.${field})`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use stringValue from utils here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that makes sense, I have updated the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I have a question regarding stringValue. If I understand correctly, its purpose is to escape problematic Unicode characters in strings, like explained here. So I changed my code to:
const orderExpression = `indexof(${stringValue(domain)}, datum['${stringValue(field)}'])`;However, specs with problematic Unicode characters break the script anyway, as the following example shows: open it in the editor.
To avoid this, I think escaping or removing those characters could be handled earlier in the process. For example, this quick and dirty solution in the main compile function seems to work:
let spec = normalize(inputSpec, config);
spec = JSON.parse(
JSON.stringify(spec)
.replaceAll('\u2028', '')
.replaceAll('\u2029', '')
);Do you agree? If so, I would be happy to dig into this, though I assume that would be best handled in a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, separate pull request. We don't really try to deal with bad characters in Vega-Lite except for a few cases that have come up.
|
Thanks for the pull request. I thought the build already included all the changes but I missed a few critical issues. Can you fix them in a follow up pull request or should I revert the pull request for now?
|
## PR Description Refines [PR: fix: align stack order with color domain](#9641): - Only for specs with nominal color encoding the stack order is aligned with a custom color domain (if one is provided). - The internal field that is use to order the stack is no longer added to aria-labels in the SVG --------- Co-authored-by: Bas Broekhuizen <bas.broekhuizen@gmail.com> Co-authored-by: GitHub Actions Bot <vega-actions-bot@users.noreply.github.com>
PR Description
This PR addresses long-standing issues (dating back to 2016) related to misalignment between the order of stacked marks and the domain in the color encoding. It potentially closes #1734, #6203, and #9496.
Proposed Solution
A new method has been added to the unit parser to check if a color domain is defined in the unit. If a domain is present and no custom order is set, additional encoding is injected to ensure that the color order of the mark matches the order in the legend.
Note
This is my first contribution to the project. If my code doesn't meet the project's standards or if the process I followed is incorrect, I apologise. I'm happy to refactor, feedback is very welcome!
Examples
Below are examples of specs rendered with the current code (left) and the same specs rendered with the proposed solution (right). All specs share this color encoding:
"scale": {"domain": ["B", "A", "C"], "range": ["red", "blue", "green"]}