2019-09-26 21:05:57 +08:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
2020-02-14 10:10:54 +08:00
|
|
|
<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>
|
|
|
|
<script src="../build/g6.js"></script>
|
|
|
|
<script>
|
|
|
|
G6.registerEdge(
|
|
|
|
'selfLine',
|
2019-09-26 21:05:57 +08:00
|
|
|
{
|
2020-02-14 10:10:54 +08:00
|
|
|
options: {
|
|
|
|
style: {
|
|
|
|
stroke: 'red',
|
|
|
|
lineWidth: 5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
drawShape(cfg, group) {
|
|
|
|
const shapeStyle = this.getShapeStyle(cfg);
|
|
|
|
const keyShape = group.addShape('path', {
|
|
|
|
className: 'edge-shape',
|
|
|
|
attrs: shapeStyle,
|
|
|
|
});
|
|
|
|
return keyShape;
|
|
|
|
},
|
2019-10-16 12:20:16 +08:00
|
|
|
},
|
2020-02-14 10:10:54 +08:00
|
|
|
'single-line',
|
|
|
|
);
|
2019-09-29 21:02:16 +08:00
|
|
|
|
2020-02-14 10:10:54 +08:00
|
|
|
const data = {
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'triangle1',
|
|
|
|
type: 'a',
|
|
|
|
label: '主题 ModelRect Title',
|
|
|
|
description: '这里是一顿描述信息,不知道长短',
|
|
|
|
x: 150,
|
|
|
|
y: 100,
|
|
|
|
anchorPoints: [
|
|
|
|
[0.5, 1],
|
|
|
|
[1, 0.5],
|
|
|
|
],
|
|
|
|
// shape: 'triangle',
|
|
|
|
style: {
|
|
|
|
fill: 'blue',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'triangle',
|
|
|
|
type: 'b',
|
|
|
|
label: '主题 ModelRect Title',
|
|
|
|
description: '这里是一顿描述信息,不知道长短',
|
|
|
|
x: 250,
|
|
|
|
y: 100,
|
|
|
|
anchorPoints: [
|
|
|
|
[0.5, 1],
|
|
|
|
[1, 0.5],
|
|
|
|
],
|
|
|
|
style: {
|
|
|
|
stroke: 'green',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
edges: [
|
|
|
|
{
|
|
|
|
source: 'triangle1',
|
|
|
|
target: 'triangle',
|
|
|
|
shape: 'selfLine',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const graph = new G6.Graph({
|
|
|
|
container: 'mountNode',
|
|
|
|
width: 800,
|
|
|
|
height: 600,
|
|
|
|
defaultNode: {
|
|
|
|
shape: 'star',
|
|
|
|
size: [60, 80],
|
2019-09-29 21:02:16 +08:00
|
|
|
style: {
|
2020-02-14 10:10:54 +08:00
|
|
|
fill: '#bae637',
|
|
|
|
stroke: '#000',
|
|
|
|
lineWidth: 5,
|
|
|
|
},
|
|
|
|
labelCfg: {
|
|
|
|
position: 'bottom',
|
|
|
|
offset: 20,
|
|
|
|
style: {
|
|
|
|
fill: '#9254de',
|
|
|
|
fontSize: 18,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
linkPoints: {
|
|
|
|
top: true,
|
|
|
|
left: true,
|
|
|
|
right: true,
|
|
|
|
leftBottom: true,
|
|
|
|
rightBottom: true,
|
|
|
|
size: 5,
|
|
|
|
fill: '#fff',
|
|
|
|
},
|
|
|
|
icon: {
|
|
|
|
show: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nodeStateStyles: {
|
|
|
|
hover: {
|
|
|
|
fill: '#d3adf7',
|
|
|
|
},
|
2019-09-26 21:05:57 +08:00
|
|
|
},
|
2020-02-14 10:10:54 +08:00
|
|
|
modes: {
|
|
|
|
default: ['drag-canvas'],
|
2019-09-26 21:05:57 +08:00
|
|
|
},
|
2020-02-14 10:10:54 +08:00
|
|
|
});
|
2019-09-26 21:05:57 +08:00
|
|
|
|
2020-02-14 10:10:54 +08:00
|
|
|
graph.data(data);
|
|
|
|
graph.render();
|
2019-09-26 21:05:57 +08:00
|
|
|
|
2020-02-14 10:10:54 +08:00
|
|
|
graph.on('node:click', evt => {
|
|
|
|
const { item } = evt;
|
|
|
|
graph.setItemState(item, 'select', true);
|
|
|
|
|
|
|
|
graph.updateItem(item, {
|
|
|
|
size: [180, 90],
|
|
|
|
shape: 'modelRect',
|
|
|
|
type: 'b',
|
|
|
|
style: {
|
|
|
|
fill: '#fff',
|
|
|
|
},
|
|
|
|
preRect: {
|
|
|
|
fill: '#ff4d4f',
|
|
|
|
},
|
|
|
|
linkPoints: {
|
|
|
|
fill: '#fff',
|
|
|
|
size: 5,
|
|
|
|
},
|
|
|
|
stateIcon: {
|
|
|
|
img:
|
|
|
|
'https://gw.alipayobjects.com/zos/basement_prod/c781088a-c635-452a-940c-0173663456d4.svg',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2019-09-26 21:05:57 +08:00
|
|
|
|
2020-02-14 10:10:54 +08:00
|
|
|
graph.on('node:mouseenter', evt => {
|
|
|
|
const { item } = evt;
|
|
|
|
graph.setItemState(item, 'hover', true);
|
|
|
|
});
|
2019-09-26 21:05:57 +08:00
|
|
|
|
2020-02-14 10:10:54 +08:00
|
|
|
graph.on('node:mouseleave', evt => {
|
|
|
|
const { item } = evt;
|
|
|
|
graph.setItemState(item, 'hover', false);
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|