• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

antvis / scale / 17070978712

19 Aug 2025 01:23PM UTC coverage: 99.376% (-0.4%) from 99.781%
17070978712

Pull #215

github

lxfu1
feat: add the broken function to the linear scale
Pull Request #215: feat: add the broken function to the linear scale

368 of 376 branches covered (97.87%)

Branch coverage included in aggregate %.

45 of 46 new or added lines in 3 files covered. (97.83%)

1065 of 1066 relevant lines covered (99.91%)

31973.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/src/scales/base.ts
1
import { deepMix } from '@antv/util';
26✔
2
import { BaseOptions, Domain, Range, Unknown } from '../types';
3

4
export abstract class Base<O extends BaseOptions> {
26✔
5
  /**
6
   * 将定义域里面的一个值,根据转换规则,转换为值域的一个值。
7
   * 如果该值不合法,则返回 options.unknown
8
   * @param x 需要转换的值
9
   */
10
  abstract map(x: Domain<O>): Range<O> | Unknown<O>;
11

12
  /**
13
   * 将值域里的一个值,据转换规则,逆向转换为定义域里的一个值或者一个区间
14
   * @param x 需要转换的值
15
   */
16
  abstract invert(x: Range<O>): Domain<O> | Domain<O>[] | Unknown<O>;
17

18
  /**
19
   * 克隆一个新的比例尺,可以用于更新选项
20
   */
21
  abstract clone(): Base<O>;
22

23
  /**
24
   * 子类需要覆盖的默认配置
25
   */
26
  protected abstract getDefaultOptions(): Partial<O>;
27

28
  /**
29
   * 将用户传入的选项和默认选项合并,生成当前比例尺的选项
30
   */
31
  protected transformBreaks(options: O): O {
NEW
32
    return options;
×
33
  }
34

35
  /**
36
   * 比例尺的选项,用于配置数据映射的规则和 ticks 的生成方式
37
   */
38
  protected options: O;
39

40
  /**
41
   * 构造函数,根据自定义的选项和默认选项生成当前选项
42
   * @param options 需要自定义配置的选项
43
   */
44
  constructor(options?: O) {
45
    this.options = deepMix({}, this.getDefaultOptions());
220✔
46
    this.update(options?.breaks?.length ? this.transformBreaks(options) : options);
220✔
47
  }
48

49
  /**
50
   * 返回当前的所有选项
51
   * @returns 当前的所有选项
52
   */
53
  public getOptions(): O {
54
    return this.options;
149✔
55
  }
56

57
  /**
58
   * 更新选项和比例尺的内部状态
59
   * @param updateOptions 需要更新的选项
60
   */
61
  public update(updateOptions: Partial<O> = {}): void {
64✔
62
    const options = updateOptions.breaks ? this.transformBreaks(updateOptions as O) : updateOptions;
274✔
63
    this.options = deepMix({}, this.options, options);
274✔
64
    this.rescale(options);
274✔
65
  }
66

67
  /**
68
   * 根据需要更新 options 和更新后的 options 更新 scale 的内部状态,
69
   * 在函数内部可以用 this.options 获得更新后的 options
70
   * @param options 需要更新的 options
71
   */
72
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
73
  protected rescale(options?: Partial<O>): void {}
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc