somehow-ticks

0.0.3 • Public • Published
somehow-ticks

work in progress

calculate some sensible break-points between two numbers

npm i somehow-ticks

const somehowTicks = require('somehow-ticks')
 
let ticks = somehowTicks(0, 5000, 5)
/*
[ { label: '1k', number: 1000, value: 0.2 },
  { label: '2k', number: 2000, value: 0.4 },
  { label: '3k', number: 3000, value: 0.6 },
  { label: '4k', number: 4000, value: 0.8 } ]
*/

This library has some opinions:

  • ticks should always be spaced evenly, even if this means less ticks
  • a tick should appear x.0 or x.5
  • they don't need to begin or end at the start and end.
  • less ticks are better than too-many ticks

it was built for labelling an x-axis in a space-limited way, but you can use it for whatever weird stuff.

See also:

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i somehow-ticks

Weekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

493 kB

Total Files

18

Last publish

Collaborators

  • spencermountain