You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.2 KiB
88 lines
2.2 KiB
|
4 months ago
|
<h1 align="center">
|
||
|
|
<b>@antv/scale</b>
|
||
|
|
</h1>
|
||
|
|
|
||
|
|
<div align="center">
|
||
|
|
|
||
|
|
> Toolkit for mapping abstract data into visual representation. [Living Demo](https://observablehq.com/@pearmini/antv-scale) · [中文文档](./README.md)
|
||
|
|
|
||
|
|

|
||
|
|
|
||
|
|
[](https://github.com/antvis/scale/actions)
|
||
|
|
[](https://coveralls.io/github/antvis/scale?branch=master)
|
||
|
|
[](https://www.npmjs.com/package/@antv/scale)
|
||
|
|
[](https://www.npmjs.com/package/@antv/scale)
|
||
|
|
[](https://www.npmjs.com/package/@antv/scale)
|
||
|
|
|
||
|
|
</div>
|
||
|
|
|
||
|
|
## ✨ Features
|
||
|
|
|
||
|
|
- **Powerful**: Ability to customize tickMethod are offered with abundant kinds of scales.
|
||
|
|
- **High performance**: Use different methods to cache some state of scales to improve performance.
|
||
|
|
- **Fully embrace TypeScript**: All code are written in TypeScript and complete type definition files are provided.
|
||
|
|
|
||
|
|

|
||
|
|
|
||
|
|
## 📦 Installation
|
||
|
|
|
||
|
|
```bash
|
||
|
|
$ npm install @antv/scale
|
||
|
|
```
|
||
|
|
|
||
|
|
## 🔨 Getting Started
|
||
|
|
|
||
|
|
- Basic usage
|
||
|
|
|
||
|
|
```ts
|
||
|
|
import { Linear, LinearOptions } from '@antv/scale';
|
||
|
|
|
||
|
|
const options: LinearOptions = {
|
||
|
|
domain: [0, 10],
|
||
|
|
range: [0, 100],
|
||
|
|
};
|
||
|
|
const x = new Linear(options);
|
||
|
|
|
||
|
|
x.map(2); // 20
|
||
|
|
x.invert(20); // 2
|
||
|
|
x.getTicks(); // [0, 2.5, 5, 7.5, 10]
|
||
|
|
```
|
||
|
|
|
||
|
|
- Customize tickMethod
|
||
|
|
|
||
|
|
```ts
|
||
|
|
import { Linear } from '@antv/scale';
|
||
|
|
|
||
|
|
const x = new Linear({
|
||
|
|
domain: [0, 10],
|
||
|
|
range: [0, 100],
|
||
|
|
tickCount: 3,
|
||
|
|
tickMethod: () => [0, 5, 10],
|
||
|
|
});
|
||
|
|
|
||
|
|
x.getTicks(); // [0, 5, 10]
|
||
|
|
```
|
||
|
|
|
||
|
|
## 📎 Links
|
||
|
|
|
||
|
|
- [Introduction](https://observablehq.com/@pearmini/antv-scale)
|
||
|
|
- [API Reference](./docs/api/readme.md)
|
||
|
|
|
||
|
|
## 📮 Contribution
|
||
|
|
|
||
|
|
```bash
|
||
|
|
$ git clone git@github.com:antvis/scale.git
|
||
|
|
|
||
|
|
$ cd scale
|
||
|
|
|
||
|
|
$ npm i
|
||
|
|
|
||
|
|
$ npm t
|
||
|
|
```
|
||
|
|
|
||
|
|
Then send a pull request after coding.
|
||
|
|
|
||
|
|
## 📄 License
|
||
|
|
|
||
|
|
MIT@[AntV](https://github.com/antvis).
|