mirror of
https://gitee.com/antv/g6.git
synced 2024-12-16 02:21:25 +08:00
37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
import { Graph as BaseGraph, Extensions, Util, extend } from '@antv/g6';
|
|
|
|
const Graph = extend(BaseGraph, {
|
|
plugins: {
|
|
grid: Extensions.Grid,
|
|
},
|
|
});
|
|
|
|
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'],
|
|
},
|
|
plugins: [
|
|
{
|
|
key: 'default-grid',
|
|
type: 'grid',
|
|
img: 'url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAiIGhlaWdodD0iNDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PHBhdHRlcm4gaWQ9ImdyaWQiIHdpZHRoPSI0MCIgaGVpZ2h0PSI0MCIgcGF0dGVyblVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+PHBhdGggZD0iTSAwIDEwIEwgNDAgMTAgTSAxMCAwIEwgMTAgNDAgTSAwIDIwIEwgNDAgMjAgTSAyMCAwIEwgMjAgNDAgTSAwIDMwIEwgNDAgMzAgTSAzMCAwIEwgMzAgNDAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2UwZTBlMCIgb3BhY2l0eT0iMC4yIiBzdHJva2Utd2lkdGg9IjEiLz48cGF0aCBkPSJNIDQwIDAgTCAwIDAgMCA0MCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjZTBlMGUwIiBzdHJva2Utd2lkdGg9IjEiLz48L3BhdHRlcm4+PC9kZWZzPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JpZCkiLz48L3N2Zz4=)',
|
|
},
|
|
],
|
|
});
|
|
|
|
if (typeof window !== 'undefined')
|
|
window.onresize = () => {
|
|
if (!graph || graph.destroyed) return;
|
|
if (!container || !container.scrollWidth || !container.scrollHeight) return;
|
|
graph.setSize([container.scrollWidth, container.scrollHeight]);
|
|
};
|