1 | import { has, isNumber } from '@antv/util';
|
2 | import Base from '../base';
|
3 | import { ScaleType } from '../types';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export default class Identity extends Base {
|
11 | public readonly type: ScaleType = 'identity';
|
12 | public readonly isIdentity: boolean = true;
|
13 |
|
14 | public calculateTicks() {
|
15 | return this.values;
|
16 | }
|
17 |
|
18 | public scale(value: any): number {
|
19 |
|
20 | if (this.values[0] !== value && isNumber(value)) {
|
21 | return value;
|
22 | }
|
23 | return this.range[0];
|
24 | }
|
25 |
|
26 | public invert(value?: number): number {
|
27 | const range = this.range;
|
28 | if (value < range[0] || value > range[1]) {
|
29 | return NaN;
|
30 | }
|
31 | return this.values[0];
|
32 | }
|
33 | }
|