@antv/f2
Version:
Charts for mobile visualization.
22 lines (18 loc) • 577 B
text/typescript
import { Category as CategoryScale, ScaleConfig } from '../deps/f2-scale/src';
import Base from './base';
class Category extends Base {
createScale(scaleConfig: ScaleConfig) {
return new CategoryScale(scaleConfig);
}
_mapping(value) {
const { scale, range } = this;
if (scale.type === 'cat') {
const index = scale.translate(value);
return range[index % range.length];
}
const normalizeValue = scale.scale(value);
const index = Math.round(normalizeValue * (range.length - 1));
return range[index];
}
}
export default Category;