Skip to content

Commit

Permalink
chore: fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk authored and hustcc committed Apr 26, 2020
1 parent ec67cbb commit e1cbfda
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/manual/tutorial/slider.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface SliderOption {
readonly start?: number;
readonly end?: number;
/** 格式化 Mask */
mask?: (val: any) => string;
readonly mask?: (options: {val: string, datum: Datum, idx: number}) => string;
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/manual/tutorial/slider.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface SliderOption {
readonly start?: number;
readonly end?: number;
/** 格式化 Mask */
mask?: (val: any) => string;
readonly mask?: (options: {val: string, datum: Datum, idx: number}) => string;
}
```

Expand Down
11 changes: 6 additions & 5 deletions src/chart/controller/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { isBetween, omit } from '../../util/helper';
import View from '../view';
import { Controller } from './base';

export type SliderMaskType = (options: {val: string, datum: Datum, idx: number}) => string;
/** Slider 配置 */
export interface SliderOption {
/** slider 高度 */
Expand All @@ -32,7 +33,7 @@ export interface SliderOption {
/** 滑块初始化的结束位置 */
readonly end?: number;
/** 格式化 Mask */
mask?: (val: any) => string;
readonly mask?: SliderMaskType;
}

type Option = SliderOption | boolean;
Expand Down Expand Up @@ -228,10 +229,10 @@ export default class Slider extends Controller<Option> {
let minText = get(xData, [minIndex]);
let maxText = get(xData, [maxIndex]);

const mask = this.getSliderCfg().mask as ((val: any) => string);
if (typeof mask === 'function') {
minText = mask(minText);
maxText = mask(maxText);
const mask = this.getSliderCfg().mask as SliderMaskType;
if (mask) {
minText = mask({ val: minText, datum: data[minIndex], idx: minIndex });
maxText = mask({ val: maxText, datum: data[maxIndex], idx: maxIndex });
}

// 更新文本
Expand Down

0 comments on commit e1cbfda

Please sign in to comment.