mirror of
https://gitee.com/antv/g6.git
synced 2024-12-16 02:21:25 +08:00
339f28c564
* feat: fix plugin demo with extensions * Chore:check translate (#4886) * feat: check plugins * chore: update docs
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { Graph as BaseGraph, Extensions, Util, extend } from '@antv/g6';
|
|
|
|
const Graph = extend(BaseGraph, {
|
|
plugins: {
|
|
menu: Extensions.Menu,
|
|
},
|
|
});
|
|
|
|
const container = document.getElementById('container') as HTMLElement;
|
|
const width = container.scrollWidth;
|
|
const height = (container.scrollHeight || 500) - 110;
|
|
const data = Util.mock(6).circle();
|
|
|
|
const graph = new Graph({
|
|
container,
|
|
width,
|
|
height,
|
|
data,
|
|
modes: {
|
|
default: ['brush-select', 'zoom-canvas', 'activate-relations', 'drag-canvas', 'drag-node'],
|
|
},
|
|
});
|
|
|
|
const contextMenu = {
|
|
type: 'menu',
|
|
key: 'my-context-menu',
|
|
trigger: 'contextmenu',
|
|
/** async string menu */
|
|
getContent: (e) => {
|
|
return `
|
|
<ul class='g6-contextmenu-ul'>
|
|
<li class='g6-contextmenu-li' code='delete'> Delete </li>
|
|
<li class='g6-contextmenu-li' code='add' > Add </li>
|
|
</ul>
|
|
`;
|
|
},
|
|
handleMenuClick: (target: HTMLLIElement, itemId, graph) => {
|
|
//@ts-ignore
|
|
const { value } = Object.values(target.attributes).find((item) => item.name === 'code');
|
|
alert(`Item ID: ${itemId} \n Code: ${value}`);
|
|
},
|
|
};
|
|
|
|
graph.addPlugins([contextMenu]);
|