Skip to content

Commit

Permalink
feat(scrollbar): 支持设置与获取当前滚动条的位置 (#3639)
Browse files Browse the repository at this point in the history
* feat(scrollbar): 支持设置与获取当前滚动条的位置

* test(scrollbar): 补充了单测

Co-authored-by: yangtao.yangtao <yangtao.yangtao@alibaba-inc.com>
  • Loading branch information
Aarebecca and yangtao.yangtao committed Oct 8, 2021
1 parent c8a1407 commit 3c89edf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/chart/controller/scrollbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ export default class Scrollbar extends Controller<ScrollbarOption> {
this.yScalesCfg = [];
}

/** 设置滚动条位置 */
public setValue(ratio: number) {
this.onValueChange({ ratio });
}

/** 获得滚动条位置 */
public getValue() {
return this.ratio;
}

/**
* 获取 scrollbar 的主题配置
*/
Expand Down
42 changes: 42 additions & 0 deletions tests/unit/chart/controller/scrollbar-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,48 @@ import { near } from '../../../util/math';
describe('Scrollbar', () => {
const container = createDiv();

it('scrollbar value', async () => {
const chart = new Chart({
container,
height: 400,
width: 500,
});
chart.animate(false);
chart.data(salesBySubCategory);
chart.option('scrollbar', {
type: 'horizontal',
});
chart.scale('sales', {
nice: true,
formatter: (v) => `${Math.floor(v / 10000)}万`,
});
chart.axis('subCategory', {
label: {
autoRotate: false,
},
});
chart.interval().position('subCategory*sales').label('sales');

chart.render();
const coordinateBBox = chart.coordinateBBox;

await delay(1);

const scrollbar = chart.getController('scrollbar');

expect(scrollbar.getValue()).toBe(0);
scrollbar.setValue(1);
expect(scrollbar.getValue()).toBe(1);
scrollbar.setValue(0.5);
expect(scrollbar.getValue()).toBe(0.5);
scrollbar.setValue(-0.5);
expect(scrollbar.getValue()).toBe(0);
scrollbar.setValue(1.5);
expect(scrollbar.getValue()).toBe(1);

chart.destroy();
});

it('scrollbar /w interval horizontal', async () => {
const chart = new Chart({
container,
Expand Down

0 comments on commit 3c89edf

Please sign in to comment.