UNPKG

568 BPlain TextView Raw
1import { Category as CategoryScale, ScaleConfig } from '@antv/scale';
2import Base from './base';
3
4class Category extends Base {
5 createScale(scaleConfig: ScaleConfig) {
6 return new CategoryScale(scaleConfig);
7 }
8
9 _mapping(value) {
10 const { scale, range } = this;
11 if (scale.type === 'cat') {
12 const index = scale.translate(value);
13 return range[index % range.length];
14 }
15 const normalizeValue = scale.scale(value);
16 const index = Math.round(normalizeValue * (range.length - 1));
17 return range[index];
18 }
19}
20
21export default Category;