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

Using timestamps as x-axis values results in misaligned labels #450

Open
davestewart opened this issue Sep 25, 2024 · 3 comments
Open

Using timestamps as x-axis values results in misaligned labels #450

davestewart opened this issue Sep 25, 2024 · 3 comments

Comments

@davestewart
Copy link

Hello,

We're using timestamps as our Datum x-axis values, but it seems to result in misaligned x-axis labels:

image

Using indices, the labels line up perfectly:

image

Feels like a bug.

Is it?

@AnthonyCVP
Copy link

+1, I am having the same problem.

@davestewart
Copy link
Author

davestewart commented Sep 26, 2024

Right now I am using the following workaround:

  • add index values to data (which already contains timestamp)
  • set x-axis as (d) => d.index
  • in tickFormat() do this: tickFormat: (x, index) => formatAsMonth(data[index].timestamp)

EDIT: index will be incorrect if numTicks is modified (index is the index of the tick, not the datapoint), so will need to determine the datapoint index with something like:

tickFormat: (x: number) => {
  // workaround for https://github.com/f5/unovis/issues/450
  if (format.startsWith('date')) {
    const index = model.data.findIndex(d => d.index === x)
    return formatValue(model.data[index].timestamp, format)
  }
  return formatValue(x, format)
},

This gets us over a hump, until hopefully a fix arrives:

CleanShot 2024-09-26 at 18 16 06

@AnthonyCVP
Copy link

Thank you, I did that after your original post suggestion. Much appreciated @davestewart !

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

No branches or pull requests

2 participants