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.

57 lines
1.6 KiB

4 months ago
import { isNumber } from '@antv/util';
import { d3Ticks } from '../tick-methods/d3-ticks';
import { ConstantOptions, Domain, Range } from '../types';
import { Base } from './base';
export class Constant extends Base<ConstantOptions> {
/**
*
* @returns
*/
protected getDefaultOptions(): ConstantOptions {
return {
range: [0],
domain: [0, 1],
unknown: undefined,
tickCount: 5,
tickMethod: d3Ticks,
};
}
/**
* y = b b options.range
* @param _
* @returns
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public map(_: Domain<ConstantOptions>) {
const [v] = this.options.range;
return v !== undefined ? v : this.options.unknown;
}
/**
* x x === b []
* @param x (
* @returns
*/
public invert(x: Range<ConstantOptions>) {
const [v] = this.options.range;
return x === v && v !== undefined ? this.options.domain : [];
}
public getTicks() {
const { tickMethod, domain, tickCount } = this.options;
const [a, b] = domain;
if (!isNumber(a) || !isNumber(b)) return [];
return tickMethod(a, b, tickCount);
}
/**
* Constant Scale
* @returns Constant Scale
*/
public clone() {
return new Constant(this.options);
}
}