mirror of
https://gitee.com/antv/g6.git
synced 2024-12-05 05:09:07 +08:00
78 lines
2.3 KiB
HTML
78 lines
2.3 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">
|
|
<script src="./assets/jquery-3.2.1.min.js"></script>
|
|
<script src="../build/g6.js"></script>
|
|
<script src="https://gw.alipayobjects.com/os/antv/pkg/_antv.g2-3.2.6/dist/g2.min.js"></script>
|
|
<script src="https://gw.alipayobjects.com/os/antv/pkg/_antv.data-set-0.8.9/dist/data-set.min.js"></script>
|
|
<script src="./assets/d3-4.13.0.min.js"></script>
|
|
<script src="../build/plugins.js"></script>
|
|
<title>云栖 demo 3</title>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="mountNode" style="position: relative;">
|
|
<img class="legend" width="220" src="https://gw.alipayobjects.com/zos/rmsportal/AuLKMNbRvKidugdUCaXz.png" style="position: absolute;right: 320px;"/>
|
|
</div>
|
|
<script>
|
|
$.getJSON('./assets/data/link-data.json', data => {
|
|
const { Util } = G6;
|
|
const graph = new G6.Graph({
|
|
container: 'mountNode',
|
|
height: window.innerHeight, // 画布高
|
|
plugins: [
|
|
new G6.Plugins['tool.highlightSubgraph'](),
|
|
new G6.Plugins['tool.fisheye'](),
|
|
|
|
],
|
|
fitView:'autoZoom',
|
|
});
|
|
graph.node({
|
|
style: {
|
|
stroke: '#333'
|
|
}
|
|
})
|
|
graph.on('afteritemdraw', ({ item }) => {
|
|
const label = item.getLabel();
|
|
if (label) {
|
|
label.set('freezePoint', {
|
|
x: 0,
|
|
y: 0
|
|
});
|
|
}
|
|
});
|
|
graph.read(data);
|
|
// 画布向左偏移 1/6 的画布kuandu
|
|
const width = graph.getWidth();
|
|
graph.translate(-width/6, 0);
|
|
// 隐藏所有边
|
|
graph.getEdges().forEach(edge=>{
|
|
graph.hide(edge);
|
|
});
|
|
// 鼠标悬浮高亮节点,并显示一度关系
|
|
let showEdgesCache;
|
|
graph.on('node:mouseenter', ({item})=>{
|
|
const {
|
|
reNodes,
|
|
reEdges
|
|
} = Util.extract('bi', [item]);
|
|
graph.highlightSubgraph(reNodes.concat(reEdges));
|
|
reEdges.forEach(edge=>{
|
|
graph.show(edge);
|
|
})
|
|
showEdgesCache=reEdges
|
|
});
|
|
graph.on('node:mouseleave', ()=>{
|
|
graph.unhighlightGraph();
|
|
showEdgesCache.forEach(edge=>{
|
|
graph.hide(edge)
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |