mirror of
https://gitee.com/antv/g6.git
synced 2024-12-03 20:28:36 +08:00
124 lines
2.8 KiB
HTML
124 lines
2.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
<title>默认的图片节点</title>
|
|
</head>
|
|
<body>
|
|
<div id='xxx'>
|
|
<div id="mountNode"></div>
|
|
</div>
|
|
<script src="../build/g6.js"></script>
|
|
<script>
|
|
|
|
const data = {
|
|
nodes: [
|
|
{
|
|
id: 'triangle',
|
|
label: '主题 ModelRect Title',
|
|
description: '这里是一顿描述信息,不知道长短',
|
|
x: 150,
|
|
y: 100
|
|
}
|
|
]
|
|
}
|
|
|
|
const graph = new G6.Graph({
|
|
container: 'mountNode',
|
|
width: 800,
|
|
height: 600,
|
|
defaultNode: {
|
|
shape: 'modelRect',
|
|
size: [200, 80],
|
|
style: {
|
|
fill: '#f0f5ff',
|
|
stroke: '#adc6ff',
|
|
lineWidth: 2
|
|
},
|
|
labelCfg: {
|
|
style: {
|
|
fill: '#9254de',
|
|
fontSize: 18
|
|
}
|
|
},
|
|
linkPoints: {
|
|
top: true,
|
|
bottom: true,
|
|
left: true,
|
|
right: true,
|
|
size: 5,
|
|
fill: '#fff'
|
|
},
|
|
logoIcon: {
|
|
show: false
|
|
},
|
|
stateIcon: {
|
|
show: true,
|
|
img: 'https://gw.alipayobjects.com/zos/basement_prod/c781088a-c635-452a-940c-0173663456d4.svg'
|
|
}
|
|
},
|
|
nodeStateStyles: {
|
|
hover: {
|
|
fill: '#efdbff'
|
|
}
|
|
},
|
|
modes: {
|
|
default: ['drag-canvas']
|
|
}
|
|
})
|
|
|
|
graph.data(data)
|
|
graph.render()
|
|
|
|
graph.on('node:click', evt => {
|
|
console.log(evt)
|
|
evt.preventDefault()
|
|
evt.stopPropagation()
|
|
const { item } = evt
|
|
// graph.setItemState(item, 'select', true)
|
|
|
|
// graph.updateItem(item, {
|
|
// size: [ 160, 130],
|
|
// style: {
|
|
// fill: '#b5f5ec'
|
|
// },
|
|
// preRect: {
|
|
// fill: '#ff4d4f'
|
|
// },
|
|
// linkPoints: {
|
|
// fill: '#fff',
|
|
// size: 5
|
|
// },
|
|
// stateIcon: {
|
|
// img: 'https://gw.alipayobjects.com/zos/basement_prod/c781088a-c635-452a-940c-0173663456d4.svg'
|
|
// }
|
|
// })
|
|
})
|
|
|
|
graph.on('node:mouseenter', evt => {
|
|
const { item } = evt
|
|
graph.setItemState(item, 'hover', true)
|
|
})
|
|
|
|
graph.on('node:mouseleave', evt => {
|
|
const { item } = evt
|
|
graph.setItemState(item, 'hover', false)
|
|
})
|
|
|
|
document.getElementById('mountNode').addEventListener('click', evt => {
|
|
console.log('mountNode', evt)
|
|
evt.preventDefault()
|
|
evt.stopPropagation()
|
|
})
|
|
|
|
document.getElementById('xxx').addEventListener('click', evt => {
|
|
// 不会执行到这里
|
|
console.log('冒泡了', evt)
|
|
evt.preventDefault()
|
|
evt.stopPropagation()
|
|
})
|
|
</script>
|
|
</body>
|
|
</html> |