Skip to content

Commit

Permalink
fix(tooltip): 修复 tooltip markers 没有正确显示/隐藏的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Mar 19, 2020
1 parent 7b5f651 commit 394dad2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/chart/controller/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ export default class Tooltip extends Controller<TooltipOption> {
const items = this.getTooltipItems(point);
if (!items.length) {
// 无内容则不展示,同时 tooltip 需要隐藏
if (this.tooltip) {
this.tooltip.hide();
}
this.hideTooltip();
return;
}
const title = this.getTitle(items);
Expand Down Expand Up @@ -116,6 +114,10 @@ export default class Tooltip extends Controller<TooltipOption> {
this.tooltip.update(newPoint);
this.tooltip.show(); // tooltip 有可能被隐藏,需要保证显示状态
}

if (this.tooltipMarkersGroup) {
this.tooltipMarkersGroup.show();
}
}

this.items = items;
Expand Down
5 changes: 5 additions & 0 deletions tests/bugs/2174-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ describe('#2174, #2175', () => {
const point = chart.getXY({ name: 'London', 月份: 'Jan.', 月均降雨量: 18.9 });
// 相同的内容,先展示,再关闭,再展示,tooltip 应该展示
chart.showTooltip(point);
const tooltipMarkerGroup = chart.foregroundGroup.findAllByName('tooltipMarkersGroup')[0];
expect(tooltipMarkerGroup.get('visible')).toBeTruthy();

chart.hideTooltip();

chart.showTooltip(point);

const tooltip = chart.ele.getElementsByClassName('g2-tooltip')[0];
// @ts-ignore
expect(tooltip.style.visibility).toBe('visible');
expect(tooltipMarkerGroup.get('visible')).toBeTruthy();

// 如果内容为空,tooltip 应该隐藏
chart.showTooltip({
Expand All @@ -45,5 +49,6 @@ describe('#2174, #2175', () => {
});
// @ts-ignore
expect(tooltip.style.visibility).toBe('hidden');
expect(tooltipMarkerGroup.get('visible')).toBeFalsy();
});
});

0 comments on commit 394dad2

Please sign in to comment.