vega / vega-lite

A concise grammar of interactive graphics, built on Vega.
https://vega.github.io/vega-lite/
BSD 3-Clause "New" or "Revised" License
4.69k stars 612 forks source link

format not respected for timeUnit with type='ordinal' #3594

Closed jakevdp closed 6 years ago

jakevdp commented 6 years ago

The axis format is not respected in the case of ordinal timeUnit encodings:

{
  "data": {
    "url": "data/seattle-temps.csv"
  },
  "mark": "line",
  "encoding": {
    "x": {
      "type": "ordinal",
      "axis": {"format": "%b"},
      "field": "month"
    },
    "y": {
      "type": "quantitative",
      "aggregate": "mean",
      "field": "temp"
    }
  },
  "transform": [
    {
      "field": "date",
      "timeUnit": "month",
      "as": "month"
    }
  ],
  "$schema": "https://vega.github.io/schema/vega-lite/v2.3.0.json"
}

export

If you switch "ordinal" to "temporal", you get the expected result. This is not a problem when using timeUnit within the encoding itself.

domoritz commented 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

kanitw commented 6 years ago

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.

domoritz commented 6 years ago

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.