Search code examples
vega-lite

Vega-Lite, issue with line color specification


My example.

My goal is to have the 'handgrenade' line be a solid red which continues as the 'projected handgrenade' dashed line, also red.

I threw the 'knights' in there as a blue line (which apparently works).


Solution

  • Related to my comment on the post itself, part of the difficulty here is that the current specification is trying to accomplish the task in a bit of a convoluted way. Essentially what is happening is that each line is created as a separate layer (see the related documentation pages on "Composing Layered and Multi-View plots here), with separate encodings. In order to display them properly, Vega-Lite is trying to merge all these different encodings together to create a single output visualization given all of the information it has. What this means is that it is trying to use a shared scale for the "stroke" across all three layers, but it is not entirely sure on how to resolve the conflicts in the changing scale range.

    The simplest solution (given what you have) is to explicitly tell Vega-Lite that the different "stroke" scales should be treated independently of one another, which can be done by appending "resolve": {"scale": {"stroke": "independent"}} after the closing square bracket of the "layer". Take a look at the documentation on "resolve" here.

    However, you may also want to consider refining the specification in some of the ways discussed in my comment above to more directly support the encodings as part fo a single layer in the view.