g6/packages/site/examples/tool/minimap/demo/minimap.ts

77 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-08-23 14:59:29 +08:00
import { Graph, Util } from '@antv/g6';
import insertCss from 'insert-css';
2023-08-25 10:37:47 +08:00
const container = document.getElementById('container') as HTMLElement;
2023-08-23 14:59:29 +08:00
const width = container.scrollWidth;
const height = (container.scrollHeight || 500) - 110;
const data = Util.mock(20).random();
2023-08-25 13:52:08 +08:00
2023-08-23 14:59:29 +08:00
/** minimap with string config */
const minimap1 = 'minimap';
/** minimap with object onfig and delegate type */
2023-08-25 10:35:20 +08:00
const minimap2 = {
2023-08-23 14:59:29 +08:00
key: 'minimap2',
type: 'minimap',
2023-08-25 10:35:20 +08:00
size: [300, 200],
2023-08-23 14:59:29 +08:00
mode: 'delegate',
delegateStyle: {
fill: 'red',
},
2023-08-25 10:35:20 +08:00
className: 'g6-minimap-2',
viewportClassName: 'g6-minimap-viewport-2',
};
2023-08-23 14:59:29 +08:00
/** minimap with object onfig and keyShape type */
const minimap3 = {
key: 'minimap3',
type: 'minimap',
mode: 'keyShape',
2023-08-25 10:35:20 +08:00
size: [300, 200],
className: 'g6-minimap-3',
viewportClassName: 'g6-minimap-viewport-3',
2023-08-23 14:59:29 +08:00
};
new Graph({
container,
width,
height,
data,
2023-08-25 10:35:20 +08:00
layout: {
type: 'force',
2023-08-23 14:59:29 +08:00
},
node: {
labelShape: {
text: {
fields: ['id'],
formatter: (model) => {
return model.id;
},
},
},
},
modes: {
2023-08-25 10:35:20 +08:00
default: ['brush-select', 'zoom-canvas', 'activate-relations', 'drag-canvas', 'drag-node'],
2023-08-23 14:59:29 +08:00
},
2023-08-25 10:35:20 +08:00
plugins: [minimap1, minimap2, minimap3],
});
/** set the style of minimap */
insertCss(`
.g6-minimap-2 {
position:absolute;
bottom:40px;
right:40px;
box-shadow:0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.2);
}
.g6-minimap-viewport-2 {
border: 2px solid rgb(25, 128, 255);
}
.g6-minimap-3 {
position:absolute;
bottom:40px;
left:40px;
box-shadow:0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.2);
}
.g6-minimap-viewport-3 {
border: 2px solid rgb(25, 128, 255);
}
`);