Conversation
|
Thanks. I think the spirit of this pull request is great. I wonder whether it would make more sense to support this in Vega? |
|
The idea to support this in Vega has been discussed before, for instance in this issue and here. In both cases @jheer suggested a solution in VL. Maybe his opinion has changed?
|
|
Ah, thanks for digging up those comments. Okay, let's see how we can tackle this in Vega-Lite then. |
|
I think it would be great to have easy access to this in vega-lite! I have needed this functionality often and it would be great to have a more automatic approach. A couple of thoughts:
Thanks! |
|
@kjgoodrick Thanks for your suggestions!
|
|
|
Alright, I’ve done some work on this and I think it’s ready for review:
Please let me know if I missed something. |
we have
Currently we don't have strong types for mark specific properties. I think it's fine to not address this in this PR. |
src/mark.ts
Outdated
| * | ||
| * __Default value:__ `2` | ||
| */ | ||
| bgPadding?: Padding; |
There was a problem hiding this comment.
I think using padding for both rect padding and text strokeWidth is mixing up two different things a bit.
I think it's better to separate background from outline since they can have different sets of properties.
Maybe:
background: Color | ES | TextBackground,
outline: Color | ES | TextOutlinewhere
interface TextBackground{
color: ... // required
opacity?: ...
padding?: ...
}
interface TextOutline {
color: ... // required
strokeWidth: ...
...
// no padding, cornerRadius
}
There was a problem hiding this comment.
Thank you for this feedback. I have separated the config for background and outline as you suggested, which has the added benefit of allowing a combination of both. I also have rewritten the example, tests and documentation. Please let me know if anything else is necessary.
There was a problem hiding this comment.
@kanitw If you have some time to spare, can you have a look at these changes and let me know if further work is needed? Thanks in advance.
|
@kanitw could you take a look at the latest changes? |
PR Description
This PR introduces background support for text marks in Vega-Lite, improving readability and enabling basic annotation use cases.
Motivation
There has been interest in supporting backgrounds for text marks in the past (e.g., #1820, #3418). These discussions suggested that Vega-Lite could provide syntactic sugar to leverage Vega’s existing reactive geometry for this purpose.
Proposal
This PR adds the following properties to the text mark definition:
outline, with sub propertiescolorandstrokeWidthbackground, with sub propertiescolor,opacity,padding, andcornerRadiusWhen specified, the
outlineproperty duplicates the text mark with a contrasting color and a larger stroke-width to create an outline. Thebackgroundproperty generates a rect layer behind the text in the compiled Vega spec. A combination is possible. The image below show examples of a text with outline, a text with a background and a combination of both. This is the spec for this example (opens in editor).