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

Recommended ordinal values throws an error #398

Open
samuelhafsteinsson opened this issue Jun 6, 2024 · 1 comment
Open

Recommended ordinal values throws an error #398

samuelhafsteinsson opened this issue Jun 6, 2024 · 1 comment

Comments

@samuelhafsteinsson
Copy link

samuelhafsteinsson commented Jun 6, 2024

In the documentation about ordinal values: https://unovis.dev/docs/guides/tips-and-tricks/#displaying-ordinal-values

It is recommended to use a NumericAccessor with a StringAcessor in the tickFormat to get an ordinal scale.
However the documentation show that the following code snippet should work:

const categories = ['A', 'B', 'C', 'D', 'E']
const tickFormat = (tick: number) => categories[tick]

A problem with that snippet is, the tick can be a float and thus the code will throw an error as it cannot index the array with a float.
The fix I implemented is using Number.isInteger as so:

const categories = ['A', 'B', 'C', 'D', 'E']
const tickFormat = (tick: number) => {
  if (Number.isInteger(tick))
   return categories[tick]
  return ''
}

Versions:

"@unovis/ts": "^1.4.1"
"@unovis/vue": "^1.4.1"
@samuelhafsteinsson samuelhafsteinsson changed the title Recommended ordinal values throws an error Recommended ordinal values throws an error - Vue Jun 10, 2024
@samuelhafsteinsson samuelhafsteinsson changed the title Recommended ordinal values throws an error - Vue Recommended ordinal values throws an error Jun 10, 2024
@rokotyan
Copy link
Contributor

Thanks for pointing this out @samuelhafsteinsson! The problem can be solved by providing a tickValues array to the Axis component explicitly: https://unovis.dev/docs/auxiliary/Axis#set-ticks-explicitly. We'll need to update the docs to mention it.

cc @reb-dev @lee00678

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