An attempt to make time scale work with color schemes #3476
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, I recently faced an issue when trying to map time/temporal domain to a color scheme like "turbo".
For example the following code
produces
Which is probably not what you would expect from "turbo" color scheme.
I originally posted this as question it in vega-lite discussions, but later I realized that it is more a vega issue, rather than vega-lite.
For comparison I created the same plot using observable/plot:
and it correctly mapped time to colors, as I would expect:
As both vega and observable/plot use d3-scales under the hood, one might wonder, where does the difference come from. So here is my dive into the world of scales started. TBH, it looked pretty convoluted, at least when you look into it for the first time. I still have questions like why you need
linear
andsequentiaLinear
as separate scales, or why in some scales you haveinterpolator
, but in other scales it is calledinterpolate
.So, what I realized is that in order color schemes to work you need to use
sequential
variant of the scales. But there is noscaleSequentialTime
in d3. How does observable/plot then work? Looks like it doesn't use sequential scales at all. So, instead of:it uses:
https://github.com/observablehq/plot/blob/98d846e868e0c30bf3b55249c8ebb3308ea15440/src/scales/quantitative.js#L67-L87
In this PR, I'm trying to implement the same approach for Time and UTC scales in vega. It look like it does the job, but it feels quite hacky, so I doubt it should be merged as is. I just wanted to understand and demonstrate where does the problem come from and how it could be fixed. But probably there could be a more beautiful solution.
Here is demonstration how it works: https://observablehq.com/d/0af4e109ae46ffc3
Screen.Recording.2022-04-20.at.18.01.14.mov