1 | <h1 align="center">
|
2 | <b>@antv/scale</b>
|
3 | </h1>
|
4 |
|
5 | <div align="center">
|
6 |
|
7 | Toolkit for mapping abstract data into visual representation.
|
8 |
|
9 | ![scale mapping](https://user-images.githubusercontent.com/7856674/116353528-85644a80-a829-11eb-85e4-3463a29000a9.png)
|
10 |
|
11 | [![Build Status](https://github.com/antvis/scale/workflows/build/badge.svg?branch=master)](https://github.com/antvis/scale/actions)
|
12 | [![Coverage Status](https://img.shields.io/coveralls/github/antvis/scale/master.svg)](https://coveralls.io/github/antvis/scale?branch=master)
|
13 | [![npm Version](https://img.shields.io/npm/v/@antv/scale.svg)](https://www.npmjs.com/package/@antv/scale)
|
14 | [![npm Download](https://img.shields.io/npm/dm/@antv/scale.svg)](https://www.npmjs.com/package/@antv/scale)
|
15 | [![npm License](https://img.shields.io/npm/l/@antv/scale.svg)](https://www.npmjs.com/package/@antv/scale)
|
16 |
|
17 | </div>
|
18 |
|
19 | ## ✨ Features
|
20 |
|
21 | - **Powerful**: Ability to customize tickMethod are offered with abundant kinds of scales.
|
22 | - **High performance**: Use different methods to cache some state of scales to improve performance.
|
23 | - **Fully embrace TypeScript**: All code are written in TypeScript and complete type definition files are provided.
|
24 |
|
25 | ## 📦 Installation
|
26 |
|
27 | ```bash
|
28 | $ npm install @antv/scale
|
29 | ```
|
30 |
|
31 | ## 🔨 Getting Started
|
32 |
|
33 | - Basic usage
|
34 |
|
35 | ```ts
|
36 | import { Linear, LinearOptions } from '@antv/scale';
|
37 |
|
38 | const options: LinearOptions = {
|
39 | domain: [0, 10],
|
40 | range: [0, 100],
|
41 | };
|
42 | const x = new Linear(options);
|
43 |
|
44 | x.map(2); // 20
|
45 | x.invert(20); // 2
|
46 | x.getTicks(); // [0, 2.5, 5, 7.5, 10]
|
47 | ```
|
48 |
|
49 | - Customize tickMethod
|
50 |
|
51 | ```ts
|
52 | import { Linear } from '@antv/scale';
|
53 |
|
54 | const x = new Linear({
|
55 | domain: [0, 10],
|
56 | range: [0, 100],
|
57 | tickCount: 3,
|
58 | tickMethod: () => [0, 5, 10],
|
59 | });
|
60 |
|
61 | x.getTicks(); // [0, 5, 10]
|
62 | ```
|
63 |
|
64 | ## 📎 Links
|
65 |
|
66 | - [Introduction](https://observablehq.com/@pearmini/antv-scale)
|
67 | - [API Reference](./docs/api/readme.md)
|
68 |
|
69 | ## 📮 Contribution
|
70 |
|
71 | ```bash
|
72 | $ git clone git@github.com:antvis/scale.git
|
73 |
|
74 | $ cd scale
|
75 |
|
76 | $ npm i
|
77 |
|
78 | $ npm t
|
79 | ```
|
80 |
|
81 | Then send a pull request after coding.
|
82 |
|
83 | ## 📄 License
|
84 |
|
85 | MIT@[AntV](https://github.com/antvis).
|