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: correctly hide tooltip when point out #6270

Merged
merged 1 commit into from
Sep 4, 2024
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
16 changes: 16 additions & 0 deletions packages/g6/__tests__/demos/plugin-tooltip.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import data from '@@/dataset/combo.json';
import type { IElementEvent } from '@antv/g6';
import { Graph } from '@antv/g6';

export const pluginTooltip: TestCase = async (context) => {
Expand Down Expand Up @@ -33,6 +34,7 @@ export const pluginTooltip: TestCase = async (context) => {
pluginTooltip.form = (panel) => {
const config = {
trigger: 'click',
enable: 'all',
};
return [
panel
Expand All @@ -46,6 +48,20 @@ export const pluginTooltip: TestCase = async (context) => {
}),
);
}),
panel
.add(config, 'enable', ['all', 'node', 'edge', 'combo'])
.name('Change Enable Target')
.onChange((enable: string) => {
graph.setPlugins((plugins) =>
plugins.map((plugin) => {
if (typeof plugin === 'object' && plugin.type === 'tooltip') {
if (enable === 'all') return { ...plugin, enable: true };
else return { ...plugin, enable: (event: IElementEvent) => event.targetType === enable };
}
return plugin;
}),
);
}),
];
};

Expand Down
6 changes: 4 additions & 2 deletions packages/g6/src/plugins/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
} = event;
// click the same item twice, tooltip will be hidden
if (this.currentTarget === id) {
this.currentTarget = null;
this.hide(event);
this.currentTarget = null;
} else {
this.currentTarget = id;
this.show(event);
Expand Down Expand Up @@ -294,7 +294,9 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
this.tooltipElement?.hide();
return;
}
if (!this.tooltipElement || !this.isEnable(event)) return;
if (!this.tooltipElement) return;
// No target node: tooltip has been hidden. No need for duplicated call.
if (!this.currentTarget) return;
const {
client: { x, y },
} = event;
Expand Down
Loading