vega-lite icon indicating copy to clipboard operation
vega-lite copied to clipboard

UTC dates don't display properly in tooltips

Open jakevdp opened this issue 3 years ago • 5 comments

Here is a short example (open in editor):

{
  "data": {"values": [{"date": "2021-01-01"}]},
  "mark": {"type": "square", "size": 500},
  "encoding": {
    "tooltip": {
      "field": "date",
      "timeUnit": "utcyearmonthdatehours"
    },
    "x": {
      "field": "date",
      "timeUnit": "utcyearmonthdatehours"
    }
  }
}
Screen Shot 2021-01-25 at 3 04 09 PM

Despite showing identical fields with identical timeUnits, the date shown in the tooltip and the date shown on the axis label disagree.

Note that a workaround is to use "scale": {"type": "utc"} in the tooltip (view in editor), but I don't think this should be necessary:

{
  "data": {"values": [{"date": "2021-01-01"}]},
  "mark": {"type": "square", "size": 500},
  "encoding": {
    "tooltip": {
      "field": "date",
      "timeUnit": "utcyearmonthdatehours",
      "scale": {"type": "utc"}
    },
    "x": {
      "field": "date",
      "timeUnit": "utcyearmonthdatehours"
    }
  }
}
Screen Shot 2021-01-25 at 3 08 14 PM

jakevdp avatar Jan 25 '21 23:01 jakevdp

It looks like this also affects the text encoding, which makes the issue easier to see (open in editor):

{
  "data": {"values": [{"date": "2021-01-01"}]},
  "mark": "text",
  "encoding": {
    "text": {"field": "date", "timeUnit": "utcyearmonthdatehours"},
    "x": {"field": "date", "timeUnit": "utcyearmonthdatehours"}
  }
}

visualization (31)

jakevdp avatar Jan 25 '21 23:01 jakevdp

I am experiencing the same problem here. It is a pretty big issue for us and is blocking on going to production since data integrity is very important

image

rnvarma avatar Jan 29 '21 19:01 rnvarma

Ahh, the joy of time zones again.

@rnvarma can you look into what's going on in the Vega specs? It would help us immensely scope the effort for the fix.

domoritz avatar Jan 29 '21 20:01 domoritz

the config for the x encoding above is:

{
  field: "created",
  title: "Created",
  type: "temporal",
  timeUnit: "utcyearmonthdate",
  axis: { format: "%b %d" },
}

The date value itself in the data is 2020-08-04T00:00:00. It is correctly using UTC for the x axis value, but in the tooltip converting to local time and going back to the previous day

rnvarma avatar Feb 01 '21 15:02 rnvarma

I'm also running into this for point charts. Apologies if this isn't a minimal example, I'm new to Vega-Lite.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      {"Date": "2020-01-01", "Value": 10}
    ]
  },
  "mark": {"type": "point", "tooltip": true, "point": true},
  "height": "container",
  "width": "container",
  "encoding": {
    "x": {"field": "Date", "type": "temporal"},
    "y": {"field": "Value", "type": "quantitative"},
    "opacity": {"condition": {"param": "hover", "value": 1}, "value": 0.1},
  },
  "title": {"text": "Diff"},
  "params": [
    {
      "name": "hover",
      "bind": "legend",
      "select": {"type": "point", "fields": ["symbol"]}
    }
  ]
}
image

Open the Chart in the Vega Editor

bbkane avatar May 16 '22 03:05 bbkane

@jakevdp Do you plan to upgrade the altair version so it supports scale on the tooltip?

marr avatar Oct 18 '22 14:10 marr

Still running into this issue. Any ETA for a fix?

marr avatar Mar 03 '23 15:03 marr

I haven't had cycles to look into this yet. Can you investigate and maybe send a pull request?

domoritz avatar Mar 03 '23 15:03 domoritz

I can take a look. I had thought the workaround wasn't working, but it actually does. The schema has a squiggle under the value, but I am learning that shouldn't always be trusted.

marr avatar Mar 04 '23 13:03 marr

Anyone find a solution for this issue yet? I was going crazy thinking there was an issue with my data or how my data was read by altair, but finally realized it's an error in how altair renders the mark line tooltip.

sirusss avatar Jul 11 '23 01:07 sirusss

You can add "scale": { "type": "utc" } to the encoding as a workaround.

My PR fixes the issue but I wasn't able to get it merged because of the github access token. It still might be worth trying to merge that, @domoritz

marr avatar Jul 11 '23 12:07 marr

That worked - thank you!

sirusss avatar Jul 12 '23 02:07 sirusss

You can add "scale": { "type": "utc" } to the encoding as a workaround.

My PR fixes the issue but I wasn't able to get it merged because of the github access token. It still might be worth trying to merge that, @domoritz

Did that PR make it in? If so, what version fixes this?

jsherman256 avatar Sep 06 '23 10:09 jsherman256

No, I wasn’t able to get the support I needed to get the fix merged in.

On Wed, Sep 6, 2023 at 6:46 AM Justin Sherman @.***> wrote:

You can add "scale": { "type": "utc" } to the encoding as a workaround.

My PR fixes the issue but I wasn't able to get it merged because of the github access token. It still might be worth trying to merge that, @domoritz https://github.com/domoritz

Did that PR make it in? If so, what version fixes this?

— Reply to this email directly, view it on GitHub https://github.com/vega/vega-lite/issues/7185#issuecomment-1708107510, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAK2WEQB225RUBJPEKUJXTXZBIANANCNFSM4WSQEG5Q . You are receiving this because you commented.Message ID: @.***>

marr avatar Sep 06 '23 11:09 marr