f5 / unovis

Modular data visualization framework for React, Angular, Svelte, Vue, and vanilla TypeScript or JavaScript
https://unovis.dev
Apache License 2.0
2.26k stars 43 forks source link

Recommended ordinal values throws an error #398

Open ghost opened 5 months ago

ghost commented 5 months ago

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"
rokotyan commented 4 months ago

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