Closed jakevdp closed 6 years ago
The problem is that we don't know that the field is a date.
The way to fix it (as you pointed out) is to use timeUnit.
{
"data": {
"url": "data/seattle-temps.csv"
},
"mark": "line",
"encoding": {
"x": {
"type": "ordinal",
"axis": {"format": "%b"},
"field": "month",
"timeUnit": "month"
},
"y": {
"type": "quantitative",
"aggregate": "mean",
"field": "temp"
}
},
"transform": [
{
"field": "date",
"timeUnit": "month",
"as": "month"
}
],
"$schema": "https://vega.github.io/schema/vega-lite/v2.json"
}
I don't remember how we were trying to solve this but one way would be to track whether a field is temporal or not or introduce a new type temporal-ordinal
.
@kanitw might have a suggestion
I would strong vote against adding temporal-ordinal
. I don't see why we would need it.
Casting raw temporal value as ordinal doesn't make sense. Casting temporal value with timeUnit like month to ordinal is reasonable, but that doesn't need a new complex type.
If we track the month
is a field that is derived by applying timeUnit
(#2862), this problem would go away.
Since this is a duplicate of #2862, I'll close this for now.
Oh, I missed the time unit transform in the spec Jake posted. Yes, in this case we can track it. However, how do we handle this case if there is no time unit? I think we can ask people to parse fields as dates.
The axis format is not respected in the case of ordinal timeUnit encodings:
If you switch
"ordinal"
to"temporal"
, you get the expected result. This is not a problem when usingtimeUnit
within the encoding itself.