Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fisker/to-nice-number
A JavaScript implementation of "Nice Numbers for Graph Labels" from Graphic Gems
https://github.com/fisker/to-nice-number
Last synced: 6 days ago
JSON representation
A JavaScript implementation of "Nice Numbers for Graph Labels" from Graphic Gems
- Host: GitHub
- URL: https://github.com/fisker/to-nice-number
- Owner: fisker
- License: mit
- Created: 2021-09-17T06:56:48.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-13T07:51:21.000Z (7 months ago)
- Last Synced: 2024-04-13T21:14:19.202Z (7 months ago)
- Language: JavaScript
- Size: 301 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# to-nice-number
> A JavaScript implementation of "Nice Numbers for Graph Labels" from Graphic Gems
## Install
```bash
yarn add to-nice-number
```## Files
```text
dist/
├─ index.js ( UMD )
├─ index.min.js ( UMD, compressed )
├─ index.mjs ( ES Module )
├─ index.min.mjs ( ES Module, compressed )
├─ index.cjs ( CommonJS )
└─ index.min.cjs ( CommonJS, compressed )
```## Usage
### browser
```html
import toNiceNumber from 'https://unpkg.com/to-nice-number?module'
console.log(toNiceNumber(Math.PI))
// => 5```
### node
```js
import toNiceNumber from 'to-nice-number'console.log(toNiceNumber(Math.PI))
// => 5
```## API
### toNiceNumber(number, round = false)
Get "nice" number for given `number`
## Links
- ["Nice Label Algorithm for Charts with minimum ticks"](https://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks)