Skip to content

Commit

Permalink
fix: tooltip plugin with shouldBegin problem, closes #2006.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanyan-Wang committed Sep 2, 2020
1 parent bddae6f commit c5f7bc3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/plugins/tooltip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ export default class Tooltip extends Base {
}

onMouseEnter(e: IG6GraphEvent) {
const shouldBegin = this.get('shouldBegin');
if (!shouldBegin(e)) return;
const itemTypes = this.get('itemTypes');

if (e.item && e.item.getType && itemTypes.indexOf(e.item.getType()) === -1) return;
const { item } = e;
const graph: IGraph = this.get('graph');
Expand All @@ -99,8 +98,6 @@ export default class Tooltip extends Base {
}

onMouseMove(e: IG6GraphEvent) {
const shouldBegin = this.get('shouldBegin');
if (!shouldBegin(e)) return;
const itemTypes = this.get('itemTypes');
if (e.item && e.item.getType && itemTypes.indexOf(e.item.getType()) === -1) return;
if (!this.currentTarget || e.item !== this.currentTarget) {
Expand All @@ -117,12 +114,11 @@ export default class Tooltip extends Base {
}

showTooltip(e: IG6GraphEvent) {
const shouldBegin = this.get('shouldBegin');
if (!shouldBegin(e)) return;
if (!e.item) {
return;
}
const itemTypes = this.get('itemTypes');

if (e.item.getType && itemTypes.indexOf(e.item.getType()) === -1) return;

const container = this.get('tooltip');
Expand All @@ -146,11 +142,18 @@ export default class Tooltip extends Base {
}

updatePosition(e: IG6GraphEvent) {
const shouldBegin = this.get('shouldBegin');
const tooltip = this.get('tooltip');
if (!shouldBegin(e)) {
modifyCSS(tooltip, {
visibility: 'hidden',
});
return
};
const graph: Graph = this.get('graph');
const width: number = graph.get('width');
const height: number = graph.get('height');

const tooltip = this.get('tooltip');

const offsetX = this.get('offsetX') || 0;
const offsetY = this.get('offsetY') || 0;
Expand Down
7 changes: 7 additions & 0 deletions stories/Plugins/component/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const Tooltip = () => {
const tooltip = new G6.Tooltip({
offsetX: 0,
offsetY: 100, // the height of the top div
shouldBegin: d => {
if (d.target.get('name') === 'text-shape') return true;
return false;
}
});
graph = new Graph({
container: container.current as string | HTMLElement,
Expand All @@ -57,6 +61,9 @@ const Tooltip = () => {
modes: {
default: ['drag-canvas', 'zoom-canvas'],
},
defaultNode: {
size: 50
}
});
graph.data(data);
graph.render();
Expand Down

0 comments on commit c5f7bc3

Please sign in to comment.