Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(issue-2078): 修复 waterfall 无法关闭 tooltip #2079

Merged
merged 3 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions __tests__/bugs/issue-2078-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Waterfall } from '../../src';
import { createDiv } from '../utils/dom';

describe('#2078', () => {
const data = [
{ type: '日用品', money: 300 },
{ type: '伙食费', money: 900 },
{ type: '交通费', money: -200 },
{ type: '水电费', money: 300 },
{ type: '房租', money: 1200 },
{ type: '商场消费', money: 1000 },
{ type: '应酬交际', money: 2000 },
{ type: '总费用', money: 5900 },
];

const waterfall = new Waterfall(createDiv(), {
width: 400,
height: 300,
xField: 'type',
yField: 'money',
data: data,
tooltip: false,
});

it('关闭 tooltip', () => {
waterfall.render();
// @ts-ignore
expect(waterfall.chart.getController('tooltip').isVisible()).toBe(false);
});

afterAll(() => {
waterfall.destroy();
});
});
10 changes: 9 additions & 1 deletion __tests__/unit/plots/waterfall/component-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ describe('waterfall components', () => {
data: salesByArea,
xField: 'area',
yField: 'sales',
total: {
label: '总计',
},
});

waterfall.render();
Expand All @@ -19,6 +22,11 @@ describe('waterfall components', () => {
// 默认展示:rising, falling & total
expect(legendController.getComponents()[0].id).toMatch('custom');
expect(legendController.getComponents()[0].component.get('items').length).toBe(3);
expect(legendController.getComponents()[0].component.get('items')[2].name).toBe('总计');
expect(legendController.getComponents()[0].component.get('items')[2].value).toBe('total');

waterfall.update({ total: { label: '测试' } });
expect(legendController.getComponents()[0].component.get('items')[2].name).toBe('测试');

waterfall.update({ total: false });
expect(legendController.getComponents()[0].component.get('items').length).toBe(2);
Expand Down Expand Up @@ -50,7 +58,7 @@ describe('waterfall components', () => {
tooltip: false,
});
// @ts-ignore
expect(waterfall.chart.options.tooltip).toBe(undefined);
expect(waterfall.chart.options.tooltip).toBe(false);
expect(waterfall.chart.getComponents().find((co) => co.type === 'tooltip')).toBe(undefined);
});

Expand Down
2 changes: 2 additions & 0 deletions src/plots/waterfall/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ export function tooltip(params: Params<WaterfallOptions>): Params<WaterfallOptio
fields: [yField],
...tooltip,
});
} else {
chart.tooltip(false);
}

return params;
Expand Down