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
Conversation
f5c792a
to
4fdecd7
Compare
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. |
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"
}
}
} |
I filed vega/vega#2651 but I think Vega-Lite is doing the right thing so I think we should merge this pull request. |
There was a problem hiding this 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.
I marked vega/vega#2651 as blocking. |
@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. |
Closes #6349, closes #6348