-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tooltip): support multiple tooltips for hover and click on the s…
…ame element (#6602) * feat(tooltip): support multiple tooltips for hover and click on the same element * docs: add dual tooltips demo * docs: update screenshot
- Loading branch information
Showing
5 changed files
with
145 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import type { IElementEvent, Tooltip } from '@antv/g6'; | ||
import { Graph } from '@antv/g6'; | ||
|
||
export const pluginTooltipDual: TestCase = async (context) => { | ||
const graph = new Graph({ | ||
...context, | ||
data: { | ||
nodes: [ | ||
{ id: 'node1', style: { x: 100, y: 100 } }, | ||
{ id: 'node2', style: { x: 200, y: 200 } }, | ||
], | ||
edges: [{ id: 'edge', source: 'node1', target: 'node2' }], | ||
}, | ||
node: { | ||
style: { | ||
labelText: (d) => d.id, | ||
}, | ||
}, | ||
plugins: [ | ||
function () { | ||
return { | ||
key: 'tooltip-click', | ||
type: 'tooltip', | ||
trigger: 'click', | ||
getContent: (evt: any, items: any[]) => { | ||
return `<div>click ${items[0].id}</div>`; | ||
}, | ||
onOpenChange: (open: boolean) => { | ||
const tooltip = this.getPluginInstance('tooltip-hover') as Tooltip; | ||
if (tooltip && open) tooltip.hide(); | ||
}, | ||
}; | ||
}, | ||
function () { | ||
return { | ||
key: 'tooltip-hover', | ||
type: 'tooltip', | ||
trigger: 'hover', | ||
enable: (e: IElementEvent) => { | ||
const tooltip = this.getPluginInstance('tooltip-click') as Tooltip; | ||
// @ts-expect-error access private property | ||
return e.target.id !== tooltip.currentTarget; | ||
}, | ||
getContent: (evt: any, items: any[]) => { | ||
return `<div>hover ${items[0].id}</div>`; | ||
}, | ||
onOpenChange: (open: boolean) => { | ||
const tooltip = this.getPluginInstance('tooltip-click') as Tooltip; | ||
if (tooltip && open) { | ||
tooltip.hide(); | ||
} | ||
}, | ||
}; | ||
}, | ||
], | ||
}); | ||
|
||
await graph.render(); | ||
|
||
return graph; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Graph } from '@antv/g6'; | ||
|
||
const graph = new Graph({ | ||
container: 'container', | ||
data: { | ||
nodes: [ | ||
{ id: '0', data: { label: 'node-0', description: 'This is node-0.' } }, | ||
{ id: '1', data: { label: 'node-1', description: 'This is node-1.' } }, | ||
{ id: '2', data: { label: 'node-2', description: 'This is node-2.' } }, | ||
{ id: '3', data: { label: 'node-3', description: 'This is node-3.' } }, | ||
{ id: '4', data: { label: 'node-4', description: 'This is node-4.' } }, | ||
{ id: '5', data: { label: 'node-5', description: 'This is node-5.' } }, | ||
], | ||
edges: [ | ||
{ source: '0', target: '1', data: { description: 'This is edge from node 0 to node 1.' } }, | ||
{ source: '0', target: '2', data: { description: 'This is edge from node 0 to node 2.' } }, | ||
{ source: '0', target: '3', data: { description: 'This is edge from node 0 to node 3.' } }, | ||
{ source: '0', target: '4', data: { description: 'This is edge from node 0 to node 4.' } }, | ||
{ source: '0', target: '5', data: { description: 'This is edge from node 0 to node 5.' } }, | ||
], | ||
}, | ||
layout: { | ||
type: 'grid', | ||
}, | ||
plugins: [ | ||
function () { | ||
return { | ||
key: 'tooltip-click', | ||
type: 'tooltip', | ||
trigger: 'click', | ||
getContent: (evt, items) => { | ||
return `<div>click ${items[0].id}</div>`; | ||
}, | ||
onOpenChange: (open) => { | ||
const tooltip = this.getPluginInstance('tooltip-hover'); | ||
if (tooltip && open) tooltip.hide(); | ||
}, | ||
}; | ||
}, | ||
function () { | ||
return { | ||
key: 'tooltip-hover', | ||
type: 'tooltip', | ||
trigger: 'hover', | ||
enable: (e) => { | ||
const tooltip = this.getPluginInstance('tooltip-click'); | ||
return e.target.id !== tooltip.currentTarget; | ||
}, | ||
getContent: (evt, items) => { | ||
return `<div>hover ${items[0].id}</div>`; | ||
}, | ||
onOpenChange: (open) => { | ||
const tooltip = this.getPluginInstance('tooltip-click'); | ||
if (tooltip && open) { | ||
tooltip.hide(); | ||
} | ||
}, | ||
}; | ||
}, | ||
], | ||
behaviors: ['drag-canvas', 'drag-element'], | ||
}); | ||
|
||
graph.render(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters