g6/demos/internal-node-rect.html
2019-11-01 09:58:54 +08:00

137 lines
2.9 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="mountNode"></div>
<div id="mountNode1"></div>
<script src="../build/g6.js"></script>
<script>
G6.registerNode('selfCircle', {
drawShape(cfg, group) {
const style = this.getShapeStyle(cfg)
debugger
console.log(style)
const keyShape = group.addShape('circle', {
attrs: style
})
return keyShape
},
afterDraw(cfg, group) {
const shape = group.addShape('rect', {
attrs: {
x: 0,
y: 0,
width: 20,
height: 30,
fill: 'blue'
}
})
return shape
}
}, 'circle')
let nodes = []
for(let i = 0; i < 500; i++) {
nodes.push({
id: `node-${i}`,
label: `label-${i}`,
x: Math.random() * 650,
y: Math.random() * 550
})
}
const data = {
nodes
}
const graph = new G6.Graph({
container: 'mountNode',
width: 800,
height: 600,
defaultNode: {
shape: 'rect',
size: [60, 30],
color: 'green',
style: {
// fill: 'red',
// stroke: '#eaff8f',
lineWidth: 5
},
labelCfg: {
style: {
fill: '#9254de',
fontSize: 18
}
},
linkPoints: {
top: true,
bottom: true,
left: true,
right: true,
size: 5,
fill: '#fff'
}
},
nodeStateStyles: {
hover: {
fill: '#d3adf7'
}
},
modes: {
default: ['drag-canvas', 'drag-node', {
type: 'brush-select',
trigger: 'ctrl'
}]
}
})
graph.data(data)
graph.render()
graph.on('node:click', evt => {
const { item } = evt
graph.setItemState(item, 'select', true)
graph.updateItem(item, {
size: [ 260, 130],
style: {
opacity: 0.6
},
preRect: {
fill: 'blue'
},
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)
})
// graph.addItem('group', {
// nodes: ['image', 'triangle'],
// type: 'rect',
// zIndex: 0,
// title: {
// text: '名称'
// }
// })
</script>
</body>
</html>