2019-09-30 13:19:00 +08:00
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="en">
|
|
|
|
|
<head>
|
2020-02-14 10:10:54 +08:00
|
|
|
|
<meta charset="UTF-8" />
|
2019-09-30 13:19:00 +08:00
|
|
|
|
<title>自定义节点选中样式</title>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div id="mountNode"></div>
|
|
|
|
|
<script src="../build/g6.js"></script>
|
|
|
|
|
<script>
|
|
|
|
|
/**
|
|
|
|
|
* 本案例演示如何通过交互设置元素状态:当鼠标hover到圆形节点上时,圆形节点执行动画效果
|
|
|
|
|
* by 镜曦。
|
2020-02-14 10:10:54 +08:00
|
|
|
|
*/
|
|
|
|
|
G6.registerNode(
|
|
|
|
|
'animate-circle',
|
|
|
|
|
{
|
|
|
|
|
setState: function setState(name, value, item) {
|
|
|
|
|
const shape = item.get('keyShape');
|
|
|
|
|
const cfg = item.get('model');
|
|
|
|
|
if (name === 'running') {
|
|
|
|
|
if (value) {
|
|
|
|
|
shape.animate(
|
|
|
|
|
ratio => {
|
|
|
|
|
const diff = ratio <= 0.5 ? ratio * 10 : (1 - ratio) * 10;
|
|
|
|
|
return {
|
|
|
|
|
r: cfg.size / 2 + diff,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
repeat: true,
|
|
|
|
|
duration: 1000,
|
|
|
|
|
easing: 'easeCubic',
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
shape.stopAnimate();
|
|
|
|
|
shape.attr('lineDash', null);
|
|
|
|
|
}
|
2019-09-30 13:19:00 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
2020-02-14 10:10:54 +08:00
|
|
|
|
'circle',
|
|
|
|
|
);
|
|
|
|
|
const data = {
|
|
|
|
|
nodes: [
|
|
|
|
|
{
|
|
|
|
|
x: 100,
|
|
|
|
|
y: 100,
|
|
|
|
|
shape: 'animate-circle',
|
|
|
|
|
label: 'animate-circle',
|
|
|
|
|
id: 'node1',
|
|
|
|
|
size: 30,
|
|
|
|
|
labelCfg: {
|
|
|
|
|
position: 'bottom',
|
|
|
|
|
},
|
2019-09-30 13:19:00 +08:00
|
|
|
|
},
|
2020-02-14 10:10:54 +08:00
|
|
|
|
{
|
|
|
|
|
x: 400,
|
|
|
|
|
y: 100,
|
|
|
|
|
shape: 'rect',
|
|
|
|
|
label: 'rect2',
|
|
|
|
|
id: 'node2',
|
|
|
|
|
labelCfg: {
|
|
|
|
|
position: 'bottom',
|
|
|
|
|
},
|
2019-09-30 13:19:00 +08:00
|
|
|
|
},
|
2020-02-14 10:10:54 +08:00
|
|
|
|
],
|
|
|
|
|
edges: [
|
|
|
|
|
{
|
|
|
|
|
source: 'node1',
|
|
|
|
|
target: 'node2',
|
|
|
|
|
label: 'line',
|
|
|
|
|
labelCfg: {
|
|
|
|
|
refY: 10,
|
|
|
|
|
},
|
|
|
|
|
style: {
|
|
|
|
|
endArrow: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
2019-09-30 13:19:00 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const graph = new G6.Graph({
|
|
|
|
|
container: 'mountNode',
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 600,
|
|
|
|
|
defaultNode: {
|
|
|
|
|
color: '#87e8de',
|
|
|
|
|
style: {
|
2020-02-14 10:10:54 +08:00
|
|
|
|
fill: '#87e8de',
|
|
|
|
|
},
|
2019-09-30 13:19:00 +08:00
|
|
|
|
},
|
|
|
|
|
defaultEdge: {
|
2020-02-14 10:10:54 +08:00
|
|
|
|
color: '#bae7ff',
|
2019-09-30 13:19:00 +08:00
|
|
|
|
},
|
|
|
|
|
modes: {
|
2020-02-14 10:10:54 +08:00
|
|
|
|
default: ['drag-node'],
|
|
|
|
|
},
|
2019-09-30 13:19:00 +08:00
|
|
|
|
});
|
|
|
|
|
graph.data(data);
|
|
|
|
|
graph.render();
|
|
|
|
|
|
|
|
|
|
graph.on('node:mouseenter', ev => {
|
|
|
|
|
const node = ev.item;
|
|
|
|
|
graph.setItemState(node, 'running', true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
graph.on('node:mouseleave', ev => {
|
|
|
|
|
const node = ev.item;
|
|
|
|
|
graph.setItemState(node, 'running', false);
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
</body>
|
2020-02-14 10:10:54 +08:00
|
|
|
|
</html>
|