Feature request: "day of year" timeUnit
See original GitHub issueIt would be nice if it were possible to compute the day of year as a timeUnit. Here is how it can be calculated using a series of transforms:
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {"url": "data/seattle-weather.csv"},
"transform": [
{"timeUnit": "yearmonthdate", "field": "date", "as": "date"},
{"timeUnit": "year", "field": "date", "as": "start"},
{"calculate": "round((datum.date - datum.start) / (24 * 60 * 60 * 1000), 1)", "as": "dayOfYear"}
],
"mark": "rect",
"encoding": {
"x": {"field": "dayOfYear", "type": "ordinal", "title": "day of year"},
"y": {"field": "date", "timeUnit": "year", "type": "ordinal", "title": "year"},
"color": {"field": "temp_max", "type": "quantitative"}
},
"width": 800
}
It would be nicer if the above chart could be expressed as something like this:
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {"url": "data/seattle-weather.csv"},
"mark": "rect",
"encoding": {
"x": {"field": "date", "timeUnit": "dayofyear", "type": "ordinal", "title": "day of year"},
"y": {"field": "date", "timeUnit": "year", "type": "ordinal", "title": "year"},
"color": {"field": "temp_max", "type": "quantitative"}
},
"width": 800
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
TimeUnit - Android Developers
android.icu.util.MeasureUnit. ↳, android.icu.util.TimeUnit ... public static final TimeUnit · DAY ... Constant for unit of length: light-year.
Read more >TimeUnit (Java Platform SE 8 ) - Oracle Help Center
A TimeUnit represents time durations at a given unit of granularity and provides utility methods to convert across units, and to perform timing...
Read more >Add a duration/timedelta type · Issue #514 · toml-lang ... - GitHub
Feature request : Add a duration/timedelta type #514 ... Ending up with a duration that's either years and months, or days and time...
Read more >TimeUnit - ArcGIS Developers
The units of time used in a service, layer or sublayer which support time based operations. This is used to determine what the...
Read more >All Power Apps Date & Time Functions (With Examples)
Creates a date from a year, month and day. Syntax. Date(year, month, day) ... Can also add another time unit such as hours...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jakevdp https://github.com/vega/vega-lite/issues/6349
I just added a
dayofyear
unit in this Vega PR: https://github.com/vega/vega/pull/2530Also, Vega supports both week (
week
) and day of week (day
) units that I think you should be able to use for a nice cross-tab, assuming Vega-Lite exposes those.I don’t think we’d support a complement, in part because as I don’t know how that should handle all the fields of full date-times (with hours, milliseconds, etc).