vega-lite: Setting only `width` when using `autosize: fit` should not use default height in compiled Vega

See the compiled Vega from this example. The height is set the default config.view.height of 200, but I’d expect this chart to only “fit” the width (since that is all I specified).

To solve this, I imagine there are two options:

  1. We should not apply the config’s height or width when using "autosize": "fit" with one of the dimensions specified.
  2. We allow for some value of "autosize" that specifies only to "fit" along one dimension.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 25 (25 by maintainers)

Most upvoted comments

if we do this, wouldn’t it be impossible to specify something like

{ “width”: 200, “autosize”: “fit-x” }

without vega-lite adding in the default height as well? Or is that intentional?

Vega-Lite already always add default width/height if not specified (always a number for continuous and number or step for discrete) as in:

width = specifiedWidth || config.view.xxxWidth 

Basically, the width/height always have to come from somewhere anyway. So this issue is about how to apply the width/height (to just the axis or fit to axis + padding for label/title), not about how we get width/height.

width = specifiedWidth || config.view.xxxWidth

Of I understand @kanitw’s comment correctly, he assumes that we add fit-x and fit-y.

Yes, my proposed scheme works better with width and height.

should “autosize”: “fit” and “width”: 200 on QxQ compile to fit in Vega (and apply height config)?

Yes. Good point that it differs a bit from https://github.com/vega/vega-lite/issues/5133#issuecomment-513447536.

But we can simplify a lot of logic by saying that

width = specifiedWidth || config.view.xxxWidth // where XXX depends on whether x is discrete or continuous

Then the logic is simply “drop the ‘x’ part of fit when width (as defined above) is based on a step size”.

Note that we drop step when if x is continuous (as it’s invalid), so this logic should come after we drop step.

The same logic can be applied for “height” and “y”.

I think this actually simplifies the logic as compared to the comment above. Basically, we shouldn’t distinguish the width/height values whether it’s explicitly specified or derived from config.

Yes. In https://github.com/vega/vega-lite/issues/5133#issuecomment-513447536, you proposed to change VL, though, right? I am not yet convinced that we need to change the VL language.

Once that lands, you probably want to:

  • Update model.fit to be {x: boolean, y: boolean} instead of boolean and update their references accordingly.
  • Document the behavior in size.md

Thanks for volunteering to help. 😃

  1. would require changing Vega. Maybe 1. is simpler to do?