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

Support gradientLength for quantile and quantize color scales #9399

Open
hydrosquall opened this issue Jul 31, 2024 · 4 comments · May be fixed by #9400
Open

Support gradientLength for quantile and quantize color scales #9399

hydrosquall opened this issue Jul 31, 2024 · 4 comments · May be fixed by #9400
Labels

Comments

@hydrosquall
Copy link
Member

hydrosquall commented Jul 31, 2024

Motivation

For continuous (linear) scales on a color encoding, the gradientLength config can be used to control legend length.

Standard With custom config
image image

Unfortunately, this property has no effect when using discrete color scales, like quantile or quantize . As far as I could tell, the symbol config options don't control height either.

This can lead to legends that are much taller than their graph (see below: the gradientLength param is set, but it appears to have no effect.)

Quantize Quantile
image image

Proposed solution

  • Add at least 1 configuration option for discrete color scales, perhaps setting the overall legend height (since the quantile mode won't have even tick sizes), in the direction of discreteColorLegendLength .
  • If this property is added for Vega first, it will have to be propagated up to Vega-Lite separately.

Related PRs

@hydrosquall
Copy link
Member Author

hydrosquall commented Jul 31, 2024

From a code dive, it looks like discrete gradient legend is already reading the length param. However, it is not having a (visible) effect on the height of the legend.

This FR could be reclassified as a bugfix if the resolution is to wire the existing gradientLegend param into the discrete gradient legend.

https://github.com/vega/vega/blob/8a7f2f233b7fec430e52fbe19a544c1f290be591/packages/vega-parser/src/parsers/guides/legend-gradient-discrete.js#L13

@hydrosquall hydrosquall changed the title Custom legend length for quantile and quantize color scales Support gradientLength for quantile and quantize color scales Jul 31, 2024
@domoritz
Copy link
Member

Yeah, sounds like a bug fix.

@hydrosquall
Copy link
Member Author

hydrosquall commented Jul 31, 2024

After running local tests (I hardcoded a value into guide-util.js and checked the test specs for legends-discrete, this is a bug for vega-lite rather than vega .

Vega respects the gradientLength if there was is one passed in. The Vega-Lite specs are losing gradientLength at compile time, not at runtime.

Custom size (120) Default size (300)
image image

@hydrosquall hydrosquall transferred this issue from vega/vega Jul 31, 2024
@hydrosquall
Copy link
Member Author

hydrosquall commented Jul 31, 2024

I figured out a runtime fix, which I'll push shortly. The deeper conceptual question which might lead to a change back in vega is whether Discrete

https://github.com/vega/vega/blob/8a7f2f233b7fec430e52fbe19a544c1f290be591/packages/vega-parser/src/parsers/guides/constants.js#L25-L27

should be exported as a 3rd LegendType,

or if discrete should be classified as a special mode within gradient instead of as a mode under symbol.

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

Successfully merging a pull request may close this issue.

2 participants