question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: "day of year" timeUnit

See original GitHub issue

It 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
}

visualization - 2020-04-17T061237 583

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:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jheercommented, Apr 17, 2020

I just added a dayofyear unit in this Vega PR: https://github.com/vega/vega/pull/2530

Also, 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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found