Fork me on GitHub
#data-science
<
2019-02-23
>
jsa-aerial19:02:12

>>> How can I get vega-lite to understand this as a date? I don't believe you can - that does not conform to Vega(Lite) "temporal" (date) format: https://vega.github.io/vega-lite/docs/type.html. So to make use of the various capabilities and formatting https://vega.github.io/vega-lite/docs/format.html you will need to put it into a conforming form: "2019-02-012". This can also include a hour time stamp as part of it: "2019-02-012T08:00:00"

jsa-aerial19:02:21

Then you can cast to ordinal and use timeunits or just indicate type "temporal". For example:

jsa-aerial20:02:45

@dcj ^^^^ Note, those images (according to slack bot) may disappear soon...

dcj20:02:29

@jsa-aerial thanks! I find it curious that there is not some way to give vega-lite something like the output of parse by constructing the result from access from various fields, but whatever

jsa-aerial20:02:18

@dcj You might be able to do something like that with a transform. The idea would be to add a transform to your spec which takes your year, month, day map and turns it into a legal temporal string and assigns that to a new field. This would update the data stream with that added new field and formatted value. You would then use that in your encodings

dcj20:02:26

@jsa-aerial good idea, I will likely try that. That will save me from having to directly pollute my data with formatted time strings. Again, that they only let you parse a string is sub-optimal, iMHO

jsa-aerial20:02:00

@dcj Well, it is a bunch of different strings https://vega.github.io/vega-lite/docs/timeunit.html 🙂

jsa-aerial20:02:13

Also, you could (probably even easier) just do this yourself:

jsa-aerial20:02:32

I mean this doesn't pollute your data either and does what you want at the level of your specification as well.

dcj22:02:39

@jsa-aerial Sweet! Works great. Thank you!

dcj22:02:54

@jsa-aerial For some reason if I don't explicity parse the resulting vgldate, it labels 2019-02-01 as Jan 31! Cant't figure that one out!

jsa-aerial22:02:50

@dcj WTF? Hmmm, sounds like that might be a bug. Can you post the offending map (with your date and the vgldate)? I'd like to see that. Or you could ping the devs in Vega(Lite) Slack. What versions are you using??