Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add week and dayofyear time units #6526

Merged
merged 1 commit into from May 25, 2020
Merged

feat: add week and dayofyear time units #6526

merged 1 commit into from May 25, 2020

Conversation

domoritz
Copy link
Member

Closes #6349, closes #6348

@domoritz
Copy link
Member Author

domoritz commented May 23, 2020

One issue this pull request shows is that

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "data": {"url": "data/seattle-weather.csv"},
  "mark": "bar",
  "encoding": {
    "x": {
      "timeUnit": "week",
      "field": "date",
      "type": "ordinal"
    },
    "y": {
      "aggregate": "mean",
      "field": "precipitation",
      "type": "quantitative"
    }
  }
}

is incorrect. Notice how week 52 is repeated and the sort is incorrect.

@domoritz
Copy link
Member Author

I think the real issue is in Vega, though. Notice how week 52 appears twice because we are asking for week numbers in 2011 and 2012.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "data": {"url": "data/seattle-weather.csv"},
  "mark": "bar",
  "transform": [{
    "timeUnit": "week",
    "as": "week",
    "field": "date"
  }, {
    "aggregate": [{"op": "count", "as": "count"}],
    "groupby": ["week"]
  }, {
    "calculate": "timeFormat(datum.week, timeUnitSpecifier(['week']))",
    "as": "format_week"
  }],
  "encoding": {
    "y": {
      "field": "week",
      "type": "ordinal",
      "axis": {
        "format": "%Y W%U",
        "formatType": "time"
      }
    },
    "x": {
      "field": "count",
      "type": "quantitative"
    }
  }
}

image

@domoritz
Copy link
Member Author

I filed vega/vega#2651 but I think Vega-Lite is doing the right thing so I think we should merge this pull request.

@domoritz domoritz marked this pull request as ready for review May 24, 2020 04:08
@domoritz domoritz requested review from a team and jheer May 24, 2020 04:08
Copy link
Member

@kanitw kanitw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Vega-Lite is doing the right thing so I think we should merge this pull request.

I disagree. Merging this means we're exposing it in the schema and docs in the next version, even though it doesn't work correctly yet (without a fix in Vega).

We better merge this after this is fixed in Vega.

@kanitw kanitw added the Blocked 🕐 For issues that are blocked by other issues label May 24, 2020
@domoritz
Copy link
Member Author

I marked vega/vega#2651 as blocking.

@domoritz domoritz removed the Blocked 🕐 For issues that are blocked by other issues label May 24, 2020
@domoritz
Copy link
Member Author

@jheer helped me understand the issue here and I don't think vega/vega#2651 is still blocking this pull request.

The problem is that week 0 can be shorter in some years. Since time unit floors dates to Sunday and 2012 (which we use for time units) does not have a week 0 (the year starts on a Sunday), dates in week 0 are in week 52 in 2011. If we want to have both a bin for week 0 and for week 53, we would need to give up that time units are at regular intervals.

I'd say that we should accept this pull request as is. The time units are correct albeit the labels are a bit odd. In the future, we can consider formatting times in the transform and grouping by the label instead of using time unit but that's an invasive change that I don't see as necessary right now.

@domoritz domoritz requested a review from kanitw May 24, 2020 20:33
@kanitw kanitw merged commit 72a6838 into master May 25, 2020
@kanitw kanitw deleted the dom/week-dayofyear branch May 25, 2020 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add week Time Unit Feature request: "day of year" timeUnit
2 participants